Class: Fe::Condition

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/fe/condition.rb

Instance Method Summary collapse

Instance Method Details

#evaluate?Boolean

evaluate triggering element against expression and return match|nil

Returns:

  • (Boolean)


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_jsObject

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 = <<-JS
disabled = (response.find(function(answer) {
  answer = toLowerCase(answer);
  return eval("#{escape_javascript(self.expression.downcase)}");
}) == undefined);
  JS

  if toggle_id.nil?
    # toggling a whole page (link), which will affect final page validation
  else
    # toggling an element (form element)... if page is loaded/cached (if not, the server-side will take care of it on load)
    js = js + <<-JS
  if(page_handler.isPageLoaded('page_#{self.toggle_page_id}'))
  {
    $('element_#{self.toggle_id}').disabled = disabled;
  }
    JS
  end

  js
end