jqgrid_utils 1.1.4 → 1.1.7

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/.tern-port ADDED
@@ -0,0 +1 @@
1
+ 46471
package/README.md CHANGED
@@ -1,10 +1,9 @@
1
- # Vanilla - website - utils
1
+ # Jqgrid_utils
2
2
  Convenient Functions for free jqGrid
3
3
 
4
4
  Demo:
5
5
  https://jqgrid_utils.calantas.org
6
6
 
7
-
8
7
  # Example Usage:
9
8
 
10
9
  Add a the library to your website
@@ -43,6 +43,7 @@ module.exports = class Vanilla_website_utils
43
43
  {
44
44
  this.grid_set_captain(_grid, data=[]);
45
45
  }
46
+
46
47
  async grid_set_captain(_grid, data=[])
47
48
  {
48
49
  const grid = jQuery(_grid);
@@ -226,6 +227,163 @@ async hide_del_icon()
226
227
  jQuery('.ui-inline-del').each(function(index) {jQuery(this).html('');});
227
228
  }
228
229
 
230
+
231
+
232
+
233
+ // example: col_model = await jqu.add_link_details(col_model,'http://foo.bar'' , 'target_field','target="_blank"',{"key":"field1","key":"field2"});
234
+ async add_link_details(col_model, url, edit_field, attr = '', keys, format)
235
+ {
236
+ let self = this;
237
+ if (url.indexOf('?') > -1)
238
+ {
239
+ url = url + '&';
240
+ }
241
+ else
242
+ {
243
+ url = url + '?';
244
+ }
245
+
246
+ for (let i = 0; i < col_model.length; i++)
247
+ {
248
+ if (col_model[i]['name'] === edit_field)
249
+ {
250
+ col_model[i]['formatter'] = function(cell_val, obj)
251
+ {
252
+ let key_val = cell_val;
253
+
254
+ if (typeof keys === 'object')
255
+ {
256
+ let pref = '';
257
+ for (i in keys)
258
+ {
259
+ let key = i;
260
+ let v = keys[i];
261
+ key_val = obj.rowData[v];
262
+ if (key_val)
263
+ {
264
+ if (key_val)
265
+ {
266
+ if (key.indexOf('=') !== -1)
267
+ {
268
+ pref = pref + '' + key + '' + encodeURIComponent(key_val) + '&';
269
+ }
270
+ else
271
+ {
272
+ pref = pref + '' + key + '=' + encodeURIComponent(key_val) + '&';
273
+ }
274
+ }
275
+ }
276
+ }
277
+ if (pref)
278
+ {
279
+ if (pref.slice(-1) === '&')
280
+ {
281
+ pref = pref.slice(0, -1);
282
+ }
283
+
284
+ const _cell_val = self.__cell_format(cell_val, format);
285
+
286
+ cell_val = '<a ' + attr + 'href="' + url + pref + '"> ' + _cell_val + '</a>';
287
+ }
288
+
289
+ }
290
+
291
+ return cell_val;
292
+ };
293
+ }
294
+
295
+ }
296
+
297
+ return col_model;
298
+ }
299
+
300
+
301
+
302
+ // examplecol_model = await jqu.add_link_details_separator(col_model, 'https://foo.com' , 'couchdb','target="_blank"',{"mykey":"myval"});
303
+ async add_link_details_separator(col_model, url, edit_field, attr = '', keys, format)
304
+ {
305
+ url = url + '/';
306
+ let self = this;
307
+ for (let i = 0; i < col_model.length; i++)
308
+ {
309
+ if (col_model[i]['name'] === edit_field)
310
+ {
311
+ col_model[i]['formatter'] = function(cell_val, obj)
312
+ {
313
+ let key_val = cell_val;
314
+
315
+ if (typeof keys === 'object')
316
+ {
317
+ let pref = '';
318
+ for (i in keys)
319
+ {
320
+
321
+ let key = i;
322
+ let v = keys[i];
323
+ key_val = obj.rowData[v];
324
+ if (key_val)
325
+ {
326
+ if (key_val)
327
+ {
328
+ if(key != '')
329
+ {
330
+ pref += key + '' + '/' + encodeURIComponent(key_val);
331
+ }
332
+ else
333
+ {
334
+ pref += encodeURIComponent(key_val);
335
+ }
336
+ }
337
+ }
338
+ }
339
+ if (pref)
340
+ {
341
+ if (pref.slice(-1) === '&')
342
+ {
343
+ pref = pref.slice(0, -1);
344
+ }
345
+ const _cell_val = self.__cell_format(cell_val, format);
346
+ cell_val = '<a ' + attr + 'href="' + url + pref + '"> ' + _cell_val + '</a>';
347
+ }
348
+
349
+ }
350
+
351
+ return cell_val;
352
+ };
353
+ }
354
+
355
+ }
356
+
357
+ return col_model;
358
+ }
359
+
360
+
361
+
362
+
363
+
364
+
365
+
366
+ __cell_format(cell_value, format)
367
+ {
368
+ if (format == 'format_ok')
369
+ {
370
+ if (cell_value == 0 || cell_value === 'fail')
371
+ {
372
+ cell_value = '<i class="fa fa-times-circle" aria-hidden="true" style="color:#ff0000;"></i>';
373
+ }
374
+ else
375
+ {
376
+ cell_value = '<i class="fa fa-check-circle" aria-hidden="true" style="color:#008000;"></i>';
377
+ }
378
+ }
379
+ return cell_value;
380
+ }
381
+
382
+
383
+
384
+
385
+
386
+
229
387
  };
230
388
 
231
389
 
package/jqgrid_utils.js CHANGED
@@ -42,6 +42,7 @@ module.exports = class Vanilla_website_utils
42
42
  {
43
43
  this.grid_set_captain(_grid, data=[]);
44
44
  }
45
+
45
46
  async grid_set_captain(_grid, data=[])
46
47
  {
47
48
  const grid = jQuery(_grid);
@@ -225,6 +226,186 @@ async hide_del_icon()
225
226
  jQuery('.ui-inline-del').each(function(index) {jQuery(this).html('');});
226
227
  }
227
228
 
229
+
230
+
231
+
232
+ // example: col_model = await jqu.add_link_details(col_model,'http://foo.bar'' , 'target_field','target="_blank"',{"key":"field1","key":"field2"});
233
+ async add_link_details(col_model, url, edit_field, attr = '', keys, format)
234
+ {
235
+ let self = this;
236
+ if (url.indexOf('?') > -1)
237
+ {
238
+ url = url + '&';
239
+ }
240
+ else
241
+ {
242
+ url = url + '?';
243
+ }
244
+
245
+ for (let i = 0; i < col_model.length; i++)
246
+ {
247
+ if (col_model[i]['name'] === edit_field)
248
+ {
249
+ col_model[i]['formatter'] = function(cell_val, obj)
250
+ {
251
+ let key_val = cell_val;
252
+
253
+ if (typeof keys === 'object')
254
+ {
255
+ let pref = '';
256
+ for (i in keys)
257
+ {
258
+ let key = i;
259
+ let v = keys[i];
260
+ key_val = obj.rowData[v];
261
+ if (key_val)
262
+ {
263
+ if (key_val)
264
+ {
265
+ if (key.indexOf('=') !== -1)
266
+ {
267
+ pref = pref + '' + key + '' + encodeURIComponent(key_val) + '&';
268
+ }
269
+ else
270
+ {
271
+ pref = pref + '' + key + '=' + encodeURIComponent(key_val) + '&';
272
+ }
273
+ }
274
+ }
275
+ }
276
+ if (pref)
277
+ {
278
+ if (pref.slice(-1) === '&')
279
+ {
280
+ pref = pref.slice(0, -1);
281
+ }
282
+
283
+ const _cell_val = self.__cell_format(cell_val, format);
284
+
285
+ cell_val = '<a ' + attr + 'href="' + url + pref + '"> ' + _cell_val + '</a>';
286
+ }
287
+
288
+ }
289
+
290
+ return cell_val;
291
+ };
292
+ }
293
+
294
+ }
295
+
296
+ return col_model;
297
+ }
298
+
299
+
300
+
301
+ // examplecol_model = await jqu.add_link_details_separator(col_model, 'https://foo.com' , 'couchdb','target="_blank"',{"mykey":"myval"});
302
+ async add_link_details_separator(col_model, url, edit_field, attr = '', keys, format)
303
+ {
304
+ url = url + '/';
305
+ let self = this;
306
+ for (let i = 0; i < col_model.length; i++)
307
+ {
308
+ if (col_model[i]['name'] === edit_field)
309
+ {
310
+ col_model[i]['formatter'] = function(cell_val, obj)
311
+ {
312
+ let key_val = cell_val;
313
+
314
+ if (typeof keys === 'object')
315
+ {
316
+ let pref = '';
317
+ for (i in keys)
318
+ {
319
+
320
+ let key = i;
321
+ let v = keys[i];
322
+ key_val = obj.rowData[v];
323
+ if (key_val)
324
+ {
325
+ if (key_val)
326
+ {
327
+ if(key != '')
328
+ {
329
+ pref += key + '' + '/' + encodeURIComponent(key_val);
330
+ }
331
+ else
332
+ {
333
+ pref += encodeURIComponent(key_val);
334
+ }
335
+ }
336
+ }
337
+ }
338
+ if (pref)
339
+ {
340
+ if (pref.slice(-1) === '&')
341
+ {
342
+ pref = pref.slice(0, -1);
343
+ }
344
+ const _cell_val = self.__cell_format(cell_val, format);
345
+ cell_val = '<a ' + attr + 'href="' + url + pref + '"> ' + _cell_val + '</a>';
346
+ }
347
+
348
+ }
349
+
350
+ return cell_val;
351
+ };
352
+ }
353
+
354
+ }
355
+
356
+ return col_model;
357
+ }
358
+
359
+
360
+
361
+
362
+
363
+
364
+
365
+ __cell_format(cell_value, format)
366
+ {
367
+ if (format == 'format_ok')
368
+ {
369
+ if (cell_value == 0 || cell_value === 'fail')
370
+ {
371
+ cell_value = '<i class="fa fa-times-circle" aria-hidden="true" style="color:#ff0000;"></i>';
372
+ }
373
+ else
374
+ {
375
+ cell_value = '<i class="fa fa-check-circle" aria-hidden="true" style="color:#008000;"></i>';
376
+ }
377
+ }
378
+ return cell_value;
379
+ }
380
+
381
+
382
+
383
+
384
+ // let data_url = api + '/style_row?f=data&style=';
385
+ // let col_model_url = api + '/style_row?f=col_model';
386
+ // await jqu.subgrid(_id, id, data_url, col_model_url);
387
+ async subgrid(_id, id, data_url, col_model_url)
388
+ {
389
+ let col_model = JSON.parse(await aget_api(col_model_url));
390
+ let url = data_url + id;
391
+ let $s1 = jQuery("<table id='" + _id + "_t'></table>");
392
+ let data = jQuery(this).getLocalRow(id);
393
+ $s1.appendTo("#" + jQuery.jgrid.jqID(_id));
394
+ $s1.jqGrid({
395
+ colModel: col_model,
396
+ datatype: "json",
397
+ url: url,
398
+ gridview: true,
399
+ rownumbers: true,
400
+ autoencode: true,
401
+ sortname: "c1",
402
+ sortorder: "desc",
403
+ caption: data.name
404
+ });
405
+ }
406
+
407
+
408
+
228
409
  };
229
410
 
230
411
 
@@ -0,0 +1,388 @@
1
+ 'use strict';
2
+
3
+ module.exports = class Vanilla_website_utils
4
+ {
5
+
6
+ constructor(settings=false)
7
+ {
8
+ if(settings)
9
+ {
10
+ if(settings.hasOwnProperty('page'))
11
+ {
12
+ this.page = settings['page'];
13
+ localStorage.setItem('page', this.page);
14
+ }
15
+ }
16
+
17
+ }
18
+
19
+ async s_set_link(col_model, edit_field, url ,attr='')
20
+ {
21
+ this.set_link(col_model, edit_field, url ,attr);
22
+ }
23
+
24
+
25
+ async set_link(col_model, edit_field, url ,attr='')
26
+ {
27
+ for(let i=0;i< col_model.length;i++)
28
+ {
29
+ if(col_model[i]['name'] === edit_field)
30
+ {
31
+ col_model[i]['formatter'] = function (cell_val,o)
32
+ {
33
+ return '<a class="gl" ' + attr + 'href="' + o.rowData[url] + '">'+ cell_val +'</a>';
34
+ };
35
+ }
36
+ }
37
+ return col_model;
38
+ }
39
+
40
+
41
+ s_grid_set_captain(_grid, data=[])
42
+ {
43
+ this.grid_set_captain(_grid, data=[]);
44
+ }
45
+
46
+ async grid_set_captain(_grid, data=[])
47
+ {
48
+ const grid = jQuery(_grid);
49
+ let count = 0;
50
+ if(data.length === 0)
51
+ {
52
+ count = grid.jqGrid('getGridParam', 'records');
53
+ }
54
+ else
55
+ {
56
+ count = data.length;
57
+ }
58
+ let caption = grid.jqGrid("getGridParam", "caption");
59
+ if(caption.indexOf(count+'x') === -1 )
60
+ {
61
+ grid.jqGrid('setCaption', caption + ' - ' + count + 'x');
62
+ }
63
+ }
64
+
65
+
66
+ s_resize_saved_cell_width(col_model, page=false, grid=false)
67
+ {
68
+ this.grid_set_captain(col_model, page, grid);
69
+ }
70
+
71
+ async resize_saved_cell_width(col_model,page=false, grid=false)
72
+ {
73
+ let key = page ? page : this.page;
74
+ key += grid ? '-' + grid + '-w-' : '-grid-w-';
75
+ for(let x = 0; x<= col_model.length; x++)
76
+ {
77
+ const width = localStorage.getItem(key + x);
78
+ if(width)
79
+ {
80
+ col_model[x]['width'] = width;
81
+ }
82
+ }
83
+ return col_model;
84
+ }
85
+
86
+
87
+ resize_cell(width, index, _page=false)
88
+ {
89
+ const page = _page ? _page : localStorage.getItem('page');
90
+ const grid = this.id;
91
+ let idx = index-1;
92
+ let key = page + '-' + grid + '-w-' + idx;
93
+ localStorage.setItem(key, width);
94
+ const cat = localStorage.getItem(key);
95
+ console.log(key);
96
+ }
97
+
98
+
99
+
100
+
101
+ async upsert_row(row, url, req = {})
102
+ {
103
+ if (row.rowid.startsWith('jqg'))
104
+ {
105
+ const r0 = await this.insert_row(row, url);
106
+ return r0;
107
+ }
108
+ else
109
+ {
110
+ const r1 = await this.update_row(row, url);
111
+ return r1;
112
+ }
113
+ }
114
+
115
+
116
+ async insert_row(row, url)
117
+ {
118
+ let req = {};
119
+ let ret = '';
120
+ if (row.inputData.hasOwnProperty('id'))
121
+ {
122
+ req['_id'] = 'id';
123
+ req['_id_val'] = row.inputData['id'];
124
+ for (let i in row.inputData)
125
+ {
126
+ req[i] = row.inputData[i];
127
+ }
128
+ delete req['id'];
129
+ delete req['oper'];
130
+ //console.log(req);
131
+ ret = await this.put_json(url, JSON.stringify(req));
132
+ }
133
+ return ret;
134
+ }
135
+
136
+
137
+
138
+ async update_row(row, url, req = {})
139
+ {
140
+ let ret = '';
141
+ {
142
+ if(! req['_id'])
143
+ {
144
+ req['_id'] = 'id';
145
+ }
146
+ req['_id_val'] = row.inputData['id'];
147
+ for (let i in row.inputData)
148
+ {
149
+ req[i] = row.inputData[i];
150
+ }
151
+ delete req['id'];
152
+ delete req['oper'];
153
+ ret = await this.post_json(url, JSON.stringify(req));
154
+ }
155
+ return ret;
156
+ }
157
+
158
+
159
+ async delete_row(_id, url)
160
+ {
161
+ let ret = '';
162
+ if (url.indexOf('?') > -1)
163
+ {
164
+ url += "&_id=" + encodeURIComponent(unescape(_id));
165
+ }
166
+ else
167
+ {
168
+ url += "?_id=" + encodeURIComponent(unescape(_id));
169
+ }
170
+
171
+ ret = JSON.parse(await this.adelete_api(url));
172
+ return ret['message'];
173
+ }
174
+
175
+
176
+
177
+ async adelete_api(url, json = false)
178
+ {
179
+ const ctype = json ? "application/json;charset=UTF-8" : "application/x-www-form-urlencoded";
180
+ return new Promise((resolve, reject) =>
181
+ {
182
+ let xhr = new XMLHttpRequest();
183
+ xhr.open("DELETE", url);
184
+ xhr.setRequestHeader("Content-type", ctype);
185
+ xhr.onload = () => resolve(xhr.responseText);
186
+ xhr.onerror = () => reject(xhr.statusText);
187
+ xhr.send(null);
188
+ });
189
+ }
190
+
191
+
192
+ async post_json(url, data)
193
+ {
194
+ return new Promise((resolve, reject) =>
195
+ {
196
+ let xhr = new XMLHttpRequest();
197
+ xhr.open("POST", url);
198
+ xhr.setRequestHeader("Content-type", "application/json");
199
+ xhr.onload = () => resolve(xhr.responseText);
200
+ xhr.onerror = () => reject(xhr.statusText);
201
+ xhr.send(data);
202
+ });
203
+ }
204
+
205
+ async put_json(url, data)
206
+ {
207
+ return new Promise((resolve, reject) =>
208
+ {
209
+ let xhr = new XMLHttpRequest();
210
+ xhr.open("PUT", url);
211
+ xhr.setRequestHeader("Content-type", "application/json");
212
+ xhr.onload = () => resolve(xhr.responseText);
213
+ xhr.onerror = () => reject(xhr.statusText);
214
+ xhr.send(data);
215
+ });
216
+ }
217
+
218
+
219
+ s_hide_del_icon()
220
+ {
221
+ hide_del_icon();
222
+ }
223
+
224
+ async hide_del_icon()
225
+ {
226
+ jQuery('.ui-inline-del').each(function(index) {jQuery(this).html('');});
227
+ }
228
+
229
+
230
+
231
+
232
+ // example: col_model = await jqu.add_link_details(col_model,'http://foo.bar'' , 'target_field','target="_blank"',{"key":"field1","key":"field2"});
233
+ async add_link_details(col_model, url, edit_field, attr = '', keys, format)
234
+ {
235
+ let self = this;
236
+ if (url.indexOf('?') > -1)
237
+ {
238
+ url = url + '&';
239
+ }
240
+ else
241
+ {
242
+ url = url + '?';
243
+ }
244
+
245
+ for (let i = 0; i < col_model.length; i++)
246
+ {
247
+ if (col_model[i]['name'] === edit_field)
248
+ {
249
+ col_model[i]['formatter'] = function(cell_val, obj)
250
+ {
251
+ let key_val = cell_val;
252
+
253
+ if (typeof keys === 'object')
254
+ {
255
+ let pref = '';
256
+ for (i in keys)
257
+ {
258
+ let key = i;
259
+ let v = keys[i];
260
+ key_val = obj.rowData[v];
261
+ if (key_val)
262
+ {
263
+ if (key_val)
264
+ {
265
+ if (key.indexOf('=') !== -1)
266
+ {
267
+ pref = pref + '' + key + '' + encodeURIComponent(key_val) + '&';
268
+ }
269
+ else
270
+ {
271
+ pref = pref + '' + key + '=' + encodeURIComponent(key_val) + '&';
272
+ }
273
+ }
274
+ }
275
+ }
276
+ if (pref)
277
+ {
278
+ if (pref.slice(-1) === '&')
279
+ {
280
+ pref = pref.slice(0, -1);
281
+ }
282
+
283
+ const _cell_val = self.__cell_format(cell_val, format);
284
+
285
+ cell_val = '<a ' + attr + 'href="' + url + pref + '"> ' + _cell_val + '</a>';
286
+ }
287
+
288
+ }
289
+
290
+ return cell_val;
291
+ };
292
+ }
293
+
294
+ }
295
+
296
+ return col_model;
297
+ }
298
+
299
+
300
+
301
+ // examplecol_model = await jqu.add_link_details_separator(col_model, 'https://foo.com' , 'couchdb','target="_blank"',{"mykey":"myval"});
302
+ async add_link_details_separator(col_model, url, edit_field, attr = '', keys, format)
303
+ {
304
+ url = url + '/';
305
+ let self = this;
306
+ for (let i = 0; i < col_model.length; i++)
307
+ {
308
+ if (col_model[i]['name'] === edit_field)
309
+ {
310
+ col_model[i]['formatter'] = function(cell_val, obj)
311
+ {
312
+ let key_val = cell_val;
313
+
314
+ if (typeof keys === 'object')
315
+ {
316
+ let pref = '';
317
+ for (i in keys)
318
+ {
319
+
320
+ let key = i;
321
+ let v = keys[i];
322
+ key_val = obj.rowData[v];
323
+ if (key_val)
324
+ {
325
+ if (key_val)
326
+ {
327
+ if(key != '')
328
+ {
329
+ pref += key + '' + '/' + encodeURIComponent(key_val);
330
+ }
331
+ else
332
+ {
333
+ pref += encodeURIComponent(key_val);
334
+ }
335
+ }
336
+ }
337
+ }
338
+ if (pref)
339
+ {
340
+ if (pref.slice(-1) === '&')
341
+ {
342
+ pref = pref.slice(0, -1);
343
+ }
344
+ const _cell_val = self.__cell_format(cell_val, format);
345
+ cell_val = '<a ' + attr + 'href="' + url + pref + '"> ' + _cell_val + '</a>';
346
+ }
347
+
348
+ }
349
+
350
+ return cell_val;
351
+ };
352
+ }
353
+
354
+ }
355
+
356
+ return col_model;
357
+ }
358
+
359
+
360
+
361
+
362
+
363
+
364
+
365
+ __cell_format(cell_value, format)
366
+ {
367
+ if (format == 'format_ok')
368
+ {
369
+ if (cell_value == 0 || cell_value === 'fail')
370
+ {
371
+ cell_value = '<i class="fa fa-times-circle" aria-hidden="true" style="color:#ff0000;"></i>';
372
+ }
373
+ else
374
+ {
375
+ cell_value = '<i class="fa fa-check-circle" aria-hidden="true" style="color:#008000;"></i>';
376
+ }
377
+ }
378
+ return cell_value;
379
+ }
380
+
381
+
382
+
383
+
384
+
385
+
386
+ };
387
+
388
+
package/package.json CHANGED
@@ -28,5 +28,5 @@
28
28
  {
29
29
  "test": "echo \"Error: no test specified\" && exit 1"
30
30
  },
31
- "version": "1.1.4"
31
+ "version": "1.1.7"
32
32
  }
package/package.json~ ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "author":
3
+ {
4
+ "name": "veto@myridia.com"
5
+ },
6
+ "dependencies":
7
+ {},
8
+ "deprecated": false,
9
+ "description": "Convenient Functions for the Free jqGrid",
10
+ "homepage": "http://calantas.org/jqgrid_utils",
11
+ "license": "GPL-3.0-or-later",
12
+ "main": "jqgrid_utils.js",
13
+ "name": "jqgrid_utils",
14
+ "keywords": [
15
+ "jqgrid",
16
+ "free-jqgrid",
17
+ "utilities",
18
+ "helpers",
19
+ "utils",
20
+ "extend-jqgrid"
21
+ ],
22
+ "repository":
23
+ {
24
+ "type": "hg",
25
+ "url": "https://calantas.org/jqgrid_utils"
26
+ },
27
+ "scripts":
28
+ {
29
+ "test": "echo \"Error: no test specified\" && exit 1"
30
+ },
31
+ "version": "1.1.6"
32
+ }