kaui 3.0.2 → 3.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/images/kaui/logo.svg +37 -0
  3. data/app/controllers/kaui/account_timelines_controller.rb +121 -0
  4. data/app/controllers/kaui/accounts_controller.rb +51 -14
  5. data/app/controllers/kaui/admin_tenants_controller.rb +19 -6
  6. data/app/controllers/kaui/audit_logs_controller.rb +40 -3
  7. data/app/controllers/kaui/bundles_controller.rb +5 -1
  8. data/app/controllers/kaui/charges_controller.rb +1 -1
  9. data/app/controllers/kaui/credits_controller.rb +1 -1
  10. data/app/controllers/kaui/custom_fields_controller.rb +3 -3
  11. data/app/controllers/kaui/engine_controller.rb +3 -28
  12. data/app/controllers/kaui/engine_controller_util.rb +8 -2
  13. data/app/controllers/kaui/home_controller.rb +5 -5
  14. data/app/controllers/kaui/invoice_items_controller.rb +1 -1
  15. data/app/controllers/kaui/invoices_controller.rb +59 -34
  16. data/app/controllers/kaui/payment_methods_controller.rb +3 -3
  17. data/app/controllers/kaui/payments_controller.rb +66 -10
  18. data/app/controllers/kaui/refunds_controller.rb +3 -2
  19. data/app/controllers/kaui/sessions_controller.rb +7 -0
  20. data/app/controllers/kaui/subscriptions_controller.rb +8 -8
  21. data/app/controllers/kaui/transactions_controller.rb +2 -2
  22. data/app/helpers/kaui/exception_helper.rb +25 -0
  23. data/app/helpers/kaui/subscription_helper.rb +4 -0
  24. data/app/models/kaui/account.rb +2 -0
  25. data/app/models/kaui/custom_field.rb +1 -1
  26. data/app/models/kaui/invoice.rb +2 -0
  27. data/app/models/kaui/payment_method.rb +4 -4
  28. data/app/views/kaui/account_timelines/_multi_functions_bar.html.erb +184 -0
  29. data/app/views/kaui/account_timelines/show.html.erb +2 -0
  30. data/app/views/kaui/accounts/_account_info.html.erb +7 -0
  31. data/app/views/kaui/accounts/_multi_functions_bar.html.erb +347 -0
  32. data/app/views/kaui/accounts/index.html.erb +46 -33
  33. data/app/views/kaui/audit_logs/_multi_functions_bar.html.erb +218 -0
  34. data/app/views/kaui/audit_logs/index.html.erb +1 -0
  35. data/app/views/kaui/bundles/index.html.erb +34 -0
  36. data/app/views/kaui/errors/500.html.erb +29 -0
  37. data/app/views/kaui/invoices/_multi_functions_bar.html.erb +340 -0
  38. data/app/views/kaui/invoices/index.html.erb +41 -19
  39. data/app/views/kaui/layouts/kaui_navbar.html.erb +1 -1
  40. data/app/views/kaui/payments/_multi_functions_bar.html.erb +344 -0
  41. data/app/views/kaui/payments/index.html.erb +64 -25
  42. data/config/locales/en.yml +3 -0
  43. data/config/routes.rb +7 -0
  44. data/lib/kaui/error_handler.rb +37 -0
  45. data/lib/kaui/version.rb +1 -1
  46. data/lib/kaui.rb +105 -29
  47. data/lib/tasks/kaui_tasks.rake +1 -0
  48. metadata +11 -3
  49. data/app/assets/images/kaui/logo.png +0 -0
@@ -0,0 +1,218 @@
1
+ <div class="dropdown-container">
2
+ <button class="btn btn-default download-button-right" type="button" id="modalDownloadButton">
3
+ <i class="glyphicon glyphicon-download-alt"></i>
4
+ <strong>Download CSV</strong>
5
+ </button>
6
+ </div>
7
+
8
+ <div class="modal fade" id="downloadCsvModal" tabindex="-1" role="dialog" aria-labelledby="downloadCsvModalLabel" aria-hidden="true">
9
+ <div class="modal-dialog" role="document">
10
+ <div class="modal-content">
11
+ <div class="modal-header">
12
+ <h3 class="modal-title" id="downloadCsvModalLabel">Download</h3>
13
+ <button type="button" class="close" data-dismiss="modal" aria-label="Close">
14
+ <span aria-hidden="true">&times;</span>
15
+ </button>
16
+ </div>
17
+ <div class="modal-body">
18
+ <form id="downloadCsvForm">
19
+ <div class="row">
20
+ <div class="col-md-6">
21
+ <div class="form-group">
22
+ <label for="startDate">Created Date From:</label>
23
+ <input type="text" class="form-control" id="startDate" name="startDate">
24
+ </div>
25
+ </div>
26
+ <div class="col-md-6">
27
+ <div class="form-group">
28
+ <label for="endDate">To:</label>
29
+ <input type="text" class="form-control" id="endDate" name="endDate">
30
+ </div>
31
+ </div>
32
+ </div>
33
+ <div class="row">
34
+ <div class="col-md-6">
35
+ <div class="form-check">
36
+ <div>
37
+ <input type="radio" id="customDate" name="download_option" value="customDate">
38
+ <label for="customDate">Custom date</label>
39
+ </div>
40
+ <div>
41
+ <input type="radio" id="allData" name="download_option" value="all">
42
+ <label for="allData">All logs</label>
43
+ </div>
44
+ <div>
45
+ <input type="radio" id="thisWeek" name="download_option" value="thisWeek">
46
+ <label for="thisWeek">This week</label>
47
+ </div>
48
+ <div>
49
+ <input type="radio" id="thisMonth" name="download_option" value="thisMonth">
50
+ <label for="thisMonth">This month</label>
51
+ </div>
52
+ <div>
53
+ <input type="radio" id="thisYear" name="download_option" value="thisYear">
54
+ <label for="thisYear">This year</label>
55
+ </div>
56
+ </div>
57
+ </div>
58
+ </div>
59
+ </form>
60
+ </div>
61
+ <div class="modal-footer">
62
+ <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
63
+ <button type="button" class="btn btn-primary" id="downloadButton">Download</button>
64
+ </div>
65
+ </div>
66
+ </div>
67
+ </div>
68
+
69
+ <style>
70
+ .dropdown-menu#column-visibility {
71
+ max-height: 300px;
72
+ width: 220px;
73
+ overflow-y: auto;
74
+ }
75
+
76
+ .dropdown-menu {
77
+ padding: 5px;
78
+ }
79
+ .toggle-button-right {
80
+ float: right;
81
+ margin-bottom: 10px;
82
+ margin-left: 10px;
83
+ background-color: white;
84
+ color: black;
85
+ text-transform: none;
86
+ border: 1px solid #ccc;
87
+ padding: 8px 15px;
88
+ }
89
+
90
+ .download-button-right {
91
+ float: right;
92
+ margin-bottom: 10px;
93
+ margin-left: 10px;
94
+ background-color: white;
95
+ color: black;
96
+ text-transform: none;
97
+ border: 1px solid #ccc;
98
+ padding: 8px 15px;
99
+ }
100
+
101
+ .icon-drag {
102
+ float: right;
103
+ padding: 5px;
104
+ }
105
+
106
+ .dropdown-container {
107
+ display: flex;
108
+ justify-content: flex-end;
109
+ }
110
+
111
+ .label-group-item-manual {
112
+ margin: 5px;
113
+ width: -webkit-fill-available;
114
+ cursor: grab;
115
+ }
116
+ .label-group-item-manual:active {
117
+ cursor: grabbing;
118
+ }
119
+ </style>
120
+
121
+ <%= javascript_tag do %>
122
+ $(document).ready(function() {
123
+ $('.dropdown-menu').on('click', 'input[type="checkbox"], label', function(event) {
124
+ event.stopPropagation();
125
+ });
126
+
127
+ $('#modalDownloadButton').click(function() {
128
+ $('#downloadCsvModal').modal('show');
129
+ });
130
+
131
+ $('#startDate, #endDate').datepicker({
132
+ dateFormat: 'yy-mm-dd'
133
+ });
134
+
135
+ $('#downloadCsvModal').on('show.bs.modal', function (e) {
136
+ $('#allData').prop('checked', true);
137
+ $('#startDate, #endDate').prop('disabled', true);
138
+ $('#startDate').val(null);
139
+ $('#endDate').val(null);
140
+ });
141
+
142
+ $('#allData').change(function() {
143
+ $('#startDate').val(null);
144
+ $('#endDate').val(null);
145
+ var isChecked = $(this).is(':checked');
146
+ $('#startDate, #endDate').prop('disabled', true);
147
+ });
148
+
149
+ function setDateRange(option) {
150
+ var currentDate = new Date();
151
+ var startDate, endDate;
152
+
153
+ if (option === "day") {
154
+ startDate = new Date();
155
+ endDate = new Date();
156
+ endDate.setDate(endDate.getDate() + 1);
157
+ } else if (option === "week") {
158
+ startDate = new Date(currentDate.setDate(currentDate.getDate() - currentDate.getDay() + 1));
159
+ currentDate = new Date();
160
+ endDate = new Date(currentDate.setDate(currentDate.getDate() - currentDate.getDay() + 7));
161
+ } else if (option === "month") {
162
+ startDate = new Date(currentDate.getFullYear(), currentDate.getMonth(), 1);
163
+ endDate = new Date(currentDate.getFullYear(), currentDate.getMonth() + 1, 0);
164
+ } else if (option === "year") {
165
+ startDate = new Date(currentDate.getFullYear(), 0, 1);
166
+ endDate = new Date(currentDate.getFullYear(), 11, 31);
167
+ }
168
+
169
+ var startDateFormatted = startDate.toISOString().split('T')[0];
170
+ var endDateFormatted = endDate.toISOString().split('T')[0];
171
+
172
+ $('#startDate').val(startDateFormatted);
173
+ $('#endDate').val(endDateFormatted);
174
+ $('#startDate, #endDate').prop('disabled', true);
175
+ }
176
+
177
+ $('#thisWeek').change(function() {
178
+ if ($(this).is(':checked')) {
179
+ setDateRange("week");
180
+ }
181
+ });
182
+
183
+ $('#thisMonth').change(function() {
184
+ if ($(this).is(':checked')) {
185
+ setDateRange("month");
186
+ }
187
+ });
188
+
189
+ $('#thisYear').change(function() {
190
+ if ($(this).is(':checked')) {
191
+ setDateRange("year");
192
+ }
193
+ });
194
+
195
+ $('#customDate').change(function() {
196
+ if ($(this).is(':checked')) {
197
+ setDateRange("day");
198
+ $('#startDate, #endDate').prop('disabled', false);
199
+ }
200
+ });
201
+
202
+ var downloadButton = document.getElementById('downloadButton');
203
+ if (downloadButton) {
204
+ downloadButton.addEventListener('click', function() {
205
+ event.preventDefault();
206
+ var startDate = $('#startDate').val();
207
+ var endDate = $('#endDate').val();
208
+ var downloadAll = $('#allData').is(':checked');
209
+
210
+ if (downloadAll) {
211
+ window.open("<%= download_audit_logs_path %>?account_id=<%=@account.account_id%>", '_blank');
212
+ } else {
213
+ window.open("<%= download_audit_logs_path %>?account_id=<%=@account.account_id%>&startDate="+startDate+"&endDate="+endDate, '_blank');
214
+ }
215
+ });
216
+ }
217
+ });
218
+ <% end %>
@@ -3,6 +3,7 @@
3
3
  <div class="column-block">
4
4
 
5
5
  <h1>Audit logs</h1>
6
+ <%= render :partial => 'multi_functions_bar' %>
6
7
  <input type="hidden" id="audit-logs" value="<%= @audit_logs_json %>">
7
8
  <table id="audit-logs-table" class="table table-condensed table-colored-rows mobile-data">
8
9
  <thead>
@@ -76,4 +76,38 @@
76
76
  <% end %>
77
77
  <% end %>
78
78
 
79
+ <div class="text-right" style="margin-top: 20px;">
80
+ <%= link_to 'First', account_bundles_path(page: 1), class: "btn btn-custom #{'disabled' if @page == 1}" %>
81
+ <%= link_to 'Previous', account_bundles_path(page: @page - 1), class: "btn btn-custom #{'disabled' if @page == 1}" %>
82
+
83
+ <% if @total_pages <= 10 %>
84
+ <% (1..@total_pages).each do |num| %>
85
+ <%= link_to num, account_bundles_path(page: num), class: paging_button_class(num, @page) %>
86
+ <% end %>
87
+ <% else %>
88
+ <%= link_to 1, account_bundles_path(page: 1), class: paging_button_class(1, @page) %>
89
+ <% if @page < 5 %>
90
+ <% (2..5).each do |num| %>
91
+ <%= link_to num, account_bundles_path(page: num), class: paging_button_class(num, @page) %>
92
+ <% end %>
93
+ <%= '...' %>
94
+ <% elsif @page > @total_pages - 4 %>
95
+ <%= '...' %>
96
+ <% (@total_pages-4..@total_pages-1).each do |num| %>
97
+ <%= link_to num, account_bundles_path(page: num), class: paging_button_class(num, @page) %>
98
+ <% end %>
99
+ <% else %>
100
+ <%= '...' %>
101
+ <% (@page-1..@page+1).each do |num| %>
102
+ <%= link_to num, account_bundles_path(page: num), class: paging_button_class(num, @page) %>
103
+ <% end %>
104
+ <%= '...' %>
105
+ <% end %>
106
+ <%= link_to @total_pages, account_bundles_path(page: @total_pages), class: paging_button_class(@total_pages, @page) %>
107
+ <% end %>
108
+
109
+ <%= link_to 'Next', account_bundles_path(page: @page + 1), class: "btn btn-custom #{'disabled' if @page == @total_pages}" %>
110
+ <%= link_to 'Last', account_bundles_path(page: @total_pages), class: "btn btn-custom #{'disabled' if @page == @total_pages}" %>
111
+ </div>
112
+
79
113
  </div>
@@ -0,0 +1,29 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 35em; /* Increase the width of the dialog */
9
+ padding: 1em 6em; /* Increase the padding of the dialog */
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ font-size: 1.2em; /* Increase the font size in the dialog */
15
+ }
16
+ h1 { font-size: 100%; color: #f00; line-height: 1.0em; } /* Increase the font size of the title */
17
+ </style>
18
+ </head>
19
+
20
+ <body>
21
+ <!-- This file lives in public/500.html -->
22
+ <div class="dialog">
23
+ <h1>We're sorry, but something went wrong.</h1>
24
+ <% if @error.present? %>
25
+ <p><%= @error %></p>
26
+ <% end %>
27
+ </div>
28
+ </body>
29
+ </html>
@@ -0,0 +1,340 @@
1
+ <div class="dropdown-container">
2
+ <button class="btn btn-default download-button-right" type="button" id="modalDownloadButton">
3
+ <i class="glyphicon glyphicon-download-alt"></i>
4
+ <strong>Download CSV</strong>
5
+ </button>
6
+ <div class="dropdown">
7
+ <button class="btn btn-default dropdown-toggle toggle-button-right" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
8
+ <i class="glyphicon glyphicon-cog"></i>
9
+ <strong>Edit Columns</strong>
10
+ </button>
11
+ <ul class="dropdown-menu" id="column-visibility" aria-labelledby="v">
12
+ <% Kaui.account_invoices_columns.call[0].each_with_index do |title, index| %>
13
+ <li class="list-group-item-manual" data-id="<%= index %>">
14
+ <label class="label-group-item-manual">
15
+ <input type="checkbox" class="column-toggle" draggable="true" data-column="<%= index %>" checked> <%= title %>
16
+ <span class="glyphicon glyphicon-option-vertical icon-drag" aria-hidden="true"></span>
17
+ </label>
18
+ </li>
19
+ <% end %>
20
+ </ul>
21
+ </div>
22
+ </div>
23
+
24
+ <div class="modal fade" id="downloadCsvModal" tabindex="-1" role="dialog" aria-labelledby="downloadCsvModalLabel" aria-hidden="true">
25
+ <div class="modal-dialog" role="document">
26
+ <div class="modal-content">
27
+ <div class="modal-header">
28
+ <h3 class="modal-title" id="downloadCsvModalLabel">Download</h3>
29
+ <button type="button" class="close" data-dismiss="modal" aria-label="Close">
30
+ <span aria-hidden="true">&times;</span>
31
+ </button>
32
+ </div>
33
+ <div class="modal-body">
34
+ <form id="downloadCsvForm">
35
+ <div class="row">
36
+ <div class="col-md-6">
37
+ <div class="form-group">
38
+ <label for="startDate">Invoice Date From:</label>
39
+ <input type="text" class="form-control" id="startDate" name="startDate">
40
+ </div>
41
+ </div>
42
+ <div class="col-md-6">
43
+ <div class="form-group">
44
+ <label for="endDate">To:</label>
45
+ <input type="text" class="form-control" id="endDate" name="endDate">
46
+ </div>
47
+ </div>
48
+ </div>
49
+ <div class="row">
50
+ <div class="col-md-6">
51
+ <div class="form-check">
52
+ <div>
53
+ <input type="radio" id="customDate" name="download_option" value="customDate">
54
+ <label for="customDate">Custom date</label>
55
+ </div>
56
+ <div>
57
+ <input type="radio" id="allData" name="download_option" value="all">
58
+ <label for="allData">All invoices</label>
59
+ </div>
60
+ <div>
61
+ <input type="radio" id="thisWeek" name="download_option" value="thisWeek">
62
+ <label for="thisWeek">This week</label>
63
+ </div>
64
+ <div>
65
+ <input type="radio" id="thisMonth" name="download_option" value="thisMonth">
66
+ <label for="thisMonth">This month</label>
67
+ </div>
68
+ <div>
69
+ <input type="radio" id="thisYear" name="download_option" value="thisYear">
70
+ <label for="thisYear">This year</label>
71
+ </div>
72
+ </div>
73
+ </div>
74
+ </div>
75
+ <div class="row">
76
+ <div class="col-md-12">
77
+ <h5>Additional Options</h5>
78
+ </div>
79
+ </div>
80
+ <div class="row">
81
+ <div class="col-md-6">
82
+ <div class="form-check">
83
+ <input type="checkbox" class="form-check-input" id="allFields" name="allFields">
84
+ <label class="form-check-label" for="allFields">All fields</label>
85
+ </div>
86
+ </div>
87
+ </div>
88
+ </form>
89
+ </div>
90
+ <div class="modal-footer">
91
+ <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
92
+ <button type="button" class="btn btn-primary" id="downloadButton">Download</button>
93
+ </div>
94
+ </div>
95
+ </div>
96
+ </div>
97
+
98
+ <style>
99
+ .dropdown-menu#column-visibility {
100
+ max-height: 300px;
101
+ width: 200px;
102
+ overflow-y: auto;
103
+ }
104
+
105
+ .dropdown-menu {
106
+ padding: 5px;
107
+ }
108
+ .toggle-button-right {
109
+ float: right;
110
+ margin-bottom: 10px;
111
+ margin-left: 10px;
112
+ background-color: white;
113
+ color: black;
114
+ text-transform: none;
115
+ border: 1px solid #ccc;
116
+ padding: 8px 15px;
117
+ }
118
+
119
+ .download-button-right {
120
+ float: right;
121
+ margin-bottom: 10px;
122
+ margin-left: 10px;
123
+ background-color: white;
124
+ color: black;
125
+ text-transform: none;
126
+ border: 1px solid #ccc;
127
+ padding: 8px 15px;
128
+ }
129
+
130
+ .icon-drag {
131
+ float: right;
132
+ padding: 5px;
133
+ }
134
+
135
+ .dropdown-container {
136
+ display: flex;
137
+ justify-content: flex-end;
138
+ }
139
+
140
+ .label-group-item-manual {
141
+ margin: 5px;
142
+ width: -webkit-fill-available;
143
+ cursor: grab;
144
+ }
145
+ .label-group-item-manual:active {
146
+ cursor: grabbing;
147
+ }
148
+ </style>
149
+
150
+ <%= javascript_tag do %>
151
+ $(document).ready(function() {
152
+ $('.dropdown-menu').on('click', 'input[type="checkbox"], label', function(event) {
153
+ event.stopPropagation();
154
+ });
155
+
156
+ $('#modalDownloadButton').click(function() {
157
+ $('#downloadCsvModal').modal('show');
158
+ });
159
+ $('#startDate, #endDate').datepicker({
160
+ dateFormat: 'yy-mm-dd'
161
+ });
162
+
163
+ $('#downloadCsvModal').on('show.bs.modal', function (e) {
164
+ $('#allData').prop('checked', true);
165
+ $('#startDate, #endDate').prop('disabled', true);
166
+ $('#startDate').val(null);
167
+ $('#endDate').val(null);
168
+ });
169
+
170
+ $('#allData').change(function() {
171
+ $('#startDate').val(null);
172
+ $('#endDate').val(null);
173
+ $('#startDate, #endDate').prop('disabled', true);
174
+ });
175
+
176
+ function setDateRange(option) {
177
+ var currentDate = new Date();
178
+ var startDate, endDate;
179
+
180
+ if (option === "day") {
181
+ startDate = new Date();
182
+ endDate = new Date();
183
+ endDate.setDate(endDate.getDate() + 1);
184
+ } else if (option === "week") {
185
+ startDate = new Date(currentDate.setDate(currentDate.getDate() - currentDate.getDay() + 1));
186
+ currentDate = new Date();
187
+ endDate = new Date(currentDate.setDate(currentDate.getDate() - currentDate.getDay() + 7));
188
+ } else if (option === "month") {
189
+ startDate = new Date(currentDate.getFullYear(), currentDate.getMonth(), 1);
190
+ endDate = new Date(currentDate.getFullYear(), currentDate.getMonth() + 1, 0);
191
+ } else if (option === "year") {
192
+ startDate = new Date(currentDate.getFullYear(), 0, 1);
193
+ endDate = new Date(currentDate.getFullYear(), 11, 31);
194
+ }
195
+
196
+ var startDateFormatted = startDate.toISOString().split('T')[0];
197
+ var endDateFormatted = endDate.toISOString().split('T')[0];
198
+
199
+ $('#startDate').val(startDateFormatted);
200
+ $('#endDate').val(endDateFormatted);
201
+ $('#startDate, #endDate').prop('disabled', true);
202
+ }
203
+
204
+ $('#thisWeek').change(function() {
205
+ if ($(this).is(':checked')) {
206
+ setDateRange("week");
207
+ }
208
+ });
209
+
210
+ $('#thisMonth').change(function() {
211
+ if ($(this).is(':checked')) {
212
+ setDateRange("month");
213
+ }
214
+ });
215
+
216
+ $('#thisYear').change(function() {
217
+ if ($(this).is(':checked')) {
218
+ setDateRange("year");
219
+ }
220
+ });
221
+
222
+ $('#customDate').change(function() {
223
+ if ($(this).is(':checked')) {
224
+ setDateRange("day");
225
+ $('#startDate, #endDate').prop('disabled', false);
226
+ }
227
+ });
228
+
229
+ var downloadButton = document.getElementById('downloadButton');
230
+ if (downloadButton) {
231
+ downloadButton.addEventListener('click', function() {
232
+ event.preventDefault();
233
+
234
+ var allFieldsChecked = $('#allFields').is(':checked');
235
+ var startDate = $('#startDate').val();
236
+ var endDate = $('#endDate').val();
237
+ var downloadAll = $('#allData').is(':checked');
238
+ var thElements = document.querySelectorAll('#invoices-table th');
239
+ var columnTitles = Array.from(thElements).map(function(th) {
240
+ return th.textContent.trim();
241
+ });
242
+ var columnsString = columnTitles.join(',')
243
+
244
+ var url = new URL("<%= download_invoices_path %>", window.location.origin);
245
+ var params = new URLSearchParams();
246
+ params.append('account_id', "<%=@account.account_id%>");
247
+ params.append('columnsString', columnsString);
248
+ if (!downloadAll) {
249
+ params.append('startDate', startDate);
250
+ params.append('endDate', endDate);
251
+ }
252
+ params.append('allFieldsChecked', allFieldsChecked);
253
+ url.search = params.toString();
254
+ console.log(url.toString());
255
+ window.open(url.toString(), '_blank');
256
+ });
257
+ }
258
+
259
+ updateDropdownOrder();
260
+
261
+ function loadState() {
262
+ var state = JSON.parse(localStorage.getItem('DataTables_invoices-table'));
263
+ return state || { columns: [], columnOrder: [] };
264
+ }
265
+
266
+ function updateDropdownOrder() {
267
+ var state = loadState();
268
+ var columnOrder = state.ColReorder;
269
+ var $list = $('#column-visibility');
270
+ var thElements = document.querySelectorAll('#invoices-table th');
271
+ var $columnTitles = Array.from(thElements).map(function(th) {
272
+ return th.textContent.trim();
273
+ });
274
+ if (columnOrder !== undefined) {
275
+ $list.empty();
276
+ columnOrder.forEach(function(colIdx, index) {
277
+ var $item = $('<li>', { class: "list-group-item-manual", "data-id": index });
278
+ var column = state.columns[colIdx];
279
+ var col_name = $columnTitles[colIdx];
280
+ var $label = $('<label>', {
281
+ class: "label-group-item-manual",
282
+ });
283
+ var $checkbox = $("<input>", {
284
+ type: "checkbox",
285
+ value: colIdx,
286
+ checked: column.visible,
287
+ "data-column": colIdx,
288
+ class: "column-toggle"
289
+ });
290
+ $label.append($checkbox).append(" " + col_name);
291
+ var $icon = $("<span>", { class: "glyphicon glyphicon-option-vertical icon-drag"});
292
+ $label.append($icon);
293
+ $item.append($label);
294
+ $list.append($item);
295
+ });
296
+ }
297
+ resetDataColumn();
298
+ resetDataId();
299
+ }
300
+
301
+ $("#column-visibility").sortable({
302
+ axis: "y",
303
+ containment: "parent",
304
+ stop: function(event, ui) {
305
+ var order = $("#column-visibility").sortable('toArray', {attribute: 'data-id'});
306
+ reorderTableColumns(order);
307
+ }
308
+ });
309
+ $("#column-visibility").disableSelection();
310
+
311
+ function reorderTableColumns(order) {
312
+ var table = $('#invoices-table').DataTable();
313
+ var columnIndexes = order.map(Number);
314
+ console.log('New column order:', columnIndexes);
315
+ table.colReorder.order(columnIndexes);
316
+ resetDataColumn();
317
+ resetDataId();
318
+ }
319
+
320
+ function resetDataId() {
321
+ var elements = document.querySelectorAll('.list-group-item-manual');
322
+ elements.forEach(function(element, index) {
323
+ element.setAttribute('data-id', index);
324
+ });
325
+ }
326
+
327
+ function resetDataColumn() {
328
+ var elements = document.querySelectorAll('.column-toggle');
329
+ elements.forEach(function(element, index) {
330
+ element.setAttribute('data-column', index);
331
+ });
332
+ }
333
+
334
+ $('.column-toggle').on('change', function() {
335
+ var table = $('#invoices-table').DataTable();
336
+ var column = table.column($(this).attr('data-column'));
337
+ column.visible(!column.visible());
338
+ });
339
+ });
340
+ <% end %>