3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'app/helpers/work_flow_helper.rb', line 3
def get_input_html(name, value, write_type=true)
html = ""
javascript = ""
if Array === value
ary = get_input_html(name+[0], value[0])
fname = "add_#{name.join("_")}"
html += "["
html += ary[0]
html += ", "
html += "<span class=\"link\" onclick=\"#{fname}(this);\">add</span>"
html += "]"
if ary[1]
javascript += ary[1]
end
tmp = "tmp#{name.length}"
ary = get_input_html(name+[tmp], value[0], false)
javascript +=<<"EOF"
window.#{fname} = function(elm) {
if (elm.count)
elm.count += 1;
else
elm.count = 1;
new Insertion.Before(elm,'#{ary[0]}, '.gsub('#{tmp}',elm.count));
EOF
if ary[1]
javascript += " eval('#{escape_javascript(ary[1])}'.gsub('#{tmp}',elm.count));\n"
end
javascript += "}\n"
elsif Hash === value
html += '<ul style="margin:0">'
value.each{|k,v|
ary = get_input_html(name+[k], v)
html += "<li>#{k}: "
html += ary[0]
if ary[1]
javascript += ary[1]
end
}
html += '</ul>'
elsif value == "string"
if write_type
html += "(#{value})"
end
html += text_field_tag("apis[api_id][#{name.join("][")}]")
elsif value == "int" || value == "float" || value == "double"
if write_type
html += "(#{value})"
end
html += text_field_tag("apis[api_id][#{name.join("][")}]", nil, :size=>5)
elsif value == "boolean"
html += select_tag("apis[api_id][#{name.join("][")}]", "<option></option><option>true</option><option>false</option>")
elsif
if write_type
html += "(#{value})"
end
html += text_field_tag("apis[api_id][#{name.join("][")}]")
end
return html, javascript=="" ? nil : javascript
end
|