widget_list 1.0.6 → 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/lib/widget_list.rb CHANGED
@@ -1,4 +1,3 @@
1
- require 'widget_list/sequel'
2
1
  require 'widget_list/version'
3
2
  require 'widget_list/hash'
4
3
  require 'widget_list/string'
@@ -10,8 +9,6 @@ require 'csv'
10
9
  require 'json'
11
10
  require 'uri'
12
11
  require 'extensions/action_controller_base'
13
- require 'sequel'
14
-
15
12
 
16
13
  module WidgetList
17
14
 
@@ -27,192 +24,143 @@ module WidgetList
27
24
 
28
25
  include ActionView::Helpers::SanitizeHelper
29
26
 
30
- def self.determine_db_type(db_type)
31
- the_type, void = db_type.split("://")
32
- if the_type == 'sqlite:/'
33
- the_type = 'sqlite'
34
- end
35
- return the_type.downcase
36
- end
37
-
38
- def self.connect
39
-
40
- begin
41
- if Rails.root.join("config", "widget-list.yml").file?
42
- config = YAML.load(ERB.new(File.new(Rails.root.join("config", "widget-list.yml")).read).result)[Rails.env]
43
- if config.nil?
44
- throw 'Configuration file widget-list.yml has no data. Check that (' + Rails.env + ') Rails.env matches the pointers in the file'
45
- end
46
- @primary_conn = config[:primary]
47
- @secondary_conn = config[:secondary]
48
- else
49
- throw 'widget-list.yml not found'
50
- end
51
-
52
- $DATABASE = Sequel.connect(@primary_conn) if @primary_conn != 'false' and @primary_conn != false
53
- $DATABASE2 = Sequel.connect(@secondary_conn) if @secondary_conn != 'false' and @secondary_conn != false
54
-
55
- if @primary_conn.class.name != 'false' and @primary_conn != false
56
- $DATABASE.db_type = determine_db_type(@primary_conn)
57
- end
58
-
59
- if @primary_conn.class.name != 'false' and @secondary_conn != false
60
- $DATABASE2.db_type = determine_db_type(@secondary_conn)
61
- end
62
- rescue Exception => e
63
- p "widget-list.yml and connection to \$DATABASE failed. Please fix and try again (" + e.to_s + ")"
64
- end
65
-
66
- end
67
-
68
- def self.get_database
69
- case $current_db_selection
70
- when 'primary'
71
- $DATABASE
72
- when 'secondary'
73
- $DATABASE2
74
- else
75
- $DATABASE
76
- end
77
- end
78
-
79
27
  # @param [Hash] list
80
28
  def initialize(list={})
81
29
 
30
+ # Defaults for all configs
31
+ # See https://github.com/davidrenne/widget_list/blob/master/README.md#feature-configurations
82
32
  @items = {
83
- 'name' => ([*('A'..'Z'),*('0'..'9')]-%w(0 1 I O)).sample(16).join,
84
- 'database' => 'primary',
85
- 'title' => '',# will add <h1> title and horizontal rule
86
- 'listDescription' => '',# will add grey header box
87
- 'pageId' => $_SERVER['PATH_INFO'],
88
- 'sql' => '',
89
- 'table' => '',
90
- 'view' => '',
91
- 'data' => {},
92
- 'mode' => 'passive',
93
- 'collClass' => '',
94
- 'collAlign' => '',
95
- 'fields' => {},
96
- 'columns' => {},
97
- 'bindVars' => [],
98
- 'bindVarsLegacy' => {},
99
- 'links' => {},
100
- 'results' => {},
101
- 'buttons' => {},
102
- 'inputs' => {},
103
- 'filter' => [],
104
- 'rowStart' => 0,
105
- 'rowLimit' => 10,
106
- 'orderBy' => '',
107
- 'allowHTML' => true,
108
- 'strlength' => 30,
109
- 'searchClear' => false, # build a custom conditional for each page to clear session
110
- 'searchClearAll' => false, # build a custom conditional for each page to clear session
111
- 'showPagination' => true,
112
- 'searchSession' => true, #on list render use last filter
33
+ 'errors' => [],
34
+ 'name' => ([*('A'..'Z'),*('0'..'9')]-%w(0 1 I O)).sample(16).join,
35
+ 'database' => 'primary', #
36
+ 'title' => '',
37
+ 'listDescription' => '',
38
+ 'pageId' => $_SERVER['PATH_INFO'],
39
+ 'view' => '',
40
+ 'data' => {},
41
+ 'collClass' => '',
42
+ 'collAlign' => '',
43
+ 'fields' => {},
44
+ 'fieldsHidden' => [],
45
+ 'bindVars' => [],
46
+ 'bindVarsLegacy' => {},
47
+ 'links' => {},
48
+ 'buttons' => {},
49
+ 'inputs' => {},
50
+ 'filter' => [],
51
+ 'groupBy' => '',
52
+ 'rowStart' => 0,
53
+ 'rowLimit' => 10,
54
+ 'orderBy' => '',
55
+ 'allowHTML' => true,
56
+ 'searchClear' => false,
57
+ 'searchClearAll' => false,
58
+ 'showPagination' => true,
59
+ 'searchSession' => true,
113
60
 
114
- #
115
- # Custom count query
116
- #
117
- 'force_count_sql' => '',
118
- 'force_query_sql' => '',
61
+ #
62
+ # carryOverRequests will allow you to post custom things from request to all sort/paging URLS for each ajax
63
+ #
64
+ 'carryOverRequsts' => ['switch_grouping'],
119
65
 
120
- #
121
- # Ajax
122
- #
123
- 'ajax_action' => '',
124
- 'ajax_function' => 'ListJumpMin',
125
- 'ajax_search_function'=> 'ListJumpMin',
66
+ #
67
+ # Head/Foot
68
+ #
126
69
 
127
- #
128
- # Search
129
- #
130
- 'showSearch' => true,
131
- 'searchOnkeyup' => '',
132
- 'searchOnclick' => '',
133
- 'searchIdCol' => 'id', #By default `id` column is here because typically if you call your PK's id and are auto-increment
134
- 'searchInputLegacyCSS'=> false,
135
- 'searchBtnName' => 'Search by Id or a list of Ids and more',
136
- 'searchTitle' => '',
137
- 'searchFieldsIn' => {}, #White list of fields to include in a alpha-numeric based search
138
- 'searchFieldsOut' => {'id'=>true}, #Black list of fields to include in a alpha-numeric based search (default `id` to NEVER search when alpha seach)
70
+ 'customFooter' => '',
71
+ 'customHeader' => '',
139
72
 
140
- #
141
- # Export
142
- #
143
- 'showExport' => true,
73
+ #
74
+ # Ajax
75
+ #
76
+ 'ajaxFunctionAll' => '',
77
+ 'ajaxFunction' => 'ListJumpMin',
144
78
 
145
- #
146
- # Group By Box
147
- #
148
- 'groupByItems' => [], #array of strings (each a new "select option")
149
- 'groupBySelected' => false, #initially selected grouping - defaults to first in list if not
150
- 'groupByLabel' => 'Group By',
79
+ #
80
+ # Search
81
+ #
82
+ 'showSearch' => true,
83
+ 'searchOnkeyup' => '',
84
+ 'searchOnclick' => '',
85
+ 'searchIdCol' => 'id',
86
+ 'searchTitle' => 'Search by Id or a list of Ids and more',
87
+ 'searchFieldsIn' => {},
88
+ 'searchFieldsOut' => {'id'=>true},
89
+ 'templateFilter' => '',
151
90
 
91
+ #
92
+ # Export
93
+ #
94
+ 'showExport' => true,
95
+ 'exportButtonTitle' => 'Export CSV',
152
96
 
153
- #
154
- # Advanced searching
155
- #
156
- 'list_search_form' => '', #The HTML form used for the advanced search drop down
157
- 'list_search_attribs' => {}, #widgetinput "search_ahead" attributes
97
+ #
98
+ # Group By Box
99
+ #
100
+ 'groupByItems' => [],
101
+ 'groupBySelected' => false,
102
+ 'groupByLabel' => 'Group By',
103
+ 'groupByClick' => '',
104
+ 'groupByClickDefault' => "ListChangeGrouping('<!--NAME-->', this);",
158
105
 
159
- #
160
- # Column Specific
161
- #
162
- 'columnStyle' => {},
163
- 'columnClass' => {},
164
- 'columnPopupTitle' => {},
165
- 'columnSort' => {},
166
- 'columnWidth' => {},
167
- 'columnNoSort' => {},
168
- 'columnFilter' => {},
169
106
 
170
- #
171
- # Column Border (on right)
172
- #
173
- 'borderedColumns' => false,
174
- 'borderColumnStyle' => '1px solid #CCCCCC',
107
+ #
108
+ # Advanced searching
109
+ #
110
+ 'listSearchForm' => '',
175
111
 
176
- #
177
- # Row specifics
178
- #
179
- 'rowColor' => '#FFFFFF',
180
- 'rowClass' => '',
181
- 'rowColorByStatus' => {},
182
- 'rowStylesByStatus' => {},
183
- 'offsetRows' => true,
184
- 'rowOffsets' => ['FFFFFF','FFFFFF'],
185
-
186
- 'class' => 'listContainerPassive',
187
- 'tableclass' => 'tableBlowOutPreventer',
188
- 'noDataMessage' => 'Currently no data.',
189
- 'useSort' => true,
190
- 'headerClass' => {},
191
- 'groupBy' => '',
192
- 'fieldFunction' => {},
193
- 'buttonVal' => 'templateListJump',
194
- 'linkFunction' => 'ButtonLinkPost',
195
- 'template' => '',
196
- 'templateFilter' => '',
197
- 'pagerFull' => true,
198
- 'LIST_COL_SORT_ORDER' => 'ASC',
199
- 'LIST_COL_SORT' => '',
200
- 'LIST_FILTER_ALL' => '',
201
- 'ROW_LIMIT' => '',
202
- 'LIST_SEQUENCE' => 1,
203
- 'NEW_SEARCH' => false,
112
+ #
113
+ # Column Specific
114
+ #
115
+ 'columnStyle' => {},
116
+ 'columnClass' => {},
117
+ 'columnPopupTitle' => {},
118
+ 'columnSort' => {},
119
+ 'columnWidth' => {},
120
+ 'columnNoSort' => {},
204
121
 
205
- #
206
- # Checkbox
207
- #
208
- 'checked_class' => 'widgetlist-checkbox',
209
- 'checked_flag' => {},
122
+ #
123
+ # Column Border (on right)
124
+ #
125
+ 'borderedColumns' => false,
126
+ 'borderColumnStyle' => '1px solid #CCCCCC',
210
127
 
211
- #
212
- # Hooks
213
- #
214
- 'column_hooks' => {},
215
- 'row_hooks' => {}
128
+ #
129
+ # Row specifics
130
+ #
131
+ 'rowClass' => '',
132
+ 'rowColorByStatus' => {},
133
+ 'rowStylesByStatus' => {},
134
+ 'rowOffsets' => ['FFFFFF','FFFFFF'],
135
+
136
+ 'class' => 'listContainerPassive',
137
+ 'tableclass' => 'tableBlowOutPreventer',
138
+ 'noDataMessage' => 'Currently no data.',
139
+ 'useSort' => true,
140
+ 'headerClass' => {},
141
+ 'fieldFunction' => {},
142
+ 'buttonVal' => 'templateListJump',
143
+ 'linkFunction' => 'ButtonLinkPost',
144
+ 'template' => '',
145
+ 'LIST_COL_SORT_ORDER' => 'ASC',
146
+ 'LIST_COL_SORT' => '',
147
+ 'LIST_FILTER_ALL' => '',
148
+ 'ROW_LIMIT' => '',
149
+ 'LIST_SEQUENCE' => 1,
150
+ 'NEW_SEARCH' => false,
151
+
152
+ #
153
+ # Checkbox
154
+ #
155
+ 'checkedClass' => 'widgetlist-checkbox',
156
+ 'checkedFlag' => {},
157
+ 'storeSessionChecks' => false,
158
+
159
+ #
160
+ # Hooks
161
+ #
162
+ 'columnHooks' => {},
163
+ 'rowHooks' => {}
216
164
  }
217
165
 
218
166
  @csv = []
@@ -233,9 +181,10 @@ module WidgetList
233
181
 
234
182
  #the main template and outer shell
235
183
  @items.deep_merge!({'template' =>
236
- '
184
+ '
237
185
  <!--WRAP_START-->
238
186
  <!--HEADER-->
187
+ <!--CUSTOM_CONTENT_TOP-->
239
188
  <div class="<!--CLASS-->" id="<!--NAME-->">
240
189
  <table class="widget_list <!--TABLE_CLASS-->" style="<!--INLINE_STYLE-->" border="0" width="100%" cellpadding="0" cellspacing="0">
241
190
  <!--LIST_TITLE-->
@@ -243,7 +192,7 @@ module WidgetList
243
192
  <!--DATA-->
244
193
  <tr>
245
194
  <td colspan="<!--COLSPAN_FULL-->" align="left" style="padding:0px;margin:0px;text-align:left">
246
- <div style="background-color:#ECECEC;height:50px;"><div style="padding:10px"><!--CUSTOM_CONTENT--></div>
195
+ <div style="background-color:#ECECEC;height:50px;"><div style="padding:10px"><!--CUSTOM_CONTENT_BOTTOM--></div>
247
196
  </td>
248
197
  </tr>
249
198
  </table>
@@ -256,69 +205,69 @@ module WidgetList
256
205
  })
257
206
 
258
207
  @items.deep_merge!({'row' =>
259
- '
208
+ '
260
209
  <tr style="background-color:<!--BGCOLOR-->;<!--ROWSTYLE-->" class="<!--ROWCLASS-->"><!--CONTENT--></tr>
261
210
  '
262
211
  })
263
212
 
264
213
  @items.deep_merge!({'list_description' =>
265
- '
214
+ '
266
215
  <tr class="summary">
267
- <td id="<!--LIST_NAME-->_list_description" class="header" style="text-align: left;padding-bottom: 2px;padding-top: 7px;font-size: 20px;" colspan="<!--COLSPAN-->"><!--LIST_DESCRIPTION--></td>
216
+ <td id="<!--LIST_NAME-->_list_description" class="header" style="text-align: left;padding-bottom: 2px;padding-top: 7px;font-size: 14px;" colspan="<!--COLSPAN-->"><!--LIST_DESCRIPTION--></td>
268
217
  </tr>
269
218
  '
270
219
  })
271
220
 
272
221
  @items.deep_merge!({'col' =>
273
- '
222
+ '
274
223
  <td class="<!--CLASS-->" align="<!--ALIGN-->" title="<!--TITLE-->" onclick="<!--ONCLICK-->" style="<!--STYLE-->"><!--CONTENT--></td>
275
224
  '
276
225
  })
277
226
 
278
227
  @items.deep_merge!({'templateSequence' =>
279
- '
228
+ '
280
229
  <!--LIST_SEQUENCE--> of <!--TOTAL_PAGES-->
281
230
  '
282
231
  })
283
232
  #Sorting
284
233
  #
285
234
  @items.deep_merge!({'templateSortColumn' =>
286
- '
287
- <td style="font-weight:bold;<!--INLINE_STYLE--><!--INLINE_STYLE-->" id="<!--COL_HEADER_ID-->" class="<!--COL_HEADER_CLASS-->" valign="middle"><span onclick="<!--FUNCTION-->(\'<!--COLSORTURL-->\',\'<!--NAME-->\')" style="cursor:pointer;background:none;" title="<!--TITLE_POPUP-->"><!--TITLE--><!--COLSORTICON-></span></td>
235
+ '
236
+ <td style="font-weight:bold;<!--INLINE_STYLE--><!--INLINE_STYLE-->" id="<!--COL_HEADER_ID-->" class="<!--COL_HEADER_CLASS-->" title="<!--TITLE_POPUP-->" valign="middle"><span onclick="<!--FUNCTION-->(\'<!--COLSORTURL-->\',\'<!--NAME-->\');<!--FUNCTION_ALL-->" style="cursor:pointer;background:none;"><!--TITLE--><!--COLSORTICON-></span></td>
288
237
  '
289
238
  })
290
239
 
291
240
  @items.deep_merge!({'templateNoSortColumn' =>
292
- '
241
+ '
293
242
  <td style="font-weight:bold;<!--INLINE_STYLE-->" title="<!--TITLE_POPUP-->" id="<!--COL_HEADER_ID-->" class="<!--COL_HEADER_CLASS-->" valign="middle"><span style="background:none;"><!--TITLE--></span></td>
294
243
  '
295
244
  })
296
245
 
297
246
  @items.deep_merge!({'statement' =>
298
- {'select'=>
299
- {'view' =>
300
- '
247
+ {'select'=>
248
+ {'view' =>
249
+ '
301
250
  SELECT <!--FIELDS--> FROM <!--SOURCE--> <!--WHERE--> <!--GROUPBY--> <!--ORDERBY--> <!--LIMIT-->
302
251
  '
303
- }
304
- }
252
+ }
253
+ }
305
254
  })
306
255
 
307
256
  @items.deep_merge!({'statement' =>
308
- {'count'=>
309
- {'view' =>
310
- '
311
- SELECT count(1) total FROM <!--VIEW--> <!--WHERE-->
312
- '
313
- }
314
- }
257
+ {'count'=>
258
+ {'view' =>
259
+ '
260
+ SELECT count(1) total FROM <!--VIEW--> <!--WHERE--> <!--GROUPBY-->
261
+ '
262
+ }
263
+ }
315
264
  })
316
265
 
317
266
  #Pagintion
318
267
  #
319
268
 
320
269
  @items.deep_merge!({'template_pagination_wrapper' =>
321
- '
270
+ '
322
271
  <ul id="pagination" class="page_legacy">
323
272
  Page <!--PREVIOUS_BUTTON-->
324
273
  <input type="text" value="<!--SEQUENCE-->" size="1" style="width:15px;padding:0px;font-size:10px;" onblur="">
@@ -330,55 +279,55 @@ module WidgetList
330
279
  })
331
280
 
332
281
  @items.deep_merge!({'template_pagination_next_active' =>
333
- "
334
- <li><span onclick=\"<!--FUNCTION-->('<!--NEXT_URL-->','<!--LIST_NAME-->')\" style=\"cursor:pointer;background: transparent url(<!--HTTP_SERVER-->images/page-next.gif) no-repeat\">&nbsp;</span></li>
282
+ "
283
+ <li><span onclick=\"<!--FUNCTION-->('<!--NEXT_URL-->','<!--LIST_NAME-->');<!--FUNCTION_ALL-->\" style=\"cursor:pointer;background: transparent url(<!--HTTP_SERVER-->images/page-next.gif) no-repeat\">&nbsp;</span></li>
335
284
  "
336
285
  })
337
286
 
338
287
  @items.deep_merge!({'template_pagination_next_disabled' =>
339
- "
288
+ "
340
289
  <li><span style=\"opacity:0.4;filter:alpha(opacity=40);background: transparent url(<!--HTTP_SERVER-->images/page-next.gif) no-repeat\">&nbsp;</span></li>
341
290
  "
342
291
  })
343
292
 
344
293
  @items.deep_merge!({'template_pagination_previous_active' =>
345
- "
346
- <li><span onclick=\"<!--FUNCTION-->('<!--PREVIOUS_URL-->','<!--LIST_NAME-->')\" style=\"cursor:pointer;background: transparent url(<!--HTTP_SERVER-->images/page-back.gif) no-repeat\">&nbsp;</span></li>
294
+ "
295
+ <li><span onclick=\"<!--FUNCTION-->('<!--PREVIOUS_URL-->','<!--LIST_NAME-->');<!--FUNCTION_ALL-->\" style=\"cursor:pointer;background: transparent url(<!--HTTP_SERVER-->images/page-back.gif) no-repeat\">&nbsp;</span></li>
347
296
  "
348
297
  })
349
298
 
350
299
  @items.deep_merge!({'template_pagination_previous_disabled' =>
351
- "
300
+ "
352
301
  <li><span style=\"opacity:0.4;filter:alpha(opacity=40);background: transparent url(<!--HTTP_SERVER-->images/page-back.gif) no-repeat\">&nbsp;</span></li>
353
302
  "
354
303
  })
355
304
 
356
305
  @items.deep_merge!({'template_pagination_jump_active' =>
357
- '
306
+ '
358
307
  <li><div class="active"><!--SEQUENCE--></div></li>
359
308
  '
360
309
  })
361
310
 
362
311
  @items.deep_merge!({'template_pagination_jump_unactive' =>
363
- '
364
- <li onclick="<!--FUNCTION-->(\'<!--JUMP_URL-->\',\'<!--LIST_NAME-->\')"><div><!--SEQUENCE--></div></li>
312
+ '
313
+ <li onclick="<!--FUNCTION-->(\'<!--JUMP_URL-->\',\'<!--LIST_NAME-->\');<!--FUNCTION_ALL-->"><div><!--SEQUENCE--></div></li>
365
314
  '
366
315
  })
367
316
 
368
317
  @items = WidgetList::Widgets::populate_items(list,@items)
369
318
 
370
319
  # current_db is a flag of the last known primary or secondary YML used or defaulted when running a list
371
- $current_db_selection = @items['database']
320
+ @current_db_selection = @items['database']
372
321
 
373
- if WidgetList::List.get_database.db_type == 'oracle'
322
+ if get_database.db_type == 'oracle'
374
323
  @items.deep_merge!({'statement' =>
375
- {'select'=>
376
- {'view' =>
377
- '
378
- SELECT <!--FIELDS-->, rn FROM ( SELECT ' + ( (!@items['view'].include?('(')) ? '<!--SOURCE-->' : @items['view'].strip.split(" ").last ) + '.*, rank() over (<!--ORDERBY-->) rn FROM <!--SOURCE--> ) a <!--WHERE--> <!--GROUPBY--> <!--ORDERBY--> <!--LIMIT-->
379
- '
380
- }
381
- }
324
+ {'select'=>
325
+ {'view' =>
326
+ '
327
+ SELECT <!--FIELDS_PLAIN--> FROM ( SELECT a.*, DENSE_RANK() over (<!--ORDERBY-->) rn FROM ( SELECT ' + ( (!get_view().include?('(')) ? '<!--SOURCE-->' : get_view().strip.split(" ").last ) + '.* FROM <!--SOURCE--> ) a <!--WHERE--> <!--ORDERBY--> ) <!--LIMIT--> ' + ((!@active_record_model) ? '<!--GROUPBY-->' : '') + '
328
+ '
329
+ }
330
+ }
382
331
  })
383
332
 
384
333
  end
@@ -421,13 +370,13 @@ module WidgetList
421
370
 
422
371
  clear_sort_get_vars()
423
372
 
424
- if $_REQUEST.key?('list_action') && $_REQUEST['list_action'] == 'ajax_widgetlist_checks'
373
+ if $_REQUEST.key?('list_action') && $_REQUEST['list_action'] == 'ajax_widgetlist_checks' && @items['storeSessionChecks']
425
374
  ajax_maintain_checks()
426
375
  end
427
376
 
428
377
  end
429
378
 
430
- @items['groupByClick'] = "ListChangeGrouping('" + @items['name'] + "')"
379
+ @items['groupByClick'] = WidgetList::Utils::fill({'<!--NAME-->' => @items['name']}, @items['groupByClickDefault'] + @items['groupByClick'])
431
380
 
432
381
  if $_REQUEST.key?('searchClear')
433
382
  clear_search_session()
@@ -464,11 +413,17 @@ module WidgetList
464
413
  @items['filter'] << filterString
465
414
  end
466
415
 
467
- fieldsToSearch = @items['fields']
416
+ fieldsToSearch = @items['fields'].dup
468
417
 
469
- @items['columns'].each { |columnPivot|
470
- fieldsToSearch[columnPivot] = columnPivot
471
- }
418
+ if @items['fieldsHidden'].class.name == 'Array'
419
+ @items['fieldsHidden'].each { |columnPivot|
420
+ fieldsToSearch[columnPivot] = strip_aliases(columnPivot)
421
+ }
422
+ elsif @items['fieldsHidden'].class.name == 'Hash'
423
+ @items['fieldsHidden'].each { |columnPivot|
424
+ fieldsToSearch[columnPivot[0]] = strip_aliases(columnPivot[0])
425
+ }
426
+ end
472
427
 
473
428
  searchCriteria = searchFilter.strip_or_self()
474
429
  searchSQL = []
@@ -545,10 +500,15 @@ module WidgetList
545
500
 
546
501
  fieldsToSearch.each { |fieldName,fieldTitle|
547
502
 
503
+ fieldName = strip_aliases(fieldName)
548
504
  # new lodgette. if fieldFunction exists, find all matches and skip them
549
505
 
550
506
  if @items['fieldFunction'].key?(fieldName)
551
- theField = @items['fieldFunction'][fieldName] + cast_col()
507
+ if get_database.db_type == 'oracle'
508
+ theField = fieldName
509
+ else
510
+ theField = @items['fieldFunction'][fieldName] + cast_col()
511
+ end
552
512
  else
553
513
  theField = tick_field() + "#{fieldName}" + cast_col() + tick_field()
554
514
  end
@@ -607,7 +567,7 @@ module WidgetList
607
567
 
608
568
  if ! $_REQUEST.key?('BUTTON_VALUE') && !@items['title'].empty?
609
569
  @items['templateHeader'] = '
610
- <h1><!--TITLE--></h1><div class="horizontal_rule"></div>
570
+ <h1 style="font-size:24px;"><!--TITLE--></h1><div class="horizontal_rule"></div>
611
571
  <!--FILTER_HEADER-->
612
572
  '
613
573
  elsif !$_REQUEST.key?('BUTTON_VALUE')
@@ -674,7 +634,7 @@ module WidgetList
674
634
  end
675
635
 
676
636
  def tick_field()
677
- case WidgetList::List.get_database.db_type
637
+ case get_database.db_type
678
638
  when 'postgres'
679
639
  when 'oracle'
680
640
  ''
@@ -684,7 +644,7 @@ module WidgetList
684
644
  end
685
645
 
686
646
  def cast_col()
687
- case WidgetList::List.get_database.db_type
647
+ case get_database.db_type
688
648
  when 'postgres'
689
649
  '::char(1000)'
690
650
  else
@@ -694,12 +654,17 @@ module WidgetList
694
654
 
695
655
  def ajax_maintain_checks()
696
656
 
657
+ if !$_SESSION.key?('list_checks')
658
+ $_SESSION['list_checks'] = {}
659
+ end
660
+
697
661
  #
698
662
  # A list must be provided
699
663
  #
700
664
  if $_REQUEST.key?('LIST_NAME')
701
- listName = $_REQUEST['LIST_NAME']
702
- sqlHash = $_REQUEST['SQL_HASH']
665
+ listName = $_REQUEST['LIST_NAME']
666
+ sqlHash = $_REQUEST['SQL_HASH']
667
+ sequence = $_REQUEST['LIST_SEQUENCE'].to_s
703
668
 
704
669
  #
705
670
  # The placeholder is created when the list initially forms. This validates it and makes it so
@@ -729,18 +694,18 @@ module WidgetList
729
694
  #
730
695
  # Check All
731
696
  #
732
- if $_REQUEST.key?('checked_all')
697
+ if $_REQUEST.key?('checked_all') && $_REQUEST['checked_all'] == '1'
733
698
  if $_SESSION.key?('list_checks')
734
699
 
735
- if $_SESSION['list_checks'].key?('check_all_' + sqlHash + $_REQUEST['LIST_NAME'] + $_REQUEST['LIST_SEQUENCE'])
700
+ if $_SESSION['list_checks'].key?('check_all_' + sqlHash + listName + sequence)
736
701
  if $_REQUEST['checked_all'].empty?
737
- $_SESSION['list_checks'].delete('check_all_' + sqlHash + $_REQUEST['LIST_NAME'] + $_REQUEST['LIST_SEQUENCE'])
702
+ $_SESSION['list_checks'].delete('check_all_' + sqlHash + listName + sequence)
738
703
  else
739
- $_SESSION.deep_merge!({'list_checks' => { 'check_all_' + sqlHash + $_REQUEST['LIST_NAME'] + $_REQUEST['LIST_SEQUENCE'] => true } })
704
+ $_SESSION.deep_merge!({'list_checks' => { 'check_all_' + sqlHash + listName + sequence => true } })
740
705
  end
741
706
  else
742
707
  if ! $_REQUEST['checked_all'].empty?
743
- $_SESSION.deep_merge!({'list_checks' => { 'check_all_' + sqlHash + $_REQUEST['LIST_NAME'] + $_REQUEST['LIST_SEQUENCE'] => true } })
708
+ $_SESSION.deep_merge!({'list_checks' => { 'check_all_' + sqlHash + listName + $_REQUEST['LIST_SEQUENCE'] => true } })
744
709
  end
745
710
  end
746
711
  end
@@ -758,6 +723,12 @@ module WidgetList
758
723
  $_SESSION.delete('DRILL_DOWNS')
759
724
  end
760
725
 
726
+ $_SESSION['list_checks'].keys.each { |key|
727
+ if key.include?(name)
728
+ $_SESSION['list_checks'].delete(key)
729
+ end
730
+ } if $_SESSION.key?('list_checks')
731
+
761
732
  end
762
733
 
763
734
  def clear_search_session(all=false)
@@ -852,12 +823,14 @@ module WidgetList
852
823
 
853
824
  if @sequence.to_i > 1 && ! @items['NEW_SEARCH']
854
825
  subtractLimit = 0
855
- if WidgetList::List.get_database.db_type != 'oracle'
826
+ if get_database.db_type != 'oracle'
856
827
  subtractLimit = @items['rowLimit']
857
828
  end
858
829
  @items['bindVarsLegacy']['LOW'] = (((@sequence * @items['rowLimit']) - subtractLimit))
859
- if WidgetList::List.get_database.db_type == 'oracle'
830
+ if get_database.db_type == 'oracle'
860
831
  @items['bindVarsLegacy']['HIGH'] = ((((@sequence + 1) * @items['rowLimit'])))
832
+ @items['bindVarsLegacy']['LOW'] = @items['bindVarsLegacy']['LOW'] - @items['rowLimit']
833
+ @items['bindVarsLegacy']['HIGH'] = @items['bindVarsLegacy']['HIGH'] - @items['rowLimit']
861
834
  end
862
835
 
863
836
  end
@@ -909,44 +882,39 @@ module WidgetList
909
882
  listJumpUrl['LIST_NAME'] = @items['name']
910
883
  listJumpUrl['SQL_HASH'] = @sqlHash
911
884
 
912
- if @items.key?('ajax_action')
913
- listJumpUrl['list_action'] = @items['ajax_action']
914
- end
915
-
916
885
  if $_REQUEST.key?('switch_grouping')
917
886
  listJumpUrl['switch_grouping'] = $_REQUEST['switch_grouping']
918
887
  end
919
888
 
920
-
921
-
922
-
923
- @templateFill['<!--WRAP_START-->'] = ''
924
- @templateFill['<!--WRAP_END-->'] = ''
889
+ @templateFill['<!--CUSTOM_CONTENT_BOTTOM-->']= @items['customFooter']
890
+ @templateFill['<!--CUSTOM_CONTENT_TOP-->'] = @items['customHeader']
891
+ @templateFill['<!--WRAP_START-->'] = ''
892
+ @templateFill['<!--WRAP_END-->'] = ''
925
893
  if !$_REQUEST.key?('BUTTON_VALUE')
926
- @templateFill['<!--WRAP_START-->'] = '<div class="widget_list_outer">
894
+ @templateFill['<!--WRAP_START-->'] = '<div class="widget_list_outer">
927
895
  <input type="hidden" id="<!--NAME-->_jump_url_original" value="<!--JUMP_URL-->"/>'
928
- @templateFill['<!--WRAP_END-->'] = '</div>'
896
+ @templateFill['<!--WRAP_END-->'] = '</div>'
929
897
  end
930
898
 
931
- @templateFill['<!--HEADER-->'] = @items['templateHeader']
932
- @templateFill['<!--TITLE-->'] = @items['title']
933
- @templateFill['<!--NAME-->'] = @items['name']
934
- @templateFill['<!--JUMP_URL-->'] = WidgetList::Utils::build_url(@items['pageId'],listJumpUrl,(!$_REQUEST.key?('BUTTON_VALUE')))
935
- @templateFill['<!--JUMP_URL_NAME-->'] = @items['name'] + '_jump_url'
936
- @templateFill['<!--CLASS-->'] = @items['class']
899
+ @templateFill['<!--HEADER-->'] = @items['templateHeader']
900
+ @templateFill['<!--TITLE-->'] = @items['title']
901
+ @templateFill['<!--NAME-->'] = @items['name']
902
+ @templateFill['<!--JUMP_URL-->'] = WidgetList::Utils::build_url(@items['pageId'],listJumpUrl,(!$_REQUEST.key?('BUTTON_VALUE')))
903
+ @templateFill['<!--JUMP_URL_NAME-->'] = @items['name'] + '_jump_url'
904
+ @templateFill['<!--CLASS-->'] = @items['class']
937
905
 
938
906
  if @totalRowCount > 0
939
- @templateFill['<!--INLINE_STYLE-->'] = ''
940
- @templateFill['<!--TABLE_CLASS-->'] = @items['tableclass']
907
+ @templateFill['<!--INLINE_STYLE-->'] = ''
908
+ @templateFill['<!--TABLE_CLASS-->'] = @items['tableclass']
941
909
  else
942
- @templateFill['<!--INLINE_STYLE-->'] = 'table-layout:auto;'
910
+ @templateFill['<!--INLINE_STYLE-->'] = 'table-layout:auto;'
943
911
  end
944
912
 
945
913
  #Filter form
946
914
  #
947
915
  if @items['showSearch'] === true
948
916
  if ! @items['templateFilter'].empty?
949
- @templateFill['<!--FILTER_HEADER-->'] = @items['templateFilter']
917
+ @templateFill['<!--FILTER_HEADER-->'] = @items['templateFilter']
950
918
  else
951
919
  if !$_REQUEST.key?('search_filter') && !@isJumpingList
952
920
 
@@ -966,13 +934,13 @@ module WidgetList
966
934
  filterParameters['PAGE_ID'] = @items['pageId']
967
935
  filterParameters['LIST_NAME'] = @items['name']
968
936
  filterParameters['SQL_HASH'] = @sqlHash
969
- if @items.key?('ajax_action') && ! @items['ajax_action'].empty?
970
- filterParameters['list_action'] = @items['ajax_action']
971
- end
972
937
 
973
- if $_REQUEST.key?('switch_grouping')
974
- filterParameters['switch_grouping'] = $_REQUEST['switch_grouping']
975
- end
938
+ @items['carryOverRequsts'].each { |value|
939
+ if $_REQUEST.key?(value)
940
+ filterParameters[value] = $_REQUEST[value]
941
+ end
942
+ }
943
+
976
944
  searchUrl = WidgetList::Utils::build_url(@items['pageId'], filterParameters, (!$_REQUEST.key?('BUTTON_VALUE')))
977
945
 
978
946
  list_search = {}
@@ -993,17 +961,17 @@ module WidgetList
993
961
  list_search['list-search'] = true
994
962
  list_search['width'] = '500'
995
963
  list_search['input_class'] = 'info-input'
996
- list_search['title'] = (@items['searchTitle'].empty?) ? @items['searchBtnName'] :@items['searchTitle']
964
+ list_search['title'] = @items['searchTitle']
997
965
  list_search['id'] = 'list_search_id_' + @items['name']
998
966
  list_search['name'] = 'list_search_name_' + @items['name']
999
967
  list_search['class'] = 'inputOuter widget-search-outer ' + @items['name'].downcase + '-search'
1000
968
  list_search['search_ahead'] = {
1001
- 'url' => searchUrl,
1002
- 'skip_queue' => false,
1003
- 'target' => @items['name'],
1004
- 'search_form' => @items['list_search_form'],
1005
- 'onclick' => (! @items['searchOnclick'].empty? && ! @items['list_search_form'].empty?) ? @items['searchOnclick'] : '',
1006
- 'onkeyup' => (! @items['searchOnkeyup'].empty?) ? @items['searchOnkeyup'] : ''
969
+ 'url' => searchUrl,
970
+ 'skip_queue' => false,
971
+ 'target' => @items['name'],
972
+ 'search_form' => @items['listSearchForm'],
973
+ 'onclick' => (! @items['searchOnclick'].empty? && ! @items['listSearchForm'].empty?) ? @items['searchOnclick'] : '',
974
+ 'onkeyup' => (! @items['searchOnkeyup'].empty?) ? @items['searchOnkeyup'] : ''
1007
975
  }
1008
976
 
1009
977
  @templateFill['<!--FILTER_HEADER-->'] = WidgetList::Widgets::widget_input(list_search)
@@ -1038,21 +1006,23 @@ module WidgetList
1038
1006
  className = 'widget-search-results-row-selected'
1039
1007
  end
1040
1008
 
1009
+ num = 1
1041
1010
  @items['groupByItems'].each { |grouping|
1042
1011
  if @items['groupBySelected'] && @items['groupBySelected'] === grouping
1043
1012
  className = 'widget-search-results-row-selected'
1044
1013
  end
1045
- groupRows << '<div class="widget-search-results-row ' + className + '" title="' + grouping + '" onmouseover="jQuery(\'.widget-search-results-row\').removeClass(\'widget-search-results-row-selected\')" onclick="SelectBoxSetValue(\'' + grouping + '\',\'' + @items['name'] + '\');' + @items['groupByClick'] + '">' + grouping + '</div>'
1014
+ groupRows << '<div class="widget-search-results-row ' + className + '" id="' + @items['name'] + '_row_' + num.to_s + '" title="' + grouping + '" onmouseover="jQuery(\'.widget-search-results-row\').removeClass(\'widget-search-results-row-selected\')" onclick="SelectBoxSetValue(\'' + grouping + '\',\'' + @items['name'] + '\');' + @items['groupByClick'] + '">' + grouping + '</div>'
1046
1015
  className = ''
1016
+ num = num + 1
1047
1017
  }
1048
1018
 
1049
1019
  list_group['search_ahead'] = {
1050
- 'skip_queue' => false,
1051
- 'search_form'=> '
1020
+ 'skip_queue' => false,
1021
+ 'search_form'=> '
1052
1022
  <div id="advanced-search-container" style="height:100% !important;">
1053
1023
  ' + groupRows.join("\n") + '
1054
1024
  </div>',
1055
- 'onclick' => @items['searchOnclick']
1025
+ 'onclick' => @items['searchOnclick']
1056
1026
  }
1057
1027
  if !@templateFill.key?('<!--FILTER_HEADER-->')
1058
1028
  @templateFill['<!--FILTER_HEADER-->'] = ''
@@ -1060,7 +1030,7 @@ module WidgetList
1060
1030
  @templateFill['<!--FILTER_HEADER-->'] += '<div class="fake-select"><div class="label">' + @items['groupByLabel'] + ':</div> ' + WidgetList::Widgets::widget_input(list_group) + '</div>'
1061
1031
 
1062
1032
  if @items['showExport']
1063
- @templateFill['<!--FILTER_HEADER-->'] += WidgetList::Widgets::widget_button('Export CSV', {'onclick' => 'ListExport(\'' + @items['name'] + '\');'}, true)
1033
+ @templateFill['<!--FILTER_HEADER-->'] += WidgetList::Widgets::widget_button(@items['exportButtonTitle'], {'onclick' => 'ListExport(\'' + @items['name'] + '\');'}, true)
1064
1034
  end
1065
1035
 
1066
1036
  end
@@ -1124,14 +1094,11 @@ module WidgetList
1124
1094
  }
1125
1095
  end
1126
1096
 
1127
- if @items.key?('ajax_action') && ! @items['ajax_action'].empty?
1128
- urlTags['list_action'] = @items['ajax_action']
1129
- end
1130
-
1131
- if $_REQUEST.key?('switch_grouping')
1132
- urlTags['switch_grouping'] = $_REQUEST['switch_grouping']
1133
- end
1134
-
1097
+ @items['carryOverRequsts'].each { |value|
1098
+ if $_REQUEST.key?(value)
1099
+ urlTags[value] = $_REQUEST[value]
1100
+ end
1101
+ }
1135
1102
  if (@sequence == @totalPages || ! (@totalPages > 0))
1136
1103
  showNext = false
1137
1104
  else
@@ -1157,11 +1124,12 @@ module WidgetList
1157
1124
  #Assemble navigation buttons
1158
1125
  #
1159
1126
  pieces = {
1160
- '<!--NEXT_URL-->' => nextUrl,
1161
- '<!--LIST_NAME-->' => @items['name'],
1162
- '<!--HTTP_SERVER-->' => $_SERVER['rack.url_scheme'] + '://' + $_SERVER['HTTP_HOST'] + '/assets/',
1163
- '<!--PREVIOUS_URL-->' => prevUrl,
1164
- '<!--FUNCTION-->' => @items['ajax_function']
1127
+ '<!--NEXT_URL-->' => nextUrl,
1128
+ '<!--LIST_NAME-->' => @items['name'],
1129
+ '<!--HTTP_SERVER-->' => $_SERVER['rack.url_scheme'] + '://' + $_SERVER['HTTP_HOST'] + '/assets/',
1130
+ '<!--PREVIOUS_URL-->' => prevUrl,
1131
+ '<!--FUNCTION-->' => @items['ajaxFunction'],
1132
+ '<!--FUNCTION_ALL-->' => @items['ajaxFunctionAll'],
1165
1133
  }
1166
1134
 
1167
1135
  templates['btn_next'] = WidgetList::Utils::fill(pieces,templates['btn_next'])
@@ -1175,9 +1143,11 @@ module WidgetList
1175
1143
  urlTags['LIST_SEQUENCE'] = @sequence
1176
1144
  urlTags['ROW_LIMIT'] = 10
1177
1145
 
1178
- if $_REQUEST.key?('switch_grouping')
1179
- urlTags['switch_grouping'] = $_REQUEST['switch_grouping']
1180
- end
1146
+ @items['carryOverRequsts'].each { |value|
1147
+ if $_REQUEST.key?(value)
1148
+ urlTags[value] = $_REQUEST[value]
1149
+ end
1150
+ }
1181
1151
 
1182
1152
  # Automate select box and rules
1183
1153
  #
@@ -1204,7 +1174,7 @@ module WidgetList
1204
1174
 
1205
1175
  # WidgetSelect( todo)
1206
1176
  pageSelect = <<-EOD
1207
- <select onchange="#{@items['ajax_function']}(this.value,'#{@items['name']}')" style="width:58px">
1177
+ <select onchange="#{@items['ajaxFunction']}(this.value,'#{@items['name']}');#{@items['ajaxFunctionAll']}" style="width:58px">
1208
1178
  #{options}
1209
1179
  </select>
1210
1180
  EOD
@@ -1261,18 +1231,24 @@ module WidgetList
1261
1231
  jumpTemplate = @items['template_pagination_jump_unactive']
1262
1232
  end
1263
1233
 
1264
- jumpSection << WidgetList::Utils::fill({'<!--SEQUENCE-->'=>page,'<!--JUMP_URL-->'=>jumpUrl,'<!--LIST_NAME-->'=>@items['name'],'<!--FUNCTION-->'=>@items['ajax_function']}, jumpTemplate)
1234
+ jumpSection << WidgetList::Utils::fill({
1235
+ '<!--SEQUENCE-->' => page,
1236
+ '<!--JUMP_URL-->' => jumpUrl,
1237
+ '<!--LIST_NAME-->' => @items['name'],
1238
+ '<!--FUNCTION-->' => @items['ajaxFunction'],
1239
+ '<!--FUNCTION_ALL-->' => @items['ajaxFunctionAll'],
1240
+ }, jumpTemplate)
1265
1241
  end
1266
1242
 
1267
1243
  pieces = {
1268
- '<!--PREVIOUS_BUTTON-->' => templates['btn_previous'],
1269
- '<!--SEQUENCE-->' => @sequence,
1270
- '<!--NEXT_BUTTON-->' => templates['btn_next'],
1271
- '<!--TOTAL_PAGES-->' => @totalPages,
1272
- '<!--TOTAL_ROWS-->' => @totalRows,
1273
- '<!--PAGE_SEQUENCE_JUMP_LIST-->' => pageSelect,
1274
- '<!--JUMP-->' => jumpSection.join(''),
1275
- '<!--LIST_NAME-->' => @items['name'],
1244
+ '<!--PREVIOUS_BUTTON-->' => templates['btn_previous'],
1245
+ '<!--SEQUENCE-->' => @sequence,
1246
+ '<!--NEXT_BUTTON-->' => templates['btn_next'],
1247
+ '<!--TOTAL_PAGES-->' => @totalPages,
1248
+ '<!--TOTAL_ROWS-->' => @totalRows,
1249
+ '<!--PAGE_SEQUENCE_JUMP_LIST-->' => pageSelect,
1250
+ '<!--JUMP-->' => jumpSection.join(''),
1251
+ '<!--LIST_NAME-->' => @items['name'],
1276
1252
  }
1277
1253
 
1278
1254
  paginationOutput = WidgetList::Utils::fill(pieces,@items['template_pagination_wrapper'])
@@ -1389,7 +1365,7 @@ module WidgetList
1389
1365
 
1390
1366
  if (
1391
1367
  ( (@items.key?('LIST_COL_SORT') && !@items['LIST_COL_SORT'].empty?) && @items['LIST_COL_SORT'] == colSort['LIST_COL_SORT']) ||
1392
- ( $_SESSION.key?('LIST_COL_SORT') && $_SESSION['LIST_COL_SORT'].key?(@sqlHash) && $_SESSION['LIST_COL_SORT'][@sqlHash].key?(field))
1368
+ ( $_SESSION.key?('LIST_COL_SORT') && $_SESSION['LIST_COL_SORT'].key?(@sqlHash) && $_SESSION['LIST_COL_SORT'][@sqlHash].key?(field))
1393
1369
  )
1394
1370
  changedSession = false
1395
1371
  if @items.key?('LIST_COL_SORT') && !@items['LIST_COL_SORT'].empty?
@@ -1428,13 +1404,12 @@ module WidgetList
1428
1404
  end
1429
1405
  end
1430
1406
 
1431
- if $_REQUEST.key?('switch_grouping')
1432
- colSort['switch_grouping'] = $_REQUEST['switch_grouping']
1433
- end
1407
+ @items['carryOverRequsts'].each { |value|
1408
+ if $_REQUEST.key?(value)
1409
+ colSort[value] = $_REQUEST[value]
1410
+ end
1411
+ }
1434
1412
 
1435
- if @items.key?('ajax_action') && ! @items['ajax_action'].empty?
1436
- colSort['list_action'] = @items['ajax_action']
1437
- end
1438
1413
  colSort['SQL_HASH'] = @sqlHash
1439
1414
 
1440
1415
  pieces = { '<!--COLSORTURL-->' => WidgetList::Utils::build_url(@items['pageId'],colSort,(!$_REQUEST.key?('BUTTON_VALUE'))),
@@ -1445,7 +1420,8 @@ module WidgetList
1445
1420
  '<!--TITLE_POPUP-->' => popupTitle,
1446
1421
  '<!--COL_HEADER_CLASS-->' => colClass,
1447
1422
  '<!--TITLE-->' => fieldTitle,
1448
- '<!--FUNCTION-->' => @items['ajax_function']
1423
+ '<!--FUNCTION-->' => @items['ajaxFunction'],
1424
+ '<!--FUNCTION_ALL-->' => @items['ajaxFunctionAll'],
1449
1425
  }
1450
1426
  headers << WidgetList::Utils::fill(pieces, @items[templateIdx])
1451
1427
  else
@@ -1463,13 +1439,6 @@ module WidgetList
1463
1439
 
1464
1440
  @templateFill['<!--COLSPAN_FULL-->'] = headers.count()
1465
1441
 
1466
- if @items['mode'] != 'passive'
1467
- pieces = {'<!--LIST_SEQUENCE-->' => @sequence,
1468
- '<!--TOTAL_PAGES-->' => @totalPages}
1469
-
1470
- @templateFill['<!--PAGE_SEQUENCE_DISPLAY-->'] = WidgetList::Utils::fill(pieces, @items['templateSequence'])
1471
- end
1472
-
1473
1442
  @templateFill['<!--PAGINATION_LIST-->'] = build_pagination()
1474
1443
  @templateFill['<!--HEADERS-->'] = headers.join('')
1475
1444
 
@@ -1566,9 +1535,9 @@ module WidgetList
1566
1535
  #
1567
1536
  # Checkbox is checked or not per query value
1568
1537
  #
1569
- if ! @items['checked_flag'].empty?
1570
- if @items['checked_flag'].key?(column)
1571
- input['checked'] = !!@results[ @items['checked_flag'][column].upcase ][row]
1538
+ if ! @items['checkedFlag'].empty?
1539
+ if @items['checkedFlag'].key?(column)
1540
+ input['checked'] = !!@results[ @items['checkedFlag'][column].upcase ][row]
1572
1541
  end
1573
1542
  end
1574
1543
 
@@ -1596,24 +1565,118 @@ module WidgetList
1596
1565
  return content
1597
1566
  end
1598
1567
 
1568
+ # build_list controls a default AJAX/Export and full HTML return output
1569
+ # in some cases you should copy and paste this logic for custom scenarios in your controller, but in most cases, this is okay
1570
+
1571
+ def self.build_list(list_parms)
1572
+
1573
+ list = WidgetList::List.new(list_parms)
1574
+
1575
+ #
1576
+ # If AJAX, send back JSON
1577
+ #
1578
+ if $_REQUEST.key?('BUTTON_VALUE') && $_REQUEST['LIST_NAME'] == list_parms['name']
1579
+
1580
+ if $_REQUEST.key?('export_widget_list')
1581
+ return ['export',list.render()]
1582
+ end
1583
+
1584
+ ret = {}
1585
+
1586
+ if $_REQUEST['list_action'] != 'ajax_widgetlist_checks'
1587
+ ret['list'] = list.render()
1588
+ ret['list_id'] = list_parms['name']
1589
+ ret['callback'] = 'ListSearchAheadResponse'
1590
+ end
1591
+
1592
+ return ['json',WidgetList::Utils::json_encode(ret)]
1593
+ else
1594
+ #
1595
+ # Else assign to variable for view
1596
+ #
1597
+ return ['html', list.render() ]
1598
+ end
1599
+
1600
+ end
1601
+
1602
+ # checkbox_helper just builds the proper Hashes to setup a checkbox widget row
1603
+ # it assumes you have a fake column called '' AS checkbox to fill in with the widget_check
1604
+
1605
+ def self.checkbox_helper(list_parms,primary_key)
1606
+
1607
+ list_parms.deep_merge!({'inputs' =>
1608
+ {'checkbox'=>
1609
+ {'type' => 'checkbox'
1610
+ }
1611
+ }
1612
+ })
1613
+
1614
+ list_parms.deep_merge!({'inputs' =>
1615
+ {'checkbox'=>
1616
+ {'items' =>
1617
+ {
1618
+ 'name' => list_parms['name'] + '_visible_checks[]',
1619
+ 'value' => primary_key, #the value should be a column name mapping
1620
+ 'class_handle' => list_parms['name'] + '_info_tables',
1621
+ }
1622
+ }
1623
+ }
1624
+ })
1625
+
1626
+ list_parms.deep_merge!({'inputs' =>
1627
+ {'checkbox_header'=>
1628
+ {'type' => 'checkbox'
1629
+ }
1630
+ }
1631
+ })
1632
+
1633
+ list_parms.deep_merge!({'inputs' =>
1634
+ {'checkbox_header'=>
1635
+ {'items' =>
1636
+ {
1637
+ 'check_all' => true,
1638
+ 'id' => list_parms['name'] + '_info_tables_check_all',
1639
+ 'class_handle' => list_parms['name'] + '_info_tables',
1640
+ }
1641
+ }
1642
+ }
1643
+ })
1644
+ return list_parms
1645
+ end
1646
+
1599
1647
  def self.drill_down_back(list_name='')
1600
1648
  '<div class="goback" onclick="ListHome(\'' + list_name + '\');" title="Go Back"></div>'
1601
1649
  end
1602
1650
 
1603
- def self.build_drill_down_link(listId,drillDownName,dataToPassFromView,columnToShow,columnAlias='',functionName='ListDrillDown',columnClass='',color='blue')
1651
+ def self.build_drill_down_link(listId,drillDownName,dataToPassFromView,columnToShow,columnAlias='',extraFunction='',functionName='ListDrillDown',columnClass='',color='blue',extraJSFunctionParams='',primary=true)
1604
1652
  if columnAlias.empty?
1605
1653
  columnAlias = columnToShow
1606
1654
  end
1607
1655
 
1608
1656
  if !columnClass.empty?
1609
- columnClass = ' "' + WidgetList::List::concat_string() + columnClass + WidgetList::List::concat_string() + '"'
1657
+ columnClass = ' "' + WidgetList::List::concat_string(primary) + columnClass + WidgetList::List::concat_string(primary) + '"'
1658
+ end
1659
+
1660
+ if WidgetList::List.get_db_type(primary) == 'oracle'
1661
+ if $_REQUEST.key?('export_widget_list')
1662
+ link = "#{columnToShow} #{WidgetList::List::is_sequel(primary) ? " as #{columnAlias} " : ""}"
1663
+ else
1664
+ link = %[q'[<a style='cursor:pointer;color:#{color};' class='#{columnAlias}_drill#{columnClass}' onclick='#{functionName}("#{drillDownName}", ListDrillDownGetRowValue(this) ,"#{listId}"#{extraJSFunctionParams});#{extraFunction}'>]' #{WidgetList::List::concat_string(primary)}#{columnToShow}#{WidgetList::List::concat_string(primary)}q'[</a><script class='val-db' type='text'>]' #{WidgetList::List::concat_string(primary)} #{dataToPassFromView} #{WidgetList::List::concat_string(primary)} q'[</script>]' #{WidgetList::List::concat_outer(primary)} #{WidgetList::List::is_sequel(primary) ? " as #{columnAlias} " : ""}]
1665
+ end
1666
+ else
1667
+ if $_REQUEST.key?('export_widget_list')
1668
+ link = "#{columnToShow} #{WidgetList::List::is_sequel(primary) ? " as #{columnAlias} " : ""}"
1669
+ else
1670
+ link = %[#{WidgetList::List::concat_inner(primary)}"<a style='cursor:pointer;color:#{color};' class='#{columnAlias}_drill#{columnClass}' onclick='#{functionName}(#{WidgetList::List::double_quote(primary)}#{drillDownName}#{WidgetList::List::double_quote(primary)}, ListDrillDownGetRowValue(this) ,#{WidgetList::List::double_quote(primary)}#{listId}#{WidgetList::List::double_quote(primary)}#{extraJSFunctionParams});#{extraFunction}'>"#{WidgetList::List::concat_string(primary)}#{columnToShow}#{WidgetList::List::concat_string(primary)}"</a><script class='val-db' type='text'>"#{WidgetList::List::concat_string(primary)} #{dataToPassFromView} #{WidgetList::List::concat_string(primary)}"</script>"#{WidgetList::List::concat_outer(primary)} #{WidgetList::List::is_sequel(primary) ? " as #{columnAlias} " : ""}]
1671
+ end
1610
1672
  end
1611
1673
 
1612
- link = %[#{WidgetList::List::concat_inner()}"<a style='cursor:pointer;color:#{color};' class='#{columnAlias}_drill#{columnClass}' onclick='#{functionName}(#{WidgetList::List::double_quote()}#{drillDownName}#{WidgetList::List::double_quote()}, ListDrillDownGetRowValue(this) ,#{WidgetList::List::double_quote()}#{listId}#{WidgetList::List::double_quote()});'>"#{WidgetList::List::concat_string()}#{columnToShow}#{WidgetList::List::concat_string()}"</a><script class='val-db' type='text'>"#{WidgetList::List::concat_string()} #{dataToPassFromView} #{WidgetList::List::concat_string()}"</script>"#{WidgetList::List::concat_outer()} as #{columnAlias},]
1674
+
1613
1675
  end
1614
1676
 
1615
- def self.concat_string
1616
- case WidgetList::List.get_database.db_type
1677
+ def self.concat_string(primary)
1678
+
1679
+ case WidgetList::List.get_db_type(primary)
1617
1680
  when 'mysql'
1618
1681
  ' , '
1619
1682
  when 'oracle','sqlite'
@@ -1623,8 +1686,8 @@ module WidgetList
1623
1686
  end
1624
1687
  end
1625
1688
 
1626
- def self.double_quote
1627
- case WidgetList::List.get_database.db_type
1689
+ def self.double_quote(primary)
1690
+ case WidgetList::List.get_db_type(primary)
1628
1691
  when 'mysql'
1629
1692
  '\\"'
1630
1693
  when 'oracle','sqlite'
@@ -1634,8 +1697,8 @@ module WidgetList
1634
1697
  end
1635
1698
  end
1636
1699
 
1637
- def self.concat_outer
1638
- case WidgetList::List.get_database.db_type
1700
+ def self.concat_outer(primary)
1701
+ case WidgetList::List.get_db_type(primary)
1639
1702
  when 'mysql'
1640
1703
  ')'
1641
1704
  else
@@ -1643,8 +1706,8 @@ module WidgetList
1643
1706
  end
1644
1707
  end
1645
1708
 
1646
- def self.concat_inner
1647
- case WidgetList::List.get_database.db_type
1709
+ def self.concat_inner(primary)
1710
+ case WidgetList::List.get_db_type(primary)
1648
1711
  when 'mysql'
1649
1712
  'CONCAT('
1650
1713
  else
@@ -1673,15 +1736,15 @@ module WidgetList
1673
1736
  if @results.key?(tag.upcase) && @results[tag.upcase][j]
1674
1737
 
1675
1738
  buttonAttribs.deep_merge!({'args' =>
1676
- {
1677
- tagName => @results[tag.upcase][j]
1678
- }
1739
+ {
1740
+ tagName => @results[tag.upcase][j]
1741
+ }
1679
1742
  })
1680
1743
  else
1681
1744
  buttonAttribs.deep_merge!({'args' =>
1682
- {
1683
- tagName => tag
1684
- }
1745
+ {
1746
+ tagName => tag
1747
+ }
1685
1748
  })
1686
1749
  end
1687
1750
  }
@@ -1722,18 +1785,6 @@ module WidgetList
1722
1785
  function = @items['linkFunction']
1723
1786
  parameters = ''
1724
1787
 
1725
- if links.key?('PAGE_ID') && ! links['PAGE_ID'].empty?
1726
- url['PAGE_ID'] = links['PAGE_ID']
1727
- end
1728
-
1729
- if links.key?('ACTION') && ! links['ACTION'].empty?
1730
- url['list_action'] = links['ACTION']
1731
- end
1732
-
1733
- if links.key?('BUTTON_VALUE') && ! links['BUTTON_VALUE'].empty?
1734
- url['BUTTON_VALUE'] = links['BUTTON_VALUE']
1735
- end
1736
-
1737
1788
  #todo unit test this and all of column links
1738
1789
  if links.key?('tags')
1739
1790
  links['tags'].each { | tagName, tag |
@@ -1759,12 +1810,8 @@ module WidgetList
1759
1810
  end
1760
1811
  end
1761
1812
 
1762
- if @items.key?('ajax_action') && !@items['ajax_action'].empty?
1763
- url['list_action'] = @items['ajax_action']
1764
- end
1765
-
1766
1813
  url['SQL_HASH'] = @sqlHash
1767
- linkUrl = WidgetList::Utils::build_url(@items['pageId'],(!$_REQUEST.key?('BUTTON_VALUE')))
1814
+ linkUrl = WidgetList::Utils::build_url(@items['pageId'], url, (!$_REQUEST.key?('BUTTON_VALUE')))
1768
1815
 
1769
1816
  "#{function}('#{linkUrl}'#{parameters})"
1770
1817
  end
@@ -1775,12 +1822,12 @@ module WidgetList
1775
1822
  if @items['data'].empty?
1776
1823
  #Run the actual statement
1777
1824
  #
1778
- @totalRowCount = WidgetList::List.get_database._select(sql, @items['bindVars'], @items['bindVarsLegacy'])
1825
+ @totalRowCount = get_database._select(sql , @items['bindVars'], @items['bindVarsLegacy'], @active_record_model)
1779
1826
  end
1780
1827
 
1781
1828
  if @totalRowCount > 0
1782
1829
  if @items['data'].empty?
1783
- @results = WidgetList::List.get_database.final_results
1830
+ @results = get_database.final_results
1784
1831
  else
1785
1832
  @results = @items['data']
1786
1833
  end
@@ -1801,6 +1848,8 @@ module WidgetList
1801
1848
  #
1802
1849
 
1803
1850
  @items['fields'].each { |column , fieldTitle|
1851
+ column = strip_aliases(column)
1852
+
1804
1853
  colPieces = {}
1805
1854
  colClasses = []
1806
1855
  theStyle = ''
@@ -1833,7 +1882,7 @@ module WidgetList
1833
1882
  # Column is an input
1834
1883
  #
1835
1884
  elsif @items['inputs'].key?(column) && @items['inputs'][column].class.name == 'Hash'
1836
- colClasses << @items['checked_class']
1885
+ colClasses << @items['checkedClass']
1837
1886
  content = build_column_input(column, j)
1838
1887
 
1839
1888
 
@@ -1861,7 +1910,7 @@ module WidgetList
1861
1910
  content = strip_tags(content)
1862
1911
  end
1863
1912
 
1864
- content = WidgetList::List.get_database._bind(content, @items['bindVarsLegacy'])
1913
+ content = get_database._bind(content, @items['bindVarsLegacy'])
1865
1914
 
1866
1915
  # Column color
1867
1916
  #
@@ -1958,14 +2007,11 @@ module WidgetList
1958
2007
  if @items['rowColorByStatus'].empty? && @items['rowStylesByStatus'].empty?
1959
2008
  #Set the row color
1960
2009
  #
1961
- rowColor = @items['rowColor']
1962
2010
 
1963
- if @items['offsetRows']
1964
- if( j % 2 ==0)
1965
- rowColor = @items['rowOffsets'][1]
1966
- else
1967
- rowColor = @items['rowOffsets'][0]
1968
- end
2011
+ if( j % 2 ==0)
2012
+ rowColor = @items['rowOffsets'][1]
2013
+ else
2014
+ rowColor = @items['rowOffsets'][0]
1969
2015
  end
1970
2016
 
1971
2017
  #Draw default color
@@ -1986,7 +2032,7 @@ module WidgetList
1986
2032
 
1987
2033
  else
1988
2034
 
1989
- err_message = (WidgetList::List.get_database.errors) ? @items['noDataMessage'] + ' <span style="color:red">(An error occurred)</span>' : @items['noDataMessage']
2035
+ err_message = (get_database.errors) ? @items['noDataMessage'] + ' <span style="color:red">(An error occurred)</span>' : @items['noDataMessage']
1990
2036
 
1991
2037
  @templateFill['<!--DATA-->'] = '<tr><td colspan="50"><div id="noListResults">' + generate_error_output() + err_message + '</div></td></tr>'
1992
2038
 
@@ -1994,7 +2040,7 @@ module WidgetList
1994
2040
 
1995
2041
  else
1996
2042
 
1997
- err_message = (WidgetList::List.get_database.errors) ? @items['noDataMessage'] + ' <span style="color:red">(An error occurred)</span>' : @items['noDataMessage']
2043
+ err_message = (get_database.errors) ? @items['noDataMessage'] + ' <span style="color:red">(An error occurred)</span>' : @items['noDataMessage']
1998
2044
 
1999
2045
  @templateFill['<!--DATA-->'] = '<tr><td colspan="50"><div id="noListResults">' + generate_error_output() + err_message + '</div></td></tr>'
2000
2046
  end
@@ -2003,50 +2049,91 @@ module WidgetList
2003
2049
 
2004
2050
  def generate_error_output(ex='')
2005
2051
  sqlDebug = ""
2052
+
2053
+ if !@items['errors'].empty?
2054
+ sqlDebug += "<br/><br/><strong style='color:red'>(" + @items['errors'].join(', ') + ")</strong>"
2055
+ end
2056
+
2006
2057
  if Rails.env == 'development'
2007
- sqlDebug += "<br/><br/><textarea style='width:100%;height:400px;'>" + WidgetList::List.get_database.last_sql.to_s + "</textarea>"
2058
+ sqlDebug += "<br/><br/><textarea style='width:100%;height:400px;'>" + get_database.last_sql.to_s + "</textarea>"
2008
2059
  end
2009
2060
 
2010
- if Rails.env == 'development' && WidgetList::List.get_database.errors
2011
- sqlDebug += "<br/><br/><strong style='color:red'>(" + WidgetList::List.get_database.last_error.to_s + ")</strong>"
2061
+ if Rails.env == 'development' && get_database.errors
2062
+ sqlDebug += "<br/><br/><strong style='color:red'>(" + get_database.last_error.to_s + ")</strong>"
2012
2063
  end
2013
2064
 
2014
2065
  if Rails.env == 'development' && ex != ''
2015
2066
  sqlDebug += "<br/><br/><strong style='color:red'>(" + ex.to_s + ") <pre>" + $!.backtrace.join("\n\n") + "</pre></strong>"
2016
2067
  end
2068
+ Rails.logger.info sqlDebug
2017
2069
 
2018
2070
  sqlDebug
2019
2071
  end
2020
2072
 
2021
2073
  def build_statement()
2022
- statement = ''
2023
- pieces = { '<!--FIELDS-->' => '',
2024
- '<!--SOURCE-->' => '',
2025
- '<!--WHERE-->' => '',
2026
- '<!--GROUPBY-->' => '',
2027
- '<!--ORDERBY-->' => '',
2028
- '<!--LIMIT-->' => ''}
2074
+ statement = ''
2075
+ @fieldList = []
2076
+ @fieldListPlain = []
2077
+ pieces = { '<!--FIELDS_PLAIN-->' => '',
2078
+ '<!--FIELDS-->' => '',
2079
+ '<!--SOURCE-->' => '',
2080
+ '<!--WHERE-->' => '',
2081
+ '<!--GROUPBY-->' => '',
2082
+ '<!--ORDERBY-->' => '',
2083
+ '<!--LIMIT-->' => ''}
2029
2084
 
2030
2085
  #Build out a list of columns to select from
2031
2086
  #
2087
+
2032
2088
  @items['fields'].each { |column, fieldTitle|
2089
+ @fieldListPlain << strip_aliases(column)
2033
2090
  if @items['fieldFunction'].key?(column) && !@items['fieldFunction'][column].empty?
2034
2091
  # fieldFunction's should not have an alias, just the database functions
2035
2092
  column = @items['fieldFunction'][column] + " " + column
2036
2093
  end
2037
-
2038
2094
  @fieldList << column
2039
2095
  }
2040
2096
 
2041
- #Add any columns without corresponding header titles
2042
- #
2043
- @items['columns'].each { |column|
2044
- @fieldList << column
2045
- }
2097
+
2098
+ if get_database.db_type == 'oracle'
2099
+ if !@items['groupBy'].empty?
2100
+ @fieldList << 'MAX(rn) as rn'
2101
+ else
2102
+ @fieldList << 'rn'
2103
+ end
2104
+ @fieldListPlain << 'rn'
2105
+ end
2106
+
2107
+ if @items['fieldsHidden'].class.name == 'Array'
2108
+ @items['fieldsHidden'].each { |column|
2109
+ if !@items['fields'].key?(column)
2110
+ @fieldListPlain << strip_aliases(column)
2111
+ if @items['fieldFunction'].key?(column) && !@items['fieldFunction'][column].empty?
2112
+ # fieldFunction's should not have an alias, just the database functions
2113
+ column = @items['fieldFunction'][column] + " " + column
2114
+ end
2115
+ @fieldList << column
2116
+ end
2117
+ }
2118
+ elsif @items['fieldsHidden'].class.name == 'Hash'
2119
+ @items['fieldsHidden'].each { |column|
2120
+ col = column[0]
2121
+ if !@items['fields'].key?(col)
2122
+ @fieldListPlain << strip_aliases(col)
2123
+ if @items['fieldFunction'].key?(column[0]) && !@items['fieldFunction'][column[0]].empty?
2124
+ # fieldFunction's should not have an alias, just the database functions
2125
+ col = @items['fieldFunction'][column[0]] + " " + column[0]
2126
+ end
2127
+ @fieldList << col
2128
+ end
2129
+ }
2130
+ end
2131
+
2046
2132
 
2047
2133
  viewPieces = {}
2134
+ viewPieces['<!--FIELDS_PLAIN-->'] = @fieldListPlain.join(',')
2048
2135
  viewPieces['<!--FIELDS-->'] = @fieldList.join(',')
2049
- viewPieces['<!--SOURCE-->'] = @items['view']
2136
+ viewPieces['<!--SOURCE-->'] = get_view()
2050
2137
 
2051
2138
  statement = WidgetList::Utils::fill(viewPieces, @items['statement']['select']['view'])
2052
2139
 
@@ -2066,7 +2153,9 @@ module WidgetList
2066
2153
  end
2067
2154
 
2068
2155
  if !@items['groupBy'].empty?
2069
- pieces['<!--GROUPBY-->'] += ' GROUP BY ' + @items['groupBy']
2156
+ pieces['<!--GROUPBY-->'] = ' GROUP BY ' + @items['groupBy']
2157
+ else
2158
+ pieces['<!--GROUPBY-->'] = ''
2070
2159
  end
2071
2160
 
2072
2161
  if !@items['LIST_COL_SORT'].empty? || ($_SESSION.key?('LIST_COL_SORT') && $_SESSION['LIST_COL_SORT'].class.name == 'Hash' && $_SESSION['LIST_COL_SORT'].key?(@sqlHash))
@@ -2091,28 +2180,34 @@ module WidgetList
2091
2180
  pieces['<!--ORDERBY-->'] += ' ORDER BY ' + @items['orderBy']
2092
2181
  end
2093
2182
 
2094
- if WidgetList::List.get_database.db_type == 'oracle' && pieces['<!--ORDERBY-->'].empty?
2095
- keys = @items['fields'].keys
2096
- pieces['<!--ORDERBY-->'] += ' ORDER BY ' + keys.first + ' ASC'
2183
+ if get_database.db_type == 'oracle' && pieces['<!--ORDERBY-->'].empty?
2184
+ #oracle needs a field to perform the rank() over
2185
+ #if field is not an "inputs" or a "buttons"
2186
+ #if field is all NULL, then you better watch out as paging will NOT work
2187
+ tmp = @items['fields'].dup.reject { |val|
2188
+ if (!@items['inputs'].key?(val) && !@items['buttons'].key?(val))
2189
+ false
2190
+ else
2191
+ true
2192
+ end
2193
+ }
2194
+
2195
+ keys = tmp.keys
2196
+ pieces['<!--ORDERBY-->'] += ' ORDER BY ' + keys[0] + ' ASC'
2097
2197
  end
2098
2198
 
2099
- case WidgetList::List.get_database.db_type
2199
+ case get_database.db_type
2100
2200
  when 'postgres'
2101
2201
  pieces['<!--LIMIT-->'] = ' LIMIT :HIGH OFFSET :LOW'
2102
2202
  when 'oracle'
2103
- pieces['<!--LIMIT-->'] = ''
2104
2203
 
2105
- if !@filter.empty?
2106
- and_where = ' AND '
2107
- else
2108
- and_where = ' WHERE '
2109
- end
2110
- pieces['<!--WHERE-->'] += and_where +
2111
- '
2204
+ pieces['<!--LIMIT-->'] =
2205
+ '
2206
+ WHERE
2112
2207
  (
2113
- a.rn >= :LOW
2208
+ rn >' + (@sequence > 1 ? '' : '=') + ' :LOW
2114
2209
  AND
2115
- a.rn <= :HIGH
2210
+ rn <= :HIGH
2116
2211
  )
2117
2212
  '
2118
2213
  else
@@ -2122,7 +2217,7 @@ module WidgetList
2122
2217
 
2123
2218
  statement = WidgetList::Utils::fill(pieces, statement)
2124
2219
 
2125
- if @items['rowLimit'] >= @totalRows
2220
+ if @items['rowLimit'].to_i >= @totalRows
2126
2221
  @items['bindVarsLegacy']['LOW'] = 0
2127
2222
  @sequence = 1
2128
2223
  end
@@ -2130,6 +2225,10 @@ module WidgetList
2130
2225
  statement
2131
2226
  end
2132
2227
 
2228
+ def strip_aliases(name='')
2229
+ ((name.include?('.')) ? name.split('.').last.gsub(/'||"/,'') : name.gsub(/'||"/,''))
2230
+ end
2231
+
2133
2232
  def auto_column_name(name='')
2134
2233
  name.gsub(/\_/,' ').gsub(/\-/,' ').capitalize
2135
2234
  end
@@ -2141,10 +2240,8 @@ module WidgetList
2141
2240
  sql = ''
2142
2241
  hashed = false
2143
2242
 
2144
- if !@items['force_count_sql'].empty?
2145
- sql = @items['force_count_sql']
2146
- elsif !@items['view'].empty?
2147
- sql = WidgetList::Utils::fill({'<!--VIEW-->' => @items['view']}, @items['statement']['count']['view'])
2243
+ if !get_view().empty?
2244
+ sql = WidgetList::Utils::fill({'<!--VIEW-->' => get_view(),'<!--GROUPBY-->' => !@items['groupBy'].empty? ? ' GROUP BY ' + @items['groupBy'] : '' }, @items['statement']['count']['view'])
2148
2245
  end
2149
2246
 
2150
2247
  if ! @filter.empty?
@@ -2155,13 +2252,13 @@ module WidgetList
2155
2252
 
2156
2253
  if ! sql.empty?
2157
2254
  if @items['showPagination']
2158
- if WidgetList::List.get_database._select(sql, @items['bindVars'], @items['bindVarsLegacy']) > 0
2159
- rows = WidgetList::List.get_database.final_results['TOTAL'][0]
2255
+ if get_database._select(sql, @items['bindVars'], @items['bindVarsLegacy'], @active_record_model) > 0
2256
+ rows = get_database.final_results['TOTAL'][0]
2160
2257
  else
2161
2258
  rows = 0
2162
2259
  end
2163
2260
  if rows > 0
2164
- @totalRows = rows
2261
+ @totalRows = rows.to_i
2165
2262
  end
2166
2263
  else
2167
2264
  rows = 1
@@ -2177,6 +2274,212 @@ module WidgetList
2177
2274
  rows
2178
2275
  end
2179
2276
 
2277
+ def self.determine_db_type(db_type)
2278
+ if db_type.include?('://')
2279
+ the_type, void = db_type.split("://")
2280
+ if the_type == 'sqlite:/'
2281
+ the_type = 'sqlite'
2282
+ end
2283
+ return the_type.downcase
2284
+ else
2285
+ begin
2286
+ WidgetList::List::load_widget_list_database_yml()
2287
+
2288
+ if $widget_list_db_conf.key?(db_type)
2289
+ if $widget_list_db_conf[db_type]['adapter'].include?('mysql')
2290
+ return 'mysql'
2291
+ elsif $widget_list_db_conf[db_type]['adapter'].include?('postgres')
2292
+ return 'postgres'
2293
+ elsif $widget_list_db_conf[db_type]['adapter'].include?('oracle')
2294
+ return 'oracle'
2295
+ elsif $widget_list_db_conf[db_type]['adapter'].include?('sqlite')
2296
+ return 'sqlite'
2297
+ elsif $widget_list_db_conf[db_type]['adapter'].include?('sqlserver')
2298
+ return 'sqlserver'
2299
+ elsif $widget_list_db_conf[db_type]['adapter'].include?('ibm')
2300
+ return 'db2'
2301
+ end
2302
+ end
2303
+ rescue
2304
+ return ''
2305
+ end
2306
+
2307
+ end
2308
+ end
2309
+
2310
+ def self.load_widget_list_yml
2311
+ if $widget_list_conf.nil?
2312
+ $widget_list_conf = YAML.load(ERB.new(File.new(Rails.root.join("config", "widget-list.yml")).read).result)[Rails.env]
2313
+ end
2314
+ end
2315
+
2316
+ def self.load_widget_list_database_yml
2317
+ if $widget_list_db_conf.nil?
2318
+ $widget_list_db_conf = YAML.load(ERB.new(File.new(Rails.root.join("config", "database.yml")).read).result)
2319
+ end
2320
+ end
2321
+
2322
+ def self.get_db_type(primary)
2323
+ WidgetList::List::load_widget_list_yml()
2324
+ if primary
2325
+ database_conn = $widget_list_conf[:primary]
2326
+ else
2327
+ database_conn = $widget_list_conf[:secondary]
2328
+ end
2329
+ WidgetList::List::determine_db_type(database_conn)
2330
+ end
2331
+
2332
+ def get_db_type(primary)
2333
+ WidgetList::List::get_db_type(primary)
2334
+ end
2335
+
2336
+ def get_view
2337
+ @active_record_model = false
2338
+ if @is_sequel
2339
+ return @items['view']
2340
+ elsif @items['view'].respond_to?('scoped') && @items['view'].scoped.respond_to?('to_sql')
2341
+ @active_record_model = @items['view'].name.constantize
2342
+
2343
+ new_columns = []
2344
+
2345
+ @items['fields'].each { |column, fieldTitle|
2346
+ if @items['fieldFunction'].key?(column) && !@items['fieldFunction'][column].empty?
2347
+ # fieldFunction's should not have an alias, just the database functions
2348
+ column = @items['fieldFunction'][column] + " " + column
2349
+ end
2350
+ new_columns << column
2351
+ }
2352
+
2353
+ if @items['fieldsHidden'].class.name == 'Array' && !@items['fieldsHidden'].empty?
2354
+ @items['fieldsHidden'].each { |columnPivot|
2355
+ if !@items['fields'].key?(columnPivot)
2356
+ if @items['fieldFunction'].key?(columnPivot) && !@items['fieldFunction'][columnPivot].empty?
2357
+ # fieldFunction's should not have an alias, just the database functions
2358
+ columnPivot = @items['fieldFunction'][columnPivot] + " " + columnPivot
2359
+ end
2360
+ new_columns << columnPivot
2361
+ end
2362
+ }
2363
+ elsif @items['fieldsHidden'].class.name == 'Hash' && !@items['fieldsHidden'].empty?
2364
+ @items['fieldsHidden'].each { |columnPivot|
2365
+ if !@items['fields'].key?(columnPivot[0])
2366
+ if @items['fieldFunction'].key?(columnPivot[0]) && !@items['fieldFunction'][columnPivot[0]].empty?
2367
+ # fieldFunction's should not have an alias, just the database functions
2368
+ columnPivot[0] = @items['fieldFunction'][columnPivot[0]] + " " + columnPivot[0]
2369
+ end
2370
+ new_columns << columnPivot[0]
2371
+ end
2372
+ }
2373
+ end
2374
+
2375
+ view = @items['view'].scoped.to_sql
2376
+ sql_from = view[view.index(/FROM/),view.length]
2377
+ view = "SELECT #{new_columns.join(',')} " + sql_from
2378
+
2379
+ return "( #{view} <!--GROUPBY-->) a"
2380
+ else
2381
+ return ""
2382
+ end
2383
+ end
2384
+
2385
+ def connect
2386
+ @has_connected = true
2387
+ begin
2388
+ if Rails.root.join("config", "widget-list.yml").file?
2389
+ WidgetList::List::load_widget_list_yml()
2390
+ if $widget_list_conf.nil?
2391
+ throw 'Configuration file widget-list.yml has no data. Check that (' + Rails.env + ') Rails.env matches the pointers in the file'
2392
+ end
2393
+ @primary_conn = $widget_list_conf[:primary]
2394
+ @secondary_conn = $widget_list_conf[:secondary]
2395
+ else
2396
+ throw 'widget-list.yml not found'
2397
+ end
2398
+
2399
+ @is_sequel = true
2400
+ if @primary_conn != false && ! @primary_conn.include?('://')
2401
+ @is_sequel = false
2402
+ end
2403
+
2404
+ if @secondary_conn != false && !@secondary_conn.include?('://')
2405
+ @is_sequel = false
2406
+ end
2407
+
2408
+ if @primary_conn != false
2409
+ if @primary_conn.include?('://')
2410
+ @widget_list_sequel_conn = Sequel.connect(@primary_conn)
2411
+ @widget_list_sequel_conn.db_type = WidgetList::List::determine_db_type(@primary_conn)
2412
+ else
2413
+ @widget_list_ar_conn = WidgetListActiveRecord.new
2414
+ @widget_list_ar_conn.db_type = WidgetList::List::determine_db_type(@primary_conn)
2415
+ end
2416
+ end
2417
+
2418
+ if @secondary_conn != false
2419
+ if @secondary_conn.include?('://')
2420
+ @widget_list_sequel_conn2 = Sequel.connect(@secondary_conn)
2421
+ @widget_list_sequel_conn2.db_type = WidgetList::List::determine_db_type(@secondary_conn)
2422
+ else
2423
+ @widget_list_ar_conn2 = WidgetListActiveRecord.new
2424
+ @widget_list_ar_conn2.db_type = WidgetList::List::determine_db_type(@secondary_conn)
2425
+ end
2426
+ end
2427
+
2428
+ rescue Exception => e
2429
+ p "widget-list.yml and connection to @widget_list_sequel_conn or @widget_list_sequel_conn2 failed. Please fix and try again (" + e.to_s + ")"
2430
+ end
2431
+
2432
+ end
2433
+
2434
+
2435
+ def self.is_sequel(primary)
2436
+ WidgetList::List::load_widget_list_yml()
2437
+ if primary
2438
+ database_conn = $widget_list_conf[:primary]
2439
+ else
2440
+ database_conn = $widget_list_conf[:secondary]
2441
+ end
2442
+ is_sequel = true
2443
+ if database_conn != false && ! database_conn.include?('://')
2444
+ is_sequel = false
2445
+ end
2446
+ return is_sequel
2447
+ end
2448
+
2449
+ def get_database
2450
+
2451
+ if @has_connected.nil?
2452
+ connect
2453
+ end
2454
+
2455
+ if @is_sequel
2456
+ begin
2457
+ if @widget_list_sequel_conn.class.name.to_s.split('::').first == 'Sequel'
2458
+ if @current_db_selection == 'primary' || @current_db_selection.nil?
2459
+ @widget_list_sequel_conn.test_connection
2460
+ end
2461
+ if @current_db_selection == 'secondary'
2462
+ @widget_list_sequel_conn2.test_connection
2463
+ end
2464
+ else
2465
+ connect
2466
+ end
2467
+ rescue
2468
+ connect
2469
+ end
2470
+ end
2471
+
2472
+ case @current_db_selection
2473
+ when 'primary'
2474
+ return (@is_sequel) ? @widget_list_sequel_conn : @widget_list_ar_conn
2475
+ when 'secondary'
2476
+ return (@is_sequel) ? @widget_list_sequel_conn2 : @widget_list_ar_conn2
2477
+ else
2478
+ return (@is_sequel) ? @widget_list_sequel_conn : @widget_list_ar_conn
2479
+ end
2480
+
2481
+ end
2482
+
2180
2483
  end
2181
2484
 
2182
2485
  end