zuora_connect_ui 0.10.3 → 0.11.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/zuora_connect_ui.js +8 -24
  3. data/app/assets/javascripts/zuora_connect_ui/app.js.erb +4 -18
  4. data/app/assets/javascripts/zuora_connect_ui/bundle/connect-ui.min.js +28 -0
  5. data/app/assets/javascripts/zuora_connect_ui/bundle/connect-ui.min.js.map +1 -0
  6. data/app/assets/javascripts/zuora_connect_ui/globals.js +24 -0
  7. data/app/assets/javascripts/zuora_connect_ui/noty.js +0 -21
  8. data/app/assets/stylesheets/zuora_connect_ui/buttons.scss +37 -12
  9. data/app/assets/stylesheets/zuora_connect_ui/datatables.scss +4 -0
  10. data/app/helpers/zuora_connect_ui/application_helper.rb +2 -2
  11. data/app/views/partials/_table.html.erb +3 -3
  12. data/lib/peek/views/connect.rb +2 -0
  13. data/lib/zuora_connect_ui.rb +2 -0
  14. data/lib/zuora_connect_ui/serializer.rb +15 -11
  15. data/lib/zuora_connect_ui/serializer/relationship.rb +7 -2
  16. data/lib/zuora_connect_ui/version.rb +1 -1
  17. metadata +145 -29
  18. data/app/assets/javascripts/zuora_connect_ui/datatable.js +0 -344
  19. data/app/assets/javascripts/zuora_connect_ui/fetch.js +0 -42
  20. data/app/assets/javascripts/zuora_connect_ui/iframe.js +0 -49
  21. data/app/assets/javascripts/zuora_connect_ui/input.js +0 -10
  22. data/app/assets/javascripts/zuora_connect_ui/tabs.js +0 -4
  23. data/app/assets/javascripts/zuora_connect_ui/util.js +0 -51
  24. data/vendor/assets/bootstrap-datepicker/js/bootstrap-datepicker.min.js +0 -8
  25. data/vendor/assets/bootstrap-datepicker/locales/bootstrap-datepicker.it.min.js +0 -1
  26. data/vendor/assets/bootstrap-datepicker/locales/bootstrap-datepicker.ja.min.js +0 -1
  27. data/vendor/assets/bootstrap-datepicker/locales/bootstrap-datepicker.zh-CN.min.js +0 -1
  28. data/vendor/assets/html5sortable/js/html5sortable.min.js +0 -1
  29. data/vendor/assets/idb-keyval/js/idb-keyval-iife.js +0 -100
  30. data/vendor/assets/noty/js/noty.min.js +0 -16
@@ -1,344 +0,0 @@
1
- // Datatables in tabs that aren't initially shown need columns resized on show
2
- $(document).on("shown.bs.tab", 'a[data-toggle="tab"]', function(e) {
3
- $(this.getAttribute("href"))
4
- .find("table.dataTable")
5
- .each(function() {
6
- $(this)
7
- .dataTable()
8
- .fnAdjustColumnSizing();
9
- });
10
- });
11
-
12
- const zStorage = (function() {
13
- const stores = {};
14
- let warning = false;
15
-
16
- function logWarning(error) {
17
- if (warning) return;
18
- console.warn("Table State cannot be saved in Safari");
19
- warning = true;
20
- }
21
-
22
- return {
23
- set(key, value, table) {
24
- if (!stores.hasOwnProperty(table)) {
25
- stores[table] = new idbKeyval.Store(APP_NAME, table + "_table");
26
- }
27
- return idbKeyval.set(key, value, stores[table]).catch(logWarning);
28
- },
29
-
30
- get(key, table) {
31
- if (!stores.hasOwnProperty(table)) {
32
- stores[table] = new idbKeyval.Store(APP_NAME, table + "_table");
33
- }
34
- return idbKeyval.get(key, stores[table]).catch(logWarning);
35
- }
36
- };
37
- })();
38
-
39
- const DEBUG = false;
40
-
41
- function getTableParams(tableName, settings, callback) {
42
- const [cacheFilters, paramFilters] = settings.filters.reduce(
43
- ([c, p], cur) => (cur.cache ? [[cur, ...c], p] : [c, [cur, ...p]]),
44
- [[], []]
45
- );
46
-
47
- Promise.all(
48
- [
49
- zStorage.get("view", tableName),
50
- zStorage.get("size", tableName),
51
- zStorage.get("sort", tableName),
52
- zStorage.get("fields", tableName)
53
- ].concat(cacheFilters.map(f => zStorage.get(f.name + "_filter", tableName)))
54
- ).then(v => {
55
- const [view, size, sort, fields, ...savedFilters] = v;
56
-
57
- cacheFilters.forEach((f, i) => setupFilter(tableName, f, savedFilters[i]));
58
- paramFilters.forEach(f => setupFilter(tableName, f, undefined));
59
-
60
- const visibleColumns = (fields || []).reduce(
61
- (acc, cur) => (cur.vis ? acc.concat(cur.col) : acc),
62
- []
63
- );
64
-
65
- const columns =
66
- fields === undefined
67
- ? settings.columns
68
- : settings.columns
69
- .map(c => {
70
- const index = fields.findIndex(f => f.col === c.data);
71
- return {
72
- ...c,
73
- visible: visibleColumns.includes(c.data),
74
- sortIndex: index === -1 ? 9999 : index
75
- };
76
- })
77
- .sort((a, b) => a.sortIndex - b.sortIndex);
78
-
79
- callback(
80
- columns,
81
- view || settings.view,
82
- size || settings.size,
83
- (sort || settings.sort).map(([col, dir]) => {
84
- const newCol = settings.columns.findIndex(c => c.data === col);
85
- return [newCol > -1 ? newCol : 1, dir];
86
- })
87
- );
88
- });
89
- }
90
-
91
- function setupFilter(tableName, filter, cached) {
92
- switch (filter.type) {
93
- case "checkbox":
94
- return (cached === undefined ? filter.defaults : cached).forEach(v =>
95
- $(`#zc_${tableName}_${filter.name} input[value="${v}"]`).prop(
96
- "checked",
97
- true
98
- )
99
- );
100
- case "select":
101
- case "group-select":
102
- return $(`#${tableName}_content select[name="${filter.name}"]`)
103
- .val(cached === undefined ? filter.defaults : cached)
104
- .trigger("change");
105
- // Is boolean used by any apps?
106
- case "boolean":
107
- return $(`#${tableName}_content input[name="${filter.name}"]`).prop(
108
- "checked",
109
- cached === undefined ? filter.defaults : cached
110
- );
111
- }
112
- }
113
-
114
- function initTable(api, tableName, settings, columns, tableFilters) {
115
- initViewMode(api, tableName, settings.view);
116
- initTableSize(api, tableName, settings.size);
117
- initSortEvent(api, tableName);
118
- initSearch(api, tableName);
119
- initTableSelection(api, tableName);
120
- initColumnEvents(api, tableName, columns);
121
- initTableFilters(api, tableName, tableFilters);
122
-
123
- $(`#${tableName}_refresh`).on("click", function(e) {
124
- if (
125
- $(`#${tableName}_content`).is(":visible") &&
126
- !$(this).hasClass("zc-spin")
127
- ) {
128
- api.draw(false);
129
- }
130
- });
131
- }
132
-
133
- function initViewMode(api, tableName, mode) {
134
- $(`#${tableName}_view_${mode}`).addClass("active");
135
-
136
- const viewModeSelectors = `#${tableName}_view_table, #${tableName}_view_grid`;
137
- $(viewModeSelectors).on("click", () => {
138
- if ($(this).hasClass("active")) return;
139
-
140
- $(viewModeSelectors).toggleClass("active");
141
- zStorage.set("view", $(this).data("mode"), tableName);
142
- api
143
- .draw(false)
144
- .rows()
145
- .deselect();
146
- });
147
- }
148
-
149
- function getTableViewMode(tableName, fallback) {
150
- if ($(`#${tableName}_view_table`).hasClass("active")) return "table";
151
- else if ($(`#${tableName}_view_grid`).hasClass("active")) return "grid";
152
- else return fallback;
153
- }
154
-
155
- function initTableSize(api, tableName, size) {
156
- $("<select>", { id: "table_size", name: "table_size" }) // TODO: Not sure if this needs to be named
157
- .appendTo(`#${tableName}_select_container`)
158
- .append([10, 25, 50, 100].map(v => `<option value="${v}">${v}</option>`))
159
- .val(size)
160
- .select2({
161
- theme: "default",
162
- minimumResultsForSearch: Infinity
163
- })
164
- .on("change", function(e) {
165
- api.page.len(+$(this).val()).draw(false);
166
- zStorage.set("size", +$(this).val(), tableName);
167
- });
168
- }
169
-
170
- function initSortEvent(api, tableName) {
171
- api.on("order.dt", function(e) {
172
- zStorage.set(
173
- "sort",
174
- api.order().map(([col, dir]) => [api.column(col).dataSrc(), dir]),
175
- tableName
176
- );
177
- });
178
- }
179
-
180
- function initSearch(api, tableName) {
181
- $(`#${tableName}_search_btn`).on("click", () => {
182
- $(`#${tableName}_search_wrapper`).toggleClass("active");
183
- $(`#${tableName}_search`).focus();
184
- });
185
-
186
- let timer;
187
- $(`#${tableName}_search`).on("input", function(e) {
188
- clearTimeout(timer);
189
- timer = setTimeout(function() {
190
- api.draw();
191
- }, 700);
192
- });
193
-
194
- $(`#${tableName}_search`).keydown(function(e) {
195
- if (e.keyCode == 13) {
196
- e.preventDefault();
197
- return false;
198
- }
199
- });
200
- }
201
-
202
- function initTableSelection(api, tableName) {
203
- $(`#${tableName}_select_all`).on("click", function(e) {
204
- $(this)
205
- .find("span")
206
- .hasClass("z-icon-addition")
207
- ? api.rows().select()
208
- : api.rows().deselect();
209
- });
210
-
211
- api.on("select.dt deselect.dt", function(e, dt, type, indexes) {
212
- const count = dt.rows({ selected: true }).count();
213
- $(`#${tableName}_group_actions`).toggleClass("hidden", count == 0);
214
- $(`#${tableName}_select_all span`)
215
- .toggleClass("z-icon-addition", count !== dt.rows().count())
216
- .toggleClass("z-icon-subtraction", count === dt.rows().count());
217
- if (DEBUG) {
218
- console.log(e.type === "select" ? "Selected" : "Deselected");
219
- console.log(dt.rows(indexes).data());
220
- }
221
- });
222
- }
223
-
224
- function initColumnEvents(api, tableName, columns) {
225
- let dropdownReorder = false;
226
-
227
- $(`#${tableName}_visibility_menu`).html(
228
- columns.map((c, i) =>
229
- $("<li>", { "data-key": c.data, class: "checkbox-row" }).append(
230
- $("<div>", { class: "checkbox checkbox-primary" }).append(
231
- $("<input>", {
232
- type: "checkbox",
233
- name: `${tableName}[table_column_vis][]`,
234
- checked: !Object.keys(c).includes("visible") || c.visible,
235
- value: i
236
- }).on("change", function() {
237
- const index = api.colReorder.transpose(+$(this).val(), "toCurrent");
238
- api.column(index).visible($(this).is(":checked"));
239
- resize_iframe();
240
- saveColumns();
241
- }),
242
- $("<label>").html(
243
- (c.class || "").includes("actions") ? "Actions" : c.title
244
- )
245
- ),
246
- $('<span class="icon z-icon-hamburger"></span>')
247
- )
248
- )
249
- );
250
-
251
- sortable(`#${tableName}_visibility_menu`, {
252
- placeholder: '<li class="checkbox-row">&nbsp;</li>'
253
- })[0].addEventListener("sortupdate", () => {
254
- if (DEBUG) console.log(`Sort Stop Trigger ${tableName}`);
255
- dropdownReorder = true;
256
-
257
- api.colReorder.order(
258
- $(`#${tableName}_visibility_menu li input`)
259
- .get()
260
- .map(v => api.colReorder.transpose(+$(v).val(), "toCurrent"))
261
- );
262
- });
263
-
264
- api.on("column-reorder", function(e, settings, details) {
265
- if (DEBUG) console.log(`Ordering Trigger ${tableName}`, details);
266
- saveColumns();
267
-
268
- if (dropdownReorder) return (dropdownReorder = false);
269
- if (DEBUG) console.log(`Ordering Trigger Rebuild DropDown ${tableName}`);
270
-
271
- const orderedItems = api
272
- .columns()
273
- .dataSrc()
274
- .toArray()
275
- .map(v => $(`#${tableName}_visibility_menu li[data-key="${v}"]`));
276
- $(`#${tableName}_visibility_menu`).html(orderedItems);
277
- });
278
-
279
- function saveColumns() {
280
- if (DEBUG) console.log(`Save Fields ${tableName}`);
281
-
282
- const fields = api
283
- .columns()
284
- .indexes()
285
- .toArray()
286
- .map(i => ({
287
- col: api.column(i).dataSrc(),
288
- vis: api.column(i).visible()
289
- }));
290
-
291
- zStorage.set("fields", fields, tableName);
292
- }
293
- }
294
-
295
- function initTableFilters(api, tableName, tableFilters) {
296
- tableFilters.forEach(filter => {
297
- const cache = filter.hasOwnProperty("cache") && filter.cache;
298
-
299
- switch (filter.type) {
300
- case "checkbox":
301
- return checkboxFilter(api, cache, filter);
302
- case "select":
303
- case "group-select":
304
- return selectFilter(api, cache, filter);
305
- case "boolean":
306
- return booleanFilter(api, cache, filter);
307
- }
308
- });
309
-
310
- function checkboxFilter(api, cache, filter) {
311
- const checkboxDebounceDraw = debounce(() => {
312
- const f = $(
313
- `#zc_${tableName}_${filter.name} input[name="${filter.name}[]"]:checked`
314
- )
315
- .map((_, el) => $(el).val())
316
- .get();
317
- if (cache) zStorage.set(filter.name + "_filter", f, tableName);
318
- api.draw();
319
- }, 750);
320
-
321
- $(`#zc_${tableName}_${filter.name} input[name="${filter.name}[]"]`).on(
322
- "click",
323
- checkboxDebounceDraw
324
- );
325
- }
326
-
327
- function selectFilter(api, cache, filter) {
328
- $(`#${tableName}_content select[name="${filter.name}"]`).change(function() {
329
- const f = $(this).val();
330
- if (cache) zStorage.set(filter.name + "_filter", f, tableName);
331
- api.draw();
332
- });
333
- }
334
-
335
- function booleanFilter(api, cache, filter) {
336
- $(`#${tableName}_content input[name="${filter.name}"]`).change(function() {
337
- const f = $(
338
- `#${tableName}_content input[name="${filter.name}"]:checked`
339
- ).val();
340
- if (cache) zStorage.set(filter.name + "_filter", f, tableName);
341
- api.draw();
342
- });
343
- }
344
- }
@@ -1,42 +0,0 @@
1
- const hallwayPrefix = (() => {
2
- let prefix;
3
-
4
- return () => {
5
- if (prefix === undefined) {
6
- const meta = document.querySelector('meta[name="z-hallway-prefix"]');
7
- prefix = meta ? meta.content : "";
8
- }
9
- return prefix;
10
- };
11
- })();
12
-
13
- const fetchJson = (url, options) =>
14
- fetch(`${hallwayPrefix()}${url}`, {
15
- ...options,
16
- headers: {
17
- Accept: "application/json",
18
- ...(options && options.headers) // npm package uses a default parameter
19
- }
20
- }).then(checkStatus);
21
-
22
- const checkStatus = response => {
23
- if (!response.ok) throw response;
24
- return response.json();
25
- };
26
-
27
- const getErrorMessage = response => {
28
- if (response.json)
29
- return response
30
- .json()
31
- .catch(error => {
32
- if (process.env.NODE_ENV !== "production") console.error(error);
33
- throw `${response.status} - ${response.statusText}`;
34
- })
35
- .then(json => {
36
- if (process.env.NODE_ENV !== "production") console.error(json);
37
- if (json.csrf) location.reload();
38
- throw json.message;
39
- });
40
- if (process.env.NODE_ENV !== "production") console.error(response);
41
- throw "Unknown Error";
42
- };
@@ -1,49 +0,0 @@
1
- $(document).on("hidden.bs.modal shown.bs.modal shown.bs.tab", resize_iframe);
2
-
3
- let height_prev;
4
- function resize_iframe() {
5
- if (typeof(hallwayPrefix) !== "undefined") {
6
- workflow_canvas = document.getElementById('canvas');
7
- if (workflow_canvas !== null) {
8
- height = window.innerHeight - $(".new_navbar").height() - $("#breadcrumbs").height() - $(".nav.tab-header").height() - $(".green-header").height() - $(".new_navbar_footer").height() - 35;
9
- workflow_canvas.setAttribute("style", "height: " + height + "px;");
10
- }
11
- return;
12
- }
13
- var height = 0;
14
- if ($(".modal-dialog").height() + 100 > $("body").height()) {
15
- height = $(".modal-dialog").height() + 100;
16
- } else if (
17
- $(".dropdown-menu.table_visiblity.ui-sortable:visible").height() + 150 >
18
- $("body").height()
19
- ) {
20
- height =
21
- $(".dropdown-menu.table_visiblity.ui-sortable:visible").height() + 150;
22
- } else if ($("#canvas").is(":visible")) {
23
- var canvas_height =
24
- window.innerHeight -
25
- ($("#breadcrumbs").height() + $(".green-header").height() + 20);
26
- $("#canvas").css("height", "500px");
27
- height = $("body").height();
28
- } else if ($("#canvas-swimlane").is(":visible")) {
29
- $("#canvas-swimlane").css("height", "300px");
30
- height = $("body").height() + $("#task_data").height() - 160;
31
- } else {
32
- height = $("body").height() + 25;
33
- }
34
- if (height_prev != height) {
35
- window.parent.postMessage({ func: "resizeIframe", height: height }, "*");
36
- }
37
- height_prev = height;
38
- }
39
-
40
- // Function to be called from iframe
41
- function receiveMessage(event) {
42
- if (event.origin !== window.location.origin) return;
43
- var data = event.data;
44
- if (typeof window[data.func] == "function") {
45
- window[data.func].call(null, data.type, data.url);
46
- } else {
47
- console.log("Function not found: " + data.func);
48
- }
49
- }
@@ -1,10 +0,0 @@
1
- // 'Polyfill' for :placeholder-shown, since it's not standard yet
2
-
3
- $(document).on('change change.select2', '.zuo-form-group.has-error > input, .zuo-form-group.has-error > select', function(e) {
4
- $(this).parent('.zuo-form-group').removeClass('has-error');
5
- });
6
-
7
- $.fn.select2.defaults.set("theme", "bootstrap");
8
- $.fn.select2.defaults.set("dropdownAutoWidth", true);
9
- $.fn.select2.defaults.set("width", "100%");
10
- $.fn.select2.defaults.set("placeholder", "");
@@ -1,4 +0,0 @@
1
- $(document).on('click', 'anj-tab', function(e) {
2
- $(this).siblings('anj-tab').prop('active', false);
3
- $(this).prop('active', true);
4
- });