Module: DoopHelper

Defined in:
app/helpers/doop_helper.rb

Instance Method Summary collapse

Instance Method Details

#change_answer_tooltip(id, &block) ⇒ Object



70
71
72
# File 'app/helpers/doop_helper.rb', line 70

def change_answer_tooltip id, &block
  render( "doop/change_answer_tooltip", :content => block, :id => id )
end

#doop_textfield(name, answer, res, options = {}) ⇒ Object



78
79
80
# File 'app/helpers/doop_helper.rb', line 78

def doop_textfield name, answer, res, options = {}
  s = render "doop/textfield", :answer => answer, :name => name, :res => res, :label => options[:label]
end

#error(res, id) ⇒ Object



36
37
38
# File 'app/helpers/doop_helper.rb', line 36

def error res, id
  render( "doop/error", :msg => res[id] ) if res[id] != nil
end

#info_box(&block) ⇒ Object



3
4
5
# File 'app/helpers/doop_helper.rb', line 3

def info_box &block
  render "doop/info_box", :content => block
end

#list(path_regex, &block) ⇒ Object



40
41
42
43
44
45
46
47
48
49
# File 'app/helpers/doop_helper.rb', line 40

def list path_regex, &block
  doop = request[:doop]
  l = {}
  doop.each_question do |root,path|
    m = path.match( "^#{path_regex}$")
    l[m[1]] = path if m != nil
  end

  l.keys.sort.each { |k| block.call( l[k], k.to_i ) }
end

#question(path, opts = {:title => nil, :indent => false}, &block) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'app/helpers/doop_helper.rb', line 21

def question path, opts = {:title => nil, :indent => false}, &block
  doop = request[:doop]
  root = doop[path]
  s = ""
  if question_visible? path
    s = render( "doop/question", :content => block, :root => root, :path => path, :answer => root["_answer"], :title => opts[:title], :indent => opts[:indent], :id => question_id(path) )
  end
  s
end

#question_form(doop, res, &block) ⇒ Object



15
16
17
18
19
# File 'app/helpers/doop_helper.rb', line 15

def question_form doop, res, &block
  request[:doop] = doop
  s = render( "doop/question_form", :content => block, :res => res, :doop => doop )
  s
end

#question_id(path) ⇒ Object



74
75
76
# File 'app/helpers/doop_helper.rb', line 74

def question_id path
  path.split("/").last
end

#question_visible?(path) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
10
11
12
13
# File 'app/helpers/doop_helper.rb', line 7

def question_visible? path
  doop = request[:doop]
  doop.each_visible_question do |root,p|
    return true if p == path
  end
  false
end

#tooltip(id, &block) ⇒ Object



66
67
68
# File 'app/helpers/doop_helper.rb', line 66

def tooltip id, &block
  render( "doop/tooltip", :content => block, :id => id )
end

#when_answered(path, &block) ⇒ Object



31
32
33
34
# File 'app/helpers/doop_helper.rb', line 31

def when_answered path, &block
  doop = request[:doop]
  block.call if doop.all_nested_answered(path)
end

#when_question(options = {}, &block) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/helpers/doop_helper.rb', line 51

def when_question options = {}, &block
  doop = request[:doop]
  if options.include? :last_answered
    path = options[:last_answered]
    if doop.last_answered == path 
      block.call doop[path]["_answer"], question_id(path)
    end
  elsif options.include? :changed
    path = options[:changed]
    if doop.is_being_changed(path)
      block.call doop[path]["_answer"], question_id(path)
    end
  end
end