Module: FormHelper
- Defined in:
- app/helpers/form_helper.rb
Instance Method Summary collapse
- #html_options(type) ⇒ Object
- #select_tree(field_id, data, field_options, value = nil) ⇒ Object
- #show_tree(data) ⇒ Object
- #text_captcha_entry ⇒ Object
- #text_captcha_qa ⇒ Object
Instance Method Details
#html_options(type) ⇒ Object
83 84 85 86 87 88 89 90 |
# File 'app/helpers/form_helper.rb', line 83 def (type) hash = {} type..split('|').each do |ss| name,value = ss.split('=') hash[name] = value end return hash end |
#select_tree(field_id, data, field_options, value = nil) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'app/helpers/form_helper.rb', line 41 def select_tree(field_id, data, , value = nil) # sample: Test1\BlahA\BlahB\BlahC|Test2\BloopA\BloopB # value: if present, of the form x:y return "no values" unless data a = data.split("|") = [] parent_value = nil child_value = nil parent_value, child_value = value.split(':') if value op = '<script type="text/javascript">' op += "var data_#{field_id} = {" a.each do |parent| first = true parent.split('~').each do |v| v.strip! if first op += " '#{v}' : [" << v first = false else op += '"' + v + '",' end end op += '],' end op += "};" op += "$(document).ready(function() {" op += "$('##{field_id}_parent').bind('change', function() {" op += "select_change_parent('#{field_id}_parent', '#{field_id}', data_#{field_id}, \"#{child_value}\");" op += "});" op += "select_change_parent('#{field_id}_parent', '#{field_id}', data_#{field_id}, \"#{child_value}\");" op += "});" op += "</script>"; op += select_tag("#{field_id}_parent", (, parent_value), ) op += select_tag(field_id, "", {:style=>"margin-left: 20px;"}) return op.html_safe end |
#show_tree(data) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/helpers/form_helper.rb', line 18 def show_tree(data) a = data.split("|") = [] op = "<table class='loosen'>" a.each do |aa| first = true bb = aa.split('~') op += "<tr><td valign='top'>#{bb[0]} →</td><td>" for i in 1..bb.length-1 op += bb[i] op += "<br/>" end op += "</td></tr>" end op += "</table>" op.html_safe end |
#text_captcha_entry ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'app/helpers/form_helper.rb', line 4 def text_captcha_entry question, answers = Form.captcha_question(500) "<div class='q_a'> <input type='hidden' name='q_q' value='#{answers}'/> <label>#{question}</label> <input type='text' name='q_a' value='' class='captcha'> </div>".html_safe end |
#text_captcha_qa ⇒ Object
14 15 16 |
# File 'app/helpers/form_helper.rb', line 14 def text_captcha_qa return Form.captcha_question(500) end |