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