zuora_connect_ui 0.2.0 → 0.2.2

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.
Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -0
  3. data/app/assets/javascripts/zuora_connect_ui.js +6 -0
  4. data/app/assets/javascripts/zuora_connect_ui/datatable.js +327 -2
  5. data/app/assets/javascripts/zuora_connect_ui/iframe.js +41 -0
  6. data/app/assets/javascripts/zuora_connect_ui/input.js +3 -2
  7. data/app/assets/stylesheets/_zuora_connect_ui.scss +3 -0
  8. data/app/assets/stylesheets/zuora_connect_ui/base.scss +5 -1
  9. data/app/assets/stylesheets/zuora_connect_ui/breadcrumb_bar.scss +15 -17
  10. data/app/assets/stylesheets/zuora_connect_ui/buttons.scss +94 -61
  11. data/app/assets/stylesheets/zuora_connect_ui/datatables.scss +71 -7
  12. data/app/assets/stylesheets/zuora_connect_ui/datepicker.scss +1 -0
  13. data/app/assets/stylesheets/zuora_connect_ui/input.scss +42 -28
  14. data/app/assets/stylesheets/zuora_connect_ui/modal.scss +41 -2
  15. data/app/assets/stylesheets/zuora_connect_ui/tabs.scss +4 -3
  16. data/app/helpers/datatable_helper.rb +0 -15
  17. data/app/views/partials/_filters.html.erb +33 -34
  18. data/app/views/partials/_table.html.erb +206 -364
  19. data/lib/zuora_connect_ui/version.rb +1 -1
  20. data/vendor/assets/contextMenu/css/jquery.contextMenu.min.css.map +1 -0
  21. data/vendor/assets/contextMenu/css/jquery.contextMenu.min.scss +16 -0
  22. data/vendor/assets/contextMenu/fonts/context-menu-icons.eot +0 -0
  23. data/vendor/assets/contextMenu/fonts/context-menu-icons.ttf +0 -0
  24. data/vendor/assets/contextMenu/fonts/context-menu-icons.woff +0 -0
  25. data/vendor/assets/contextMenu/fonts/context-menu-icons.woff2 +0 -0
  26. data/vendor/assets/contextMenu/js/jquery.contextMenu.min.js +18 -0
  27. data/vendor/assets/contextMenu/js/jquery.contextMenu.min.js.map.js +1 -0
  28. data/vendor/assets/contextMenu/js/jquery.ui.position.min.js +6 -0
  29. data/vendor/assets/idb-keyval/js/idb-keyval-iife.js +100 -0
  30. metadata +13 -2
@@ -59,6 +59,7 @@
59
59
 
60
60
  .zuo-datepicker.date {
61
61
  display: block;
62
+ position: relative;
62
63
 
63
64
  .input-group-addon {
64
65
  font-size: 1.1rem;
@@ -4,9 +4,9 @@
4
4
  margin-top: 3px;
5
5
 
6
6
  + label::before {
7
- top: .125rem;
8
- transition: all .2s ease;
9
- border-radius: .1rem;
7
+ top: 0.125rem;
8
+ transition: all 0.2s ease;
9
+ border-radius: 0.1rem;
10
10
  border-color: #d3d7d8; // default is #ccc
11
11
  }
12
12
 
@@ -17,6 +17,7 @@
17
17
  overflow: hidden;
18
18
  line-height: 1.25rem;
19
19
  color: $neutral-4;
20
+ text-align: left;
20
21
 
21
22
  -webkit-transition: all 0.4s ease;
22
23
  -moz-transition: all 0.4s ease;
@@ -42,16 +43,16 @@
42
43
  + label {
43
44
  cursor: normal;
44
45
  &:before {
45
- transition: all .4s ease;
46
+ transition: all 0.4s ease;
46
47
  height: 1rem;
47
48
  width: 1rem;
48
49
  }
49
50
  &:after {
50
51
  transform: none;
51
- height: .4rem;
52
- width: .4rem;
53
- top: .3rem;
54
- left: .3rem;
52
+ height: 0.4rem;
53
+ width: 0.4rem;
54
+ top: 0.3rem;
55
+ left: 0.3rem;
55
56
  background-color: $neutral-4;
56
57
  }
57
58
  }
@@ -75,7 +76,7 @@ textarea.zuo-textbox {
75
76
  }
76
77
 
77
78
  input[type="file"] {
78
- margin-left: .875rem;
79
+ margin-left: 0.875rem;
79
80
  line-height: 2.5;
80
81
 
81
82
  + label {
@@ -96,7 +97,7 @@ input[type="file"] {
96
97
  color: $neutral-1;
97
98
  background: transparent;
98
99
  transition: border-color 0.2s;
99
- padding: 0rem 0rem .375rem 0rem;
100
+ padding: 0rem 0rem 0.375rem 0rem;
100
101
 
101
102
  &:not([readonly]):focus {
102
103
  border-color: $support-1;
@@ -108,13 +109,17 @@ input[type="file"] {
108
109
  }
109
110
  }
110
111
 
112
+ .has-error .zuo-textbox {
113
+ border-bottom: 1px solid $support-4;
114
+ }
115
+
111
116
  label.zuo-floating-label {
112
117
  position: relative;
113
118
  top: -1.4375rem;
114
119
  display: block;
115
120
  transition: 0.2s;
116
- font-size: .875rem;
117
- line-height: .875rem;
121
+ font-size: 0.875rem;
122
+ line-height: 0.875rem;
118
123
  font-weight: normal;
119
124
  color: #6e7c89;
120
125
  margin-bottom: 0;
@@ -124,7 +129,7 @@ label.zuo-floating-label {
124
129
  .zuo-floating-label.floating,
125
130
  .zuo-textbox:focus + .zuo-floating-label,
126
131
  select + .select2-container--open + .zuo-floating-label {
127
- font-size: .75rem;
132
+ font-size: 0.75rem;
128
133
  top: -2.6875rem;
129
134
  }
130
135
 
@@ -133,20 +138,19 @@ select + .select2-container--open + .zuo-floating-label {
133
138
  color: $support-1;
134
139
  }
135
140
 
136
-
137
141
  .select2-container {
138
142
  .select2-selection {
139
- border: none;
143
+ border: none;
140
144
  }
141
145
 
142
146
  .select2-dropdown {
143
147
  border: 1px solid $neutral-shadow;
144
148
  box-shadow: 0 1px 8px -1px $neutral-shadow;
145
- border-radius: .25rem;
146
- padding: .5rem 0;
149
+ border-radius: 0.25rem;
150
+ padding: 0.5rem 0;
147
151
 
148
152
  .select2-results__option[role="treeitem"] {
149
- padding: .25rem .75rem;
153
+ padding: 0.25rem 0.75rem;
150
154
  }
151
155
 
152
156
  .select2-results__option[aria-selected="true"] {
@@ -171,15 +175,20 @@ select + .select2-container--open + .zuo-floating-label {
171
175
  }
172
176
 
173
177
  .select2-dropdown--below {
174
- top: .5rem;
178
+ top: 0.5rem;
175
179
  }
176
180
  }
177
181
 
178
182
  .select2-container--bootstrap {
183
+ .select2-selection--multiple .select2-selection__clear {
184
+ margin-top: 0;
185
+ }
186
+
179
187
  .select2-selection {
188
+ position: relative;
180
189
  box-shadow: none;
181
190
  height: auto;
182
- padding: 0 2rem .375rem 0;
191
+ padding: 0 2rem 0.375rem 0;
183
192
  margin-top: 1rem;
184
193
  border-radius: 0;
185
194
 
@@ -198,10 +207,10 @@ select + .select2-container--open + .zuo-floating-label {
198
207
  .select2-selection__choice__remove {
199
208
  width: 1rem;
200
209
  height: 1rem;
201
- font-size: .75rem;
210
+ font-size: 0.75rem;
202
211
  line-height: 1;
203
212
  position: absolute;
204
- right: .25rem;
213
+ right: 0.25rem;
205
214
  top: 3.5px;
206
215
  text-align: center;
207
216
  margin-right: 0;
@@ -230,9 +239,9 @@ select + .select2-container--open + .zuo-floating-label {
230
239
  &:before {
231
240
  content: "\E90D";
232
241
  font-family: webicons;
233
- font-size: .75rem;
242
+ font-size: 0.75rem;
234
243
  color: #a5a3b6;
235
- transition: color .2s ease;
244
+ transition: color 0.2s ease;
236
245
  }
237
246
 
238
247
  b {
@@ -256,23 +265,28 @@ select + .select2-container--open + .zuo-floating-label {
256
265
  }
257
266
 
258
267
  &.select2-container--disabled .select2-selection--single,
259
- &.select2-container--disabled .select2-selection--multiple .select2-selection__choice {
268
+ &.select2-container--disabled
269
+ .select2-selection--multiple
270
+ .select2-selection__choice {
260
271
  background-color: transparent;
261
272
 
262
273
  .select2-selection__rendered {
263
274
  color: #6e7c89;
264
275
  }
265
276
  }
266
-
267
277
  }
268
278
 
269
- .select2-container.select2-container--focus .select2-selection, .select2-container--bootstrap.select2-container--open .select2-selection {
279
+ .select2-container.select2-container--focus .select2-selection,
280
+ .select2-container--bootstrap.select2-container--open .select2-selection {
270
281
  box-shadow: none;
271
282
  }
272
283
 
273
284
  .select2-container .select2-selection--single .select2-selection__arrow b {
274
285
  border-color: $neutral-1 transparent transparent transparent;
275
286
  }
276
- .select2-container.select2-container--open .select2-selection .select2-selection__arrow b {
287
+ .select2-container.select2-container--open
288
+ .select2-selection
289
+ .select2-selection__arrow
290
+ b {
277
291
  border-color: transparent transparent $neutral-1 transparent;
278
292
  }
@@ -33,8 +33,47 @@
33
33
 
34
34
  #z_hub_modal {
35
35
  div.popover {
36
- &.left, &.top {
37
- max-width:500px;
36
+ &.left,
37
+ &.top {
38
+ max-width: 500px;
38
39
  }
39
40
  }
40
41
  }
42
+
43
+ form {
44
+ &.loading {
45
+ .modal-body {
46
+ opacity: .15;
47
+ }
48
+ .overlay {
49
+ display: block;
50
+ #loading_form_icon {
51
+ visibility: visible;
52
+ color: #3c4d55;
53
+ }
54
+ }
55
+ }
56
+ .overlay {
57
+ display: none;
58
+ position: absolute;
59
+ top: 0;
60
+ right: 0;
61
+ bottom: 61px;
62
+ left: 0;
63
+
64
+ #loading_form_icon {
65
+ display: inline-block;
66
+ position: absolute;
67
+ font-size: 60px;
68
+ right: 45%;
69
+ top: 55%;
70
+ visibility: hidden;
71
+ z-index: 1000;
72
+ }
73
+ }
74
+ }
75
+
76
+ #loading_form_icon {
77
+ display:none;
78
+ }
79
+
@@ -9,7 +9,7 @@
9
9
  }
10
10
  }
11
11
 
12
- ul.tab-header{
12
+ ul.tab-header {
13
13
  padding: 0 1rem;
14
14
  border-bottom: 2px solid $neutral-2;
15
15
 
@@ -20,11 +20,12 @@ ul.tab-header{
20
20
  // non-hover tab styling
21
21
  background-color: transparent; // Override bootstrap default
22
22
  font-weight: 600;
23
- padding: .5rem;
23
+ padding: 0.5rem;
24
24
  margin-right: 2rem;
25
25
  margin-bottom: -3px; // pulls bottom border under the navbar bottom border
26
26
 
27
- &:hover, &:focus {
27
+ &:hover,
28
+ &:focus {
28
29
  background-color: transparent;
29
30
  }
30
31
  }
@@ -33,19 +33,4 @@ module DatatableHelper
33
33
  }.merge(request.query_parameters), formats: [:html]
34
34
  )
35
35
  end
36
-
37
- def return_cookie_filters(cookie_key, filter_key, values: nil, defaults: nil, type: nil)
38
- raise "Error" if values.nil? && type != "boolean"
39
- values = ["false"] if type == "boolean"
40
- values = values.map {|v| v[1].to_s} if type == "select" || values[0].class == Array
41
- defaults ||= [] if type == "select"
42
- if cookies[cookie_key].present?
43
- json = JSON.parse(cookies[cookie_key])
44
- if json[filter_key].present?
45
- checked_envs ||= json[filter_key] if type == "boolean" || type == "select"
46
- checked_envs ||= values.map {|v| json[filter_key].include?(v) ? v : nil }.compact
47
- end
48
- end
49
- checked_envs ||= defaults.nil? ? (type == "checkbox" ? values : nil) : defaults
50
- end
51
36
  end
@@ -1,39 +1,38 @@
1
- <% placeholder = defined?(table_filter["placeholder"]) ? table_filter["placeholder"] : "" %>
2
- <% prompt = defined?(table_filter["prompt"]) ? table_filter["prompt"] : "" %>
3
- <% index = defined?(index) ? index : nil %>
4
- <% filter_count = defined?(filter_count) ? filter_count : nil %>
5
- <% width = defined?(table_filter["width"]) ? table_filter["width"] : "100%" %>
6
- <% allow_clear = table_filter.key?("allow-clear") ? table_filter["allow-clear"] : true %>
7
- <% searchable = table_filter.key?("searchable") && table_filter["searchable"] ? 0 : -1 %>
1
+ <% filter_name = table_filter["name"].parameterize('_') %>
2
+ <% prompt = table_filter.fetch("prompt", "") %>
8
3
 
9
- <% if table_filter["type"] == "checkbox" %>
10
- <div class="btn-group">
11
- <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
12
- <%= prompt %> <span class="caret"></span>
13
- </button>
14
- <ul class="dropdown-menu" >
15
- <li>
4
+ <div class="table-filter">
5
+ <% if table_filter["type"] == "checkbox" %>
6
+ <div class="dropdown checkbox-filter">
7
+ <div class="dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
8
+ <%= prompt %> <span class="z-icon-desc"></span>
9
+ </div>
10
+ <ul class="dropdown-menu" >
16
11
  <% table_filter["values"].each do |type| %>
17
- <div class="checkbox checkbox-success" style='margin-left: 15px;'>
18
- <input type="checkbox" name='<%= table_filter["name"].parameterize('_') %>[]' <%= table_filter["selection"].include?(type) ? 'checked' : ''%> value="<%= type %>"><label for="<%= table_filter["name"].parameterize('_') %>"><%= type %></label>
19
- </div>
12
+ <li class="checkbox-row">
13
+ <div class="checkbox">
14
+ <input type="checkbox" name='<%= filter_name %>[]' value="<%= type %>">
15
+ <label for="<%= filter_name %>"><%= type %></label>
16
+ </div>
17
+ </li>
20
18
  <% end %>
21
- </li>
22
- </ul>
23
- </div>
24
- <% elsif ["select", "group-select"].include?(table_filter["type"]) %>
25
- <div class="btn-group <%= index > 0 ? 'select2-bootstrap-prepend' : '' %> <%= (index + 1 != filter_count && filter_count > 1) ? 'select2-bootstrap-append' : '' %>">
26
- <% if table_filter["type"] == "select" %>
27
- <%= select_tag(table_filter["name"].parameterize('_'), options_for_select(table_filter["values"], table_filter["selection"]), options = {:prompt => prompt, :data =>{:placeholder => placeholder, "allow-clear" => allow_clear }}) %>
28
- <% elsif table_filter["type"] == "group-select" %>
29
- <%= select_tag(table_filter["name"].parameterize('_'), grouped_options_for_select(table_filter["values"], table_filter["selection"]), options = {:prompt => prompt, :data =>{:placeholder => placeholder, "allow-clear" => allow_clear }}) %>
19
+ </ul>
20
+ </div>
21
+ <% elsif ["select", "group-select"].include?(table_filter["type"]) %>
22
+ <% option_tags = table_filter["type"] == "select" ? options_for_select(table_filter["values"]) : grouped_options_for_select(table_filter["values"]) %>
23
+ <%= select_tag(filter_name, option_tags, options = {:prompt => prompt}) %>
24
+ <% content_for :scripts do %>
25
+ $('#<%= table_name %>_content select[name="<%= filter_name %>"]').select2({
26
+ theme: "bootstrap",
27
+ minimumResultsForSearch: <%= table_filter.key?("searchable") && table_filter["searchable"] ? 0 : -1 %>,
28
+ width: '<%= table_filter.fetch('width', '100%') %>',
29
+ dropdownAutoWidth: true,
30
+ placeholder: '<%= table_filter.fetch('placeholder', '') %>',
31
+ allowClear: <%= table_filter.fetch('allow-clear', true) %>
32
+ });
30
33
  <% end %>
31
- </div>
32
- <% content_for :scripts do %>
33
- $('#<%= "#{table_name}_content" %>').find('select[name="<%= table_filter["name"].parameterize('_') %>"]').select2({theme: "bootstrap", minimumResultsForSearch: <%= searchable %>, width: '<%= width %>', allowClear: <%= allow_clear %>})
34
+ <% elsif table_filter["type"] == "boolean" %>
35
+ <input type="checkbox" value="true" name="<%= filter_name %>">
36
+ <label for="<%= filter_name %>"><%= table_filter["name"] %></label>
34
37
  <% end %>
35
- <% elsif table_filter["type"] == "boolean" %>
36
- <div class="btn-group" style="margin-left:10px">
37
- <input type="checkbox" value="true" name='<%= table_filter["name"].parameterize('_') %>' <%= table_filter["selection"] == "true" ? 'checked' : ''%>><label for="<%= table_filter["name"].parameterize('_') %>"><%= table_filter["name"] %></label>
38
- </div>
39
- <% end %>
38
+ </div>
@@ -1,395 +1,237 @@
1
- <% columns = columns.map{ |column| column.symbolize_keys! } %>
2
- <% if !cookies["#{table_name}_table"].blank? %>
3
- <% json = JSON.parse(cookies["#{table_name}_table"]) %>
4
- <% if !json['columns'].blank? %>
5
- <% columns.each_with_index do |column, key| %>
6
- <% column[:visible] = json['columns'].include?(column[:data].to_s) ? true : false %>
7
- <% end %>
8
- <% end %>
9
- <% if !json['view'].blank? %>
10
- <% default_view = json['view'] %>
11
- <% end %>
12
- <% sort = json['sort'].blank? ? sort : json['sort'] %>
13
- <% initial_size = json['table_size'].blank? ? initial_size : json['table_size'] %>
14
- <% ordering = json['ordering'].blank? ? [] : json['ordering'] %>
15
- <% end %>
16
-
17
- <% if !ordering.blank? %>
18
- <% columns = columns.sort_by{ |v| ordering.index(v[:data]).blank? ? 9999 : ordering.index(v[:data])} %>
19
- <% end %>
20
- <% mapping = columns.each_with_index.map {|v,i| [v[:data],i]}.to_h %>
21
- <% sort = sort.map{|col,dir| [mapping[col].blank? ? 1 : mapping[col] ,dir]} %>
22
- <% debug = !defined?(debug) ? false : debug %>
1
+ <% debug = defined?(debug) ? debug : false %>
2
+ <% defer_loading = defined?(defer_loading) ? defer_loading : false %>
23
3
 
24
- <div id='<%= "#{table_name}_content" %>'>
25
- <div class='table-header'>
26
- <div class="table-header-left" >
27
- <div class="btn-group">
4
+ <div id="<%= table_name %>_content">
5
+ <div class="table-header">
6
+ <div class="table-header-left">
28
7
  <% if defined?(table_filters) %>
29
- <% table_filters.each_with_index do |table_filter, index| %>
30
- <% table_filter["selection"] = return_cookie_filters(cookie_key: "#{table_name}_table", filter_key: "#{table_filter["name"].parameterize('_')}_filter", values: table_filter["values"], type: table_filter["type"], defaults: table_filter["defaults"]) %>
31
- <%= render(:partial=>"partials/filters", locals: {:table_filter => table_filter, :index => index, :filter_count => table_filters.size, :table_name => table_name}, :formats => [:html]) %>
8
+ <% table_filters.each do |table_filter| %>
9
+ <%= render(:partial=>"partials/filters", locals: {:table_filter => table_filter, :filter_count => table_filters.size, :table_name => table_name}, :formats => [:html]) %>
32
10
  <% end %>
33
11
  <% end %>
34
- </div>
35
12
  </div>
36
13
 
37
- <div class="table-header-right" >
38
- <div class="btn-group" data-toggle="buttons">
39
- <% if defined?(table_actions) && !table_actions.blank? %>
40
- <%= table_actions %>
14
+ <div class="table-header-right">
15
+ <% if defined?(table_actions) && table_actions.present? %>
16
+ <% if table_actions.class == Hash %>
17
+ <div class="btn-group">
18
+ <span id="<%= table_name %>_actions" class="table-btn" data-items="<%= raw(table_actions.to_json) %>">
19
+ <i class='fa fa-object-ungroup'></i>
20
+ </span>
21
+ </div>
22
+ <% else %>
23
+ <%= table_actions %>
41
24
  <% end %>
42
- <div class="dropdown">
43
- <button type="button" class="hidden table-btn dropdown-toggle group_actions" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
44
- <span class='fa fa-gears'></span>
45
- </button>
46
- <ul class="dropdown-menu" >
47
- <li style="white-space: nowrap;"><div class="col-sm-12">Export</div></li>
48
- </ul>
49
- </div>
50
- <div class="dropdown">
51
- <button id='<%= "#{table_name}_visiblity" %>' type="button" class="table-btn dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
52
- <span class='fa fa-eye'></span>
53
- </button>
54
- <ul class="dropdown-menu table_visibility" >
55
- <% columns.each_with_index do |column, key| %>
56
- <li>
57
- <div class='checkbox checkbox-primary'>
58
- <input type="checkbox" data-key="<%= column[:data] %>" name="<%= table_name %>[table_column_vis][]" <%= column[:visible] == false ? '' : 'checked' %> value="<%= key %>">
59
- <label><%= ["#{table_name}__actions"].include?(column[:data]) ? 'Actions' : column[:title] %></label>
60
- </div>
61
- <span class="icon z-icon-hamburger"></span>
62
- </li>
63
- <% end %>
64
- </ul>
25
+ <% end %>
26
+ <% if defined?(table_group_actions) && table_group_actions.present? %>
27
+ <div class="btn-group">
28
+ <span id="<%= table_name %>_group_actions" class="hidden table-btn" data-items='<%= raw(table_group_actions.to_json) %>'>
29
+ <i class='fa fa-object-ungroup'></i>
30
+ </span>
65
31
  </div>
32
+ <% end %>
33
+ <div class="dropdown">
34
+ <button id="<%= table_name %>_visiblity" type="button" class="table-btn dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
35
+ <span class='fa fa-eye'></span>
36
+ </button>
37
+ <ul id="<%= table_name %>_visibility_menu" class="dropdown-menu table_visibility pull-right"></ul>
38
+ </div>
66
39
 
67
- <% default_view ||= table_views.select {|k,v| v == true }.first[0].to_s %>
68
- <% table_view = table_views[:table] %>
69
- <% grid_view = table_views[:grid] %>
70
-
71
- <label id='<%= "#{table_name}_view_table" %>'class="btn table-btn <%= default_view == 'table' ? 'active' : '' %> <%= !table_view ? 'hidden' : '' %>">
72
- <input type="radio" name="<%= table_name %>[view_mode]" <%= default_view == 'table' ? 'checked' : '' %> value='table' />
73
- <span class="fa fa-table"></span>
74
- </label>
75
- <label id='<%= "#{table_name}_view_grid" %>'class="btn table-btn <%= default_view == 'grid' ? 'active' : '' %> <%= !grid_view ? 'hidden' : '' %>" >
76
- <input type="radio" name="<%= table_name %>[view_mode]" <%= default_view == 'grid' ? 'checked' : '' %> value='grid' />
77
- <span class="fa fa-th-large"></span>
78
- </label>
79
- <label id='<%= "#{table_name}_refresh" %>' class="table-btn table_refresh">
80
- <span class="z-icon-refresh"></span>
81
- </label>
40
+ <div id="<%= table_name %>_view_table" class="table-btn <%= 'hidden' unless table_views[:table] and table_views[:grid] %>">
41
+ <span class="fa fa-table"></span>
42
+ </div>
43
+ <div id="<%= table_name %>_view_grid" class="table-btn <%= 'hidden' unless table_views[:grid] and table_views[:table] %>">
44
+ <span class="fa fa-th-large"></span>
82
45
  </div>
83
- <div id="<%= "#{table_name}_search_wrapper" %>" class="search-wrapper">
84
- <span id="<%="#{table_name}_search_btn" %>" class="z-icon-search table-btn"></span>
85
- <input id='<%= "#{table_name}_search" %>' type="search" name='table[search]' class="form-control" placeholder='Search..'>
46
+ <label id="<%= table_name %>_refresh" class="table-btn table_refresh">
47
+ <span class="z-icon-refresh"></span>
48
+ </label>
49
+ <div id="<%= table_name %>_search_wrapper" class="search-wrapper">
50
+ <span id="<%= table_name %>_search_btn" class="z-icon-search table-btn"></span>
51
+ <input id="<%= table_name %>_search" type="search" name="table[search]" class="form-control" placeholder="Search..">
86
52
  </div>
87
53
  </div>
88
54
  </div>
89
- <table id='<%= "#{table_name}" %>' data-source="<%= table_url %>" class="table bootstrap-datatable datatable hidden" style="width: 100% !important;"></table>
55
+ <table id="<%= table_name %>" data-source="<%= table_url %>" class="table bootstrap-datatable datatable hidden" style="width: 100% !important;"></table>
90
56
  </div>
91
57
 
92
58
  <% content_for :scripts do %>
93
- columns = <%= raw(columns.to_json) %>;
94
- $.each(columns, function(key, column) {
95
- $.each(column, function(key, value) {
96
- if(key=='render'){columns[0][key] = new Function('data', 'type', 'row', value);};
59
+ getTableParams(
60
+ '<%= table_name %>',
61
+ {
62
+ columns: <%= raw columns.to_json %>,
63
+ filters: <%= raw table_filters.to_json %>,
64
+ view: '<%= table_views.select { |k, v| v == true }.first[0].to_s %>',
65
+ size: <%= initial_size %>,
66
+ sort: <%= raw sort %>
67
+ },
68
+ create<%= table_name %>Table
69
+ );
70
+
71
+ function create<%= table_name %>Table(columns, view, size, sort) {
72
+ $.each(columns, function(key1, column) {
73
+ $.each(column, function(key2, value) {
74
+ if(key2 == 'render') {
75
+ columns[key1][key2] = new Function('data', 'type', 'row', value);
76
+ };
77
+ <% if defined?(table_group_actions) && table_group_actions.present? %>
78
+ if(key2 == 'data' && value == 'actions'){
79
+ columns[key1]['title'] = '<span id="<%= table_name %>_select_all" class="btn btn-xs btn-default "><span class="z-icon-addition"></span></span>';
80
+ };
81
+ <% end %>
82
+ });
83
+ });
84
+
85
+ $('#<%= table_name %>_content').contextMenu({
86
+ selector: '#<%= table_name %>_group_actions, #<%= table_name %>_actions',
87
+ trigger: 'left',
88
+ zIndex: 10,
89
+ callback: function(id, options) {
90
+ array = id.split('::');
91
+ object_ids = []
92
+ $.each(<%= table_name %>.api().rows({ selected: true }).ids(), function(key, value) {
93
+ object_ids.push(value);
94
+ })
95
+ if(array[1].includes('?')){
96
+ ExecuteRemoteJS(array[0], array[1].concat('&' + jQuery.param({ids: object_ids})));
97
+ }else{
98
+ ExecuteRemoteJS(array[0], array[1].concat('?' + jQuery.param({ids: object_ids})));
99
+ }
100
+ },
101
+ build: function($trigger, e) {
102
+ var items = ($(e.target).data('items') == null) ? $(e.target).parent().first().data('items') : $(e.target).data('items') ;
103
+ return {
104
+ items: items
105
+ };
106
+ }
97
107
  });
98
- });
99
108
 
100
- var <%= table_name %> = $('#<%= "#{table_name}_content" %>').find('table.datatable').dataTable({
101
- "sDom": "t<'row'<'grid_view col-lg-12'>><'table_footer'i<'<%="\##{table_name}_select_container" %>.select_container'>p>",
102
- "pagingType": "full_numbers",
103
- "language" : {
104
- "paginate" : {
105
- "previous" : "<span class='z-icon-arrow-left' />",
106
- "next" : "<span class='z-icon-arrow-right' />"
109
+ <!-- Debounce Draw Function -->
110
+ var <%= table_name %>_draw = debounce(function() {
111
+ if($('#<%= table_name %>_content').is(":visible") && !$('#<%= table_name %>_content .table_refresh').hasClass('zc-spin') && !document.hidden) {
112
+ return $("#<%= table_name %>").DataTable().draw(false);
107
113
  }
108
- },
109
- "bProcessing": true,
110
- "bServerSide": true,
111
- "colReorder": true,
112
- "select": false, //{ style: 'multi'},
113
- "columns": [].concat(columns),
114
- "aaSorting": <%= raw(sort.to_json) %>,
115
- "sAjaxSource": $('#<%= "#{table_name}_content" %>').find('table.datatable').data('source'),
116
- "iDisplayLength": <%= initial_size %> ,
117
- "fnServerParams": function ( aoData ) {
118
- aoData.push(
119
- { "name": "table_view_mode", "value": $('#<%= "#{table_name}_content" %>').find('input[type=radio][name="<%= table_name %>[view_mode]"]:checked').val()},
120
- { "name": "sSearch", "value": $('#<%= "#{table_name}_content" %>').find('input[name="table[search]"]').val()}
121
- );
122
- <% if !aoData.blank? %>
123
- <% aoData.each do |data| %>
124
- aoData.push(<%= raw(data.to_json) %>);
125
- <% end %>
114
+ }, 4000);
115
+
116
+ var <%= table_name %> = $('#<%= table_name %>').dataTable({
117
+ "sDom": "t<'grid_view'><'table-footer'i<'#<%= table_name %>_select_container.select_container'>p>",
118
+ "pagingType": "full_numbers",
119
+ "language" : {
120
+ "paginate" : {
121
+ "previous" : "<span class='z-icon-arrow-left' />",
122
+ "next" : "<span class='z-icon-arrow-right' />"
123
+ }
124
+ },
125
+ "bProcessing": true,
126
+ "bServerSide": true,
127
+ "colReorder": true,
128
+ <% if defined?(table_group_actions) && table_group_actions.present? %>
129
+ "select": { style: 'multi'},
126
130
  <% end %>
127
- <% if defined?(table_filters) %>
128
- <% table_filters.each do |table_filter| %>
129
- <% if table_filter["type"] == "checkbox" %>
130
- aoData.push({ "name": "<%= table_filter["name"].parameterize('_') %>", "value": $('#<%= "#{table_name}_content" %>').find('input[name="<%= table_filter["name"].parameterize('_') %>[]"]:checked').map(function(_, el) { return $(el).val()}).get() });
131
- <% elsif table_filter["type"] == "boolean" %>
132
- aoData.push({ "name": "<%= table_filter["name"].parameterize('_') %>", "value": $('#<%= "#{table_name}_content" %>').find('input[name="<%= table_filter["name"].parameterize('_') %>"]:checked').val() });
133
- <% elsif table_filter["type"] == "select" %>
134
- aoData.push({ "name": "<%= table_filter["name"].parameterize('_') %>", "value": $('#<%= "#{table_name}_content" %>').find('select[name="<%= table_filter["name"].parameterize('_') %>"]').val() });
131
+ "columns": [].concat(columns),
132
+ "aaSorting": sort,
133
+ "sAjaxSource": $('#<%= table_name %>_content table.datatable').data('source'),
134
+ <% if defer_loading %>
135
+ "deferLoading": 0,
136
+ <% end %>
137
+ "iDisplayLength": size,
138
+ "fnServerParams": function ( aoData ) {
139
+ aoData.push(
140
+ { "name": "table_view_mode", "value": getTableViewMode('<%= table_name %>', view) },
141
+ { "name": "sSearch", "value": $('#<%= table_name %>_search').val() }
142
+ );
143
+ <% if !aoData.blank? %>
144
+ <% aoData.each do |data| %>
145
+ aoData.push(<%= raw(data.to_json) %>);
135
146
  <% end %>
136
147
  <% end %>
137
- <% end %>
138
- },
139
- "fnDrawCallback": function( oSettings ) {
140
- $('#<%= "#{table_name}_content" %>').find('.table [rel="status_popover"], .table[data-rel="status_popover"]').popover({ placement: "left", html: 'true', container: '.table'});
141
- $('#<%= "#{table_name}_content" %>').find('.table [data-toggle="tooltip"]').tooltip();
142
- view_mode = $('#<%= "#{table_name}_content" %>').find('input[type=radio][name="<%= table_name %>[view_mode]"]:checked').val();
143
-
144
- $('#<%= "#{table_name}_content" %>').find('.grid_view').addClass('hidden');
145
- $('#<%= "#{table_name}_content" %>').find('table.datatable').addClass("hidden");
146
-
147
- if(view_mode == 'grid'){
148
- $('#<%= "#{table_name}_content .grid_view" %>').html('');
149
-
150
- $.each(oSettings.aoData, function(index, result) {
151
- $('#<%= "#{table_name}_content .grid_view" %>').append(result._aData.grid_view);
152
- });
153
- if (oSettings.aoData.length == 0) {
154
- $(".login_grid").append("<div class='row'><div class='col-md-12 center'><h3>" + oSettings.oLanguage.sEmptyTable + "</h3></div></div>")
148
+ <% if defined?(table_filters) %>
149
+ <% table_filters.each do |table_filter| %>
150
+ <% if table_filter["type"] == "checkbox" %>
151
+ aoData.push({ "name": "<%= table_filter["name"].parameterize('_') %>", "value": $('#<%= table_name %>_content input[name="<%= table_filter["name"].parameterize('_') %>[]"]:checked').map(function(_, el) { return $(el).val()}).get() });
152
+ <% elsif table_filter["type"] == "boolean" %>
153
+ aoData.push({ "name": "<%= table_filter["name"].parameterize('_') %>", "value": $('#<%= table_name %>_content input[name="<%= table_filter["name"].parameterize('_') %>"]:checked').val() });
154
+ <% elsif ["select", "group-select"].include?(table_filter["type"]) %>
155
+ aoData.push({ "name": "<%= table_filter["name"].parameterize('_') %>", "value": $('#<%= table_name %>_content select[name="<%= table_filter["name"].parameterize('_') %>"]').val() });
156
+ <% end %>
157
+ <% end %>
158
+ <% end %>
159
+ },
160
+ "fnDrawCallback": function(oSettings) {
161
+ $('#<%= table_name %>_content').find('.table [rel="status_popover"], .table[data-rel="status_popover"]').popover({ placement: "left", html: 'true', container: '.table'});
162
+ $('#<%= table_name %>_content').find('.table [data-toggle="tooltip"]').tooltip();
163
+ $('#<%= table_name %>_content .grid_view').addClass('hidden');
164
+ $('#<%= table_name %>_content table.datatable').addClass("hidden");
165
+
166
+ if (oSettings.oAjaxData.table_view_mode === 'grid') {
167
+ $('#<%= table_name %>_content .grid_view').html('');
168
+
169
+ $.each(oSettings.aoData, function(index, result) {
170
+ $('#<%= table_name %>_content .grid_view').append(result._aData.grid_view);
171
+ });
172
+ if (oSettings.aoData.length == 0) {
173
+ $(".login_grid").append("<div class='row'><div class='col-md-12 center'><h3>" + oSettings.oLanguage.sEmptyTable + "</h3></div></div>")
174
+ }
175
+ $('#<%= table_name %>_content .grid_view').removeClass('hidden');
176
+ } else if (oSettings.oAjaxData.table_view_mode === 'table') {
177
+ $('#<%= table_name %>_content table.datatable').removeClass("hidden");
155
178
  }
156
- $('#<%= "#{table_name}_content" %>').find('.grid_view').removeClass('hidden')
157
- }else if(view_mode == 'table'){
158
- $('#<%= "#{table_name}_content" %>').find('table.datatable').removeClass("hidden");
159
- }
160
179
 
161
- <%= table_name %>.find('input[type="checkbox"].select_row').on('click', function(e){
162
- if($('#<%= "#{table_name}_select_all" %>').is(':checked')){ $('#<%= "#{table_name}_select_all" %>').prop("checked", false);}
163
- });
164
- if( <%= table_name %>.find('tr[processing="true"]').length > 0 && <%= table_name %>.is(":visible")){
165
- setTimeout(function(){
166
- <%= table_name %>.api().draw(false);
167
- }, 1000);
168
- }
169
- if(<%= table_name %>.find('tr[processing="true"]').length > 0 && $('#<%= table_name %>_wrapper .grid_view').is(":visible")){
170
- setTimeout(function(){
171
- <%= table_name %>.api().draw(false);
172
- }, 1000);
173
- }
174
- },
175
- "fnServerData": function ( sSource, aoData, fnCallback, oSettings ) {
176
- data = aoData;
177
- if ( data && $.isArray(data) ) {
178
- var tmp = {};var rbracket = /(.*?)\[\]$/;
179
- $.each( data, function (key, val) {
180
- var match = val.name.match(rbracket);
181
- if ( match ) {var name = match[0];if ( ! tmp[ name ] ) {tmp[ name ] = [];}tmp[ name ].push( val.value );}else {tmp[val.name] = val.value;}
180
+ <%= table_name %>.find('input[type="checkbox"].select_row').on('click', function(e) {
181
+ if($('#<%= table_name %>_select_all').is(':checked')) {
182
+ $('#<%= table_name %>_select_all').prop("checked", false);
183
+ }
182
184
  });
183
- data = tmp;
184
- }
185
- <% if debug %>console.log(fnCallback); console.log(oSettings);console.log(data);<% end %>
186
- oSettings.jqXHR = $.ajax({"dataType": 'json', "url": sSource, "data": data, "success": fnCallback,"error": function (textStatus, errorThrown) {
187
- if(textStatus.status == 400 || textStatus.status == 302 ){
188
- window.location.replace("/");
189
- }else if(textStatus.status == 500 ){
190
- alert('<%= "Table Server Error: #{table_name} Contact Support" %>');
191
- }else{
192
- window.location.replace("/");
193
- };
194
- }});
195
- }
196
- }).on( 'draw.dt', function () {
197
- <% if debug %> console.log('Drawing Trigger <%= table_name %>'); <% end %>
198
- <%= table_name + '_cookie' %>();
199
- }).on( 'processing.dt', function ( e, settings, processing ) {
200
- if(processing){
201
- $('#<%= "#{table_name}_content" %>').find('.table_refresh i').addClass('fa-spin');
202
- }else{
203
- $('#<%= "#{table_name}_content" %>').find('.table_refresh i').removeClass('fa-spin');
204
- }
205
- });
206
-
207
- function <%= table_name + '_cookie' %>(){
208
- <% if debug %> console.log('Save Cookie <%= table_name %>'); <% end %>
209
- columns = $('#<%= "#{table_name}_content" %>').find('input[name="<%= table_name %>[table_column_vis][]"]:checked').map(function(_, el) { return $(el).data('key')}).toArray();
210
- view = $('#<%= "#{table_name}_content" %>').find('input[type=radio][name="<%= table_name %>[view_mode]"]:checked').val();
211
- sort = <%= table_name %>.fnSettings().aaSorting;
212
- table_size = <%= table_name %>.fnSettings()._iDisplayLength;
213
- sort = sort.map(function(value,key) {
214
- column = <%= table_name %>.api().column(value[0]).dataSrc();
215
- return [column,value[1]]
216
- })
217
-
218
- var orderedItems = [];
219
- $.each(<%= table_name %>.api().colReorder.order(), function(value) {
220
- data_key = <%= table_name %>.api().column(value).dataSrc();
221
- if (data_key != null && data_key.length > 0 ){orderedItems.push(data_key);}
222
- });
223
185
 
224
- if (Cookies.get('<%= "#{table_name}_table" %>') != null){
225
- data = $.parseJSON( Cookies.get('<%= "#{table_name}_table" %>'));
226
- data['columns'] = columns;
227
- data['view'] = view;
228
- data['sort'] = sort;
229
- data['table_size'] = table_size;
230
- data['ordering'] = orderedItems;
231
- }else{
232
- data = {'columns' : columns, 'view' : view, 'sort' : sort, 'table_size' : table_size, 'orderedItems' : orderedItems};
233
- }
234
-
235
- Cookies.set('<%= "#{table_name}_table" %>', data);
236
- }
186
+ if (<%= table_name %>.find('tr[processing="true"]').length > 0 && <%= table_name %>.is(":visible")) {
187
+ <%= table_name %>_draw();
188
+ }
237
189
 
238
- function <%= table_name + '_column_vis' %>(sorting){
239
- $('#<%= "#{table_name}_content" %>').find('input[name="<%= table_name %>[table_column_vis][]"]').on("change", function(e) {
240
- index = <%= table_name %>.api().colReorder.transpose(parseInt($(this).val()),'toCurrent');
241
- column = <%= table_name %>.api().column(index);
242
- column.visible($(this).is(':checked'));
243
- <%= table_name + '_cookie' %>();
190
+ if (<%= table_name %>.find('tr[processing="true"]').length > 0 && $('#<%= table_name %>_wrapper .grid_view').is(":visible")) {
191
+ <%= table_name %>_draw();
192
+ }
193
+ resize_iframe();
194
+
195
+ <!-- Hide group actions and deselect-->
196
+ $('#<%= table_name %>_select_all span').removeClass('z-icon-subtraction').addClass('z-icon-addition');
197
+ $('#<%= table_name %>_group_actions').addClass('hidden');
198
+ },
199
+ "fnServerData": function ( sSource, aoData, fnCallback, oSettings ) {
200
+ data = aoData;
201
+ if ( data && $.isArray(data) ) {
202
+ var tmp = {};var rbracket = /(.*?)\[\]$/;
203
+ $.each( data, function (key, val) {
204
+ var match = val.name.match(rbracket);
205
+ if ( match ) {var name = match[0];if ( ! tmp[ name ] ) {tmp[ name ] = [];}tmp[ name ].push( val.value );}else {tmp[val.name] = val.value;}
206
+ });
207
+ data = tmp;
208
+ }
209
+ <% if debug %>console.log(fnCallback); console.log(oSettings);console.log(data);<% end %>
210
+ oSettings.jqXHR = $.ajax({"dataType": 'json', "url": sSource, "data": data, "success": fnCallback,"error": function (textStatus, errorThrown) {
211
+ if (textStatus.status == 400 || textStatus.status == 302 ) {
212
+ window.location.replace("/");
213
+ } else if (textStatus.status == 500 ) {
214
+ $('#<%= table_name %>_content .table_refresh').removeClass('zc-spin');
215
+ alert('Table Server Error: <%= table_name %> Contact Support: ' + errorThrown);
216
+ } else if (textStatus.status == 502 ) {
217
+ $('#<%= table_name %>_content .table_refresh').removeClass('zc-spin');
218
+ } else {
219
+ window.location.replace("/");
220
+ };
221
+ }});
222
+ }
223
+ }).on('draw.dt', function() {
224
+ <% if debug %> console.log('Drawing Trigger <%= table_name %>'); <% end %>
225
+ }).on('processing.dt', function(e, settings, processing) {
226
+ $('#<%= table_name %>_content .table_refresh').toggleClass('zc-spin', processing);
244
227
  });
245
- if(sorting){
246
- $('#<%= "#{table_name}_content" %>').find('.table_visibility').sortable({axis: 'y'}).on("sortstop", function( event, ui ) {
247
- <% if debug %> console.log('Sort Stop Trigger <%= table_name %>'); <% end %>
248
- items = $('#<%= "#{table_name}_content" %>').find('.table_visibility li input');
249
- var orderedItems = [];
250
- $.each(items, function(index, value) {
251
- index = <%= table_name %>.api().colReorder.transpose(parseInt($(value).val()),'toCurrent');
252
- column = <%= table_name %>.api().column(index);
253
- if (column != null && column.length > 0 ){orderedItems.push(column.index());}
254
- });
255
- <%= table_name %>.api().colReorder.order(orderedItems);
256
- });
257
- $('#<%= "#{table_name}_content" %>').find('.table_visibility').disableSelection();
258
- }
259
- }
260
- <%= table_name + '_column_vis' %>(true);
261
228
 
262
- //Datable Select
263
- function <%= table_name + '_row_select' %>(select, data){
264
- var count = <%= table_name %>.api().rows({ selected: true }).count();
265
- if(count > 0){
266
- $('#<%= "#{table_name}_content" %>').find('.group_actions').removeClass('hidden');
267
- }else {
268
- $('#<%= "#{table_name}_content" %>').find('.group_actions').addClass('hidden');
269
- }
270
- if(select){
271
- <% if debug %>
272
- console.log('Selected');
273
- console.log(data);
274
- <% end %>
275
- }else{
276
- <% if debug %>
277
- console.log('Deselected');
278
- console.log(data);
279
- <% end %>
280
- }
229
+ initTable(
230
+ <%= table_name %>.api(),
231
+ '<%= table_name %>',
232
+ { view, size },
233
+ columns,
234
+ <%= raw table_filters.to_json %>
235
+ );
281
236
  }
282
- <%= table_name %>.api().on('select', function ( e, dt, type, indexes ) {
283
- <%= table_name + '_row_select' %>(true, <%= table_name %>.api().rows( indexes ).data());
284
- });
285
- <%= table_name %>.api().on('deselect', function ( e, dt, type, indexes ) {
286
- <%= table_name + '_row_select' %>(false, <%= table_name %>.api().rows( indexes ).data());
287
- });
288
-
289
- //Datatable header reorder
290
- <%= table_name %>.api().on('column-reorder', function ( e, settings, details ) {
291
- <% if debug %> console.log('Ordering Trigger <%= table_name %>'); <% end %>
292
- var orderedItems = [];
293
- $.each(<%= table_name %>.api().colReorder.order(), function(value) {
294
- data_key = <%= table_name %>.api().column(value).dataSrc();
295
- item = $('#<%= "#{table_name}_content" %>').find('.table_visibility li input[data-key="' + data_key + '"]').parents('li');
296
- if (item != null && item.length > 0 ){orderedItems.push(item);}
297
- });
298
- <% if debug %> console.log('Ordering Trigger Rebuild DropDown <%= table_name %>'); <% end %>
299
- $('#<%= "#{table_name}_content" %>').find('.table_visibility').empty().html(orderedItems);
300
- <%= table_name + '_column_vis' %>(false);
301
- <%= table_name + '_cookie' %>();
302
- });
303
-
304
- $('#<%= "#{table_name}_select_all" %>').on('click', function(e){
305
- if($(this).is(':checked')){<%= table_name %>.find('input[type="checkbox"].select_row').prop("checked", true);}else{<%= table_name %>.find('input[type="checkbox"].select_row').prop("checked", false);}
306
- });
307
-
308
- $('#<%= "#{table_name}_content" %>').find('.table_refresh').click(function(e){<%= table_name %>.api().draw(false)});
309
-
310
- // Add the row # select to the footer
311
- const <%= "#{table_name}_select" %> = $('<select>')
312
- .attr('id', 'table_size')
313
- .attr('class', '')
314
- .attr('name', 'table_size')
315
- .appendTo('<%="\##{table_name}_select_container" %>');
316
- [10, 25, 50, 100].forEach(e => {
317
- <%= "#{table_name}_select" %>.append($('<option>').attr('value', e).text(e));
318
- });
319
- <%= "#{table_name}_select" %>.val("<%= initial_size.to_s %>");
320
- <%= "#{table_name}_select" %>.select2({
321
- minimumResultsForSearch: Infinity,
322
- dropdownAutoWidth: true,
323
- width: '100%',
324
- });
325
-
326
- $('#<%= "#{table_name}_search_btn" %>').on('click', () => {
327
- $('#<%= "#{table_name}_search_wrapper" %>').toggleClass('active');
328
- $('#<%= "#{table_name}_search" %>').focus();
329
- });
330
-
331
- $('#<%= "#{table_name}_content" %>').find('select[name="table_size"]').on("change", function(e) {
332
- <%= table_name %>.fnSettings()._iDisplayLength = $(this).val();<%= table_name %>.api().draw(false);
333
- });
334
-
335
- $('#<%= "#{table_name}_content" %>').find('input[type=radio][name="<%= table_name %>[view_mode]"]').on("change", function(e) {
336
- <%= table_name %>.api().draw(false)
337
- });
338
-
339
- var timer;
340
- var timeout = 300;
341
- $('#<%= "#{table_name}_content" %>').find('input[name="table[search]"]').keydown(function(){
342
- clearTimeout(timer);
343
- var search = $(this);
344
- if (search.val()) {timer = setTimeout(function(){<%= table_name %>.api().draw();}, timeout);}
345
- });
346
-
347
- <% if defined?(table_filters) %>
348
- <% table_filters.each do |table_filter| %>
349
- <% cache = table_filter["cache"].blank? ? false : table_filter["cache"] %>
350
- <% if table_filter["type"] == "checkbox" %>
351
- $('#<%= "#{table_name}_content" %>').find('input[name="<%= table_filter["name"].parameterize('_') %>[]"]').click(function(){
352
- filters = $('#<%= "#{table_name}_content" %>').find('input[name="<%= table_filter["name"].parameterize('_') %>[]"]:checked').map(function(_, el) { return $(el).val()}).toArray();
353
- <% if cache %>
354
- if (Cookies.get('<%= "#{table_name}_table" %>') != null){
355
- data = $.parseJSON( Cookies.get('<%= "#{table_name}_table" %>'));
356
- data['<%= table_filter["name"].parameterize('_') %>_filter'] = filters
357
- }else{
358
- data = {'<%= table_filter["name"].parameterize('_') %>_filter' : filters }
359
- }
360
- Cookies.set('<%= "#{table_name}_table" %>', data);
361
- <% end %>
362
- return $("table#<%= table_name %>").dataTable().api().draw()
363
- });
364
- <% elsif table_filter["type"] == "select" %>
365
- $('#<%= "#{table_name}_content" %>').find('select[name="<%= table_filter["name"].parameterize('_') %>"]').change(function(){
366
- filter = $('#<%= "#{table_name}_content" %>').find('select[name="<%= table_filter["name"].parameterize('_') %>"]').val();
367
- <% if cache %>
368
- if (Cookies.get('<%= "#{table_name}_table" %>') != null){
369
- data = $.parseJSON( Cookies.get('<%= "#{table_name}_table" %>'));
370
- data['<%= table_filter["name"].parameterize('_') %>_filter'] = filter
371
- }else{
372
- data = {'<%= table_filter["name"].parameterize('_') %>_filter' : filter }
373
- }
374
- Cookies.set('<%= "#{table_name}_table" %>', data);
375
- <% end %>
376
- return $("table#<%= table_name %>").dataTable().api().draw()
377
- });
378
- <% elsif table_filter["type"] == "boolean" %>
379
- $('#<%= "#{table_name}_content" %>').find('input[name="<%= table_filter["name"].parameterize('_') %>"]').change(function(){
380
- filter = $('#<%= "#{table_name}_content" %>').find('input[name="<%= table_filter["name"].parameterize('_') %>"]:checked').val();
381
- <% if cache %>
382
- if (Cookies.get('<%= "#{table_name}_table" %>') != null){
383
- data = $.parseJSON( Cookies.get('<%= "#{table_name}_table" %>'));
384
- data['<%= table_filter["name"].parameterize('_') %>_filter'] = filter
385
- }else{
386
- data = {'<%= table_filter["name"].parameterize('_') %>_filter' : filter }
387
- }
388
- Cookies.set('<%= "#{table_name}_table" %>', data);
389
- <% end %>
390
- return $("table#<%= table_name %>").dataTable().api().draw()
391
- });
392
- <% end %>
393
- <% end %>
394
- <% end %>
395
237
  <% end %>