From 51640423a77e703dd14c861c039b3ea01f8844dc Mon Sep 17 00:00:00 2001 From: Lukas Date: Mon, 29 Apr 2013 16:06:45 +0800 Subject: [PATCH] survey module initial --- app/assets/javascripts/survey_form.js.erb | 56 ++++++++ .../back_end/surveys_answers_controller.rb | 29 ++++ .../survey/back_end/surveys_controller.rb | 86 ++++++++++++ .../survey/front_end/surveys_controller.rb | 78 +++++++++++ .../survey/app/models/survey.rb | 55 ++++++++ .../survey/app/models/survey_answer.rb | 7 + .../survey/app/models/survey_question.rb | 27 ++++ .../app/models/survey_question_option.rb | 7 + .../app/models/survey_question_radiogroup.rb | 7 + .../survey/back_end/surveys/_form.html.erb | 105 ++++++++++++++ .../surveys/_form_survey_question.html.erb | 130 ++++++++++++++++++ .../_form_survey_question_option.html.erb | 26 ++++ .../_form_survey_question_radiogroup.html.erb | 26 ++++ .../back_end/surveys/_sort_headers.html.erb | 6 + .../survey/back_end/surveys/_survey.html.erb | 30 ++++ .../back_end/surveys_answers/_answer.html.erb | 21 +++ .../back_end/surveys_answers/_filter.html.erb | 11 ++ .../surveys_answers/_sort_headers.html.erb | 7 + .../back_end/surveys_answers/index.html.erb | 23 ++++ .../back_end/surveys_answers/index.js.erb | 4 + .../front_end/surveys/answer_error.html.erb | 4 + .../front_end/surveys/answer_success.html.erb | 4 + .../survey/front_end/surveys/show.html.erb | 87 ++++++++++++ .../survey/config/locales/en.yml | 17 +++ .../survey/config/locales/zh_tw.yml | 46 +++++++ .../built_in_modules/survey/config/routes.rb | 23 ++++ vendor/built_in_modules/survey/init.rb | 52 +++++++ vendor/built_in_modules/survey/survey.json | 12 ++ 28 files changed, 986 insertions(+) create mode 100644 app/assets/javascripts/survey_form.js.erb create mode 100644 vendor/built_in_modules/survey/app/controllers/panel/survey/back_end/surveys_answers_controller.rb create mode 100644 vendor/built_in_modules/survey/app/controllers/panel/survey/back_end/surveys_controller.rb create mode 100644 vendor/built_in_modules/survey/app/controllers/panel/survey/front_end/surveys_controller.rb create mode 100644 vendor/built_in_modules/survey/app/models/survey.rb create mode 100644 vendor/built_in_modules/survey/app/models/survey_answer.rb create mode 100644 vendor/built_in_modules/survey/app/models/survey_question.rb create mode 100644 vendor/built_in_modules/survey/app/models/survey_question_option.rb create mode 100644 vendor/built_in_modules/survey/app/models/survey_question_radiogroup.rb create mode 100644 vendor/built_in_modules/survey/app/views/panel/survey/back_end/surveys/_form.html.erb create mode 100644 vendor/built_in_modules/survey/app/views/panel/survey/back_end/surveys/_form_survey_question.html.erb create mode 100644 vendor/built_in_modules/survey/app/views/panel/survey/back_end/surveys/_form_survey_question_option.html.erb create mode 100644 vendor/built_in_modules/survey/app/views/panel/survey/back_end/surveys/_form_survey_question_radiogroup.html.erb create mode 100644 vendor/built_in_modules/survey/app/views/panel/survey/back_end/surveys/_sort_headers.html.erb create mode 100644 vendor/built_in_modules/survey/app/views/panel/survey/back_end/surveys/_survey.html.erb create mode 100644 vendor/built_in_modules/survey/app/views/panel/survey/back_end/surveys_answers/_answer.html.erb create mode 100644 vendor/built_in_modules/survey/app/views/panel/survey/back_end/surveys_answers/_filter.html.erb create mode 100644 vendor/built_in_modules/survey/app/views/panel/survey/back_end/surveys_answers/_sort_headers.html.erb create mode 100644 vendor/built_in_modules/survey/app/views/panel/survey/back_end/surveys_answers/index.html.erb create mode 100644 vendor/built_in_modules/survey/app/views/panel/survey/back_end/surveys_answers/index.js.erb create mode 100644 vendor/built_in_modules/survey/app/views/panel/survey/front_end/surveys/answer_error.html.erb create mode 100644 vendor/built_in_modules/survey/app/views/panel/survey/front_end/surveys/answer_success.html.erb create mode 100644 vendor/built_in_modules/survey/app/views/panel/survey/front_end/surveys/show.html.erb create mode 100644 vendor/built_in_modules/survey/config/locales/en.yml create mode 100644 vendor/built_in_modules/survey/config/locales/zh_tw.yml create mode 100644 vendor/built_in_modules/survey/config/routes.rb create mode 100644 vendor/built_in_modules/survey/init.rb create mode 100644 vendor/built_in_modules/survey/survey.json diff --git a/app/assets/javascripts/survey_form.js.erb b/app/assets/javascripts/survey_form.js.erb new file mode 100644 index 00000000..b187b316 --- /dev/null +++ b/app/assets/javascripts/survey_form.js.erb @@ -0,0 +1,56 @@ +<%#= encoding: utf-8 %> +$(document).ready(function(){ + + $(document).on('click', '.survey_question_item a.remove_existing_record_question', function(){ + if(confirm("<%= I18n.t(:sure?)%>")){ + $(this).next('.should_destroy').val(1); + $(".survey_question_item#" + $(this).prev().attr('value')).hide(); + } + }); + + $(document).on('click', '.survey_question_option_item a.remove_existing_record_option', function(){ + if(confirm("<%= I18n.t(:sure?)%>")){ + $(this).next('.should_destroy').val(1); + $(".survey_question_option_item#" + $(this).prev().attr('value')).hide(); + } + }); + + $(document).on('click', '.survey_question_radiogroup_item a.remove_existing_record_radiogroup', function(){ + if(confirm("<%= I18n.t(:sure?)%>")){ + $(this).next('.should_destroy').val(1); + $(".survey_question_radiogroup_item#" + $(this).prev().attr('value')).hide(); + } + }); + + $('.survey_question_item .type-selector').live('change', function(){ + $item = $(this).parents('.survey_question_item'); + $item.find('.type-specify').hide(); + $item.find('.type-specify.type-' + $(this).val()).show(); + $item.find('.type-specify.hide-type-' + $(this).val()).hide(); + }); + + $('.survey_question_item .type-selector').trigger('change'); + + $('.survey_question_item .add_survey_question_option a.add').live('click', function(){ + var new_id = $(this).prev().attr('value'); + var old_id = new RegExp("new_survey_question_options", "g"); + $(this).prev().attr('value', parseInt(new_id) + 1); + $_new = $($(this).next().html().replace(old_id, new_id)); + $(this).parents('.survey_question_options_wrapper').find('tbody').append($_new); + $_new.find('a.delete_option').on('click', function(){ + $(this).parents('.survey_question_option_item').remove(); + }); + }); + + $('.survey_question_item .add_survey_question_radiogroup a.add').live('click', function(){ + var new_id = $(this).prev().attr('value'); + var old_id = new RegExp("new_survey_question_radiogroups", "g"); + $(this).prev().attr('value', parseInt(new_id) + 1); + $_new = $($(this).next().html().replace(old_id, new_id)); + $(this).parents('.survey_question_radiogroups_wrapper').find('tbody').append($_new); + $_new.find('a.delete_radiogroup').on('click', function(){ + $(this).parents('.survey_question_radiogroup_item').remove(); + }); + }); + +}); \ No newline at end of file diff --git a/vendor/built_in_modules/survey/app/controllers/panel/survey/back_end/surveys_answers_controller.rb b/vendor/built_in_modules/survey/app/controllers/panel/survey/back_end/surveys_answers_controller.rb new file mode 100644 index 00000000..b61a5b5a --- /dev/null +++ b/vendor/built_in_modules/survey/app/controllers/panel/survey/back_end/surveys_answers_controller.rb @@ -0,0 +1,29 @@ +class Panel::Survey::BackEnd::SurveysAnswersController < OrbitBackendController + + include AdminHelper + include OrbitControllerLib::DivisionForDisable + + def initialize + super + @app_title = 'survey_answer' + end + + def index + @survey = ::Survey.find(params[:survey_id]) + @answers = (params[:sort]) ? get_sorted_and_filtered("@survey.survey_answers") : get_viewable("@survey.survey_answers") + respond_to do |format| + format.html # index.html.erb + format.xml { render :xml => @qas } + format.js + end + end + + def delete + @survey = ::Survey.find(params[:survey_id]) + if params[:ids] + answers = @survey.survey_answers.any_in(:_id => params[:ids]).destroy_all + end + redirect_to panel_survey_back_end_survey_answers_url(@survey, :direction => params[:direction], :sort => params[:sort], :sort_options => params[:sort_options]) + end + +end \ No newline at end of file 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 new file mode 100644 index 00000000..de3c1f84 --- /dev/null +++ b/vendor/built_in_modules/survey/app/controllers/panel/survey/back_end/surveys_controller.rb @@ -0,0 +1,86 @@ +class Panel::Survey::BackEnd::SurveysController < OrbitBackendController + + include AdminHelper + include OrbitControllerLib::DivisionForDisable + + def initialize + super + @app_title = 'survey' + end + + def index + @surveys = (params[:sort]) ? get_sorted_and_filtered("survey") : get_viewable("survey") + + respond_to do |format| + format.html # index.html.erb + format.xml { render :xml => @qas } + format.js + end + end + + def new + @survey = ::Survey.new + + respond_to do |format| + format.html # new.html.erb + format.xml { render :xml => @survey } + end + end + + def create + @survey = ::Survey.new(params[:survey]) + + @survey.create_user_id = current_user.id + @survey.update_user_id = current_user.id + + respond_to do |format| + if @survey.save + format.html { redirect_to(panel_survey_back_end_surveys_url) } + format.xml { render :xml => @survey, :status => :created, :location => @survey } + else + format.html { render :action => "new" } + format.xml { render :xml => @survey.errors, :status => :unprocessable_entity } + end + end + end + + def edit + @survey = ::Survey.find(params[:id]) + end + + def update + @survey = ::Survey.find(params[:id]) + + @survey.update_user_id = current_user.id + + respond_to do |format| + if @survey.update_attributes(params[:survey]) + format.html { redirect_to(panel_survey_back_end_surveys_url(:page => params[:page])) } + format.xml { head :ok } + else + format.html { render :action => "edit" } + format.xml { render :xml => @survey.errors, :status => :unprocessable_entity } + end + end + end + + def destroy + @survey = ::Survey.find(params[:id]) + + @survey.destroy + + respond_to do |format| + + format.html { redirect_to(panel_survey_back_end_surveys_url) } + format.js + end + end + + def delete + if params[:ids] + surveys = ::Survey.any_in(:_id => params[:ids]).destroy_all + end + redirect_to panel_survey_back_end_surveys_url(:direction => params[:direction], :sort => params[:sort], :sort_options => params[:sort_options]) + end + +end \ No newline at end of file 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 new file mode 100644 index 00000000..80b03c5b --- /dev/null +++ b/vendor/built_in_modules/survey/app/controllers/panel/survey/front_end/surveys_controller.rb @@ -0,0 +1,78 @@ +class Panel::Survey::FrontEnd::SurveysController < OrbitWidgetController + + def initialize + super + @app_title = 'survey' + end + + def index + + end + + def show + @survey = ::Survey.find params[:id] + end + + def update + @survey = ::Survey.find params[:id] + answer = params[:answer] + + @answer_model = @survey.survey_answers.new + @survey.survey_questions.each do |question| + qid = question.id.to_s + if question.is_required && answer[qid].blank? + @answer_model.errors.add question.title, t('survey_question.required_error') + else + case question.type + when ::SurveyQuestion::Radio, ::SurveyQuestion::Select + if question.custom_option && answer[qid] == 'custom_option' + @answer_model[qid] = answer[qid + '_custom_option'] + else + if answer[qid] + @answer_model[qid] = question.survey_question_options.find(answer[qid]).name + end + end + when ::SurveyQuestion::Check + @answer_model[qid] = [] + if answer[qid] + answer[qid].each do |oid, value| + if value.to_i != 0 + if question.custom_option && oid == 'custom_option' + @answer_model[qid].push answer[qid + '_custom_option'] + else + @answer_model[qid].push question.survey_question_options.find(oid).name + end + end + end + end + when ::SurveyQuestion::Radiogroup + @answer_model[qid] = {} + options = Hash[question.survey_question_options.collect{|o| [ o.id.to_s, o.name ] }] + radiogroups = Hash[question.survey_question_radiogroups.collect{|rg| [ rg.id.to_s, rg.name] }] + if answer[qid] + answer[qid].each do |oid, value| + unless value.blank? + @answer_model[qid][options[oid]] = radiogroups[value] + else + if question.is_required + @answer_model.errors.add question.title, t('survey_question.required_error') + end + end + end + end + when ::SurveyQuestion::Oneline, ::SurveyQuestion::Multiline + @answer_model[qid] = answer[qid] + end + end + end + p @answer_model + if @answer_model.errors.empty? + @answer_model.save! + render :answer_success + else + @survey_answer_error = @answer_model.errors.full_messages.join(',') + render :answer_error + end + end + +end \ No newline at end of file diff --git a/vendor/built_in_modules/survey/app/models/survey.rb b/vendor/built_in_modules/survey/app/models/survey.rb new file mode 100644 index 00000000..3706947c --- /dev/null +++ b/vendor/built_in_modules/survey/app/models/survey.rb @@ -0,0 +1,55 @@ +# encoding: utf-8 + +class Survey + + include Mongoid::Document + include Mongoid::Timestamps + + scope :available_for_lang, ->(locale){ where("available_for_#{locale}".to_sym => true) } + scope :can_display, where(is_hidden: false) + + field :title, :localize => true + field :description, :localize => true + + field :create_user_id + field :update_user_id + + field :postdate, :type => DateTime + field :deadline, :type => DateTime + + field :is_hidden, :type => Boolean, :default => false + + validates :title, :at_least_one => true + + has_many :survey_questions, :autosave => true, :dependent => :destroy + has_many :survey_answers, :dependent => :destroy + + accepts_nested_attributes_for :survey_questions, :allow_destroy => true + + before_save :check_deadline, :update_avliable_language + + def time_range + r = "#{self.postdate.to_date}" + r += "- #{self.deadline.to_date}" if self.deadline + r + end + + protected + + def check_deadline + if(!self.deadline.nil? and (self.deadline < self.postdate )) + self.deadline = nil + end + end + + def update_avliable_language + VALID_LOCALES.each do |locale| + if (title_translations[locale].blank? rescue true) + self["available_for_#{locale}".to_sym] = false + else + self["available_for_#{locale}".to_sym] = true + end + end + end + +end \ No newline at end of file diff --git a/vendor/built_in_modules/survey/app/models/survey_answer.rb b/vendor/built_in_modules/survey/app/models/survey_answer.rb new file mode 100644 index 00000000..94fa2158 --- /dev/null +++ b/vendor/built_in_modules/survey/app/models/survey_answer.rb @@ -0,0 +1,7 @@ +class SurveyAnswer + include Mongoid::Document + include Mongoid::Timestamps + + belongs_to :survey + +end diff --git a/vendor/built_in_modules/survey/app/models/survey_question.rb b/vendor/built_in_modules/survey/app/models/survey_question.rb new file mode 100644 index 00000000..9d1e3155 --- /dev/null +++ b/vendor/built_in_modules/survey/app/models/survey_question.rb @@ -0,0 +1,27 @@ +class SurveyQuestion + + Oneline = 0 + Multiline = 1 + Radio = 2 + Check = 3 + Select = 4 + Radiogroup = 5 + + include Mongoid::Document + include Mongoid::Timestamps + + field :title, :localize => true + field :description, :localize => true + field :is_required, :type => Boolean + field :type, :type => Integer + + # allow custom answer option + field :custom_option, :type => Boolean + + belongs_to :survey + embeds_many :survey_question_options + embeds_many :survey_question_radiogroups + + accepts_nested_attributes_for :survey_question_options, :allow_destroy => true + accepts_nested_attributes_for :survey_question_radiogroups, :allow_destroy => true +end diff --git a/vendor/built_in_modules/survey/app/models/survey_question_option.rb b/vendor/built_in_modules/survey/app/models/survey_question_option.rb new file mode 100644 index 00000000..22dfd0f5 --- /dev/null +++ b/vendor/built_in_modules/survey/app/models/survey_question_option.rb @@ -0,0 +1,7 @@ +class SurveyQuestionOption + include Mongoid::Document + + field :name, :localize => true + + embedded_in :survey_question +end \ No newline at end of file diff --git a/vendor/built_in_modules/survey/app/models/survey_question_radiogroup.rb b/vendor/built_in_modules/survey/app/models/survey_question_radiogroup.rb new file mode 100644 index 00000000..05d4fcf6 --- /dev/null +++ b/vendor/built_in_modules/survey/app/models/survey_question_radiogroup.rb @@ -0,0 +1,7 @@ +class SurveyQuestionRadiogroup + include Mongoid::Document + + field :name, :localize => true + + embedded_in :survey_question +end \ No newline at end of file diff --git a/vendor/built_in_modules/survey/app/views/panel/survey/back_end/surveys/_form.html.erb b/vendor/built_in_modules/survey/app/views/panel/survey/back_end/surveys/_form.html.erb new file mode 100644 index 00000000..0bd483a8 --- /dev/null +++ b/vendor/built_in_modules/survey/app/views/panel/survey/back_end/surveys/_form.html.erb @@ -0,0 +1,105 @@ +<% # encoding: utf-8 %> +
+ + <%= f.error_messages %> + +
+
+
+ +
+

<%= t(:date_) %>

+
+
+ <%= f.datetime_picker :postdate, :picker_type => 'separated', :label => t('survey.postdate') %> +
+
+ <%= f.datetime_picker :deadline, :picker_type => 'separated', :label => t('survey.deadline') %> +
+
+
+
+ +
+
+ +
+ + <% @site_valid_locales.each_with_index do |locale, i| %> + +
"> +
+ <%= f.label :title , t('survey.title') %> + <%= f.fields_for :title_translations do |f| %> + <%= I18nVariable.from_locale(locale) %> + <%= f.text_field locale, :style=>"width:98%;", :class=>'post-title', :value => (@survey.title_translations[locale] rescue nil) %> + <% end %> +
+ +
+ <%= f.label :description ,t('survey.description') %> + <%= f.fields_for :description_translations do |f| %> + <%= I18nVariable.from_locale(locale) %> + <%= f.text_area locale, :rows => 5, :style=>"width:98%;", :value => (@survey.description_translations[locale] rescue nil) %> + <% end %> +
+ +
+ + <% end %> + +
+ +
+
+
+ <% @survey.survey_questions.each_with_index do |survey_question, i| %> + <%= f.fields_for :survey_questions, survey_question do |f| %> + <%= render :partial => 'form_survey_question', :object => survey_question, :locals => {:f => f, :i => i} %> + <% end %> + <% end %> +
+
+ <%= hidden_field_tag 'survey_question_field_count', @survey.survey_questions.count %> + <%= t(:add) %> <%= t('survey.question') %> +
+
+ +
+ +
+ +
+ <%= hidden_field_tag 'page', params[:page] if !params[:page].blank? %> + <%= f.submit t('submit'), :class=>'btn btn-primary' %> + <%= link_to t('cancel'), get_go_back, :class=>"btn" %> +
+ +
+ +
+ + +<% content_for :page_specific_javascript do %> + <%= javascript_include_tag "survey_form" %> + +<% end %> \ No newline at end of file diff --git a/vendor/built_in_modules/survey/app/views/panel/survey/back_end/surveys/_form_survey_question.html.erb b/vendor/built_in_modules/survey/app/views/panel/survey/back_end/surveys/_form_survey_question.html.erb new file mode 100644 index 00000000..4163991e --- /dev/null +++ b/vendor/built_in_modules/survey/app/views/panel/survey/back_end/surveys/_form_survey_question.html.erb @@ -0,0 +1,130 @@ +<% # encoding: utf-8 %> + +
" class="survey_question_item clear"> +
+
+ +
+

<%= t('survey.question') %>

+
+
+ <% @site_valid_locales.each_with_index do |locale, i| %> + +
"> + +
+ <%= f.label :title , t('survey_question.title') %> + <%= f.fields_for :title_translations do |f| %> + <%= I18nVariable.from_locale(locale) %> + <%= f.text_field locale, :style=>"width:98%;", :value => (form_survey_question.title_translations[locale] rescue nil) %> + <% end %> +
+ +
+ <%= f.label :description ,t('survey_question.description') %> + <%= f.fields_for :description_translations do |f| %> + <%= I18nVariable.from_locale(locale) %> + <%= f.text_area locale, :rows => 5, :style=>"width:98%;", :value => (form_survey_question.description_translations[locale] rescue nil) %> + <% end %> +
+ +
+ + <% end %> + +
+ <%= f.label :type, t('survey_question.type')%> + <%= f.select :type, { + t('survey_question.oneline') => SurveyQuestion::Oneline, + t('survey_question.multiline') => SurveyQuestion::Multiline, + t('survey_question.radio') => SurveyQuestion::Radio, + t('survey_question.check') => SurveyQuestion::Check, + t('survey_question.select') => SurveyQuestion::Select, + t('survey_question.radiogroup') => SurveyQuestion::Radiogroup + }, {}, :class => "type-selector input-medium" %> +
+ +
+ <%= f.label :is_required, t('survey_question.is_required')%> + <%= f.check_box :is_required %> +
+ +
+ <%= f.label :survey_question_options, t('survey_question.radiogroups_lists')%> + + + + + + + + + <% form_survey_question.survey_question_radiogroups.each_with_index do |survey_question_radiogroup, i| %> + <%= f.fields_for :survey_question_radiogroups, survey_question_radiogroup do |f| %> + <%= render :partial => 'form_survey_question_radiogroup', :object => survey_question_radiogroup, :locals => {:f => f, :i => i} %> + <% end %> + <% end %> + + + + + + +
<%= t('survey_question.radiogroup_label') %>
+
+ <%= f.hidden_field :survey_question_radiogroup_field_count, :value => form_survey_question.survey_question_radiogroups.count %> + <%= t(:add) %> + +
+
+
+ +
+ <%= f.label :survey_question_options, t('survey_question.options_lists')%> + + + + + + + + + <% form_survey_question.survey_question_options.each_with_index do |survey_question_option, i| %> + <%= f.fields_for :survey_question_options, survey_question_option do |f| %> + <%= render :partial => 'form_survey_question_option', :object => survey_question_option, :locals => {:f => f, :i => i} %> + <% end %> + <% end %> + + + + + + +
<%= t('survey_question.option') %>
+
+ <%= f.hidden_field :survey_question_option_field_count, :value => form_survey_question.survey_question_options.count %> + <%= t(:add) %> + +
+
+
+ <%= f.label :custom_option, t('survey_question.custom_option')%> + <%= f.check_box :custom_option %> +
+
+
+ <% if form_survey_question.new_record? %> + + <% else %> + <%= f.hidden_field :id %> + <%= hidden_field_tag :tr, (dom_id form_survey_question) %> + + <%= f.hidden_field :_destroy, :value => nil, :class => 'should_destroy' %> + <% end %> +
+
+
\ No newline at end of file diff --git a/vendor/built_in_modules/survey/app/views/panel/survey/back_end/surveys/_form_survey_question_option.html.erb b/vendor/built_in_modules/survey/app/views/panel/survey/back_end/surveys/_form_survey_question_option.html.erb new file mode 100644 index 00000000..082767e7 --- /dev/null +++ b/vendor/built_in_modules/survey/app/views/panel/survey/back_end/surveys/_form_survey_question_option.html.erb @@ -0,0 +1,26 @@ +" class='survey_question_option_item'> + +
+ <% @site_valid_locales.each_with_index do |locale, i| %> +
"> + <%= f.fields_for :name_translations do |f| %> + <%= I18nVariable.from_locale(locale) %> + <%= f.text_field locale, :style=>"width:98%;", :value => (form_survey_question_option.name_translations[locale] rescue nil) %> + <% end %> +
+ <% end %> +
+ + + + <% if form_survey_question_option.new_record? %> + + <% else %> + <%= f.hidden_field :id %> + <%= hidden_field_tag :tr, (dom_id form_survey_question_option) %> + + <%= f.hidden_field :_destroy, :value => nil, :class => 'should_destroy' %> + <% end %> + + + \ No newline at end of file diff --git a/vendor/built_in_modules/survey/app/views/panel/survey/back_end/surveys/_form_survey_question_radiogroup.html.erb b/vendor/built_in_modules/survey/app/views/panel/survey/back_end/surveys/_form_survey_question_radiogroup.html.erb new file mode 100644 index 00000000..640e6404 --- /dev/null +++ b/vendor/built_in_modules/survey/app/views/panel/survey/back_end/surveys/_form_survey_question_radiogroup.html.erb @@ -0,0 +1,26 @@ +" class='survey_question_radiogroup_item'> + +
+ <% @site_valid_locales.each_with_index do |locale, i| %> +
"> + <%= f.fields_for :name_translations do |f| %> + <%= I18nVariable.from_locale(locale) %> + <%= f.text_field locale, :style=>"width:98%;", :value => (form_survey_question_radiogroup.name_translations[locale] rescue nil) %> + <% end %> +
+ <% end %> +
+ + + + <% if form_survey_question_radiogroup.new_record? %> + + <% else %> + <%= f.hidden_field :id %> + <%= hidden_field_tag :tr, (dom_id form_survey_question_radiogroup) %> + + <%= f.hidden_field :_destroy, :value => nil, :class => 'should_destroy' %> + <% end %> + + + \ No newline at end of file diff --git a/vendor/built_in_modules/survey/app/views/panel/survey/back_end/surveys/_sort_headers.html.erb b/vendor/built_in_modules/survey/app/views/panel/survey/back_end/surveys/_sort_headers.html.erb new file mode 100644 index 00000000..9b556368 --- /dev/null +++ b/vendor/built_in_modules/survey/app/views/panel/survey/back_end/surveys/_sort_headers.html.erb @@ -0,0 +1,6 @@ +<%= render_sort_bar(true, delete_panel_survey_back_end_surveys_path(:direction => params[:direction], :sort => params[:sort], :sort_options => params[:sort_options]), + ['title', 'title', 'span3', 'survey.title'], + ['postdate', 'postdate','span1', 'survey.postdate'], + ['deadline', 'deadline','span1', 'survey.deadline'], + ['results_count', 'results_count','span1', 'survey.results_count'], + ['update_user', 'update_user','span2', 'survey.update_user']).html_safe %> \ No newline at end of file diff --git a/vendor/built_in_modules/survey/app/views/panel/survey/back_end/surveys/_survey.html.erb b/vendor/built_in_modules/survey/app/views/panel/survey/back_end/surveys/_survey.html.erb new file mode 100644 index 00000000..eeaa50ea --- /dev/null +++ b/vendor/built_in_modules/survey/app/views/panel/survey/back_end/surveys/_survey.html.erb @@ -0,0 +1,30 @@ + + + <% if (survey.create_user_id == current_or_guest_user.id) || is_manager? %> + <%= check_box_tag 'to_delete[]', survey.id, false, :class => "checkbox_in_list" %> + <% end -%> + + + <%= link_to survey.title, panel_survey_front_end_survey_path(survey) %> +
+ +
+ + + <%= (survey.postdate) ? display_date_time(survey.postdate): t(:no_deadline) %> + + + <%= (survey.deadline) ? display_date_time(survey.deadline): t(:no_deadline) %> + + + <%= survey.survey_answers.count %> + + <%= User.from_id(survey.update_user_id).name rescue ''%> + + diff --git a/vendor/built_in_modules/survey/app/views/panel/survey/back_end/surveys_answers/_answer.html.erb b/vendor/built_in_modules/survey/app/views/panel/survey/back_end/surveys_answers/_answer.html.erb new file mode 100644 index 00000000..b70c5db3 --- /dev/null +++ b/vendor/built_in_modules/survey/app/views/panel/survey/back_end/surveys_answers/_answer.html.erb @@ -0,0 +1,21 @@ + + + <%= check_box_tag 'to_delete[]', answer.id, false, :class => "checkbox_in_list" %> + + <% @survey.survey_questions.each do |question| %> + + <% qid = question.id %> + <% case question.type %> + <% when ::SurveyQuestion::Check %> + <%= answer[qid].join(', ') %> + <% when ::SurveyQuestion::Radiogroup %> + <%= answer[qid].map{|key, value| key + ': ' + value}.join('; ') unless answer[qid].blank? %> + <% else %> + <%= answer[qid] %> + <% end %> + + <% end %> + + <%= answer.created_at %> + + \ No newline at end of file diff --git a/vendor/built_in_modules/survey/app/views/panel/survey/back_end/surveys_answers/_filter.html.erb b/vendor/built_in_modules/survey/app/views/panel/survey/back_end/surveys_answers/_filter.html.erb new file mode 100644 index 00000000..0042d5c3 --- /dev/null +++ b/vendor/built_in_modules/survey/app/views/panel/survey/back_end/surveys_answers/_filter.html.erb @@ -0,0 +1,11 @@ + + +<% content_for :page_specific_javascript do %> + <%= javascript_include_tag "sort_header" %> +<% end %> \ No newline at end of file diff --git a/vendor/built_in_modules/survey/app/views/panel/survey/back_end/surveys_answers/_sort_headers.html.erb b/vendor/built_in_modules/survey/app/views/panel/survey/back_end/surveys_answers/_sort_headers.html.erb new file mode 100644 index 00000000..b4cb1477 --- /dev/null +++ b/vendor/built_in_modules/survey/app/views/panel/survey/back_end/surveys_answers/_sort_headers.html.erb @@ -0,0 +1,7 @@ +<% _sort_args = [] %> +<% @survey.survey_questions.each do |question| %> + <% _sort_args.push [question.id.to_s, question.id.to_s, 'span1', question.title] %> +<% end %> +<% _sort_args.push ['created_at', 'created_at','span1', 'created_at'] %> +<%= render_sort_bar(true, delete_panel_survey_back_end_survey_answers_path(@survey, :direction => params[:direction], :sort => params[:sort], :sort_options => params[:sort_options]), + *_sort_args).html_safe %> \ No newline at end of file diff --git a/vendor/built_in_modules/survey/app/views/panel/survey/back_end/surveys_answers/index.html.erb b/vendor/built_in_modules/survey/app/views/panel/survey/back_end/surveys_answers/index.html.erb new file mode 100644 index 00000000..c30d7f60 --- /dev/null +++ b/vendor/built_in_modules/survey/app/views/panel/survey/back_end/surveys_answers/index.html.erb @@ -0,0 +1,23 @@ +<%= render 'filter' %> + + + + + + <% @survey.survey_questions.each do |question| %> + + <% end %> + + + + + <%= render :partial => 'answer', :collection => @answers %> + +
+ +
+ <%= link_to t(:back) + t('survey.survey'), panel_survey_back_end_surveys_path, :class => 'btn btn-primary pull-right' %> +
+ <%= paginate @answers %> +
+
\ No newline at end of file diff --git a/vendor/built_in_modules/survey/app/views/panel/survey/back_end/surveys_answers/index.js.erb b/vendor/built_in_modules/survey/app/views/panel/survey/back_end/surveys_answers/index.js.erb new file mode 100644 index 00000000..c199c634 --- /dev/null +++ b/vendor/built_in_modules/survey/app/views/panel/survey/back_end/surveys_answers/index.js.erb @@ -0,0 +1,4 @@ +$("#delete_all").attr("action", "<%= delete_panel_survey_back_end_survey_answers_path(@survey, :direction => params[:direction], :sort => params[:sort], :filter => @filter, :new_filter => nil, :sort_options => params[:sort_options]) %>"); +$("#sort_headers").html("<%= j render 'sort_headers' %>"); +$("#tbody_survey_answers").html("<%= j render :partial => 'answer', :collection => @answers %>"); +$("#survey_answers_pagination").html("<%= j paginate @answers %>"); \ No newline at end of file diff --git a/vendor/built_in_modules/survey/app/views/panel/survey/front_end/surveys/answer_error.html.erb b/vendor/built_in_modules/survey/app/views/panel/survey/front_end/surveys/answer_error.html.erb new file mode 100644 index 00000000..67e73a44 --- /dev/null +++ b/vendor/built_in_modules/survey/app/views/panel/survey/front_end/surveys/answer_error.html.erb @@ -0,0 +1,4 @@ + \ No newline at end of file diff --git a/vendor/built_in_modules/survey/app/views/panel/survey/front_end/surveys/answer_success.html.erb b/vendor/built_in_modules/survey/app/views/panel/survey/front_end/surveys/answer_success.html.erb new file mode 100644 index 00000000..d5e77ab3 --- /dev/null +++ b/vendor/built_in_modules/survey/app/views/panel/survey/front_end/surveys/answer_success.html.erb @@ -0,0 +1,4 @@ + \ No newline at end of file diff --git a/vendor/built_in_modules/survey/app/views/panel/survey/front_end/surveys/show.html.erb b/vendor/built_in_modules/survey/app/views/panel/survey/front_end/surveys/show.html.erb new file mode 100644 index 00000000..2e4cca6c --- /dev/null +++ b/vendor/built_in_modules/survey/app/views/panel/survey/front_end/surveys/show.html.erb @@ -0,0 +1,87 @@ +<% # encoding: utf-8 %> +

<%= @survey.title %>

+<%= form_for :answer, :method => :put, :url => panel_survey_front_end_survey_path(@survey, :inner => true), :html => {:class => 'clear'} do |f| %> + <% @survey.survey_questions.each do |question| %> + <% label = question.title %> + <% label += ' (' + t('survey_question.required') + ')' if question.is_required %> + <%= f.label question.id, label %> +

<%= question.description %>

+ <% case question.type %> + <% when ::SurveyQuestion::Oneline %> + <%= f.text_field question.id, :required => question.is_required %> + <% when ::SurveyQuestion::Multiline %> + <%= f.text_area question.id, :rows => 5, :required => question.is_required %> + <% when ::SurveyQuestion::Radio %> + <% question.survey_question_options.each do |option| %> +

+ <%= f.radio_button question.id, option.id %> + <%= f.label "#{question.id}_#{option.id}", option.name, :style => "display:inline" %> +

+ <% end %> + <% if question.custom_option %> +

+ <%= f.radio_button question.id, 'custom_option' %> + <%= f.label "#{question.id}_custom_option", t('survey_question.use_custom_option') + ': ', :style => "display:inline" %> + <%= f.text_field "#{question.id}_custom_option" %> +

+ <% end %> + <% when ::SurveyQuestion::Check %> + <%= f.fields_for "#{question.id}" do |cf| %> + <% question.survey_question_options.each do |option| %> +

+ <%= cf.check_box option.id %> + <%= cf.label option.id, option.name, :style => "display:inline" %> +

+ <% end %> + <% if question.custom_option %> +

+ <%= cf.check_box 'custom_option' %> + <%= f.label "#{question.id}_custom_option", t('survey_question.use_custom_option') + ': ', :style => "display:inline" %> + <%= f.text_field "#{question.id}_custom_option" %> +

+ <% end %> + <% end %> + <% when ::SurveyQuestion::Select %> + <% options = question.survey_question_options.collect {|o| [ o.name, o.id ] } %> + <% if question.custom_option %> + <% options.push [t('survey_question.use_custom_option'), 'custom_option'] %> + <% end %> + <%= f.select question.id, options %> + <% if question.custom_option %> + <%= f.text_field "#{question.id}_custom_option" %> + <% end %> + <% when ::SurveyQuestion::Radiogroup %> + <%= f.fields_for "#{question.id}" do |rgf| %> + + + + + <% question.survey_question_radiogroups.each do |radiogroup| %> + + <% end %> + + + + <% question.survey_question_options.each do |option| %> + + + <% question.survey_question_radiogroups.each do |radiogroup| %> + + <% end %> + + <% end %> + +
+ <%= rgf.label radiogroup.id, radiogroup.name %> +
+ <%= rgf.label option.id, option.name %> + + <%= rgf.radio_button option.id, radiogroup.id %> +
+ <% end %> + <% end %> + <% end %> +

+ <%= f.submit t('submit') %> +

+<% end %> \ No newline at end of file diff --git a/vendor/built_in_modules/survey/config/locales/en.yml b/vendor/built_in_modules/survey/config/locales/en.yml new file mode 100644 index 00000000..d2ce8eb7 --- /dev/null +++ b/vendor/built_in_modules/survey/config/locales/en.yml @@ -0,0 +1,17 @@ +en: + + survey: + survey: Survey + title: Title + description: Description + postdate: Start Date + deadline: End Date + no_postdate: No Start Date + no_deadline: No Start Date + results_count: Results Count + update_user: Update User + question: Question + + survey_question: + title: Question + description: Description \ No newline at end of file diff --git a/vendor/built_in_modules/survey/config/locales/zh_tw.yml b/vendor/built_in_modules/survey/config/locales/zh_tw.yml new file mode 100644 index 00000000..f099acb1 --- /dev/null +++ b/vendor/built_in_modules/survey/config/locales/zh_tw.yml @@ -0,0 +1,46 @@ +zh_tw: + + survey: + survey: 問卷調查 + title: 問卷標題 + description: 問卷說明 + postdate: 開始時間 + deadline: 結束時間 + start_deadline: 開始/結束時間 + no_postdate: 沒有開始時間 + no_deadline: 沒有結束時間 + results_count: 回覆數 + update_user: 最後更新者 + question: 問題 + + answer_success: 問卷填寫成功,現在跳回 + answer_error: 問卷填寫錯誤 + + answers: 結果 + + default_widget: + title: 問卷標題 + time_range: 問卷期間 + + frontend: + survey: 問卷調查前台 + + survey_question: + title: 題目 + description: 說明 + type: 作答方式 + is_required: 設為必填 + required: 必填 + required_error: 沒有回答 + oneline: 單行文字 + multiline: 多行文字 + radio: 單選按鈕 + check: 多選方塊 + select: 下拉選單 + radiogroup: 格狀呈現 + options_lists: 選項清單 + radiogroup_label: 橫欄 + radiogroups_lists: 橫欄清單 + option: 選項 + custom_option: 允許自定回答選項 + use_custom_option: 其他 diff --git a/vendor/built_in_modules/survey/config/routes.rb b/vendor/built_in_modules/survey/config/routes.rb new file mode 100644 index 00000000..aeae5f5b --- /dev/null +++ b/vendor/built_in_modules/survey/config/routes.rb @@ -0,0 +1,23 @@ +Rails.application.routes.draw do + + namespace :panel do + namespace :survey do + namespace :back_end do + resources :surveys do + collection do + get 'delete' + end + resources :answers, :controller => :surveys_answers do + collection do + get 'delete' + end + end + end + end + namespace :front_end do + resources :surveys + end + end + end + match "/appfront/*path" => redirect("/panel/*path") +end \ No newline at end of file diff --git a/vendor/built_in_modules/survey/init.rb b/vendor/built_in_modules/survey/init.rb new file mode 100644 index 00000000..f1c3deb7 --- /dev/null +++ b/vendor/built_in_modules/survey/init.rb @@ -0,0 +1,52 @@ +module Faq + OrbitApp.registration "Survey",:type=> 'ModuleApp' do + module_label 'survey.survey' + base_url File.expand_path File.dirname(__FILE__) + # personal_plugin :enable => true,:path=>"panel/faq/plugin/profile",:i18n=>'admin.faq' + + version "0.1" + organization "Rulingcom" + author "RD dep" + intro "I am intro" + update_info 'some update_info' + + front_end do + app_page 'survey' do + frontend_i18n "survey.frontend.survey" + end + end + + data_count 1..20 + + widgets do + default_widget do + enable ["typeA"] + query 'Survey.any_of( {deadline: nil,:postdate.lte => Time.now} , {:deadline.gte => Time.now, :postdate.lte => Time.now} )' + link_field :title,{:method => 'panel_survey_front_end_survey_path',:args=>:self} + field :time_range + link_to_more 'panel_survey_front_end_survey_path',:title_i18n=> 'faq.default_widget.to_more' + end + end + + + side_bar do + head_label_i18n 'survey.survey',:icon_class=>"icons-pie" + available_for [:admin,:manager,:sub_manager] + active_for_controllers ({:private=>['surveys', 'surveys_answers']}) + + head_link_path "panel_survey_back_end_surveys_path" + + context_link 'list_', + :link_path=>"panel_survey_back_end_surveys_path" , + :priority=>1, + :active_for_action=>{:surveys=>:index}, + :available_for => [:all] + + context_link 'add', + :link_path=>"new_panel_survey_back_end_survey_path" , + :priority=>2, + :active_for_action=>{:surveys=>:new}, + :available_for => [:sub_manager] + end + end +end diff --git a/vendor/built_in_modules/survey/survey.json b/vendor/built_in_modules/survey/survey.json new file mode 100644 index 00000000..92faea8e --- /dev/null +++ b/vendor/built_in_modules/survey/survey.json @@ -0,0 +1,12 @@ +{ + "title": "survey", + "version": "0.1", + "organization": "Rulingcom", + "author": "RD dep", + "intro": "survey", + "update_info": "Some info", + "create_date": "04-18-2013", + "widgets": ["index"], + "category": [], + "enable_frontend": true +}