jqgrid_utils 1.1.0 → 1.1.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 +19 -0
- package/dist/jqgrid_utils.js +169 -13
- package/jqgrid_utils.js +169 -13
- package/make.sh +2 -0
- package/npmignore +2 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -35,3 +35,22 @@ Discover All Functions:
|
|
|
35
35
|
await gu.grid_set_captain(_grid, data);
|
|
36
36
|
}
|
|
37
37
|
```
|
|
38
|
+
|
|
39
|
+
## Functions:
|
|
40
|
+
|
|
41
|
+
### add grid_load_complete to don't show the delete icon
|
|
42
|
+
```javascript
|
|
43
|
+
loadComplete: async function(data)
|
|
44
|
+
{
|
|
45
|
+
jqu.s_hide_del_icon();
|
|
46
|
+
grid_load_complete;
|
|
47
|
+
},
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
```javascript
|
|
51
|
+
loadComplete: async function(data)
|
|
52
|
+
{
|
|
53
|
+
await jqu.hide_del_icon();
|
|
54
|
+
grid_load_complete;
|
|
55
|
+
},
|
|
56
|
+
```
|
package/dist/jqgrid_utils.js
CHANGED
|
@@ -17,23 +17,50 @@ module.exports = class Vanilla_website_utils
|
|
|
17
17
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
async s_set_link(col_model, edit_field, url ,attr='')
|
|
21
|
+
{
|
|
22
|
+
this.set_link(col_model, edit_field, url ,attr);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
async set_link(col_model, edit_field, url ,attr='')
|
|
27
|
+
{
|
|
28
|
+
for(let i=0;i< col_model.length;i++)
|
|
25
29
|
{
|
|
26
|
-
|
|
27
|
-
if(data.length ===0)
|
|
28
|
-
{
|
|
29
|
-
data = grid.jqGrid('getRowData');
|
|
30
|
-
}
|
|
31
|
-
let caption = grid.jqGrid("getGridParam", "caption");
|
|
32
|
-
if (Array.isArray(data))
|
|
30
|
+
if(col_model[i]['name'] === edit_field)
|
|
33
31
|
{
|
|
34
|
-
|
|
32
|
+
col_model[i]['formatter'] = function (cell_val,o)
|
|
33
|
+
{
|
|
34
|
+
return '<a class="gl" ' + attr + 'href="' + o.rowData[url] + '">'+ cell_val +'</a>';
|
|
35
|
+
};
|
|
35
36
|
}
|
|
36
37
|
}
|
|
38
|
+
return col_model;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
s_grid_set_captain(_grid, data=[])
|
|
43
|
+
{
|
|
44
|
+
this.grid_set_captain(_grid, data=[]);
|
|
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
|
+
}
|
|
37
64
|
|
|
38
65
|
|
|
39
66
|
s_resize_saved_cell_width(col_model, page=false, grid=false)
|
|
@@ -70,6 +97,135 @@ module.exports = class Vanilla_website_utils
|
|
|
70
97
|
|
|
71
98
|
|
|
72
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
|
+
|
|
73
229
|
};
|
|
74
230
|
|
|
75
231
|
|
package/jqgrid_utils.js
CHANGED
|
@@ -16,23 +16,50 @@ module.exports = class Vanilla_website_utils
|
|
|
16
16
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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++)
|
|
24
28
|
{
|
|
25
|
-
|
|
26
|
-
if(data.length ===0)
|
|
27
|
-
{
|
|
28
|
-
data = grid.jqGrid('getRowData');
|
|
29
|
-
}
|
|
30
|
-
let caption = grid.jqGrid("getGridParam", "caption");
|
|
31
|
-
if (Array.isArray(data))
|
|
29
|
+
if(col_model[i]['name'] === edit_field)
|
|
32
30
|
{
|
|
33
|
-
|
|
31
|
+
col_model[i]['formatter'] = function (cell_val,o)
|
|
32
|
+
{
|
|
33
|
+
return '<a class="gl" ' + attr + 'href="' + o.rowData[url] + '">'+ cell_val +'</a>';
|
|
34
|
+
};
|
|
34
35
|
}
|
|
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
|
+
async grid_set_captain(_grid, data=[])
|
|
46
|
+
{
|
|
47
|
+
const grid = jQuery(_grid);
|
|
48
|
+
let count = 0;
|
|
49
|
+
if(data.length === 0)
|
|
50
|
+
{
|
|
51
|
+
count = grid.jqGrid('getGridParam', 'records');
|
|
52
|
+
}
|
|
53
|
+
else
|
|
54
|
+
{
|
|
55
|
+
count = data.length;
|
|
56
|
+
}
|
|
57
|
+
let caption = grid.jqGrid("getGridParam", "caption");
|
|
58
|
+
if(caption.indexOf(count+'x') === -1 )
|
|
59
|
+
{
|
|
60
|
+
grid.jqGrid('setCaption', caption + ' - ' + count + 'x');
|
|
61
|
+
}
|
|
62
|
+
}
|
|
36
63
|
|
|
37
64
|
|
|
38
65
|
s_resize_saved_cell_width(col_model, page=false, grid=false)
|
|
@@ -69,6 +96,135 @@ module.exports = class Vanilla_website_utils
|
|
|
69
96
|
|
|
70
97
|
|
|
71
98
|
|
|
99
|
+
|
|
100
|
+
async upsert_row(row, url, req = {})
|
|
101
|
+
{
|
|
102
|
+
if (row.rowid.startsWith('jqg'))
|
|
103
|
+
{
|
|
104
|
+
const r0 = await this.insert_row(row, url);
|
|
105
|
+
return r0;
|
|
106
|
+
}
|
|
107
|
+
else
|
|
108
|
+
{
|
|
109
|
+
const r1 = await this.update_row(row, url);
|
|
110
|
+
return r1;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
async insert_row(row, url)
|
|
116
|
+
{
|
|
117
|
+
let req = {};
|
|
118
|
+
let ret = '';
|
|
119
|
+
if (row.inputData.hasOwnProperty('id'))
|
|
120
|
+
{
|
|
121
|
+
req['_id'] = 'id';
|
|
122
|
+
req['_id_val'] = row.inputData['id'];
|
|
123
|
+
for (let i in row.inputData)
|
|
124
|
+
{
|
|
125
|
+
req[i] = row.inputData[i];
|
|
126
|
+
}
|
|
127
|
+
delete req['id'];
|
|
128
|
+
delete req['oper'];
|
|
129
|
+
//console.log(req);
|
|
130
|
+
ret = await this.put_json(url, JSON.stringify(req));
|
|
131
|
+
}
|
|
132
|
+
return ret;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
async update_row(row, url, req = {})
|
|
138
|
+
{
|
|
139
|
+
let ret = '';
|
|
140
|
+
{
|
|
141
|
+
if(! req['_id'])
|
|
142
|
+
{
|
|
143
|
+
req['_id'] = 'id';
|
|
144
|
+
}
|
|
145
|
+
req['_id_val'] = row.inputData['id'];
|
|
146
|
+
for (let i in row.inputData)
|
|
147
|
+
{
|
|
148
|
+
req[i] = row.inputData[i];
|
|
149
|
+
}
|
|
150
|
+
delete req['id'];
|
|
151
|
+
delete req['oper'];
|
|
152
|
+
ret = await this.post_json(url, JSON.stringify(req));
|
|
153
|
+
}
|
|
154
|
+
return ret;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
async delete_row(_id, url)
|
|
159
|
+
{
|
|
160
|
+
let ret = '';
|
|
161
|
+
if (url.indexOf('?') > -1)
|
|
162
|
+
{
|
|
163
|
+
url += "&_id=" + encodeURIComponent(unescape(_id));
|
|
164
|
+
}
|
|
165
|
+
else
|
|
166
|
+
{
|
|
167
|
+
url += "?_id=" + encodeURIComponent(unescape(_id));
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
ret = JSON.parse(await this.adelete_api(url));
|
|
171
|
+
return ret['message'];
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
async adelete_api(url, json = false)
|
|
177
|
+
{
|
|
178
|
+
const ctype = json ? "application/json;charset=UTF-8" : "application/x-www-form-urlencoded";
|
|
179
|
+
return new Promise((resolve, reject) =>
|
|
180
|
+
{
|
|
181
|
+
let xhr = new XMLHttpRequest();
|
|
182
|
+
xhr.open("DELETE", url);
|
|
183
|
+
xhr.setRequestHeader("Content-type", ctype);
|
|
184
|
+
xhr.onload = () => resolve(xhr.responseText);
|
|
185
|
+
xhr.onerror = () => reject(xhr.statusText);
|
|
186
|
+
xhr.send(null);
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
async post_json(url, data)
|
|
192
|
+
{
|
|
193
|
+
return new Promise((resolve, reject) =>
|
|
194
|
+
{
|
|
195
|
+
let xhr = new XMLHttpRequest();
|
|
196
|
+
xhr.open("POST", url);
|
|
197
|
+
xhr.setRequestHeader("Content-type", "application/json");
|
|
198
|
+
xhr.onload = () => resolve(xhr.responseText);
|
|
199
|
+
xhr.onerror = () => reject(xhr.statusText);
|
|
200
|
+
xhr.send(data);
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
async put_json(url, data)
|
|
205
|
+
{
|
|
206
|
+
return new Promise((resolve, reject) =>
|
|
207
|
+
{
|
|
208
|
+
let xhr = new XMLHttpRequest();
|
|
209
|
+
xhr.open("PUT", url);
|
|
210
|
+
xhr.setRequestHeader("Content-type", "application/json");
|
|
211
|
+
xhr.onload = () => resolve(xhr.responseText);
|
|
212
|
+
xhr.onerror = () => reject(xhr.statusText);
|
|
213
|
+
xhr.send(data);
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
s_hide_del_icon()
|
|
219
|
+
{
|
|
220
|
+
hide_del_icon();
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
async hide_del_icon()
|
|
224
|
+
{
|
|
225
|
+
jQuery('.ui-inline-del').each(function(index) {jQuery(this).html('');});
|
|
226
|
+
}
|
|
227
|
+
|
|
72
228
|
};
|
|
73
229
|
|
|
74
230
|
|
package/make.sh
CHANGED
package/npmignore
ADDED
package/package.json
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
"dependencies":
|
|
7
7
|
{},
|
|
8
8
|
"deprecated": false,
|
|
9
|
-
"description": "Convenient Functions for
|
|
10
|
-
"homepage": "
|
|
9
|
+
"description": "Convenient Functions for the Free jqGrid",
|
|
10
|
+
"homepage": "http://calantas.org/jqgrid_utils",
|
|
11
11
|
"license": "GPL-3.0-or-later",
|
|
12
12
|
"main": "jqgrid_utils.js",
|
|
13
13
|
"name": "jqgrid_utils",
|
|
@@ -28,5 +28,5 @@
|
|
|
28
28
|
{
|
|
29
29
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
30
30
|
},
|
|
31
|
-
"version": "1.1.
|
|
31
|
+
"version": "1.1.4"
|
|
32
32
|
}
|