Module: Fe::ChoiceFieldConcern
- Extended by:
- ActiveSupport::Concern
- Included in:
- ChoiceField
- Defined in:
- app/models/fe/concerns/choice_field_concern.rb
Instance Method Summary collapse
-
#choices ⇒ Object
Returns choices stored one per line in content field.
-
#default_label? ⇒ Boolean
element view provides the element label?.
- #display_response(app = nil) ⇒ Object
- #has_answer?(choice, app) ⇒ Boolean
-
#ptemplate ⇒ Object
which view to render this element?.
-
#validation_class(answer_sheet) ⇒ Object
css class names for javascript-based validation.
Instance Method Details
#choices ⇒ Object
Returns choices stored one per line in content field
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/models/fe/concerns/choice_field_concern.rb', line 17 def choices retVal = Array.new if ['yes-no', 'acceptance'].include?(self.style) return [["Yes",1],["No",0]] elsif !source.blank? begin doc = XML::Document.file(source) = doc.find(text_xpath).collect { |n| n.content } values = doc.find(value_xpath).collect { |n| n.content } retVal = [, values].transpose rescue NameError doc = REXML::Document.new Net::HTTP.get_response(URI.parse(source)).body retVal = [ doc.elements.collect(text_xpath){|c|c.text}, doc.elements.collect(value_xpath){|c|c.text} ].transpose.sort end elsif !content.nil? content.split("\n").each do |opt| pair = opt.strip.split(";").reverse! pair[1] ||= pair[0] retVal << pair end end return retVal end |
#default_label? ⇒ Boolean
element view provides the element label?
76 77 78 79 80 81 82 |
# File 'app/models/fe/concerns/choice_field_concern.rb', line 76 def default_label? if self.style == 'acceptance' || self.hide_option_labels? false # template provides its own label else true end end |
#display_response(app = nil) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'app/models/fe/concerns/choice_field_concern.rb', line 101 def display_response(app=nil) r = responses(app) r.reject! {|a| a.class == Answer && a.value.blank?} if r.blank? "" elsif self.style == 'yes-no' ans = r.first if ans.class == Answer is_true(ans.value) ? "Yes" : "No" else is_true(ans) ? "Yes" : "No" end elsif self.style == 'acceptance' "Accepted" # if not blank, it's accepted else r.compact.join(", ") end end |
#has_answer?(choice, app) ⇒ Boolean
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/models/fe/concerns/choice_field_concern.rb', line 41 def has_answer?(choice, app) responses(app).each do |r| # loop through Answers # legacy field type choices may be int or tinyint # raise r.inspect + ' - ' + choice.inspect if id == 1137 && r != 1 # r = r.to_s return true if case true when is_true(r) then is_true(choice) when is_false(r) then is_false(choice) else r.to_s == choice.to_s end end false end |
#ptemplate ⇒ Object
which view to render this element?
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'app/models/fe/concerns/choice_field_concern.rb', line 57 def ptemplate if self.style == 'checkbox' 'checkbox_field' elsif self.style == 'drop-down' 'drop_down_field' elsif self.style == 'radio' 'radio_button_field' elsif self.style == 'yes-no' 'yes_no' elsif self.style == 'rating' 'rating' elsif self.style == 'acceptance' 'acceptance' elsif self.style == 'country' 'country' end end |
#validation_class(answer_sheet) ⇒ Object
css class names for javascript-based validation
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'app/models/fe/concerns/choice_field_concern.rb', line 85 def validation_class(answer_sheet) if self.required?(answer_sheet) if self.style == 'drop-down' 'validate-selection required' elsif self.style == 'rating' 'validate-rating required' elsif self.style == 'acceptance' 'required' else 'validate-one-required required' end else '' end end |