From 515185d87c0a6b99c7185fc0fa339702b2bf3016 Mon Sep 17 00:00:00 2001 From: Lukas Date: Fri, 10 May 2013 17:15:55 +0800 Subject: [PATCH] ques: fix submit --- .../survey/back_end/surveys_controller.rb | 35 +++++++++++++++++-- .../survey/front_end/surveys_controller.rb | 2 +- .../survey/app/models/survey_question.rb | 1 - 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/vendor/built_in_modules/survey/app/controllers/panel/survey/back_end/surveys_controller.rb b/vendor/built_in_modules/survey/app/controllers/panel/survey/back_end/surveys_controller.rb index d0286ab0..72b91e82 100644 --- a/vendor/built_in_modules/survey/app/controllers/panel/survey/back_end/surveys_controller.rb +++ b/vendor/built_in_modules/survey/app/controllers/panel/survey/back_end/surveys_controller.rb @@ -97,7 +97,12 @@ class Panel::Survey::BackEnd::SurveysController < OrbitBackendController @survey.survey_answers.each do |answer| row = [] @survey_questions.each do |question| - row << answer[question.id.to_s] + if question.type == ::SurveyQuestion::Radiogroup + options = Hash[question.survey_question_options.collect{|o| [ o.id.to_s, o.name ] }] + row << Hash[answer[question.id.to_s].map {|o, g| [options[o], g]}] + else + row << answer[question.id.to_s] + end end csv << row end @@ -143,14 +148,38 @@ class Panel::Survey::BackEnd::SurveysController < OrbitBackendController @survey.survey_questions.all.each do |question| new_question = @new_survey.survey_questions.new question.attributes.each do |key, value| - unless ['_id', 'created_at', 'updated_at'].include? key - if @survey.respond_to?(key + '_translations') + unless ['_id', 'survey_id'].include? key + if question.respond_to?(key + '_translations') new_question.send(key + '_translations=', value) else new_question.write_attribute(key, value) end end end + question.survey_question_options.all.each do |option| + new_option = new_question.survey_question_options.new + option.attributes.each do |key, value| + unless ['_id', 'survey_question_id'].include? key + if option.respond_to?(key + '_translations') + new_option.send(key + '_translations=', value) + else + new_option.write_attribute(key, value) + end + end + end + end + question.survey_question_radiogroups.all.each do |radiogroup| + new_radiogroup = new_question.survey_question_radiogroups.new + radiogroup.attributes.each do |key, value| + unless ['_id', 'survey_question_id'].include? key + if radiogroup.respond_to?(key + '_translations') + new_radiogroup.send(key + '_translations=', value) + else + new_radiogroup.write_attribute(key, value) + end + end + end + end end @new_survey.create_user_id = current_user.id diff --git a/vendor/built_in_modules/survey/app/controllers/panel/survey/front_end/surveys_controller.rb b/vendor/built_in_modules/survey/app/controllers/panel/survey/front_end/surveys_controller.rb index 0cf5d848..25e2c9a7 100644 --- a/vendor/built_in_modules/survey/app/controllers/panel/survey/front_end/surveys_controller.rb +++ b/vendor/built_in_modules/survey/app/controllers/panel/survey/front_end/surveys_controller.rb @@ -60,7 +60,7 @@ class Panel::Survey::FrontEnd::SurveysController < OrbitWidgetController if answer[qid] answer[qid].each do |oid, value| unless value.blank? - @answer_model[qid][options[oid]] = radiogroups[value] + @answer_model[qid][oid] = radiogroups[value] else if question.is_required @answer_model.errors.add question.title, t('survey_question.required_error') diff --git a/vendor/built_in_modules/survey/app/models/survey_question.rb b/vendor/built_in_modules/survey/app/models/survey_question.rb index c482a48a..bb0c9004 100644 --- a/vendor/built_in_modules/survey/app/models/survey_question.rb +++ b/vendor/built_in_modules/survey/app/models/survey_question.rb @@ -8,7 +8,6 @@ class SurveyQuestion Radiogroup = 5 include Mongoid::Document - include Mongoid::Timestamps field :title, :localize => true field :description, :localize => true