Skip to content

Commit

Permalink
Revert "replacing formtastic with simple_form"
Browse files Browse the repository at this point in the history
This reverts commit 6d7a69b.
  • Loading branch information
Mark Yoon committed May 12, 2014
1 parent 68407c6 commit d4fe8df
Show file tree
Hide file tree
Showing 59 changed files with 607 additions and 8,686 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ History for Surveyor

* Adding support for Rails 4.0 and removing support for Rails 3.1. Applications requiring Rails 3.1 should use Surveyor v1.4.1
* Removing support for Ruby 1.8.7 and Ruby 1.9.3. Applications requiring Ruby 1.x shoudl use Survyeor v1.4.1
* switching from formtastic to simple_form

### Fixes

Expand Down
2 changes: 0 additions & 2 deletions Gemfile.rails_version
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,3 @@ when /^4.0/
else
fail "Unsupported Rails version #{ENV['RAILS_VERSION']}"
end

gem 'simple_form', '3.1.0.rc1'
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Some key dependencies are:

* HAML
* Sass
* Formtastic

A more exhaustive list can be found in the [gemspec][].

Expand Down Expand Up @@ -101,6 +102,20 @@ and review the [changelog][] for changes that may affect your customizations.
[1]: https://github.com/NUBIC/surveyor/blob/master/lib/surveyor/models/response_set_methods.rb#L94
[2]: https://github.com/NUBIC/surveyor/blob/master/lib/surveyor/models/response_set_methods.rb#L97


## Users of spork

There is [an issue with spork and custom inputs in formatstic (#851)][851]. A workaround (thanks rmm5t!):

Spork.prefork do
# ...
surveyor_path = Gem.loaded_specs['surveyor'].full_gem_path
Dir["#{surveyor_path}/app/inputs/*_input.rb"].each { |f| require File.basename(f) }
# ...
end

[851]: https://github.com/justinfrench/formtastic/issues/851

## Follow master

If you are following pre-release versions of surveyor using a `:git`
Expand Down
21 changes: 0 additions & 21 deletions app/inputs/check_boxes_plus_input.rb

This file was deleted.

5 changes: 5 additions & 0 deletions app/inputs/quiet_input.rb
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
21 changes: 0 additions & 21 deletions app/inputs/radio_buttons_plus_input.rb

This file was deleted.

35 changes: 35 additions & 0 deletions app/inputs/surveyor_check_boxes_input.rb
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
18 changes: 18 additions & 0 deletions app/inputs/surveyor_radio_input.rb
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
42 changes: 25 additions & 17 deletions app/views/partials/_answer.html.haml
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"
49 changes: 28 additions & 21 deletions app/views/partials/_question.html.haml
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
82 changes: 44 additions & 38 deletions app/views/partials/_question_group.html.haml
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 &nbsp;
- 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 &nbsp;
- 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 &nbsp;
- 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 &nbsp;
- 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
16 changes: 12 additions & 4 deletions app/views/partials/_section.html.haml
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
12 changes: 5 additions & 7 deletions app/views/partials/_section_menu.html.haml
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)
5 changes: 0 additions & 5 deletions app/views/partials/_surveyor_flash.html.haml

This file was deleted.

Loading

0 comments on commit d4fe8df

Please sign in to comment.