jqgrid_utils 1.2.1 → 1.2.4
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 +115 -5
- package/_README.md +56 -0
- package/dist/jqgrid_utils.js +136 -25
- package/jqgrid_utils.js +136 -25
- package/make_doc.sh +4 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -54,20 +54,130 @@ Discover All Functions:
|
|
|
54
54
|
},
|
|
55
55
|
```
|
|
56
56
|
|
|
57
|
-
<a name="
|
|
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
|
-
|
|
60
|
-
**Kind**:
|
|
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
|
+
|
package/dist/jqgrid_utils.js
CHANGED
|
@@ -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);
|
|
@@ -69,36 +79,70 @@ module.exports = class Vanilla_website_utils
|
|
|
69
79
|
this.grid_set_captain(col_model, page, grid);
|
|
70
80
|
}
|
|
71
81
|
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
@alias module:Vanilla_website_utils
|
|
85
|
+
@param {object} - col_model for the grid
|
|
86
|
+
@param {string} - page
|
|
87
|
+
@param {object} - grid
|
|
88
|
+
@example
|
|
89
|
+
* col_model = await jqu.resize_saved_cell_width(col_model);
|
|
90
|
+
*/
|
|
72
91
|
async resize_saved_cell_width(col_model,page=false, grid=false)
|
|
73
92
|
{
|
|
74
93
|
let key = page ? page : this.page;
|
|
75
94
|
key += grid ? '-' + grid + '-w-' : '-grid-w-';
|
|
76
95
|
for(let x = 0; x<= col_model.length; x++)
|
|
77
96
|
{
|
|
78
|
-
|
|
79
|
-
if(width)
|
|
97
|
+
if(col_model[x])
|
|
80
98
|
{
|
|
81
|
-
col_model[x]['
|
|
99
|
+
if(col_model[x]['name'])
|
|
100
|
+
{
|
|
101
|
+
const name = col_model[x]['name'];
|
|
102
|
+
const width = localStorage.getItem(key + name);
|
|
103
|
+
if(width)
|
|
104
|
+
{
|
|
105
|
+
col_model[x]['width'] = width;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
82
108
|
}
|
|
83
109
|
}
|
|
84
110
|
return col_model;
|
|
85
111
|
}
|
|
86
112
|
|
|
87
|
-
|
|
113
|
+
/**
|
|
114
|
+
@alias module:Vanilla_website_utils
|
|
115
|
+
* resize_cell
|
|
116
|
+
* call after resize a column
|
|
117
|
+
@param {string} - width - the size of the resized column
|
|
118
|
+
@param {string} - index - column number what get resized
|
|
119
|
+
@param {string} - _page - not in use yet
|
|
120
|
+
@example
|
|
121
|
+
* var jqu = new Jqgrid_utils({page:'mypage'});
|
|
122
|
+
* resizeStop: jqu.resize_cell,
|
|
123
|
+
*/
|
|
88
124
|
resize_cell(width, index, _page=false)
|
|
89
125
|
{
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
126
|
+
const col_model = jQuery(this).jqGrid ('getGridParam', 'colModel');
|
|
127
|
+
if(col_model[index])
|
|
128
|
+
{
|
|
129
|
+
if(col_model[index]['name'])
|
|
130
|
+
{
|
|
131
|
+
const name = col_model[index]['name'];
|
|
132
|
+
const page = _page ? _page : localStorage.getItem('page');
|
|
133
|
+
const grid = this.id;
|
|
134
|
+
let key = page + '-' + grid + '-w-' + name;
|
|
135
|
+
localStorage.setItem(key, width);
|
|
136
|
+
const cat = localStorage.getItem(key);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
97
139
|
}
|
|
98
140
|
|
|
99
141
|
|
|
100
142
|
|
|
101
|
-
|
|
143
|
+
/**
|
|
144
|
+
@alias module:Vanilla_website_utils
|
|
145
|
+
*/
|
|
102
146
|
async upsert_row(row, url, req = {})
|
|
103
147
|
{
|
|
104
148
|
if (row.rowid.startsWith('jqg'))
|
|
@@ -113,7 +157,9 @@ async upsert_row(row, url, req = {})
|
|
|
113
157
|
}
|
|
114
158
|
}
|
|
115
159
|
|
|
116
|
-
|
|
160
|
+
/**
|
|
161
|
+
@alias module:Vanilla_website_utils
|
|
162
|
+
*/
|
|
117
163
|
async insert_row(row, url)
|
|
118
164
|
{
|
|
119
165
|
let req = {};
|
|
@@ -135,7 +181,9 @@ async insert_row(row, url)
|
|
|
135
181
|
}
|
|
136
182
|
|
|
137
183
|
|
|
138
|
-
|
|
184
|
+
/**
|
|
185
|
+
@alias module:Vanilla_website_utils
|
|
186
|
+
*/
|
|
139
187
|
async update_row(row, url, req = {})
|
|
140
188
|
{
|
|
141
189
|
let ret = '';
|
|
@@ -156,7 +204,9 @@ async update_row(row, url, req = {})
|
|
|
156
204
|
return ret;
|
|
157
205
|
}
|
|
158
206
|
|
|
159
|
-
|
|
207
|
+
/**
|
|
208
|
+
@alias module:Vanilla_website_utils
|
|
209
|
+
*/
|
|
160
210
|
async delete_row(_id, url)
|
|
161
211
|
{
|
|
162
212
|
let ret = '';
|
|
@@ -174,7 +224,9 @@ async delete_row(_id, url)
|
|
|
174
224
|
}
|
|
175
225
|
|
|
176
226
|
|
|
177
|
-
|
|
227
|
+
/**
|
|
228
|
+
@alias module:Vanilla_website_utils
|
|
229
|
+
*/
|
|
178
230
|
async adelete_api(url, json = false)
|
|
179
231
|
{
|
|
180
232
|
const ctype = json ? "application/json;charset=UTF-8" : "application/x-www-form-urlencoded";
|
|
@@ -190,6 +242,9 @@ async adelete_api(url, json = false)
|
|
|
190
242
|
}
|
|
191
243
|
|
|
192
244
|
|
|
245
|
+
/**
|
|
246
|
+
@alias module:Vanilla_website_utils
|
|
247
|
+
*/
|
|
193
248
|
async post_json(url, data)
|
|
194
249
|
{
|
|
195
250
|
return new Promise((resolve, reject) =>
|
|
@@ -203,6 +258,9 @@ async post_json(url, data)
|
|
|
203
258
|
});
|
|
204
259
|
}
|
|
205
260
|
|
|
261
|
+
/**
|
|
262
|
+
@alias module:Vanilla_website_utils
|
|
263
|
+
*/
|
|
206
264
|
async put_json(url, data)
|
|
207
265
|
{
|
|
208
266
|
return new Promise((resolve, reject) =>
|
|
@@ -222,6 +280,9 @@ s_hide_del_icon()
|
|
|
222
280
|
hide_del_icon();
|
|
223
281
|
}
|
|
224
282
|
|
|
283
|
+
/**
|
|
284
|
+
@alias module:Vanilla_website_utils
|
|
285
|
+
*/
|
|
225
286
|
async hide_del_icon()
|
|
226
287
|
{
|
|
227
288
|
jQuery('.ui-inline-del').each(function(index) {jQuery(this).html('');});
|
|
@@ -229,8 +290,11 @@ async hide_del_icon()
|
|
|
229
290
|
|
|
230
291
|
|
|
231
292
|
|
|
232
|
-
|
|
293
|
+
/**
|
|
294
|
+
@alias module:Vanilla_website_utils
|
|
295
|
+
@example
|
|
233
296
|
// example: col_model = await jqu.add_link_details(col_model,'http://foo.bar'' , 'target_field','target="_blank"',{"key":"field1","key":"field2"});
|
|
297
|
+
*/
|
|
234
298
|
async add_link_details(col_model, url, edit_field, attr = '', keys, format)
|
|
235
299
|
{
|
|
236
300
|
let self = this;
|
|
@@ -298,8 +362,11 @@ async add_link_details(col_model, url, edit_field, attr = '', keys, format)
|
|
|
298
362
|
}
|
|
299
363
|
|
|
300
364
|
|
|
301
|
-
|
|
302
|
-
|
|
365
|
+
/**
|
|
366
|
+
@alias module:Vanilla_website_utils
|
|
367
|
+
@example
|
|
368
|
+
// col_model = await jqu.add_link_details_separator(col_model, 'https://foo.com' , 'couchdb','target="_blank"',{"mykey":"myval"});
|
|
369
|
+
*/
|
|
303
370
|
async add_link_details_separator(col_model, url, edit_field, attr = '', keys, format)
|
|
304
371
|
{
|
|
305
372
|
url = url + '/';
|
|
@@ -362,7 +429,9 @@ async add_link_details_separator(col_model, url, edit_field, attr = '', keys, fo
|
|
|
362
429
|
|
|
363
430
|
|
|
364
431
|
|
|
365
|
-
|
|
432
|
+
/**
|
|
433
|
+
@alias module:Vanilla_website_utils
|
|
434
|
+
*/
|
|
366
435
|
__cell_format(cell_value, format)
|
|
367
436
|
{
|
|
368
437
|
if (format == 'format_ok')
|
|
@@ -382,20 +451,24 @@ __cell_format(cell_value, format)
|
|
|
382
451
|
|
|
383
452
|
|
|
384
453
|
/**
|
|
454
|
+
@alias module:Vanilla_website_utils
|
|
385
455
|
@param {string} - row_id
|
|
386
456
|
@param {string} - data id
|
|
387
457
|
@param {object} - col_model for the table
|
|
458
|
+
@param {string} - Caption
|
|
388
459
|
@example
|
|
389
460
|
* let data_url = api + '/phone_detail?f=data&_id=';
|
|
390
461
|
* let col_model_url = api + '/phone_detail?f=col_model';
|
|
391
462
|
* let col_model = JSON.parse(await vwu.aget_api(col_model_url))
|
|
392
463
|
*/
|
|
393
|
-
async subgrid(_id, id, data_url, col_model)
|
|
464
|
+
async subgrid(_id, id, data_url, col_model, caption='' )
|
|
394
465
|
{
|
|
466
|
+
caption = caption != '' ? caption + ' ' : '';
|
|
395
467
|
let url = data_url + id;
|
|
396
|
-
let $s1 = jQuery("<table
|
|
468
|
+
let $s1 = jQuery("<table style='margin: 5px 0' class='" + _id + "_t'></table>");
|
|
397
469
|
$s1.appendTo("#" + jQuery.jgrid.jqID(_id));
|
|
398
470
|
$s1.jqGrid({
|
|
471
|
+
caption: caption + id,
|
|
399
472
|
colModel: col_model,
|
|
400
473
|
datatype: "json",
|
|
401
474
|
url: url,
|
|
@@ -403,12 +476,50 @@ async subgrid(_id, id, data_url, col_model)
|
|
|
403
476
|
rownumbers: true,
|
|
404
477
|
autoencode: true,
|
|
405
478
|
sortname: "c1",
|
|
406
|
-
sortorder: "desc"
|
|
407
|
-
caption: id
|
|
479
|
+
sortorder: "desc"
|
|
408
480
|
});
|
|
409
481
|
}
|
|
410
482
|
|
|
411
483
|
|
|
484
|
+
/**
|
|
485
|
+
@alias module:Vanilla_website_utils
|
|
486
|
+
@param {object} - col_model for the grid
|
|
487
|
+
@param {string} - field what include the image/picture href path like http://mypicture.png
|
|
488
|
+
@param {int} - size of the picture
|
|
489
|
+
@param {bolen} - image path should be a link
|
|
490
|
+
@example
|
|
491
|
+
* col_model = await jqu.add_image(col_model, 'image', 60, false);
|
|
492
|
+
*/
|
|
493
|
+
async add_image(col_model, edit_field, size, link=false)
|
|
494
|
+
{
|
|
495
|
+
if (size === undefined)
|
|
496
|
+
{
|
|
497
|
+
size = 60;
|
|
498
|
+
}
|
|
499
|
+
for (let i = 0; i < col_model.length; i++)
|
|
500
|
+
{
|
|
501
|
+
if (col_model[i]['name'] === edit_field)
|
|
502
|
+
{
|
|
503
|
+
col_model[i]['picture'] = true;
|
|
504
|
+
col_model[i]['width'] = size;
|
|
505
|
+
col_model[i]['height'] = size;
|
|
506
|
+
col_model[i]['formatter'] = function(cell_val)
|
|
507
|
+
{
|
|
508
|
+
if(link)
|
|
509
|
+
{
|
|
510
|
+
return '<a target="blank" href="' + cell_val + '"><img src="' + cell_val + '" alt="my image" width="' + size + '" /></a>';
|
|
511
|
+
}
|
|
512
|
+
else
|
|
513
|
+
{
|
|
514
|
+
return '<img src="' + cell_val + '" alt="my image" width="' + size + '" />';
|
|
515
|
+
}
|
|
516
|
+
};
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
return col_model;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
|
|
412
523
|
|
|
413
524
|
};
|
|
414
525
|
|
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);
|
|
@@ -68,36 +78,70 @@ module.exports = class Vanilla_website_utils
|
|
|
68
78
|
this.grid_set_captain(col_model, page, grid);
|
|
69
79
|
}
|
|
70
80
|
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
@alias module:Vanilla_website_utils
|
|
84
|
+
@param {object} - col_model for the grid
|
|
85
|
+
@param {string} - page
|
|
86
|
+
@param {object} - grid
|
|
87
|
+
@example
|
|
88
|
+
* col_model = await jqu.resize_saved_cell_width(col_model);
|
|
89
|
+
*/
|
|
71
90
|
async resize_saved_cell_width(col_model,page=false, grid=false)
|
|
72
91
|
{
|
|
73
92
|
let key = page ? page : this.page;
|
|
74
93
|
key += grid ? '-' + grid + '-w-' : '-grid-w-';
|
|
75
94
|
for(let x = 0; x<= col_model.length; x++)
|
|
76
95
|
{
|
|
77
|
-
|
|
78
|
-
if(width)
|
|
96
|
+
if(col_model[x])
|
|
79
97
|
{
|
|
80
|
-
col_model[x]['
|
|
98
|
+
if(col_model[x]['name'])
|
|
99
|
+
{
|
|
100
|
+
const name = col_model[x]['name'];
|
|
101
|
+
const width = localStorage.getItem(key + name);
|
|
102
|
+
if(width)
|
|
103
|
+
{
|
|
104
|
+
col_model[x]['width'] = width;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
81
107
|
}
|
|
82
108
|
}
|
|
83
109
|
return col_model;
|
|
84
110
|
}
|
|
85
111
|
|
|
86
|
-
|
|
112
|
+
/**
|
|
113
|
+
@alias module:Vanilla_website_utils
|
|
114
|
+
* resize_cell
|
|
115
|
+
* call after resize a column
|
|
116
|
+
@param {string} - width - the size of the resized column
|
|
117
|
+
@param {string} - index - column number what get resized
|
|
118
|
+
@param {string} - _page - not in use yet
|
|
119
|
+
@example
|
|
120
|
+
* var jqu = new Jqgrid_utils({page:'mypage'});
|
|
121
|
+
* resizeStop: jqu.resize_cell,
|
|
122
|
+
*/
|
|
87
123
|
resize_cell(width, index, _page=false)
|
|
88
124
|
{
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
125
|
+
const col_model = jQuery(this).jqGrid ('getGridParam', 'colModel');
|
|
126
|
+
if(col_model[index])
|
|
127
|
+
{
|
|
128
|
+
if(col_model[index]['name'])
|
|
129
|
+
{
|
|
130
|
+
const name = col_model[index]['name'];
|
|
131
|
+
const page = _page ? _page : localStorage.getItem('page');
|
|
132
|
+
const grid = this.id;
|
|
133
|
+
let key = page + '-' + grid + '-w-' + name;
|
|
134
|
+
localStorage.setItem(key, width);
|
|
135
|
+
const cat = localStorage.getItem(key);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
96
138
|
}
|
|
97
139
|
|
|
98
140
|
|
|
99
141
|
|
|
100
|
-
|
|
142
|
+
/**
|
|
143
|
+
@alias module:Vanilla_website_utils
|
|
144
|
+
*/
|
|
101
145
|
async upsert_row(row, url, req = {})
|
|
102
146
|
{
|
|
103
147
|
if (row.rowid.startsWith('jqg'))
|
|
@@ -112,7 +156,9 @@ async upsert_row(row, url, req = {})
|
|
|
112
156
|
}
|
|
113
157
|
}
|
|
114
158
|
|
|
115
|
-
|
|
159
|
+
/**
|
|
160
|
+
@alias module:Vanilla_website_utils
|
|
161
|
+
*/
|
|
116
162
|
async insert_row(row, url)
|
|
117
163
|
{
|
|
118
164
|
let req = {};
|
|
@@ -134,7 +180,9 @@ async insert_row(row, url)
|
|
|
134
180
|
}
|
|
135
181
|
|
|
136
182
|
|
|
137
|
-
|
|
183
|
+
/**
|
|
184
|
+
@alias module:Vanilla_website_utils
|
|
185
|
+
*/
|
|
138
186
|
async update_row(row, url, req = {})
|
|
139
187
|
{
|
|
140
188
|
let ret = '';
|
|
@@ -155,7 +203,9 @@ async update_row(row, url, req = {})
|
|
|
155
203
|
return ret;
|
|
156
204
|
}
|
|
157
205
|
|
|
158
|
-
|
|
206
|
+
/**
|
|
207
|
+
@alias module:Vanilla_website_utils
|
|
208
|
+
*/
|
|
159
209
|
async delete_row(_id, url)
|
|
160
210
|
{
|
|
161
211
|
let ret = '';
|
|
@@ -173,7 +223,9 @@ async delete_row(_id, url)
|
|
|
173
223
|
}
|
|
174
224
|
|
|
175
225
|
|
|
176
|
-
|
|
226
|
+
/**
|
|
227
|
+
@alias module:Vanilla_website_utils
|
|
228
|
+
*/
|
|
177
229
|
async adelete_api(url, json = false)
|
|
178
230
|
{
|
|
179
231
|
const ctype = json ? "application/json;charset=UTF-8" : "application/x-www-form-urlencoded";
|
|
@@ -189,6 +241,9 @@ async adelete_api(url, json = false)
|
|
|
189
241
|
}
|
|
190
242
|
|
|
191
243
|
|
|
244
|
+
/**
|
|
245
|
+
@alias module:Vanilla_website_utils
|
|
246
|
+
*/
|
|
192
247
|
async post_json(url, data)
|
|
193
248
|
{
|
|
194
249
|
return new Promise((resolve, reject) =>
|
|
@@ -202,6 +257,9 @@ async post_json(url, data)
|
|
|
202
257
|
});
|
|
203
258
|
}
|
|
204
259
|
|
|
260
|
+
/**
|
|
261
|
+
@alias module:Vanilla_website_utils
|
|
262
|
+
*/
|
|
205
263
|
async put_json(url, data)
|
|
206
264
|
{
|
|
207
265
|
return new Promise((resolve, reject) =>
|
|
@@ -221,6 +279,9 @@ s_hide_del_icon()
|
|
|
221
279
|
hide_del_icon();
|
|
222
280
|
}
|
|
223
281
|
|
|
282
|
+
/**
|
|
283
|
+
@alias module:Vanilla_website_utils
|
|
284
|
+
*/
|
|
224
285
|
async hide_del_icon()
|
|
225
286
|
{
|
|
226
287
|
jQuery('.ui-inline-del').each(function(index) {jQuery(this).html('');});
|
|
@@ -228,8 +289,11 @@ async hide_del_icon()
|
|
|
228
289
|
|
|
229
290
|
|
|
230
291
|
|
|
231
|
-
|
|
292
|
+
/**
|
|
293
|
+
@alias module:Vanilla_website_utils
|
|
294
|
+
@example
|
|
232
295
|
// example: col_model = await jqu.add_link_details(col_model,'http://foo.bar'' , 'target_field','target="_blank"',{"key":"field1","key":"field2"});
|
|
296
|
+
*/
|
|
233
297
|
async add_link_details(col_model, url, edit_field, attr = '', keys, format)
|
|
234
298
|
{
|
|
235
299
|
let self = this;
|
|
@@ -297,8 +361,11 @@ async add_link_details(col_model, url, edit_field, attr = '', keys, format)
|
|
|
297
361
|
}
|
|
298
362
|
|
|
299
363
|
|
|
300
|
-
|
|
301
|
-
|
|
364
|
+
/**
|
|
365
|
+
@alias module:Vanilla_website_utils
|
|
366
|
+
@example
|
|
367
|
+
// col_model = await jqu.add_link_details_separator(col_model, 'https://foo.com' , 'couchdb','target="_blank"',{"mykey":"myval"});
|
|
368
|
+
*/
|
|
302
369
|
async add_link_details_separator(col_model, url, edit_field, attr = '', keys, format)
|
|
303
370
|
{
|
|
304
371
|
url = url + '/';
|
|
@@ -361,7 +428,9 @@ async add_link_details_separator(col_model, url, edit_field, attr = '', keys, fo
|
|
|
361
428
|
|
|
362
429
|
|
|
363
430
|
|
|
364
|
-
|
|
431
|
+
/**
|
|
432
|
+
@alias module:Vanilla_website_utils
|
|
433
|
+
*/
|
|
365
434
|
__cell_format(cell_value, format)
|
|
366
435
|
{
|
|
367
436
|
if (format == 'format_ok')
|
|
@@ -381,20 +450,24 @@ __cell_format(cell_value, format)
|
|
|
381
450
|
|
|
382
451
|
|
|
383
452
|
/**
|
|
453
|
+
@alias module:Vanilla_website_utils
|
|
384
454
|
@param {string} - row_id
|
|
385
455
|
@param {string} - data id
|
|
386
456
|
@param {object} - col_model for the table
|
|
457
|
+
@param {string} - Caption
|
|
387
458
|
@example
|
|
388
459
|
* let data_url = api + '/phone_detail?f=data&_id=';
|
|
389
460
|
* let col_model_url = api + '/phone_detail?f=col_model';
|
|
390
461
|
* let col_model = JSON.parse(await vwu.aget_api(col_model_url))
|
|
391
462
|
*/
|
|
392
|
-
async subgrid(_id, id, data_url, col_model)
|
|
463
|
+
async subgrid(_id, id, data_url, col_model, caption='' )
|
|
393
464
|
{
|
|
465
|
+
caption = caption != '' ? caption + ' ' : '';
|
|
394
466
|
let url = data_url + id;
|
|
395
|
-
let $s1 = jQuery("<table
|
|
467
|
+
let $s1 = jQuery("<table style='margin: 5px 0' class='" + _id + "_t'></table>");
|
|
396
468
|
$s1.appendTo("#" + jQuery.jgrid.jqID(_id));
|
|
397
469
|
$s1.jqGrid({
|
|
470
|
+
caption: caption + id,
|
|
398
471
|
colModel: col_model,
|
|
399
472
|
datatype: "json",
|
|
400
473
|
url: url,
|
|
@@ -402,12 +475,50 @@ async subgrid(_id, id, data_url, col_model)
|
|
|
402
475
|
rownumbers: true,
|
|
403
476
|
autoencode: true,
|
|
404
477
|
sortname: "c1",
|
|
405
|
-
sortorder: "desc"
|
|
406
|
-
caption: id
|
|
478
|
+
sortorder: "desc"
|
|
407
479
|
});
|
|
408
480
|
}
|
|
409
481
|
|
|
410
482
|
|
|
483
|
+
/**
|
|
484
|
+
@alias module:Vanilla_website_utils
|
|
485
|
+
@param {object} - col_model for the grid
|
|
486
|
+
@param {string} - field what include the image/picture href path like http://mypicture.png
|
|
487
|
+
@param {int} - size of the picture
|
|
488
|
+
@param {bolen} - image path should be a link
|
|
489
|
+
@example
|
|
490
|
+
* col_model = await jqu.add_image(col_model, 'image', 60, false);
|
|
491
|
+
*/
|
|
492
|
+
async add_image(col_model, edit_field, size, link=false)
|
|
493
|
+
{
|
|
494
|
+
if (size === undefined)
|
|
495
|
+
{
|
|
496
|
+
size = 60;
|
|
497
|
+
}
|
|
498
|
+
for (let i = 0; i < col_model.length; i++)
|
|
499
|
+
{
|
|
500
|
+
if (col_model[i]['name'] === edit_field)
|
|
501
|
+
{
|
|
502
|
+
col_model[i]['picture'] = true;
|
|
503
|
+
col_model[i]['width'] = size;
|
|
504
|
+
col_model[i]['height'] = size;
|
|
505
|
+
col_model[i]['formatter'] = function(cell_val)
|
|
506
|
+
{
|
|
507
|
+
if(link)
|
|
508
|
+
{
|
|
509
|
+
return '<a target="blank" href="' + cell_val + '"><img src="' + cell_val + '" alt="my image" width="' + size + '" /></a>';
|
|
510
|
+
}
|
|
511
|
+
else
|
|
512
|
+
{
|
|
513
|
+
return '<img src="' + cell_val + '" alt="my image" width="' + size + '" />';
|
|
514
|
+
}
|
|
515
|
+
};
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
return col_model;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
|
|
411
522
|
|
|
412
523
|
};
|
|
413
524
|
|
package/make_doc.sh
ADDED
package/package.json
CHANGED