jqgrid_utils 1.1.7 → 1.1.8

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.
@@ -382,6 +382,29 @@ __cell_format(cell_value, format)
382
382
 
383
383
 
384
384
 
385
+ // let data_url = api + '/style_row?f=data&style=';
386
+ // let col_model_url = api + '/style_row?f=col_model';
387
+ // await jqu.subgrid(_id, id, data_url, col_model_url);
388
+ async subgrid(_id, id, data_url, col_model_url)
389
+ {
390
+ let col_model = JSON.parse(await aget_api(col_model_url));
391
+ let url = data_url + id;
392
+ let $s1 = jQuery("<table id='" + _id + "_t'></table>");
393
+ let data = jQuery(this).getLocalRow(id);
394
+ $s1.appendTo("#" + jQuery.jgrid.jqID(_id));
395
+ $s1.jqGrid({
396
+ colModel: col_model,
397
+ datatype: "json",
398
+ url: url,
399
+ gridview: true,
400
+ rownumbers: true,
401
+ autoencode: true,
402
+ sortname: "c1",
403
+ sortorder: "desc",
404
+ caption: data.name
405
+ });
406
+ }
407
+
385
408
 
386
409
 
387
410
  };
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.7"
31
+ "version": "1.1.8"
32
32
  }
package/.tern-port DELETED
@@ -1 +0,0 @@
1
- 46471
package/jqgrid_utils.js~ DELETED
@@ -1,388 +0,0 @@
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~ DELETED
@@ -1,32 +0,0 @@
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
- }