diff --git a/app/controllers/admin/surveys_controller.rb b/app/controllers/admin/surveys_controller.rb index 680df17..364c999 100644 --- a/app/controllers/admin/surveys_controller.rb +++ b/app/controllers/admin/surveys_controller.rb @@ -174,6 +174,34 @@ class Admin::SurveysController < OrbitAdminController end + def set_sections + @sections = QuestionnaireSurvey.find(params[:id]).survey_sections + end + + def add_section + @section = SurveySection.new + @survey = QuestionnaireSurvey.find(params[:id]) + end + + def edit_section + @section = SurveySection.find(params[:id]) + @survey = @section.questionnaire_survey + end + + def delete_section + end + + def create_section + section = SurveySection.create(survey_section_params) + redirect_to set_sections_admin_survey_path(section.questionnaire_survey.id) + end + + def update_section + section = SurveySection.find(params[:id]) + section.update_attributes(survey_section_params) + redirect_to set_sections_admin_survey_path(section.questionnaire_survey.id) + end + def jump @questions = @survey.survey_questions.all @@ -258,5 +286,9 @@ class Admin::SurveysController < OrbitAdminController end p end + + def survey_section_params + params.require(:survey_section).permit! + end end \ No newline at end of file diff --git a/app/models/questionnaire_survey.rb b/app/models/questionnaire_survey.rb index b850590..be7e58f 100644 --- a/app/models/questionnaire_survey.rb +++ b/app/models/questionnaire_survey.rb @@ -40,6 +40,7 @@ class QuestionnaireSurvey has_many :survey_questions, :autosave => true, :dependent => :destroy has_many :survey_answers, :dependent => :destroy + has_many :survey_sections, :dependent => :destroy accepts_nested_attributes_for :survey_questions, :allow_destroy => true diff --git a/app/models/survey_section.rb b/app/models/survey_section.rb new file mode 100644 index 0000000..38d39e8 --- /dev/null +++ b/app/models/survey_section.rb @@ -0,0 +1,12 @@ +class SurveySection + include Mongoid::Document + include Mongoid::Timestamps + + field :section_title, localize: true + field :section_description, localize: true + field :order, type: Integer + field :start_question, type: Integer + field :end_question, type: Integer + + belongs_to :questionnaire_survey +end \ No newline at end of file diff --git a/app/views/admin/surveys/_index.html.erb b/app/views/admin/surveys/_index.html.erb index 7cd4742..072d720 100644 --- a/app/views/admin/surveys/_index.html.erb +++ b/app/views/admin/surveys/_index.html.erb @@ -31,6 +31,7 @@
| Section Title | +Section Description | +
|---|---|
|
+ <%= section.section_title %>
+
+
+
+ |
+ <%= section.section_description %> | +