<?xml version="1.0" encoding="utf-8"?>
<odoo>

    <!-- For Add pattern attribute in odoo standard textbox -->
    <template id="tmpl_sh_textbox_for_pattern" inherit_id="survey.question_char_box" name="Text box">
        <xpath expr="//input" position="replace">
            <t t-if="question.validation_is_sh_textbox_pattern">
 			
 			 <input  
 			   type="text" 
               class="form-control o_survey_question_text_box bg-transparent text-dark rounded-0 p-0" 
               t-attf-pattern="#{question.validation_sh_textbox_pattern}" 
               t-attf-placeholder="#{question.validation_sh_textbox_placeholder}" 
               t-att-name="question.id"
               t-att-value="answer_lines[0].value_char_box if answer_lines else None"
               t-att-data-question-type="question.question_type"
               t-att-data-validation-length-min="question.validation_length_min if question.validation_required else False"
               t-att-data-validation-length-max="question.validation_length_max if question.validation_required else False"/>
            </t>                

        
            <t t-else="">
            <input t-att-type="'email' if question.validation_email else 'text'"
               class="form-control o_survey_question_text_box bg-transparent text-dark rounded-0 p-0" t-att-name="question.id"
               t-att-value="answer_lines[0].value_char_box if answer_lines else None"
               t-att-data-question-type="question.question_type"
               t-att-data-validation-length-min="question.validation_length_min if question.validation_required else False"
               t-att-data-validation-length-max="question.validation_length_max if question.validation_required else False"/>
            </t>
        </xpath>
    </template>

    <!-- template for color -->
    <template id="tmpl_sh_color" name="SH Color">
        <input
            type="color"
            class="form-control o_survey_question_color_box bg-transparent text-dark rounded-0 p-2"
            t-att-name="question.id"
            t-att-value="answer_lines[0].value_ans_sh_color if answer_lines else None"
            t-att-data-question-type="question.question_type"
        />
    </template>

    <!-- template for email -->
    <template id="tmpl_sh_email" name="SH email">
        <input
            type="email"
            class="form-control o_survey_question_email_box bg-transparent text-dark rounded-0 p-0"
            t-att-name="question.id"
            t-att-value="answer_lines[0].value_ans_sh_email if answer_lines else None"
            placeholder="example@domain.com"
            t-att-data-question-type="question.question_type"
        />
    </template>

    <!-- template for url -->
    <template id="tmpl_sh_url" name="SH URL">
        <input
            type="url"
            class="form-control o_survey_question_email_box bg-transparent text-dark rounded-0 p-0"
            t-att-name="question.id"
            t-att-value="answer_lines[0].value_ans_sh_url if answer_lines else None"
            placeholder="https://example.com"
            t-att-data-question-type="question.question_type"
        />
    </template>

    <!-- template for Time -->
    <template id="tmpl_sh_time" name="SH Time">
        <t t-if="question.validation_required">
            <input
                type="time"
                class="form-control o_survey_question_email_box bg-transparent text-dark rounded-0 p-0"
                t-att-name="question.id"
                t-att-value="answer_lines[0].value_ans_sh_time if answer_lines else None"
                t-attf-min="#{question.validation_sh_time_min}"
                t-attf-max="#{question.validation_sh_time_max}"
                t-attf-step="#{question.validation_sh_time_step}"
                placeholder="https://example.com"
                t-att-data-question-type="question.question_type"
            />
        </t>
        <t t-if="question.validation_required == False">
            <input
                type="time"
                class="form-control o_survey_question_email_box bg-transparent text-dark rounded-0 p-0"
                t-att-name="question.id"
                t-att-value="answer_lines[0].value_ans_sh_time if answer_lines else None"
                placeholder="https://example.com"
                t-att-data-question-type="question.question_type"
            />
        </t>
    </template>

    <!-- template for Range -->
    <template id="tmpl_sh_range" name="SH Range">
        <t t-if="question.validation_required">
            <input
                type="range"
                class="form-control o_survey_question_email_box bg-transparent text-dark rounded-0 p-0"
                t-att-name="question.id"
                t-att-value="answer_lines[0].value_ans_sh_range if answer_lines else None"
                t-attf-max="#{question.validation_sh_range_max}"
                t-attf-min="#{question.validation_sh_range_min}"
                t-attf-step="#{question.validation_sh_range_step}"
                t-att-data-question-type="question.question_type"
                style='padding: 0 !important;height:8px;overflow: inherit;'        
            />
            <label t-attf-id="#{question.id}" class='range_value d-block text-center mt-2' style='height: 22px;color:#212121;margin-top:0.4rem;'>
            	<span style='color:#212121;margin-top:1rem;' t-out="answer_lines[0].value_ans_sh_range if answer_lines else None"/>
            </label>
        </t>
        <t t-if="question.validation_required == False">
            <input
                type="range"
                class="form-control o_survey_question_email_box bg-transparent text-dark rounded-0 p-0"
                t-att-name="question.id"
                t-att-value="answer_lines[0].value_ans_sh_range if answer_lines else None"
                t-att-data-question-type="question.question_type"
                style='padding: 0 !important;height:8px;overflow: inherit;'
            />
            <!--   t-attf-oninput="document.getElementById(#{question.id}).innerHTML = this.value" -->

            <label t-attf-id="#{question.id}" class='range_value d-block text-center mt-2' style='height: 22px;color:#212121;margin-top:0.4rem;'>
            	<span  t-out="answer_lines[0].value_ans_sh_range if answer_lines else None"/>
            </label>
        </t>
    </template>

    <!-- template for Week -->
    <template id="tmpl_sh_week" name="SH Week">
        <t t-if="question.validation_required">
            <input
                type="week"
                class="form-control o_survey_question_email_box bg-transparent text-dark rounded-0 p-0"
                t-attf-min="#{question.validation_sh_week_min}"
                t-attf-max="#{question.validation_sh_week_max}"
                t-attf-step="#{question.validation_sh_week_step}"
                t-att-name="question.id"
                t-att-value="answer_lines[0].value_ans_sh_week if answer_lines else None"
                t-att-data-question-type="question.question_type"
            />
        </t>
        <t t-if="question.validation_required == False">
            <input
                type="week"
                class="form-control o_survey_question_email_box bg-transparent text-dark rounded-0 p-0"
                t-att-name="question.id"
                t-att-value="answer_lines[0].value_ans_sh_week if answer_lines else None"
                t-att-data-question-type="question.question_type"
            />
        </t>
    </template>

    <!-- template for Month -->
    <template id="tmpl_sh_month" name="SH Month">
        <t t-if="question.validation_required">
            <input
                type="month"
                class="form-control o_survey_question_email_box bg-transparent text-dark rounded-0 p-0"
                t-attf-min="#{question.validation_sh_month_min}"
                t-attf-max="#{question.validation_sh_month_max}"
                t-attf-step="#{question.validation_sh_month_step}"
                t-att-name="question.id"
                t-att-value="answer_lines[0].value_ans_sh_month if answer_lines else None"
                t-att-data-question-type="question.question_type"
            />
        </t>
        <t t-if="question.validation_required == False">
            <input
                type="month"
                class="form-control o_survey_question_email_box bg-transparent text-dark rounded-0 p-0"
                t-att-name="question.id"
                t-att-value="answer_lines[0].value_ans_sh_month if answer_lines else None"
                t-att-data-question-type="question.question_type"
            />
        </t>
    </template>

    <!-- template for Password -->
    <template id="tmpl_sh_password" name="SH Password">
        <t t-if="question.validation_required">
            <input
                type="password"
                class="form-control o_survey_question_email_box bg-transparent text-dark rounded-0 p-0"
                t-attf-minlength="#{question.validation_sh_password_minlen}"
                t-attf-maxlength="#{question.validation_sh_password_maxlen}"
                t-att-name="question.id"
                t-att-value="answer_lines[0].value_ans_sh_password if answer_lines else None"
                t-att-data-question-type="question.question_type"
            />
        </t>
        <t t-if="question.validation_required == False">
            <input
                type="password"
                class="form-control o_survey_question_email_box bg-transparent text-dark rounded-0 p-0"
                t-att-name="question.id"
                t-att-value="answer_lines[0].value_ans_sh_password if answer_lines else None"
                t-att-data-question-type="question.question_type"
            />
        </t>
    </template>

    <!-- template for file -->
    <template id="tmpl_sh_file" name="SH File">
        <input type="file" class="form-control o_survey_question_email_box bg-transparent text-dark rounded-0 p-0 sh_file_input" t-att-id="question.id" />
        <input
            type="text"
            class="form-control o_survey_question_email_box bg-transparent text-dark rounded-0 p-0 sh_file_input_data"
            t-att-id="question.id"
            t-att-name="question.id"
            t-att-value="answer_lines[0].value_ans_sh_password if answer_lines else None"
            t-att-data-question-type="question.question_type"
            style="display: none;"
        />
    </template>

    <!-- template for file name for review your survey -->
    <template id="tmpl_sh_file_print" name="SH File">
        <a t-att-href="'/survey/download/'+str(answer.id)+'/'+str(question.id)+'/'+str(answer.access_token)">Click here to download file</a>
    </template>


            
        
        
    <!-- template for Many2one -->
<!--      <template id="tmpl_sh_many2one" name="SH Many2one">
     

              
                <select 
                t-att-name="question.id"
                class="form-control">
                    <option value="">Country...</option>
                    
                    <t t-set="sh_m2o_model_records" t-value='request.env[question.que_sh_many2one_model_id.name].sudo().search[()]'/> 
                    <t t-foreach="sh_m2o_model_records" t-as="record">
                        <option t-att-value="record.id">
                            <t t-esc="record.name" />
                        </option>
                    </t>
                </select>
   
     
    </template>  -->
            
        

    <template id="tmpl_sh_address" name="SH Address">
	    <div class="form-row js_cls_sh_address_wrapper row">
	        <div t-if="question.sh_is_show_street" class="form-group col-lg-12 mb-2">
				<b t-if='question.sh_is_show_street_label' t-field='question.sh_is_show_street_label'></b>
	            <input type="text" t-att-data-question-type="question.question_type" t-att-name="question.id" class="js_cls_street form-control" />
	        </div>
	
	        <div t-if="question.sh_is_show_street2" class="form-group col-lg-12 mb-2">
	            <b t-if='question.sh_is_show_street2_label' t-field='question.sh_is_show_street2_label'></b>
	            <input type="text" t-att-data-question-type="question.question_type" t-att-name="question.id" class="js_cls_street2 form-control" />
	        </div>
	        <div class="w-100" />
	
	        <div t-if="question.sh_is_show_city" class="form-group col-md-8 mb-2">
	            <b t-if='question.sh_is_show_city_label' t-field='question.sh_is_show_city_label'></b>
	            <input type="text" t-att-data-question-type="question.question_type" t-att-name="question.id" class="js_cls_city form-control" />
	        </div>
	
	        <div t-if="question.sh_is_show_zip" class="form-group col-md-4 mb-2">
	            <b t-if='question.sh_is_show_zip_label' t-field='question.sh_is_show_zip_label'></b>
	            <input type="text" t-att-name="question.id" t-att-data-question-type="question.question_type" class="js_cls_zip form-control" />
	        </div>
	
	        <div class="w-100" />
	        <div t-if="question.sh_is_show_country_id" class="form-group col-lg-6 mb-2">
	            <b t-if='question.sh_is_show_country_id_label' t-field='question.sh_is_show_country_id_label'></b>
	            <select id="country_id" t-att-data-question-type="question.question_type" t-att-name="question.id" class="js_cls_country_id form-control">
	                <option value="" disabled="disabled" selected="selected">Country...</option>
	            </select>
	        </div>
	        <div t-if="question.sh_is_show_state_id" class="form-group col-lg-6 mb-2">
	            <b t-if='question.sh_is_show_state_id_label' t-field='question.sh_is_show_state_id_label'></b>
	            <select data-init="1" t-att-data-question-type="question.question_type" t-att-name="question.id" class="js_cls_state_id form-control">
	                <option value="" disabled="disabled" selected="selected">State / Province...</option>
	            </select>
	        </div>
	        <div class="w-100" />
	    </div>
	</template>




<!-- 
Many2one
 -->

    <template id="tmpl_sh_many2one" name="SH Many2one">
        <div class="form-row js_cls_sh_many2one_wrapper">
           <div class="form-group col-lg-12">
                 <input t-attf-list="m2o_selection_#{question.id}"  style="width:100%;"
                 type="text"  t-att-data-question-type="question.question_type"
                t-att-data-model_id="question.que_sh_many2one_model_id.id if question.que_sh_many2one_model_id else False"
                t-att-name="question.id" >
                  <datalist t-attf-id="m2o_selection_#{question.id}"
                t-att-data-model_id="question.que_sh_many2one_model_id.id if question.que_sh_many2one_model_id else False"
                t-att-name="question.id" class="d-none js_cls_sh_many2one_select form-control">
                          <option value="">Select...</option>
                  </datalist>
                  </input>
                        
                        
            </div>
        </div>
    </template>
    
    


    <template id="tmpl_sh_many2one_review" name="SH Many2one Review">
        <div class="form-row js_cls_sh_many2one_wrapper">
           <div class="form-group col-lg-12">
                <select  
                t-att-data-question-type="question.question_type"
                t-att-data-model_id="question.que_sh_many2one_model_id.id if question.que_sh_many2one_model_id else False"
                t-att-name="question.id" class="js_cls_sh_many2one_select form-control">
                    <option value="">
                    <t t-if="answer_lines" t-esc="answer_lines[0].value_ans_sh_many2one or None"/>
                    </option>
                </select>
            </div>
        </div>
    </template>



    <template id="tmpl_sh_address_review" name="SH Address Review">
  
          <div class="o_survey_comment_container p-0">
            <textarea class="form-control o_survey_question_text_box bg-transparent text-dark rounded-0 p-0" rows="3" t-att-name="question.id"
                      t-att-data-question-type="question.question_type"><t t-if="answer_lines" t-esc="answer_lines[0].value_ans_sh_address or None"/></textarea>
        </div>
        
    </template>



	<!-- Many2many -->

    <template id="tmpl_sh_many2many" name="SH Many2many">
        <div class="form-row js_cls_sh_many2many_wrapper">
           <div class="form-group col-lg-12">
           		<div  t-att-data-question-type="question.question_type"
                t-att-data-model_id="question.que_sh_many2many_model_id.id if question.que_sh_many2many_model_id else False"
                t-att-name="question.id" class="js_cls_sh_many2many_select_div">
                	  <select multiple="multiple"  t-att-data-question-type="question.question_type"
                t-att-data-model_id="question.que_sh_many2many_model_id.id if question.que_sh_many2many_model_id else False"
                t-att-name="question.id" class="d-none js_cls_sh_many2many_select form-control" >
			                   <!--  <option value="">Select...</option> -->
			                </select>
                </div>
              
            </div>
        </div>
    </template>
    
    


    <template id="tmpl_sh_many2many_review" name="SH Many2many Review">
        <div class="form-row js_cls_sh_many2many_wrapper">
           <div class="form-group col-lg-12">
                <select 
                t-att-data-question-type="question.question_type"
                t-att-data-model_id="question.que_sh_many2many_model_id.id if question.que_sh_many2many_model_id else False"
                t-att-name="question.id" class="js_cls_sh_many2many_select form-control">
                    <option value="">
                    <t t-if="answer_lines" t-esc="answer_lines[0].value_ans_sh_many2many or None"/>
                    </option>
                </select>
            </div>
        </div>
    </template>


	<!-- Signature -->
    <template id="tmpl_sh_signature" name="SH Signature">
        <div class="form-row js_cls_sh_signature_wrapper">
           <div class="form-group col-lg-12">
                <input type="text" 
                t-att-data-question-type="question.question_type"
                t-att-name="question.id" class="js_cls_sh_signature_input d-none form-control"/>


<a href="#" class="btn btn-primary js_cls_sh_signature_clear_btn">
	Clear
</a>                
<div class="js_cls_sh_signature_pad">
  <div class="js_cls_sh_signature_pad_inner"></div>
</div>
                
            </div>
        </div>
    </template>    
    


    <template id="tmpl_sh_signature_review" name="SH Signature Review">
        <div class="form-row js_cls_sh_signature_wrapper">
           <div class="form-group col-lg-12">
           		
           		<img 
           		t-att-src="'data:image/png;base64,%s' % (answer_lines[0].value_ans_sh_signature_src if answer_lines else None)"
           		t-att-data-question-type="question.question_type"
           		t-att-name="question.id"
           		/>
           		
                
            </div>
        </div>
    </template>   
    
    


    <!-- A page -->
    <template id="sh_survey_extra_fields_question" inherit_id="survey.question_container" name="Question">
        <xpath expr="//div[1]/t" position="after">
            <t t-if="question.question_type == 'que_sh_color'"><t t-call="sh_survey_all_in_one.tmpl_sh_color" /></t>
            <t t-if="question.question_type == 'que_sh_email'"><t t-call="sh_survey_all_in_one.tmpl_sh_email" /></t>
            <t t-if="question.question_type == 'que_sh_url'"><t t-call="sh_survey_all_in_one.tmpl_sh_url" /></t>
            <t t-if="question.question_type == 'que_sh_time'"><t t-call="sh_survey_all_in_one.tmpl_sh_time" /></t>
            <t t-if="question.question_type == 'que_sh_range'"><t t-call="sh_survey_all_in_one.tmpl_sh_range" /></t>
            <t t-if="question.question_type == 'que_sh_week'"><t t-call="sh_survey_all_in_one.tmpl_sh_week" /></t>
            <t t-if="question.question_type == 'que_sh_month'"><t t-call="sh_survey_all_in_one.tmpl_sh_month" /></t>
            <t t-if="question.question_type == 'que_sh_password'"><t t-call="sh_survey_all_in_one.tmpl_sh_password" /></t>

            <t t-if="question.question_type == 'que_sh_file'"><t t-call="sh_survey_all_in_one.tmpl_sh_file" /></t>

            <t t-if="question.question_type == 'que_sh_signature'"><t t-call="sh_survey_all_in_one.tmpl_sh_signature" /></t>

            <t t-if="question.question_type == 'que_sh_address'"><t t-call="sh_survey_all_in_one.tmpl_sh_address" /></t>

            <t t-if="question.question_type == 'que_sh_many2one'"><t t-call="sh_survey_all_in_one.tmpl_sh_many2one" /></t>
            
            <t t-if="question.question_type == 'que_sh_many2many'"><t t-call="sh_survey_all_in_one.tmpl_sh_many2many" /></t>
            
        </xpath>
    </template>

    <!-- Printable view of a survey (all pages) -->
    <template id="sh_survey_extra_fields_survey_print" inherit_id="survey.survey_page_print" name="Survey">
        <xpath expr="//div[hasclass('js_question-wrapper')]/t" position="after">
            <t t-if="question.question_type == 'que_sh_color'"><t t-call="sh_survey_all_in_one.tmpl_sh_color" /></t>
            <t t-if="question.question_type == 'que_sh_email'"><t t-call="sh_survey_all_in_one.tmpl_sh_email" /></t>
            <t t-if="question.question_type == 'que_sh_url'"><t t-call="sh_survey_all_in_one.tmpl_sh_url" /></t>
            <t t-if="question.question_type == 'que_sh_time'"><t t-call="sh_survey_all_in_one.tmpl_sh_time" /></t>
            <t t-if="question.question_type == 'que_sh_range'"><t t-call="sh_survey_all_in_one.tmpl_sh_range" /></t>
            <t t-if="question.question_type == 'que_sh_week'"><t t-call="sh_survey_all_in_one.tmpl_sh_week" /></t>
            <t t-if="question.question_type == 'que_sh_month'"><t t-call="sh_survey_all_in_one.tmpl_sh_month" /></t>
            <t t-if="question.question_type == 'que_sh_password'"><t t-call="sh_survey_all_in_one.tmpl_sh_password" /></t>

            <t t-if="question.question_type == 'que_sh_file'"><t t-call="sh_survey_all_in_one.tmpl_sh_file_print" /></t>
     
            <t t-if="question.question_type == 'que_sh_signature'"><t t-call="sh_survey_all_in_one.tmpl_sh_signature_review" /></t>


            <t t-if="question.question_type == 'que_sh_address'"><t t-call="sh_survey_all_in_one.tmpl_sh_address_review" /></t>
                 
            <t t-if="question.question_type == 'que_sh_many2one'"><t t-call="survey.question_simple_choice" /></t>
                 
            <t t-if="question.question_type == 'que_sh_many2many'"><t t-call="survey.question_multiple_choice" /></t>
                             
                 
        </xpath>
    </template>
    
    <template id="sh_survey_question_result_choice_inherit" inherit_id="survey.question_result_choice" name="Question: choice result (simple_choice, multiple_choice)">
        <xpath expr="//div[hasclass('survey_graph')]" position="replace">
        		 <div role="tabpanel" class="tab-pane active survey_graph"
                t-att-id="'survey_graph_question_%d' % question.id"
                t-att-data-question_id="question.id" 
                t-att-data-graph-type="'pie' if question.question_type in ( 'simple_choice','que_sh_many2one') else 'bar'"
                t-att-data-graph-data="graph_data">
                <!-- canvas element for drawing bar chart -->
                <canvas/>
            </div>
        </xpath>
     </template>
     
     
     <!-- Many2one/Many2many condition for print page simple choice -->
     <template id='sh_survey_all_in_one_model_condition' inherit_id='survey.question_simple_choice' name='Many2one/Many2many condition single choice'>
     	<xpath expr='//div[hasclass("o_survey_form_choice")]' position='attributes'>
     		<attribute name="t-attf-class" add="row o_survey_form_choice #{'cls_custom_label' if question.question_type == 'que_sh_many2one' or question.question_type == 'que_sh_many2many' else ''}" separator=" "/>
     	</xpath>
     </template>
     
     <!-- Many2one/Many2many condition for print page multi choice -->
     <template id='sh_survey_all_in_one_model_condition_multi' inherit_id='survey.question_multiple_choice' name='Many2one/Many2many condition multi choice'>
     	<xpath expr='//div[hasclass("o_survey_question_multiple_choice")]' position='attributes'>
     		<attribute name="t-attf-class" add="row o_survey_form_choice o_survey_question_multiple_choice #{'cls_custom_label' if question and question.question_type == 'que_sh_many2one' or question and question.question_type == 'que_sh_many2many' else ''}" separator=" "/>
     	</xpath>
     </template>
</odoo>
