Module: WorkFlowHelper

Defined in:
app/helpers/work_flow_helper.rb

Instance Method Summary collapse

Instance Method Details

#get_input_html(name, value, write_type = true) ⇒ Object



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

#get_output_text(value, type, name = "") ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'app/helpers/work_flow_helper.rb', line 63

def get_output_text(value, type, name="")
  if Array === value
    case type
    when "html"
      return "[#{get_output_text(value[0], type)}]"
    when "list"
      ary = Array.new
      3.times{|i|
        ary[i] = get_output_text(value[0], type, name+"[#{i}]")
      }
      return ary.join(",")
    end
  elsif Hash === value
    case type
    when "html"
      return "{#{value.collect{|k,v| k+"=>"+get_output_text(v,type)}.join(", ")}}"
    when "list"
      return value.collect{|k,v| get_output_text(v,type,name+"[#{k}]")}.join(", ")
    end
  else
    case type
    when "html"
      return "(#{value})"
    when "list"
      return "'(#{value})#{name}'"
    end
  end
end