jqgrid_utils 1.30.0 → 1.30.3

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