Archive: ComponentOwl Rails app, DB backups, go redirect script
This commit is contained in:
78
app/helpers/upgrade_helper.rb
Normal file
78
app/helpers/upgrade_helper.rb
Normal file
@@ -0,0 +1,78 @@
|
||||
module UpgradeHelper
|
||||
|
||||
def pro?
|
||||
!params[:pro].nil?
|
||||
end
|
||||
|
||||
class SurveyFormBuilder < ActionView::Helpers::FormBuilder
|
||||
|
||||
def question(text)
|
||||
inc_questions
|
||||
@template.content_tag(:label, text) + @template.hidden_field_tag(tag_name("question"), text)
|
||||
end
|
||||
|
||||
def answer(type, *args)
|
||||
options = args.extract_options!
|
||||
value = options.delete(:value) || ""
|
||||
|
||||
content = []
|
||||
|
||||
case type
|
||||
when :text_field
|
||||
add_default_name_and_id(options)
|
||||
content << @template.text_field_tag(options.delete(:name), value, options)
|
||||
when :text_area
|
||||
add_default_name_and_id(options)
|
||||
content << @template.text_area_tag(options.delete(:name), value, options)
|
||||
when :check_box
|
||||
[args.first].flatten.each do |value|
|
||||
add_default_name_and_id_for_value(value, options)
|
||||
content << [@template.check_box_tag(options.delete(:name), value, false, options), @template.label_tag(options[:id], value)].join(" ")
|
||||
end
|
||||
when :radio_button
|
||||
[args.first].flatten.each do |value|
|
||||
add_default_name_and_id_for_value(value, options)
|
||||
content << [@template.radio_button_tag(options.delete(:name), value, false, options), @template.label_tag(options[:id], value)].join(" ")
|
||||
end
|
||||
when :select, :combo
|
||||
add_default_name_and_id(options)
|
||||
options[:class] = [options[:class], "combo"].compact.join(" ") if type == :combo
|
||||
content << @template.select_tag(options.delete(:name), @template.options_for_select(args.first, options.delete(:selected)), options)
|
||||
when :combo
|
||||
|
||||
end
|
||||
|
||||
content.join("")
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def add_default_name_and_id(options)
|
||||
options[:name] = tag_name("answer", :multiple => true)
|
||||
options[:id] = tag_id("answer")
|
||||
end
|
||||
|
||||
def add_default_name_and_id_for_value(value, options)
|
||||
pretty_tag_value = value.to_s.gsub(/\s/, "_").gsub(/\W/, "").downcase
|
||||
add_default_name_and_id(options)
|
||||
options[:id] += "_#{pretty_tag_value}"
|
||||
end
|
||||
|
||||
def tag_name(type, options = {})
|
||||
"#{@object_name}[survey][#{@questions}][#{type}]" + (options.has_key?(:multiple) ? '[]' : '')
|
||||
end
|
||||
|
||||
def tag_id(type, value = nil)
|
||||
"#{@object_name}_survey_#{@questions}_#{type}"
|
||||
end
|
||||
|
||||
def inc_questions
|
||||
if @questions
|
||||
@questions = @questions + 1
|
||||
else
|
||||
@questions = 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user