Class: Fe::Condition
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Fe::Condition
- Defined in:
- app/models/fe/condition.rb
Instance Method Summary collapse
-
#evaluate? ⇒ Boolean
evaluate triggering element against expression and return match|nil.
-
#trigger_js ⇒ Object
javascript to toggle pages/elements based on the “response”.
Instance Method Details
#evaluate? ⇒ Boolean
evaluate triggering element against expression and return match|nil
19 20 21 22 23 24 |
# File 'app/models/fe/condition.rb', line 19 def evaluate? true # answers = self.trigger.response # answers loaded? # expression = self.expression.downcase # answers.find {|answer| answer = answer.downcase; eval(expression)} end |
#trigger_js ⇒ Object
javascript to toggle pages/elements based on the “response”
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/models/fe/condition.rb', line 27 def trigger_js # will find the first answer (if multiple/checkboxes) where the expression evaluates to true (downcase both to be case insensitive) # if no match, disabled will be true, otherwise false js = "disabled = (response.find(function(answer) {\n answer = toLowerCase(answer);\n return eval(\"\#{escape_javascript(self.expression.downcase)}\");\n}) == undefined);\n JS\n\n if toggle_id.nil?\n # toggling a whole page (link), which will affect final page validation\n else\n # toggling an element (form element)... if page is loaded/cached (if not, the server-side will take care of it on load)\n js = js + <<-JS\n if(page_handler.isPageLoaded('page_\#{self.toggle_page_id}'))\n {\n $('element_\#{self.toggle_id}').disabled = disabled;\n }\n JS\n end\n\n js\nend\n" |