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