added custom fields for radio group and added to answer sets. now answer sets can be viewed also for login not required surveys

This commit is contained in:
Harry Bomrah 2016-11-15 19:33:12 +08:00
parent 5c03cf68d0
commit 730d6b896a
7 changed files with 33 additions and 12 deletions

View File

@ -149,10 +149,11 @@ function onQuestionTypeChanged ( $fieldType, _val ){
$fieldType.fadeOut(300); $fieldType.fadeOut(300);
} else { } else {
$fieldType.fadeIn(300); $fieldType.fadeIn(300);
if(_val < 5) { if(_val < 5) {
$fieldType.find('.rgl, hr').addClass('hide').siblings('.allow').removeClass('hide'); $fieldType.find('.rgl, hr').addClass('hide').siblings('.allow').removeClass('hide');
} else { } else {
$fieldType.find('.rgl, hr').removeClass('hide').siblings('.allow').addClass('hide'); $fieldType.find('.rgl, hr').removeClass('hide').siblings('.allow').removeClass('hide');
} }
}; };
} }

View File

@ -159,6 +159,11 @@ class SurveysController < ApplicationController
@answer_model.errors.add question.title, t('survey_question.required_error') @answer_model.errors.add question.title, t('survey_question.required_error')
end end
end end
if question.custom_option
unless answer[oid]["custom_group_field"].blank?
@answer_model[qid]["#{oid}_custom_group_field"] = answer[oid]["custom_group_field"]
end
end
end end
individual_total << t individual_total << t
end end

View File

@ -40,11 +40,12 @@
<td><%= (survey.postdate) ? (format_value survey.postdate) : t(:no_deadline) %></td> <td><%= (survey.postdate) ? (format_value survey.postdate) : t(:no_deadline) %></td>
<td><%= (survey.deadline) ? (format_value survey.deadline) : t(:no_deadline) %></td> <td><%= (survey.deadline) ? (format_value survey.deadline) : t(:no_deadline) %></td>
<td> <td>
<% if survey.needs_login %> <a href="/admin/surveys/<%=survey.id.to_s%>/answer_sets"> <%= survey.survey_answers.count %></a>
<a href="/admin/surveys/<%=survey.id.to_s%>/answer_sets"> <%= survey.survey_answers.count %></a> <%# if survey.needs_login %>
<% else %> <!-- <a href="/admin/surveys/<%=survey.id.to_s%>/answer_sets"> <%#= survey.survey_answers.count %></a> -->
<%= survey.survey_answers.count %> <%# else %>
<% end %> <%#= survey.survey_answers.count %>
<%# end %>
</td> </td>
<td><%= survey.update_user.user_name rescue ''%></td> <td><%= survey.update_user.user_name rescue ''%></td>
</tr> </tr>

View File

@ -69,7 +69,11 @@
<div class="radiogroup"> <div class="radiogroup">
<% sq.survey_question_options.each do |sqo| %> <% sq.survey_question_options.each do |sqo| %>
<% if !@survey_answer[sq.id.to_s].nil? %> <% if !@survey_answer[sq.id.to_s].nil? %>
<%= sqo.name %> : <%= @survey_answer[sq.id.to_s][sqo.id.to_s] %> <br /> <% if sq.custom_option %>
<%= @survey_answer[sq.id.to_s]["#{sqo.id}_custom_group_field"].blank? ? sqo.name : @survey_answer[sq.id.to_s]["#{sqo.id}_custom_group_field"] %> : <%= @survey_answer[sq.id.to_s][sqo.id.to_s] %> <br />
<% else %>
<%= sqo.name %> : <%= @survey_answer[sq.id.to_s][sqo.id.to_s] %> <br />
<% end %>
<% end %> <% end %>
<% end %> <% end %>
</div> </div>

View File

@ -15,9 +15,9 @@
<% if !user.nil? %> <% if !user.nil? %>
<td><%= user.name %></td> <td><%= user.name %></td>
<% else %> <% else %>
<td>&nbsp;</td> <td>NA</td>
<% end %> <% end %>
<td><%= sa.created_at.strftime("%y-%M-%d %h:%m") rescue nil %></td> <td><%= sa.created_at.strftime("%h %d, %Y - %H:%M") rescue nil %></td>
<td><a href="/admin/surveys/<%= sa.id.to_s %>/answer_set"><%= t("survey.view_answers") %></a></td> <td><a href="/admin/surveys/<%= sa.id.to_s %>/answer_set"><%= t("survey.view_answers") %></a></td>
</tr> </tr>
<% end %> <% end %>

View File

@ -106,6 +106,9 @@
<thead> <thead>
<tr> <tr>
<th></th> <th></th>
<% if question.custom_option %>
<th></th>
<% end %>
<% question.survey_question_radiogroups.each do |radiogroup| %> <% question.survey_question_radiogroups.each do |radiogroup| %>
<th> <th>
<%= radiogroup.name %> <%= radiogroup.name %>
@ -119,6 +122,13 @@
<th class="o-question-title"> <th class="o-question-title">
<%= option.name %> <%= option.name %>
</th> </th>
<% if question.custom_option %>
<%= f.fields_for "#{option.id}" do |oid| %>
<td>
<%= oid.text_field "custom_group_field" %>
</td>
<% end %>
<% end %>
<% question.survey_question_radiogroups.each do |radiogroup| %> <% question.survey_question_radiogroups.each do |radiogroup| %>
<td> <td>
<%= rgf.radio_button option.id, radiogroup.id %> <%= rgf.radio_button option.id, radiogroup.id %>
@ -147,8 +157,8 @@
<script type="text/javascript"> <script type="text/javascript">
<% if @survey.jump_mode %> <% if @survey.jump_mode %>
var answers = <%== @answers.to_json %>; var answers = <%= @answers.to_json %>;
var jump_tos_map = <%== @jump_tos_map.to_json %>; var jump_tos_map = <%= @jump_tos_map.to_json %>;
var $current_question = $('.question-item').eq(0); var $current_question = $('.question-item').eq(0);
var current_index = parseInt($current_question.attr('data-index')); var current_index = parseInt($current_question.attr('data-index'));
$current_question.removeClass('hide'); $current_question.removeClass('hide');