widget_list 1.0.8 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -277,7 +277,7 @@ Style a row based on the value of the column.
277
277
 
278
278
  begin
279
279
 
280
- list_parms = {}
280
+ list_parms = WidgetList::List::init_config()
281
281
 
282
282
  #
283
283
  # Give it a name, some SQL to feed widget_list and set a noDataMessage
data/lib/widget_list.rb CHANGED
@@ -29,139 +29,7 @@ module WidgetList
29
29
 
30
30
  # Defaults for all configs
31
31
  # See https://github.com/davidrenne/widget_list/blob/master/README.md#feature-configurations
32
- @items = {
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,
60
-
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'],
65
-
66
- #
67
- # Head/Foot
68
- #
69
-
70
- 'customFooter' => '',
71
- 'customHeader' => '',
72
-
73
- #
74
- # Ajax
75
- #
76
- 'ajaxFunctionAll' => '',
77
- 'ajaxFunction' => 'ListJumpMin',
78
-
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' => '',
90
-
91
- #
92
- # Export
93
- #
94
- 'showExport' => true,
95
- 'exportButtonTitle' => 'Export CSV',
96
-
97
- #
98
- # Group By Box
99
- #
100
- 'groupByItems' => [],
101
- 'groupBySelected' => false,
102
- 'groupByLabel' => 'Group By',
103
- 'groupByClick' => '',
104
- 'groupByClickDefault' => "ListChangeGrouping('<!--NAME-->', this);",
105
-
106
-
107
- #
108
- # Advanced searching
109
- #
110
- 'listSearchForm' => '',
111
-
112
- #
113
- # Column Specific
114
- #
115
- 'columnStyle' => {},
116
- 'columnClass' => {},
117
- 'columnPopupTitle' => {},
118
- 'columnSort' => {},
119
- 'columnWidth' => {},
120
- 'columnNoSort' => {},
121
-
122
- #
123
- # Column Border (on right)
124
- #
125
- 'borderedColumns' => false,
126
- 'borderColumnStyle' => '1px solid #CCCCCC',
127
-
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' => {}
164
- }
32
+ @items = WidgetList::List::get_defaults()
165
33
 
166
34
  @csv = []
167
35
  @csv << []
@@ -337,27 +205,27 @@ module WidgetList
337
205
 
338
206
  #Ajax ListJump
339
207
  if ! $_REQUEST.empty?
340
- if $_REQUEST.key?('LIST_FILTER_ALL')
208
+ if $_REQUEST.key?('LIST_FILTER_ALL') && !$_REQUEST['LIST_FILTER_ALL'].empty?
341
209
  @items['LIST_FILTER_ALL'] = $_REQUEST['LIST_FILTER_ALL']
342
210
  @isJumpingList = true
343
211
  end
344
212
 
345
- if $_REQUEST.key?('LIST_COL_SORT')
213
+ if $_REQUEST.key?('LIST_COL_SORT') && !$_REQUEST['LIST_COL_SORT'].empty?
346
214
  @items['LIST_COL_SORT'] = $_REQUEST['LIST_COL_SORT']
347
215
  @isJumpingList = true
348
216
  end
349
217
 
350
- if $_REQUEST.key?('LIST_COL_SORT_ORDER')
218
+ if $_REQUEST.key?('LIST_COL_SORT_ORDER') && !$_REQUEST['LIST_COL_SORT_ORDER'].empty?
351
219
  @items['LIST_COL_SORT_ORDER'] = $_REQUEST['LIST_COL_SORT_ORDER']
352
220
  @isJumpingList = true
353
221
  end
354
222
 
355
- if $_REQUEST.key?('LIST_SEQUENCE')
223
+ if $_REQUEST.key?('LIST_SEQUENCE') && !$_REQUEST['LIST_SEQUENCE'].empty?
356
224
  @items['LIST_SEQUENCE'] = $_REQUEST['LIST_SEQUENCE'].to_i
357
225
  @isJumpingList = true
358
226
  end
359
227
 
360
- if $_REQUEST.key?('ROW_LIMIT')
228
+ if $_REQUEST.key?('ROW_LIMIT') && !$_REQUEST['ROW_LIMIT'].empty?
361
229
  @items['ROW_LIMIT'] = $_REQUEST['ROW_LIMIT']
362
230
  @isJumpingList = true
363
231
 
@@ -619,6 +487,152 @@ module WidgetList
619
487
  end
620
488
  end
621
489
 
490
+ def self.get_defaults()
491
+ {
492
+ 'errors' => [],
493
+ 'name' => ([*('A'..'Z'),*('0'..'9')]-%w(0 1 I O)).sample(16).join,
494
+ 'database' => 'primary', #
495
+ 'title' => '',
496
+ 'listDescription' => '',
497
+ 'pageId' => $_SERVER['PATH_INFO'],
498
+ 'view' => '',
499
+ 'data' => {},
500
+ 'collClass' => '',
501
+ 'collAlign' => '',
502
+ 'fields' => {},
503
+ 'fieldsHidden' => [],
504
+ 'bindVars' => [],
505
+ 'bindVarsLegacy' => {},
506
+ 'links' => {},
507
+ 'buttons' => {},
508
+ 'inputs' => {},
509
+ 'filter' => [],
510
+ 'groupBy' => '',
511
+ 'rowStart' => 0,
512
+ 'rowLimit' => 10,
513
+ 'orderBy' => '',
514
+ 'allowHTML' => true,
515
+ 'searchClear' => false,
516
+ 'searchClearAll' => false,
517
+ 'showPagination' => true,
518
+ 'searchSession' => true,
519
+
520
+ #
521
+ # carryOverRequests will allow you to post custom things from request to all sort/paging URLS for each ajax
522
+ #
523
+ 'carryOverRequsts' => ['switch_grouping'],
524
+
525
+ #
526
+ # Head/Foot
527
+ #
528
+
529
+ 'customFooter' => '',
530
+ 'customHeader' => '',
531
+
532
+ #
533
+ # Ajax
534
+ #
535
+ 'ajaxFunctionAll' => '',
536
+ 'ajaxFunction' => 'ListJumpMin',
537
+
538
+ #
539
+ # Search
540
+ #
541
+ 'showSearch' => true,
542
+ 'searchOnkeyup' => '',
543
+ 'searchOnclick' => '',
544
+ 'searchIdCol' => 'id',
545
+ 'searchTitle' => 'Search by Id or a list of Ids and more',
546
+ 'searchFieldsIn' => {},
547
+ 'searchFieldsOut' => {'id'=>true},
548
+ 'templateFilter' => '',
549
+
550
+ #
551
+ # Export
552
+ #
553
+ 'showExport' => true,
554
+ 'exportButtonTitle' => 'Export CSV',
555
+
556
+ #
557
+ # Group By Box
558
+ #
559
+ 'groupByItems' => [],
560
+ 'groupBySelected' => false,
561
+ 'groupByLabel' => 'Group By',
562
+ 'groupByClick' => '',
563
+ 'groupByClickDefault' => "ListChangeGrouping('<!--NAME-->', this);",
564
+
565
+
566
+ #
567
+ # Advanced searching
568
+ #
569
+ 'listSearchForm' => '',
570
+
571
+ #
572
+ # Column Specific
573
+ #
574
+ 'columnStyle' => {},
575
+ 'columnClass' => {},
576
+ 'columnPopupTitle' => {},
577
+ 'columnSort' => {},
578
+ 'columnWidth' => {},
579
+ 'columnNoSort' => {},
580
+
581
+ #
582
+ # Column Border (on right)
583
+ #
584
+ 'borderedColumns' => false,
585
+ 'borderColumnStyle' => '1px solid #CCCCCC',
586
+
587
+ #
588
+ # Row specifics
589
+ #
590
+ 'rowClass' => '',
591
+ 'rowColorByStatus' => {},
592
+ 'rowStylesByStatus' => {},
593
+ 'rowOffsets' => ['FFFFFF','FFFFFF'],
594
+
595
+ 'class' => 'listContainerPassive',
596
+ 'tableclass' => 'tableBlowOutPreventer',
597
+ 'noDataMessage' => 'Currently no data.',
598
+ 'useSort' => true,
599
+ 'headerClass' => {},
600
+ 'fieldFunction' => {},
601
+ 'buttonVal' => 'templateListJump',
602
+ 'linkFunction' => 'ButtonLinkPost',
603
+ 'template' => '',
604
+ 'LIST_COL_SORT_ORDER' => 'ASC',
605
+ 'LIST_COL_SORT' => '',
606
+ 'LIST_FILTER_ALL' => '',
607
+ 'ROW_LIMIT' => '',
608
+ 'LIST_SEQUENCE' => 1,
609
+ 'NEW_SEARCH' => false,
610
+
611
+ #
612
+ # Checkbox
613
+ #
614
+ 'checkedClass' => 'widgetlist-checkbox',
615
+ 'checkedFlag' => {},
616
+ 'storeSessionChecks' => false,
617
+
618
+ #
619
+ # Hooks
620
+ #
621
+ 'columnHooks' => {},
622
+ 'rowHooks' => {}
623
+ }
624
+ end
625
+
626
+ def self.init_config()
627
+ list_parms = {}
628
+ WidgetList::List::get_defaults.each { |k,v|
629
+ if (v.is_a?(Array) || v.is_a?(Hash)) && v.empty?
630
+ list_parms[k] = v
631
+ end
632
+ }
633
+ return list_parms
634
+ end
635
+
622
636
  def skip_column(fieldName)
623
637
  skip = false
624
638
  (@items['inputs']||{}).each { |k,v|
@@ -916,6 +930,9 @@ module WidgetList
916
930
  if ! @items['templateFilter'].empty?
917
931
  @templateFill['<!--FILTER_HEADER-->'] = @items['templateFilter']
918
932
  else
933
+
934
+ @templateFill['<!--FILTER_HEADER-->'] = ''
935
+
919
936
  if !$_REQUEST.key?('search_filter') && !@isJumpingList
920
937
 
921
938
  #Search page url
@@ -1029,11 +1046,12 @@ module WidgetList
1029
1046
  end
1030
1047
  @templateFill['<!--FILTER_HEADER-->'] += '<div class="fake-select"><div class="label">' + @items['groupByLabel'] + ':</div> ' + WidgetList::Widgets::widget_input(list_group) + '</div>'
1031
1048
 
1032
- if @items['showExport']
1033
- @templateFill['<!--FILTER_HEADER-->'] += WidgetList::Widgets::widget_button(@items['exportButtonTitle'], {'onclick' => 'ListExport(\'' + @items['name'] + '\');'}, true)
1034
- end
1049
+ end
1035
1050
 
1051
+ if @items['showExport']
1052
+ @templateFill['<!--FILTER_HEADER-->'] += WidgetList::Widgets::widget_button(@items['exportButtonTitle'], {'onclick' => 'ListExport(\'' + @items['name'] + '\');'}, true)
1036
1053
  end
1054
+
1037
1055
  end
1038
1056
  end
1039
1057
 
@@ -1489,6 +1507,17 @@ module WidgetList
1489
1507
  input['value'] = @results[ input['value'].upcase ][row]
1490
1508
  end
1491
1509
 
1510
+ if input.key?('disabled_if') && input['disabled_if'].class.name == 'Proc'
1511
+ row_tmp = {}
1512
+ @results.map { |column| column }.each { |col|
1513
+ row_tmp[ col[0] ] = col[1][row]
1514
+ }
1515
+
1516
+ if input['disabled_if'].call(row_tmp)
1517
+ input['disabled'] = true
1518
+ end
1519
+ end
1520
+
1492
1521
  #
1493
1522
  # Append class handle
1494
1523
  #
@@ -1695,7 +1724,7 @@ module WidgetList
1695
1724
  end
1696
1725
 
1697
1726
  def self.build_drill_down_link(listId,drillDownName,dataToPassFromView,columnToShow,columnAlias='',extraFunction='',functionName='ListDrillDown',columnClass='',color='blue',extraJSFunctionParams='',primary=true)
1698
- warn "`build_drill_down_link` is deprecated. Use `build_drill_down` instead."
1727
+ ActiveSupport::Deprecation.warn "`build_drill_down_link` is deprecated. Use `build_drill_down` instead."
1699
1728
  if columnAlias.empty?
1700
1729
  columnAlias = columnToShow
1701
1730
  end
@@ -2206,14 +2235,10 @@ module WidgetList
2206
2235
 
2207
2236
  if !@items['LIST_COL_SORT'].empty? || ($_SESSION.key?('LIST_COL_SORT') && $_SESSION['LIST_COL_SORT'].class.name == 'Hash' && $_SESSION['LIST_COL_SORT'].key?(@sqlHash))
2208
2237
  if ! @items['LIST_COL_SORT'].empty?
2209
- if @items['fields'].key?(@items['LIST_COL_SORT'])
2210
- pieces['<!--ORDERBY-->'] += ' ORDER BY ' + tick_field() + @items['LIST_COL_SORT'] + tick_field() + " " + @items['LIST_COL_SORT_ORDER']
2211
- end
2238
+ pieces['<!--ORDERBY-->'] += ' ORDER BY ' + tick_field() + @items['LIST_COL_SORT'] + tick_field() + " " + @items['LIST_COL_SORT_ORDER']
2212
2239
  else
2213
2240
  $_SESSION['LIST_COL_SORT'][@sqlHash].each_with_index { |order,void|
2214
- if @items['fields'].key?(order[0])
2215
- pieces['<!--ORDERBY-->'] += ' ORDER BY ' + tick_field() + order[0] + tick_field() + " " + order[1]
2216
- end
2241
+ pieces['<!--ORDERBY-->'] += ' ORDER BY ' + tick_field() + order[0] + tick_field() + " " + order[1]
2217
2242
  } if $_SESSION.key?('LIST_COL_SORT') && $_SESSION['LIST_COL_SORT'].class.name == 'Hash' && $_SESSION['LIST_COL_SORT'].key?(@sqlHash)
2218
2243
  end
2219
2244
 
@@ -94,6 +94,10 @@ module Sequel
94
94
  sql
95
95
  end
96
96
 
97
+ def _get_row_value(row,fieldName)
98
+ row.send(fieldName).to_s
99
+ end
100
+
97
101
  # @param [Object or String] sql_or_obj
98
102
  # will either take raw SQL or a Sequel object
99
103
  # @param [Array] bind
@@ -145,7 +149,7 @@ module Sequel
145
149
  if first == 1
146
150
  @final_results[fieldName.to_s.upcase] = []
147
151
  end
148
- @final_results[fieldName.to_s.upcase] << ((row.send(fieldName).nil?) ? '' : row.send(fieldName))
152
+ @final_results[fieldName.to_s.upcase] << ((row.send(fieldName).nil? && row.attributes[fieldName].nil?) ? '' : _get_row_value(row,fieldName))
149
153
  }
150
154
  first = 0
151
155
  }
@@ -47,7 +47,7 @@ $G_TEMPLATE.deep_merge!({'widget' =>
47
47
  {'checkbox'=>
48
48
  {'default' =>
49
49
  '
50
- <input type="checkbox" class="<!--INPUT_CLASS-->" style="<!--INPUT_STYLE-->" id="<!--ID-->" name="<!--NAME-->" value="<!--VALUE-->" onclick="<!--ONCLICK-->" <!--CHECKED-->>
50
+ <input type="checkbox" class="<!--INPUT_CLASS-->" style="<!--INPUT_STYLE-->" id="<!--ID-->" name="<!--NAME-->" value="<!--VALUE-->" onclick="<!--ONCLICK-->" <!--CHECKED--> <!--DISABLED-->>
51
51
  <!--REQUIRED-->'
52
52
  }
53
53
  }
@@ -1,3 +1,3 @@
1
1
  module WidgetList
2
- VERSION = "1.0.8"
2
+ VERSION = "1.0.9"
3
3
  end
@@ -42,8 +42,10 @@ module WidgetList
42
42
  items['input_class'] = items['class']
43
43
  end
44
44
 
45
- if !items['disabled']
46
- items['input_class'] += ' disabled'
45
+ if items['disabled']
46
+ items['disabled'] = 'disabled'
47
+ else
48
+ items['disabled'] = ''
47
49
  end
48
50
 
49
51
  if items['hidden'] == true
@@ -60,7 +62,8 @@ module WidgetList
60
62
  '<!--VALUE-->' => items['value'],
61
63
  '<!--REQUIRED-->' => items['template_required'],
62
64
  '<!--CHECKED-->' => items['checked'],
63
- '<!--VALUE-->' => items['value']
65
+ '<!--VALUE-->' => items['value'],
66
+ '<!--DISABLED-->' => items['disabled']
64
67
  }
65
68
 
66
69
  return WidgetList::Utils::fill(pieces, items['template'])
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: widget_list
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.8
4
+ version: 1.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-20 00:00:00.000000000 Z
12
+ date: 2013-02-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sequel