widget_list 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +26 -2
- data/app/views/widget_list/_condition_fields.html.erb +0 -0
- data/app/views/widget_list/_ransack_fields.html.erb +0 -0
- data/app/views/widget_list/_ransack_widget_list_advanced_search.html.erb +0 -0
- data/app/views/widget_list/administration/_field_row.html.erb +11 -0
- data/app/views/widget_list/administration/_output.html.erb +856 -0
- data/app/views/widget_list/administration/_output_save.html.erb +2 -0
- data/app/views/widget_list/list_partials/_col.html.erb +0 -0
- data/app/views/widget_list/list_partials/_list_description.html.erb +0 -0
- data/app/views/widget_list/list_partials/_no_sort_column.html.erb +0 -0
- data/app/views/widget_list/list_partials/_pagination_jump_active.html.erb +0 -0
- data/app/views/widget_list/list_partials/_pagination_jump_unactive.html.erb +0 -0
- data/app/views/widget_list/list_partials/_pagination_next_active.html.erb +0 -0
- data/app/views/widget_list/list_partials/_pagination_next_disabled.html.erb +0 -0
- data/app/views/widget_list/list_partials/_pagination_previous_active.html.erb +0 -0
- data/app/views/widget_list/list_partials/_pagination_previous_disabled.html.erb +0 -0
- data/app/views/widget_list/list_partials/_pagination_wrapper.html.erb +0 -0
- data/app/views/widget_list/list_partials/_row.html.erb +0 -0
- data/app/views/widget_list/list_partials/_sequence.html.erb +0 -0
- data/app/views/widget_list/list_partials/_sort_column.html.erb +0 -0
- data/lib/extensions/action_controller_base.rb +33 -33
- data/lib/widget_list.rb +3664 -2783
- data/lib/widget_list/engine.rb +8 -8
- data/lib/widget_list/hash.rb +113 -113
- data/lib/widget_list/md5.rb +18 -18
- data/lib/widget_list/railtie.rb +42 -42
- data/lib/widget_list/sequel.rb +218 -218
- data/lib/widget_list/string.rb +41 -41
- data/lib/widget_list/tpl.rb +185 -185
- data/lib/widget_list/utils.rb +92 -92
- data/lib/widget_list/version.rb +3 -3
- data/lib/widget_list/widgets.rb +756 -756
- metadata +5 -2
data/lib/widget_list/utils.rb
CHANGED
@@ -1,93 +1,93 @@
|
|
1
|
-
module WidgetList
|
2
|
-
|
3
|
-
class Utils
|
4
|
-
|
5
|
-
def self.numeric?(object)
|
6
|
-
true if Float(object) rescue false
|
7
|
-
end
|
8
|
-
|
9
|
-
def self.date?(object)
|
10
|
-
true if Date.parse(object) rescue false
|
11
|
-
end
|
12
|
-
|
13
|
-
#JsonEncode
|
14
|
-
def self.json_encode(arr,return_string = false)
|
15
|
-
if return_string
|
16
|
-
p JSON.generate(arr)
|
17
|
-
else
|
18
|
-
JSON.generate(arr)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
#BuildQueryString
|
23
|
-
def self.build_query_string(args)
|
24
|
-
q = []
|
25
|
-
args.each { |k,v|
|
26
|
-
if v.class.name == 'Hash'
|
27
|
-
q << {k => v}.to_params
|
28
|
-
else
|
29
|
-
q << k.to_s + '=' + URI.encode(URI.decode(v.to_s))
|
30
|
-
end
|
31
|
-
}
|
32
|
-
q.join('&')
|
33
|
-
end
|
34
|
-
|
35
|
-
|
36
|
-
#BuildUrl
|
37
|
-
def self.build_url(page='',args = {}, append_get=false)
|
38
|
-
qs = build_query_string(args)
|
39
|
-
getvars = ''
|
40
|
-
if append_get && $_REQUEST
|
41
|
-
getvars = build_query_string($_REQUEST)
|
42
|
-
end
|
43
|
-
|
44
|
-
unless page =~ /\?/
|
45
|
-
"#{page}?" + qs + '&' + getvars
|
46
|
-
else
|
47
|
-
"#{page}" + qs + '&' + getvars
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
#Fill
|
52
|
-
def self.fill(tags = {}, template = '')
|
53
|
-
tpl = template.dup
|
54
|
-
tags.each { |k,v|
|
55
|
-
tpl = tpl.gsub(k.to_s,v.to_s)
|
56
|
-
}
|
57
|
-
tpl
|
58
|
-
end
|
59
|
-
|
60
|
-
#test_all
|
61
|
-
def self.test_all
|
62
|
-
output_final = ''
|
63
|
-
output_final += "JsonEncode\n<br/>\n<br/>"
|
64
|
-
|
65
|
-
a = { }
|
66
|
-
a['asdfasdf'] = 'asfd'
|
67
|
-
a[:test] = 1234
|
68
|
-
a[2153125] = nil
|
69
|
-
output_final += Utils.json_encode(a)
|
70
|
-
|
71
|
-
|
72
|
-
output_final += "\n<br/>\n<br/>BuildQueryString\n<br/>\n<br/>"
|
73
|
-
|
74
|
-
a = { }
|
75
|
-
a['asdfasdf'] = 'asdf asdfj ajskdfhasdf'
|
76
|
-
a['dave'] = 'a)(J#(*J@T2p2kfasdfa fas %20fj ajskdfhasdf'
|
77
|
-
output_final += Utils.build_query_string(a)
|
78
|
-
|
79
|
-
|
80
|
-
output_final += "\n<br/>\n<br/>BuildUrl\n<br/>\n<br/>"
|
81
|
-
|
82
|
-
|
83
|
-
output_final += Utils.build_url('page.php?',a)
|
84
|
-
|
85
|
-
|
86
|
-
output_final += "\n<br/>\n<br/>Fill\n<br/>\n<br/>"
|
87
|
-
|
88
|
-
output_final += Utils.fill({'<!--CONTENT-->'=>'dave','<!--TITLE-->'=>'the title'},'<!--TITLE--> --------- <!--CONTENT-->')
|
89
|
-
end
|
90
|
-
|
91
|
-
end
|
92
|
-
|
1
|
+
module WidgetList
|
2
|
+
|
3
|
+
class Utils
|
4
|
+
|
5
|
+
def self.numeric?(object)
|
6
|
+
true if Float(object) rescue false
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.date?(object)
|
10
|
+
true if Date.parse(object) rescue false
|
11
|
+
end
|
12
|
+
|
13
|
+
#JsonEncode
|
14
|
+
def self.json_encode(arr,return_string = false)
|
15
|
+
if return_string
|
16
|
+
p JSON.generate(arr)
|
17
|
+
else
|
18
|
+
JSON.generate(arr)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
#BuildQueryString
|
23
|
+
def self.build_query_string(args)
|
24
|
+
q = []
|
25
|
+
args.each { |k,v|
|
26
|
+
if v.class.name == 'Hash'
|
27
|
+
q << {k => v}.to_params
|
28
|
+
else
|
29
|
+
q << k.to_s + '=' + URI.encode(URI.decode(v.to_s))
|
30
|
+
end
|
31
|
+
}
|
32
|
+
q.join('&')
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
#BuildUrl
|
37
|
+
def self.build_url(page='',args = {}, append_get=false)
|
38
|
+
qs = build_query_string(args)
|
39
|
+
getvars = ''
|
40
|
+
if append_get && $_REQUEST
|
41
|
+
getvars = build_query_string($_REQUEST)
|
42
|
+
end
|
43
|
+
|
44
|
+
unless page =~ /\?/
|
45
|
+
"#{page}?" + qs + '&' + getvars
|
46
|
+
else
|
47
|
+
"#{page}" + qs + '&' + getvars
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
#Fill
|
52
|
+
def self.fill(tags = {}, template = '')
|
53
|
+
tpl = template.dup
|
54
|
+
tags.each { |k,v|
|
55
|
+
tpl = tpl.gsub(k.to_s,v.to_s)
|
56
|
+
}
|
57
|
+
tpl
|
58
|
+
end
|
59
|
+
|
60
|
+
#test_all
|
61
|
+
def self.test_all
|
62
|
+
output_final = ''
|
63
|
+
output_final += "JsonEncode\n<br/>\n<br/>"
|
64
|
+
|
65
|
+
a = { }
|
66
|
+
a['asdfasdf'] = 'asfd'
|
67
|
+
a[:test] = 1234
|
68
|
+
a[2153125] = nil
|
69
|
+
output_final += Utils.json_encode(a)
|
70
|
+
|
71
|
+
|
72
|
+
output_final += "\n<br/>\n<br/>BuildQueryString\n<br/>\n<br/>"
|
73
|
+
|
74
|
+
a = { }
|
75
|
+
a['asdfasdf'] = 'asdf asdfj ajskdfhasdf'
|
76
|
+
a['dave'] = 'a)(J#(*J@T2p2kfasdfa fas %20fj ajskdfhasdf'
|
77
|
+
output_final += Utils.build_query_string(a)
|
78
|
+
|
79
|
+
|
80
|
+
output_final += "\n<br/>\n<br/>BuildUrl\n<br/>\n<br/>"
|
81
|
+
|
82
|
+
|
83
|
+
output_final += Utils.build_url('page.php?',a)
|
84
|
+
|
85
|
+
|
86
|
+
output_final += "\n<br/>\n<br/>Fill\n<br/>\n<br/>"
|
87
|
+
|
88
|
+
output_final += Utils.fill({'<!--CONTENT-->'=>'dave','<!--TITLE-->'=>'the title'},'<!--TITLE--> --------- <!--CONTENT-->')
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
93
|
end
|
data/lib/widget_list/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module WidgetList
|
2
|
-
VERSION = "1.2.
|
3
|
-
end
|
1
|
+
module WidgetList
|
2
|
+
VERSION = "1.2.1"
|
3
|
+
end
|
data/lib/widget_list/widgets.rb
CHANGED
@@ -1,757 +1,757 @@
|
|
1
|
-
module WidgetList
|
2
|
-
class Widgets
|
3
|
-
|
4
|
-
#todo - WidgetRadio, WidgetData?
|
5
|
-
|
6
|
-
# WidgetCheck
|
7
|
-
def self.widget_check(list={})
|
8
|
-
|
9
|
-
items = { 'name' => '',
|
10
|
-
'id' => '',
|
11
|
-
'value' => '',
|
12
|
-
'width' => '',
|
13
|
-
'disabled' => false,
|
14
|
-
'hidden' => false,
|
15
|
-
'required' => false,
|
16
|
-
'checked' => false,
|
17
|
-
'max_length' => '',
|
18
|
-
'title' => '',
|
19
|
-
'class' => '',
|
20
|
-
'style' => '',
|
21
|
-
'onclick' => '',
|
22
|
-
'input_style' => '',
|
23
|
-
'input_class' => '',
|
24
|
-
'template' => '',
|
25
|
-
}
|
26
|
-
|
27
|
-
items['template_required'] = $G_TEMPLATE['widget']['required']
|
28
|
-
|
29
|
-
items['template'] = $G_TEMPLATE['widget']['checkbox']['default']
|
30
|
-
|
31
|
-
items = populate_items(list,items)
|
32
|
-
|
33
|
-
if !items['required']
|
34
|
-
items['template_required'] = ''
|
35
|
-
end
|
36
|
-
|
37
|
-
if items['checked'] == true
|
38
|
-
items['checked'] = 'checked'
|
39
|
-
end
|
40
|
-
|
41
|
-
if !items['class'].empty?
|
42
|
-
items['input_class'] = items['class']
|
43
|
-
end
|
44
|
-
|
45
|
-
if items['disabled']
|
46
|
-
items['disabled'] = 'disabled'
|
47
|
-
else
|
48
|
-
items['disabled'] = ''
|
49
|
-
end
|
50
|
-
|
51
|
-
if items['hidden'] == true
|
52
|
-
items['style'] += ' display:none'
|
53
|
-
end
|
54
|
-
|
55
|
-
pieces = {
|
56
|
-
'<!--INPUT_CLASS-->' => items['input_class'],
|
57
|
-
'<!--INPUT_STYLE-->' => items['input_style'],
|
58
|
-
'<!--ID-->' => items['id'],
|
59
|
-
'<!--NAME-->' => items['name'],
|
60
|
-
'<!--TITLE-->' => items['title'],
|
61
|
-
'<!--ONCLICK-->' => items['onclick'],
|
62
|
-
'<!--VALUE-->' => items['value'],
|
63
|
-
'<!--REQUIRED-->' => items['template_required'],
|
64
|
-
'<!--CHECKED-->' => items['checked'],
|
65
|
-
'<!--VALUE-->' => items['value'],
|
66
|
-
'<!--DISABLED-->' => items['disabled']
|
67
|
-
}
|
68
|
-
|
69
|
-
return WidgetList::Utils::fill(pieces, items['template'])
|
70
|
-
end
|
71
|
-
|
72
|
-
# WidgetSelect - todo - never tested one line of code in here!!!
|
73
|
-
def self.widget_select(sql = '', list={})
|
74
|
-
valid = true
|
75
|
-
selectOutput = []
|
76
|
-
|
77
|
-
#Parameter evaluation identification
|
78
|
-
#
|
79
|
-
if list.empty? && sql.class.name == 'Hash'
|
80
|
-
list = sql
|
81
|
-
end
|
82
|
-
|
83
|
-
if ! sql.empty? && ! list.key?('sql') && ! list.key?('view')
|
84
|
-
list['sql'] = sql
|
85
|
-
end
|
86
|
-
|
87
|
-
#
|
88
|
-
# Default configurations
|
89
|
-
#
|
90
|
-
items = {}
|
91
|
-
|
92
|
-
items['name'] = ''
|
93
|
-
items['id'] = ''
|
94
|
-
items['multiple'] = false
|
95
|
-
items['insertUnknown'] = false
|
96
|
-
items['required'] = ''
|
97
|
-
items['strLenBrk'] = 50
|
98
|
-
items['optGroupIndicator'] = ''
|
99
|
-
items['label'] = ''
|
100
|
-
items['selectTxt'] = 'Select One'
|
101
|
-
items['showId'] = false
|
102
|
-
items['showIdLeft'] = false
|
103
|
-
items['passive'] = false
|
104
|
-
items['freeflow'] = false
|
105
|
-
items['no_style'] = false
|
106
|
-
|
107
|
-
#
|
108
|
-
# Select box attributes
|
109
|
-
#
|
110
|
-
items['attribs'] = {}
|
111
|
-
items['size'] = 1
|
112
|
-
items['disabled'] = false
|
113
|
-
items['noDataMsg'] = 'No Data'
|
114
|
-
items['selectOne'] = 0
|
115
|
-
items['selected'] = {}
|
116
|
-
|
117
|
-
#
|
118
|
-
# SQL
|
119
|
-
#
|
120
|
-
items['bindVars'] = {}
|
121
|
-
items['view'] = ''
|
122
|
-
items['sql'] = ''
|
123
|
-
items['orderBy'] = ''
|
124
|
-
items['filter'] = ''
|
125
|
-
|
126
|
-
#
|
127
|
-
# Actions
|
128
|
-
#
|
129
|
-
items['onchange'] = ''
|
130
|
-
items['onclick'] = ''
|
131
|
-
|
132
|
-
#
|
133
|
-
# Style
|
134
|
-
#
|
135
|
-
items['style'] = '' #meant for internal use as nothing is appended only replaced.
|
136
|
-
items['inner_class'] = 'select-inner' #Left long piece of image
|
137
|
-
items['outer_class'] = 'select-outer' #Right corner of image
|
138
|
-
items['outer_style'] = '' #Basically the width of the select box ends up here
|
139
|
-
items['extra_class'] = '' #Not used currently
|
140
|
-
items['width'] = 184 #width of the select-outer element
|
141
|
-
|
142
|
-
#
|
143
|
-
# @deprecated
|
144
|
-
#
|
145
|
-
items['class'] = ''
|
146
|
-
|
147
|
-
|
148
|
-
#
|
149
|
-
# Setup templates
|
150
|
-
#
|
151
|
-
if items['freeflow']
|
152
|
-
#
|
153
|
-
# Freeflow
|
154
|
-
#
|
155
|
-
items['template']['wrapper'] = $G_TEMPLATE['widget']['selectfree']['wrapper']
|
156
|
-
items['template']['option'] = $G_TEMPLATE['widget']['selectfree']['option']
|
157
|
-
items['template']['initial'] = ''
|
158
|
-
items['template']['passive'] = ''
|
159
|
-
else
|
160
|
-
#
|
161
|
-
# Standard
|
162
|
-
#
|
163
|
-
items['template']['wrapper'] = $G_TEMPLATE['widget']['selectbox']['wrapper']
|
164
|
-
items['template']['option'] = $G_TEMPLATE['widget']['selectbox']['option']
|
165
|
-
items['template']['initial'] = $G_TEMPLATE['widget']['selectbox']['initial']
|
166
|
-
items['template']['passive'] = $G_TEMPLATE['widget']['selectbox']['passive']
|
167
|
-
end
|
168
|
-
|
169
|
-
# if numeric or string passed, convert to array
|
170
|
-
if list.key?('selected') && list['selected'].class.name != 'Array'
|
171
|
-
list['selected'] = [ list['selected'] ]
|
172
|
-
end
|
173
|
-
|
174
|
-
#
|
175
|
-
# Merge settings
|
176
|
-
#
|
177
|
-
items = populate_items(list,items)
|
178
|
-
|
179
|
-
if items['no_style']
|
180
|
-
items['template']['wrapper'] = $G_TEMPLATE['widget']['selectbox_nostyle']['wrapper']
|
181
|
-
end
|
182
|
-
|
183
|
-
|
184
|
-
#
|
185
|
-
# If multiple then override above settings and classes
|
186
|
-
#
|
187
|
-
if items['multiple']
|
188
|
-
items['outer_style'] = ';width:280px;'
|
189
|
-
items['width'] = 280
|
190
|
-
|
191
|
-
items['inner_class'] = 'select-inner-multiple'
|
192
|
-
items['outer_class'] = 'select-outer-multiple'
|
193
|
-
end
|
194
|
-
|
195
|
-
if items['showId']
|
196
|
-
items['template']['option'] = $G_TEMPLATE['widget']['selectbox']['option_showid']
|
197
|
-
end
|
198
|
-
|
199
|
-
if items['showIdLeft']
|
200
|
-
items['template']['option'] = $G_TEMPLATE['widget']['selectbox']['option_showid_left']
|
201
|
-
end
|
202
|
-
|
203
|
-
if items['disabled']
|
204
|
-
items['disabled'] = 'disabled="disabled"'
|
205
|
-
items['class'] += ' disabled'
|
206
|
-
end
|
207
|
-
|
208
|
-
if items['multiple']
|
209
|
-
items['multiple'] = 'multiple="multiple"'
|
210
|
-
end
|
211
|
-
|
212
|
-
if items['required']
|
213
|
-
items['required'] = $G_TEMPLATE['widget']['required']
|
214
|
-
end
|
215
|
-
|
216
|
-
if ! items['sql'].empty?
|
217
|
-
sql = items['sql']
|
218
|
-
elsif !items['view'].empty?
|
219
|
-
sql = "SELECT id, value FROM " + items['view']
|
220
|
-
else
|
221
|
-
valid = false
|
222
|
-
end
|
223
|
-
|
224
|
-
if ! items['filter'].empty?
|
225
|
-
sql += ' WHERE ' + items['filter'].join(' AND ')
|
226
|
-
end
|
227
|
-
|
228
|
-
if ! items['orderBy'].empty?
|
229
|
-
sql += ' ORDER BY ' + items['orderBy']
|
230
|
-
end
|
231
|
-
|
232
|
-
rows = WidgetList::List.get_database._select(sql, [], items['bindVars'])
|
233
|
-
selectRows = WidgetList::List.get_database.final_results
|
234
|
-
|
235
|
-
|
236
|
-
if rows > 0 && valid
|
237
|
-
if ! items['passive']
|
238
|
-
addedGroup = false
|
239
|
-
groupByRow = false
|
240
|
-
groupByValue = -1
|
241
|
-
if selectRows.key?('GROUPING_VAL')
|
242
|
-
groupByRow = true
|
243
|
-
end
|
244
|
-
|
245
|
-
max = rows-1
|
246
|
-
|
247
|
-
selected = ''
|
248
|
-
|
249
|
-
if (items['selectOne'] > 0 || (items['selectOne'].class.name == 'Array' && ! items['selectOne'].empty?) && ! items['freeflow'])
|
250
|
-
theVal = ''
|
251
|
-
theClk = ''
|
252
|
-
theSel = ''
|
253
|
-
theTxt = items['selectTxt']
|
254
|
-
|
255
|
-
if items['selectOne'].class.name == 'Array'
|
256
|
-
if(items['selectOne'].key?('text'))
|
257
|
-
theTxt = items['selectOne']['text']
|
258
|
-
end
|
259
|
-
|
260
|
-
if(items['selectOne'].key?('value'))
|
261
|
-
theVal = items['selectOne']['value']
|
262
|
-
end
|
263
|
-
end
|
264
|
-
|
265
|
-
pieces = { '<!--VALUE-->' => theVal,
|
266
|
-
'<!--ONCLICK-->' => theClk,
|
267
|
-
'<!--SELECTED-->' => theSel,
|
268
|
-
'<!--CONTENT-->' => theTxt
|
269
|
-
}
|
270
|
-
|
271
|
-
|
272
|
-
selectOutput << WidgetList::Utils::fill(pieces, items['template']['initial'])
|
273
|
-
end
|
274
|
-
|
275
|
-
hasASelectedMatch = false
|
276
|
-
startedGrouping = false
|
277
|
-
i = 0
|
278
|
-
for i in j..max
|
279
|
-
if items['selected'].class.name == 'Array' && items['selected'].count > 0
|
280
|
-
if items['selected'].include?(selectRows['ID'][i]) || items['selected'].include?(selectRows['VALUE'][i])
|
281
|
-
hasASelectedMatch = true
|
282
|
-
selected = ' selected'
|
283
|
-
end
|
284
|
-
end
|
285
|
-
|
286
|
-
if selectRows['VALUE'][i].length > items['strLenBrk']
|
287
|
-
first = CGI.escapeHTML(selectRows['VALUE'][i].to_s[0,10])
|
288
|
-
last = CGI.escapeHTML(selectRows['VALUE'][i].to_s[-40])
|
289
|
-
content = first + '...' + last
|
290
|
-
else
|
291
|
-
content = CGI.escapeHTML(selectRows['VALUE'][i])
|
292
|
-
end
|
293
|
-
|
294
|
-
pieces = {
|
295
|
-
'<!--VALUE-->' => selectRows['ID'][i],
|
296
|
-
'<!--ONCLICK-->' => items['onclick'],
|
297
|
-
'<!--SELECTED-->' => selected,
|
298
|
-
'<!--CONTENT-->' => content,
|
299
|
-
'<!--COUNTER-->' => i,
|
300
|
-
'<!--NAME-->' => items['name'],
|
301
|
-
}
|
302
|
-
|
303
|
-
|
304
|
-
if groupByRow
|
305
|
-
if selectRows['GROUPING_VAL'][i] != groupByValue
|
306
|
-
if (addedGroup)
|
307
|
-
selectOutput << '</optgroup>'
|
308
|
-
end
|
309
|
-
|
310
|
-
addedGroup = true
|
311
|
-
# Start new optgroup
|
312
|
-
groupByValue = selectRows['GROUPING_VAL'][i]
|
313
|
-
|
314
|
-
selectOutput << '<optgroup label="' + groupByValue + '">'
|
315
|
-
selectOutput << WidgetList::Utils::fill(pieces, items['template']['option'])
|
316
|
-
else
|
317
|
-
selectOutput << WidgetList::Utils::fill(pieces, items['template']['option'])
|
318
|
-
end
|
319
|
-
else
|
320
|
-
if selectRows['ID'][i] === 'GROUPING'
|
321
|
-
# Output OPTGROUP tags and labels no one can select this
|
322
|
-
if startedGrouping
|
323
|
-
selectOutput << '</optgroup>'
|
324
|
-
end
|
325
|
-
selectOutput << '<optgroup label="' + selectRows['VALUE'][i] + '">'
|
326
|
-
startedGrouping = true
|
327
|
-
else
|
328
|
-
# Output regular option tag
|
329
|
-
selectOutput << WidgetList::Utils::fill(pieces, items['template']['option'])
|
330
|
-
end
|
331
|
-
end
|
332
|
-
|
333
|
-
selected = ''
|
334
|
-
end
|
335
|
-
|
336
|
-
if (groupByRow && addedGroup)
|
337
|
-
selectOutput << '</optgroup>'
|
338
|
-
end
|
339
|
-
|
340
|
-
if hasASelectedMatch === false && items['insertUnknown'] === true
|
341
|
-
# in this mode, you wish to inject an option into the select box even though the results didnt find the match
|
342
|
-
|
343
|
-
|
344
|
-
items['selected'].each{ |vals|
|
345
|
-
pieces = {
|
346
|
-
'<!--VALUE-->' => vals,
|
347
|
-
'<!--ONCLICK-->' => items['onclick'],
|
348
|
-
'<!--SELECTED-->' => ' selected ',
|
349
|
-
'<!--CONTENT-->' => vals
|
350
|
-
}
|
351
|
-
selectOutput << WidgetList::Utils::fill(pieces, items['template']['option'])
|
352
|
-
}
|
353
|
-
end
|
354
|
-
end
|
355
|
-
else
|
356
|
-
pieces = {
|
357
|
-
'<!--VALUE-->' => '',
|
358
|
-
'<!--ONCLICK-->' => items['onclick'],
|
359
|
-
'<!--SELECTED-->' => '',
|
360
|
-
'<!--CONTENT-->' => items['noDataMsg']
|
361
|
-
}
|
362
|
-
|
363
|
-
selectOutput << WidgetList::Utils::fill(pieces, items['template']['initial'])
|
364
|
-
end
|
365
|
-
|
366
|
-
if items['id'].empty? && ! items['name'].empty?
|
367
|
-
items['id'] = items['name']
|
368
|
-
end
|
369
|
-
|
370
|
-
|
371
|
-
pieces = { '<!--SIZE-->' => items['size'],
|
372
|
-
'<!--ID-->' => items['id'],
|
373
|
-
'<!--NAME-->' => items['name'],
|
374
|
-
'<!--MULTIPLE-->' => items['multiple'],
|
375
|
-
'<!--OPTIONS-->' => selectOutput.join(''),
|
376
|
-
'<!--ONCHANGE-->' => items['onchange'],
|
377
|
-
'<!--REQUIRED-->' => items['required'],
|
378
|
-
'<!--CLASS-->' => items['class'],
|
379
|
-
'<!--DISABLED_FLG-->' => items['disabled'],
|
380
|
-
'<!--STYLE-->' => items['style'],
|
381
|
-
'<!--ATTRIBUTES-->' => items['attribs'].join(' '),
|
382
|
-
'<!--INNER_CLASS-->' => items['inner_class'],
|
383
|
-
'<!--OUTER_CLASS-->' => items['outer_class'],
|
384
|
-
'<!--OUTER_STYLE-->' => items['outer_style'],
|
385
|
-
'<!--INNER_STYLE-->' => '',
|
386
|
-
'<!--OUTER_ACTION-->' => ''
|
387
|
-
}
|
388
|
-
|
389
|
-
finalTemplate = items['template']['wrapper']
|
390
|
-
|
391
|
-
if items['passive'] && items['selected'].class.name == 'Array' && items['selected'].count > 0
|
392
|
-
#passKeys = array_keys(selectRows['ID'], items['selected'][0])
|
393
|
-
#pieces['<!--OPTIONS-->'] = selectRows['VALUE'][passKeys[0]]
|
394
|
-
finalTemplate = items['template']['passive']
|
395
|
-
end
|
396
|
-
|
397
|
-
WidgetList::Utils::fill(pieces, finalTemplate)
|
398
|
-
end
|
399
|
-
|
400
|
-
# WidgetInput
|
401
|
-
def self.widget_input(list={})
|
402
|
-
items = {
|
403
|
-
'name' => '',
|
404
|
-
'id' => '',
|
405
|
-
'outer_id' => '',
|
406
|
-
'value' => '',
|
407
|
-
'input_type' => 'text', #hidden
|
408
|
-
'width' => '150',
|
409
|
-
'readonly' => false,
|
410
|
-
'disabled' => false,
|
411
|
-
'hidden' => false,
|
412
|
-
'required' => false,
|
413
|
-
'list-search' => false,
|
414
|
-
'max_length' => '',
|
415
|
-
'events' => {},
|
416
|
-
'title' => '',
|
417
|
-
'add_class' => '',
|
418
|
-
'class' => 'inputOuter',
|
419
|
-
'inner_class' => 'inputInner',
|
420
|
-
'outer_onclick'=> '',
|
421
|
-
'style' => '',
|
422
|
-
'inner_style' => '',
|
423
|
-
'input_style' => '',
|
424
|
-
'input_class' => '',
|
425
|
-
'template' => '',
|
426
|
-
'search_ahead' => {},
|
427
|
-
'search_form' => '',
|
428
|
-
'search_handle'=> '',
|
429
|
-
'arrow_extra_class'=> '',
|
430
|
-
'icon_extra_class'=> '',
|
431
|
-
'arrow_action' => ''
|
432
|
-
}
|
433
|
-
|
434
|
-
items['template_required'] = $G_TEMPLATE['widget']['required']
|
435
|
-
|
436
|
-
items['template'] = $G_TEMPLATE['widget']['input']['default']
|
437
|
-
|
438
|
-
items = populate_items(list,items)
|
439
|
-
|
440
|
-
iconAction = ''
|
441
|
-
outerAction = ''
|
442
|
-
onkeyup = ''
|
443
|
-
|
444
|
-
if ! items['outer_onclick'].empty?
|
445
|
-
outerAction = items['outer_onclick']
|
446
|
-
end
|
447
|
-
|
448
|
-
if ! items['search_ahead'].empty?
|
449
|
-
# Search Ahead Input
|
450
|
-
#
|
451
|
-
items['template'] = $G_TEMPLATE['widget']['input']['search']
|
452
|
-
|
453
|
-
fill = {}
|
454
|
-
if items['list-search']
|
455
|
-
fill['<!--MAGNIFIER-->'] = '<div class="widget-search-magnifier <!--ICON_EXTRA_CLASS-->" style="" onclick="<!--ICON_ACTION-->"></div>'
|
456
|
-
end
|
457
|
-
|
458
|
-
items['template'] = WidgetList::Utils::fill(fill,items['template'])
|
459
|
-
|
460
|
-
if ! items['search_ahead']['search_form'].empty?
|
461
|
-
if(items['arrow_action'].empty?)
|
462
|
-
items['arrow_action'] = "ToggleAdvancedSearch(this)"
|
463
|
-
end
|
464
|
-
end
|
465
|
-
|
466
|
-
#####
|
467
|
-
|
468
|
-
if items['search_ahead'].key?('icon_action')
|
469
|
-
iconAction = items['search_ahead']['icon_action']
|
470
|
-
end
|
471
|
-
|
472
|
-
if items.key?('events') && items['events'].key?('onkeyup')
|
473
|
-
keyUp = items['events']['onkeyup'] + ';'
|
474
|
-
else
|
475
|
-
keyUp = ''
|
476
|
-
end
|
477
|
-
|
478
|
-
if items['search_ahead'].key?('onkeyup') && !items['search_ahead']['onkeyup'].empty?
|
479
|
-
items['events']['onkeyup'] = keyUp + items['search_ahead']['onkeyup']
|
480
|
-
else
|
481
|
-
if items['list-search']
|
482
|
-
items['events']['onkeyup'] = keyUp + "SearchWidgetList('#{items['search_ahead']['url']}', '#{items['search_ahead']['target']}', this);"
|
483
|
-
elsif items['search_ahead'].key?('skip_queue') && items['search_ahead']['skip_queue']
|
484
|
-
items['events']['onkeyup'] = keyUp + "WidgetInputSearchAhead('#{items['search_ahead']['url']}', '#{items['search_ahead']['target']}', this);"
|
485
|
-
else
|
486
|
-
items['events']['onkeyup'] = keyUp + "WidgetInputSearchAheadQueue('#{items['search_ahead']['url']}', '#{items['search_ahead']['target']}', this);"
|
487
|
-
end
|
488
|
-
end
|
489
|
-
|
490
|
-
if !items['events']['onkeyup'].empty?
|
491
|
-
iconAction = items['events']['onkeyup']
|
492
|
-
end
|
493
|
-
|
494
|
-
if items['search_ahead'].key?('onclick')
|
495
|
-
items['events']['onclick'] = items['search_ahead']['onclick']
|
496
|
-
end
|
497
|
-
|
498
|
-
items['input_class'] += ' search-ahead'
|
499
|
-
|
500
|
-
# Modify the width a bit to compensate for the search icon
|
501
|
-
#
|
502
|
-
items['width'] = items['width'].to_i - 30
|
503
|
-
|
504
|
-
# Build advanced searching
|
505
|
-
#
|
506
|
-
if ! items['search_ahead']['search_form'].empty?
|
507
|
-
if items['list-search']
|
508
|
-
items['arrow_extra_class'] += ' widget-search-arrow-advanced'
|
509
|
-
else
|
510
|
-
items['arrow_extra_class'] += ' widget-search-arrow-advanced-no-search'
|
511
|
-
end
|
512
|
-
|
513
|
-
items['icon_extra_class'] += ' widget-search-magnifier-advanced'
|
514
|
-
items['input_class'] += ' search-ahead-advanced'
|
515
|
-
end
|
516
|
-
|
517
|
-
end
|
518
|
-
|
519
|
-
#
|
520
|
-
# Mandatory For outer boundary and IE7
|
521
|
-
#
|
522
|
-
# @todo should be css MW 5/2012
|
523
|
-
#
|
524
|
-
items['style'] += "width:#{items['width']}px"
|
525
|
-
|
526
|
-
if !items['required']
|
527
|
-
items['template_required'] = ''
|
528
|
-
end
|
529
|
-
|
530
|
-
if items['disabled']
|
531
|
-
items['input_class'] += ' disabled'
|
532
|
-
end
|
533
|
-
|
534
|
-
if !items['add_class'].empty?
|
535
|
-
items['class'] += ' ' + items['add_class']
|
536
|
-
end
|
537
|
-
|
538
|
-
if items['hidden']
|
539
|
-
items['style'] += ' display:none'
|
540
|
-
end
|
541
|
-
|
542
|
-
if !items['events'].empty? && items['events'].is_a?(Hash)
|
543
|
-
items['event_attributes'] = ''
|
544
|
-
items['events'].each { |event,action|
|
545
|
-
items['event_attributes'] += ' ' + event + '="' + action + '"' + ' '
|
546
|
-
}
|
547
|
-
end
|
548
|
-
|
549
|
-
if ! items['search_ahead'].key?('search_form')
|
550
|
-
items['search_ahead']['search_form'] = ''
|
551
|
-
end
|
552
|
-
|
553
|
-
WidgetList::Utils::fill({
|
554
|
-
'<!--READONLY-->' => (items['readonly']) ? 'readonly' : '',
|
555
|
-
'<!--OUTER_ID-->' => items['outer_id'],
|
556
|
-
'<!--OUTER_CLASS-->' => items['class'],
|
557
|
-
'<!--OUTER_STYLE-->' => items['style'],
|
558
|
-
'<!--INNER_CLASS-->' => items['inner_class'],
|
559
|
-
'<!--INNER_STYLE-->' => items['inner_style'],
|
560
|
-
'<!--INPUT_CLASS-->' => items['input_class'],
|
561
|
-
'<!--INPUT_STYLE-->' => items['input_style'],
|
562
|
-
'<!--ID-->' => items['id'],
|
563
|
-
'<!--NAME-->' => items['name'],
|
564
|
-
'<!--TITLE-->' => items['title'],
|
565
|
-
'<!--MAX_LENGTH-->' => items['max_length'],
|
566
|
-
'<!--ONKEYUP-->' => onkeyup,
|
567
|
-
'<!--SEARCH_FORM-->' => items['search_ahead']['search_form'],
|
568
|
-
'<!--VALUE-->' => items['value'],
|
569
|
-
'<!--REQUIRED-->' => items['template_required'],
|
570
|
-
'<!--ICON_ACTION-->' => iconAction,
|
571
|
-
'<!--OUTER_ACTION-->' => outerAction,
|
572
|
-
'<!--EVENT_ATTRIBUTES-->' => items['event_attributes'],
|
573
|
-
'<!--INPUT_TYPE-->' => items['input_type'],
|
574
|
-
'<!--ARROW_EXTRA_CLASS-->' => items['arrow_extra_class'],
|
575
|
-
'<!--ARROW_ACTION-->' => items['arrow_action'],
|
576
|
-
'<!--ICON_EXTRA_CLASS-->' => items['icon_extra_class']
|
577
|
-
} ,
|
578
|
-
items['template']
|
579
|
-
)
|
580
|
-
|
581
|
-
end
|
582
|
-
|
583
|
-
def self.populate_items(list,items)
|
584
|
-
unless list.nil?
|
585
|
-
list.each { |k,v|
|
586
|
-
if list.key?(k)
|
587
|
-
items[k] = v
|
588
|
-
end
|
589
|
-
}
|
590
|
-
end
|
591
|
-
items
|
592
|
-
end
|
593
|
-
|
594
|
-
def self.validate_items(list,items)
|
595
|
-
valid = true
|
596
|
-
unless items.empty?
|
597
|
-
items.each { |k,v|
|
598
|
-
if !list.to_s.empty? && !list.key?(k)
|
599
|
-
valid = false
|
600
|
-
throw "Required item '#{k.to_s}' only passed in #{items.inspect}"
|
601
|
-
end
|
602
|
-
}
|
603
|
-
end
|
604
|
-
|
605
|
-
if list.to_s.empty? && !items.empty?
|
606
|
-
valid = false
|
607
|
-
throw "Required items are needing to be passed #{items.inspect} are all required for this function"
|
608
|
-
end
|
609
|
-
return valid
|
610
|
-
end
|
611
|
-
|
612
|
-
# WidgetButton
|
613
|
-
def self.widget_button(text='', list={}, small=false)
|
614
|
-
items = {
|
615
|
-
'label' => text,
|
616
|
-
'name' => '',
|
617
|
-
'id' => '',
|
618
|
-
'url' => '',
|
619
|
-
'link' => '', #alias of url
|
620
|
-
'href' => '', #alias of url
|
621
|
-
'page' => '',
|
622
|
-
'parameters' => false,
|
623
|
-
'style' => 'display:inline-block',
|
624
|
-
'frmSubmit' => '', #this option adds hidden frmbutton
|
625
|
-
'submit' => '',
|
626
|
-
'args' => {},
|
627
|
-
'class' => 'btn', #Always stays the same
|
628
|
-
'innerClass' => 'info', #.primary(blue) .info(light-blue) .success(green) .danger(red) .disabled(light grey) .default(grey)
|
629
|
-
'passive' => false,
|
630
|
-
'function' => 'ButtonLinkPost',
|
631
|
-
'onclick' => '',
|
632
|
-
'onmouseover'=> '',
|
633
|
-
'onmouseout' => '',
|
634
|
-
'template' => ''
|
635
|
-
}
|
636
|
-
|
637
|
-
items = populate_items(list,items)
|
638
|
-
|
639
|
-
if items.key?('submit') && !items['submit'].empty?
|
640
|
-
items['onclick'] = "ButtonFormPost('#{list['submit']}');"
|
641
|
-
end
|
642
|
-
|
643
|
-
if items['template'].empty?
|
644
|
-
theClass = ''
|
645
|
-
if small
|
646
|
-
theClass = items['class'] + " small " + items['innerClass']
|
647
|
-
elsif ! items['class'].empty?
|
648
|
-
theClass = items['class'] + " " + items['innerClass']
|
649
|
-
end
|
650
|
-
items['template'] = $G_TEMPLATE['widget']['button']['default']
|
651
|
-
else
|
652
|
-
theClass = items['class']
|
653
|
-
end
|
654
|
-
|
655
|
-
if items['url'].empty? && !items['page'].empty?
|
656
|
-
items['url'] = WidgetList::Utils::build_url(items['page'], items['args'])
|
657
|
-
end
|
658
|
-
|
659
|
-
if !items['href'].empty? && items['onclick'].empty?
|
660
|
-
items['onclick'] = items['function'] + "('#{items['href']}')"
|
661
|
-
end
|
662
|
-
|
663
|
-
if !items['url'].empty? && items['onclick'].empty?
|
664
|
-
items['onclick'] = items['function'] + "('#{items['url']}')"
|
665
|
-
end
|
666
|
-
|
667
|
-
if !items['link'].empty? && items['onclick'].empty?
|
668
|
-
items['onclick'] = items['function'] + "('#{items['link']}')"
|
669
|
-
end
|
670
|
-
|
671
|
-
if items['parameters'] && !items['args'].empty? && items['args'].is_a?(Hash)
|
672
|
-
parameters = []
|
673
|
-
items['args'].each {|k,parameter|
|
674
|
-
if (parameter == 'this' || (parameter =~ /function/) && parameter =~ /\{/ && parameter =~ /\}/)
|
675
|
-
parameters << parameter.to_s
|
676
|
-
else
|
677
|
-
tmp = "'" + parameter.to_s + "'"
|
678
|
-
parameters << tmp
|
679
|
-
end
|
680
|
-
}
|
681
|
-
items['onclick'] = items['function'] + "(" + parameters.join(',') + ")"
|
682
|
-
end
|
683
|
-
|
684
|
-
if !items['frmSubmit'].empty?
|
685
|
-
items['frmSubmit'] = "<input type=\"submit\" value=\"\" style=\"position: absolute; float: left; z-index: -1;\"/> "
|
686
|
-
end
|
687
|
-
|
688
|
-
WidgetList::Utils::fill({
|
689
|
-
'<!--BUTTON_CLASS-->' => theClass,
|
690
|
-
'<!--BUTTON_ONCLICK-->' => items['onclick'].gsub(/\"/,"'"),
|
691
|
-
'<!--BUTTON_LABEL-->' => items['label'],
|
692
|
-
'<!--NAME-->' => items['name'],
|
693
|
-
'<!--ID-->' => items['id'],
|
694
|
-
'<!--BUTTON_STYLE-->' => items['style'],
|
695
|
-
'<!--BUTTON_CLASS_INNER-->' => items['innerClass'],
|
696
|
-
'<!--MOUSEOVER-->' => items['onmouseover'],
|
697
|
-
'<!--MOUSEOUT-->' => items['onmouseout'],
|
698
|
-
'<!--FRM_SUBMIT-->' => items['frmSubmit'],
|
699
|
-
},
|
700
|
-
items['template']
|
701
|
-
)
|
702
|
-
end
|
703
|
-
|
704
|
-
def self.test_all
|
705
|
-
output_final = ''
|
706
|
-
output_final += "error1" if $G_TEMPLATE['widget']['input']['search'].nil?
|
707
|
-
output_final += "error2" if $G_TEMPLATE['widget']['input']['default'].nil?
|
708
|
-
output_final += "error3" if $G_TEMPLATE['widget']['radio']['default'].nil?
|
709
|
-
output_final += "error4" if $G_TEMPLATE['widget']['checkbox']['default'].nil?
|
710
|
-
output_final += "error5" if $G_TEMPLATE['widget']['selectbox_nostyle']['wrapper'].nil?
|
711
|
-
output_final += "error6" if $G_TEMPLATE['widget']['selectbox']['wrapper'].nil?
|
712
|
-
output_final += "error7" if $G_TEMPLATE['widget']['selectbox']['option'].nil?
|
713
|
-
output_final += "error8" if $G_TEMPLATE['widget']['selectbox']['option'].nil?
|
714
|
-
output_final += "error9" if $G_TEMPLATE['widget']['selectbox']['option_showid'].nil?
|
715
|
-
output_final += "error10" if $G_TEMPLATE['widget']['selectbox']['option_showid_left'].nil?
|
716
|
-
output_final += "error11" if $G_TEMPLATE['widget']['selectbox']['initial'].nil?
|
717
|
-
output_final += "error12" if $G_TEMPLATE['widget']['selectbox']['passive'].nil?
|
718
|
-
output_final += "error13" if $G_TEMPLATE['widget']['selectfreeflow']['wrapper'].nil?
|
719
|
-
output_final += "error14" if $G_TEMPLATE['widget']['button']['default'].nil?
|
720
|
-
output_final += "error15" if $G_TEMPLATE['widget']['container']['row'].nil?
|
721
|
-
output_final += "error16" if $G_TEMPLATE['widget']['container']['col']['pre_text'].nil?
|
722
|
-
output_final += "error17" if $G_TEMPLATE['widget']['container']['col']['standard'].nil?
|
723
|
-
output_final += "error18" if $G_TEMPLATE['widget']['container']['wrapper'].nil?
|
724
|
-
|
725
|
-
#test submit
|
726
|
-
output_final += WidgetList::Widgets::widget_button('asfdsaf', {'id'=>'asdfasdf','submit'=>'213131'}) + "<br/><br/>"
|
727
|
-
|
728
|
-
#test arguments
|
729
|
-
output_final += WidgetList::Widgets::widget_button('asfdsaf', {'parameters'=>true,'args'=>{'dave'=>'123','dan'=>'1234'}}) + "<br/><br/>"
|
730
|
-
|
731
|
-
#test arguments with JS func
|
732
|
-
output_final += WidgetList::Widgets::widget_button('asfdsaf', {'parameters'=>true,'args'=> {'dave'=>'function() { alert(0); } '} } ) + "<br/><br/>"
|
733
|
-
|
734
|
-
output_final += WidgetList::Widgets::widget_button('asfdsaf', {'name'=>'asdfasf', 'id'=>'asfdasdf', 'parameters'=>true,'args'=> {'dave'=>'function() { alert(0); } '} }, true) + "<br/><br/>"
|
735
|
-
|
736
|
-
input = {}
|
737
|
-
input['list-search'] = true
|
738
|
-
input['width'] = '300'
|
739
|
-
input['input_class'] = 'info-input'
|
740
|
-
input['title'] = 'test search'
|
741
|
-
input['id'] = 'list_search_id_'
|
742
|
-
input['name'] = 'list_search_name_'
|
743
|
-
input['value'] = 'asfdasd'
|
744
|
-
input['class'] = 'inputOuter widget-search-outer -search'
|
745
|
-
input['search_ahead'] = {
|
746
|
-
'url' => 'http://google.com',
|
747
|
-
'skip_queue' => false,
|
748
|
-
'target' => 'test',
|
749
|
-
'search_form' => '',
|
750
|
-
'onclick' => ''
|
751
|
-
}
|
752
|
-
output_final += WidgetList::Widgets::widget_input(input) + "<br/><br/>"
|
753
|
-
|
754
|
-
output_final
|
755
|
-
end
|
756
|
-
end
|
1
|
+
module WidgetList
|
2
|
+
class Widgets
|
3
|
+
|
4
|
+
#todo - WidgetRadio, WidgetData?
|
5
|
+
|
6
|
+
# WidgetCheck
|
7
|
+
def self.widget_check(list={})
|
8
|
+
|
9
|
+
items = { 'name' => '',
|
10
|
+
'id' => '',
|
11
|
+
'value' => '',
|
12
|
+
'width' => '',
|
13
|
+
'disabled' => false,
|
14
|
+
'hidden' => false,
|
15
|
+
'required' => false,
|
16
|
+
'checked' => false,
|
17
|
+
'max_length' => '',
|
18
|
+
'title' => '',
|
19
|
+
'class' => '',
|
20
|
+
'style' => '',
|
21
|
+
'onclick' => '',
|
22
|
+
'input_style' => '',
|
23
|
+
'input_class' => '',
|
24
|
+
'template' => '',
|
25
|
+
}
|
26
|
+
|
27
|
+
items['template_required'] = $G_TEMPLATE['widget']['required']
|
28
|
+
|
29
|
+
items['template'] = $G_TEMPLATE['widget']['checkbox']['default']
|
30
|
+
|
31
|
+
items = populate_items(list,items)
|
32
|
+
|
33
|
+
if !items['required']
|
34
|
+
items['template_required'] = ''
|
35
|
+
end
|
36
|
+
|
37
|
+
if items['checked'] == true
|
38
|
+
items['checked'] = 'checked'
|
39
|
+
end
|
40
|
+
|
41
|
+
if !items['class'].empty?
|
42
|
+
items['input_class'] = items['class']
|
43
|
+
end
|
44
|
+
|
45
|
+
if items['disabled']
|
46
|
+
items['disabled'] = 'disabled'
|
47
|
+
else
|
48
|
+
items['disabled'] = ''
|
49
|
+
end
|
50
|
+
|
51
|
+
if items['hidden'] == true
|
52
|
+
items['style'] += ' display:none'
|
53
|
+
end
|
54
|
+
|
55
|
+
pieces = {
|
56
|
+
'<!--INPUT_CLASS-->' => items['input_class'],
|
57
|
+
'<!--INPUT_STYLE-->' => items['input_style'],
|
58
|
+
'<!--ID-->' => items['id'],
|
59
|
+
'<!--NAME-->' => items['name'],
|
60
|
+
'<!--TITLE-->' => items['title'],
|
61
|
+
'<!--ONCLICK-->' => items['onclick'],
|
62
|
+
'<!--VALUE-->' => items['value'],
|
63
|
+
'<!--REQUIRED-->' => items['template_required'],
|
64
|
+
'<!--CHECKED-->' => items['checked'],
|
65
|
+
'<!--VALUE-->' => items['value'],
|
66
|
+
'<!--DISABLED-->' => items['disabled']
|
67
|
+
}
|
68
|
+
|
69
|
+
return WidgetList::Utils::fill(pieces, items['template'])
|
70
|
+
end
|
71
|
+
|
72
|
+
# WidgetSelect - todo - never tested one line of code in here!!!
|
73
|
+
def self.widget_select(sql = '', list={})
|
74
|
+
valid = true
|
75
|
+
selectOutput = []
|
76
|
+
|
77
|
+
#Parameter evaluation identification
|
78
|
+
#
|
79
|
+
if list.empty? && sql.class.name == 'Hash'
|
80
|
+
list = sql
|
81
|
+
end
|
82
|
+
|
83
|
+
if ! sql.empty? && ! list.key?('sql') && ! list.key?('view')
|
84
|
+
list['sql'] = sql
|
85
|
+
end
|
86
|
+
|
87
|
+
#
|
88
|
+
# Default configurations
|
89
|
+
#
|
90
|
+
items = {}
|
91
|
+
|
92
|
+
items['name'] = ''
|
93
|
+
items['id'] = ''
|
94
|
+
items['multiple'] = false
|
95
|
+
items['insertUnknown'] = false
|
96
|
+
items['required'] = ''
|
97
|
+
items['strLenBrk'] = 50
|
98
|
+
items['optGroupIndicator'] = ''
|
99
|
+
items['label'] = ''
|
100
|
+
items['selectTxt'] = 'Select One'
|
101
|
+
items['showId'] = false
|
102
|
+
items['showIdLeft'] = false
|
103
|
+
items['passive'] = false
|
104
|
+
items['freeflow'] = false
|
105
|
+
items['no_style'] = false
|
106
|
+
|
107
|
+
#
|
108
|
+
# Select box attributes
|
109
|
+
#
|
110
|
+
items['attribs'] = {}
|
111
|
+
items['size'] = 1
|
112
|
+
items['disabled'] = false
|
113
|
+
items['noDataMsg'] = 'No Data'
|
114
|
+
items['selectOne'] = 0
|
115
|
+
items['selected'] = {}
|
116
|
+
|
117
|
+
#
|
118
|
+
# SQL
|
119
|
+
#
|
120
|
+
items['bindVars'] = {}
|
121
|
+
items['view'] = ''
|
122
|
+
items['sql'] = ''
|
123
|
+
items['orderBy'] = ''
|
124
|
+
items['filter'] = ''
|
125
|
+
|
126
|
+
#
|
127
|
+
# Actions
|
128
|
+
#
|
129
|
+
items['onchange'] = ''
|
130
|
+
items['onclick'] = ''
|
131
|
+
|
132
|
+
#
|
133
|
+
# Style
|
134
|
+
#
|
135
|
+
items['style'] = '' #meant for internal use as nothing is appended only replaced.
|
136
|
+
items['inner_class'] = 'select-inner' #Left long piece of image
|
137
|
+
items['outer_class'] = 'select-outer' #Right corner of image
|
138
|
+
items['outer_style'] = '' #Basically the width of the select box ends up here
|
139
|
+
items['extra_class'] = '' #Not used currently
|
140
|
+
items['width'] = 184 #width of the select-outer element
|
141
|
+
|
142
|
+
#
|
143
|
+
# @deprecated
|
144
|
+
#
|
145
|
+
items['class'] = ''
|
146
|
+
|
147
|
+
|
148
|
+
#
|
149
|
+
# Setup templates
|
150
|
+
#
|
151
|
+
if items['freeflow']
|
152
|
+
#
|
153
|
+
# Freeflow
|
154
|
+
#
|
155
|
+
items['template']['wrapper'] = $G_TEMPLATE['widget']['selectfree']['wrapper']
|
156
|
+
items['template']['option'] = $G_TEMPLATE['widget']['selectfree']['option']
|
157
|
+
items['template']['initial'] = ''
|
158
|
+
items['template']['passive'] = ''
|
159
|
+
else
|
160
|
+
#
|
161
|
+
# Standard
|
162
|
+
#
|
163
|
+
items['template']['wrapper'] = $G_TEMPLATE['widget']['selectbox']['wrapper']
|
164
|
+
items['template']['option'] = $G_TEMPLATE['widget']['selectbox']['option']
|
165
|
+
items['template']['initial'] = $G_TEMPLATE['widget']['selectbox']['initial']
|
166
|
+
items['template']['passive'] = $G_TEMPLATE['widget']['selectbox']['passive']
|
167
|
+
end
|
168
|
+
|
169
|
+
# if numeric or string passed, convert to array
|
170
|
+
if list.key?('selected') && list['selected'].class.name != 'Array'
|
171
|
+
list['selected'] = [ list['selected'] ]
|
172
|
+
end
|
173
|
+
|
174
|
+
#
|
175
|
+
# Merge settings
|
176
|
+
#
|
177
|
+
items = populate_items(list,items)
|
178
|
+
|
179
|
+
if items['no_style']
|
180
|
+
items['template']['wrapper'] = $G_TEMPLATE['widget']['selectbox_nostyle']['wrapper']
|
181
|
+
end
|
182
|
+
|
183
|
+
|
184
|
+
#
|
185
|
+
# If multiple then override above settings and classes
|
186
|
+
#
|
187
|
+
if items['multiple']
|
188
|
+
items['outer_style'] = ';width:280px;'
|
189
|
+
items['width'] = 280
|
190
|
+
|
191
|
+
items['inner_class'] = 'select-inner-multiple'
|
192
|
+
items['outer_class'] = 'select-outer-multiple'
|
193
|
+
end
|
194
|
+
|
195
|
+
if items['showId']
|
196
|
+
items['template']['option'] = $G_TEMPLATE['widget']['selectbox']['option_showid']
|
197
|
+
end
|
198
|
+
|
199
|
+
if items['showIdLeft']
|
200
|
+
items['template']['option'] = $G_TEMPLATE['widget']['selectbox']['option_showid_left']
|
201
|
+
end
|
202
|
+
|
203
|
+
if items['disabled']
|
204
|
+
items['disabled'] = 'disabled="disabled"'
|
205
|
+
items['class'] += ' disabled'
|
206
|
+
end
|
207
|
+
|
208
|
+
if items['multiple']
|
209
|
+
items['multiple'] = 'multiple="multiple"'
|
210
|
+
end
|
211
|
+
|
212
|
+
if items['required']
|
213
|
+
items['required'] = $G_TEMPLATE['widget']['required']
|
214
|
+
end
|
215
|
+
|
216
|
+
if ! items['sql'].empty?
|
217
|
+
sql = items['sql']
|
218
|
+
elsif !items['view'].empty?
|
219
|
+
sql = "SELECT id, value FROM " + items['view']
|
220
|
+
else
|
221
|
+
valid = false
|
222
|
+
end
|
223
|
+
|
224
|
+
if ! items['filter'].empty?
|
225
|
+
sql += ' WHERE ' + items['filter'].join(' AND ')
|
226
|
+
end
|
227
|
+
|
228
|
+
if ! items['orderBy'].empty?
|
229
|
+
sql += ' ORDER BY ' + items['orderBy']
|
230
|
+
end
|
231
|
+
|
232
|
+
rows = WidgetList::List.get_database._select(sql, [], items['bindVars'])
|
233
|
+
selectRows = WidgetList::List.get_database.final_results
|
234
|
+
|
235
|
+
|
236
|
+
if rows > 0 && valid
|
237
|
+
if ! items['passive']
|
238
|
+
addedGroup = false
|
239
|
+
groupByRow = false
|
240
|
+
groupByValue = -1
|
241
|
+
if selectRows.key?('GROUPING_VAL')
|
242
|
+
groupByRow = true
|
243
|
+
end
|
244
|
+
|
245
|
+
max = rows-1
|
246
|
+
|
247
|
+
selected = ''
|
248
|
+
|
249
|
+
if (items['selectOne'] > 0 || (items['selectOne'].class.name == 'Array' && ! items['selectOne'].empty?) && ! items['freeflow'])
|
250
|
+
theVal = ''
|
251
|
+
theClk = ''
|
252
|
+
theSel = ''
|
253
|
+
theTxt = items['selectTxt']
|
254
|
+
|
255
|
+
if items['selectOne'].class.name == 'Array'
|
256
|
+
if(items['selectOne'].key?('text'))
|
257
|
+
theTxt = items['selectOne']['text']
|
258
|
+
end
|
259
|
+
|
260
|
+
if(items['selectOne'].key?('value'))
|
261
|
+
theVal = items['selectOne']['value']
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
pieces = { '<!--VALUE-->' => theVal,
|
266
|
+
'<!--ONCLICK-->' => theClk,
|
267
|
+
'<!--SELECTED-->' => theSel,
|
268
|
+
'<!--CONTENT-->' => theTxt
|
269
|
+
}
|
270
|
+
|
271
|
+
|
272
|
+
selectOutput << WidgetList::Utils::fill(pieces, items['template']['initial'])
|
273
|
+
end
|
274
|
+
|
275
|
+
hasASelectedMatch = false
|
276
|
+
startedGrouping = false
|
277
|
+
i = 0
|
278
|
+
for i in j..max
|
279
|
+
if items['selected'].class.name == 'Array' && items['selected'].count > 0
|
280
|
+
if items['selected'].include?(selectRows['ID'][i]) || items['selected'].include?(selectRows['VALUE'][i])
|
281
|
+
hasASelectedMatch = true
|
282
|
+
selected = ' selected'
|
283
|
+
end
|
284
|
+
end
|
285
|
+
|
286
|
+
if selectRows['VALUE'][i].length > items['strLenBrk']
|
287
|
+
first = CGI.escapeHTML(selectRows['VALUE'][i].to_s[0,10])
|
288
|
+
last = CGI.escapeHTML(selectRows['VALUE'][i].to_s[-40])
|
289
|
+
content = first + '...' + last
|
290
|
+
else
|
291
|
+
content = CGI.escapeHTML(selectRows['VALUE'][i])
|
292
|
+
end
|
293
|
+
|
294
|
+
pieces = {
|
295
|
+
'<!--VALUE-->' => selectRows['ID'][i],
|
296
|
+
'<!--ONCLICK-->' => items['onclick'],
|
297
|
+
'<!--SELECTED-->' => selected,
|
298
|
+
'<!--CONTENT-->' => content,
|
299
|
+
'<!--COUNTER-->' => i,
|
300
|
+
'<!--NAME-->' => items['name'],
|
301
|
+
}
|
302
|
+
|
303
|
+
|
304
|
+
if groupByRow
|
305
|
+
if selectRows['GROUPING_VAL'][i] != groupByValue
|
306
|
+
if (addedGroup)
|
307
|
+
selectOutput << '</optgroup>'
|
308
|
+
end
|
309
|
+
|
310
|
+
addedGroup = true
|
311
|
+
# Start new optgroup
|
312
|
+
groupByValue = selectRows['GROUPING_VAL'][i]
|
313
|
+
|
314
|
+
selectOutput << '<optgroup label="' + groupByValue + '">'
|
315
|
+
selectOutput << WidgetList::Utils::fill(pieces, items['template']['option'])
|
316
|
+
else
|
317
|
+
selectOutput << WidgetList::Utils::fill(pieces, items['template']['option'])
|
318
|
+
end
|
319
|
+
else
|
320
|
+
if selectRows['ID'][i] === 'GROUPING'
|
321
|
+
# Output OPTGROUP tags and labels no one can select this
|
322
|
+
if startedGrouping
|
323
|
+
selectOutput << '</optgroup>'
|
324
|
+
end
|
325
|
+
selectOutput << '<optgroup label="' + selectRows['VALUE'][i] + '">'
|
326
|
+
startedGrouping = true
|
327
|
+
else
|
328
|
+
# Output regular option tag
|
329
|
+
selectOutput << WidgetList::Utils::fill(pieces, items['template']['option'])
|
330
|
+
end
|
331
|
+
end
|
332
|
+
|
333
|
+
selected = ''
|
334
|
+
end
|
335
|
+
|
336
|
+
if (groupByRow && addedGroup)
|
337
|
+
selectOutput << '</optgroup>'
|
338
|
+
end
|
339
|
+
|
340
|
+
if hasASelectedMatch === false && items['insertUnknown'] === true
|
341
|
+
# in this mode, you wish to inject an option into the select box even though the results didnt find the match
|
342
|
+
|
343
|
+
|
344
|
+
items['selected'].each{ |vals|
|
345
|
+
pieces = {
|
346
|
+
'<!--VALUE-->' => vals,
|
347
|
+
'<!--ONCLICK-->' => items['onclick'],
|
348
|
+
'<!--SELECTED-->' => ' selected ',
|
349
|
+
'<!--CONTENT-->' => vals
|
350
|
+
}
|
351
|
+
selectOutput << WidgetList::Utils::fill(pieces, items['template']['option'])
|
352
|
+
}
|
353
|
+
end
|
354
|
+
end
|
355
|
+
else
|
356
|
+
pieces = {
|
357
|
+
'<!--VALUE-->' => '',
|
358
|
+
'<!--ONCLICK-->' => items['onclick'],
|
359
|
+
'<!--SELECTED-->' => '',
|
360
|
+
'<!--CONTENT-->' => items['noDataMsg']
|
361
|
+
}
|
362
|
+
|
363
|
+
selectOutput << WidgetList::Utils::fill(pieces, items['template']['initial'])
|
364
|
+
end
|
365
|
+
|
366
|
+
if items['id'].empty? && ! items['name'].empty?
|
367
|
+
items['id'] = items['name']
|
368
|
+
end
|
369
|
+
|
370
|
+
|
371
|
+
pieces = { '<!--SIZE-->' => items['size'],
|
372
|
+
'<!--ID-->' => items['id'],
|
373
|
+
'<!--NAME-->' => items['name'],
|
374
|
+
'<!--MULTIPLE-->' => items['multiple'],
|
375
|
+
'<!--OPTIONS-->' => selectOutput.join(''),
|
376
|
+
'<!--ONCHANGE-->' => items['onchange'],
|
377
|
+
'<!--REQUIRED-->' => items['required'],
|
378
|
+
'<!--CLASS-->' => items['class'],
|
379
|
+
'<!--DISABLED_FLG-->' => items['disabled'],
|
380
|
+
'<!--STYLE-->' => items['style'],
|
381
|
+
'<!--ATTRIBUTES-->' => items['attribs'].join(' '),
|
382
|
+
'<!--INNER_CLASS-->' => items['inner_class'],
|
383
|
+
'<!--OUTER_CLASS-->' => items['outer_class'],
|
384
|
+
'<!--OUTER_STYLE-->' => items['outer_style'],
|
385
|
+
'<!--INNER_STYLE-->' => '',
|
386
|
+
'<!--OUTER_ACTION-->' => ''
|
387
|
+
}
|
388
|
+
|
389
|
+
finalTemplate = items['template']['wrapper']
|
390
|
+
|
391
|
+
if items['passive'] && items['selected'].class.name == 'Array' && items['selected'].count > 0
|
392
|
+
#passKeys = array_keys(selectRows['ID'], items['selected'][0])
|
393
|
+
#pieces['<!--OPTIONS-->'] = selectRows['VALUE'][passKeys[0]]
|
394
|
+
finalTemplate = items['template']['passive']
|
395
|
+
end
|
396
|
+
|
397
|
+
WidgetList::Utils::fill(pieces, finalTemplate)
|
398
|
+
end
|
399
|
+
|
400
|
+
# WidgetInput
|
401
|
+
def self.widget_input(list={})
|
402
|
+
items = {
|
403
|
+
'name' => '',
|
404
|
+
'id' => '',
|
405
|
+
'outer_id' => '',
|
406
|
+
'value' => '',
|
407
|
+
'input_type' => 'text', #hidden
|
408
|
+
'width' => '150',
|
409
|
+
'readonly' => false,
|
410
|
+
'disabled' => false,
|
411
|
+
'hidden' => false,
|
412
|
+
'required' => false,
|
413
|
+
'list-search' => false,
|
414
|
+
'max_length' => '',
|
415
|
+
'events' => {},
|
416
|
+
'title' => '',
|
417
|
+
'add_class' => '',
|
418
|
+
'class' => 'inputOuter',
|
419
|
+
'inner_class' => 'inputInner',
|
420
|
+
'outer_onclick'=> '',
|
421
|
+
'style' => '',
|
422
|
+
'inner_style' => '',
|
423
|
+
'input_style' => '',
|
424
|
+
'input_class' => '',
|
425
|
+
'template' => '',
|
426
|
+
'search_ahead' => {},
|
427
|
+
'search_form' => '',
|
428
|
+
'search_handle'=> '',
|
429
|
+
'arrow_extra_class'=> '',
|
430
|
+
'icon_extra_class'=> '',
|
431
|
+
'arrow_action' => ''
|
432
|
+
}
|
433
|
+
|
434
|
+
items['template_required'] = $G_TEMPLATE['widget']['required']
|
435
|
+
|
436
|
+
items['template'] = $G_TEMPLATE['widget']['input']['default']
|
437
|
+
|
438
|
+
items = populate_items(list,items)
|
439
|
+
|
440
|
+
iconAction = ''
|
441
|
+
outerAction = ''
|
442
|
+
onkeyup = ''
|
443
|
+
|
444
|
+
if ! items['outer_onclick'].empty?
|
445
|
+
outerAction = items['outer_onclick']
|
446
|
+
end
|
447
|
+
|
448
|
+
if ! items['search_ahead'].empty?
|
449
|
+
# Search Ahead Input
|
450
|
+
#
|
451
|
+
items['template'] = $G_TEMPLATE['widget']['input']['search']
|
452
|
+
|
453
|
+
fill = {}
|
454
|
+
if items['list-search']
|
455
|
+
fill['<!--MAGNIFIER-->'] = '<div class="widget-search-magnifier <!--ICON_EXTRA_CLASS-->" style="" onclick="<!--ICON_ACTION-->"></div>'
|
456
|
+
end
|
457
|
+
|
458
|
+
items['template'] = WidgetList::Utils::fill(fill,items['template'])
|
459
|
+
|
460
|
+
if ! items['search_ahead']['search_form'].empty?
|
461
|
+
if(items['arrow_action'].empty?)
|
462
|
+
items['arrow_action'] = "ToggleAdvancedSearch(this)"
|
463
|
+
end
|
464
|
+
end
|
465
|
+
|
466
|
+
#####
|
467
|
+
|
468
|
+
if items['search_ahead'].key?('icon_action')
|
469
|
+
iconAction = items['search_ahead']['icon_action']
|
470
|
+
end
|
471
|
+
|
472
|
+
if items.key?('events') && items['events'].key?('onkeyup')
|
473
|
+
keyUp = items['events']['onkeyup'] + ';'
|
474
|
+
else
|
475
|
+
keyUp = ''
|
476
|
+
end
|
477
|
+
|
478
|
+
if items['search_ahead'].key?('onkeyup') && !items['search_ahead']['onkeyup'].empty?
|
479
|
+
items['events']['onkeyup'] = keyUp + items['search_ahead']['onkeyup']
|
480
|
+
else
|
481
|
+
if items['list-search']
|
482
|
+
items['events']['onkeyup'] = keyUp + "SearchWidgetList('#{items['search_ahead']['url']}', '#{items['search_ahead']['target']}', this);"
|
483
|
+
elsif items['search_ahead'].key?('skip_queue') && items['search_ahead']['skip_queue']
|
484
|
+
items['events']['onkeyup'] = keyUp + "WidgetInputSearchAhead('#{items['search_ahead']['url']}', '#{items['search_ahead']['target']}', this);"
|
485
|
+
else
|
486
|
+
items['events']['onkeyup'] = keyUp + "WidgetInputSearchAheadQueue('#{items['search_ahead']['url']}', '#{items['search_ahead']['target']}', this);"
|
487
|
+
end
|
488
|
+
end
|
489
|
+
|
490
|
+
if !items['events']['onkeyup'].empty?
|
491
|
+
iconAction = items['events']['onkeyup']
|
492
|
+
end
|
493
|
+
|
494
|
+
if items['search_ahead'].key?('onclick')
|
495
|
+
items['events']['onclick'] = items['search_ahead']['onclick']
|
496
|
+
end
|
497
|
+
|
498
|
+
items['input_class'] += ' search-ahead'
|
499
|
+
|
500
|
+
# Modify the width a bit to compensate for the search icon
|
501
|
+
#
|
502
|
+
items['width'] = items['width'].to_i - 30
|
503
|
+
|
504
|
+
# Build advanced searching
|
505
|
+
#
|
506
|
+
if ! items['search_ahead']['search_form'].empty?
|
507
|
+
if items['list-search']
|
508
|
+
items['arrow_extra_class'] += ' widget-search-arrow-advanced'
|
509
|
+
else
|
510
|
+
items['arrow_extra_class'] += ' widget-search-arrow-advanced-no-search'
|
511
|
+
end
|
512
|
+
|
513
|
+
items['icon_extra_class'] += ' widget-search-magnifier-advanced'
|
514
|
+
items['input_class'] += ' search-ahead-advanced'
|
515
|
+
end
|
516
|
+
|
517
|
+
end
|
518
|
+
|
519
|
+
#
|
520
|
+
# Mandatory For outer boundary and IE7
|
521
|
+
#
|
522
|
+
# @todo should be css MW 5/2012
|
523
|
+
#
|
524
|
+
items['style'] += "width:#{items['width']}px"
|
525
|
+
|
526
|
+
if !items['required']
|
527
|
+
items['template_required'] = ''
|
528
|
+
end
|
529
|
+
|
530
|
+
if items['disabled']
|
531
|
+
items['input_class'] += ' disabled'
|
532
|
+
end
|
533
|
+
|
534
|
+
if !items['add_class'].empty?
|
535
|
+
items['class'] += ' ' + items['add_class']
|
536
|
+
end
|
537
|
+
|
538
|
+
if items['hidden']
|
539
|
+
items['style'] += ' display:none'
|
540
|
+
end
|
541
|
+
|
542
|
+
if !items['events'].empty? && items['events'].is_a?(Hash)
|
543
|
+
items['event_attributes'] = ''
|
544
|
+
items['events'].each { |event,action|
|
545
|
+
items['event_attributes'] += ' ' + event + '="' + action + '"' + ' '
|
546
|
+
}
|
547
|
+
end
|
548
|
+
|
549
|
+
if ! items['search_ahead'].key?('search_form')
|
550
|
+
items['search_ahead']['search_form'] = ''
|
551
|
+
end
|
552
|
+
|
553
|
+
WidgetList::Utils::fill({
|
554
|
+
'<!--READONLY-->' => (items['readonly']) ? 'readonly' : '',
|
555
|
+
'<!--OUTER_ID-->' => items['outer_id'],
|
556
|
+
'<!--OUTER_CLASS-->' => items['class'],
|
557
|
+
'<!--OUTER_STYLE-->' => items['style'],
|
558
|
+
'<!--INNER_CLASS-->' => items['inner_class'],
|
559
|
+
'<!--INNER_STYLE-->' => items['inner_style'],
|
560
|
+
'<!--INPUT_CLASS-->' => items['input_class'],
|
561
|
+
'<!--INPUT_STYLE-->' => items['input_style'],
|
562
|
+
'<!--ID-->' => items['id'],
|
563
|
+
'<!--NAME-->' => items['name'],
|
564
|
+
'<!--TITLE-->' => items['title'],
|
565
|
+
'<!--MAX_LENGTH-->' => items['max_length'],
|
566
|
+
'<!--ONKEYUP-->' => onkeyup,
|
567
|
+
'<!--SEARCH_FORM-->' => items['search_ahead']['search_form'],
|
568
|
+
'<!--VALUE-->' => items['value'],
|
569
|
+
'<!--REQUIRED-->' => items['template_required'],
|
570
|
+
'<!--ICON_ACTION-->' => iconAction,
|
571
|
+
'<!--OUTER_ACTION-->' => outerAction,
|
572
|
+
'<!--EVENT_ATTRIBUTES-->' => items['event_attributes'],
|
573
|
+
'<!--INPUT_TYPE-->' => items['input_type'],
|
574
|
+
'<!--ARROW_EXTRA_CLASS-->' => items['arrow_extra_class'],
|
575
|
+
'<!--ARROW_ACTION-->' => items['arrow_action'],
|
576
|
+
'<!--ICON_EXTRA_CLASS-->' => items['icon_extra_class']
|
577
|
+
} ,
|
578
|
+
items['template']
|
579
|
+
)
|
580
|
+
|
581
|
+
end
|
582
|
+
|
583
|
+
def self.populate_items(list,items)
|
584
|
+
unless list.nil?
|
585
|
+
list.each { |k,v|
|
586
|
+
if list.key?(k)
|
587
|
+
items[k] = v
|
588
|
+
end
|
589
|
+
}
|
590
|
+
end
|
591
|
+
items
|
592
|
+
end
|
593
|
+
|
594
|
+
def self.validate_items(list,items)
|
595
|
+
valid = true
|
596
|
+
unless items.empty?
|
597
|
+
items.each { |k,v|
|
598
|
+
if !list.to_s.empty? && !list.key?(k)
|
599
|
+
valid = false
|
600
|
+
throw "Required item '#{k.to_s}' only passed in #{items.inspect}"
|
601
|
+
end
|
602
|
+
}
|
603
|
+
end
|
604
|
+
|
605
|
+
if list.to_s.empty? && !items.empty?
|
606
|
+
valid = false
|
607
|
+
throw "Required items are needing to be passed #{items.inspect} are all required for this function"
|
608
|
+
end
|
609
|
+
return valid
|
610
|
+
end
|
611
|
+
|
612
|
+
# WidgetButton
|
613
|
+
def self.widget_button(text='', list={}, small=false)
|
614
|
+
items = {
|
615
|
+
'label' => text,
|
616
|
+
'name' => '',
|
617
|
+
'id' => '',
|
618
|
+
'url' => '',
|
619
|
+
'link' => '', #alias of url
|
620
|
+
'href' => '', #alias of url
|
621
|
+
'page' => '',
|
622
|
+
'parameters' => false,
|
623
|
+
'style' => 'display:inline-block;cursor:pointer;',
|
624
|
+
'frmSubmit' => '', #this option adds hidden frmbutton
|
625
|
+
'submit' => '',
|
626
|
+
'args' => {},
|
627
|
+
'class' => 'btn', #Always stays the same
|
628
|
+
'innerClass' => 'info', #.primary(blue) .info(light-blue) .success(green) .danger(red) .disabled(light grey) .default(grey)
|
629
|
+
'passive' => false,
|
630
|
+
'function' => 'ButtonLinkPost',
|
631
|
+
'onclick' => '',
|
632
|
+
'onmouseover'=> '',
|
633
|
+
'onmouseout' => '',
|
634
|
+
'template' => ''
|
635
|
+
}
|
636
|
+
|
637
|
+
items = populate_items(list,items)
|
638
|
+
|
639
|
+
if items.key?('submit') && !items['submit'].empty?
|
640
|
+
items['onclick'] = "ButtonFormPost('#{list['submit']}');"
|
641
|
+
end
|
642
|
+
|
643
|
+
if items['template'].empty?
|
644
|
+
theClass = ''
|
645
|
+
if small
|
646
|
+
theClass = items['class'] + " small " + items['innerClass']
|
647
|
+
elsif ! items['class'].empty?
|
648
|
+
theClass = items['class'] + " " + items['innerClass']
|
649
|
+
end
|
650
|
+
items['template'] = $G_TEMPLATE['widget']['button']['default']
|
651
|
+
else
|
652
|
+
theClass = items['class']
|
653
|
+
end
|
654
|
+
|
655
|
+
if items['url'].empty? && !items['page'].empty?
|
656
|
+
items['url'] = WidgetList::Utils::build_url(items['page'], items['args'])
|
657
|
+
end
|
658
|
+
|
659
|
+
if !items['href'].empty? && items['onclick'].empty?
|
660
|
+
items['onclick'] = items['function'] + "('#{items['href']}')"
|
661
|
+
end
|
662
|
+
|
663
|
+
if !items['url'].empty? && items['onclick'].empty?
|
664
|
+
items['onclick'] = items['function'] + "('#{items['url']}')"
|
665
|
+
end
|
666
|
+
|
667
|
+
if !items['link'].empty? && items['onclick'].empty?
|
668
|
+
items['onclick'] = items['function'] + "('#{items['link']}')"
|
669
|
+
end
|
670
|
+
|
671
|
+
if items['parameters'] && !items['args'].empty? && items['args'].is_a?(Hash)
|
672
|
+
parameters = []
|
673
|
+
items['args'].each {|k,parameter|
|
674
|
+
if (parameter == 'this' || (parameter =~ /function/) && parameter =~ /\{/ && parameter =~ /\}/)
|
675
|
+
parameters << parameter.to_s
|
676
|
+
else
|
677
|
+
tmp = "'" + parameter.to_s + "'"
|
678
|
+
parameters << tmp
|
679
|
+
end
|
680
|
+
}
|
681
|
+
items['onclick'] = items['function'] + "(" + parameters.join(',') + ")"
|
682
|
+
end
|
683
|
+
|
684
|
+
if !items['frmSubmit'].empty?
|
685
|
+
items['frmSubmit'] = "<input type=\"submit\" value=\"\" style=\"position: absolute; float: left; z-index: -1;\"/> "
|
686
|
+
end
|
687
|
+
|
688
|
+
WidgetList::Utils::fill({
|
689
|
+
'<!--BUTTON_CLASS-->' => theClass,
|
690
|
+
'<!--BUTTON_ONCLICK-->' => items['onclick'].gsub(/\"/,"'"),
|
691
|
+
'<!--BUTTON_LABEL-->' => items['label'],
|
692
|
+
'<!--NAME-->' => items['name'],
|
693
|
+
'<!--ID-->' => items['id'],
|
694
|
+
'<!--BUTTON_STYLE-->' => items['style'],
|
695
|
+
'<!--BUTTON_CLASS_INNER-->' => items['innerClass'],
|
696
|
+
'<!--MOUSEOVER-->' => items['onmouseover'],
|
697
|
+
'<!--MOUSEOUT-->' => items['onmouseout'],
|
698
|
+
'<!--FRM_SUBMIT-->' => items['frmSubmit'],
|
699
|
+
},
|
700
|
+
items['template']
|
701
|
+
)
|
702
|
+
end
|
703
|
+
|
704
|
+
def self.test_all
|
705
|
+
output_final = ''
|
706
|
+
output_final += "error1" if $G_TEMPLATE['widget']['input']['search'].nil?
|
707
|
+
output_final += "error2" if $G_TEMPLATE['widget']['input']['default'].nil?
|
708
|
+
output_final += "error3" if $G_TEMPLATE['widget']['radio']['default'].nil?
|
709
|
+
output_final += "error4" if $G_TEMPLATE['widget']['checkbox']['default'].nil?
|
710
|
+
output_final += "error5" if $G_TEMPLATE['widget']['selectbox_nostyle']['wrapper'].nil?
|
711
|
+
output_final += "error6" if $G_TEMPLATE['widget']['selectbox']['wrapper'].nil?
|
712
|
+
output_final += "error7" if $G_TEMPLATE['widget']['selectbox']['option'].nil?
|
713
|
+
output_final += "error8" if $G_TEMPLATE['widget']['selectbox']['option'].nil?
|
714
|
+
output_final += "error9" if $G_TEMPLATE['widget']['selectbox']['option_showid'].nil?
|
715
|
+
output_final += "error10" if $G_TEMPLATE['widget']['selectbox']['option_showid_left'].nil?
|
716
|
+
output_final += "error11" if $G_TEMPLATE['widget']['selectbox']['initial'].nil?
|
717
|
+
output_final += "error12" if $G_TEMPLATE['widget']['selectbox']['passive'].nil?
|
718
|
+
output_final += "error13" if $G_TEMPLATE['widget']['selectfreeflow']['wrapper'].nil?
|
719
|
+
output_final += "error14" if $G_TEMPLATE['widget']['button']['default'].nil?
|
720
|
+
output_final += "error15" if $G_TEMPLATE['widget']['container']['row'].nil?
|
721
|
+
output_final += "error16" if $G_TEMPLATE['widget']['container']['col']['pre_text'].nil?
|
722
|
+
output_final += "error17" if $G_TEMPLATE['widget']['container']['col']['standard'].nil?
|
723
|
+
output_final += "error18" if $G_TEMPLATE['widget']['container']['wrapper'].nil?
|
724
|
+
|
725
|
+
#test submit
|
726
|
+
output_final += WidgetList::Widgets::widget_button('asfdsaf', {'id'=>'asdfasdf','submit'=>'213131'}) + "<br/><br/>"
|
727
|
+
|
728
|
+
#test arguments
|
729
|
+
output_final += WidgetList::Widgets::widget_button('asfdsaf', {'parameters'=>true,'args'=>{'dave'=>'123','dan'=>'1234'}}) + "<br/><br/>"
|
730
|
+
|
731
|
+
#test arguments with JS func
|
732
|
+
output_final += WidgetList::Widgets::widget_button('asfdsaf', {'parameters'=>true,'args'=> {'dave'=>'function() { alert(0); } '} } ) + "<br/><br/>"
|
733
|
+
|
734
|
+
output_final += WidgetList::Widgets::widget_button('asfdsaf', {'name'=>'asdfasf', 'id'=>'asfdasdf', 'parameters'=>true,'args'=> {'dave'=>'function() { alert(0); } '} }, true) + "<br/><br/>"
|
735
|
+
|
736
|
+
input = {}
|
737
|
+
input['list-search'] = true
|
738
|
+
input['width'] = '300'
|
739
|
+
input['input_class'] = 'info-input'
|
740
|
+
input['title'] = 'test search'
|
741
|
+
input['id'] = 'list_search_id_'
|
742
|
+
input['name'] = 'list_search_name_'
|
743
|
+
input['value'] = 'asfdasd'
|
744
|
+
input['class'] = 'inputOuter widget-search-outer -search'
|
745
|
+
input['search_ahead'] = {
|
746
|
+
'url' => 'http://google.com',
|
747
|
+
'skip_queue' => false,
|
748
|
+
'target' => 'test',
|
749
|
+
'search_form' => '',
|
750
|
+
'onclick' => ''
|
751
|
+
}
|
752
|
+
output_final += WidgetList::Widgets::widget_input(input) + "<br/><br/>"
|
753
|
+
|
754
|
+
output_final
|
755
|
+
end
|
756
|
+
end
|
757
757
|
end
|