forked from NUBIC/surveyor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "replacing formtastic with simple_form"
This reverts commit 6d7a69b.
- Loading branch information
Mark Yoon
committed
May 12, 2014
1 parent
68407c6
commit d4fe8df
Showing
59 changed files
with
607 additions
and
8,686 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,5 +23,3 @@ when /^4.0/ | |
else | ||
fail "Unsupported Rails version #{ENV['RAILS_VERSION']}" | ||
end | ||
|
||
gem 'simple_form', '3.1.0.rc1' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class QuietInput < Formtastic::Inputs::HiddenInput | ||
def to_html | ||
super | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
class SurveyorCheckBoxesInput < Formtastic::Inputs::CheckBoxesInput | ||
include Surveyor::Helpers::FormtasticCustomInput | ||
def to_html | ||
super | ||
end | ||
def choice_html(choice) | ||
output = "" | ||
output << template.content_tag(:label, | ||
hidden_fields? ? | ||
check_box_with_hidden_input(choice) : | ||
check_box_without_hidden_input(choice) << | ||
choice_label(choice), | ||
label_html_options.merge(:for => choice_input_dom_id(choice), :class => nil) | ||
) | ||
output << builder.text_field(:response_other, input_html_options_with(choice, :response_other)) if options[:response_class] == "other_and_string" | ||
output << builder.text_field(response_class_to_method(options[:response_class]), input_html_options_with(choice, options[:response_class])) if %w(date datetime time float integer string other_and_string).include? options[:response_class] | ||
output << builder.text_area(:text_value, input_html_options_with(choice, :text_value)) if options[:response_class] == "text" | ||
output.html_safe | ||
end | ||
def checked?(value) | ||
selected_values.include?(value.to_s) | ||
end | ||
def disabled?(value) | ||
disabled_values.include?(value) || input_html_options[:disabled] == true | ||
end | ||
def make_selected_values | ||
if object.respond_to?(method) | ||
selected_items = [object.send(method)].compact.flatten.map(&:to_s) | ||
|
||
[*selected_items.map { |o| send_or_call_or_object(value_method, o) }].compact | ||
else | ||
[] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
class SurveyorRadioInput < Formtastic::Inputs::RadioInput | ||
include Surveyor::Helpers::FormtasticCustomInput | ||
def to_html | ||
super | ||
end | ||
def choice_html(choice) | ||
output = "" | ||
output << template.content_tag(:label, | ||
builder.radio_button(input_name, choice_value(choice), input_html_options.merge(choice_html_options(choice)).merge(:required => false)) << | ||
choice_label(choice), | ||
label_html_options.merge(:for => choice_input_dom_id(choice), :class => nil) | ||
) | ||
output << builder.text_field(:response_other, input_html_options_with(choice, :response_other)) if options[:response_class] == "other_and_string" | ||
output << builder.text_field(response_class_to_method(options[:response_class]), input_html_options_with(choice, options[:response_class])) if %w(date datetime time float integer string other_and_string).include? options[:response_class] | ||
output << builder.text_area(:text_value, input_html_options_with(choice, :text_value)) if options[:response_class] == "text" | ||
output.html_safe | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,25 @@ | ||
= surveyor_tag_for a, local_assigns[:tag] do | ||
- r = r_for(@response_set, q, a, local_assigns[:rg]) | ||
= f.simple_fields_for index(q.pick != "one"), r do |ff| # index won't increment for radio buttons | ||
- unless q.pick == "one" # don't repeat identity fields if we're on radio buttons | ||
= ff.input_field :question_id, as: :hidden | ||
= ff.input_field :api_id, as: :hidden | ||
= ff.input_field :response_group, as: :hidden if local_assigns[:rg] | ||
- case q.pick | ||
- when "one", "any" | ||
= ff.input :answer_id, as: answer_as(q, local_assigns[:g]), collection: [[a.text_for(nil, @render_context, I18n.locale), a.id]], label: false, response_class: a.response_class, input_html: {class: a.css_class, disabled: local_assigns[:disabled]} | ||
- when "none" | ||
- if %w(date datetime time float integer string text).include? a.response_class | ||
= ff.input_field :answer_id, as: :hidden, value: a.id | ||
= ff.input rc_to_attr(a.response_class), as: answer_as(a), label: a.text_for(:pre, @render_context, I18n.locale), hint: a.text_for(:post, @render_context, I18n.locale), input_html: {value: r.to_formatted_s.blank? ? a.default_value_for(@render_context, I18n.locale) : r.to_formatted_s, class: "form-control #{a.dom_class}", disabled: local_assigns[:disabled]}.merge(data_attrs(a)) | ||
- else | ||
= a.text_for(nil, @render_context, I18n.locale) | ||
%span.help-block= a.help_text_for(@render_context, I18n.locale) unless g && g.display_type == "grid" | ||
-# TODO: disabled | ||
- rg ||= nil | ||
- r = response_for(@response_set, q, a, rg) | ||
- i = response_idx(q.pick != "one") # argument will be false (don't increment i) if we're on radio buttons | ||
- disabled = defined?(disableFlag) ? disableFlag : false | ||
= f.semantic_fields_for i, r do |ff| | ||
= ff.input :question_id, :as => :quiet unless q.pick == "one" # don't repeat question_id if we're on radio buttons | ||
= ff.input :api_id, :as => :quiet unless q.pick == "one" | ||
= ff.input :response_group, :input_html => {:value => rg}, :as => :quiet if q.pick != "one" && g && g.display_type == "repeater" | ||
- case q.pick | ||
- when "one" | ||
= ff.input :answer_id, :as => :surveyor_radio, :collection => [[a.text_for(nil, @render_context, I18n.locale), a.id]], :label => false, :input_html => {:class => a.css_class, :disabled => disabled}, :response_class => a.response_class | ||
- when "any" | ||
= ff.input :answer_id, :as => :surveyor_check_boxes, :collection => [[a.text_for(nil, @render_context, I18n.locale), a.id]], :label => false, :input_html => {:class => a.css_class, :disabled => disabled}, :response_class => a.response_class | ||
- when "none" | ||
- if %w(date datetime time float integer string text).include? a.response_class | ||
= ff.input :answer_id, :as => :quiet, :input_html => {:class => a.css_class, :value => a.id} | ||
= ff.input rc_to_attr(a.response_class), | ||
:as => rc_to_as(a.response_class), | ||
:label => a.text_for(:pre, @render_context, I18n.locale).blank? ? false : a.text_for(:pre, @render_context, I18n.locale), | ||
:hint => a.text_for(:post, @render_context, I18n.locale), | ||
:input_html => generate_pick_none_input_html(r.to_formatted_s, a.default_value_for(@render_context, I18n.locale), a.css_class, a.response_class, disabled, a.input_mask, a.input_mask_placeholder) | ||
- else | ||
= a.text_for(nil, @render_context, I18n.locale) | ||
%span.help= a.help_text_for(@render_context, I18n.locale) unless g && g.display_type == "grid" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,28 @@ | ||
= surveyor_tag_for q do | ||
%h4= q_text(q, @render_context, I18n.locale) | ||
%span.help-block= q.help_text_for(@render_context, I18n.locale) | ||
- case q.renderer | ||
- when :image, :label, :default_label, :inline_label, :repeater_label | ||
-# no answers | ||
- when :dropdown, :inline_dropdown, :default_dropdown, :slider, :repeater_dropdown | ||
= f.simple_fields_for index, r_for(@response_set, q, nil, local_assigns[:rg]) do |ff| | ||
= ff.input_field :question_id, :as => :hidden | ||
= ff.input_field :api_id, :as => :hidden | ||
= ff.input_field :response_group, :as => :hidden if local_assigns[:rg] | ||
= ff.input :answer_id, :collection => q.answers.map{|a| [a.text, a.id]}, :include_blank => (q.renderer != :slider), :label => q.text, :disabled => local_assigns[:disabled], :input_html => {:class => "form-control"} | ||
- else # :default, :inline, :inline_default | ||
- if q.pick == "one" | ||
= f.simple_fields_for index, r_for(@response_set, q, nil, local_assigns[:rg]) do |ff| | ||
= ff.input_field :question_id, :as => :hidden | ||
= ff.input_field :api_id, :as => :hidden | ||
= ff.input_field :response_group, :as => :hidden if local_assigns[:rg] | ||
- q.answers.each do |a| | ||
- next if (q.pick == "one" or q.pick == "any") and local_assigns[:disabled] and @response_set.responses.where( :question_id => q.id, :answer_id => a.id).empty? | ||
= render a.custom_renderer || '/partials/answer', :q => q, :a => a, :f => f, :rg => local_assigns[:rg], :g => local_assigns[:g], :disabled => local_assigns[:disabled] | ||
-# TODO: js for slider | ||
- rg ||= nil | ||
- renderer = q.renderer(g ||= nil) | ||
- disabled = defined?(disableFlag) ? disableFlag : false | ||
- unless q.display_type == "hidden" | ||
= f.inputs q_text(q, @render_context, I18n.locale), :id => rg ? "q_#{q.id}_#{rg}" : "q_#{q.id}", :class => "q_#{renderer} #{q.css_class(@response_set)}" do | ||
%span.help= q.help_text_for(@render_context, I18n.locale) | ||
- case renderer | ||
- when :image, :label, :default_label, :inline_label, :repeater_label | ||
- when :dropdown, :inline_dropdown, :default_dropdown, :slider, :repeater_dropdown | ||
- r = response_for(@response_set, q, nil, rg) | ||
- i = response_idx | ||
= f.semantic_fields_for i, r do |ff| | ||
= ff.input :question_id, :as => :quiet | ||
= ff.input :response_group, :as => :quiet, :input_html => {:value => rg} if g && g.display_type == "repeater" | ||
= ff.input :api_id, :as => :quiet | ||
= ff.input :answer_id, :as => :select, :collection => q.answers.map{|a| [a.text, a.id]}, :include_blank => (renderer != :slider), :label => q.text, :input_html => { :disabled => disabled } | ||
- else # :default, :inline, :inline_default | ||
- if q.pick == "one" | ||
- r = response_for(@response_set, q, nil, rg) | ||
- i = response_idx # increment the response index since the answer partial skips for q.pick == one | ||
= f.semantic_fields_for i, r do |ff| | ||
= ff.input :question_id, :as => :quiet | ||
= ff.input :response_group, :as => :quiet, :value => rg if g && g.display_type == "repeater" | ||
= ff.input :api_id, :as => :quiet | ||
- q.answers.each do |a| | ||
- next if (q.pick == "one" or q.pick == "any") and disabled and @response_set.responses.where( :question_id => q.id, :answer_id => a.id).empty? | ||
= render a.custom_renderer || '/partials/answer', :q => q, :a => a, :f => f, :rg => rg, :g => g, :disableFlag => disabled |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,44 @@ | ||
= surveyor_tag_for g = q do | ||
%h4= g_text(g, @render_context, I18n.locale) | ||
%span.help-block= g.help_text_for(@render_context, I18n.locale) | ||
- case g.renderer | ||
- when :grid | ||
%table.table | ||
%tbody | ||
- g.questions.each_slice(5) do |five_questions| # header row every 10 | ||
%tr.answers | ||
%th | ||
- five_questions.first.answers.each do |a| | ||
%th.text-center | ||
= a.text_for(nil, @render_context, I18n.locale) | ||
%span.help= a.help_text_for(@render_context, I18n.locale) | ||
%th | ||
- five_questions.each_with_index do |gq, i| | ||
= surveyor_tag_for(gq, :tr) do | ||
%th.pre.text-right | ||
%h4= gq.text_for(:pre, @render_context, I18n.locale) | ||
= gq.help_text_for(@render_context, I18n.locale) | ||
- if gq.pick == "one" | ||
- r = r_for(@response_set, gq) | ||
= f.simple_fields_for index, r do |ff| | ||
= ff.input :question_id, :as => :hidden | ||
= ff.input :api_id, :as => :hidden | ||
- gq.answers.each do |a| | ||
= render(a.custom_renderer || '/partials/answer', g: g, q: gq, a: a, :f => f, tag: :td) unless gq.display_type == "label" | ||
%th.post.text-left | ||
%h4= gq.text_for(:post, @render_context, I18n.locale) | ||
- when :repeater | ||
- (@response_set.count_group_responses(g.questions) + 1).times do |rg| | ||
- g.questions.each do |gq| | ||
- gq.response_group = rg | ||
= render gq.custom_renderer || "/partials/question", :g => g, :rg => rg, :q => gq, :f => f | ||
= submit_tag("+ add row", :name => "section[#{@section.id}][g_#{g.id}]", :class => "add_row btn btn-success") | ||
- else # :inline | ||
- g.questions.each do |gq| | ||
= render gq.custom_renderer || "/partials/question", :g => g, :q => gq, :f => f | ||
- renderer = g.renderer | ||
- unless g.display_type == "hidden" | ||
= f.inputs "#{next_question_number(g)}#{g.text_for(@render_context, I18n.locale)}", :id => "g_#{g.id}", :class => "g_#{renderer} #{g.css_class(@response_set)}" do | ||
%li.help= g.help_text_for(@render_context, I18n.locale) | ||
- case renderer | ||
- when :grid | ||
%li | ||
%table | ||
%col.pre | ||
- qs.first.answers.each do |a| | ||
%col{:class => cycle("odd", "even")} | ||
%col.post | ||
%tbody | ||
- qs.each_slice(10) do |ten_questions| # header row every 10 | ||
%tr | ||
%th | ||
- ten_questions.first.answers.each do |a| | ||
%th | ||
= a.text_for(nil, @render_context, I18n.locale) | ||
%span.help= a.help_text_for(@render_context, I18n.locale) | ||
%th | ||
- ten_questions.each_with_index do |q, i| | ||
%tr{:id => "q_#{q.id}", :class => "q_#{renderer} #{q.css_class(@response_set)}"} | ||
%th | ||
= q.text_for(:pre, @render_context, I18n.locale) | ||
= q.help_text_for(@render_context, I18n.locale) | ||
- if q.pick == "one" | ||
- r = response_for(@response_set, q, nil, g) | ||
- i = response_idx # increment the response index since the answer partial skips for q.pick == one | ||
= f.semantic_fields_for i, r do |ff| | ||
= ff.input :question_id, :as => :quiet | ||
= ff.input :api_id, :as => :quiet | ||
- q.answers.each do |a| | ||
%td= render(a.custom_renderer || '/partials/answer', :g => g, :q => q, :a => a, :f => f) unless q.display_type == "label" | ||
%th= q.text_for(:post, @render_context, I18n.locale) | ||
- when :repeater | ||
- (@response_set.count_group_responses(qs) + 1).times do |rg| | ||
%li | ||
- qs.each do |q| | ||
= render q.custom_renderer || "/partials/question", :g => g, :rg => rg, :q => q, :f => f | ||
= submit_tag("+ add row", :name => "section[#{@section.id}][g_#{g.id}]", :class => "add_row") | ||
- else # :inline | ||
- qs.each do |q| | ||
= render q.custom_renderer || "/partials/question", :g => g, :q => q, :f => f |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,12 @@ | ||
= surveyor_tag_for @section do | ||
%h3.row.title.col-md-12= @section.translation(I18n.locale)[:title] | ||
- @section.questions_and_groups.each_with_index do |q, i| | ||
= render q.custom_renderer || "/partials/#{q.class.name.underscore}", q: q, f: f | ||
= div_for @section, :class => @section.custom_class do | ||
%span.title= @section.translation(I18n.locale)[:title] | ||
- qs ||= [] | ||
- (questions = @section.questions).each_with_index do |q, i| | ||
- if q.part_of_group? | ||
- qs << q # gather up the group questions | ||
- if (i+1 >= questions.size) or (q.question_group_id != questions[i+1].question_group_id) | ||
- # this is the last question of the section, or the group | ||
= render q.question_group.custom_renderer || "/partials/question_group", :g => q.question_group, :qs => qs, :f => f | ||
- qs = [] | ||
- else # gather up the group questions | ||
= render q.custom_renderer || "/partials/question", :q => q, :f => f |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,12 @@ | ||
.surveyor_menu.col-md-4 | ||
.surveyor_menu | ||
- if [email protected]? | ||
= hidden_field_tag "current_section", @section.id | ||
.surveyor_language_selection | ||
%h2= label_tag "locale", t('surveyor.language') | ||
= label_tag "locale", t('surveyor.language') | ||
%select{:id=>"locale", :name=>"new_locale"} | ||
= options_for_select(@survey.translations.map(&:locale),I18n.locale) | ||
|
||
%h2= t('surveyor.sections') | ||
.btn-group-vertical | ||
= t('surveyor.sections') | ||
%ul | ||
- @sections.each do |s| | ||
= menu_button_for(s) | ||
|
||
|
||
%li{:class => ("active" if s == @section)}= menu_button_for(s) |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.