jqgrid_utils 1.2.0 → 1.2.3

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
@@ -54,20 +54,130 @@ Discover All Functions:
54
54
  },
55
55
  ```
56
56
 
57
- <a name="subgrid"></a>
57
+ <a name="module_Vanilla_website_utils"></a>
58
+
59
+ ## Vanilla\_website\_utils
60
+ A module for Vanilla_website_utils
61
+
62
+
63
+ * [Vanilla_website_utils](#module_Vanilla_website_utils)
64
+ * [module.exports#set_link()](#exp_module_Vanilla_website_utils--module.exports+set_link) ⏏
65
+ * [module.exports#grid_set_captain()](#exp_module_Vanilla_website_utils--module.exports+grid_set_captain) ⏏
66
+ * [module.exports#resize_saved_cell_width()](#exp_module_Vanilla_website_utils--module.exports+resize_saved_cell_width) ⏏
67
+ * [module.exports#resize_cell()](#exp_module_Vanilla_website_utils--module.exports+resize_cell) ⏏
68
+ * [module.exports#upsert_row()](#exp_module_Vanilla_website_utils--module.exports+upsert_row) ⏏
69
+ * [module.exports#insert_row()](#exp_module_Vanilla_website_utils--module.exports+insert_row) ⏏
70
+ * [module.exports#update_row()](#exp_module_Vanilla_website_utils--module.exports+update_row) ⏏
71
+ * [module.exports#delete_row()](#exp_module_Vanilla_website_utils--module.exports+delete_row) ⏏
72
+ * [module.exports#adelete_api()](#exp_module_Vanilla_website_utils--module.exports+adelete_api) ⏏
73
+ * [module.exports#post_json()](#exp_module_Vanilla_website_utils--module.exports+post_json) ⏏
74
+ * [module.exports#put_json()](#exp_module_Vanilla_website_utils--module.exports+put_json) ⏏
75
+ * [module.exports#hide_del_icon()](#exp_module_Vanilla_website_utils--module.exports+hide_del_icon) ⏏
76
+ * [module.exports#add_link_details()](#exp_module_Vanilla_website_utils--module.exports+add_link_details) ⏏
77
+ * [module.exports#add_link_details_separator()](#exp_module_Vanilla_website_utils--module.exports+add_link_details_separator) ⏏
78
+ * [module.exports#__cell_format()](#exp_module_Vanilla_website_utils--module.exports+__cell_format) ⏏
79
+ * [module.exports#subgrid(_id, id, data_url, col_model)](#exp_module_Vanilla_website_utils--module.exports+subgrid) ⏏
80
+ * [module.exports#add_image(col_model, edit_field, size, link)](#exp_module_Vanilla_website_utils--module.exports+add_image) ⏏
81
+
82
+ <a name="exp_module_Vanilla_website_utils--module.exports+set_link"></a>
83
+
84
+ ### module.exports#set\_link() ⏏
85
+ **Kind**: Exported function
86
+ <a name="exp_module_Vanilla_website_utils--module.exports+grid_set_captain"></a>
87
+
88
+ ### module.exports#grid\_set\_captain() ⏏
89
+ **Kind**: Exported function
90
+ <a name="exp_module_Vanilla_website_utils--module.exports+resize_saved_cell_width"></a>
91
+
92
+ ### module.exports#resize\_saved\_cell\_width() ⏏
93
+ **Kind**: Exported function
94
+ <a name="exp_module_Vanilla_website_utils--module.exports+resize_cell"></a>
95
+
96
+ ### module.exports#resize\_cell() ⏏
97
+ **Kind**: Exported function
98
+ <a name="exp_module_Vanilla_website_utils--module.exports+upsert_row"></a>
99
+
100
+ ### module.exports#upsert\_row() ⏏
101
+ **Kind**: Exported function
102
+ <a name="exp_module_Vanilla_website_utils--module.exports+insert_row"></a>
103
+
104
+ ### module.exports#insert\_row() ⏏
105
+ **Kind**: Exported function
106
+ <a name="exp_module_Vanilla_website_utils--module.exports+update_row"></a>
107
+
108
+ ### module.exports#update\_row() ⏏
109
+ **Kind**: Exported function
110
+ <a name="exp_module_Vanilla_website_utils--module.exports+delete_row"></a>
111
+
112
+ ### module.exports#delete\_row() ⏏
113
+ **Kind**: Exported function
114
+ <a name="exp_module_Vanilla_website_utils--module.exports+adelete_api"></a>
115
+
116
+ ### module.exports#adelete\_api() ⏏
117
+ **Kind**: Exported function
118
+ <a name="exp_module_Vanilla_website_utils--module.exports+post_json"></a>
119
+
120
+ ### module.exports#post\_json() ⏏
121
+ **Kind**: Exported function
122
+ <a name="exp_module_Vanilla_website_utils--module.exports+put_json"></a>
123
+
124
+ ### module.exports#put\_json() ⏏
125
+ **Kind**: Exported function
126
+ <a name="exp_module_Vanilla_website_utils--module.exports+hide_del_icon"></a>
127
+
128
+ ### module.exports#hide\_del\_icon() ⏏
129
+ **Kind**: Exported function
130
+ <a name="exp_module_Vanilla_website_utils--module.exports+add_link_details"></a>
131
+
132
+ ### module.exports#add\_link\_details() ⏏
133
+ **Kind**: Exported function
134
+ **Example**
135
+ ```js
136
+ // example: col_model = await jqu.add_link_details(col_model,'http://foo.bar'' , 'target_field','target="_blank"',{"key":"field1","key":"field2"});
137
+ ```
138
+ <a name="exp_module_Vanilla_website_utils--module.exports+add_link_details_separator"></a>
139
+
140
+ ### module.exports#add\_link\_details\_separator() ⏏
141
+ **Kind**: Exported function
142
+ **Example**
143
+ ```js
144
+ // col_model = await jqu.add_link_details_separator(col_model, 'https://foo.com' , 'couchdb','target="_blank"',{"mykey":"myval"});
145
+ ```
146
+ <a name="exp_module_Vanilla_website_utils--module.exports+__cell_format"></a>
58
147
 
59
- ## subgrid(_id, id, data_url)
60
- **Kind**: global function
148
+ ### module.exports#\_\_cell\_format()
149
+ **Kind**: Exported function
150
+ <a name="exp_module_Vanilla_website_utils--module.exports+subgrid"></a>
151
+
152
+ ### module.exports#subgrid(_id, id, data_url, col_model) ⏏
153
+ **Kind**: Exported function
61
154
 
62
155
  | Param | Type | Description |
63
156
  | --- | --- | --- |
64
157
  | _id | <code>string</code> | row_id |
65
158
  | id | <code>string</code> | data id |
66
159
  | data_url | <code>object</code> | col_model for the table |
160
+ | col_model | <code>string</code> | Caption |
67
161
 
68
162
  **Example**
69
163
  ```js
70
164
  let data_url = api + '/phone_detail?f=data&_id=';
71
- let col_model_url = api + '/phone_detail?f=col_model';
72
- let col_model = JSON.parse(await vwu.aget_api(col_model_url));
165
+ let col_model_url = api + '/phone_detail?f=col_model';
166
+ let col_model = JSON.parse(await vwu.aget_api(col_model_url))
167
+ ```
168
+ <a name="exp_module_Vanilla_website_utils--module.exports+add_image"></a>
169
+
170
+ ### module.exports#add\_image(col_model, edit_field, size, link) ⏏
171
+ **Kind**: Exported function
172
+
173
+ | Param | Type | Default | Description |
174
+ | --- | --- | --- | --- |
175
+ | col_model | <code>object</code> | | col_model for the grid |
176
+ | edit_field | <code>string</code> | | field what include the image/picture href path like http://mypicture.png |
177
+ | size | <code>int</code> | | size of the picture |
178
+ | link | <code>bolen</code> | <code>false</code> | image path should be a link |
179
+
180
+ **Example**
181
+ ```js
182
+ col_model = await jqu.add_image(col_model, 'image', 60, false);
73
183
  ```
package/_README.md ADDED
@@ -0,0 +1,56 @@
1
+ # Jqgrid_utils
2
+ Convenient Functions for free jqGrid
3
+
4
+ Demo:
5
+ https://jqgrid_utils.calantas.org
6
+
7
+ # Example Usage:
8
+
9
+ Add a the library to your website
10
+
11
+ ``
12
+ `html
13
+ <script src="../node_modules/jqgrid_utils/dist/jqgrid_utils.js"></script>
14
+ `
15
+ ``
16
+
17
+
18
+ Example Usage:
19
+ ```javascript
20
+
21
+ ```
22
+
23
+ Discover All Functions:
24
+
25
+ * To add the Qty of rows to the Caption text
26
+ * grid_set_captain(_grid, data)
27
+ * _grid: the DOM ID of grid(type: string), example: '#grid'
28
+ * data: the grid data(type: array) (Optional)
29
+ * example:
30
+ ```javascript
31
+ let gu = new Jqgrid_utils();
32
+ loadComplete: function(data)
33
+ {
34
+ await gu.grid_set_captain(_grid, data);
35
+ }
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
+ ```
56
+
@@ -1,4 +1,9 @@
1
1
  (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Jqgrid_utils = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
2
+ /**
3
+ * A module for Vanilla_website_utils
4
+ * @module Vanilla_website_utils
5
+ */
6
+
2
7
  'use strict';
3
8
 
4
9
  module.exports = class Vanilla_website_utils
@@ -22,7 +27,9 @@ module.exports = class Vanilla_website_utils
22
27
  this.set_link(col_model, edit_field, url ,attr);
23
28
  }
24
29
 
25
-
30
+ /**
31
+ @alias module:Vanilla_website_utils
32
+ */
26
33
  async set_link(col_model, edit_field, url ,attr='')
27
34
  {
28
35
  for(let i=0;i< col_model.length;i++)
@@ -44,6 +51,9 @@ module.exports = class Vanilla_website_utils
44
51
  this.grid_set_captain(_grid, data=[]);
45
52
  }
46
53
 
54
+ /**
55
+ @alias module:Vanilla_website_utils
56
+ */
47
57
  async grid_set_captain(_grid, data=[])
48
58
  {
49
59
  const grid = jQuery(_grid);
@@ -68,7 +78,9 @@ module.exports = class Vanilla_website_utils
68
78
  {
69
79
  this.grid_set_captain(col_model, page, grid);
70
80
  }
71
-
81
+ /**
82
+ @alias module:Vanilla_website_utils
83
+ */
72
84
  async resize_saved_cell_width(col_model,page=false, grid=false)
73
85
  {
74
86
  let key = page ? page : this.page;
@@ -84,7 +96,9 @@ module.exports = class Vanilla_website_utils
84
96
  return col_model;
85
97
  }
86
98
 
87
-
99
+ /**
100
+ @alias module:Vanilla_website_utils
101
+ */
88
102
  resize_cell(width, index, _page=false)
89
103
  {
90
104
  const page = _page ? _page : localStorage.getItem('page');
@@ -98,7 +112,9 @@ module.exports = class Vanilla_website_utils
98
112
 
99
113
 
100
114
 
101
-
115
+ /**
116
+ @alias module:Vanilla_website_utils
117
+ */
102
118
  async upsert_row(row, url, req = {})
103
119
  {
104
120
  if (row.rowid.startsWith('jqg'))
@@ -113,7 +129,9 @@ async upsert_row(row, url, req = {})
113
129
  }
114
130
  }
115
131
 
116
-
132
+ /**
133
+ @alias module:Vanilla_website_utils
134
+ */
117
135
  async insert_row(row, url)
118
136
  {
119
137
  let req = {};
@@ -135,7 +153,9 @@ async insert_row(row, url)
135
153
  }
136
154
 
137
155
 
138
-
156
+ /**
157
+ @alias module:Vanilla_website_utils
158
+ */
139
159
  async update_row(row, url, req = {})
140
160
  {
141
161
  let ret = '';
@@ -156,7 +176,9 @@ async update_row(row, url, req = {})
156
176
  return ret;
157
177
  }
158
178
 
159
-
179
+ /**
180
+ @alias module:Vanilla_website_utils
181
+ */
160
182
  async delete_row(_id, url)
161
183
  {
162
184
  let ret = '';
@@ -174,7 +196,9 @@ async delete_row(_id, url)
174
196
  }
175
197
 
176
198
 
177
-
199
+ /**
200
+ @alias module:Vanilla_website_utils
201
+ */
178
202
  async adelete_api(url, json = false)
179
203
  {
180
204
  const ctype = json ? "application/json;charset=UTF-8" : "application/x-www-form-urlencoded";
@@ -190,6 +214,9 @@ async adelete_api(url, json = false)
190
214
  }
191
215
 
192
216
 
217
+ /**
218
+ @alias module:Vanilla_website_utils
219
+ */
193
220
  async post_json(url, data)
194
221
  {
195
222
  return new Promise((resolve, reject) =>
@@ -203,6 +230,9 @@ async post_json(url, data)
203
230
  });
204
231
  }
205
232
 
233
+ /**
234
+ @alias module:Vanilla_website_utils
235
+ */
206
236
  async put_json(url, data)
207
237
  {
208
238
  return new Promise((resolve, reject) =>
@@ -222,6 +252,9 @@ s_hide_del_icon()
222
252
  hide_del_icon();
223
253
  }
224
254
 
255
+ /**
256
+ @alias module:Vanilla_website_utils
257
+ */
225
258
  async hide_del_icon()
226
259
  {
227
260
  jQuery('.ui-inline-del').each(function(index) {jQuery(this).html('');});
@@ -229,8 +262,11 @@ async hide_del_icon()
229
262
 
230
263
 
231
264
 
232
-
265
+ /**
266
+ @alias module:Vanilla_website_utils
267
+ @example
233
268
  // example: col_model = await jqu.add_link_details(col_model,'http://foo.bar'' , 'target_field','target="_blank"',{"key":"field1","key":"field2"});
269
+ */
234
270
  async add_link_details(col_model, url, edit_field, attr = '', keys, format)
235
271
  {
236
272
  let self = this;
@@ -298,8 +334,11 @@ async add_link_details(col_model, url, edit_field, attr = '', keys, format)
298
334
  }
299
335
 
300
336
 
301
-
302
- // examplecol_model = await jqu.add_link_details_separator(col_model, 'https://foo.com' , 'couchdb','target="_blank"',{"mykey":"myval"});
337
+ /**
338
+ @alias module:Vanilla_website_utils
339
+ @example
340
+ // col_model = await jqu.add_link_details_separator(col_model, 'https://foo.com' , 'couchdb','target="_blank"',{"mykey":"myval"});
341
+ */
303
342
  async add_link_details_separator(col_model, url, edit_field, attr = '', keys, format)
304
343
  {
305
344
  url = url + '/';
@@ -362,7 +401,9 @@ async add_link_details_separator(col_model, url, edit_field, attr = '', keys, fo
362
401
 
363
402
 
364
403
 
365
-
404
+ /**
405
+ @alias module:Vanilla_website_utils
406
+ */
366
407
  __cell_format(cell_value, format)
367
408
  {
368
409
  if (format == 'format_ok')
@@ -382,20 +423,24 @@ __cell_format(cell_value, format)
382
423
 
383
424
 
384
425
  /**
426
+ @alias module:Vanilla_website_utils
385
427
  @param {string} - row_id
386
428
  @param {string} - data id
387
429
  @param {object} - col_model for the table
430
+ @param {string} - Caption
388
431
  @example
389
432
  * let data_url = api + '/phone_detail?f=data&_id=';
390
433
  * let col_model_url = api + '/phone_detail?f=col_model';
391
434
  * let col_model = JSON.parse(await vwu.aget_api(col_model_url))
392
435
  */
393
- async subgrid(_id, id, data_url, col_model)
436
+ async subgrid(_id, id, data_url, col_model, caption='' )
394
437
  {
438
+ caption = caption != '' ? caption + ' ' : '';
395
439
  let url = data_url + id;
396
- let $s1 = jQuery("<table id='" + _id + "_t'></table>");
440
+ let $s1 = jQuery("<table style='margin: 5px 0' class='" + _id + "_t'></table>");
397
441
  $s1.appendTo("#" + jQuery.jgrid.jqID(_id));
398
442
  $s1.jqGrid({
443
+ caption: caption + id,
399
444
  colModel: col_model,
400
445
  datatype: "json",
401
446
  url: url,
@@ -403,12 +448,50 @@ async subgrid(_id, id, data_url, col_model)
403
448
  rownumbers: true,
404
449
  autoencode: true,
405
450
  sortname: "c1",
406
- sortorder: "desc",
407
- caption: id
451
+ sortorder: "desc"
408
452
  });
409
453
  }
410
454
 
411
455
 
456
+ /**
457
+ @alias module:Vanilla_website_utils
458
+ @param {object} - col_model for the grid
459
+ @param {string} - field what include the image/picture href path like http://mypicture.png
460
+ @param {int} - size of the picture
461
+ @param {bolen} - image path should be a link
462
+ @example
463
+ * col_model = await jqu.add_image(col_model, 'image', 60, false);
464
+ */
465
+ async add_image(col_model, edit_field, size, link=false)
466
+ {
467
+ if (size === undefined)
468
+ {
469
+ size = 60;
470
+ }
471
+ for (let i = 0; i < col_model.length; i++)
472
+ {
473
+ if (col_model[i]['name'] === edit_field)
474
+ {
475
+ col_model[i]['picture'] = true;
476
+ col_model[i]['width'] = size;
477
+ col_model[i]['height'] = size;
478
+ col_model[i]['formatter'] = function(cell_val)
479
+ {
480
+ if(link)
481
+ {
482
+ return '<a target="blank" href="' + cell_val + '"><img src="' + cell_val + '" alt="my image" width="' + size + '" /></a>';
483
+ }
484
+ else
485
+ {
486
+ return '<img src="' + cell_val + '" alt="my image" width="' + size + '" />';
487
+ }
488
+ };
489
+ }
490
+ }
491
+ return col_model;
492
+ }
493
+
494
+
412
495
 
413
496
  };
414
497
 
package/jqgrid_utils.js CHANGED
@@ -1,3 +1,8 @@
1
+ /**
2
+ * A module for Vanilla_website_utils
3
+ * @module Vanilla_website_utils
4
+ */
5
+
1
6
  'use strict';
2
7
 
3
8
  module.exports = class Vanilla_website_utils
@@ -21,7 +26,9 @@ module.exports = class Vanilla_website_utils
21
26
  this.set_link(col_model, edit_field, url ,attr);
22
27
  }
23
28
 
24
-
29
+ /**
30
+ @alias module:Vanilla_website_utils
31
+ */
25
32
  async set_link(col_model, edit_field, url ,attr='')
26
33
  {
27
34
  for(let i=0;i< col_model.length;i++)
@@ -43,6 +50,9 @@ module.exports = class Vanilla_website_utils
43
50
  this.grid_set_captain(_grid, data=[]);
44
51
  }
45
52
 
53
+ /**
54
+ @alias module:Vanilla_website_utils
55
+ */
46
56
  async grid_set_captain(_grid, data=[])
47
57
  {
48
58
  const grid = jQuery(_grid);
@@ -67,7 +77,9 @@ module.exports = class Vanilla_website_utils
67
77
  {
68
78
  this.grid_set_captain(col_model, page, grid);
69
79
  }
70
-
80
+ /**
81
+ @alias module:Vanilla_website_utils
82
+ */
71
83
  async resize_saved_cell_width(col_model,page=false, grid=false)
72
84
  {
73
85
  let key = page ? page : this.page;
@@ -83,7 +95,9 @@ module.exports = class Vanilla_website_utils
83
95
  return col_model;
84
96
  }
85
97
 
86
-
98
+ /**
99
+ @alias module:Vanilla_website_utils
100
+ */
87
101
  resize_cell(width, index, _page=false)
88
102
  {
89
103
  const page = _page ? _page : localStorage.getItem('page');
@@ -97,7 +111,9 @@ module.exports = class Vanilla_website_utils
97
111
 
98
112
 
99
113
 
100
-
114
+ /**
115
+ @alias module:Vanilla_website_utils
116
+ */
101
117
  async upsert_row(row, url, req = {})
102
118
  {
103
119
  if (row.rowid.startsWith('jqg'))
@@ -112,7 +128,9 @@ async upsert_row(row, url, req = {})
112
128
  }
113
129
  }
114
130
 
115
-
131
+ /**
132
+ @alias module:Vanilla_website_utils
133
+ */
116
134
  async insert_row(row, url)
117
135
  {
118
136
  let req = {};
@@ -134,7 +152,9 @@ async insert_row(row, url)
134
152
  }
135
153
 
136
154
 
137
-
155
+ /**
156
+ @alias module:Vanilla_website_utils
157
+ */
138
158
  async update_row(row, url, req = {})
139
159
  {
140
160
  let ret = '';
@@ -155,7 +175,9 @@ async update_row(row, url, req = {})
155
175
  return ret;
156
176
  }
157
177
 
158
-
178
+ /**
179
+ @alias module:Vanilla_website_utils
180
+ */
159
181
  async delete_row(_id, url)
160
182
  {
161
183
  let ret = '';
@@ -173,7 +195,9 @@ async delete_row(_id, url)
173
195
  }
174
196
 
175
197
 
176
-
198
+ /**
199
+ @alias module:Vanilla_website_utils
200
+ */
177
201
  async adelete_api(url, json = false)
178
202
  {
179
203
  const ctype = json ? "application/json;charset=UTF-8" : "application/x-www-form-urlencoded";
@@ -189,6 +213,9 @@ async adelete_api(url, json = false)
189
213
  }
190
214
 
191
215
 
216
+ /**
217
+ @alias module:Vanilla_website_utils
218
+ */
192
219
  async post_json(url, data)
193
220
  {
194
221
  return new Promise((resolve, reject) =>
@@ -202,6 +229,9 @@ async post_json(url, data)
202
229
  });
203
230
  }
204
231
 
232
+ /**
233
+ @alias module:Vanilla_website_utils
234
+ */
205
235
  async put_json(url, data)
206
236
  {
207
237
  return new Promise((resolve, reject) =>
@@ -221,6 +251,9 @@ s_hide_del_icon()
221
251
  hide_del_icon();
222
252
  }
223
253
 
254
+ /**
255
+ @alias module:Vanilla_website_utils
256
+ */
224
257
  async hide_del_icon()
225
258
  {
226
259
  jQuery('.ui-inline-del').each(function(index) {jQuery(this).html('');});
@@ -228,8 +261,11 @@ async hide_del_icon()
228
261
 
229
262
 
230
263
 
231
-
264
+ /**
265
+ @alias module:Vanilla_website_utils
266
+ @example
232
267
  // example: col_model = await jqu.add_link_details(col_model,'http://foo.bar'' , 'target_field','target="_blank"',{"key":"field1","key":"field2"});
268
+ */
233
269
  async add_link_details(col_model, url, edit_field, attr = '', keys, format)
234
270
  {
235
271
  let self = this;
@@ -297,8 +333,11 @@ async add_link_details(col_model, url, edit_field, attr = '', keys, format)
297
333
  }
298
334
 
299
335
 
300
-
301
- // examplecol_model = await jqu.add_link_details_separator(col_model, 'https://foo.com' , 'couchdb','target="_blank"',{"mykey":"myval"});
336
+ /**
337
+ @alias module:Vanilla_website_utils
338
+ @example
339
+ // col_model = await jqu.add_link_details_separator(col_model, 'https://foo.com' , 'couchdb','target="_blank"',{"mykey":"myval"});
340
+ */
302
341
  async add_link_details_separator(col_model, url, edit_field, attr = '', keys, format)
303
342
  {
304
343
  url = url + '/';
@@ -361,7 +400,9 @@ async add_link_details_separator(col_model, url, edit_field, attr = '', keys, fo
361
400
 
362
401
 
363
402
 
364
-
403
+ /**
404
+ @alias module:Vanilla_website_utils
405
+ */
365
406
  __cell_format(cell_value, format)
366
407
  {
367
408
  if (format == 'format_ok')
@@ -381,20 +422,24 @@ __cell_format(cell_value, format)
381
422
 
382
423
 
383
424
  /**
425
+ @alias module:Vanilla_website_utils
384
426
  @param {string} - row_id
385
427
  @param {string} - data id
386
428
  @param {object} - col_model for the table
429
+ @param {string} - Caption
387
430
  @example
388
431
  * let data_url = api + '/phone_detail?f=data&_id=';
389
432
  * let col_model_url = api + '/phone_detail?f=col_model';
390
433
  * let col_model = JSON.parse(await vwu.aget_api(col_model_url))
391
434
  */
392
- async subgrid(_id, id, data_url, col_model)
435
+ async subgrid(_id, id, data_url, col_model, caption='' )
393
436
  {
437
+ caption = caption != '' ? caption + ' ' : '';
394
438
  let url = data_url + id;
395
- let $s1 = jQuery("<table id='" + _id + "_t'></table>");
439
+ let $s1 = jQuery("<table style='margin: 5px 0' class='" + _id + "_t'></table>");
396
440
  $s1.appendTo("#" + jQuery.jgrid.jqID(_id));
397
441
  $s1.jqGrid({
442
+ caption: caption + id,
398
443
  colModel: col_model,
399
444
  datatype: "json",
400
445
  url: url,
@@ -402,12 +447,50 @@ async subgrid(_id, id, data_url, col_model)
402
447
  rownumbers: true,
403
448
  autoencode: true,
404
449
  sortname: "c1",
405
- sortorder: "desc",
406
- caption: id
450
+ sortorder: "desc"
407
451
  });
408
452
  }
409
453
 
410
454
 
455
+ /**
456
+ @alias module:Vanilla_website_utils
457
+ @param {object} - col_model for the grid
458
+ @param {string} - field what include the image/picture href path like http://mypicture.png
459
+ @param {int} - size of the picture
460
+ @param {bolen} - image path should be a link
461
+ @example
462
+ * col_model = await jqu.add_image(col_model, 'image', 60, false);
463
+ */
464
+ async add_image(col_model, edit_field, size, link=false)
465
+ {
466
+ if (size === undefined)
467
+ {
468
+ size = 60;
469
+ }
470
+ for (let i = 0; i < col_model.length; i++)
471
+ {
472
+ if (col_model[i]['name'] === edit_field)
473
+ {
474
+ col_model[i]['picture'] = true;
475
+ col_model[i]['width'] = size;
476
+ col_model[i]['height'] = size;
477
+ col_model[i]['formatter'] = function(cell_val)
478
+ {
479
+ if(link)
480
+ {
481
+ return '<a target="blank" href="' + cell_val + '"><img src="' + cell_val + '" alt="my image" width="' + size + '" /></a>';
482
+ }
483
+ else
484
+ {
485
+ return '<img src="' + cell_val + '" alt="my image" width="' + size + '" />';
486
+ }
487
+ };
488
+ }
489
+ }
490
+ return col_model;
491
+ }
492
+
493
+
411
494
 
412
495
  };
413
496
 
package/make_doc.sh ADDED
@@ -0,0 +1,4 @@
1
+ #!/bin/bash
2
+
3
+ cp _README.md README.md
4
+ jsdoc2md jqgrid_utils.js >> README.md
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "author":
3
3
  {
4
- "name": "veto@myridia.com"
4
+ "name": "veto@myridia.com",
5
+ "url": "https://www.npmjs.com/package/jqgrid_utils"
5
6
  },
6
7
  "dependencies":
7
8
  {},
@@ -28,5 +29,5 @@
28
29
  {
29
30
  "test": "echo \"Error: no test specified\" && exit 1"
30
31
  },
31
- "version": "1.2.0"
32
+ "version": "1.2.3"
32
33
  }