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- TYPES =
[TYPE_TEXT, TYPE_SELECT, TYPE_FILE, TYPE_LABEL]
- TYPE_NAMES =
["text question", "select question", "file upload", "label"]
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.
16 17 18 |
# File 'app/models/activeadmin_selleo_cms/form_question.rb', line 16 def order @order end |
Class Method Details
.for_select ⇒ Object
24 25 26 |
# File 'app/models/activeadmin_selleo_cms/form_question.rb', line 24 def for_select TYPES.map { |type| [question_type_dictionary(type), type] } end |
.question_type_dictionary(int) ⇒ Object
28 29 30 |
# File 'app/models/activeadmin_selleo_cms/form_question.rb', line 28 def question_type_dictionary(int) ["text question", "select question", "file upload", "label"][int] end |
Instance Method Details
#collection ⇒ Object
66 67 68 69 70 71 72 73 74 |
# File 'app/models/activeadmin_selleo_cms/form_question.rb', line 66 def collection if question_type == TYPE_SELECT { collection: .map{ |o| [o.title, o.id, o.] } } else {} end end |
#input_type ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/models/activeadmin_selleo_cms/form_question.rb', line 50 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 end end |
#is_type?(type) ⇒ Boolean
34 35 36 |
# File 'app/models/activeadmin_selleo_cms/form_question.rb', line 34 def is_type?(type) "ActiveadminSelleoCms::FormQuestion::TYPE_#{type.upcase}".constantize == question_type end |
#label ⇒ Object
76 77 78 |
# File 'app/models/activeadmin_selleo_cms/form_question.rb', line 76 def label "#{title}#{'<i>'+I18n.t("active_admin.cms.forms.required")+'</i>' if is_required}".html_safe end |
#set_options_order ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/models/activeadmin_selleo_cms/form_question.rb', line 38 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 |