hbl_tags 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.DS_Store +0 -0
- data/.gitattributes +2 -0
- data/.gitignore +62 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +8 -0
- data/LICENSE +339 -0
- data/README.md +2 -0
- data/Rakefile +4 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/hbl_tags-0.0.1.gem +0 -0
- data/hbl_tags-0.0.2.gem +0 -0
- data/hbl_tags-0.0.3.gem +0 -0
- data/hbl_tags.gemspec +45 -0
- data/lib/.DS_Store +0 -0
- data/lib/hbl_tags/tags_helper.rb +685 -0
- data/lib/hbl_tags/version.rb +25 -0
- data/lib/hbl_tags.rb +24 -0
- metadata +80 -0
|
@@ -0,0 +1,685 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# encoding: utf-8
|
|
3
|
+
#
|
|
4
|
+
# hbl_tags provides methods to create complex html tags
|
|
5
|
+
#
|
|
6
|
+
# Copyright © 2021 Stephan Wenzel <stephan.wenzel@drwpatent.de>
|
|
7
|
+
#
|
|
8
|
+
# This program is free software; you can redistribute it and/or
|
|
9
|
+
# modify it under the terms of the GNU General Public License
|
|
10
|
+
# as published by the Free Software Foundation; either version 2
|
|
11
|
+
# of the License, or (at your option) any later version.
|
|
12
|
+
#
|
|
13
|
+
# This program is distributed in the hope that it will be useful,
|
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16
|
+
# GNU General Public License for more details.
|
|
17
|
+
#
|
|
18
|
+
# You should have received a copy of the GNU General Public License
|
|
19
|
+
# along with this program; if not, write to the Free Software
|
|
20
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
21
|
+
#
|
|
22
|
+
module HBLTags
|
|
23
|
+
module TagsHelper
|
|
24
|
+
|
|
25
|
+
#---------------------------------------------------------------------------------------
|
|
26
|
+
# creates a check box field
|
|
27
|
+
#
|
|
28
|
+
def hbl_check_box( f, model, field, editable, options = {} )
|
|
29
|
+
check_box_options = options.deep_dup
|
|
30
|
+
if @bulk && !check_box_options[:nobulk]; return hbl_boolean_select(f, model, field, editable, check_box_options ); end
|
|
31
|
+
check_box_options[:class] = check_box_options[:class].to_s << " checked_box" if options[:mimic_checked]
|
|
32
|
+
check_box_options[:label] = label_text(model, field)
|
|
33
|
+
check_box_options[:disabled] ||= !editable
|
|
34
|
+
if check_box_options.delete(:boolean)
|
|
35
|
+
checked = "true"; unchecked = "false"
|
|
36
|
+
else
|
|
37
|
+
checked = 1; unchecked = 0
|
|
38
|
+
end
|
|
39
|
+
content_tag(:div, :class => ("flash error" if !model.errors[field].empty? ) ) do
|
|
40
|
+
content_tag(:p ) do
|
|
41
|
+
f.check_box( field, check_box_options.compact, checked, unchecked ) +
|
|
42
|
+
content_tag(:a, :href =>'#', :class => 'icon icon-help', :title => l(:label_help), :onclick => "$('##{help_tag_id(model, field)}').toggle(); return false;" ) do
|
|
43
|
+
l(:label_help)
|
|
44
|
+
end +
|
|
45
|
+
tag(:br ) +
|
|
46
|
+
content_tag(:span, :id => "#{help_tag_id(model, field)}", :class => "info", :style => "display:none;" ) do
|
|
47
|
+
content_tag(:em, :class => "info") do
|
|
48
|
+
help_text(model, field)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end #def
|
|
54
|
+
|
|
55
|
+
#---------------------------------------------------------------------------------------
|
|
56
|
+
# creates a boolean select field
|
|
57
|
+
#
|
|
58
|
+
def hbl_boolean_select(f, model, field, editable, options = {}, html_options={} )
|
|
59
|
+
hbl_select_field( f, model, field, boolean_values_options(options), options, html_options)
|
|
60
|
+
end #def
|
|
61
|
+
|
|
62
|
+
def boolean_values_options(options)
|
|
63
|
+
if @bulk && !options[:nobulk]
|
|
64
|
+
[ [l(:label_no_change_option),"none"],
|
|
65
|
+
[l(:label_none), nil],
|
|
66
|
+
[l(:general_text_Yes), 1],
|
|
67
|
+
[l(:general_text_No), 0] ]
|
|
68
|
+
else
|
|
69
|
+
[ [],
|
|
70
|
+
[l(:general_text_Yes), 1],
|
|
71
|
+
[l(:general_text_No), 0] ]
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
#---------------------------------------------------------------------------------------
|
|
76
|
+
# creates a file select field
|
|
77
|
+
#
|
|
78
|
+
def hbl_file_field( f, model, field, editable, options = {} )
|
|
79
|
+
file_field_options = options.deep_dup
|
|
80
|
+
file_field_options[:label] = label_text(model, field)
|
|
81
|
+
file_field_options[:disabled] ||= !editable
|
|
82
|
+
content_tag(:div, :class => ("flash error" if !model.errors[field].empty? ) ) do
|
|
83
|
+
content_tag(:p ) do
|
|
84
|
+
f.file_field( field, file_field_options.compact ) +
|
|
85
|
+
content_tag(:a, :href =>'#', :class => 'icon icon-help', :title => l(:label_help), :onclick => "$('##{help_tag_id(model, field)}').toggle(); return false;" ) do
|
|
86
|
+
l(:label_help)
|
|
87
|
+
end +
|
|
88
|
+
tag(:br ) +
|
|
89
|
+
content_tag(:span, :id => "#{help_tag_id(model, field)}", :class => "info", :style => "display:none;" ) do
|
|
90
|
+
content_tag(:em, :class => "info") do
|
|
91
|
+
help_text(model, field)
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end #def
|
|
97
|
+
|
|
98
|
+
#---------------------------------------------------------------------------------------
|
|
99
|
+
# creates a text field
|
|
100
|
+
#
|
|
101
|
+
def hbl_text_field( f, model, field, editable, options = {} )
|
|
102
|
+
text_field_options = options.deep_dup
|
|
103
|
+
text_field_options[:label] = label_text(model, field)
|
|
104
|
+
text_field_options[:placeholder] = placeholder(field, model, options)
|
|
105
|
+
text_field_options[:size] ||= 32
|
|
106
|
+
text_field_options[:disabled] ||= !editable
|
|
107
|
+
content_tag(:div, :class => ("flash error" if !model.errors[field].empty? ) ) do
|
|
108
|
+
content_tag(:p ) do
|
|
109
|
+
f.text_field( field, text_field_options.compact ) +
|
|
110
|
+
if @bulk && !text_field_options[:nobulk]
|
|
111
|
+
name = model.class.name.underscore
|
|
112
|
+
check_box_tag( "#{name}[#{field}]", "none", (model.send(field) == 'none'), :id => nil, :disabled => !editable, :class => 'inline', :data => {:disables => "##{name}_#{field}"} ) + tag(:span, :class=>"icon icon-del")
|
|
113
|
+
end.to_s +
|
|
114
|
+
content_tag(:a, :href =>'#', :class => 'icon icon-help', :title => l(:label_help), :onclick => "$('##{help_tag_id(model, field)}').toggle(); return false;" ) do
|
|
115
|
+
l(:label_help)
|
|
116
|
+
end +
|
|
117
|
+
tag(:br ) +
|
|
118
|
+
content_tag(:span, :id => "#{help_tag_id(model, field)}", :class => "info", :style => "display:none;" ) do
|
|
119
|
+
content_tag(:em, :class => "info") do
|
|
120
|
+
help_text(model, field)
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
end #def
|
|
126
|
+
|
|
127
|
+
#---------------------------------------------------------------------------------------
|
|
128
|
+
# creates a password field
|
|
129
|
+
#
|
|
130
|
+
def hbl_password_field( f, model, field, editable, options = {} )
|
|
131
|
+
text_field_options = options.deep_dup
|
|
132
|
+
text_field_options[:label] = label_text(model, field)
|
|
133
|
+
text_field_options[:value] = model.send(field.to_sym) unless text_field_options[:novalue]
|
|
134
|
+
text_field_options[:placeholder] = placeholder(field, model, options)
|
|
135
|
+
text_field_options[:size] ||= 32
|
|
136
|
+
text_field_options[:disabled] ||= !editable
|
|
137
|
+
content_tag(:div, :class => ("flash error" if !model.errors[field].empty? ) ) do
|
|
138
|
+
content_tag(:p ) do
|
|
139
|
+
f.password_field( field, text_field_options.compact ) +
|
|
140
|
+
if @bulk && !text_field_options[:nobulk]
|
|
141
|
+
name = model.class.name.underscore
|
|
142
|
+
check_box_tag( "#{name}[#{field}]", "none", (model.send(field) == 'none'), :id => nil, :disabled => !editable, :class => 'inline', :data => {:disables => "##{name}_#{field}"} ) + tag(:span, :class=>"icon icon-del")
|
|
143
|
+
end.to_s +
|
|
144
|
+
content_tag(:a, :href =>'#', :class => 'icon icon-help', :title => l(:label_help), :onclick => "$('##{help_tag_id(model, field)}').toggle(); return false;" ) do
|
|
145
|
+
l(:label_help)
|
|
146
|
+
end +
|
|
147
|
+
tag(:br ) +
|
|
148
|
+
content_tag(:span, :id => "#{help_tag_id(model, field)}", :class => "info", :style => "display:none;" ) do
|
|
149
|
+
content_tag(:em, :class => "info") do
|
|
150
|
+
help_text(model, field)
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
end #def
|
|
156
|
+
|
|
157
|
+
#---------------------------------------------------------------------------------------
|
|
158
|
+
# creates a date field
|
|
159
|
+
#
|
|
160
|
+
def hbl_date_field( f, model, field, editable, options = {} )
|
|
161
|
+
date_field_options = options.deep_dup
|
|
162
|
+
date_field_options[:label] = label_text(model, field)
|
|
163
|
+
date_field_options[:placeholder] = placeholder(field, model, options)
|
|
164
|
+
date_field_options[:size] ||= 32
|
|
165
|
+
date_field_options[:disabled] ||= !editable
|
|
166
|
+
content_tag(:div, :class => ("flash error" if !model.errors[field].empty? ) ) do
|
|
167
|
+
content_tag(:p ) do
|
|
168
|
+
f.date_field( field, date_field_options.compact ) +
|
|
169
|
+
if @bulk && !date_field_options[:nobulk]
|
|
170
|
+
name = model.class.name.underscore
|
|
171
|
+
check_box_tag( "#{name}[#{field}]", "none", (model.send(field) == 'none'), :id => nil, :disabled => !editable, :class => 'inline', :data => {:disables => "##{name}_#{field}"} ) + tag(:span, :class=>"icon icon-del")
|
|
172
|
+
end.to_s +
|
|
173
|
+
content_tag(:a, :href =>'#', :class => 'icon icon-help', :title => l(:label_help), :onclick => "$('##{help_tag_id(model, field)}').toggle(); return false;" ) do
|
|
174
|
+
l(:label_help)
|
|
175
|
+
end +
|
|
176
|
+
tag(:br ) +
|
|
177
|
+
content_tag(:span, :id => "#{help_tag_id(model, field)}", :class => "info", :style => "display:none;" ) do
|
|
178
|
+
content_tag(:em, :class => "info") do
|
|
179
|
+
help_text(model, field)
|
|
180
|
+
end
|
|
181
|
+
end
|
|
182
|
+
end
|
|
183
|
+
end
|
|
184
|
+
end #def
|
|
185
|
+
|
|
186
|
+
#---------------------------------------------------------------------------------------
|
|
187
|
+
# creates an email address field
|
|
188
|
+
#
|
|
189
|
+
def hbl_email_field( f, model, field, editable, options = {} )
|
|
190
|
+
date_field_options = options.deep_dup
|
|
191
|
+
date_field_options[:label] = label_text(model, field)
|
|
192
|
+
date_field_options[:placeholder] = placeholder(field, model, options)
|
|
193
|
+
date_field_options[:size] ||= 32
|
|
194
|
+
date_field_options[:disabled] ||= !editable
|
|
195
|
+
content_tag(:div, :class => ("flash error" if !model.errors[field].empty? ) ) do
|
|
196
|
+
content_tag(:p ) do
|
|
197
|
+
f.email_field( field, date_field_options.compact ) +
|
|
198
|
+
if @bulk && !date_field_options[:nobulk]
|
|
199
|
+
name = model.class.name.underscore
|
|
200
|
+
check_box_tag( "#{name}[#{field}]", "none", (model.send(field) == 'none'), :id => nil, :disabled => !editable, :class => 'inline', :data => {:disables => "##{name}_#{field}"} ) + tag(:span, :class=>"icon icon-del")
|
|
201
|
+
end.to_s +
|
|
202
|
+
content_tag(:a, :href =>'#', :class => 'icon icon-help', :title => l(:label_help), :onclick => "$('##{help_tag_id(model, field)}').toggle(); return false;" ) do
|
|
203
|
+
l(:label_help)
|
|
204
|
+
end +
|
|
205
|
+
tag(:br ) +
|
|
206
|
+
content_tag(:span, :id => "#{help_tag_id(model, field)}", :class => "info", :style => "display:none;" ) do
|
|
207
|
+
content_tag(:em, :class => "info") do
|
|
208
|
+
help_text(model, field)
|
|
209
|
+
end
|
|
210
|
+
end
|
|
211
|
+
end
|
|
212
|
+
end
|
|
213
|
+
end #def
|
|
214
|
+
|
|
215
|
+
#---------------------------------------------------------------------------------------
|
|
216
|
+
# creates a telephone numer field
|
|
217
|
+
#
|
|
218
|
+
def hbl_telephone_field( f, model, field, editable, options = {} )
|
|
219
|
+
field_options = options.deep_dup
|
|
220
|
+
field_options[:label] = label_text(model, field)
|
|
221
|
+
field_options[:placeholder] = placeholder(field, model, options)
|
|
222
|
+
field_options[:size] ||= 32
|
|
223
|
+
field_options[:disabled] ||= !editable
|
|
224
|
+
content_tag(:div, :class => ("flash error" if !model.errors[field].empty? ) ) do
|
|
225
|
+
content_tag(:p ) do
|
|
226
|
+
f.telephone_field( field, field_options.compact ) +
|
|
227
|
+
if @bulk && !field_options[:nobulk]
|
|
228
|
+
name = model.class.name.underscore
|
|
229
|
+
check_box_tag( "#{name}[#{field}]", "none", (model.send(field) == 'none'), :id => nil, :disabled => !editable, :class => 'inline', :data => {:disables => "##{name}_#{field}"} ) + tag(:span, :class=>"icon icon-del")
|
|
230
|
+
end.to_s +
|
|
231
|
+
content_tag(:a, :href =>'#', :class => 'icon icon-help', :title => l(:label_help), :onclick => "$('##{help_tag_id(model, field)}').toggle(); return false;" ) do
|
|
232
|
+
l(:label_help)
|
|
233
|
+
end +
|
|
234
|
+
tag(:br ) +
|
|
235
|
+
content_tag(:span, :id => "#{help_tag_id(model, field)}", :class => "info", :style => "display:none;" ) do
|
|
236
|
+
content_tag(:em, :class => "info") do
|
|
237
|
+
help_text(model, field)
|
|
238
|
+
end
|
|
239
|
+
end
|
|
240
|
+
end
|
|
241
|
+
end
|
|
242
|
+
end #def
|
|
243
|
+
|
|
244
|
+
#---------------------------------------------------------------------------------------
|
|
245
|
+
# creates a date time field
|
|
246
|
+
#
|
|
247
|
+
def hbl_datetime_field( f, model, field, editable, options = {} )
|
|
248
|
+
date_field_options = options.deep_dup
|
|
249
|
+
date_field_options[:label] = label_text(model, field)
|
|
250
|
+
date_field_options[:placeholder] = placeholder(field, model, options)
|
|
251
|
+
date_field_options[:size] ||= 32
|
|
252
|
+
date_field_options[:disabled] ||= !editable
|
|
253
|
+
content_tag(:div, :class => ("flash error" if !model.errors[field].empty? ) ) do
|
|
254
|
+
content_tag(:p ) do
|
|
255
|
+
f.datetime_field( field, date_field_options.compact ) +
|
|
256
|
+
if @bulk && !text_field_options[:nobulk]
|
|
257
|
+
name = model.class.name.underscore
|
|
258
|
+
check_box_tag( "#{name}[#{field}]", "none", (model.send(field) == 'none'), :id => nil, :disabled => !editable, :class => 'inline', :data => {:disables => "##{name}_#{field}"} ) + tag(:span, :class=>"icon icon-del")
|
|
259
|
+
end.to_s +
|
|
260
|
+
content_tag(:a, :href =>'#', :class => 'icon icon-help', :title => l(:label_help), :onclick => "$('##{help_tag_id(model, field)}').toggle(); return false;" ) do
|
|
261
|
+
l(:label_help)
|
|
262
|
+
end +
|
|
263
|
+
tag(:br ) +
|
|
264
|
+
content_tag(:span, :id => "#{help_tag_id(model, field)}", :class => "info", :style => "display:none;" ) do
|
|
265
|
+
content_tag(:em, :class => "info") do
|
|
266
|
+
help_text(model, field)
|
|
267
|
+
end
|
|
268
|
+
end
|
|
269
|
+
end
|
|
270
|
+
end
|
|
271
|
+
end #def
|
|
272
|
+
|
|
273
|
+
#---------------------------------------------------------------------------------------
|
|
274
|
+
# creates a text area
|
|
275
|
+
#
|
|
276
|
+
def hbl_text_area_field( f, model, field, editable, options = {} )
|
|
277
|
+
text_area_options = options.deep_dup
|
|
278
|
+
text_area_options[:label] = label_text(model, field)
|
|
279
|
+
text_area_options[:placeholder] = placeholder(field, model, options)
|
|
280
|
+
text_area_options[:rows] ||= 4
|
|
281
|
+
text_area_options[:cols] ||= 29
|
|
282
|
+
text_area_options[:disabled] ||= !editable
|
|
283
|
+
content_tag(:div, :class => ("flash error" if !model.errors[field].empty? ) ) do
|
|
284
|
+
content_tag(:p ) do
|
|
285
|
+
f.text_area( field, text_area_options.compact ) +
|
|
286
|
+
if @bulk && !text_area_options[:nobulk]
|
|
287
|
+
name = model.class.name.underscore
|
|
288
|
+
check_box_tag( "#{name}[#{field}]", "none", (model.send(field) == 'none'), :id => nil, :disabled => !editable, :class => 'inline', :data => {:disables => "##{name}_#{field}"} ) + tag(:span, :class=>"icon icon-del")
|
|
289
|
+
end.to_s +
|
|
290
|
+
content_tag(:a, :href =>'#', :class => 'icon icon-help', :title => l(:label_help), :onclick => "$('##{help_tag_id(model, field)}').toggle(); return false;" ) do
|
|
291
|
+
l(:label_help)
|
|
292
|
+
end +
|
|
293
|
+
tag(:br ) +
|
|
294
|
+
content_tag(:span, :id => "#{help_tag_id(model, field)}", :class => "info", :style => "display:none;" ) do
|
|
295
|
+
content_tag(:em, :class => "info") do
|
|
296
|
+
help_text(model, field)
|
|
297
|
+
end
|
|
298
|
+
end
|
|
299
|
+
end
|
|
300
|
+
end
|
|
301
|
+
end #def
|
|
302
|
+
|
|
303
|
+
#---------------------------------------------------------------------------------------
|
|
304
|
+
# creates a select drop down menu
|
|
305
|
+
#
|
|
306
|
+
def hbl_select_field( f, model, field, values, options={}, html_options={})
|
|
307
|
+
select_field_options = options.deep_dup
|
|
308
|
+
select_field_options[:label] = label_text(model, field)
|
|
309
|
+
select_field_options[:disabled] ||= !options[:editable]
|
|
310
|
+
|
|
311
|
+
if @bulk && !select_field_options[:nobulk]
|
|
312
|
+
pvalue = placeholder(field, model, options)
|
|
313
|
+
option_label = values.map{|l,v| l if v == pvalue }.compact.first
|
|
314
|
+
values.unshift([(l(:label_no_change_option) + " #{option_label}").html_safe, ''])
|
|
315
|
+
end
|
|
316
|
+
|
|
317
|
+
content_tag(:div, :class => ("flash error" if !model.errors[field].empty? ) ) do
|
|
318
|
+
content_tag(:p ) do
|
|
319
|
+
f.select( field, values, select_field_options.compact, html_options ) +
|
|
320
|
+
content_tag(:a, :href =>'#', :class => 'icon icon-help', :title => l(:label_help), :onclick => "$('##{help_tag_id(model, field)}').toggle(); return false;" ) do
|
|
321
|
+
l(:label_help)
|
|
322
|
+
end +
|
|
323
|
+
tag(:br ) +
|
|
324
|
+
content_tag(:span, :id => "#{help_tag_id(model, field)}", :class => "info", :style => "display:none;" ) do
|
|
325
|
+
content_tag(:em, :class => "info") do
|
|
326
|
+
help_text(model, field)
|
|
327
|
+
end
|
|
328
|
+
end
|
|
329
|
+
end
|
|
330
|
+
end
|
|
331
|
+
end #def
|
|
332
|
+
|
|
333
|
+
#---------------------------------------------------------------------------------------
|
|
334
|
+
# creates a country select drop down menu
|
|
335
|
+
#
|
|
336
|
+
def hbl_country_select_field( f, model, field, values, options={}, html_options={})
|
|
337
|
+
country_field_options = options.deep_dup
|
|
338
|
+
country_field_options[:label] ||= label_text(model, field)
|
|
339
|
+
#country_field_options[:disabled] ||= !editable
|
|
340
|
+
content_tag(:div, :class => ("flash error" if !model.errors[field].empty? ) ) do
|
|
341
|
+
content_tag(:p ) do
|
|
342
|
+
content_tag(:label, country_field_options[:label]) +
|
|
343
|
+
f.country_select( field, values, country_field_options.compact, html_options ) +
|
|
344
|
+
content_tag(:a, :href =>'#', :class => 'icon icon-help', :title => l(:label_help), :onclick => "$('##{help_tag_id(model, field)}').toggle(); return false;" ) do
|
|
345
|
+
l(:label_help)
|
|
346
|
+
end +
|
|
347
|
+
tag(:br ) +
|
|
348
|
+
content_tag(:span, :id => "#{help_tag_id(model, field)}", :class => "info", :style => "display:none;" ) do
|
|
349
|
+
content_tag(:em, :class => "info") do
|
|
350
|
+
help_text(model, field)
|
|
351
|
+
end
|
|
352
|
+
end
|
|
353
|
+
end
|
|
354
|
+
end
|
|
355
|
+
end #def
|
|
356
|
+
|
|
357
|
+
#---------------------------------------------------------------------------------------
|
|
358
|
+
# creates a hidden field
|
|
359
|
+
#
|
|
360
|
+
def hbl_hidden_field( f, field, options={})
|
|
361
|
+
f.hidden_field( field, options )
|
|
362
|
+
end #def
|
|
363
|
+
|
|
364
|
+
#---------------------------------------------------------------------------------------
|
|
365
|
+
# creates a tagged field
|
|
366
|
+
#
|
|
367
|
+
def hbl_tagged_fields_hash(f, model, field, editable, options={} )
|
|
368
|
+
tagged_fields_options = options.deep_dup
|
|
369
|
+
tagged_fields_options[:label] = label_text(model, field)
|
|
370
|
+
tagged_fields_options[:size] ||= 32
|
|
371
|
+
tagged_fields_options[:disabled] ||= !editable
|
|
372
|
+
content_tag(:div, :class => ("flash error" if !model.errors[field].empty? ) ) do
|
|
373
|
+
tags = model.send(field).map do |k, v|
|
|
374
|
+
case v.class.name
|
|
375
|
+
when "Array"
|
|
376
|
+
v.map do |av|
|
|
377
|
+
content_tag(:p ) do
|
|
378
|
+
content_tag(:label, get_tagged_fields_hash_name(model, k)) +
|
|
379
|
+
text_field_tag( "[#{model.class.name.underscore}][#{field}][#{k}][]", av, tagged_fields_options ) +
|
|
380
|
+
(editable ? content_tag(:a, "", :href=>"#", :class=>"icon icon-del", :onclick=>"$(this).parent().remove();" ) : "")
|
|
381
|
+
end
|
|
382
|
+
end.join("\n").html_safe
|
|
383
|
+
else
|
|
384
|
+
content_tag(:p ) do
|
|
385
|
+
content_tag(:label, get_tagged_fields_hash_name(model, k)) +
|
|
386
|
+
text_field_tag( "[#{model.class.name.underscore}][#{field}][#{k}]", v, tagged_fields_options ) +
|
|
387
|
+
(editable ? content_tag(:a, "", :href=>"#", :class=>"icon icon-del", :onclick=>"$(this).parent().remove();" ) : "")
|
|
388
|
+
end
|
|
389
|
+
end
|
|
390
|
+
end
|
|
391
|
+
tags.join("\n").html_safe
|
|
392
|
+
end
|
|
393
|
+
end #def
|
|
394
|
+
|
|
395
|
+
#---------------------------------------------------------------------------------------
|
|
396
|
+
# creates a tagged field selector
|
|
397
|
+
#
|
|
398
|
+
HBL_ADD_TAG_SCRIPT= <<-EOF
|
|
399
|
+
|
|
400
|
+
function hbl_append_tagged_field( url) {
|
|
401
|
+
$.ajax({
|
|
402
|
+
url: url,
|
|
403
|
+
async: false,
|
|
404
|
+
method: 'get',
|
|
405
|
+
dataType: 'script'
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
var formElements = new Array();
|
|
410
|
+
var formElementPrefix = "";
|
|
411
|
+
|
|
412
|
+
function hbl_update_selector_field() {
|
|
413
|
+
|
|
414
|
+
/* define variables */
|
|
415
|
+
var id = "";
|
|
416
|
+
|
|
417
|
+
/* enable all select options */
|
|
418
|
+
$('#tagged_field_selector').children().removeAttr('disabled');
|
|
419
|
+
|
|
420
|
+
/* collect all current text input tags */
|
|
421
|
+
formElements = [];
|
|
422
|
+
$("#entity-tagged_fields-fields :input").each(function(){
|
|
423
|
+
formElements.push($(this).attr('id'));
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
/* now diable all elements, not ending with "_", which are not multiple */
|
|
427
|
+
formElements.forEach( function (item, index) {
|
|
428
|
+
id = item.replace(formElementPrefix,'');
|
|
429
|
+
$('#tagged_field_selector').children('option[value="' + id + '"]').attr('disabled', 'disabled');
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
EOF
|
|
434
|
+
|
|
435
|
+
def hbl_tagged_fields_selector(project, model, field, tag_id, editable )
|
|
436
|
+
tagged_fields = TaggedField.of(project)
|
|
437
|
+
mod = model.class.name.underscore
|
|
438
|
+
content_tag(:p) do
|
|
439
|
+
content_tag(:label, l(:label_new_tagged_field)) +
|
|
440
|
+
select_tag(
|
|
441
|
+
"tagged_field_selector",
|
|
442
|
+
options_for_select([[l(:label_select_tagged_field),""]] + tagged_fields.collect{ |u| [u.name, u.identifier] } ),
|
|
443
|
+
:onchange => "hbl_append_tagged_field('#{add_project_tagged_fields_path(project,:m=>mod,:f=>field,:t=>tag_id)}&identifier='+this.value);this.selectedIndex = 0;hbl_update_selector_field();".html_safe,
|
|
444
|
+
:disabled => !editable
|
|
445
|
+
) +
|
|
446
|
+
content_tag(:script) do
|
|
447
|
+
HBL_ADD_TAG_SCRIPT.html_safe +
|
|
448
|
+
"formElementPrefix='_#{escape_javascript mod}_#{escape_javascript field.to_s}_';\n".html_safe +
|
|
449
|
+
"$(function() {hbl_update_selector_field();});"
|
|
450
|
+
end
|
|
451
|
+
end
|
|
452
|
+
end #def
|
|
453
|
+
|
|
454
|
+
#---------------------------------------------------------------------------------------
|
|
455
|
+
#
|
|
456
|
+
# edit tags for inline editing
|
|
457
|
+
# require:
|
|
458
|
+
# update_field_of_project_#{model}_path or options[:update_function]
|
|
459
|
+
# edit_#{models} as permission or options[:edit_permissions]
|
|
460
|
+
# view_#{models} as permission or options[:view_permissions]
|
|
461
|
+
#
|
|
462
|
+
def hbl_edit_string_tag( column, model, value, options={} )
|
|
463
|
+
|
|
464
|
+
klass = options[:class] || model.class
|
|
465
|
+
denominator = klass.name.underscore
|
|
466
|
+
|
|
467
|
+
project = model.project || @project
|
|
468
|
+
view_permission = options[:view_permission] || "view_#{denominator.pluralize}".to_sym
|
|
469
|
+
edit_permission = options[:edit_permission] || "edit_#{denominator.pluralize}".to_sym
|
|
470
|
+
update_function = options[:update_function] || "update_field_of_project_#{denominator}_path".to_sym
|
|
471
|
+
width = options[:width] || 12
|
|
472
|
+
value_representation = options[:value] || value
|
|
473
|
+
style = options[:style] || ""
|
|
474
|
+
css_class = options[:css_class] || "ipmclickempty"
|
|
475
|
+
data_text = options[:data_text] || "\xE2\x80\x8B" # zero width space
|
|
476
|
+
|
|
477
|
+
if User.current.allowed_to?(edit_permission, project) && (model.respond_to?(:editable?) ? model.editable? : true)
|
|
478
|
+
content_tag(
|
|
479
|
+
"div",
|
|
480
|
+
value_representation,
|
|
481
|
+
:field => column.name.to_s,
|
|
482
|
+
:id => "#{denominator}-#{model.id}-#{column.name.to_s}",
|
|
483
|
+
:onclick => "editTextField(this, '#{send(update_function, project.identifier, model)}', #{width}); return false;",
|
|
484
|
+
:class => css_class,
|
|
485
|
+
:content_editable => true,
|
|
486
|
+
:data => {:text => data_text}, # placeholder text
|
|
487
|
+
:style => style
|
|
488
|
+
)
|
|
489
|
+
elsif User.current.allowed_to?(view_permission, project)
|
|
490
|
+
content_tag(
|
|
491
|
+
"div",
|
|
492
|
+
value_representation,
|
|
493
|
+
:id => "#{column.name.to_s}_#{model.id}"
|
|
494
|
+
)
|
|
495
|
+
else
|
|
496
|
+
content_tag(
|
|
497
|
+
"div",
|
|
498
|
+
"---x---",
|
|
499
|
+
:id => "#{denominator}-#{model.id}-#{column.name.to_s}"
|
|
500
|
+
)
|
|
501
|
+
end #if
|
|
502
|
+
end #def
|
|
503
|
+
|
|
504
|
+
#---------------------------------------------------------------------------------------
|
|
505
|
+
# creates an edit array tag
|
|
506
|
+
#
|
|
507
|
+
def hbl_edit_array_tag( column, model, value, options={} )
|
|
508
|
+
|
|
509
|
+
klass = options[:class] || model.class
|
|
510
|
+
denominator = klass.name.underscore
|
|
511
|
+
|
|
512
|
+
project = model.project || @project
|
|
513
|
+
view_permission = options[:view_permission] || "view_#{denominator.pluralize}".to_sym
|
|
514
|
+
edit_permission = options[:edit_permission] || "edit_#{denominator.pluralize}".to_sym
|
|
515
|
+
update_function = options[:update_function] || "update_field_of_project_#{denominator}_path".to_sym
|
|
516
|
+
width = options[:width] || 12
|
|
517
|
+
css_class = options[:css_class] || "ipmclickempty"
|
|
518
|
+
|
|
519
|
+
if User.current.allowed_to?(edit_permission, project) && (model.respond_to?(:editable?) ? model.editable? : true)
|
|
520
|
+
content_tag(
|
|
521
|
+
"div",
|
|
522
|
+
value.to_s.split(/;|,|\ /).select(&:present?).join(", "),
|
|
523
|
+
:field => column.name.to_s,
|
|
524
|
+
:id => "#{denominator}-#{model.id}-#{column.name.to_s}",
|
|
525
|
+
:onclick => "editTextField(this, '#{send(update_function, project.identifier, model)}', #{width}); return false;",
|
|
526
|
+
:class => css_class
|
|
527
|
+
)
|
|
528
|
+
elsif User.current.allowed_to?(view_permission, project)
|
|
529
|
+
content_tag(
|
|
530
|
+
"div",
|
|
531
|
+
value.to_s.split(/;|,|\ /).select(&:present?).join(", "),
|
|
532
|
+
:id => "#{denominator}-#{model.id}-#{column.name.to_s}",
|
|
533
|
+
)
|
|
534
|
+
else
|
|
535
|
+
content_tag(
|
|
536
|
+
"div",
|
|
537
|
+
"---x---",
|
|
538
|
+
:id => "#{denominator}-#{model.id}-#{column.name.to_s}"
|
|
539
|
+
)
|
|
540
|
+
end #if
|
|
541
|
+
end #def
|
|
542
|
+
|
|
543
|
+
#---------------------------------------------------------------------------------------
|
|
544
|
+
# creates an edit text tag
|
|
545
|
+
#
|
|
546
|
+
def hbl_edit_text_tag( column, model, value, options={} )
|
|
547
|
+
|
|
548
|
+
klass = options[:class] || model.class
|
|
549
|
+
denominator = klass.name.underscore
|
|
550
|
+
|
|
551
|
+
project = model.project || @project
|
|
552
|
+
view_permission = options[:view_permission] || "view_#{denominator.pluralize}".to_sym
|
|
553
|
+
edit_permission = options[:edit_permission] || "edit_#{denominator.pluralize}".to_sym
|
|
554
|
+
update_function = options[:update_function] || "update_field_of_project_#{denominator}_path".to_sym
|
|
555
|
+
height = options[:height] || 5
|
|
556
|
+
value_representation = options[:value] || value
|
|
557
|
+
css_class = options[:css_class] || "ipmclickempty"
|
|
558
|
+
inner_css_class = options[:inner_css_class] || "ipmclickpre"
|
|
559
|
+
|
|
560
|
+
if User.current.allowed_to?(edit_permission, project) && (model.respond_to?(:editable?) ? model.editable? : true)
|
|
561
|
+
content_tag(
|
|
562
|
+
"div",
|
|
563
|
+
value_representation,
|
|
564
|
+
#content_tag("pre", value_representation, :class => inner_css_class),
|
|
565
|
+
:field => column.name.to_s,
|
|
566
|
+
:id => "#{denominator}-#{model.id}-#{column.name.to_s}",
|
|
567
|
+
:onclick => "editTextAreaField(this, '#{send(update_function, project.identifier, model)}', #{height}); return false;",
|
|
568
|
+
:class => css_class
|
|
569
|
+
)
|
|
570
|
+
elsif User.current.allowed_to?(view_permission, project)
|
|
571
|
+
content_tag(
|
|
572
|
+
"div",
|
|
573
|
+
value_representation,
|
|
574
|
+
:id => "#{column.name.to_s}_#{model.id}"
|
|
575
|
+
)
|
|
576
|
+
else
|
|
577
|
+
content_tag(
|
|
578
|
+
"div",
|
|
579
|
+
"---x---",
|
|
580
|
+
:id => "#{denominator}-#{model.id}-#{column.name.to_s}"
|
|
581
|
+
)
|
|
582
|
+
end #if
|
|
583
|
+
end #def
|
|
584
|
+
|
|
585
|
+
|
|
586
|
+
#---------------------------------------------------------------------------------------
|
|
587
|
+
# creates an iframe tag
|
|
588
|
+
#
|
|
589
|
+
def ipm_iframe_tag(path, title, id, options={})
|
|
590
|
+
|
|
591
|
+
content_tag(:div,
|
|
592
|
+
content_tag(
|
|
593
|
+
:iframe,
|
|
594
|
+
"",
|
|
595
|
+
{ :src => path,
|
|
596
|
+
:id => id,
|
|
597
|
+
:title => title,
|
|
598
|
+
:frameborder => "0",
|
|
599
|
+
:scrolling => "no",
|
|
600
|
+
:allowtransparency => "true",
|
|
601
|
+
:seamless => "seamless",
|
|
602
|
+
:style => "width:100%;height:16px;",
|
|
603
|
+
:onload => "resizeIframe(this);"
|
|
604
|
+
}
|
|
605
|
+
),
|
|
606
|
+
options
|
|
607
|
+
)
|
|
608
|
+
end #def
|
|
609
|
+
|
|
610
|
+
#---------------------------------------------------------------------------------------
|
|
611
|
+
# private methods
|
|
612
|
+
#
|
|
613
|
+
def get_tagged_fields_hash_name(model, k)
|
|
614
|
+
tagged_fields = TaggedField.of(model.project).where(:identifier => k)
|
|
615
|
+
return tagged_fields[0].name if tagged_fields.present?
|
|
616
|
+
return k.to_s.humanize
|
|
617
|
+
end #def
|
|
618
|
+
|
|
619
|
+
def help_tag_id(model, field)
|
|
620
|
+
stem = field.to_s.gsub(/_id\z/, "")
|
|
621
|
+
"help_#{model.class.name.demodulize.underscore}_#{stem}_#{model.id}"
|
|
622
|
+
end #def
|
|
623
|
+
|
|
624
|
+
def help_text(model, field)
|
|
625
|
+
stem = field.to_s.gsub(/_id\z/, "")
|
|
626
|
+
hbl_label( "help_#{stem}".to_sym, model )
|
|
627
|
+
end #def
|
|
628
|
+
|
|
629
|
+
def label_text(model, field)
|
|
630
|
+
stem = field.to_s.gsub(/_id\z/, "")
|
|
631
|
+
hbl_label( "field_#{stem}".to_sym, model )
|
|
632
|
+
end #def
|
|
633
|
+
|
|
634
|
+
# get placeholder value in the following hierarchy:
|
|
635
|
+
#
|
|
636
|
+
# 1. options[:placeholder]
|
|
637
|
+
# 2. an instance variable containing a model named #{model.class.name.underscore}_placeholder
|
|
638
|
+
# 3. an instance variable with a hash contaning attributes with placeholders name #{model.class.name.underscore}_attributes
|
|
639
|
+
# 4. preset values from init.rb
|
|
640
|
+
#
|
|
641
|
+
def placeholder( field, model, options={} )
|
|
642
|
+
|
|
643
|
+
placeholder = options[:placeholder]
|
|
644
|
+
name = "#{model.class.name.underscore}"
|
|
645
|
+
attr_model = instance_variable_get("@#{name}_placeholder")
|
|
646
|
+
attr_hash = instance_variable_get("@#{name}_attributes")
|
|
647
|
+
|
|
648
|
+
name = "#{model.class.base_class.name.underscore}"
|
|
649
|
+
attr_model ||= instance_variable_get("@#{name}_placeholder")
|
|
650
|
+
attr_hash ||= instance_variable_get("@#{name}_attributes")
|
|
651
|
+
|
|
652
|
+
placeholder ||= (attr_model && attr_model.send(field) rescue "__error__")
|
|
653
|
+
placeholder ||= attr_hash.symbolize_keys[field.to_sym] if attr_hash.is_a?(Hash)
|
|
654
|
+
placeholder ||= I18n.translate( "#{model.class.name.underscore}.#{field}".to_sym )
|
|
655
|
+
|
|
656
|
+
placeholder
|
|
657
|
+
end #def
|
|
658
|
+
|
|
659
|
+
def project_tree_options_array(projects, options = {})
|
|
660
|
+
s = []
|
|
661
|
+
if blank_text = options[:include_blank]
|
|
662
|
+
if blank_text == true
|
|
663
|
+
blank_text = ' '.html_safe
|
|
664
|
+
end
|
|
665
|
+
s << [blank_text, '']
|
|
666
|
+
end
|
|
667
|
+
Project.project_tree(projects) do |project, level|
|
|
668
|
+
name_prefix = (level > 0 ? ' ' * 2 * level + '» ' : '').html_safe
|
|
669
|
+
s << [name_prefix + h(project), project.id]
|
|
670
|
+
end
|
|
671
|
+
s
|
|
672
|
+
end
|
|
673
|
+
|
|
674
|
+
def currency_options_for_select(blank=true)
|
|
675
|
+
(blank ? [["(auto)", ""]] : []) + currencies_options
|
|
676
|
+
end #def
|
|
677
|
+
|
|
678
|
+
def currencies_options
|
|
679
|
+
["DE", "US", "CH"].map do |cc|
|
|
680
|
+
c = ISO3166::Country[cc];
|
|
681
|
+
I18n.with_locale(:de) { [c.currency.name, c.currency.iso_code] }
|
|
682
|
+
end
|
|
683
|
+
end #def
|
|
684
|
+
end
|
|
685
|
+
end
|