jqgrid_utils 1.1.2 → 1.1.5

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 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
@@ -35,3 +34,22 @@ Discover All Functions:
35
34
  await gu.grid_set_captain(_grid, data);
36
35
  }
37
36
  ```
37
+
38
+ ## Functions:
39
+
40
+ ### add grid_load_complete to don't show the delete icon
41
+ ```javascript
42
+ loadComplete: async function(data)
43
+ {
44
+ jqu.s_hide_del_icon();
45
+ grid_load_complete;
46
+ },
47
+ ```
48
+
49
+ ```javascript
50
+ loadComplete: async function(data)
51
+ {
52
+ await jqu.hide_del_icon();
53
+ grid_load_complete;
54
+ },
55
+ ```
@@ -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);
@@ -97,6 +98,282 @@ module.exports = class Vanilla_website_utils
97
98
 
98
99
 
99
100
 
101
+
102
+ async upsert_row(row, url, req = {})
103
+ {
104
+ if (row.rowid.startsWith('jqg'))
105
+ {
106
+ const r0 = await this.insert_row(row, url);
107
+ return r0;
108
+ }
109
+ else
110
+ {
111
+ const r1 = await this.update_row(row, url);
112
+ return r1;
113
+ }
114
+ }
115
+
116
+
117
+ async insert_row(row, url)
118
+ {
119
+ let req = {};
120
+ let ret = '';
121
+ if (row.inputData.hasOwnProperty('id'))
122
+ {
123
+ req['_id'] = 'id';
124
+ req['_id_val'] = row.inputData['id'];
125
+ for (let i in row.inputData)
126
+ {
127
+ req[i] = row.inputData[i];
128
+ }
129
+ delete req['id'];
130
+ delete req['oper'];
131
+ //console.log(req);
132
+ ret = await this.put_json(url, JSON.stringify(req));
133
+ }
134
+ return ret;
135
+ }
136
+
137
+
138
+
139
+ async update_row(row, url, req = {})
140
+ {
141
+ let ret = '';
142
+ {
143
+ if(! req['_id'])
144
+ {
145
+ req['_id'] = 'id';
146
+ }
147
+ req['_id_val'] = row.inputData['id'];
148
+ for (let i in row.inputData)
149
+ {
150
+ req[i] = row.inputData[i];
151
+ }
152
+ delete req['id'];
153
+ delete req['oper'];
154
+ ret = await this.post_json(url, JSON.stringify(req));
155
+ }
156
+ return ret;
157
+ }
158
+
159
+
160
+ async delete_row(_id, url)
161
+ {
162
+ let ret = '';
163
+ if (url.indexOf('?') > -1)
164
+ {
165
+ url += "&_id=" + encodeURIComponent(unescape(_id));
166
+ }
167
+ else
168
+ {
169
+ url += "?_id=" + encodeURIComponent(unescape(_id));
170
+ }
171
+
172
+ ret = JSON.parse(await this.adelete_api(url));
173
+ return ret['message'];
174
+ }
175
+
176
+
177
+
178
+ async adelete_api(url, json = false)
179
+ {
180
+ const ctype = json ? "application/json;charset=UTF-8" : "application/x-www-form-urlencoded";
181
+ return new Promise((resolve, reject) =>
182
+ {
183
+ let xhr = new XMLHttpRequest();
184
+ xhr.open("DELETE", url);
185
+ xhr.setRequestHeader("Content-type", ctype);
186
+ xhr.onload = () => resolve(xhr.responseText);
187
+ xhr.onerror = () => reject(xhr.statusText);
188
+ xhr.send(null);
189
+ });
190
+ }
191
+
192
+
193
+ async post_json(url, data)
194
+ {
195
+ return new Promise((resolve, reject) =>
196
+ {
197
+ let xhr = new XMLHttpRequest();
198
+ xhr.open("POST", url);
199
+ xhr.setRequestHeader("Content-type", "application/json");
200
+ xhr.onload = () => resolve(xhr.responseText);
201
+ xhr.onerror = () => reject(xhr.statusText);
202
+ xhr.send(data);
203
+ });
204
+ }
205
+
206
+ async put_json(url, data)
207
+ {
208
+ return new Promise((resolve, reject) =>
209
+ {
210
+ let xhr = new XMLHttpRequest();
211
+ xhr.open("PUT", url);
212
+ xhr.setRequestHeader("Content-type", "application/json");
213
+ xhr.onload = () => resolve(xhr.responseText);
214
+ xhr.onerror = () => reject(xhr.statusText);
215
+ xhr.send(data);
216
+ });
217
+ }
218
+
219
+
220
+ s_hide_del_icon()
221
+ {
222
+ hide_del_icon();
223
+ }
224
+
225
+ async hide_del_icon()
226
+ {
227
+ jQuery('.ui-inline-del').each(function(index) {jQuery(this).html('');});
228
+ }
229
+
230
+
231
+
232
+
233
+
234
+
235
+ async add_link_details(col_model, url, edit_field, attr = '', keys, format)
236
+ {
237
+
238
+ if (url.indexOf('?') > -1)
239
+ {
240
+ url = url + '&';
241
+ }
242
+ else
243
+ {
244
+ url = url + '?';
245
+ }
246
+
247
+ for (let i = 0; i < col_model.length; i++)
248
+ {
249
+ if (col_model[i]['name'] === edit_field)
250
+ {
251
+ col_model[i]['formatter'] = function(cell_val, obj)
252
+ {
253
+ let key_val = cell_val;
254
+
255
+ if (typeof keys === 'object')
256
+ {
257
+ let pref = '';
258
+ for (i in keys)
259
+ {
260
+ let key = i;
261
+ let v = keys[i];
262
+ key_val = obj.rowData[v];
263
+ if (key_val)
264
+ {
265
+ if (key_val)
266
+ {
267
+ if (key.indexOf('=') !== -1)
268
+ {
269
+ pref = pref + '' + key + '' + encodeURIComponent(key_val) + '&';
270
+ }
271
+ else
272
+ {
273
+ pref = pref + '' + key + '=' + encodeURIComponent(key_val) + '&';
274
+ }
275
+ }
276
+ }
277
+ }
278
+ if (pref)
279
+ {
280
+ if (pref.slice(-1) === '&')
281
+ {
282
+ pref = pref.slice(0, -1);
283
+ }
284
+ if (format == 'format_ok')
285
+ {
286
+
287
+ if (cell_val == 0 || cell_val === 'fail')
288
+ {
289
+ cell_val = '<i class="fa fa-times-circle" aria-hidden="true" style="color:#ff0000;"></i>';
290
+ }
291
+ else
292
+ {
293
+ cell_val = '<i class="fa fa-check-circle" aria-hidden="true" style="color:#008000;"></i>';
294
+ }
295
+ }
296
+
297
+
298
+ cell_val = '<a ' + attr + 'href="' + url + pref + '"> ' + cell_val + '</a>';
299
+ }
300
+
301
+ }
302
+
303
+ return cell_val;
304
+ };
305
+ }
306
+
307
+ }
308
+
309
+ return col_model;
310
+ }
311
+
312
+
313
+
314
+ async add_link_details_separator(col_model, url, edit_field, attr = '', keys)
315
+ {
316
+
317
+ url = url + '/';
318
+
319
+
320
+ for (let i = 0; i < col_model.length; i++)
321
+ {
322
+ if (col_model[i]['name'] === edit_field)
323
+ {
324
+ col_model[i]['formatter'] = function(cell_val, obj)
325
+ {
326
+ let key_val = cell_val;
327
+
328
+ if (typeof keys === 'object')
329
+ {
330
+ let pref = '';
331
+ for (i in keys)
332
+ {
333
+ let key = i;
334
+ let v = keys[i];
335
+ key_val = obj.rowData[v];
336
+ if (key_val)
337
+ {
338
+ if (key_val)
339
+ {
340
+ pref = pref + '' + '/' + encodeURIComponent(key_val) + '&';
341
+ }
342
+ }
343
+ }
344
+ if (pref)
345
+ {
346
+ if (pref.slice(-1) === '&')
347
+ {
348
+ pref = pref.slice(0, -1);
349
+ }
350
+
351
+ cell_val = '<a ' + attr + 'href="' + url + pref + '"> ' + cell_val + '</a>';
352
+ }
353
+
354
+ }
355
+
356
+ return cell_val;
357
+ };
358
+ }
359
+
360
+ }
361
+
362
+ return col_model;
363
+ }
364
+
365
+
366
+
367
+
368
+
369
+
370
+
371
+
372
+
373
+
374
+
375
+
376
+
100
377
  };
101
378
 
102
379
 
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);
@@ -96,6 +97,282 @@ module.exports = class Vanilla_website_utils
96
97
 
97
98
 
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
+
233
+
234
+ async add_link_details(col_model, url, edit_field, attr = '', keys, format)
235
+ {
236
+
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
+ if (format == 'format_ok')
284
+ {
285
+
286
+ if (cell_val == 0 || cell_val === 'fail')
287
+ {
288
+ cell_val = '<i class="fa fa-times-circle" aria-hidden="true" style="color:#ff0000;"></i>';
289
+ }
290
+ else
291
+ {
292
+ cell_val = '<i class="fa fa-check-circle" aria-hidden="true" style="color:#008000;"></i>';
293
+ }
294
+ }
295
+
296
+
297
+ cell_val = '<a ' + attr + 'href="' + url + pref + '"> ' + cell_val + '</a>';
298
+ }
299
+
300
+ }
301
+
302
+ return cell_val;
303
+ };
304
+ }
305
+
306
+ }
307
+
308
+ return col_model;
309
+ }
310
+
311
+
312
+
313
+ async add_link_details_separator(col_model, url, edit_field, attr = '', keys)
314
+ {
315
+
316
+ url = url + '/';
317
+
318
+
319
+ for (let i = 0; i < col_model.length; i++)
320
+ {
321
+ if (col_model[i]['name'] === edit_field)
322
+ {
323
+ col_model[i]['formatter'] = function(cell_val, obj)
324
+ {
325
+ let key_val = cell_val;
326
+
327
+ if (typeof keys === 'object')
328
+ {
329
+ let pref = '';
330
+ for (i in keys)
331
+ {
332
+ let key = i;
333
+ let v = keys[i];
334
+ key_val = obj.rowData[v];
335
+ if (key_val)
336
+ {
337
+ if (key_val)
338
+ {
339
+ pref = pref + '' + '/' + encodeURIComponent(key_val) + '&';
340
+ }
341
+ }
342
+ }
343
+ if (pref)
344
+ {
345
+ if (pref.slice(-1) === '&')
346
+ {
347
+ pref = pref.slice(0, -1);
348
+ }
349
+
350
+ cell_val = '<a ' + attr + 'href="' + url + pref + '"> ' + cell_val + '</a>';
351
+ }
352
+
353
+ }
354
+
355
+ return cell_val;
356
+ };
357
+ }
358
+
359
+ }
360
+
361
+ return col_model;
362
+ }
363
+
364
+
365
+
366
+
367
+
368
+
369
+
370
+
371
+
372
+
373
+
374
+
375
+
99
376
  };
100
377
 
101
378
 
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.2"
31
+ "version": "1.1.5"
32
32
  }