Class: ActiveadminSelleoCms::FormQuestion
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- ActiveadminSelleoCms::FormQuestion
- Defined in:
- app/models/activeadmin_selleo_cms/form_question.rb
Constant Summary collapse
- TYPE_TEXT =
0
- TYPE_SELECT =
1
- TYPE_FILE =
2
- TYPE_LABEL =
3
- TYPE_EMAIL =
4
- TYPES =
[TYPE_TEXT, TYPE_SELECT, TYPE_FILE, TYPE_LABEL, TYPE_EMAIL]
- TYPE_NAMES =
["text question", "select question", "file upload", "label", "email"]
Instance Attribute Summary collapse
-
#order ⇒ Object
Returns the value of attribute order.
Class Method Summary collapse
Instance Method Summary collapse
- #collection ⇒ Object
- #input_type ⇒ Object
- #is_type?(type) ⇒ Boolean
- #label ⇒ Object
- #set_options_order ⇒ Object
Instance Attribute Details
#order ⇒ Object
Returns the value of attribute order.
18 19 20 |
# File 'app/models/activeadmin_selleo_cms/form_question.rb', line 18 def order @order end |
Class Method Details
.for_select ⇒ Object
26 27 28 |
# File 'app/models/activeadmin_selleo_cms/form_question.rb', line 26 def for_select TYPES.map { |type| [question_type_dictionary(type), type] } end |
.question_type_dictionary(int) ⇒ Object
30 31 32 |
# File 'app/models/activeadmin_selleo_cms/form_question.rb', line 30 def question_type_dictionary(int) TYPE_NAMES[int] end |
Instance Method Details
#collection ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'app/models/activeadmin_selleo_cms/form_question.rb', line 70 def collection if question_type == TYPE_SELECT { collection: .map{ |o| [o.title, o.id, o.] } } else {} end end |
#input_type ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'app/models/activeadmin_selleo_cms/form_question.rb', line 52 def input_type if question_type == TYPE_TEXT and is_multi :text_area_tag elsif question_type == TYPE_TEXT :text_field_tag elsif question_type == TYPE_SELECT and is_multi :check_box_tag elsif question_type == TYPE_SELECT :radio_button_tag elsif question_type == TYPE_FILE :file_field_tag elsif question_type == TYPE_LABEL :legend elsif question_type == TYPE_EMAIL :email_field_tag end end |
#is_type?(type) ⇒ Boolean
36 37 38 |
# File 'app/models/activeadmin_selleo_cms/form_question.rb', line 36 def is_type?(type) "ActiveadminSelleoCms::FormQuestion::TYPE_#{type.upcase}".constantize == question_type end |
#label ⇒ Object
80 81 82 |
# File 'app/models/activeadmin_selleo_cms/form_question.rb', line 80 def label "#{title}#{'<i>'+I18n.t("active_admin.cms.forms.required")+'</i>' if is_required}".html_safe end |
#set_options_order ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/models/activeadmin_selleo_cms/form_question.rb', line 40 def unless order.nil? order.split(",").each_with_index do |temp_id, index| .each do |o| o.update_attribute(:position, index+1) if temp_id == o.temp_id end end order = nil self.save end end |