jqgrid_utils 1.40.6 → 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,2254 +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
- * Add Formatter
942
- @alias module:Jqgrid_utils
943
- @param {array} - grid col_model
944
- @param {string} - string columns names what will be formatted
945
- @param {object} - formatter object like { formatter: "select", formatoptions: {value: "1:ok;0:fail", defaultValue: "1" }}
946
- @example
947
- var jqu = new Jqgrid_utils();
948
- col_model = await jqu.add_formatter(col_model,'select',{ formatter: "select", formatoptions: {value: "1:ok;0:fail", defaultValue: "1" }})
949
- */
950
-
951
- async add_formatter(col_model, edit_field, formatter) {
952
- for (let i = 0; i < col_model.length; i++) {
953
- if (col_model[i]["name"] === edit_field) {
954
- if (
955
- formatter.hasOwnProperty("formatter") &&
956
- formatter.hasOwnProperty("formatoptions")
957
- ) {
958
- col_model[i]["formatter"] = formatter["formatter"];
959
- col_model[i]["formatoptions"] = formatter["formatoptions"];
960
- col_model[i]["edittype"] = formatter["formatter"];
961
- col_model[i]["editoptions"] = formatter["formatoptions"];
962
- }
963
- }
964
- }
965
- return col_model;
966
- }
967
-
968
- /**
969
- * Natural Sort Column
970
- @alias module:Jqgrid_utils
971
- @param {array} - grid col_model
972
- @param {string} - string columns names for natural sorting
973
- @returns {array} - col_model
974
- @example
975
- var jqu = new Jqgrid_utils();
976
- col_model = await jqu.natural_sort(col_model,'colunmename');
977
- */
978
-
979
- async natural_sort(col_model, column_name) {
980
- for (let i = 0; i < col_model.length; i++) {
981
- if (col_model[i]["name"] === column_name) {
982
- col_model[i]["sortfunc"] = function (a, b, d) {
983
- if (d === undefined) {
984
- d = 1;
985
- }
986
- var re =
987
- /(^-?[0-9]+(\.?[0-9]*)[df]?e?[0-9]?$|^0x[0-9a-f]+$|[0-9]+)/gi,
988
- sre = /(^[ ]*|[ ]*$)/g,
989
- dre =
990
- /(^([\w ]+,?[\w ]+)?[\w ]+,?[\w ]+\d+:\d+(:\d+)?[\w ]?|^\d{1,4}[\/\-]\d{1,4}[\/\-]\d{1,4}|^\w+, \w+ \d+, \d{4})/,
991
- hre = /^0x[0-9a-f]+$/i,
992
- ore = /^0/,
993
- i = function (s) {
994
- return (self.insensitive && ("" + s).toLowerCase()) || "" + s;
995
- },
996
- // convert all to strings strip whitespace
997
- x = i(a).replace(sre, "") || "",
998
- y = i(b).replace(sre, "") || "",
999
- // chunk/tokenize
1000
- xN = x
1001
- .replace(re, "\0$1\0")
1002
- .replace(/\0$/, "")
1003
- .replace(/^\0/, "")
1004
- .split("\0"),
1005
- yN = y
1006
- .replace(re, "\0$1\0")
1007
- .replace(/\0$/, "")
1008
- .replace(/^\0/, "")
1009
- .split("\0"),
1010
- // numeric, hex or date detection
1011
- xD =
1012
- parseInt(x.match(hre)) ||
1013
- (xN.length != 1 && x.match(dre) && Date.parse(x)),
1014
- yD =
1015
- parseInt(y.match(hre)) ||
1016
- (xD && y.match(dre) && Date.parse(y)) ||
1017
- null,
1018
- oFxNcL,
1019
- oFyNcL;
1020
- // first try and sort Hex codes or Dates
1021
- if (yD)
1022
- if (xD < yD) return -d;
1023
- else if (xD > yD) return d;
1024
- // natural sorting through split numeric strings and default strings
1025
- for (
1026
- var cLoc = 0, numS = Math.max(xN.length, yN.length);
1027
- cLoc < numS;
1028
- cLoc++
1029
- ) {
1030
- // find floats not starting with '0', string or 0 if not defined (Clint Priest)
1031
- oFxNcL =
1032
- (!(xN[cLoc] || "").match(ore) && parseFloat(xN[cLoc])) ||
1033
- xN[cLoc] ||
1034
- 0;
1035
- oFyNcL =
1036
- (!(yN[cLoc] || "").match(ore) && parseFloat(yN[cLoc])) ||
1037
- yN[cLoc] ||
1038
- 0;
1039
- // handle numeric vs string comparison - number < string - (Kyle Adams)
1040
- if (isNaN(oFxNcL) !== isNaN(oFyNcL)) {
1041
- return isNaN(oFxNcL) ? d : -d;
1042
- }
1043
- // rely on string comparison if different types - i.e. '02' < 2 != '02' < '2'
1044
- else if (typeof oFxNcL !== typeof oFyNcL) {
1045
- oFxNcL += "";
1046
- oFyNcL += "";
1047
- }
1048
- if (oFxNcL < oFyNcL) return -d;
1049
- if (oFxNcL > oFyNcL) return d;
1050
- }
1051
- return 0;
1052
- };
1053
- }
1054
- }
1055
- return col_model;
1056
- }
1057
-
1058
- /**
1059
- * Add HTML Formatter
1060
- @alias module:Jqgrid_utils
1061
- @param {array} - grid col_model
1062
- @param {string} - string columns names what will be converted to ok buttons
1063
- @param {string} - html tag code
1064
- @returns {array} - col_model
1065
- @example
1066
- var jqu = new Jqgrid_utils();
1067
- col_model = await jqu.add_html_formatter(col_model,'process',"<button tabindex='0' class='cellbtn' type='button'>Process</button>");
1068
- */
1069
-
1070
- async add_html_formatter(col_model, edit_field, html) {
1071
- for (let i = 0; i < col_model.length; i++) {
1072
- if (col_model[i]["name"] === edit_field) {
1073
- col_model[i]["formatter"] = function (cell_val, o) {
1074
- return html;
1075
- };
1076
- }
1077
- }
1078
- return col_model;
1079
- }
1080
-
1081
- /**
1082
- * Add an OK Button
1083
- @alias module:Jqgrid_utils
1084
- @param {array} - grid col_model
1085
- @param {array} - list of columns names what will be converted to ok buttons
1086
- @returns {array} - col_model
1087
- @example
1088
- var jqu = new Jqgrid_utils();
1089
- col_model = await jqu.add_ok_button(col_model, ['checked']);
1090
- */
1091
-
1092
- async add_ok_button(col_model, fields) {
1093
- let self = this;
1094
- for (let i = 0; i < col_model.length; i++) {
1095
- if (fields.indexOf(col_model[i]["name"]) > -1) {
1096
- col_model[i]["formatter"] = function (cell_val) {
1097
- if (cell_val != undefined) {
1098
- return self.__cell_format(cell_val, "format_ok");
1099
- } else {
1100
- return "";
1101
- }
1102
- };
1103
- }
1104
- }
1105
- return col_model;
1106
- }
1107
-
1108
- /**
1109
- * Get the filled cell data
1110
- @alias module:Jqgrid_utils
1111
- @param {object} - the grid object or its name
1112
- @param {array} - list of columns names what will be collected
1113
- @returns {array} - table array
1114
- @example
1115
- var jqu = new Jqgrid_utils();
1116
- col_model = await jqu.get_filled_cell_table_dat("#gridname","fieldname");
1117
-
1118
- */
1119
- async get_filled_cell_table_data(_grid, fields = []) {
1120
- let d = jQuery(_grid).jqGrid("getGridParam", "data");
1121
- let keys = fields;
1122
- let _data = [];
1123
- for (let i in d) {
1124
- if (d[i].hasOwnProperty("id")) {
1125
- let row = [d[i]["id"]];
1126
- for (let x in keys) {
1127
- if (d[i].hasOwnProperty(keys[x])) {
1128
- row.push(d[i][keys[x]]);
1129
- } else {
1130
- row.push("");
1131
- }
1132
- }
1133
- var f = row.filter(function (value, index, arr) {
1134
- return value !== "";
1135
- });
1136
- if (Object.keys(f).length > 1) {
1137
- _data.push(row);
1138
- }
1139
- }
1140
- }
1141
- return _data;
1142
- }
1143
-
1144
- /**
1145
- * Get the filled cell data
1146
- @alias module:Jqgrid_utils
1147
- @param {object} - the grid object or its name
1148
- @param {array} - list of columns names what will be collected
1149
- @returns {object} - json object of the colleted fields
1150
- @example
1151
- var jqu = new Jqgrid_utils();
1152
- let _data = await jqu.get_filled_cell_data(this,["P-","bulk","wholesale"]);
1153
- */
1154
-
1155
- async get_filled_cell_data(_grid, fields = []) {
1156
- let d = jQuery(_grid).jqGrid("getGridParam", "data");
1157
- let keys = fields;
1158
- let _data = [];
1159
- for (let i in d) {
1160
- if (d[i].hasOwnProperty("id")) {
1161
- let row = { id: d[i]["id"] };
1162
- for (let x in keys) {
1163
- if (d[i].hasOwnProperty(keys[x])) {
1164
- if (d[i][keys[x]] != "") {
1165
- row[keys[x]] = d[i][keys[x]];
1166
- }
1167
- }
1168
- }
1169
- if (Object.keys(row).length > 1) {
1170
- _data.push(row);
1171
- }
1172
- }
1173
- }
1174
- return _data;
1175
- }
1176
-
1177
- /**
1178
- * Add an URL from the data to a specific cell/column
1179
- @alias module:Jqgrid_utils
1180
- @param {object} - col_model of the grid
1181
- @param {string} - name of the column what should get convert to the url
1182
- @param {string} - the used url of the data
1183
- @returns {object} https://foo.bar.com/av0_code/bar
1184
- @example
1185
- var jqu = new Jqgrid_utils();
1186
- col_model = await jqu.set_link(col_model,'field_get_url','field_with_the_url','target="blank"');
1187
- console.log(_data);
1188
- */
1189
- async set_link(col_model, edit_field, url, attr = "") {
1190
- for (let i = 0; i < col_model.length; i++) {
1191
- if (col_model[i]["name"] === edit_field) {
1192
- col_model[i]["formatter"] = function (cell_val, o) {
1193
- return (
1194
- '<a class="gl" ' +
1195
- attr +
1196
- 'href="' +
1197
- o.rowData[url] +
1198
- '">' +
1199
- cell_val +
1200
- "</a>"
1201
- );
1202
- };
1203
- }
1204
- }
1205
- return col_model;
1206
- }
1207
-
1208
- /**
1209
- * Hide all columns execpt column
1210
- * @alias module:Jqgrid_utils
1211
- * @param {object} - col_model of the grid
1212
- * @param {array} - array of names to not to hide
1213
- * @returns {object} col_model
1214
- * @example
1215
- col_model = await jqu.hide_all_columns_except(col_model,['supplier','customer']);
1216
- */
1217
- async hide_all_columns_except(col_model, fields) {
1218
- for (let i = 0; i < col_model.length; i++) {
1219
- if (fields.indexOf(col_model[i]["name"]) > -1) {
1220
- col_model[i]["hidden"] = false;
1221
- } else {
1222
- col_model[i]["hidden"] = true;
1223
- }
1224
- }
1225
- return col_model;
1226
- }
1227
-
1228
- /**
1229
- * Hide a col_model column before load the grid
1230
- * @alias module:Jqgrid_utils
1231
- * @param {object} - col_model of the grid
1232
- * @param {string} - name of the column to hide
1233
- * @returns {object} col_model
1234
- * @example
1235
- col_model = await jqu.hide_column(col_model,'wholesale');
1236
- col_model = await jqu.hide_column(col_model,'wholesale_formula');
1237
- */
1238
- async hide_column(col_model, field) {
1239
- for (let i = 0; i < col_model.length; i++) {
1240
- if (col_model[i]["name"] === field) {
1241
- col_model[i]["hidden"] = true;
1242
- }
1243
- }
1244
- return col_model;
1245
- }
1246
-
1247
- /**
1248
- @alias module:Jqgrid_utils
1249
- @param {object} - gridobject;
1250
- @param {object} - grid data (optional);
1251
- @example
1252
- var jqu = new Jqgrid_utils();
1253
- loadComplete: function(){
1254
- jqu.grid_set_caption(this);
1255
- },
1256
- */
1257
-
1258
- s_grid_set_caption(_grid, data = []) {
1259
- this.grid_set_captionn(_grid, (data = []));
1260
- }
1261
-
1262
- /**
1263
- Adding the row count number to the caption
1264
- @alias module:Jqgrid_utils
1265
- @param {object} - gridobject;
1266
- @param {object} - grid data (optional);
1267
- @example
1268
- var jqu = new Jqgrid_utils();
1269
- loadComplete: function(){
1270
- await jqu.grid_set_caption(this);
1271
- },
1272
- */
1273
- async grid_set_caption(_grid, data = []) {
1274
- if (_grid) {
1275
- const grid = jQuery(_grid);
1276
- let count = 0;
1277
- if (data.length === 0) {
1278
- count = grid.jqGrid("getGridParam", "records");
1279
- } else {
1280
- count = data.length;
1281
- }
1282
- let caption = grid.jqGrid("getGridParam", "caption");
1283
- const reg = /\d.*x/;
1284
- const new_caption = caption.replace(reg, "");
1285
- grid.jqGrid("setCaption", new_caption + " " + count + "x");
1286
- }
1287
- }
1288
-
1289
- /**
1290
- @alias module:Jqgrid_utils
1291
- @param {object} - the col_model of the grid
1292
- @param {string} - the name of the page(optional)
1293
- @param {object} - the grid objec(optional)
1294
- @example
1295
- col_model = await jqu.resize_saved_cell_width(col_model);
1296
- */
1297
- s_resize_saved_cell_width(col_model, page = false, grid = false) {
1298
- this.grid_set_caption(col_model, page, grid);
1299
- }
1300
-
1301
- /**
1302
- @alias module:Jqgrid_utils
1303
- @param {object} - the col_model of the grid
1304
- @param {string} - the name of the page(optional)
1305
- @param {object} - the grid objec(optional)
1306
- @example
1307
- col_model = await jqu.resize_saved_cell_width(col_model);
1308
- */
1309
- async resize_saved_cell_width(col_model, page = false, grid = false) {
1310
- let key = page ? page : this.page;
1311
- key += grid ? "-" + grid + "-w-" : "-grid-w-";
1312
- for (let x = 0; x <= col_model.length; x++) {
1313
- if (col_model[x]) {
1314
- if (col_model[x]["name"]) {
1315
- const name = col_model[x]["name"];
1316
- const width = localStorage.getItem(key + name);
1317
- if (width) {
1318
- col_model[x]["width"] = width;
1319
- }
1320
- }
1321
- }
1322
- }
1323
- return col_model;
1324
- }
1325
-
1326
- /**
1327
- @alias module:Jqgrid_utils
1328
- @param {string} the width of the resized column
1329
- @param {string} column number what get resized
1330
- @param {string} not in use yet
1331
- @example
1332
- * var jqu = new Jqgrid_utils({page:'mypage'});
1333
- * resizeStop: jqu.resize_cell,
1334
- */
1335
- resize_cell(width, index, _page = false) {
1336
- const col_model = jQuery(this).jqGrid("getGridParam", "colModel");
1337
- if (col_model[index]) {
1338
- if (col_model[index]["name"]) {
1339
- const name = col_model[index]["name"];
1340
- const page = _page ? _page : localStorage.getItem("page");
1341
- const grid = this.id;
1342
- let key = page + "-" + grid + "-w-" + name;
1343
- localStorage.setItem(key, width);
1344
- const cat = localStorage.getItem(key);
1345
- }
1346
- }
1347
- }
1348
-
1349
- /**
1350
- * Upsert(insert or update) from the grid to an API
1351
- @alias module:Jqgrid_utils
1352
- @param {object} - row object
1353
- @param {string} - url of the API
1354
- @param {string} - data oject
1355
- @returns {object} {update: 'ok'} or {update: 'failed'}
1356
- @example
1357
- var jqu = new Jqgrid_utils();
1358
- afterSetRow: async function(row)
1359
- {
1360
- let r = await jqu.upsert_row(row, 'http://api.com',{'key':'value'});
1361
- console.log(r);
1362
- },
1363
- */
1364
- async upsert_row(row, url, req = {}) {
1365
- if (row.rowid.startsWith("jqg")) {
1366
- const r0 = await this.insert_row(row, url);
1367
- return r0;
1368
- } else {
1369
- const r1 = await this.update_row(row, url);
1370
- return r1;
1371
- }
1372
- }
1373
-
1374
- /**
1375
- * Insert from the grid to an API used by the upsert_row function
1376
- @alias module:Jqgrid_utils
1377
- @param {object} - row object
1378
- @param {string} - URL of the API
1379
- @returns {object} Object from the the API like {update: 'ok'} or {update: 'failed'}
1380
- @example
1381
- var jqu = new Jqgrid_utils();
1382
- afterSetRow: async function(row)
1383
- {
1384
- let r = await jqu.insert_row(row, 'http://api.com');
1385
- console.log(r);
1386
- },
1387
- */
1388
- async insert_row(row, url) {
1389
- let req = {};
1390
- let ret = "";
1391
- if (row.inputData.hasOwnProperty("id")) {
1392
- req["_id"] = "id";
1393
- req["_id_val"] = row.inputData["id"];
1394
- for (let i in row.inputData) {
1395
- req[i] = row.inputData[i];
1396
- }
1397
- delete req["id"];
1398
- delete req["oper"];
1399
- //console.log(req);
1400
- ret = await this.put_json(url, JSON.stringify(req));
1401
- }
1402
- return ret;
1403
- }
1404
-
1405
- /**
1406
- * Update from the grid to an API used by the upsert_row function
1407
- @alias module:Jqgrid_utils
1408
- @param {object} - row object
1409
- @param {string} - url of the API
1410
- @param {string} - data oject
1411
- @returns {object} Object from the the API like {update: 'ok'} or {update: 'failed'}
1412
- @example
1413
- var jqu = new Jqgrid_utils();
1414
- afterSetRow: async function(row)
1415
- {
1416
- let r = await jqu.update_row(row, 'http://api.com',{'key':value});
1417
- console.log(r);
1418
- },
1419
- */
1420
-
1421
- async update_row(row, url, req = {}) {
1422
- let ret = "";
1423
- {
1424
- if (!req["_id"]) {
1425
- req["_id"] = "id";
1426
- }
1427
- req["_id_val"] = row.inputData["id"];
1428
- for (let i in row.inputData) {
1429
- req[i] = row.inputData[i];
1430
- }
1431
- delete req["id"];
1432
- delete req["oper"];
1433
- ret = await this.post_json(url, JSON.stringify(req));
1434
- }
1435
- return ret;
1436
- }
1437
-
1438
- /**
1439
- * Delete from the grid to an API
1440
- @alias module:Jqgrid_utils
1441
- @param {string} - row id
1442
- @param {string} - url of the API
1443
- @returns {object} @returns {object} Object from the the API like {delete: 'ok'} or {delete: 'failed'}
1444
- @example
1445
- var jqu = new Jqgrid_utils();
1446
- afterDelRow: async function(row)
1447
- {
1448
- const r = await jqu.delete_row('id', 'http://api.com');
1449
- console.log(r + ' : ' + row + ' - from API');
1450
- },
1451
- */
1452
-
1453
- async delete_row(_id, url) {
1454
- let ret = "";
1455
- if (url.indexOf("?") > -1) {
1456
- url += "&_id=" + encodeURIComponent(unescape(_id));
1457
- } else {
1458
- url += "?_id=" + encodeURIComponent(unescape(_id));
1459
- }
1460
-
1461
- ret = JSON.parse(await this.adelete_api(url));
1462
- return ret["message"];
1463
- }
1464
-
1465
- /**
1466
- * Async Delete request used by function delete_row
1467
- @alias module:Jqgrid_utils
1468
- @param {string} - url of the API
1469
- @param {boalan} - header should be json type? default form type
1470
- @returns {object} @returns {object} Object from the the API like {delete: 'ok'} or {delete: 'failed'}
1471
- @example
1472
- var jqu = new Jqgrid_utils();
1473
- afterDelRow: async function(row)
1474
- {
1475
- ret = JSON.parse(await jqu.adelete_api(url));
1476
- },
1477
- */
1478
-
1479
- async adelete_api(url, json = false) {
1480
- let ctype = "application/x-www-form-urlencoded";
1481
- let body = null;
1482
- if (json) {
1483
- ctype = "application/json;charset=UTF-8";
1484
- body = json;
1485
- }
1486
- return new Promise((resolve, reject) => {
1487
- let xhr = new XMLHttpRequest();
1488
- xhr.open("DELETE", url);
1489
- xhr.setRequestHeader("Content-type", ctype);
1490
- xhr.onload = () => resolve(xhr.responseText);
1491
- xhr.onerror = () => reject(xhr.statusText);
1492
- xhr.send(body);
1493
- });
1494
- }
1495
-
1496
- /**
1497
- * Async Post request used by the update_row function
1498
- @alias module:Jqgrid_utils
1499
- @param {string} - url of the API
1500
- @param {object} - json object
1501
- @returns {object} @returns {object} Object from the the API like {update: 'ok'} or {update: 'failed'}
1502
- @example
1503
- var jqu = new Jqgrid_utils();
1504
- ret = JSON.parse(await jqu.post_json(url,{'key':value,'key2':'value'}));
1505
- */
1506
-
1507
- async post_json(url, data) {
1508
- return new Promise((resolve, reject) => {
1509
- let xhr = new XMLHttpRequest();
1510
- xhr.open("POST", url);
1511
- xhr.setRequestHeader("Content-type", "application/json");
1512
- xhr.onload = () => resolve(xhr.responseText);
1513
- xhr.onerror = () => reject(xhr.statusText);
1514
- xhr.send(data);
1515
- });
1516
- }
1517
-
1518
- /**
1519
- * Async Put request used by the insert_row function
1520
- @alias module:Jqgrid_utils
1521
- @param {string} - url of the API
1522
- @param {object} - json object
1523
- @returns {object} @returns {object} Object from the the API like {insert: 'ok'} or {insert: 'failed'}
1524
- @example
1525
- var jqu = new Jqgrid_utils();
1526
- ret = JSON.parse(await jqu.put_json(url,{'key':value,'key2':'value2'}));
1527
- */
1528
- async put_json(url, data) {
1529
- return new Promise((resolve, reject) => {
1530
- let xhr = new XMLHttpRequest();
1531
- xhr.open("PUT", url);
1532
- xhr.setRequestHeader("Content-type", "application/json");
1533
- xhr.onload = () => resolve(xhr.responseText);
1534
- xhr.onerror = () => reject(xhr.statusText);
1535
- xhr.send(data);
1536
- });
1537
- }
1538
-
1539
- /**
1540
- * Hide the del iconf rom the grid
1541
- @alias module:Jqgrid_utils
1542
- @example
1543
- var jqu = new Jqgrid_utils();
1544
- jqu.hide_del_icon();
1545
- */
1546
- s_hide_del_icon() {
1547
- hide_del_icon();
1548
- }
1549
-
1550
- /**
1551
- * Hide the del iconf rom the grid
1552
- @alias module:Jqgrid_utils
1553
- @example
1554
- var jqu = new Jqgrid_utils();
1555
- await jqu.hide_del_icon();
1556
- */
1557
- async hide_del_icon() {
1558
- jQuery(".ui-inline-del").each(function (index) {
1559
- jQuery(this).html("");
1560
- });
1561
- }
1562
-
1563
- /**
1564
- * Convert a cell into a link/url with data from another cell and spit the value by comma - CSV
1565
- @alias module:Jqgrid_utils
1566
- @param {object} - col_model of the grid
1567
- @param {string} - URL string
1568
- @param {string} - Column/Cell to use
1569
- @param {string} - URL Attributes
1570
- @param {object} - keys and fields value to use
1571
- @param {object} - format info
1572
- @param {string} - seperator of the cell value to split (default is comma)
1573
- @example
1574
- var jqu = new Jqgrid_utils();
1575
- col_model = await jqu.add_link_details_csv(col_model, host + '/html/report.html' , 'tags','target="_blank"',{"tags":"tags"},',');
1576
-
1577
- */
1578
- async add_link_details_csv(
1579
- col_model,
1580
- url,
1581
- edit_field,
1582
- attr = "",
1583
- keys,
1584
- format,
1585
- seperator = ",",
1586
- ) {
1587
- let self = this;
1588
- if (url.indexOf("?") > -1) {
1589
- url = url + "&";
1590
- } else {
1591
- url = url + "?";
1592
- }
1593
-
1594
- for (let i = 0; i < col_model.length; i++) {
1595
- if (col_model[i]["name"] === edit_field) {
1596
- col_model[i]["formatter"] = function (cell_val, obj) {
1597
- let key_val = cell_val;
1598
- const _cell_val = self.__cell_format(cell_val, format);
1599
- const a = _cell_val.split(seperator);
1600
- let cell_value = "";
1601
- for (let x in a) {
1602
- const x_value = a[x].trim();
1603
- if (x_value) {
1604
- if (typeof keys === "object") {
1605
- let pref = "";
1606
- for (let ii in keys) {
1607
- let key = ii;
1608
- let v = keys[ii];
1609
- key_val = obj.rowData[v];
1610
- if (key_val) {
1611
- if (key.indexOf("=") !== -1) {
1612
- pref =
1613
- pref +
1614
- "" +
1615
- key +
1616
- "" +
1617
- encodeURIComponent(x_value) +
1618
- "&";
1619
- } else {
1620
- pref =
1621
- pref +
1622
- "" +
1623
- key +
1624
- "=" +
1625
- encodeURIComponent(x_value) +
1626
- "&";
1627
- }
1628
- }
1629
- }
1630
- if (pref.slice(-1) === "&") {
1631
- pref = pref.slice(0, -1);
1632
- }
1633
- cell_value +=
1634
- "<a " +
1635
- attr +
1636
- 'href="' +
1637
- url +
1638
- pref +
1639
- '"> ' +
1640
- x_value +
1641
- "</a>" +
1642
- seperator +
1643
- " ";
1644
- }
1645
- }
1646
- cell_val = cell_value.trim();
1647
- if (cell_val.slice(-1) === seperator) {
1648
- //remove last seperator
1649
- cell_val = cell_val.slice(0, -1);
1650
- }
1651
- }
1652
-
1653
- if (cell_val) {
1654
- return cell_val;
1655
- } else {
1656
- return _cell_val;
1657
- }
1658
- };
1659
- }
1660
- }
1661
-
1662
- return col_model;
1663
- }
1664
-
1665
- /**
1666
- * Compare 2 columns and give them a style class when they have different content
1667
- * http://www.trirand.com/jqgridwiki/doku.php?id=wiki:methods
1668
- @alias module:Jqgrid_utils
1669
- @param {object} - grid object
1670
- @param {string} - first column
1671
- @param {string} - second column
1672
- @param {string} - css class name
1673
- @example
1674
- loadComplete: async function()
1675
- {
1676
- await jqu.compare(this,'first_column','second_column','redlight');
1677
- }
1678
-
1679
- */
1680
- async compare(obj, column1, column2, css_class) {
1681
- const rows = jQuery(obj).jqGrid("getGridParam", "data");
1682
- for (let i in rows) {
1683
- if (rows[i][column1] != rows[i][column2]) {
1684
- jQuery(obj).jqGrid("setCell", rows[i]["id"], column1, "", css_class);
1685
- jQuery(obj).jqGrid("setCell", rows[i]["id"], column2, "", css_class);
1686
- }
1687
- }
1688
- }
1689
-
1690
- /**
1691
- * Compare 2 columns for smaller and give them a style class
1692
- * http://www.trirand.com/jqgridwiki/doku.php?id=wiki:methods
1693
- @alias module:Jqgrid_utils
1694
- @param {object} - grid object
1695
- @param {string} - first column
1696
- @param {string} - second column
1697
- @param {string} - css class name
1698
- @example
1699
- loadComplete: async function()
1700
- {
1701
- await jqu.compare(this,'first_column','second_column','redlight');
1702
- }
1703
-
1704
- */
1705
- async compare_smaller(obj, column1, column2, css_class) {
1706
- const rows = jQuery(obj).jqGrid("getGridParam", "data");
1707
- for (let i in rows) {
1708
- if (rows[i][column1] < rows[i][column2]) {
1709
- jQuery(obj).jqGrid("setCell", rows[i]["id"], column1, "", css_class);
1710
- jQuery(obj).jqGrid("setCell", rows[i]["id"], column2, "", css_class);
1711
- }
1712
- }
1713
- }
1714
-
1715
- /**
1716
- * Compare 2 columns for bigger and give them a style class
1717
- * http://www.trirand.com/jqgridwiki/doku.php?id=wiki:methods
1718
- @alias module:Jqgrid_utils
1719
- @param {object} - grid object
1720
- @param {string} - first column
1721
- @param {string} - second column
1722
- @param {string} - css class name
1723
- @example
1724
- loadComplete: async function()
1725
- {
1726
- await jqu.compare(this,'first_column','second_column','redlight');
1727
- }
1728
-
1729
- */
1730
- async compare_bigger(obj, column1, column2, css_class) {
1731
- const rows = jQuery(obj).jqGrid("getGridParam", "data");
1732
- for (let i in rows) {
1733
- if (rows[i][column1] > rows[i][column2]) {
1734
- jQuery(obj).jqGrid("setCell", rows[i]["id"], column1, "", css_class);
1735
- jQuery(obj).jqGrid("setCell", rows[i]["id"], column2, "", css_class);
1736
- }
1737
- }
1738
- }
1739
-
1740
- /**
1741
- * Set styles to individual cells, what are defined in a dedicated column
1742
- @alias module:Jqgrid_utils
1743
- @param {object} - grid object
1744
- @param {string} - name of the column what includes the style values what need to be in a strinify json format
1745
- @example
1746
- var jqu = new Jqgrid_utils();
1747
- loadComplete: async function() {
1748
- await jqu.set_styles(this);
1749
- },
1750
- */
1751
- async set_styles(obj, style_column = "styles") {
1752
- const rows = jQuery(obj).jqGrid("getGridParam", "data");
1753
-
1754
- for (let i in rows) {
1755
- if (rows[i][style_column]) {
1756
- const styles = JSON.parse(rows[i][style_column]);
1757
- for (let ii in styles) {
1758
- const rowid = rows[i]["id"];
1759
- const name = ii;
1760
- if (rows[i].hasOwnProperty(name)) {
1761
- jQuery(obj).jqGrid("setCell", rowid, name, "", styles[ii]);
1762
- }
1763
- }
1764
- }
1765
- }
1766
- }
1767
-
1768
- /**
1769
- * Set a class to a row, what must be defined in a dedicated column called row.class
1770
- * Once the grid is loaded, the functions adds extra class to the row element
1771
- @alias module:Jqgrid_utils
1772
- @param {object} - grid id like #grid
1773
- @example
1774
- var jqu = new Jqgrid_utils();
1775
- loadComplete: async function() {
1776
- await jqu.set_classes("#grid");
1777
- },
1778
- */
1779
- async set_classes(grid_id, field) {
1780
- const rows = jQuery(grid_id).getDataIDs();
1781
- for (var i = 0; i < rows.length; i = i + 1) {
1782
- const row = jQuery(grid_id).getRowData(rows[i]);
1783
- var e = jQuery("#" + rows[i], jQuery(grid_id));
1784
- e.removeClass("ui-widget-content");
1785
- e.addClass(row.class);
1786
- }
1787
- }
1788
-
1789
- /**
1790
- * Convert a cell into a link/url with data from another cell
1791
- @alias module:Jqgrid_utils
1792
- @param {object} - col_model of the grid
1793
- @param {string} - URL string
1794
- @param {string} - Column/Cell to use
1795
- @param {string} - URL Attributes
1796
- @param {object} - keys and fields value to use
1797
- @example
1798
- var jqu = new Jqgrid_utils();
1799
- col_model = await jqu.add_link_details(col_model,'http://foo.bar' , 'style','target="_blank"',{'key':'style'});
1800
- col_model = await jqu.add_link_details(col_model, host + '/html/table_size.html' , 'database','target="_blank"',{"database":"database","server":"server"});
1801
- */
1802
- async add_link_details(col_model, url, edit_field, attr = "", keys, format) {
1803
- let self = this;
1804
- if (url.indexOf("?") > -1) {
1805
- url = url + "&";
1806
- } else {
1807
- url = url + "?";
1808
- }
1809
-
1810
- for (let i = 0; i < col_model.length; i++) {
1811
- if (col_model[i]["name"] === edit_field) {
1812
- col_model[i]["formatter"] = function (cell_val, obj) {
1813
- cell_val = String(cell_val);
1814
- let key_val = "";
1815
- if (cell_val) {
1816
- key_val = cell_val;
1817
- }
1818
- let t = "";
1819
- if (cell_val) {
1820
- t = cell_val.toString();
1821
- }
1822
-
1823
- if (typeof keys === "object") {
1824
- let pref = "";
1825
- for (let ii in keys) {
1826
- let key = ii;
1827
- let v = keys[ii];
1828
- key_val = obj.rowData[v];
1829
- if (key_val) {
1830
- if (key_val) {
1831
- if (key.indexOf("=") !== -1) {
1832
- pref =
1833
- pref + "" + key + "" + encodeURIComponent(key_val) + "&";
1834
- } else {
1835
- pref =
1836
- pref + "" + key + "=" + encodeURIComponent(key_val) + "&";
1837
- }
1838
- }
1839
- }
1840
- }
1841
- if (pref) {
1842
- if (pref.slice(-1) === "&") {
1843
- pref = pref.slice(0, -1);
1844
- }
1845
- const _cell_val = self.__cell_format(cell_val, format);
1846
-
1847
- if (t != "" && _cell_val && t) {
1848
- cell_val =
1849
- "<a " +
1850
- attr +
1851
- 'href="' +
1852
- url +
1853
- pref +
1854
- '"> ' +
1855
- _cell_val +
1856
- "</a>";
1857
- } else {
1858
- cell_val = "";
1859
- }
1860
- }
1861
- }
1862
- if (t) {
1863
- return cell_val;
1864
- } else {
1865
- return "";
1866
- }
1867
- };
1868
- }
1869
- }
1870
-
1871
- return col_model;
1872
- }
1873
-
1874
- /**
1875
- * Convert a cell into seperated based link/url like https://foo.bar.com/field/value/field/value
1876
- @alias module:Jqgrid_utils
1877
- @param {object} - col_model of the grid
1878
- @param {string} - URL string
1879
- @param {string} - Column/Cell to use
1880
- @param {string} - URL Attributes
1881
- @param {object} - keys and fields value to use
1882
- @example
1883
- var jqu = new Jqgrid_utils();
1884
- col_model = await jqu.add_link_details_separator(col_model, url1 , 'style','target="_blank"',{"pricelist":"pricelist","style":"style"});
1885
- col_model = await jqu.add_link_details_separator(col_model, 'https://foo.com' , 'target_column','target="_blank"',{"mykey":"myval"});
1886
- */
1887
- async add_link_details_separator(
1888
- col_model,
1889
- url,
1890
- edit_field,
1891
- attr = "",
1892
- keys,
1893
- format,
1894
- ) {
1895
- url = url + "/";
1896
- let self = this;
1897
- for (let i = 0; i < col_model.length; i++) {
1898
- if (col_model[i]["name"] === edit_field) {
1899
- col_model[i]["formatter"] = function (cell_val, obj) {
1900
- let key_val = cell_val;
1901
-
1902
- if (typeof keys === "object") {
1903
- let pref = "";
1904
- for (let ii in keys) {
1905
- let key = ii;
1906
- let v = keys[ii];
1907
- key_val = obj.rowData[v];
1908
- if (key_val) {
1909
- if (key_val) {
1910
- if (key != "") {
1911
- pref += key + "" + "/" + encodeURIComponent(key_val) + "/";
1912
- } else {
1913
- pref += encodeURIComponent(key_val);
1914
- }
1915
- }
1916
- }
1917
- }
1918
- if (pref) {
1919
- if (pref.slice(-1) === "&" || pref.slice(-1) === "/") {
1920
- pref = pref.slice(0, -1);
1921
- }
1922
- const _cell_val = self.__cell_format(cell_val, format);
1923
- cell_val =
1924
- "<a " +
1925
- attr +
1926
- 'href="' +
1927
- url +
1928
- pref +
1929
- '"> ' +
1930
- _cell_val +
1931
- "</a>";
1932
- }
1933
- }
1934
-
1935
- return cell_val;
1936
- };
1937
- }
1938
- }
1939
-
1940
- return col_model;
1941
- }
1942
-
1943
- /**
1944
- * Convert a cell into seperated based link/url include parameter based url like https://foo.bar.com/field.html?k=v
1945
- @alias module:Jqgrid_utils
1946
- @param {object} - col_model of the grid
1947
- @param {string} - URL string
1948
- @param {array} - array of dict
1949
- @param {string} - URL Attributes
1950
- @example
1951
- var jqu = new Jqgrid_utils();
1952
- col_model = await jqu.add_link_separator(col_model, host + '/html' , 'style',[
1953
- {
1954
- 'field':'pricelist',
1955
- 'extension':'.html',
1956
- 'fields':{'style':'style'}
1957
- }
1958
- ]);
1959
- //other example
1960
- col_model = await jqu.add_link_separator(col_model, 'https://wiki.salamander-jewelry.net/index.php/grid_loss' , 'e',[{'field':'e'}],'target="_blank"');
1961
-
1962
- */
1963
- async add_link_separator(col_model, url, edit_field, fields, attr = "") {
1964
- url = url + "/";
1965
- let self = this;
1966
- for (let i = 0; i < col_model.length; i++) {
1967
- if (col_model[i]["name"] === edit_field) {
1968
- col_model[i]["formatter"] = function (cell_val, obj) {
1969
- let key_val = cell_val;
1970
- let pref = "";
1971
- for (let x in fields) {
1972
- for (let xx in fields[x]) {
1973
- if (xx === "field") {
1974
- let field_value = obj.rowData[fields[x][xx]];
1975
- pref += field_value;
1976
- }
1977
- if (xx === "extension") {
1978
- pref += fields[x][xx];
1979
- }
1980
- if (xx === "fields") {
1981
- pref += "?";
1982
- for (let key in fields[x][xx]) {
1983
- let val = obj.rowData[fields[x][xx][key]];
1984
- pref = pref + "" + key + "=" + encodeURIComponent(val) + "&";
1985
- }
1986
- }
1987
- }
1988
- }
1989
- if (pref) {
1990
- if (pref.slice(-1) === "&" || pref.slice(-1) === "/") {
1991
- pref = pref.slice(0, -1);
1992
- }
1993
- cell_val =
1994
- "<a " + attr + 'href="' + url + pref + '"> ' + cell_val + "</a>";
1995
- }
1996
-
1997
- return cell_val;
1998
- };
1999
- }
2000
- }
2001
- return col_model;
2002
- }
2003
-
2004
- /**
2005
- * Private Function
2006
- @alias module:Jqgrid_utils
2007
- @param {string} - number to add comma
2008
- */
2009
- _format_number_with_commas(number) {
2010
- const parts = number.toString().split(".");
2011
- parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
2012
- return parts.join(".");
2013
- }
2014
-
2015
- /**
2016
- * Private Function
2017
- @alias module:Jqgrid_utils
2018
- @param {object} - cell_value
2019
- @param {string} - format_ok or $ sign
2020
- */
2021
- __cell_format(cell_value, format) {
2022
- if (format == "format_ok") {
2023
- if (cell_value == 0 || cell_value === "fail") {
2024
- cell_value =
2025
- '<i data-check="failed" class="fa fa-times-circle" aria-hidden="true" style="color:#ff0000;"></i>';
2026
- } else {
2027
- cell_value =
2028
- '<i data-check="ok" class="fa fa-check-circle" aria-hidden="true" style="color:#008000;"></i>';
2029
- }
2030
- } else if (format == "$") {
2031
- if (cell_value) {
2032
- const number = this._format_number_with_commas(cell_value);
2033
- cell_value = format + "" + number;
2034
- }
2035
- }
2036
-
2037
- return cell_value;
2038
- }
2039
-
2040
- /**
2041
- @alias module:Jqgrid_utils
2042
- @param {string} - row_id
2043
- @param {string} - data id
2044
- @param {string} - url to request
2045
- @param {object} - col_model for the table
2046
- @param {string} - Add to the caption of the subgrid
2047
- @example
2048
- subGrid: true,
2049
- ,subGridRowExpanded: async function(_id, id) {
2050
- let data_url2 = api + '/process_locations?f=data&process=';
2051
- let col_model_url2 = api + '/process_locations?f=col_model';
2052
- let col_model2 = JSON.parse(await vwu.aget_api(col_model_url2));
2053
- await jqu.subgrid(_id, id, data_url2, col_model2,'Locations for Process');
2054
-
2055
- let data_url = api + '/process_styles?f=data&process=';
2056
- let col_model_url = api + '/process_styles?f=col_model';
2057
- let col_model = JSON.parse(await vwu.aget_api(col_model_url));
2058
- await jqu.subgrid(_id, id, data_url, col_model,'Styles for Process');
2059
- },
2060
-
2061
- or
2062
-
2063
- subGrid: true,
2064
- subGridRowExpanded: async function(_id, id) {
2065
- let row_data = jQuery(this).jqGrid ('getRowData', id);
2066
- let param={f:'data','style':row_data['style'],pricelist:'P-TENENGR1'};
2067
- let data_url = api + '/order_ln';
2068
- data_url = await add_parameters(data_url, param);
2069
- let col_model_url2 = api + '/order_ln?f=col_model';
2070
- let col_model2 = JSON.parse(await vwu.aget_api(col_model_url2));
2071
- await jqu.subgrid(_id, false, data_url, col_model2,'Order Lines for ' + row_data['style']);
2072
- },
2073
-
2074
- */
2075
- async subgrid(_id, id, url, col_model, caption = "") {
2076
- caption = caption != "" ? caption + " " : "";
2077
- if (id) {
2078
- url += id;
2079
- } else {
2080
- id = "";
2081
- }
2082
- let $s1 = jQuery(
2083
- "<table style='margin: 5px 0' class='" + _id + "_t'></table>",
2084
- );
2085
- $s1.appendTo("#" + jQuery.jgrid.jqID(_id));
2086
- $s1.jqGrid({
2087
- caption: caption + id,
2088
- colModel: col_model,
2089
- datatype: "json",
2090
- url: url,
2091
- gridview: true,
2092
- rownumbers: true,
2093
- autoencode: true,
2094
- sortname: "c1",
2095
- sortorder: "desc",
2096
- });
2097
- }
2098
-
2099
- /**
2100
- @alias module:Jqgrid_utils
2101
- @param {object} - col_model for the grid
2102
- @param {string} - field what include the image/picture href path like http://mypicture.png
2103
- @param {int} - size of the picture
2104
- @param {bolen} - image path should be a link
2105
- @example
2106
- col_model = await jqu.add_image(col_model, image_field, 60, false);
2107
- */
2108
- async add_image(col_model, edit_field, size, link = false) {
2109
- if (size === undefined) {
2110
- size = 60;
2111
- }
2112
- for (let i = 0; i < col_model.length; i++) {
2113
- if (col_model[i]["name"] === edit_field) {
2114
- col_model[i]["picture"] = true;
2115
- col_model[i]["width"] = size;
2116
- col_model[i]["height"] = size;
2117
- col_model[i]["formatter"] = function (cell_val) {
2118
- const cell_val2 = cell_val.toLowerCase();
2119
-
2120
- if (
2121
- cell_val2.startsWith("https://", 0) ||
2122
- cell_val2.startsWith("http://", 0)
2123
- ) {
2124
- if (
2125
- cell_val2.includes(".png") ||
2126
- cell_val2.includes(".jpg") ||
2127
- cell_val2.includes(".jpeg") ||
2128
- cell_val2.includes(".gif") ||
2129
- cell_val2.includes(".svg") ||
2130
- cell_val2.includes(".svgz") ||
2131
- cell_val2.includes(".webp")
2132
- ) {
2133
- if (link) {
2134
- return (
2135
- '<a target="blank" href="' +
2136
- cell_val +
2137
- '"><img src="' +
2138
- cell_val +
2139
- '" alt="my image" width="' +
2140
- size +
2141
- '" /></a>'
2142
- );
2143
- } else {
2144
- return (
2145
- '<img src="' +
2146
- cell_val +
2147
- '" alt="my image" width="' +
2148
- size +
2149
- '" />'
2150
- );
2151
- }
2152
- }
2153
- }
2154
- return cell_val;
2155
- };
2156
- }
2157
- }
2158
- return col_model;
2159
- }
2160
-
2161
- /**
2162
- * Add a filter to the website beside the grid
2163
- @alias module:Jqgrid_utils
2164
- @param {object} - grid object or grid string name
2165
- @param {object} - the grid data object
2166
- @param {object} - a dict with a array what should be filterd by the grid
2167
- @param {string} - id name of the DOM oject where the filter should be appened
2168
- @example
2169
- var jqu = new Jqgrid_utils();
2170
- var run_me_once = true;
2171
- gridComplete: async function(){
2172
- if(run_me_once)
2173
- {
2174
- await jqu.set_filter(this, data, {material:[],section:[]}, '#filter');
2175
- run_me_once = false;
2176
- }
2177
- },
2178
- */
2179
- async set_filter(grid, data, fx, append_to = "#filter") {
2180
- jQuery(grid).jqGrid("setGridParam", { fdata: data });
2181
- let f = document.querySelector(append_to);
2182
- for (const i in data) {
2183
- for (let x in fx) {
2184
- fx[x].push(data[i][x]);
2185
- }
2186
- }
2187
-
2188
- for (let x in fx) {
2189
- fx[x] = fx[x].filter((val, ind, arr) => arr.indexOf(val) === ind);
2190
- fx[x].sort();
2191
- }
2192
-
2193
- for (let x in fx) {
2194
- let ul = document.createElement("ul");
2195
- let lh = document.createElement("lh");
2196
- lh.innerHTML = x;
2197
- ul.appendChild(lh);
2198
- for (let i in fx[x]) {
2199
- let li = document.createElement("li");
2200
- let l = document.createElement("label");
2201
- l.innerHTML = fx[x][i];
2202
- let c = document.createElement("input");
2203
- c.setAttribute("type", "checkbox");
2204
- c.setAttribute("class", x);
2205
- c.setAttribute("id", x + "_" + fx[x][i]);
2206
- l.setAttribute("for", x + "_" + fx[x][i]);
2207
- c.value = fx[x][i];
2208
- c.onchange = async () => {
2209
- await this._filter(grid, fx);
2210
- };
2211
- li.appendChild(l);
2212
- li.appendChild(c);
2213
- ul.appendChild(li);
2214
- }
2215
- f.appendChild(ul);
2216
- }
2217
- }
2218
-
2219
- /**
2220
- * private function of set_filter
2221
- @alias module:Jqgrid_utils
2222
- */
2223
- async _filter(grid, fx) {
2224
- let _data = [];
2225
- let data = jQuery(grid).jqGrid("getGridParam", "fdata");
2226
- let filter = [];
2227
- for (let x in fx) {
2228
- let m = document.querySelectorAll("." + x);
2229
- filter[x] = [];
2230
- for (let i in m) {
2231
- if (m[i].checked) {
2232
- filter[x].push(m[i].value);
2233
- }
2234
- }
2235
- }
2236
- for (let i in data) {
2237
- let include = false;
2238
- for (let x in fx) {
2239
- if (filter[x].indexOf(data[i][x]) != -1) {
2240
- include = true;
2241
- }
2242
- }
2243
- if (include) {
2244
- _data.push(data[i]);
2245
- }
2246
- }
2247
- jQuery(grid).jqGrid("clearGridData");
2248
- jQuery(grid).jqGrid("setGridParam", { data: _data });
2249
- jQuery(grid).trigger("reloadGrid");
2250
- }
2251
- };
2252
-
2253
- },{}]},{},[1])(1)
2254
- });
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)});