<% # encoding: utf-8 %>

<div id="<%= "survey_question_#{form_survey_question.id}" if !form_survey_question.new_record? %>" class="survey_question_item clear">
  <div id="widget-question" class="widget-box">
    <div class="widget-action clear tip" title="a question">
      <a class="action"><i class="icon-exclamation-sign icon-white"></i></a>
    </div>
    <h3 class="widget-title"><i class="icons-help"></i><%= t('survey.question') %></h3>
    <div class="widget-content">
      <div class="tab-content">
        <% @site_in_use_locales.each_with_index do |locale, i| %>
          
          <div class="<%= locale %> fade tab-pane <%= ( i == 0 ) ? "in active" : '' %>">

            <div class="title">
              <%= f.label :title , t('survey_question.title') %>
              <%= f.fields_for :title_translations do |f| %>
                <%= I18nVariable.from_locale(locale) %>
                <%= f.text_field locale, :style=>"width:98%;", :value => (form_survey_question.title_translations[locale] rescue nil) %>
              <% end %>
            </div>
            
            <div class="description">
              <%= f.label :description ,t('survey_question.description') %>
              <%= f.fields_for :description_translations do |f| %>
                <%= I18nVariable.from_locale(locale) %>
                <%= f.text_area locale, :rows => 5, :style=>"width:98%;", :value => (form_survey_question.description_translations[locale] rescue nil) %>
              <% end %>       
            </div>

          </div>

        <% end %>

        <div class="sequence">
          <%= f.label :sequence , t('survey_question.sequence') %>
          <%= f.text_field :sequence %>
          <a href="#" class="btn btn-mini move-up"><%= t('survey_question.move_up') %></a>
          <a href="#" class="btn btn-mini move-down"><%= t('survey_question.move_down') %></a>
        </div>

        <div class="type">
          <%= f.label :type, t('survey_question.type')%> 
          <%= f.select :type, {
            t('survey_question.oneline') => SurveyQuestion::Oneline, 
            t('survey_question.multiline') => SurveyQuestion::Multiline,
            t('survey_question.radio') => SurveyQuestion::Radio,
            t('survey_question.check') => SurveyQuestion::Check,
            t('survey_question.select') => SurveyQuestion::Select,
            t('survey_question.radiogroup') => SurveyQuestion::Radiogroup
          }, {}, :class => "type-selector input-medium" %>      
        </div>

        <div class="is_required">
          <%= f.label :is_required, t('survey_question.is_required')%> 
          <%= f.check_box :is_required %>    
        </div>

        <div class="survey_question_radiogroups_wrapper hide type-specify type-<%= SurveyQuestion::Radiogroup%>">
          <%= f.label :survey_question_options, t('survey_question.radiogroups_lists')%>
          <table class="table table-condensed">
            <thead>
              <tr>
                <th><%= t('survey_question.radiogroup_label') %></th>
                <th class="span1"></th>
              </tr>
            </thead>
            <tbody>
              <% form_survey_question.survey_question_radiogroups.each_with_index do |survey_question_radiogroup, i| %>
                <%= f.fields_for :survey_question_radiogroups, survey_question_radiogroup do |f| %>
                  <%= render :partial => 'form_survey_question_radiogroup', :object => survey_question_radiogroup, :locals => {:f => f, :i => i} %>
                <% end %>
              <% end %> 
            </tbody>
            <tfoot>
              <tr>
                <td style="text-align:center" colspan="2">
                  <div class="info_input add_survey_question_radiogroup">
                    <%= f.hidden_field :survey_question_radiogroup_field_count, :value => form_survey_question.survey_question_radiogroups.count %>
                    <a class="add"><span class="btn btn-primary btn-small"><i class="icon-plus icon-white"></i> <%= t(:add) %></span></a>
                    <script type="text/template">
                      <%= add_attribute('form_survey_question_radiogroup', f, :survey_question_radiogroups) %>
                    </script>
                  </div>
                </td>
              </tr>
            </tfoot>
          </table>
        </div>

        <div class="survey_question_options_wrapper hide type-specify type-<%= SurveyQuestion::Radio%> type-<%= SurveyQuestion::Check%> type-<%= SurveyQuestion::Select%> type-<%= SurveyQuestion::Radiogroup%>">
          <%= f.label :survey_question_options, t('survey_question.options_lists')%> 
          <table class="table table-condensed">
            <thead>
              <tr>
                <th><%= t('survey_question.option') %></th>
                <th class="span1"></th>
              </tr>
            </thead>
            <tbody>
              <% form_survey_question.survey_question_options.each_with_index do |survey_question_option, i| %>
                <%= f.fields_for :survey_question_options, survey_question_option do |f| %>
                  <%= render :partial => 'form_survey_question_option', :object => survey_question_option, :locals => {:f => f, :i => i} %>
                <% end %>
              <% end %> 
            </tbody>
            <tfoot>
              <tr>
                <td style="text-align:center" colspan="2">
                  <div class="info_input add_survey_question_option">
                    <%= f.hidden_field :survey_question_option_field_count, :value => form_survey_question.survey_question_options.count %>
                    <a class="add"><span class="btn btn-primary btn-small"><i class="icon-plus icon-white"></i> <%= t(:add) %></span></a>
                    <script type="text/template">
                      <%= add_attribute('form_survey_question_option', f, :survey_question_options) %>
                    </script>
                  </div>
                </td>
              </tr>
            </tfoot>
          </table>
          <div class="type-specify type-<%= SurveyQuestion::Radio%> type-<%= SurveyQuestion::Check%> type-<%= SurveyQuestion::Select%> hide-type-<%= SurveyQuestion::Radiogroup%>">
            <%= f.label :custom_option, t('survey_question.custom_option')%> 
            <%= f.check_box :custom_option %>
          </div>
        </div>
      </div>
      <% if form_survey_question.new_record? %>
        <a class="btn delete_question"><i class="icon-remove"></i></a>
      <% else %>  
        <%= f.hidden_field :id %>
        <%= hidden_field_tag :tr, (dom_id form_survey_question) %>
        <a class="btn remove_existing_record_question"><i class="icon-remove"></i></a>
        <%= f.hidden_field :_destroy, :value => nil, :class => 'should_destroy' %>
      <% end %>
    </div>
  </div>
</div>
