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