From ad241361fe3822197ece3f36aadc62712c18ff40 Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Fri, 3 Mar 2017 21:00:52 +0800 Subject: [PATCH] added datetime type to survey --- app/assets/javascripts/survey.js | 11 ++++++++--- app/controllers/surveys_controller.rb | 2 +- app/models/survey_question.rb | 2 ++ app/views/admin/surveys/_questions.html.erb | 12 ++++++++++++ app/views/surveys/show.html.erb | 5 ++++- config/locales/en.yml | 3 ++- config/locales/zh_tw.yml | 3 ++- 7 files changed, 31 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/survey.js b/app/assets/javascripts/survey.js index 5bc2d49..1dfcb6e 100644 --- a/app/assets/javascripts/survey.js +++ b/app/assets/javascripts/survey.js @@ -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 { diff --git a/app/controllers/surveys_controller.rb b/app/controllers/surveys_controller.rb index a8d1efb..0405762 100644 --- a/app/controllers/surveys_controller.rb +++ b/app/controllers/surveys_controller.rb @@ -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 diff --git a/app/models/survey_question.rb b/app/models/survey_question.rb index 99bea01..b1e592f 100644 --- a/app/models/survey_question.rb +++ b/app/models/survey_question.rb @@ -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 diff --git a/app/views/admin/surveys/_questions.html.erb b/app/views/admin/surveys/_questions.html.erb index e15cbf1..581e67f 100644 --- a/app/views/admin/surveys/_questions.html.erb +++ b/app/views/admin/surveys/_questions.html.erb @@ -59,6 +59,7 @@ + @@ -104,7 +105,18 @@ + +
diff --git a/app/views/surveys/show.html.erb b/app/views/surveys/show.html.erb index 65dd450..55a2da1 100644 --- a/app/views/surveys/show.html.erb +++ b/app/views/surveys/show.html.erb @@ -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 @@ <% end %> + <% 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 %>