Class: Qe::Condition
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Qe::Condition
- Defined in:
- app/models/qe/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
16 17 18 19 20 21 |
# File 'app/models/qe/condition.rb', line 16 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”
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/models/qe/condition.rb', line 24 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" |