added datetime type to survey

This commit is contained in:
Harry Bomrah 2017-03-03 21:00:52 +08:00
parent 18d1e2561f
commit ad241361fe
7 changed files with 31 additions and 7 deletions

View File

@ -31,6 +31,7 @@ function setData(l, length, optionsI, className) {
_title_translations: [id+l+"_title_translations", name+l+"][title_translations]", "questions_title_"+l,{"en":"","zh_tw":""}],
_description_translations: [id+l+"_description_translations", name+l+"][description_translations]", "questions_depiction_"+l,{"en":"","zh_tw":""}],
_type: [id+l+"_type", name+l+"][type]"],
_dateformat : [id+l+"_datetime_type", name+l+"][datetime_type]"],
_is_required: [id+l+"_is_required", name+l+"][is_required]",false],
_option: [id+optionID, name+optionName, "attributes_"+l+"_options_"+optionsI+"_",{"en":"","zh_tw":""}],
_points: [id+pointsID, name+pointsName, "attributes_"+l+"_options_"+optionsI+"_"],
@ -64,6 +65,7 @@ function setEditData(l, length, d, optionsI, className) {
_title_translations: [id+l+"_title_translations", name+l+"][title_translations]", "questions_title_"+l,d.title_translations],
_description_translations: [id+l+"_description_translations", name+l+"][description_translations]", "questions_depiction_"+l,d.description_translations],
_type: [id+l+"_type", name+l+"][type]",d.type],
_dateformat : [id+l+"_datetime_type", name+l+"][datetime_type]",d.datetime_type],
_is_required: [id+l+"_is_required", name+l+"][is_required]",d.is_required],
_option: [id+optionID, name+optionName, "attributes_"+l+"_options_"+optionsI+"_"],
_points: [id+pointsID, name+pointsName, "attributes_"+l+"_options_"+optionsI+"_", d.points],
@ -74,7 +76,6 @@ function setEditData(l, length, d, optionsI, className) {
};
function setEditQuestionAttributes(l, length, d, optionsI, className) {
console.log(d);
if(!optionsI) {
optionsI = 0;
}
@ -123,7 +124,7 @@ function editQuestion (dataArray){
$('#template-survery').tmpl(setEditData(l, $('.questions > .attributes').length + 1, d)).appendTo($('.questions'));
checkQuestionsLength();
textareaResizable(); // from textarea-lang-btn.js
if( d.type > 1 && d.type < 5 ){
if( (d.type > 1 && d.type < 5) || d.type == 6 ){
onQuestionTypeChanged( $(".questions .field-type:eq("+ i +")"), d.type );
$.each(d.survey_question_options,function ( x, data ){
$('#template-survery-option').tmpl(setEditQuestionAttributes( l, "", data, x, "options" )).insertBefore($(".questions .field-type:eq("+ i +") .options .add-btn"));
@ -147,9 +148,13 @@ function editQuestion (dataArray){
function onQuestionTypeChanged ( $fieldType, _val ){
if(_val < 2) {
$fieldType.fadeOut(300);
$fieldType.next(".date-format").fadeOut(300);
}else if(_val == 6){
$fieldType.fadeOut(300);
$fieldType.next(".date-format").fadeIn(300);
} else {
$fieldType.fadeIn(300);
$fieldType.next(".date-format").fadeOut(300);
if(_val < 5) {
$fieldType.find('.rgl, hr').addClass('hide').siblings('.allow').removeClass('hide');
} else {

View File

@ -167,7 +167,7 @@ class SurveysController < ApplicationController
end
individual_total << t
end
when SurveyQuestion::Oneline, SurveyQuestion::Multiline
when SurveyQuestion::Oneline, SurveyQuestion::Multiline, SurveyQuestion::DateTime
@answer_model[qid] = answer[qid]
individual_total << 0
end

View File

@ -6,6 +6,7 @@ class SurveyQuestion
Check = 3
Select = 4
Radiogroup = 5
DateTime = 6
include Mongoid::Document
@ -13,6 +14,7 @@ class SurveyQuestion
field :description, :localize => true
field :is_required, :type => Boolean
field :type, :type => Integer
field :datetime_type
# allow custom answer option
field :custom_option, :type => Boolean

View File

@ -59,6 +59,7 @@
<option value="3" {{if _type[2] == 3}}selected="selected"{{/if}}><%= t('survey_question.check') %></option>
<option value="4" {{if _type[2] == 4}}selected="selected"{{/if}}><%= t('survey_question.select') %></option>
<option value="5" {{if _type[2] == 5}}selected="selected"{{/if}}><%= t('survey_question.radiogroup') %></option>
<option value="6" {{if _type[2] == 6}}selected="selected"{{/if}}><%= t('survey_question.datetime') %></option>
</select>
</div>
</div>
@ -104,7 +105,18 @@
</div>
</div>
</div>
<div class="control-group date-format" style="display:none;">
<label class="control-label muted" for=""><%= t('survey_question.datetimeformat') %> </label>
<div class="controls">
<select id="${_dateformat[0]}" name="${_dateformat[1]}">
<option value="yyyy/MM/dd hh:mm" {{if _dateformat[2] == 'yyyy/MM/dd hh:mm'}}selected="selected"{{/if}}>YYYY/MM/DD HH:MM</option>
<option value="yyyy/MM/dd" {{if _dateformat[2] == 'yyyy/MM/dd'}}selected="selected"{{/if}}>YYYY/MM/DD</option>
<option value="yyyy/MM" {{if _dateformat[2] == 'yyyy/MM'}}selected="selected"{{/if}}>YYYY/MM</option>
<option value="yyyy" {{if _dateformat[2] == 'yyyy'}}selected="selected"{{/if}}>YYYY</option>
</select>
</div>
</div>
<div class="control-group">

View File

@ -1,5 +1,6 @@
<% # encoding: utf-8 %>
<%= javascript_include_tag "lib/bootstrap-datetimepicker" %>
<%= javascript_include_tag "lib/datetimepicker/datetimepicker.js" %>
<%
data = action_data
@survey = data["survey"]
@ -73,6 +74,8 @@
</li>
<% end %>
</ul>
<% when SurveyQuestion::DateTime %>
<%= f.datetime_picker question.id, :no_label => true, :new_record => true, :format => question.datetime_type, :placeholder => question.datetime_type.upcase, :required => question.is_required %>
<% when SurveyQuestion::Check %>
<ul class="o-question-group view-list">
<%= f.fields_for "#{question.id}" do |cf| %>

View File

@ -83,7 +83,8 @@ en:
use_custom_option: Other
add: Add
delete: Delete
datetime: DateTime
datetimeformat: Format
have_not_chart: This type of question havn't chart
move_up: Move up

View File

@ -87,7 +87,8 @@ zh_tw:
use_custom_option: 其他
add: 新增
delete: 刪除
datetime: DateTime
datetimeformat: Format
have_not_chart: 此種類型問題不含結果圖表
move_up: 上移