/
application_helper.rb
166 lines (149 loc) · 5.56 KB
/
application_helper.rb
1
2
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
62
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
module Forms::ApplicationHelper
def label(object_name,method, text = nil, options = {})
obj = object_name_is(object_name,options)
if options[:short_name]
options.delete(:short_name)
text = obj.classify.constantize.human_attribute_name("#{method}")
else
text = t('tasks.' + obj.to_s.gsub(/trst/,"db") + '.list.' + method.to_s)
end if text.nil? || text.blank?
options.delete(:object)
options["name"] ||= "#{object_name}_#{method}"
options["name"] ||= "#{obj}_#{method}" if object_name.is_a? Object
content_tag(:label, text , options)
end
#TODO text not nil or blank
def th_label_tag(object_name,method, text = nil, options = {})
obj = object_name_is(object_name,options)
case options[:attributes]
when 'label_attribute'
options.delete(:attributes)
text = t('activerecord.attributes.label_attribute')
when 'label_value'
options.delete(:attributes)
text = t('activerecord.attributes.label_value')
else
options[:title] = t('tasks.' + obj.to_s.gsub(/trst/,"db") + '.list.' + method.to_s)
text = obj.classify.constantize.human_attribute_name("#{method}")
end
options.delete(:object)
content_tag(:th, text, options)
end
def td_value_tag(object_name,method, options = {})
obj = object_name_is(object_name,options)
options[:title] = t('tasks.' + obj.to_s.gsub(/trst/,"db") + '.list.' + method.to_s)
content = object_name.send(method)
content_tag(:td, content, options)
end
def td_label_tag(object_name,method, text = nil, options = {})
obj = object_name_is(object_name,options)
options.delete(:object)
options[:title] = t('tasks.' + obj.to_s.gsub(/trst/,"db") + '.list.' + method.to_s)
text = t('tasks.' + obj.to_s.gsub(/trst/,"db") + '.list.' + method.to_s) if text.nil? || text.blank?
content_tag(:td, text, options)
end
def td_text_field(object_name,method, options = {})
options[:value] ||= options[:object].send(method)
options[:id] = "#{object_name}_#{method}"
options[:name] = "#{object_name}[#{method}]"
options.delete(:object)
td_options = options[:td]
options.delete(:td)
"<td #{td_options}>#{tag(:input, options)}</td>"
end
def text_field(object_name,method, options = {})
options[:size] = options["maxlength"] unless options[:size]
options[:type] = "text"
options[:value] ||= options[:object].send(method)
options[:id] = "#{object_name}_#{method}"
options[:name] = "#{object_name}[#{method}]"
options.delete(:object)
tag(:input, options)
end
def hidden_fields(object_name, fields = {})
options = Hash.new
options[:type] = "hidden"
html ="<tr><td colspan='2'>"
fields.each_pair { |key,value|
options[:name] = "#{object_name}[#{key}]"
options[:value] = "#{value}"
html += tag(:input, options)
}
html += "</tr></td>"
end
def link_to_task(object_name,method, options = {})
case method
when :last_column
link_to_task_last_column(object_name)
end
end
def last_row_for(object_name,method, options = {})
case method
when :edit
last_row_for_edit
when :list
options[:colspan] = 10 unless options[:colspan]
last_row_for_list(object_name, options)
when :row20
last_row_for_row20(object_name, options)
end
end
private
def object_name_is(object_name,options)
case object_name
when String, Symbol
ActionController::RecordIdentifier.singular_class_name(options[:object])
when WillPaginate::Collection
ActionController::RecordIdentifier.singular_class_name(object_name[0])
when ActiveRecord::Base
ActionController::RecordIdentifier.singular_class_name(object_name)
else
object_name
end
end
def last_row_for_edit
"<tr>
<td align='center' colspan='2' style ='padding-top:10px'>
<input type='submit' value='#{t('activerecord.attributes.crud.save')}'/>
<input type='button' value='#{t('activerecord.attributes.crud.cancel')}' onclick='Lightview.hide();return false'/>
</td>
</tr>
"
end
def last_row_for_list(object_name, options)
"<tr class='even'>
<td colspan='#{options[:colspan]}' align='center' style='padding-top:10px'>#{trst_paginate(object_name)}</td>
<td style='border-left : 1px ridge #ffffff; width : 50px'>
#{image_tag_for_link("new", {:arg1 => params[:id], :arg2 => "new", :size => "18x18", :style => "padding : 0 0 0 10px; cursor : pointer; vertical-align : middle;" })}
</td>
</tr>
"
end
def last_row_for_row20(object_name, options)
html = ""
if options[:offset].modulo(object_name.per_page) > 0
(object_name.per_page-options[:offset].modulo(object_name.per_page)).times do
html += "<tr class='even'>
<td colspan='#{options[:colspan]}'> </td>
</tr>"
end
end
html
end
def link_to_task_last_column(object_name)
"<td align='center' style='border-left : 1px ridge #ffffff; width : 50px'>
#{image_tag_for_link("edit,show,remove", {:arg1 => params[:id], :arg2 => object_name.id })}
</td>"
end
def image_tag_for_link(src,options ={})
html = ""
src.split(",").each { |s|
options[:alt] = options[:title] = t('activerecord.attributes.crud.' + s)
options[:size] = "13x13" unless options[:size]
options[:style] = "cursor : pointer; vertical-align : middle;" unless options[:style]
options[:onclick] = "TrstWindow.#{s}(#{options.delete(:arg1)}, #{options.delete(:arg2)}); return false;"
html += image_tag("db_#{s}.png", options)
}
html
end
end