survey module initial

This commit is contained in:
Lukas 2013-04-29 16:06:45 +08:00 committed by iCross
parent 30824d1620
commit 51640423a7
28 changed files with 986 additions and 0 deletions

View File

@ -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();
});
});
});

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,7 @@
class SurveyAnswer
include Mongoid::Document
include Mongoid::Timestamps
belongs_to :survey
end

View File

@ -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

View File

@ -0,0 +1,7 @@
class SurveyQuestionOption
include Mongoid::Document
field :name, :localize => true
embedded_in :survey_question
end

View File

@ -0,0 +1,7 @@
class SurveyQuestionRadiogroup
include Mongoid::Document
field :name, :localize => true
embedded_in :survey_question
end

View File

@ -0,0 +1,105 @@
<% # encoding: utf-8 %>
<div id= "poststuff">
<%= f.error_messages %>
<div id="sub-wiget">
<div id="widget-date" class="widget-box widget-size-300">
<div class="widget-action clear tip" title="Set the announcement to start and end dates">
<a href="#" class="action"><i class="icon-exclamation-sign icon-white"></i></a>
</div>
<h3 class="widget-title"><i class="icons-calendar"></i><%= t(:date_) %></h3>
<div class="widget-content clear">
<div class="control-group">
<%= f.datetime_picker :postdate, :picker_type => 'separated', :label => t('survey.postdate') %>
</div>
<div class="control-group">
<%= f.datetime_picker :deadline, :picker_type => 'separated', :label => t('survey.deadline') %>
</div>
</div>
</div>
</div>
<div id="post-body">
<div id="post-body-content" class="clear">
<ul class="nav nav-tabs">
<% @site_valid_locales.each_with_index do |locale, i| %>
<li <%= ( i == 0 ) ? "class=active" : '' %>><a data-toggle="tab" href=".<%= locale %>"><%= I18nVariable.from_locale(locale) %></a></li>
<% end %>
</ul>
<div class="tab-content">
<% @site_valid_locales.each_with_index do |locale, i| %>
<div class="<%= locale %> fade tab-pane <%= ( i == 0 ) ? "in active" : '' %>">
<div class="title">
<%= 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 %>
</div>
<div class="description">
<%= 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 %>
</div>
</div>
<% end %>
</div>
<div class="main-widget">
<div id="survey_questions_wrapper">
<div id='survey_questions' class="survey_questions_block">
<% @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 %>
</div>
<div id='add_survey_question' class="info_input survey_questions_block">
<%= hidden_field_tag 'survey_question_field_count', @survey.survey_questions.count %>
<a class="add"><span class="btn btn-primary btn-small"><i class="icon-plus icon-white"></i> <%= t(:add) %> <%= t('survey.question') %></span></a>
</div>
</div>
</div>
</div>
<div class="form-actions">
<%= 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" %>
</div>
</div>
</div>
<% content_for :page_specific_javascript do %>
<%= javascript_include_tag "survey_form" %>
<script>
$(document).ready(function() {
$('#add_survey_question a.add').live('click', function(){
var new_id = $(this).prev().attr('value');
var old_id = new RegExp("new_survey_questions", "g");
$(this).prev().attr('value', parseInt(new_id) + 1);
$_new = $(("<%= escape_javascript(add_attribute 'form_survey_question', f, :survey_questions) %>").replace(old_id, new_id));
$('#survey_questions').append($_new);
$_new.find('a.delete_question').on('click', function(){
$(this).parents('.survey_question_item').remove();
});
});
});
</script>
<% end %>

View File

@ -0,0 +1,130 @@
<% # encoding: utf-8 %>
<div id="<%= "survey_question_#{form_survey_question.id}" if !form_survey_question.new_record? %>" class="survey_question_item clear">
<div id="widget-question" class="widget-box">
<div class="widget-action clear tip" title="a question">
<a class="action"><i class="icon-exclamation-sign icon-white"></i></a>
</div>
<h3 class="widget-title"><i class="icons-help"></i><%= t('survey.question') %></h3>
<div class="widget-content">
<div class="tab-content">
<% @site_valid_locales.each_with_index do |locale, i| %>
<div class="<%= locale %> fade tab-pane <%= ( i == 0 ) ? "in active" : '' %>">
<div class="title">
<%= 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 %>
</div>
<div class="description">
<%= 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 %>
</div>
</div>
<% end %>
<div class="type">
<%= 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" %>
</div>
<div class="is_required">
<%= f.label :is_required, t('survey_question.is_required')%>
<%= f.check_box :is_required %>
</div>
<div class="survey_question_radiogroups_wrapper hide type-specify type-<%= SurveyQuestion::Radiogroup%>">
<%= f.label :survey_question_options, t('survey_question.radiogroups_lists')%>
<table class="table table-condensed">
<thead>
<tr>
<th><%= t('survey_question.radiogroup_label') %></th>
<th class="span1"></th>
</tr>
</thead>
<tbody>
<% 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 %>
</tbody>
<tfoot>
<tr>
<td style="text-align:center" colspan="2">
<div class="info_input add_survey_question_radiogroup">
<%= f.hidden_field :survey_question_radiogroup_field_count, :value => form_survey_question.survey_question_radiogroups.count %>
<a class="add"><span class="btn btn-primary btn-small"><i class="icon-plus icon-white"></i> <%= t(:add) %></span></a>
<script type="text/template">
<%= add_attribute('form_survey_question_radiogroup', f, :survey_question_radiogroups) %>
</script>
</div>
</td>
</tr>
</tfoot>
</table>
</div>
<div class="survey_question_options_wrapper hide type-specify type-<%= SurveyQuestion::Radio%> type-<%= SurveyQuestion::Check%> type-<%= SurveyQuestion::Select%> type-<%= SurveyQuestion::Radiogroup%>">
<%= f.label :survey_question_options, t('survey_question.options_lists')%>
<table class="table table-condensed">
<thead>
<tr>
<th><%= t('survey_question.option') %></th>
<th class="span1"></th>
</tr>
</thead>
<tbody>
<% 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 %>
</tbody>
<tfoot>
<tr>
<td style="text-align:center" colspan="2">
<div class="info_input add_survey_question_option">
<%= f.hidden_field :survey_question_option_field_count, :value => form_survey_question.survey_question_options.count %>
<a class="add"><span class="btn btn-primary btn-small"><i class="icon-plus icon-white"></i> <%= t(:add) %></span></a>
<script type="text/template">
<%= add_attribute('form_survey_question_option', f, :survey_question_options) %>
</script>
</div>
</td>
</tr>
</tfoot>
</table>
<div class="type-specify hide-type-<%= SurveyQuestion::Radiogroup%>">
<%= f.label :custom_option, t('survey_question.custom_option')%>
<%= f.check_box :custom_option %>
</div>
</div>
</div>
<% if form_survey_question.new_record? %>
<a class="btn delete_question"><i class="icon-remove"></i></a>
<% else %>
<%= f.hidden_field :id %>
<%= hidden_field_tag :tr, (dom_id form_survey_question) %>
<a class="btn remove_existing_record_question"><i class="icon-remove"></i></a>
<%= f.hidden_field :_destroy, :value => nil, :class => 'should_destroy' %>
<% end %>
</div>
</div>
</div>

View File

@ -0,0 +1,26 @@
<tr id="<%= "survey_question_option_#{form_survey_question_option.id}" if !form_survey_question_option.new_record? %>" class='survey_question_option_item'>
<td>
<div class="tab-content">
<% @site_valid_locales.each_with_index do |locale, i| %>
<div class="<%= locale %> fade tab-pane <%= ( i == 0 ) ? "in active" : '' %>">
<%= 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 %>
</div>
<% end %>
</div>
</td>
<td>
<span class="action">
<% if form_survey_question_option.new_record? %>
<a class="delete_option"><i class="icon-remove"></i></a>
<% else %>
<%= f.hidden_field :id %>
<%= hidden_field_tag :tr, (dom_id form_survey_question_option) %>
<a class="remove_existing_record_option"><i class="icon-remove"></i></a>
<%= f.hidden_field :_destroy, :value => nil, :class => 'should_destroy' %>
<% end %>
</span>
</td>
</tr>

View File

@ -0,0 +1,26 @@
<tr id="<%= "survey_question_radiogroup_#{form_survey_question_radiogroup.id}" if !form_survey_question_radiogroup.new_record? %>" class='survey_question_radiogroup_item'>
<td>
<div class="tab-content">
<% @site_valid_locales.each_with_index do |locale, i| %>
<div class="<%= locale %> fade tab-pane <%= ( i == 0 ) ? "in active" : '' %>">
<%= 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 %>
</div>
<% end %>
</div>
</td>
<td>
<span class="action">
<% if form_survey_question_radiogroup.new_record? %>
<a class="delete_radiogroup"><i class="icon-remove"></i></a>
<% else %>
<%= f.hidden_field :id %>
<%= hidden_field_tag :tr, (dom_id form_survey_question_radiogroup) %>
<a class="remove_existing_record_radiogroup"><i class="icon-remove"></i></a>
<%= f.hidden_field :_destroy, :value => nil, :class => 'should_destroy' %>
<% end %>
</span>
</td>
</tr>

View File

@ -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 %>

View File

@ -0,0 +1,30 @@
<tr id="<%= dom_id survey %>" class="with_action">
<td>
<% 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 -%>
</td>
<td>
<%= link_to survey.title, panel_survey_front_end_survey_path(survey) %>
<div class="quick-edit">
<ul class="nav nav-pills hide">
<%if at_least_module_manager %>
<li><%= link_to t('edit'), edit_panel_survey_back_end_survey_path(survey, :page => params[:page]) %></li>
<li><%= link_to t('survey.answers'), panel_survey_back_end_survey_answers_path(survey, :page => params[:page]) %></li>
<li><%= link_to t(:delete_), panel_survey_back_end_survey_path(survey), :confirm => t('sure?'), :method => :delete, :remote => true %></li>
<% end -%>
</ul>
</div>
</td>
<td>
<%= (survey.postdate) ? display_date_time(survey.postdate): t(:no_deadline) %>
</td>
<td>
<%= (survey.deadline) ? display_date_time(survey.deadline): t(:no_deadline) %>
</td>
<td>
<%= survey.survey_answers.count %>
</td>
<td><%= User.from_id(survey.update_user_id).name rescue ''%></td>
</tr>

View File

@ -0,0 +1,21 @@
<tr id="<%= dom_id answer %>" class="with_action">
<td>
<%= check_box_tag 'to_delete[]', answer.id, false, :class => "checkbox_in_list" %>
</td>
<% @survey.survey_questions.each do |question| %>
<td>
<% 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 %>
</td>
<% end %>
<td>
<%= answer.created_at %>
</td>
</tr>

View File

@ -0,0 +1,11 @@
<div id='filter' class="subnav">
<div class="filters accordion-group">
<div id="sort_headers" class="table-label">
<%= render 'sort_headers' %>
</div>
</div>
</div>
<% content_for :page_specific_javascript do %>
<%= javascript_include_tag "sort_header" %>
<% end %>

View File

@ -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 %>

View File

@ -0,0 +1,23 @@
<%= render 'filter' %>
<table class="table main-list">
<thead>
<tr>
<th class="span1"></th>
<% @survey.survey_questions.each do |question| %>
<th class="span1"></th>
<% end %>
<th class="span1"></th>
</tr>
</thead>
<tbody id="tbody_survey_answers" class="sort-holder">
<%= render :partial => 'answer', :collection => @answers %>
</tbody>
</table>
<div class="form-actions form-fixed pagination-right">
<%= link_to t(:back) + t('survey.survey'), panel_survey_back_end_surveys_path, :class => 'btn btn-primary pull-right' %>
<div id="survey_answers_pagination" class="paginationFixed">
<%= paginate @answers %>
</div>
</div>

View File

@ -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 %>");

View File

@ -0,0 +1,4 @@
<script type="text/javascript">
alert("<%= t('survey.answer_error')%>: <%= @survey_answer_error %>");
window.location.href = "<%= panel_survey_front_end_survey_path(@survey, :clicked_field_name => 'title') %>";
</script>

View File

@ -0,0 +1,4 @@
<script type="text/javascript">
alert("<%= t('survey.answer_success')%>");
window.location.href = "<%= panel_survey_front_end_surveys_path %>";
</script>

View File

@ -0,0 +1,87 @@
<% # encoding: utf-8 %>
<h1 class="h1"><%= @survey.title %></h1>
<%= 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 %>
<p><%= question.description %></p>
<% 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| %>
<p>
<%= f.radio_button question.id, option.id %>
<%= f.label "#{question.id}_#{option.id}", option.name, :style => "display:inline" %>
</p>
<% end %>
<% if question.custom_option %>
<p>
<%= 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" %>
</p>
<% end %>
<% when ::SurveyQuestion::Check %>
<%= f.fields_for "#{question.id}" do |cf| %>
<% question.survey_question_options.each do |option| %>
<p>
<%= cf.check_box option.id %>
<%= cf.label option.id, option.name, :style => "display:inline" %>
</p>
<% end %>
<% if question.custom_option %>
<p>
<%= 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" %>
</p>
<% 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| %>
<table>
<thead>
<tr>
<td></td>
<% question.survey_question_radiogroups.each do |radiogroup| %>
<td>
<%= rgf.label radiogroup.id, radiogroup.name %>
</td>
<% end %>
</tr>
</thead>
<tbody>
<% question.survey_question_options.each do |option| %>
<tr>
<td>
<%= rgf.label option.id, option.name %>
</td>
<% question.survey_question_radiogroups.each do |radiogroup| %>
<td>
<%= rgf.radio_button option.id, radiogroup.id %>
</td>
<% end %>
</tr>
<% end %>
</tbody>
</table>
<% end %>
<% end %>
<% end %>
<p>
<%= f.submit t('submit') %>
</p>
<% end %>

View File

@ -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

View File

@ -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: 其他

View File

@ -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

52
vendor/built_in_modules/survey/init.rb vendored Normal file
View File

@ -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

View File

@ -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
}