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