jqgrid_utils 1.0.5 → 1.1.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/dist/jqgrid_utils.js +204 -14
- package/jqgrid_utils.js +204 -14
- package/make.sh +2 -0
- package/npmignore +2 -0
- package/package.json +3 -3
package/dist/jqgrid_utils.js
CHANGED
|
@@ -4,26 +4,216 @@
|
|
|
4
4
|
module.exports = class Vanilla_website_utils
|
|
5
5
|
{
|
|
6
6
|
|
|
7
|
-
constructor()
|
|
8
|
-
{
|
|
9
|
-
|
|
10
|
-
s_grid_set_captain(_grid, data=[])
|
|
11
|
-
{
|
|
12
|
-
this.grid_set_captain(_grid, data=[]);
|
|
13
|
-
}
|
|
14
|
-
async grid_set_captain(_grid, data=[])
|
|
7
|
+
constructor(settings=false)
|
|
8
|
+
{
|
|
9
|
+
if(settings)
|
|
15
10
|
{
|
|
16
|
-
|
|
17
|
-
if(data.length ===0)
|
|
11
|
+
if(settings.hasOwnProperty('page'))
|
|
18
12
|
{
|
|
19
|
-
|
|
13
|
+
this.page = settings['page'];
|
|
14
|
+
localStorage.setItem('page', this.page);
|
|
20
15
|
}
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
}
|
|
19
|
+
|
|
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++)
|
|
29
|
+
{
|
|
30
|
+
if(col_model[i]['name'] === edit_field)
|
|
23
31
|
{
|
|
24
|
-
|
|
32
|
+
col_model[i]['formatter'] = function (cell_val,o)
|
|
33
|
+
{
|
|
34
|
+
return '<a class="gl" ' + attr + 'href="' + o.rowData[url] + '">'+ cell_val +'</a>';
|
|
35
|
+
};
|
|
25
36
|
}
|
|
26
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
|
+
}
|
|
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
|
+
}
|
|
27
217
|
|
|
28
218
|
|
|
29
219
|
};
|
package/jqgrid_utils.js
CHANGED
|
@@ -3,26 +3,216 @@
|
|
|
3
3
|
module.exports = class Vanilla_website_utils
|
|
4
4
|
{
|
|
5
5
|
|
|
6
|
-
constructor()
|
|
7
|
-
{
|
|
8
|
-
|
|
9
|
-
s_grid_set_captain(_grid, data=[])
|
|
10
|
-
{
|
|
11
|
-
this.grid_set_captain(_grid, data=[]);
|
|
12
|
-
}
|
|
13
|
-
async grid_set_captain(_grid, data=[])
|
|
6
|
+
constructor(settings=false)
|
|
7
|
+
{
|
|
8
|
+
if(settings)
|
|
14
9
|
{
|
|
15
|
-
|
|
16
|
-
if(data.length ===0)
|
|
10
|
+
if(settings.hasOwnProperty('page'))
|
|
17
11
|
{
|
|
18
|
-
|
|
12
|
+
this.page = settings['page'];
|
|
13
|
+
localStorage.setItem('page', this.page);
|
|
19
14
|
}
|
|
20
|
-
|
|
21
|
-
|
|
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)
|
|
22
30
|
{
|
|
23
|
-
|
|
31
|
+
col_model[i]['formatter'] = function (cell_val,o)
|
|
32
|
+
{
|
|
33
|
+
return '<a class="gl" ' + attr + 'href="' + o.rowData[url] + '">'+ cell_val +'</a>';
|
|
34
|
+
};
|
|
24
35
|
}
|
|
25
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
|
+
}
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
s_resize_saved_cell_width(col_model, page=false, grid=false)
|
|
66
|
+
{
|
|
67
|
+
this.grid_set_captain(col_model, page, grid);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async resize_saved_cell_width(col_model,page=false, grid=false)
|
|
71
|
+
{
|
|
72
|
+
let key = page ? page : this.page;
|
|
73
|
+
key += grid ? '-' + grid + '-w-' : '-grid-w-';
|
|
74
|
+
for(let x = 0; x<= col_model.length; x++)
|
|
75
|
+
{
|
|
76
|
+
const width = localStorage.getItem(key + x);
|
|
77
|
+
if(width)
|
|
78
|
+
{
|
|
79
|
+
col_model[x]['width'] = width;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return col_model;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
resize_cell(width, index, _page=false)
|
|
87
|
+
{
|
|
88
|
+
const page = _page ? _page : localStorage.getItem('page');
|
|
89
|
+
const grid = this.id;
|
|
90
|
+
let idx = index-1;
|
|
91
|
+
let key = page + '-' + grid + '-w-' + idx;
|
|
92
|
+
localStorage.setItem(key, width);
|
|
93
|
+
const cat = localStorage.getItem(key);
|
|
94
|
+
console.log(key);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
|
|
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
|
+
}
|
|
26
216
|
|
|
27
217
|
|
|
28
218
|
};
|
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.
|
|
31
|
+
"version": "1.1.3"
|
|
32
32
|
}
|