jqgrid_utils 1.41.0 → 1.42.0

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.
@@ -1,2282 +1 @@
1
- (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Jqgrid_utils = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
2
- /**
3
- * A module for Jqgrid_utils
4
- * @module Jqgrid_utils
5
- */
6
-
7
- "use strict";
8
-
9
- module.exports = class Vanilla_website_utils {
10
- constructor(settings = false) {
11
- if (settings) {
12
- if (settings.hasOwnProperty("page")) {
13
- this.page = settings["page"];
14
- localStorage.setItem("page", this.page);
15
- }
16
- }
17
- }
18
-
19
- /**
20
- * Format a number into a currency if have value, otherwise return empty
21
- @alias module:Jqgrid_utils
22
- @param {object} - col_model of the grid
23
- @param {string} - name of column to be formatter
24
- @param {string} - currency symbol, default is $
25
- @example
26
- var jqu = new Jqgrid_utils();
27
- let _data = await jqu.format_currency(this,'my_field','$');
28
- console.log(_data);
29
- */
30
- async format_currency_on_value(col_model, edit_field, currency = "$") {
31
- for (let i = 0; i < col_model.length; i++) {
32
- if (col_model[i]["name"] === edit_field) {
33
- col_model[i]["formatoptions"] = {
34
- prefix: currency,
35
- decimalSeparator: ".",
36
- thousandsSeparator: ",",
37
- decimalPlaces: 2,
38
- };
39
- col_model[i]["formatter"] = function (cellvalue, options, rowObject) {
40
- if (
41
- cellvalue === null ||
42
- cellvalue === undefined ||
43
- cellvalue === ""
44
- ) {
45
- return ""; // Return an empty string for no value
46
- } else if (parseFloat(cellvalue) === 0) {
47
- return ""; // Return an empty string for zero value
48
- } else {
49
- // Apply currency formatting
50
- var currency = options.colModel.formatoptions.prefix; // Get currency symbol
51
- var decimalSeparator =
52
- options.colModel.formatoptions.decimalSeparator;
53
- var thousandsSeparator =
54
- options.colModel.formatoptions.thousandsSeparator;
55
- var decimalPlaces = options.colModel.formatoptions.decimalPlaces;
56
-
57
- // Implement your currency formatting logic here
58
- // (This is a simplified example; you might need a more robust formatting function)
59
- var formattedValue = parseFloat(cellvalue).toFixed(decimalPlaces);
60
- formattedValue = formattedValue.replace(".", decimalSeparator);
61
-
62
- // Add thousands separator
63
- var parts = formattedValue.split(decimalSeparator);
64
- parts[0] = parts[0].replace(
65
- /\B(?=(\d{3})+(?!\d))/g,
66
- thousandsSeparator,
67
- );
68
- formattedValue = parts.join(decimalSeparator);
69
-
70
- return currency + formattedValue; // Return formatted value
71
- }
72
- };
73
- }
74
- }
75
- return col_model;
76
- }
77
-
78
- /**
79
- * Format a number into a currency
80
- @alias module:Jqgrid_utils
81
- @param {object} - col_model of the grid
82
- @param {string} - name of column to be formatter
83
- @param {string} - currency symbol, default is $
84
- @example
85
- var jqu = new Jqgrid_utils();
86
- let _data = await jqu.format_currency(this,'my_field','$');
87
- console.log(_data);
88
- */
89
- async format_currency(col_model, edit_field, currency = "$") {
90
- for (let i = 0; i < col_model.length; i++) {
91
- if (col_model[i]["name"] === edit_field) {
92
- col_model[i]["formatter"] = "currency";
93
- col_model[i]["formatoptions"] = {
94
- prefix: currency,
95
- decimalSeparator: ".",
96
- thousandsSeparator: ",",
97
- decimalPlaces: 2,
98
- };
99
- }
100
- }
101
- return col_model;
102
- }
103
-
104
- /**
105
- * Add a Checkbox to the Model
106
- @alias module:Jqgrid_utils
107
- @param {array} - grid col_model
108
- @param {string} - column_name
109
- @example
110
- var jqu = new Jqgrid_utils();
111
- ol_model = await jqu.add_checkbox(col_model, "closed");
112
- */
113
- async add_checkbox(col_model, field_name) {
114
- for (let i = 0; i < col_model.length; i++) {
115
- if (col_model[i]["name"] === field_name) {
116
- col_model[i]["formatter"] = "checkbox";
117
- col_model[i]["formatoptions"] = { disabled: false };
118
- col_model[i]["edittype"] = "checkbox";
119
- col_model[i]["editoptions"] = { value: "Yes:No", defaultValue: "Yes" };
120
- }
121
- }
122
- return col_model;
123
- }
124
-
125
- /**
126
- * Add a Class to the Model
127
- @alias module:Jqgrid_utils
128
- @param {array} - grid col_model
129
- @param {string} - column_name
130
- @param {string} - class_name
131
- @example
132
- var jqu = new Jqgrid_utils();
133
- col_model = await jqu.add_class(col_model,field_name,class_name)
134
- */
135
-
136
- async add_class(col_model, field_name, class_name) {
137
- for (let i = 0; i < col_model.length; i++) {
138
- if (col_model[i]["name"] === field_name) {
139
- if (col_model[i]["classes"]) {
140
- col_model[i]["classes"] += " " + class_name;
141
- } else {
142
- col_model[i]["classes"] = class_name;
143
- }
144
- }
145
- }
146
- return col_model;
147
- }
148
-
149
- /**
150
- * Syncron Alias grid_sum_on
151
- @alias module:Jqgrid_utils
152
- */
153
- async _grid_substract_on(
154
- grid,
155
- minuend = [],
156
- subtrahend = [],
157
- difference,
158
- no_negative = false,
159
- ) {
160
- return await this.grid_substract_on(
161
- grid,
162
- minuend,
163
- subtrahend,
164
- difference,
165
- no_negative,
166
- );
167
- }
168
-
169
- /**
170
- * Sum the columns values together
171
- @alias module:Jqgrid_utils
172
- @param {object} - Grid Object (required)
173
- @param {array} - string array list of field_names used as minuend(number from which the other number is subtracted)
174
- @param {array} - string array list of field_names used as subtrahend(number which is to be subtracted from the minuend)
175
- @param {string} - string field name for the difference(number which is to be subtracted from the minuend)
176
- @param {bolen} - true or 1 to not show negative numbers
177
-
178
- @example
179
- var jqu = new Jqgrid_utils({page:page});
180
- gridComplete: function () {
181
- jqu._jqu._grid_sum_on(this, [
182
- "qty_icollect",
183
- "qty_ordered",
184
- "need_for_qty_ordered",
185
- "wait_icollect",
186
- ]);
187
- },
188
- */
189
- async grid_substract_on(
190
- grid,
191
- minuend = [],
192
- subtrahend = [],
193
- difference,
194
- no_negative = false,
195
- ) {
196
- let $self = jQuery(grid);
197
- let rows = $self.jqGrid("getGridParam", "data");
198
- let footer = { invdate: "Total" };
199
- let _minuend = 0.0;
200
- let _subtrahend = 0.0;
201
- for (let i in minuend) {
202
- let sum = 0;
203
- for (let r in rows) {
204
- if (rows[r].hasOwnProperty(minuend[i])) {
205
- let val = rows[r][minuend[i]];
206
- if (typeof val === "string") {
207
- if (is_digit(val)) {
208
- val = parseFloat(val);
209
- }
210
- }
211
- sum += val;
212
- }
213
- }
214
- if (sum != Math.floor(sum)) {
215
- sum = sum.toFixed(2);
216
- }
217
- footer[minuend[i]] = sum;
218
- _minuend = sum;
219
- }
220
-
221
- for (let i in subtrahend) {
222
- let sum = 0;
223
- for (let r in rows) {
224
- if (rows[r].hasOwnProperty(subtrahend[i])) {
225
- let val = rows[r][subtrahend[i]];
226
- if (typeof val === "string") {
227
- if (is_digit(val)) {
228
- val = parseFloat(val);
229
- }
230
- }
231
- sum += val;
232
- }
233
- }
234
- if (sum != Math.floor(sum)) {
235
- sum = sum.toFixed(2);
236
- }
237
- footer[subtrahend[i]] = sum;
238
- _subtrahend = sum;
239
- }
240
-
241
- let diff = _minuend - _subtrahend;
242
- if (no_negative) {
243
- if (diff < 0) {
244
- diff = 0;
245
- }
246
- }
247
- footer[difference] = diff;
248
-
249
- $self.jqGrid("footerData", "set", footer);
250
-
251
- return footer;
252
- }
253
-
254
- /**
255
- * Syncron Alias grid_ratio_on
256
- @alias module:Jqgrid_utils
257
- */
258
- _grid_ratio_on(grid, fraction_col, denominator_col, ratio_col) {
259
- return this.grid_ratio_on(grid, fraction_col, denominator_col, ratio_col);
260
- }
261
-
262
- /**
263
- * Get the ratio the columns values together
264
- @alias module:Jqgrid_utils
265
- @param {object} - Grid Object (required)
266
- @param {string} - Column/Field Name for value 1
267
- @param {string} - Column/Field Name for value 2
268
- @param {string} - Column/Field Name to the set the target ratio
269
- @example
270
- var jqu = new Jqgrid_utils({page:page});
271
- gridComplete: function()
272
- {
273
- jqu._grid_ratio_on(this, 'actual_days', 'plan_days', 'qc_eta_ratio');
274
- },
275
-
276
- */
277
- async grid_ratio_on(grid, fraction_col, denominator_col, ratio_col) {
278
- var allrows = jQuery("#grid").jqGrid("getGridParam", "data");
279
- let $self = jQuery(grid);
280
- let rows = $self.jqGrid("getGridParam", "data");
281
- let footer = {
282
- invdate: "Total",
283
- };
284
- let sum = 0;
285
- fraction_sum = 0;
286
- denominator_sum = 0;
287
- ratio_sum = 0;
288
- for (let r in rows) {
289
- if (rows[r].hasOwnProperty(fraction_col)) {
290
- fraction_sum += rows[r][fraction_col];
291
- }
292
- if (rows[r].hasOwnProperty(denominator_col)) {
293
- denominator_sum += rows[r][denominator_col];
294
- }
295
- }
296
- footer["qc_eta_ratio"] = (fraction_sum / denominator_sum).toFixed(2);
297
- $self.jqGrid("footerData", "set", footer);
298
- return footer;
299
- }
300
-
301
- /**
302
- * Check if the string is html
303
- @alias module:Jqgrid_utils
304
- @param {string} - String of any kind
305
- @returns {boolean} - true or false
306
- */
307
- is_html(str) {
308
- let r = false;
309
- try {
310
- const doc = new DOMParser().parseFromString(str, "text/html");
311
- const a = Array.from(doc.body.childNodes).some((n) => n.nodeType === 1);
312
- if (a) {
313
- r = true;
314
- }
315
- } catch (err) {}
316
- return r;
317
- }
318
-
319
- /**
320
- * Syncron Alias grid_sum_on
321
- @alias module:Jqgrid_utils
322
- */
323
- async _grid_sum_on(grid, fields = [], format = "", exclude = []) {
324
- return await this.grid_sum_on(grid, fields, format, exclude);
325
- }
326
-
327
- /**
328
- * Sum the columns values together
329
- @alias module:Jqgrid_utils
330
- @param {object} - Grid Object (required)
331
- @param {string} - Column/Field Name to sum
332
- @param {string} - format, currency sign
333
- @param {array} - exclude, array of column field key:value object, example [{"user": "foo"}] - it excludes user with value foo
334
- @example
335
- var jqu = new Jqgrid_utils({page:page});
336
- gridComplete: function () {
337
- jqu._jqu._grid_sum_on(this, [
338
- "qty_icollect",
339
- "qty_ordered",
340
- "need_for_qty_ordered",
341
- "wait_icollect",
342
- ]
343
- "$",
344
- [{user:"foo",country:"None"}]
345
- );
346
- },
347
- */
348
- async grid_sum_on(grid, fields = [], format = "", exclude = []) {
349
- //console.log(format);
350
- let $self = jQuery(grid);
351
- let rows = $self.jqGrid("getGridParam", "data");
352
- let footer = {
353
- invdate: "Total",
354
- };
355
- for (let i in fields) {
356
- let sum = 0;
357
- for (let r in rows) {
358
- let _val = 0;
359
- if (rows[r].hasOwnProperty(fields[i])) {
360
- let val = rows[r][fields[i]];
361
- let include = true;
362
-
363
- for (let x = 0; x < exclude.length; x++) {
364
- for (let e in exclude[x]) {
365
- //console.log(exclude[x][e] + " <> " + rows[r][e]);
366
- if (rows[r][e] === exclude[x][e]) {
367
- include = false;
368
- break;
369
- }
370
- }
371
- }
372
-
373
- if (val && include) {
374
- if (typeof val === "string") {
375
- if (this.is_html(val)) {
376
- const doc = new DOMParser().parseFromString(val, "text/html");
377
- const _a = doc.querySelectorAll("a");
378
- const a = Array.from(_a).map((a) => a.text);
379
- if (a.length) {
380
- const n = a[0].replace(",", "");
381
- if (is_digit(n)) {
382
- _val = parseFloat(n);
383
- }
384
- }
385
- } else {
386
- if (is_digit(val)) {
387
- _val = parseFloat(val);
388
- }
389
- }
390
- } else if (typeof val === "number") {
391
- _val = val;
392
- }
393
- sum += _val;
394
- }
395
- }
396
- }
397
- //let number = new Intl.NumberFormat('en-En', { style: 'currency', currency: 'USD' }).format(sum);
398
- if (sum != Math.floor(sum)) {
399
- sum = sum.toFixed(2);
400
- }
401
-
402
- if (format != "") {
403
- footer[fields[i]] = format + "" + this._format_number_with_commas(sum);
404
- } else {
405
- footer[fields[i]] = sum;
406
- }
407
- }
408
-
409
- $self.jqGrid("footerData", "set", footer);
410
- return footer;
411
- }
412
-
413
- /**
414
- * Syncron Alias grid_avg_on
415
- @alias module:Jqgrid_utils
416
- */
417
- _grid_avg_on(grid, fields = []) {
418
- return this.grid_avg_on(grid, fields);
419
- }
420
-
421
- /**
422
- * Average the column values together
423
- @alias module:Jqgrid_utils
424
- @param {object} - Grid Object (required)
425
- @param {array} - Column/Field Names to where the average of each column should be calculated
426
- @example
427
- var jqu = new Jqgrid_utils({page:page});
428
-
429
- gridComplete: function()
430
- {
431
- jqu._grid_avg_on(this, ['diff_plan_to_actual', 'days_early', 'days_late']);
432
- },
433
-
434
-
435
- */
436
-
437
- async grid_avg_on(grid, fields = []) {
438
- let $self = jQuery(grid);
439
- let rows = $self.jqGrid("getGridParam", "data");
440
- let count = 0;
441
- let footer = {
442
- invdate: "Total",
443
- };
444
- for (let i in fields) {
445
- let sum = 0;
446
- for (let r in rows) {
447
- if (rows[r].hasOwnProperty(fields[i])) {
448
- let val = rows[r][fields[i]];
449
- if (typeof val === "string") {
450
- if (is_digit(val)) {
451
- val = parseFloat(val);
452
- }
453
- }
454
- sum += val;
455
- count++;
456
- }
457
- }
458
- sum = sum / count;
459
- if (sum != Math.floor(sum)) {
460
- sum = sum.toFixed(2);
461
- }
462
- footer[fields[i]] = sum;
463
- }
464
- $self.jqGrid("footerData", "set", footer);
465
- return footer;
466
- }
467
-
468
- /**
469
- * Syncron Alias grid_percent_on
470
- @alias module:Jqgrid_utils
471
- */
472
- _grid_percent_on(grid, obj) {
473
- return grid_percent_on(grid, obj);
474
- }
475
-
476
- /**
477
- * Percent the columns values together
478
- @alias module:Jqgrid_utils
479
- @param {object} - Grid Object (required)
480
- @param {string} - Column/Field Name to sum
481
- @example
482
- var jqu = new Jqgrid_utils({page:page});
483
- gridComplete: function () {
484
- jqu._jqu._grid_sum_on(this, [
485
- "qty_icollect",
486
- "qty_ordered",
487
- "need_for_qty_ordered",
488
- "wait_icollect",
489
- ]);
490
- },
491
- */
492
- async grid_percent_on(grid, obj) {
493
- let $self = jQuery(grid);
494
- let rows = $self.jqGrid("getGridParam", "data");
495
- let footer_sum = {};
496
- let id = obj["id"] ? obj["id"] : "invate";
497
- footer[id] = "Total";
498
- let total = obj["total"];
499
- let sums = JSON.parse(JSON.stringify(obj["percent"]));
500
- sums.push(total);
501
- for (let i in sums) {
502
- let field = sums[i];
503
- let sum = 0;
504
- let _rows = 0;
505
- for (let r in rows) {
506
- if (rows[r].hasOwnProperty(field)) {
507
- let val = rows[r][field];
508
- if (typeof val === "string") {
509
- if (is_digit(val)) {
510
- val = parseFloat(val);
511
- sum += val;
512
- _rows++;
513
- }
514
- } else {
515
- sum += val;
516
- _rows++;
517
- }
518
- }
519
- }
520
- footer_sum[field] = sum;
521
- }
522
-
523
- for (let i in sums) {
524
- let field = sums[i];
525
- let percent = footer_sum[field] / (footer_sum[total] / 100);
526
- percent = percent.toFixed(2);
527
- footer[field] = percent + "%";
528
- }
529
- $self.jqGrid("footerData", "set", footer);
530
- }
531
-
532
- /**
533
- * Takes the updated columns data and send it to your API post server
534
- * loadComplete: async function() for the old record needs to be called, see example !
535
- @alias module:Jqgrid_utils
536
- @param {object} - Grid Object (required)
537
- @param {string} - API URL like https://foo.com (required)
538
- @param {array} - id list, ids from the column header (required)
539
- @param {object} - settings - extra key:value to send to your server
540
-
541
- @example
542
- var jqu = new Jqgrid_utils({page:page});
543
-
544
- ....},
545
- loadComplete: async function()
546
- {
547
- $grid.jqGrid('setGridParam',{record_data:$grid.jqGrid("getGridParam").data});
548
- },
549
- afterSetRow: async function(row)
550
- {
551
- const _api = await get_api_url('sapir');
552
- const api = _api + '/column2';
553
- let info = {"msg":"failed"};
554
- var jqu = new Jqgrid_utils();
555
- info = await jqu.update_row_to_api($grid, api,['id'],row,{server : '232',db : 'sl_h',table : 'kpi',});
556
- for(let i in info)
557
- {
558
- log.info(info[i]);
559
- }
560
- },
561
- */
562
-
563
- async update_row_to_api(_self, api = "", _ids = ["id"], row = {}, data) {
564
- let self = this;
565
- let infos = [];
566
- let ids = {};
567
- let values = {};
568
- let changed = {};
569
- const rd = _self.jqGrid("getGridParam", "record_data");
570
-
571
- if (
572
- api != "" &&
573
- Object.keys(row).length > 0 &&
574
- row.inputData.oper == "edit"
575
- ) {
576
- for (let i in rd) {
577
- if (rd[i]["id"] === row.rowid) {
578
- for (let ii in _ids) {
579
- if (rd[i].hasOwnProperty(_ids[ii])) {
580
- ids[_ids[ii]] = rd[i][_ids[ii]];
581
- }
582
- }
583
-
584
- for (let iii in row.inputData) {
585
- if (iii != "oper") {
586
- if (Object.keys(ids).indexOf(iii) < 0) {
587
- //console.log(iii);
588
- //console.log(row.inputData[iii]);
589
- //console.log(rd[i][iii]);
590
- if (row.inputData[iii] != rd[i][iii]) {
591
- changed[iii] = row.inputData[iii];
592
- }
593
- }
594
- }
595
- }
596
- }
597
- }
598
-
599
- for (let i in changed) {
600
- if (Object.keys(ids).indexOf(i) < 0 && i != "oper") {
601
- const col_name = i;
602
- let col_value = {};
603
- col_value[col_name] = changed[i];
604
- data["ids"] = ids;
605
- data["values"] = col_value;
606
- data["operator"] = "edit";
607
- //console.log(data)
608
- const info = await self.post_json(api, JSON.stringify(data));
609
- infos.push(info);
610
- }
611
- }
612
- } else if (
613
- api != "" &&
614
- Object.keys(row).length > 0 &&
615
- row.inputData.oper == "add"
616
- ) {
617
- //console.log("...add");
618
- for (let i in row.inputData) {
619
- if (row.inputData[i] && i != "id" && i != "oper") {
620
- values[i] = row.inputData[i];
621
- }
622
- }
623
- data["ids"] = ids;
624
- data["values"] = values;
625
- data["operator"] = "add";
626
- //console.log(data);
627
- let info = await self.post_json(api, JSON.stringify(data));
628
- infos.push(info);
629
- }
630
-
631
- return infos;
632
- }
633
-
634
- /**
635
- * After Delete a Grid Row send to and DELETE REST Request
636
- * You need to define loadComplete and afterDelRow
637
- * The Grid data needs to be saved as record within loadComplete
638
- @alias module:Jqgrid_utils
639
- @param {object} - Grid Object (required)
640
- @param {string} - API URL like https://foo.com (required)
641
- @param {string} - the row id value from afterDelRow (required)
642
- @param {array} - id list, ids from the column header colmodel (required)
643
- @param {object} - settings - extra key:value to send to your server
644
- @example
645
-
646
- loadComplete: async function()
647
- {
648
- $grid.jqGrid('setGridParam',{record_data:$grid.jqGrid("getGridParam").data});
649
- },
650
- afterDelRow: async function(rowid)
651
- {
652
- const _api = await get_api_url('sapir');
653
- const api = _api + '/column2';
654
- let info = {"msg":"failed"};
655
- var jqu = new Jqgrid_utils();
656
-
657
- info = await jqu.delete_row_to_api($grid,api,rowid,['id'],{
658
- server : '232',
659
- db : 'sl_h',
660
- table : 'kpi',
661
- operator: 'delete',
662
- });
663
- log.info(JSON.parse(info).msg);
664
- },
665
-
666
-
667
-
668
-
669
-
670
- */
671
-
672
- async delete_row_to_api(_self, api = "", rowid, _ids = [], data = {}) {
673
- let info = { msg: "failed" };
674
- let self = this;
675
- let ids = [];
676
- let values = {};
677
- const rd = _self.jqGrid("getGridParam", "record_data");
678
- for (let i in rd) {
679
- if (rd[i]["id"] === rowid) {
680
- for (let ii in _ids) {
681
- if (rd[i].hasOwnProperty(_ids[ii])) {
682
- values[_ids[ii]] = rd[i][_ids[ii]];
683
- ids.push(_ids[ii]);
684
- }
685
- }
686
- break;
687
- }
688
- }
689
-
690
- if (api != "" && Object.keys(values).length == ids.length) {
691
- data["ids"] = ids;
692
- data["values"] = values;
693
- //console.log(data);
694
- info = await self.adelete_api(api, JSON.stringify(data));
695
- }
696
- return info;
697
- }
698
-
699
- /**
700
- *Append and sperator based link column to the end of a row
701
- @alias module:Jqgrid_utils
702
- @param {object} - col_model of the grid
703
- @param {string} - URL string
704
- @param {string} - field value - the visible text of the anchor
705
- @param {object} - base row key value - like {"name":'wiki','label':"Wiki"}
706
- @param {string} - URL Attributes
707
- @param {object} - keys and fields value to use
708
- @example
709
- var jqu = new Jqgrid_utils();
710
- col_model = await jqu.append_seperator_link_column(col_model, 'http://wiki.foo.com/index.php' ,'Wiki',{"name":'wiki','label':"Wiki","width":"65px","align":"center"} ,'target="_blank"',{"report_central":"name"});
711
-
712
- */
713
-
714
- async append_seperator_link_column(
715
- col_model,
716
- url,
717
- field_value,
718
- base,
719
- attr = "",
720
- keys,
721
- ) {
722
- url = url + "/";
723
- let self = this;
724
- base["formatter"] = function (cell_val, obj) {
725
- let _cell_val = field_value;
726
- if (typeof keys === "object") {
727
- let pref = "";
728
- for (let i in keys) {
729
- let key = i;
730
- let v = keys[i];
731
- let key_val = obj.rowData[v];
732
- if (key_val) {
733
- if (key_val) {
734
- if (key != "") {
735
- pref += key + "" + "/" + encodeURIComponent(key_val) + "/";
736
- } else {
737
- pref += encodeURIComponent(key_val);
738
- }
739
- }
740
- }
741
- }
742
- if (pref) {
743
- if (pref.slice(-1) === "&" || pref.slice(-1) === "/") {
744
- pref = pref.slice(0, -1);
745
- }
746
- cell_val =
747
- "<a " + attr + 'href="' + url + pref + '"> ' + _cell_val + "</a>";
748
- }
749
- }
750
-
751
- return cell_val;
752
- };
753
-
754
- col_model.push(base);
755
-
756
- return col_model;
757
- }
758
-
759
- /**
760
- * add textarea
761
- @alias module:Jqgrid_utils
762
- @param {object} - edittype like
763
- @example
764
- let col_model = JSON.parse(await aget_api(url + "/model"));
765
- col_model = await jqu.add_edit(col_model, 'mon',{ edittype:'textarea', editoptions:{rows:6,cols:100} });
766
- see for other inputfields:
767
- http://www.trirand.com/blog/phpjqgrid/doc/_2v80w6oam.htm
768
- */
769
- async add_edit(col_model, edit_field, edittype, editoptions) {
770
- for (let i = 0; i < col_model.length; i++) {
771
- if (col_model[i]["name"] === edit_field) {
772
- Object.assign(col_model[i], edittype);
773
- Object.assign(col_model[i], editoptions);
774
- }
775
- }
776
- return col_model;
777
- }
778
-
779
- /**
780
- * add textarea
781
- @alias module:Jqgrid_utils
782
- @param {string} - edit_filed
783
- @param {string} - style of the textaread
784
- @example
785
- let col_model = JSON.parse(await aget_api(url + "/model"));
786
- col_model = await jqu.add_textarea(col_model, 'worker','style="width:100%;height:100px"');
787
- */
788
- async add_textarea(
789
- col_model,
790
- edit_field,
791
- style = 'style="width:100%;height:100px"',
792
- ) {
793
- for (let i = 0; i < col_model.length; i++) {
794
- if (col_model[i]["name"] === edit_field) {
795
- col_model[i]["formatter"] = function (cell_val) {
796
- const txt = "<textarea " + style + ">" + cell_val + "</textarea>";
797
- return txt;
798
- };
799
- }
800
- }
801
- return col_model;
802
- }
803
-
804
- /**
805
- * Get basic colModel data from raw data
806
- @alias module:Jqgrid_utils
807
- @param {array} - grid object
808
- @param {array} - raw data object from loadComplete
809
- @param {array} - list of columns to exclude (optional)
810
- @param {array} - existing colModel (optional)
811
- @returns {array} - col_model
812
- @example
813
- var jqu = new Jqgrid_utils();
814
- ,loadComplete: async function(data)
815
- {
816
- let col_model = jQuery(this).jqGrid('getGridParam',"colModel");
817
- const new_col_model= await update_col_model(this, data, ['id','cust_qty','waiting_supplier_orders','waiting_assemblies','pending_components','pending_customer_order',col_model);
818
- jQuery(this).jqGrid('setGridParam',{colModel:new_col_model});
819
- },
820
- */
821
- async get_col_model_from_data(obj, data, exclude = [], col_model = []) {
822
- let cols = [];
823
- for (let i in data) {
824
- const keys = Object.keys(data[i]);
825
- for (let ii in keys) {
826
- const key = keys[ii];
827
- cols.push(key);
828
- }
829
- }
830
- cols = cols.filter((item, pos) => cols.indexOf(item) === pos);
831
- let mcols = [];
832
- for (let i in col_model) {
833
- mcols.push(col_model[i]["name"]);
834
- }
835
-
836
- let diff = cols.filter((x) => !mcols.includes(x));
837
- const _exclude = new Set(exclude);
838
- diff = diff.filter((name) => {
839
- return !_exclude.has(name);
840
- });
841
- diff.sort();
842
-
843
- for (let x = 0; x < diff.length; x++) {
844
- col_model.push({ name: diff[x], label: diff[x] });
845
- }
846
- //console.log(col_model);
847
- return col_model;
848
- }
849
-
850
- /**
851
- * Replace a Binaery 0 or 1 to other given value
852
- @alias module:Jqgrid_utils
853
- @param {string} - cell value
854
- @param {string} - string replacement for 0
855
- @param {string} - string replacement for 1
856
- @example
857
- var jqu = new Jqgrid_utils();
858
- let _data = jqu.binery_replace(0,'zero','one');
859
- or for column formatter
860
- download_formatter:"var jqu = new Jqgrid_utils();jqu.binary_replace({0},'zero','one')"});
861
- */
862
- binary_replace(cell_value, a = "zero", b = "one") {
863
- let value = a;
864
- if (cell_value == 1 || cell_value == 0) {
865
- if (cell_value == 1) {
866
- value = b;
867
- }
868
- }
869
- return value;
870
- }
871
-
872
- /**
873
- * Convert a 112 date string to a DMY format with sepertaor - sync function
874
- @alias module:Jqgrid_utils
875
- @param {string} - date string
876
- @param {string} - seperator used
877
- @example
878
- var jqu = new Jqgrid_utils();
879
- let _data = jqu._date112_to_DMY('20220104','/');
880
- console.log(_data);
881
- */
882
- _date112_to_DMY(cell_value, seperator = "/") {
883
- let value = cell_value;
884
- cell_value = String(cell_value);
885
- if (
886
- cell_value.trim().length >= 8 &&
887
- cell_value.trim().indexOf(seperator) === -1
888
- ) {
889
- let a = [];
890
- a.push(cell_value.substr(6, 2));
891
- a.push(cell_value.substr(4, 2));
892
- a.push(cell_value.substr(0, 4));
893
- value = a.join(seperator);
894
- }
895
- return value;
896
- }
897
-
898
- /**
899
- * Convert a 112 date to a DMY format with sepertaor
900
- @alias module:Jqgrid_utils
901
- @param {object} - col_model of the grid
902
- @param {string} - name of the date 112 column what should get converted
903
- @param {string} - seperator used
904
- @example
905
- var jqu = new Jqgrid_utils();
906
- let _data = await jqu.date112_to_DMY(this,'field','/');
907
- console.log(_data);
908
- */
909
- async date112_to_DMY(col_model, edit_field, seperator = "/") {
910
- for (let i = 0; i < col_model.length; i++) {
911
- if (col_model[i]["name"] === edit_field) {
912
- col_model[i]["formatter"] = function (cell_value, o) {
913
- cell_value = String(cell_value);
914
- if (
915
- cell_value.trim().length >= 8 &&
916
- cell_value.trim().indexOf(seperator) === -1
917
- ) {
918
- cell_value = cell_value.toString();
919
- let value = cell_value;
920
- if (
921
- cell_value.length >= 8 &&
922
- cell_value.indexOf(seperator) === -1
923
- ) {
924
- let a = [];
925
- a.push(cell_value.substr(6, 2));
926
- a.push(cell_value.substr(4, 2));
927
- a.push(cell_value.substr(0, 4));
928
- value = a.join(seperator);
929
- }
930
- return value;
931
- } else {
932
- return cell_value;
933
- }
934
- };
935
- }
936
- }
937
- return col_model;
938
- }
939
-
940
- /**
941
- * Set col_model
942
- @alias module:Jqgrid_utils
943
- @param {array} - grid col_model
944
- @param {string} - string columns names what will be formatted
945
- @param {string} - key of the model
946
- @param {string} - value of the model
947
-
948
- @example
949
- var jqu = new Jqgrid_utils();
950
- col_model = await jqu.set_col_model(
951
- col_model,
952
- "to_close",
953
- "editable",
954
- true,
955
- );
956
-
957
- */
958
-
959
- async set_col_model(col_model, edit_field, key, value) {
960
- for (let i = 0; i < col_model.length; i++) {
961
- if (col_model[i]["name"] === edit_field) {
962
- col_model[i][key] = value;
963
- }
964
- }
965
- return col_model;
966
- }
967
-
968
- /**
969
- * Add Formatter
970
- @alias module:Jqgrid_utils
971
- @param {array} - grid col_model
972
- @param {string} - string columns names what will be formatted
973
- @param {object} - formatter object like { formatter: "select", formatoptions: {value: "1:ok;0:fail", defaultValue: "1" }}
974
- @example
975
- var jqu = new Jqgrid_utils();
976
- col_model = await jqu.add_formatter(col_model,'select',{ formatter: "select", formatoptions: {value: "1:ok;0:fail", defaultValue: "1" }})
977
- */
978
-
979
- async add_formatter(col_model, edit_field, formatter) {
980
- for (let i = 0; i < col_model.length; i++) {
981
- if (col_model[i]["name"] === edit_field) {
982
- if (
983
- formatter.hasOwnProperty("formatter") &&
984
- formatter.hasOwnProperty("formatoptions")
985
- ) {
986
- col_model[i]["formatter"] = formatter["formatter"];
987
- col_model[i]["formatoptions"] = formatter["formatoptions"];
988
- col_model[i]["edittype"] = formatter["formatter"];
989
- col_model[i]["editoptions"] = formatter["formatoptions"];
990
- }
991
- }
992
- }
993
- return col_model;
994
- }
995
-
996
- /**
997
- * Natural Sort Column
998
- @alias module:Jqgrid_utils
999
- @param {array} - grid col_model
1000
- @param {string} - string columns names for natural sorting
1001
- @returns {array} - col_model
1002
- @example
1003
- var jqu = new Jqgrid_utils();
1004
- col_model = await jqu.natural_sort(col_model,'colunmename');
1005
- */
1006
-
1007
- async natural_sort(col_model, column_name) {
1008
- for (let i = 0; i < col_model.length; i++) {
1009
- if (col_model[i]["name"] === column_name) {
1010
- col_model[i]["sortfunc"] = function (a, b, d) {
1011
- if (d === undefined) {
1012
- d = 1;
1013
- }
1014
- var re =
1015
- /(^-?[0-9]+(\.?[0-9]*)[df]?e?[0-9]?$|^0x[0-9a-f]+$|[0-9]+)/gi,
1016
- sre = /(^[ ]*|[ ]*$)/g,
1017
- dre =
1018
- /(^([\w ]+,?[\w ]+)?[\w ]+,?[\w ]+\d+:\d+(:\d+)?[\w ]?|^\d{1,4}[\/\-]\d{1,4}[\/\-]\d{1,4}|^\w+, \w+ \d+, \d{4})/,
1019
- hre = /^0x[0-9a-f]+$/i,
1020
- ore = /^0/,
1021
- i = function (s) {
1022
- return (self.insensitive && ("" + s).toLowerCase()) || "" + s;
1023
- },
1024
- // convert all to strings strip whitespace
1025
- x = i(a).replace(sre, "") || "",
1026
- y = i(b).replace(sre, "") || "",
1027
- // chunk/tokenize
1028
- xN = x
1029
- .replace(re, "\0$1\0")
1030
- .replace(/\0$/, "")
1031
- .replace(/^\0/, "")
1032
- .split("\0"),
1033
- yN = y
1034
- .replace(re, "\0$1\0")
1035
- .replace(/\0$/, "")
1036
- .replace(/^\0/, "")
1037
- .split("\0"),
1038
- // numeric, hex or date detection
1039
- xD =
1040
- parseInt(x.match(hre)) ||
1041
- (xN.length != 1 && x.match(dre) && Date.parse(x)),
1042
- yD =
1043
- parseInt(y.match(hre)) ||
1044
- (xD && y.match(dre) && Date.parse(y)) ||
1045
- null,
1046
- oFxNcL,
1047
- oFyNcL;
1048
- // first try and sort Hex codes or Dates
1049
- if (yD)
1050
- if (xD < yD) return -d;
1051
- else if (xD > yD) return d;
1052
- // natural sorting through split numeric strings and default strings
1053
- for (
1054
- var cLoc = 0, numS = Math.max(xN.length, yN.length);
1055
- cLoc < numS;
1056
- cLoc++
1057
- ) {
1058
- // find floats not starting with '0', string or 0 if not defined (Clint Priest)
1059
- oFxNcL =
1060
- (!(xN[cLoc] || "").match(ore) && parseFloat(xN[cLoc])) ||
1061
- xN[cLoc] ||
1062
- 0;
1063
- oFyNcL =
1064
- (!(yN[cLoc] || "").match(ore) && parseFloat(yN[cLoc])) ||
1065
- yN[cLoc] ||
1066
- 0;
1067
- // handle numeric vs string comparison - number < string - (Kyle Adams)
1068
- if (isNaN(oFxNcL) !== isNaN(oFyNcL)) {
1069
- return isNaN(oFxNcL) ? d : -d;
1070
- }
1071
- // rely on string comparison if different types - i.e. '02' < 2 != '02' < '2'
1072
- else if (typeof oFxNcL !== typeof oFyNcL) {
1073
- oFxNcL += "";
1074
- oFyNcL += "";
1075
- }
1076
- if (oFxNcL < oFyNcL) return -d;
1077
- if (oFxNcL > oFyNcL) return d;
1078
- }
1079
- return 0;
1080
- };
1081
- }
1082
- }
1083
- return col_model;
1084
- }
1085
-
1086
- /**
1087
- * Add HTML Formatter
1088
- @alias module:Jqgrid_utils
1089
- @param {array} - grid col_model
1090
- @param {string} - string columns names what will be converted to ok buttons
1091
- @param {string} - html tag code
1092
- @returns {array} - col_model
1093
- @example
1094
- var jqu = new Jqgrid_utils();
1095
- col_model = await jqu.add_html_formatter(col_model,'process',"<button tabindex='0' class='cellbtn' type='button'>Process</button>");
1096
- */
1097
-
1098
- async add_html_formatter(col_model, edit_field, html) {
1099
- for (let i = 0; i < col_model.length; i++) {
1100
- if (col_model[i]["name"] === edit_field) {
1101
- col_model[i]["formatter"] = function (cell_val, o) {
1102
- return html;
1103
- };
1104
- }
1105
- }
1106
- return col_model;
1107
- }
1108
-
1109
- /**
1110
- * Add an OK Button
1111
- @alias module:Jqgrid_utils
1112
- @param {array} - grid col_model
1113
- @param {array} - list of columns names what will be converted to ok buttons
1114
- @returns {array} - col_model
1115
- @example
1116
- var jqu = new Jqgrid_utils();
1117
- col_model = await jqu.add_ok_button(col_model, ['checked']);
1118
- */
1119
-
1120
- async add_ok_button(col_model, fields) {
1121
- let self = this;
1122
- for (let i = 0; i < col_model.length; i++) {
1123
- if (fields.indexOf(col_model[i]["name"]) > -1) {
1124
- col_model[i]["formatter"] = function (cell_val) {
1125
- if (cell_val != undefined) {
1126
- return self.__cell_format(cell_val, "format_ok");
1127
- } else {
1128
- return "";
1129
- }
1130
- };
1131
- }
1132
- }
1133
- return col_model;
1134
- }
1135
-
1136
- /**
1137
- * Get the filled cell data
1138
- @alias module:Jqgrid_utils
1139
- @param {object} - the grid object or its name
1140
- @param {array} - list of columns names what will be collected
1141
- @returns {array} - table array
1142
- @example
1143
- var jqu = new Jqgrid_utils();
1144
- col_model = await jqu.get_filled_cell_table_dat("#gridname","fieldname");
1145
-
1146
- */
1147
- async get_filled_cell_table_data(_grid, fields = []) {
1148
- let d = jQuery(_grid).jqGrid("getGridParam", "data");
1149
- let keys = fields;
1150
- let _data = [];
1151
- for (let i in d) {
1152
- if (d[i].hasOwnProperty("id")) {
1153
- let row = [d[i]["id"]];
1154
- for (let x in keys) {
1155
- if (d[i].hasOwnProperty(keys[x])) {
1156
- row.push(d[i][keys[x]]);
1157
- } else {
1158
- row.push("");
1159
- }
1160
- }
1161
- var f = row.filter(function (value, index, arr) {
1162
- return value !== "";
1163
- });
1164
- if (Object.keys(f).length > 1) {
1165
- _data.push(row);
1166
- }
1167
- }
1168
- }
1169
- return _data;
1170
- }
1171
-
1172
- /**
1173
- * Get the filled cell data
1174
- @alias module:Jqgrid_utils
1175
- @param {object} - the grid object or its name
1176
- @param {array} - list of columns names what will be collected
1177
- @returns {object} - json object of the colleted fields
1178
- @example
1179
- var jqu = new Jqgrid_utils();
1180
- let _data = await jqu.get_filled_cell_data(this,["P-","bulk","wholesale"]);
1181
- */
1182
-
1183
- async get_filled_cell_data(_grid, fields = []) {
1184
- let d = jQuery(_grid).jqGrid("getGridParam", "data");
1185
- let keys = fields;
1186
- let _data = [];
1187
- for (let i in d) {
1188
- if (d[i].hasOwnProperty("id")) {
1189
- let row = { id: d[i]["id"] };
1190
- for (let x in keys) {
1191
- if (d[i].hasOwnProperty(keys[x])) {
1192
- if (d[i][keys[x]] != "") {
1193
- row[keys[x]] = d[i][keys[x]];
1194
- }
1195
- }
1196
- }
1197
- if (Object.keys(row).length > 1) {
1198
- _data.push(row);
1199
- }
1200
- }
1201
- }
1202
- return _data;
1203
- }
1204
-
1205
- /**
1206
- * Add an URL from the data to a specific cell/column
1207
- @alias module:Jqgrid_utils
1208
- @param {object} - col_model of the grid
1209
- @param {string} - name of the column what should get convert to the url
1210
- @param {string} - the used url of the data
1211
- @returns {object} https://foo.bar.com/av0_code/bar
1212
- @example
1213
- var jqu = new Jqgrid_utils();
1214
- col_model = await jqu.set_link(col_model,'field_get_url','field_with_the_url','target="blank"');
1215
- console.log(_data);
1216
- */
1217
- async set_link(col_model, edit_field, url, attr = "") {
1218
- for (let i = 0; i < col_model.length; i++) {
1219
- if (col_model[i]["name"] === edit_field) {
1220
- col_model[i]["formatter"] = function (cell_val, o) {
1221
- return (
1222
- '<a class="gl" ' +
1223
- attr +
1224
- 'href="' +
1225
- o.rowData[url] +
1226
- '">' +
1227
- cell_val +
1228
- "</a>"
1229
- );
1230
- };
1231
- }
1232
- }
1233
- return col_model;
1234
- }
1235
-
1236
- /**
1237
- * Hide all columns execpt column
1238
- * @alias module:Jqgrid_utils
1239
- * @param {object} - col_model of the grid
1240
- * @param {array} - array of names to not to hide
1241
- * @returns {object} col_model
1242
- * @example
1243
- col_model = await jqu.hide_all_columns_except(col_model,['supplier','customer']);
1244
- */
1245
- async hide_all_columns_except(col_model, fields) {
1246
- for (let i = 0; i < col_model.length; i++) {
1247
- if (fields.indexOf(col_model[i]["name"]) > -1) {
1248
- col_model[i]["hidden"] = false;
1249
- } else {
1250
- col_model[i]["hidden"] = true;
1251
- }
1252
- }
1253
- return col_model;
1254
- }
1255
-
1256
- /**
1257
- * Hide a col_model column before load the grid
1258
- * @alias module:Jqgrid_utils
1259
- * @param {object} - col_model of the grid
1260
- * @param {string} - name of the column to hide
1261
- * @returns {object} col_model
1262
- * @example
1263
- col_model = await jqu.hide_column(col_model,'wholesale');
1264
- col_model = await jqu.hide_column(col_model,'wholesale_formula');
1265
- */
1266
- async hide_column(col_model, field) {
1267
- for (let i = 0; i < col_model.length; i++) {
1268
- if (col_model[i]["name"] === field) {
1269
- col_model[i]["hidden"] = true;
1270
- }
1271
- }
1272
- return col_model;
1273
- }
1274
-
1275
- /**
1276
- @alias module:Jqgrid_utils
1277
- @param {object} - gridobject;
1278
- @param {object} - grid data (optional);
1279
- @example
1280
- var jqu = new Jqgrid_utils();
1281
- loadComplete: function(){
1282
- jqu.grid_set_caption(this);
1283
- },
1284
- */
1285
-
1286
- s_grid_set_caption(_grid, data = []) {
1287
- this.grid_set_captionn(_grid, (data = []));
1288
- }
1289
-
1290
- /**
1291
- Adding the row count number to the caption
1292
- @alias module:Jqgrid_utils
1293
- @param {object} - gridobject;
1294
- @param {object} - grid data (optional);
1295
- @example
1296
- var jqu = new Jqgrid_utils();
1297
- loadComplete: function(){
1298
- await jqu.grid_set_caption(this);
1299
- },
1300
- */
1301
- async grid_set_caption(_grid, data = []) {
1302
- if (_grid) {
1303
- const grid = jQuery(_grid);
1304
- let count = 0;
1305
- if (data.length === 0) {
1306
- count = grid.jqGrid("getGridParam", "records");
1307
- } else {
1308
- count = data.length;
1309
- }
1310
- let caption = grid.jqGrid("getGridParam", "caption");
1311
- const reg = /\d.*x/;
1312
- const new_caption = caption.replace(reg, "");
1313
- grid.jqGrid("setCaption", new_caption + " " + count + "x");
1314
- }
1315
- }
1316
-
1317
- /**
1318
- @alias module:Jqgrid_utils
1319
- @param {object} - the col_model of the grid
1320
- @param {string} - the name of the page(optional)
1321
- @param {object} - the grid objec(optional)
1322
- @example
1323
- col_model = await jqu.resize_saved_cell_width(col_model);
1324
- */
1325
- s_resize_saved_cell_width(col_model, page = false, grid = false) {
1326
- this.grid_set_caption(col_model, page, grid);
1327
- }
1328
-
1329
- /**
1330
- @alias module:Jqgrid_utils
1331
- @param {object} - the col_model of the grid
1332
- @param {string} - the name of the page(optional)
1333
- @param {object} - the grid objec(optional)
1334
- @example
1335
- col_model = await jqu.resize_saved_cell_width(col_model);
1336
- */
1337
- async resize_saved_cell_width(col_model, page = false, grid = false) {
1338
- let key = page ? page : this.page;
1339
- key += grid ? "-" + grid + "-w-" : "-grid-w-";
1340
- for (let x = 0; x <= col_model.length; x++) {
1341
- if (col_model[x]) {
1342
- if (col_model[x]["name"]) {
1343
- const name = col_model[x]["name"];
1344
- const width = localStorage.getItem(key + name);
1345
- if (width) {
1346
- col_model[x]["width"] = width;
1347
- }
1348
- }
1349
- }
1350
- }
1351
- return col_model;
1352
- }
1353
-
1354
- /**
1355
- @alias module:Jqgrid_utils
1356
- @param {string} the width of the resized column
1357
- @param {string} column number what get resized
1358
- @param {string} not in use yet
1359
- @example
1360
- * var jqu = new Jqgrid_utils({page:'mypage'});
1361
- * resizeStop: jqu.resize_cell,
1362
- */
1363
- resize_cell(width, index, _page = false) {
1364
- const col_model = jQuery(this).jqGrid("getGridParam", "colModel");
1365
- if (col_model[index]) {
1366
- if (col_model[index]["name"]) {
1367
- const name = col_model[index]["name"];
1368
- const page = _page ? _page : localStorage.getItem("page");
1369
- const grid = this.id;
1370
- let key = page + "-" + grid + "-w-" + name;
1371
- localStorage.setItem(key, width);
1372
- const cat = localStorage.getItem(key);
1373
- }
1374
- }
1375
- }
1376
-
1377
- /**
1378
- * Upsert(insert or update) from the grid to an API
1379
- @alias module:Jqgrid_utils
1380
- @param {object} - row object
1381
- @param {string} - url of the API
1382
- @param {string} - data oject
1383
- @returns {object} {update: 'ok'} or {update: 'failed'}
1384
- @example
1385
- var jqu = new Jqgrid_utils();
1386
- afterSetRow: async function(row)
1387
- {
1388
- let r = await jqu.upsert_row(row, 'http://api.com',{'key':'value'});
1389
- console.log(r);
1390
- },
1391
- */
1392
- async upsert_row(row, url, req = {}) {
1393
- if (row.rowid.startsWith("jqg")) {
1394
- const r0 = await this.insert_row(row, url);
1395
- return r0;
1396
- } else {
1397
- const r1 = await this.update_row(row, url);
1398
- return r1;
1399
- }
1400
- }
1401
-
1402
- /**
1403
- * Insert from the grid to an API used by the upsert_row function
1404
- @alias module:Jqgrid_utils
1405
- @param {object} - row object
1406
- @param {string} - URL of the API
1407
- @returns {object} Object from the the API like {update: 'ok'} or {update: 'failed'}
1408
- @example
1409
- var jqu = new Jqgrid_utils();
1410
- afterSetRow: async function(row)
1411
- {
1412
- let r = await jqu.insert_row(row, 'http://api.com');
1413
- console.log(r);
1414
- },
1415
- */
1416
- async insert_row(row, url) {
1417
- let req = {};
1418
- let ret = "";
1419
- if (row.inputData.hasOwnProperty("id")) {
1420
- req["_id"] = "id";
1421
- req["_id_val"] = row.inputData["id"];
1422
- for (let i in row.inputData) {
1423
- req[i] = row.inputData[i];
1424
- }
1425
- delete req["id"];
1426
- delete req["oper"];
1427
- //console.log(req);
1428
- ret = await this.put_json(url, JSON.stringify(req));
1429
- }
1430
- return ret;
1431
- }
1432
-
1433
- /**
1434
- * Update from the grid to an API used by the upsert_row function
1435
- @alias module:Jqgrid_utils
1436
- @param {object} - row object
1437
- @param {string} - url of the API
1438
- @param {string} - data oject
1439
- @returns {object} Object from the the API like {update: 'ok'} or {update: 'failed'}
1440
- @example
1441
- var jqu = new Jqgrid_utils();
1442
- afterSetRow: async function(row)
1443
- {
1444
- let r = await jqu.update_row(row, 'http://api.com',{'key':value});
1445
- console.log(r);
1446
- },
1447
- */
1448
-
1449
- async update_row(row, url, req = {}) {
1450
- let ret = "";
1451
- {
1452
- if (!req["_id"]) {
1453
- req["_id"] = "id";
1454
- }
1455
- req["_id_val"] = row.inputData["id"];
1456
- for (let i in row.inputData) {
1457
- req[i] = row.inputData[i];
1458
- }
1459
- delete req["id"];
1460
- delete req["oper"];
1461
- ret = await this.post_json(url, JSON.stringify(req));
1462
- }
1463
- return ret;
1464
- }
1465
-
1466
- /**
1467
- * Delete from the grid to an API
1468
- @alias module:Jqgrid_utils
1469
- @param {string} - row id
1470
- @param {string} - url of the API
1471
- @returns {object} @returns {object} Object from the the API like {delete: 'ok'} or {delete: 'failed'}
1472
- @example
1473
- var jqu = new Jqgrid_utils();
1474
- afterDelRow: async function(row)
1475
- {
1476
- const r = await jqu.delete_row('id', 'http://api.com');
1477
- console.log(r + ' : ' + row + ' - from API');
1478
- },
1479
- */
1480
-
1481
- async delete_row(_id, url) {
1482
- let ret = "";
1483
- if (url.indexOf("?") > -1) {
1484
- url += "&_id=" + encodeURIComponent(unescape(_id));
1485
- } else {
1486
- url += "?_id=" + encodeURIComponent(unescape(_id));
1487
- }
1488
-
1489
- ret = JSON.parse(await this.adelete_api(url));
1490
- return ret["message"];
1491
- }
1492
-
1493
- /**
1494
- * Async Delete request used by function delete_row
1495
- @alias module:Jqgrid_utils
1496
- @param {string} - url of the API
1497
- @param {boalan} - header should be json type? default form type
1498
- @returns {object} @returns {object} Object from the the API like {delete: 'ok'} or {delete: 'failed'}
1499
- @example
1500
- var jqu = new Jqgrid_utils();
1501
- afterDelRow: async function(row)
1502
- {
1503
- ret = JSON.parse(await jqu.adelete_api(url));
1504
- },
1505
- */
1506
-
1507
- async adelete_api(url, json = false) {
1508
- let ctype = "application/x-www-form-urlencoded";
1509
- let body = null;
1510
- if (json) {
1511
- ctype = "application/json;charset=UTF-8";
1512
- body = json;
1513
- }
1514
- return new Promise((resolve, reject) => {
1515
- let xhr = new XMLHttpRequest();
1516
- xhr.open("DELETE", url);
1517
- xhr.setRequestHeader("Content-type", ctype);
1518
- xhr.onload = () => resolve(xhr.responseText);
1519
- xhr.onerror = () => reject(xhr.statusText);
1520
- xhr.send(body);
1521
- });
1522
- }
1523
-
1524
- /**
1525
- * Async Post request used by the update_row function
1526
- @alias module:Jqgrid_utils
1527
- @param {string} - url of the API
1528
- @param {object} - json object
1529
- @returns {object} @returns {object} Object from the the API like {update: 'ok'} or {update: 'failed'}
1530
- @example
1531
- var jqu = new Jqgrid_utils();
1532
- ret = JSON.parse(await jqu.post_json(url,{'key':value,'key2':'value'}));
1533
- */
1534
-
1535
- async post_json(url, data) {
1536
- return new Promise((resolve, reject) => {
1537
- let xhr = new XMLHttpRequest();
1538
- xhr.open("POST", url);
1539
- xhr.setRequestHeader("Content-type", "application/json");
1540
- xhr.onload = () => resolve(xhr.responseText);
1541
- xhr.onerror = () => reject(xhr.statusText);
1542
- xhr.send(data);
1543
- });
1544
- }
1545
-
1546
- /**
1547
- * Async Put request used by the insert_row function
1548
- @alias module:Jqgrid_utils
1549
- @param {string} - url of the API
1550
- @param {object} - json object
1551
- @returns {object} @returns {object} Object from the the API like {insert: 'ok'} or {insert: 'failed'}
1552
- @example
1553
- var jqu = new Jqgrid_utils();
1554
- ret = JSON.parse(await jqu.put_json(url,{'key':value,'key2':'value2'}));
1555
- */
1556
- async put_json(url, data) {
1557
- return new Promise((resolve, reject) => {
1558
- let xhr = new XMLHttpRequest();
1559
- xhr.open("PUT", url);
1560
- xhr.setRequestHeader("Content-type", "application/json");
1561
- xhr.onload = () => resolve(xhr.responseText);
1562
- xhr.onerror = () => reject(xhr.statusText);
1563
- xhr.send(data);
1564
- });
1565
- }
1566
-
1567
- /**
1568
- * Hide the del iconf rom the grid
1569
- @alias module:Jqgrid_utils
1570
- @example
1571
- var jqu = new Jqgrid_utils();
1572
- jqu.hide_del_icon();
1573
- */
1574
- s_hide_del_icon() {
1575
- hide_del_icon();
1576
- }
1577
-
1578
- /**
1579
- * Hide the del iconf rom the grid
1580
- @alias module:Jqgrid_utils
1581
- @example
1582
- var jqu = new Jqgrid_utils();
1583
- await jqu.hide_del_icon();
1584
- */
1585
- async hide_del_icon() {
1586
- jQuery(".ui-inline-del").each(function (index) {
1587
- jQuery(this).html("");
1588
- });
1589
- }
1590
-
1591
- /**
1592
- * Convert a cell into a link/url with data from another cell and spit the value by comma - CSV
1593
- @alias module:Jqgrid_utils
1594
- @param {object} - col_model of the grid
1595
- @param {string} - URL string
1596
- @param {string} - Column/Cell to use
1597
- @param {string} - URL Attributes
1598
- @param {object} - keys and fields value to use
1599
- @param {object} - format info
1600
- @param {string} - seperator of the cell value to split (default is comma)
1601
- @example
1602
- var jqu = new Jqgrid_utils();
1603
- col_model = await jqu.add_link_details_csv(col_model, host + '/html/report.html' , 'tags','target="_blank"',{"tags":"tags"},',');
1604
-
1605
- */
1606
- async add_link_details_csv(
1607
- col_model,
1608
- url,
1609
- edit_field,
1610
- attr = "",
1611
- keys,
1612
- format,
1613
- seperator = ",",
1614
- ) {
1615
- let self = this;
1616
- if (url.indexOf("?") > -1) {
1617
- url = url + "&";
1618
- } else {
1619
- url = url + "?";
1620
- }
1621
-
1622
- for (let i = 0; i < col_model.length; i++) {
1623
- if (col_model[i]["name"] === edit_field) {
1624
- col_model[i]["formatter"] = function (cell_val, obj) {
1625
- let key_val = cell_val;
1626
- const _cell_val = self.__cell_format(cell_val, format);
1627
- const a = _cell_val.split(seperator);
1628
- let cell_value = "";
1629
- for (let x in a) {
1630
- const x_value = a[x].trim();
1631
- if (x_value) {
1632
- if (typeof keys === "object") {
1633
- let pref = "";
1634
- for (let ii in keys) {
1635
- let key = ii;
1636
- let v = keys[ii];
1637
- key_val = obj.rowData[v];
1638
- if (key_val) {
1639
- if (key.indexOf("=") !== -1) {
1640
- pref =
1641
- pref +
1642
- "" +
1643
- key +
1644
- "" +
1645
- encodeURIComponent(x_value) +
1646
- "&";
1647
- } else {
1648
- pref =
1649
- pref +
1650
- "" +
1651
- key +
1652
- "=" +
1653
- encodeURIComponent(x_value) +
1654
- "&";
1655
- }
1656
- }
1657
- }
1658
- if (pref.slice(-1) === "&") {
1659
- pref = pref.slice(0, -1);
1660
- }
1661
- cell_value +=
1662
- "<a " +
1663
- attr +
1664
- 'href="' +
1665
- url +
1666
- pref +
1667
- '"> ' +
1668
- x_value +
1669
- "</a>" +
1670
- seperator +
1671
- " ";
1672
- }
1673
- }
1674
- cell_val = cell_value.trim();
1675
- if (cell_val.slice(-1) === seperator) {
1676
- //remove last seperator
1677
- cell_val = cell_val.slice(0, -1);
1678
- }
1679
- }
1680
-
1681
- if (cell_val) {
1682
- return cell_val;
1683
- } else {
1684
- return _cell_val;
1685
- }
1686
- };
1687
- }
1688
- }
1689
-
1690
- return col_model;
1691
- }
1692
-
1693
- /**
1694
- * Compare 2 columns and give them a style class when they have different content
1695
- * http://www.trirand.com/jqgridwiki/doku.php?id=wiki:methods
1696
- @alias module:Jqgrid_utils
1697
- @param {object} - grid object
1698
- @param {string} - first column
1699
- @param {string} - second column
1700
- @param {string} - css class name
1701
- @example
1702
- loadComplete: async function()
1703
- {
1704
- await jqu.compare(this,'first_column','second_column','redlight');
1705
- }
1706
-
1707
- */
1708
- async compare(obj, column1, column2, css_class) {
1709
- const rows = jQuery(obj).jqGrid("getGridParam", "data");
1710
- for (let i in rows) {
1711
- if (rows[i][column1] != rows[i][column2]) {
1712
- jQuery(obj).jqGrid("setCell", rows[i]["id"], column1, "", css_class);
1713
- jQuery(obj).jqGrid("setCell", rows[i]["id"], column2, "", css_class);
1714
- }
1715
- }
1716
- }
1717
-
1718
- /**
1719
- * Compare 2 columns for smaller and give them a style class
1720
- * http://www.trirand.com/jqgridwiki/doku.php?id=wiki:methods
1721
- @alias module:Jqgrid_utils
1722
- @param {object} - grid object
1723
- @param {string} - first column
1724
- @param {string} - second column
1725
- @param {string} - css class name
1726
- @example
1727
- loadComplete: async function()
1728
- {
1729
- await jqu.compare(this,'first_column','second_column','redlight');
1730
- }
1731
-
1732
- */
1733
- async compare_smaller(obj, column1, column2, css_class) {
1734
- const rows = jQuery(obj).jqGrid("getGridParam", "data");
1735
- for (let i in rows) {
1736
- if (rows[i][column1] < rows[i][column2]) {
1737
- jQuery(obj).jqGrid("setCell", rows[i]["id"], column1, "", css_class);
1738
- jQuery(obj).jqGrid("setCell", rows[i]["id"], column2, "", css_class);
1739
- }
1740
- }
1741
- }
1742
-
1743
- /**
1744
- * Compare 2 columns for bigger and give them a style class
1745
- * http://www.trirand.com/jqgridwiki/doku.php?id=wiki:methods
1746
- @alias module:Jqgrid_utils
1747
- @param {object} - grid object
1748
- @param {string} - first column
1749
- @param {string} - second column
1750
- @param {string} - css class name
1751
- @example
1752
- loadComplete: async function()
1753
- {
1754
- await jqu.compare(this,'first_column','second_column','redlight');
1755
- }
1756
-
1757
- */
1758
- async compare_bigger(obj, column1, column2, css_class) {
1759
- const rows = jQuery(obj).jqGrid("getGridParam", "data");
1760
- for (let i in rows) {
1761
- if (rows[i][column1] > rows[i][column2]) {
1762
- jQuery(obj).jqGrid("setCell", rows[i]["id"], column1, "", css_class);
1763
- jQuery(obj).jqGrid("setCell", rows[i]["id"], column2, "", css_class);
1764
- }
1765
- }
1766
- }
1767
-
1768
- /**
1769
- * Set styles to individual cells, what are defined in a dedicated column
1770
- @alias module:Jqgrid_utils
1771
- @param {object} - grid object
1772
- @param {string} - name of the column what includes the style values what need to be in a strinify json format
1773
- @example
1774
- var jqu = new Jqgrid_utils();
1775
- loadComplete: async function() {
1776
- await jqu.set_styles(this);
1777
- },
1778
- */
1779
- async set_styles(obj, style_column = "styles") {
1780
- const rows = jQuery(obj).jqGrid("getGridParam", "data");
1781
-
1782
- for (let i in rows) {
1783
- if (rows[i][style_column]) {
1784
- const styles = JSON.parse(rows[i][style_column]);
1785
- for (let ii in styles) {
1786
- const rowid = rows[i]["id"];
1787
- const name = ii;
1788
- if (rows[i].hasOwnProperty(name)) {
1789
- jQuery(obj).jqGrid("setCell", rowid, name, "", styles[ii]);
1790
- }
1791
- }
1792
- }
1793
- }
1794
- }
1795
-
1796
- /**
1797
- * Set a class to a row, what must be defined in a dedicated column called row.class
1798
- * Once the grid is loaded, the functions adds extra class to the row element
1799
- @alias module:Jqgrid_utils
1800
- @param {object} - grid id like #grid
1801
- @example
1802
- var jqu = new Jqgrid_utils();
1803
- loadComplete: async function() {
1804
- await jqu.set_classes("#grid");
1805
- },
1806
- */
1807
- async set_classes(grid_id, field) {
1808
- const rows = jQuery(grid_id).getDataIDs();
1809
- for (var i = 0; i < rows.length; i = i + 1) {
1810
- const row = jQuery(grid_id).getRowData(rows[i]);
1811
- var e = jQuery("#" + rows[i], jQuery(grid_id));
1812
- e.removeClass("ui-widget-content");
1813
- e.addClass(row.class);
1814
- }
1815
- }
1816
-
1817
- /**
1818
- * Convert a cell into a link/url with data from another cell
1819
- @alias module:Jqgrid_utils
1820
- @param {object} - col_model of the grid
1821
- @param {string} - URL string
1822
- @param {string} - Column/Cell to use
1823
- @param {string} - URL Attributes
1824
- @param {object} - keys and fields value to use
1825
- @example
1826
- var jqu = new Jqgrid_utils();
1827
- col_model = await jqu.add_link_details(col_model,'http://foo.bar' , 'style','target="_blank"',{'key':'style'});
1828
- col_model = await jqu.add_link_details(col_model, host + '/html/table_size.html' , 'database','target="_blank"',{"database":"database","server":"server"});
1829
- */
1830
- async add_link_details(col_model, url, edit_field, attr = "", keys, format) {
1831
- let self = this;
1832
- if (url.indexOf("?") > -1) {
1833
- url = url + "&";
1834
- } else {
1835
- url = url + "?";
1836
- }
1837
-
1838
- for (let i = 0; i < col_model.length; i++) {
1839
- if (col_model[i]["name"] === edit_field) {
1840
- col_model[i]["formatter"] = function (cell_val, obj) {
1841
- cell_val = String(cell_val);
1842
- let key_val = "";
1843
- if (cell_val) {
1844
- key_val = cell_val;
1845
- }
1846
- let t = "";
1847
- if (cell_val) {
1848
- t = cell_val.toString();
1849
- }
1850
-
1851
- if (typeof keys === "object") {
1852
- let pref = "";
1853
- for (let ii in keys) {
1854
- let key = ii;
1855
- let v = keys[ii];
1856
- key_val = obj.rowData[v];
1857
- if (key_val) {
1858
- if (key_val) {
1859
- if (key.indexOf("=") !== -1) {
1860
- pref =
1861
- pref + "" + key + "" + encodeURIComponent(key_val) + "&";
1862
- } else {
1863
- pref =
1864
- pref + "" + key + "=" + encodeURIComponent(key_val) + "&";
1865
- }
1866
- }
1867
- }
1868
- }
1869
- if (pref) {
1870
- if (pref.slice(-1) === "&") {
1871
- pref = pref.slice(0, -1);
1872
- }
1873
- const _cell_val = self.__cell_format(cell_val, format);
1874
-
1875
- if (t != "" && _cell_val && t) {
1876
- cell_val =
1877
- "<a " +
1878
- attr +
1879
- 'href="' +
1880
- url +
1881
- pref +
1882
- '"> ' +
1883
- _cell_val +
1884
- "</a>";
1885
- } else {
1886
- cell_val = "";
1887
- }
1888
- }
1889
- }
1890
- if (t) {
1891
- return cell_val;
1892
- } else {
1893
- return "";
1894
- }
1895
- };
1896
- }
1897
- }
1898
-
1899
- return col_model;
1900
- }
1901
-
1902
- /**
1903
- * Convert a cell into seperated based link/url like https://foo.bar.com/field/value/field/value
1904
- @alias module:Jqgrid_utils
1905
- @param {object} - col_model of the grid
1906
- @param {string} - URL string
1907
- @param {string} - Column/Cell to use
1908
- @param {string} - URL Attributes
1909
- @param {object} - keys and fields value to use
1910
- @example
1911
- var jqu = new Jqgrid_utils();
1912
- col_model = await jqu.add_link_details_separator(col_model, url1 , 'style','target="_blank"',{"pricelist":"pricelist","style":"style"});
1913
- col_model = await jqu.add_link_details_separator(col_model, 'https://foo.com' , 'target_column','target="_blank"',{"mykey":"myval"});
1914
- */
1915
- async add_link_details_separator(
1916
- col_model,
1917
- url,
1918
- edit_field,
1919
- attr = "",
1920
- keys,
1921
- format,
1922
- ) {
1923
- url = url + "/";
1924
- let self = this;
1925
- for (let i = 0; i < col_model.length; i++) {
1926
- if (col_model[i]["name"] === edit_field) {
1927
- col_model[i]["formatter"] = function (cell_val, obj) {
1928
- let key_val = cell_val;
1929
-
1930
- if (typeof keys === "object") {
1931
- let pref = "";
1932
- for (let ii in keys) {
1933
- let key = ii;
1934
- let v = keys[ii];
1935
- key_val = obj.rowData[v];
1936
- if (key_val) {
1937
- if (key_val) {
1938
- if (key != "") {
1939
- pref += key + "" + "/" + encodeURIComponent(key_val) + "/";
1940
- } else {
1941
- pref += encodeURIComponent(key_val);
1942
- }
1943
- }
1944
- }
1945
- }
1946
- if (pref) {
1947
- if (pref.slice(-1) === "&" || pref.slice(-1) === "/") {
1948
- pref = pref.slice(0, -1);
1949
- }
1950
- const _cell_val = self.__cell_format(cell_val, format);
1951
- cell_val =
1952
- "<a " +
1953
- attr +
1954
- 'href="' +
1955
- url +
1956
- pref +
1957
- '"> ' +
1958
- _cell_val +
1959
- "</a>";
1960
- }
1961
- }
1962
-
1963
- return cell_val;
1964
- };
1965
- }
1966
- }
1967
-
1968
- return col_model;
1969
- }
1970
-
1971
- /**
1972
- * Convert a cell into seperated based link/url include parameter based url like https://foo.bar.com/field.html?k=v
1973
- @alias module:Jqgrid_utils
1974
- @param {object} - col_model of the grid
1975
- @param {string} - URL string
1976
- @param {array} - array of dict
1977
- @param {string} - URL Attributes
1978
- @example
1979
- var jqu = new Jqgrid_utils();
1980
- col_model = await jqu.add_link_separator(col_model, host + '/html' , 'style',[
1981
- {
1982
- 'field':'pricelist',
1983
- 'extension':'.html',
1984
- 'fields':{'style':'style'}
1985
- }
1986
- ]);
1987
- //other example
1988
- col_model = await jqu.add_link_separator(col_model, 'https://wiki.salamander-jewelry.net/index.php/grid_loss' , 'e',[{'field':'e'}],'target="_blank"');
1989
-
1990
- */
1991
- async add_link_separator(col_model, url, edit_field, fields, attr = "") {
1992
- url = url + "/";
1993
- let self = this;
1994
- for (let i = 0; i < col_model.length; i++) {
1995
- if (col_model[i]["name"] === edit_field) {
1996
- col_model[i]["formatter"] = function (cell_val, obj) {
1997
- let key_val = cell_val;
1998
- let pref = "";
1999
- for (let x in fields) {
2000
- for (let xx in fields[x]) {
2001
- if (xx === "field") {
2002
- let field_value = obj.rowData[fields[x][xx]];
2003
- pref += field_value;
2004
- }
2005
- if (xx === "extension") {
2006
- pref += fields[x][xx];
2007
- }
2008
- if (xx === "fields") {
2009
- pref += "?";
2010
- for (let key in fields[x][xx]) {
2011
- let val = obj.rowData[fields[x][xx][key]];
2012
- pref = pref + "" + key + "=" + encodeURIComponent(val) + "&";
2013
- }
2014
- }
2015
- }
2016
- }
2017
- if (pref) {
2018
- if (pref.slice(-1) === "&" || pref.slice(-1) === "/") {
2019
- pref = pref.slice(0, -1);
2020
- }
2021
- cell_val =
2022
- "<a " + attr + 'href="' + url + pref + '"> ' + cell_val + "</a>";
2023
- }
2024
-
2025
- return cell_val;
2026
- };
2027
- }
2028
- }
2029
- return col_model;
2030
- }
2031
-
2032
- /**
2033
- * Private Function
2034
- @alias module:Jqgrid_utils
2035
- @param {string} - number to add comma
2036
- */
2037
- _format_number_with_commas(number) {
2038
- const parts = number.toString().split(".");
2039
- parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
2040
- return parts.join(".");
2041
- }
2042
-
2043
- /**
2044
- * Private Function
2045
- @alias module:Jqgrid_utils
2046
- @param {object} - cell_value
2047
- @param {string} - format_ok or $ sign
2048
- */
2049
- __cell_format(cell_value, format) {
2050
- if (format == "format_ok") {
2051
- if (cell_value == 0 || cell_value === "fail") {
2052
- cell_value =
2053
- '<i data-check="failed" class="fa fa-times-circle" aria-hidden="true" style="color:#ff0000;"></i>';
2054
- } else {
2055
- cell_value =
2056
- '<i data-check="ok" class="fa fa-check-circle" aria-hidden="true" style="color:#008000;"></i>';
2057
- }
2058
- } else if (format == "$") {
2059
- if (cell_value) {
2060
- const number = this._format_number_with_commas(cell_value);
2061
- cell_value = format + "" + number;
2062
- }
2063
- }
2064
-
2065
- return cell_value;
2066
- }
2067
-
2068
- /**
2069
- @alias module:Jqgrid_utils
2070
- @param {string} - row_id
2071
- @param {string} - data id
2072
- @param {string} - url to request
2073
- @param {object} - col_model for the table
2074
- @param {string} - Add to the caption of the subgrid
2075
- @example
2076
- subGrid: true,
2077
- ,subGridRowExpanded: async function(_id, id) {
2078
- let data_url2 = api + '/process_locations?f=data&process=';
2079
- let col_model_url2 = api + '/process_locations?f=col_model';
2080
- let col_model2 = JSON.parse(await vwu.aget_api(col_model_url2));
2081
- await jqu.subgrid(_id, id, data_url2, col_model2,'Locations for Process');
2082
-
2083
- let data_url = api + '/process_styles?f=data&process=';
2084
- let col_model_url = api + '/process_styles?f=col_model';
2085
- let col_model = JSON.parse(await vwu.aget_api(col_model_url));
2086
- await jqu.subgrid(_id, id, data_url, col_model,'Styles for Process');
2087
- },
2088
-
2089
- or
2090
-
2091
- subGrid: true,
2092
- subGridRowExpanded: async function(_id, id) {
2093
- let row_data = jQuery(this).jqGrid ('getRowData', id);
2094
- let param={f:'data','style':row_data['style'],pricelist:'P-TENENGR1'};
2095
- let data_url = api + '/order_ln';
2096
- data_url = await add_parameters(data_url, param);
2097
- let col_model_url2 = api + '/order_ln?f=col_model';
2098
- let col_model2 = JSON.parse(await vwu.aget_api(col_model_url2));
2099
- await jqu.subgrid(_id, false, data_url, col_model2,'Order Lines for ' + row_data['style']);
2100
- },
2101
-
2102
- */
2103
- async subgrid(_id, id, url, col_model, caption = "") {
2104
- caption = caption != "" ? caption + " " : "";
2105
- if (id) {
2106
- url += id;
2107
- } else {
2108
- id = "";
2109
- }
2110
- let $s1 = jQuery(
2111
- "<table style='margin: 5px 0' class='" + _id + "_t'></table>",
2112
- );
2113
- $s1.appendTo("#" + jQuery.jgrid.jqID(_id));
2114
- $s1.jqGrid({
2115
- caption: caption + id,
2116
- colModel: col_model,
2117
- datatype: "json",
2118
- url: url,
2119
- gridview: true,
2120
- rownumbers: true,
2121
- autoencode: true,
2122
- sortname: "c1",
2123
- sortorder: "desc",
2124
- });
2125
- }
2126
-
2127
- /**
2128
- @alias module:Jqgrid_utils
2129
- @param {object} - col_model for the grid
2130
- @param {string} - field what include the image/picture href path like http://mypicture.png
2131
- @param {int} - size of the picture
2132
- @param {bolen} - image path should be a link
2133
- @example
2134
- col_model = await jqu.add_image(col_model, image_field, 60, false);
2135
- */
2136
- async add_image(col_model, edit_field, size, link = false) {
2137
- if (size === undefined) {
2138
- size = 60;
2139
- }
2140
- for (let i = 0; i < col_model.length; i++) {
2141
- if (col_model[i]["name"] === edit_field) {
2142
- col_model[i]["picture"] = true;
2143
- col_model[i]["width"] = size;
2144
- col_model[i]["height"] = size;
2145
- col_model[i]["formatter"] = function (cell_val) {
2146
- const cell_val2 = cell_val.toLowerCase();
2147
-
2148
- if (
2149
- cell_val2.startsWith("https://", 0) ||
2150
- cell_val2.startsWith("http://", 0)
2151
- ) {
2152
- if (
2153
- cell_val2.includes(".png") ||
2154
- cell_val2.includes(".jpg") ||
2155
- cell_val2.includes(".jpeg") ||
2156
- cell_val2.includes(".gif") ||
2157
- cell_val2.includes(".svg") ||
2158
- cell_val2.includes(".svgz") ||
2159
- cell_val2.includes(".webp")
2160
- ) {
2161
- if (link) {
2162
- return (
2163
- '<a target="blank" href="' +
2164
- cell_val +
2165
- '"><img src="' +
2166
- cell_val +
2167
- '" alt="my image" width="' +
2168
- size +
2169
- '" /></a>'
2170
- );
2171
- } else {
2172
- return (
2173
- '<img src="' +
2174
- cell_val +
2175
- '" alt="my image" width="' +
2176
- size +
2177
- '" />'
2178
- );
2179
- }
2180
- }
2181
- }
2182
- return cell_val;
2183
- };
2184
- }
2185
- }
2186
- return col_model;
2187
- }
2188
-
2189
- /**
2190
- * Add a filter to the website beside the grid
2191
- @alias module:Jqgrid_utils
2192
- @param {object} - grid object or grid string name
2193
- @param {object} - the grid data object
2194
- @param {object} - a dict with a array what should be filterd by the grid
2195
- @param {string} - id name of the DOM oject where the filter should be appened
2196
- @example
2197
- var jqu = new Jqgrid_utils();
2198
- var run_me_once = true;
2199
- gridComplete: async function(){
2200
- if(run_me_once)
2201
- {
2202
- await jqu.set_filter(this, data, {material:[],section:[]}, '#filter');
2203
- run_me_once = false;
2204
- }
2205
- },
2206
- */
2207
- async set_filter(grid, data, fx, append_to = "#filter") {
2208
- jQuery(grid).jqGrid("setGridParam", { fdata: data });
2209
- let f = document.querySelector(append_to);
2210
- for (const i in data) {
2211
- for (let x in fx) {
2212
- fx[x].push(data[i][x]);
2213
- }
2214
- }
2215
-
2216
- for (let x in fx) {
2217
- fx[x] = fx[x].filter((val, ind, arr) => arr.indexOf(val) === ind);
2218
- fx[x].sort();
2219
- }
2220
-
2221
- for (let x in fx) {
2222
- let ul = document.createElement("ul");
2223
- let lh = document.createElement("lh");
2224
- lh.innerHTML = x;
2225
- ul.appendChild(lh);
2226
- for (let i in fx[x]) {
2227
- let li = document.createElement("li");
2228
- let l = document.createElement("label");
2229
- l.innerHTML = fx[x][i];
2230
- let c = document.createElement("input");
2231
- c.setAttribute("type", "checkbox");
2232
- c.setAttribute("class", x);
2233
- c.setAttribute("id", x + "_" + fx[x][i]);
2234
- l.setAttribute("for", x + "_" + fx[x][i]);
2235
- c.value = fx[x][i];
2236
- c.onchange = async () => {
2237
- await this._filter(grid, fx);
2238
- };
2239
- li.appendChild(l);
2240
- li.appendChild(c);
2241
- ul.appendChild(li);
2242
- }
2243
- f.appendChild(ul);
2244
- }
2245
- }
2246
-
2247
- /**
2248
- * private function of set_filter
2249
- @alias module:Jqgrid_utils
2250
- */
2251
- async _filter(grid, fx) {
2252
- let _data = [];
2253
- let data = jQuery(grid).jqGrid("getGridParam", "fdata");
2254
- let filter = [];
2255
- for (let x in fx) {
2256
- let m = document.querySelectorAll("." + x);
2257
- filter[x] = [];
2258
- for (let i in m) {
2259
- if (m[i].checked) {
2260
- filter[x].push(m[i].value);
2261
- }
2262
- }
2263
- }
2264
- for (let i in data) {
2265
- let include = false;
2266
- for (let x in fx) {
2267
- if (filter[x].indexOf(data[i][x]) != -1) {
2268
- include = true;
2269
- }
2270
- }
2271
- if (include) {
2272
- _data.push(data[i]);
2273
- }
2274
- }
2275
- jQuery(grid).jqGrid("clearGridData");
2276
- jQuery(grid).jqGrid("setGridParam", { data: _data });
2277
- jQuery(grid).trigger("reloadGrid");
2278
- }
2279
- };
2280
-
2281
- },{}]},{},[1])(1)
2282
- });
1
+ !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).Jqgrid_utils=e()}}(function(){return function e(t,r,n){function a(o,s){if(!r[o]){if(!t[o]){var l="function"==typeof require&&require;if(!s&&l)return l(o,!0);if(i)return i(o,!0);var d=new Error("Cannot find module '"+o+"'");throw d.code="MODULE_NOT_FOUND",d}var c=r[o]={exports:{}};t[o][0].call(c.exports,function(e){return a(t[o][1][e]||e)},c,c.exports,e,t,r,n)}return r[o].exports}for(var i="function"==typeof require&&require,o=0;o<n.length;o++)a(n[o]);return a}({1:[function(e,t,r){"use strict";t.exports=class{constructor(e=!1){e&&e.hasOwnProperty("page")&&(this.page=e.page,localStorage.setItem("page",this.page))}async format_currency_on_value(e,t,r="$"){for(let n=0;n<e.length;n++)e[n].name===t&&(e[n].formatoptions={prefix:r,decimalSeparator:".",thousandsSeparator:",",decimalPlaces:2},e[n].formatter=function(e,t,r){if(null==e||""===e)return"";if(0===parseFloat(e))return"";var n=t.colModel.formatoptions.prefix,a=t.colModel.formatoptions.decimalSeparator,i=t.colModel.formatoptions.thousandsSeparator,o=t.colModel.formatoptions.decimalPlaces,s=parseFloat(e).toFixed(o),l=(s=s.replace(".",a)).split(a);return l[0]=l[0].replace(/\B(?=(\d{3})+(?!\d))/g,i),n+(s=l.join(a))});return e}async format_currency(e,t,r="$"){for(let n=0;n<e.length;n++)e[n].name===t&&(e[n].formatter="currency",e[n].formatoptions={prefix:r,decimalSeparator:".",thousandsSeparator:",",decimalPlaces:2});return e}async add_checkbox(e,t){for(let r=0;r<e.length;r++)e[r].name===t&&(e[r].formatter="checkbox",e[r].formatoptions={disabled:!1},e[r].edittype="checkbox",e[r].editoptions={value:"Yes:No",defaultValue:"Yes"});return e}async add_class(e,t,r){for(let n=0;n<e.length;n++)e[n].name===t&&(e[n].classes?e[n].classes+=" "+r:e[n].classes=r);return e}async _grid_substract_on(e,t=[],r=[],n,a=!1){return await this.grid_substract_on(e,t,r,n,a)}async grid_substract_on(e,t=[],r=[],n,a=!1){let i=jQuery(e),o=i.jqGrid("getGridParam","data"),s={invdate:"Total"},l=0,d=0;for(let e in t){let r=0;for(let n in o)if(o[n].hasOwnProperty(t[e])){let a=o[n][t[e]];"string"==typeof a&&is_digit(a)&&(a=parseFloat(a)),r+=a}r!=Math.floor(r)&&(r=r.toFixed(2)),s[t[e]]=r,l=r}for(let e in r){let t=0;for(let n in o)if(o[n].hasOwnProperty(r[e])){let a=o[n][r[e]];"string"==typeof a&&is_digit(a)&&(a=parseFloat(a)),t+=a}t!=Math.floor(t)&&(t=t.toFixed(2)),s[r[e]]=t,d=t}let c=l-d;return a&&c<0&&(c=0),s[n]=c,i.jqGrid("footerData","set",s),s}_grid_ratio_on(e,t,r,n){return this.grid_ratio_on(e,t,r,n)}async grid_ratio_on(e,t,r,n){jQuery("#grid").jqGrid("getGridParam","data");let a=jQuery(e),i=a.jqGrid("getGridParam","data"),o={invdate:"Total"};fraction_sum=0,denominator_sum=0,ratio_sum=0;for(let e in i)i[e].hasOwnProperty(t)&&(fraction_sum+=i[e][t]),i[e].hasOwnProperty(r)&&(denominator_sum+=i[e][r]);return o.qc_eta_ratio=(fraction_sum/denominator_sum).toFixed(2),a.jqGrid("footerData","set",o),o}is_html(e){let t=!1;try{const r=(new DOMParser).parseFromString(e,"text/html");Array.from(r.body.childNodes).some(e=>1===e.nodeType)&&(t=!0)}catch(e){}return t}async _grid_sum_on(e,t=[],r="",n=[]){return await this.grid_sum_on(e,t,r,n)}async grid_sum_on(e,t=[],r="",n=[],a=""){let i=jQuery(e),o=i.jqGrid("getGridParam","data"),s={invdate:"Total"};for(let e in t){let i=0,l=[];for(let r in o){if(""!=a&&l.includes(o[r][a]))continue;let s=0;if(o[r].hasOwnProperty(t[e])){let a=o[r][t[e]],l=!0;for(let e=0;e<n.length;e++)for(let t in n[e])if(o[r][t]===n[e][t]){l=!1;break}if(a&&l){if("string"==typeof a)if(this.is_html(a)){const e=(new DOMParser).parseFromString(a,"text/html").querySelectorAll("a"),t=Array.from(e).map(e=>e.text);if(t.length){const e=t[0].replace(",","");is_digit(e)&&(s=parseFloat(e))}}else is_digit(a)&&(s=parseFloat(a));else"number"==typeof a&&(s=a);i+=s}}""!=a&&l.push(o[r][a])}i!=Math.floor(i)&&(i=i.toFixed(2)),s[t[e]]=""!=r?r+""+this._format_number_with_commas(i):i}return i.jqGrid("footerData","set",s),s}_grid_avg_on(e,t=[]){return this.grid_avg_on(e,t)}async grid_avg_on(e,t=[]){let r=jQuery(e),n=r.jqGrid("getGridParam","data"),a=0,i={invdate:"Total"};for(let e in t){let r=0;for(let i in n)if(n[i].hasOwnProperty(t[e])){let o=n[i][t[e]];"string"==typeof o&&is_digit(o)&&(o=parseFloat(o)),r+=o,a++}r/=a,r!=Math.floor(r)&&(r=r.toFixed(2)),i[t[e]]=r}return r.jqGrid("footerData","set",i),i}_grid_percent_on(e,t){return grid_percent_on(e,t)}async grid_percent_on(e,t){let r=jQuery(e),n=r.jqGrid("getGridParam","data"),a={},i=t.id?t.id:"invate";footer[i]="Total";let o=t.total,s=JSON.parse(JSON.stringify(t.percent));s.push(o);for(let e in s){let t=s[e],r=0,i=0;for(let e in n)if(n[e].hasOwnProperty(t)){let a=n[e][t];"string"==typeof a?is_digit(a)&&(a=parseFloat(a),r+=a,i++):(r+=a,i++)}a[t]=r}for(let e in s){let t=s[e],r=a[t]/(a[o]/100);r=r.toFixed(2),footer[t]=r+"%"}r.jqGrid("footerData","set",footer)}async update_row_to_api(e,t="",r=["id"],n={},a){let i=this,o=[],s={},l={},d={};const c=e.jqGrid("getGridParam","record_data");if(""!=t&&Object.keys(n).length>0&&"edit"==n.inputData.oper){for(let e in c)if(c[e].id===n.rowid){for(let t in r)c[e].hasOwnProperty(r[t])&&(s[r[t]]=c[e][r[t]]);for(let t in n.inputData)"oper"!=t&&Object.keys(s).indexOf(t)<0&&n.inputData[t]!=c[e][t]&&(d[t]=n.inputData[t])}for(let e in d)if(Object.keys(s).indexOf(e)<0&&"oper"!=e){let r={};r[e]=d[e],a.ids=s,a.values=r,a.operator="edit";const n=await i.post_json(t,JSON.stringify(a));o.push(n)}}else if(""!=t&&Object.keys(n).length>0&&"add"==n.inputData.oper){for(let e in n.inputData)n.inputData[e]&&"id"!=e&&"oper"!=e&&(l[e]=n.inputData[e]);a.ids=s,a.values=l,a.operator="add";let e=await i.post_json(t,JSON.stringify(a));o.push(e)}return o}async delete_row_to_api(e,t="",r,n=[],a={}){let i={msg:"failed"},o=this,s=[],l={};const d=e.jqGrid("getGridParam","record_data");for(let e in d)if(d[e].id===r){for(let t in n)d[e].hasOwnProperty(n[t])&&(l[n[t]]=d[e][n[t]],s.push(n[t]));break}return""!=t&&Object.keys(l).length==s.length&&(a.ids=s,a.values=l,i=await o.adelete_api(t,JSON.stringify(a))),i}async append_seperator_link_column(e,t,r,n,a="",i){t+="/";return n.formatter=function(e,n){let o=r;if("object"==typeof i){let r="";for(let e in i){let t=e,a=i[e],o=n.rowData[a];o&&o&&(r+=""!=t?t+"/"+encodeURIComponent(o)+"/":encodeURIComponent(o))}r&&("&"!==r.slice(-1)&&"/"!==r.slice(-1)||(r=r.slice(0,-1)),e="<a "+a+'href="'+t+r+'"> '+o+"</a>")}return e},e.push(n),e}async add_edit(e,t,r,n){for(let a=0;a<e.length;a++)e[a].name===t&&(Object.assign(e[a],r),Object.assign(e[a],n));return e}async add_textarea(e,t,r='style="width:100%;height:100px"'){for(let n=0;n<e.length;n++)e[n].name===t&&(e[n].formatter=function(e){return"<textarea "+r+">"+e+"</textarea>"});return e}async get_col_model_from_data(e,t,r=[],n=[]){let a=[];for(let e in t){const r=Object.keys(t[e]);for(let e in r){const t=r[e];a.push(t)}}a=a.filter((e,t)=>a.indexOf(e)===t);let i=[];for(let e in n)i.push(n[e].name);let o=a.filter(e=>!i.includes(e));const s=new Set(r);o=o.filter(e=>!s.has(e)),o.sort();for(let e=0;e<o.length;e++)n.push({name:o[e],label:o[e]});return n}binary_replace(e,t="zero",r="one"){let n=t;return 1!=e&&0!=e||1==e&&(n=r),n}_date112_to_DMY(e,t="/"){let r=e;if((e=String(e)).trim().length>=8&&-1===e.trim().indexOf(t)){let n=[];n.push(e.substr(6,2)),n.push(e.substr(4,2)),n.push(e.substr(0,4)),r=n.join(t)}return r}async date112_to_DMY(e,t,r="/"){for(let n=0;n<e.length;n++)e[n].name===t&&(e[n].formatter=function(e,t){if((e=String(e)).trim().length>=8&&-1===e.trim().indexOf(r)){let t=e=e.toString();if(e.length>=8&&-1===e.indexOf(r)){let n=[];n.push(e.substr(6,2)),n.push(e.substr(4,2)),n.push(e.substr(0,4)),t=n.join(r)}return t}return e});return e}async set_col_model(e,t,r,n){for(let a=0;a<e.length;a++)e[a].name===t&&(e[a][r]=n);return e}async add_formatter(e,t,r){for(let n=0;n<e.length;n++)e[n].name===t&&r.hasOwnProperty("formatter")&&r.hasOwnProperty("formatoptions")&&(e[n].formatter=r.formatter,e[n].formatoptions=r.formatoptions,e[n].edittype=r.formatter,e[n].editoptions=r.formatoptions);return e}async natural_sort(e,t){for(let r=0;r<e.length;r++)e[r].name===t&&(e[r].sortfunc=function(e,t,r){void 0===r&&(r=1);var n,a,i=/(^-?[0-9]+(\.?[0-9]*)[df]?e?[0-9]?$|^0x[0-9a-f]+$|[0-9]+)/gi,o=/(^[ ]*|[ ]*$)/g,s=/(^([\w ]+,?[\w ]+)?[\w ]+,?[\w ]+\d+:\d+(:\d+)?[\w ]?|^\d{1,4}[\/\-]\d{1,4}[\/\-]\d{1,4}|^\w+, \w+ \d+, \d{4})/,l=/^0x[0-9a-f]+$/i,d=/^0/,c=function(e){return self.insensitive&&(""+e).toLowerCase()||""+e},f=c(e).replace(o,"")||"",u=c(t).replace(o,"")||"",p=f.replace(i,"\0$1\0").replace(/\0$/,"").replace(/^\0/,"").split("\0"),m=u.replace(i,"\0$1\0").replace(/\0$/,"").replace(/^\0/,"").split("\0"),_=parseInt(f.match(l))||1!=p.length&&f.match(s)&&Date.parse(f),h=parseInt(u.match(l))||_&&u.match(s)&&Date.parse(u)||null;if(h){if(_<h)return-r;if(_>h)return r}for(var y=0,g=Math.max(p.length,m.length);y<g;y++){if(n=!(p[y]||"").match(d)&&parseFloat(p[y])||p[y]||0,a=!(m[y]||"").match(d)&&parseFloat(m[y])||m[y]||0,isNaN(n)!==isNaN(a))return isNaN(n)?r:-r;if(typeof n!=typeof a&&(n+="",a+=""),n<a)return-r;if(n>a)return r}return 0});return e}async add_html_formatter(e,t,r){for(let n=0;n<e.length;n++)e[n].name===t&&(e[n].formatter=function(e,t){return r});return e}async add_ok_button(e,t){let r=this;for(let n=0;n<e.length;n++)t.indexOf(e[n].name)>-1&&(e[n].formatter=function(e){return null!=e?r.__cell_format(e,"format_ok"):""});return e}async get_filled_cell_table_data(e,t=[]){let r=jQuery(e).jqGrid("getGridParam","data"),n=t,a=[];for(let e in r)if(r[e].hasOwnProperty("id")){let t=[r[e].id];for(let a in n)r[e].hasOwnProperty(n[a])?t.push(r[e][n[a]]):t.push("");var i=t.filter(function(e,t,r){return""!==e});Object.keys(i).length>1&&a.push(t)}return a}async get_filled_cell_data(e,t=[]){let r=jQuery(e).jqGrid("getGridParam","data"),n=t,a=[];for(let e in r)if(r[e].hasOwnProperty("id")){let t={id:r[e].id};for(let a in n)r[e].hasOwnProperty(n[a])&&""!=r[e][n[a]]&&(t[n[a]]=r[e][n[a]]);Object.keys(t).length>1&&a.push(t)}return a}async set_link(e,t,r,n=""){for(let a=0;a<e.length;a++)e[a].name===t&&(e[a].formatter=function(e,t){return'<a class="gl" '+n+'href="'+t.rowData[r]+'">'+e+"</a>"});return e}async hide_all_columns_except(e,t){for(let r=0;r<e.length;r++)t.indexOf(e[r].name)>-1?e[r].hidden=!1:e[r].hidden=!0;return e}async hide_column(e,t){for(let r=0;r<e.length;r++)e[r].name===t&&(e[r].hidden=!0);return e}s_grid_set_caption(e,t=[]){this.grid_set_captionn(e,[])}async grid_set_caption(e,t=[]){if(e){const r=jQuery(e);let n=0;n=0===t.length?r.jqGrid("getGridParam","records"):t.length;const a=/\d.*x/,i=r.jqGrid("getGridParam","caption").replace(a,"");r.jqGrid("setCaption",i+" "+n+"x")}}s_resize_saved_cell_width(e,t=!1,r=!1){this.grid_set_caption(e,t,r)}async resize_saved_cell_width(e,t=!1,r=!1){let n=t||this.page;n+=r?"-"+r+"-w-":"-grid-w-";for(let t=0;t<=e.length;t++)if(e[t]&&e[t].name){const r=e[t].name,a=localStorage.getItem(n+r);a&&(e[t].width=a)}return e}resize_cell(e,t,r=!1){const n=jQuery(this).jqGrid("getGridParam","colModel");if(n[t]&&n[t].name){const a=n[t].name;let i=(r||localStorage.getItem("page"))+"-"+this.id+"-w-"+a;localStorage.setItem(i,e);localStorage.getItem(i)}}async upsert_row(e,t,r={}){if(e.rowid.startsWith("jqg")){return await this.insert_row(e,t)}return await this.update_row(e,t)}async insert_row(e,t){let r={},n="";if(e.inputData.hasOwnProperty("id")){r._id="id",r._id_val=e.inputData.id;for(let t in e.inputData)r[t]=e.inputData[t];delete r.id,delete r.oper,n=await this.put_json(t,JSON.stringify(r))}return n}async update_row(e,t,r={}){let n="";r._id||(r._id="id"),r._id_val=e.inputData.id;for(let t in e.inputData)r[t]=e.inputData[t];return delete r.id,delete r.oper,n=await this.post_json(t,JSON.stringify(r)),n}async delete_row(e,t){let r="";return t.indexOf("?")>-1?t+="&_id="+encodeURIComponent(unescape(e)):t+="?_id="+encodeURIComponent(unescape(e)),r=JSON.parse(await this.adelete_api(t)),r.message}async adelete_api(e,t=!1){let r="application/x-www-form-urlencoded",n=null;return t&&(r="application/json;charset=UTF-8",n=t),new Promise((t,a)=>{let i=new XMLHttpRequest;i.open("DELETE",e),i.setRequestHeader("Content-type",r),i.onload=()=>t(i.responseText),i.onerror=()=>a(i.statusText),i.send(n)})}async post_json(e,t){return new Promise((r,n)=>{let a=new XMLHttpRequest;a.open("POST",e),a.setRequestHeader("Content-type","application/json"),a.onload=()=>r(a.responseText),a.onerror=()=>n(a.statusText),a.send(t)})}async put_json(e,t){return new Promise((r,n)=>{let a=new XMLHttpRequest;a.open("PUT",e),a.setRequestHeader("Content-type","application/json"),a.onload=()=>r(a.responseText),a.onerror=()=>n(a.statusText),a.send(t)})}s_hide_del_icon(){hide_del_icon()}async hide_del_icon(){jQuery(".ui-inline-del").each(function(e){jQuery(this).html("")})}async add_link_details_csv(e,t,r,n="",a,i,o=","){let s=this;t.indexOf("?")>-1?t+="&":t+="?";for(let l=0;l<e.length;l++)e[l].name===r&&(e[l].formatter=function(e,r){let l=e;const d=s.__cell_format(e,i),c=d.split(o);let f="";for(let i in c){const s=c[i].trim();if(s&&"object"==typeof a){let e="";for(let t in a){let n=t,i=a[t];l=r.rowData[i],l&&(e=-1!==n.indexOf("=")?e+""+n+encodeURIComponent(s)+"&":e+""+n+"="+encodeURIComponent(s)+"&")}"&"===e.slice(-1)&&(e=e.slice(0,-1)),f+="<a "+n+'href="'+t+e+'"> '+s+"</a>"+o+" "}(e=f.trim()).slice(-1)===o&&(e=e.slice(0,-1))}return e||d});return e}async compare(e,t,r,n){const a=jQuery(e).jqGrid("getGridParam","data");for(let i in a)a[i][t]!=a[i][r]&&(jQuery(e).jqGrid("setCell",a[i].id,t,"",n),jQuery(e).jqGrid("setCell",a[i].id,r,"",n))}async compare_smaller(e,t,r,n){const a=jQuery(e).jqGrid("getGridParam","data");for(let i in a)a[i][t]<a[i][r]&&(jQuery(e).jqGrid("setCell",a[i].id,t,"",n),jQuery(e).jqGrid("setCell",a[i].id,r,"",n))}async compare_bigger(e,t,r,n){const a=jQuery(e).jqGrid("getGridParam","data");for(let i in a)a[i][t]>a[i][r]&&(jQuery(e).jqGrid("setCell",a[i].id,t,"",n),jQuery(e).jqGrid("setCell",a[i].id,r,"",n))}async set_styles(e,t="styles"){const r=jQuery(e).jqGrid("getGridParam","data");for(let n in r)if(r[n][t]){const a=JSON.parse(r[n][t]);for(let t in a){const i=r[n].id,o=t;r[n].hasOwnProperty(o)&&jQuery(e).jqGrid("setCell",i,o,"",a[t])}}}async set_classes(e,t){const r=jQuery(e).getDataIDs();for(var n=0;n<r.length;n+=1){const t=jQuery(e).getRowData(r[n]);var a=jQuery("#"+r[n],jQuery(e));a.removeClass("ui-widget-content"),a.addClass(t.class)}}async add_link_details(e,t,r,n="",a,i){let o=this;t.indexOf("?")>-1?t+="&":t+="?";for(let s=0;s<e.length;s++)e[s].name===r&&(e[s].formatter=function(e,r){let s="";(e=String(e))&&(s=e);let l="";if(e&&(l=e.toString()),"object"==typeof a){let d="";for(let e in a){let t=e,n=a[e];s=r.rowData[n],s&&s&&(d=-1!==t.indexOf("=")?d+""+t+encodeURIComponent(s)+"&":d+""+t+"="+encodeURIComponent(s)+"&")}if(d){"&"===d.slice(-1)&&(d=d.slice(0,-1));const r=o.__cell_format(e,i);e=""!=l&&r&&l?"<a "+n+'href="'+t+d+'"> '+r+"</a>":""}}return l?e:""});return e}async add_link_details_separator(e,t,r,n="",a,i){t+="/";let o=this;for(let s=0;s<e.length;s++)e[s].name===r&&(e[s].formatter=function(e,r){let s=e;if("object"==typeof a){let l="";for(let e in a){let t=e,n=a[e];s=r.rowData[n],s&&s&&(l+=""!=t?t+"/"+encodeURIComponent(s)+"/":encodeURIComponent(s))}if(l){"&"!==l.slice(-1)&&"/"!==l.slice(-1)||(l=l.slice(0,-1));const r=o.__cell_format(e,i);e="<a "+n+'href="'+t+l+'"> '+r+"</a>"}}return e});return e}async add_link_separator(e,t,r,n,a=""){t+="/";for(let i=0;i<e.length;i++)e[i].name===r&&(e[i].formatter=function(e,r){let i="";for(let e in n)for(let t in n[e]){if("field"===t){i+=r.rowData[n[e][t]]}if("extension"===t&&(i+=n[e][t]),"fields"===t){i+="?";for(let a in n[e][t]){let o=r.rowData[n[e][t][a]];i=i+""+a+"="+encodeURIComponent(o)+"&"}}}return i&&("&"!==i.slice(-1)&&"/"!==i.slice(-1)||(i=i.slice(0,-1)),e="<a "+a+'href="'+t+i+'"> '+e+"</a>"),e});return e}_format_number_with_commas(e){const t=e.toString().split(".");return t[0]=t[0].replace(/\B(?=(\d{3})+(?!\d))/g,","),t.join(".")}__cell_format(e,t){if("format_ok"==t)e=0==e||"fail"===e?'<i data-check="failed" class="fa fa-times-circle" aria-hidden="true" style="color:#ff0000;"></i>':'<i data-check="ok" class="fa fa-check-circle" aria-hidden="true" style="color:#008000;"></i>';else if("$"==t&&e){e=t+""+this._format_number_with_commas(e)}return e}async subgrid(e,t,r,n,a=""){a=""!=a?a+" ":"",t?r+=t:t="";let i=jQuery("<table style='margin: 5px 0' class='"+e+"_t'></table>");i.appendTo("#"+jQuery.jgrid.jqID(e)),i.jqGrid({caption:a+t,colModel:n,datatype:"json",url:r,gridview:!0,rownumbers:!0,autoencode:!0,sortname:"c1",sortorder:"desc"})}async add_image(e,t,r,n=!1){void 0===r&&(r=60);for(let a=0;a<e.length;a++)e[a].name===t&&(e[a].picture=!0,e[a].width=r,e[a].height=r,e[a].formatter=function(e){const t=e.toLowerCase();return(t.startsWith("https://",0)||t.startsWith("http://",0))&&(t.includes(".png")||t.includes(".jpg")||t.includes(".jpeg")||t.includes(".gif")||t.includes(".svg")||t.includes(".svgz")||t.includes(".webp"))?n?'<a target="blank" href="'+e+'"><img src="'+e+'" alt="my image" width="'+r+'" /></a>':'<img src="'+e+'" alt="my image" width="'+r+'" />':e});return e}async set_filter(e,t,r,n="#filter"){jQuery(e).jqGrid("setGridParam",{fdata:t});let a=document.querySelector(n);for(const e in t)for(let n in r)r[n].push(t[e][n]);for(let e in r)r[e]=r[e].filter((e,t,r)=>r.indexOf(e)===t),r[e].sort();for(let t in r){let n=document.createElement("ul"),i=document.createElement("lh");i.innerHTML=t,n.appendChild(i);for(let a in r[t]){let i=document.createElement("li"),o=document.createElement("label");o.innerHTML=r[t][a];let s=document.createElement("input");s.setAttribute("type","checkbox"),s.setAttribute("class",t),s.setAttribute("id",t+"_"+r[t][a]),o.setAttribute("for",t+"_"+r[t][a]),s.value=r[t][a],s.onchange=async()=>{await this._filter(e,r)},i.appendChild(o),i.appendChild(s),n.appendChild(i)}a.appendChild(n)}}async _filter(e,t){let r=[],n=jQuery(e).jqGrid("getGridParam","fdata"),a=[];for(let e in t){let t=document.querySelectorAll("."+e);a[e]=[];for(let r in t)t[r].checked&&a[e].push(t[r].value)}for(let e in n){let i=!1;for(let r in t)-1!=a[r].indexOf(n[e][r])&&(i=!0);i&&r.push(n[e])}jQuery(e).jqGrid("clearGridData"),jQuery(e).jqGrid("setGridParam",{data:r}),jQuery(e).trigger("reloadGrid")}}},{}]},{},[1])(1)});