jqgrid_utils 1.21.0 → 1.23.0

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
@@ -27,6 +27,8 @@ A module for Jqgrid_utils
27
27
 
28
28
 
29
29
  * [Jqgrid_utils](#module_Jqgrid_utils)
30
+ * [module.exports#update_row_to_api(_self, api, _ids, row)](#exp_module_Jqgrid_utils--module.exports+update_row_to_api) ⏏
31
+ * [module.exports#delete_row_to_api(_self, api, rowid, _ids, data)](#exp_module_Jqgrid_utils--module.exports+delete_row_to_api) ⏏
30
32
  * [module.exports#append_seperator_link_column(col_model, url, field_value, base, attr, keys)](#exp_module_Jqgrid_utils--module.exports+append_seperator_link_column) ⏏
31
33
  * [module.exports#add_edit(col_model)](#exp_module_Jqgrid_utils--module.exports+add_edit) ⏏
32
34
  * [module.exports#add_textarea(col_model, edit_field)](#exp_module_Jqgrid_utils--module.exports+add_textarea) ⏏
@@ -65,6 +67,77 @@ A module for Jqgrid_utils
65
67
  * [module.exports#set_filter(grid, data, fx, append_to)](#exp_module_Jqgrid_utils--module.exports+set_filter) ⏏
66
68
  * [module.exports#_filter()](#exp_module_Jqgrid_utils--module.exports+_filter) ⏏
67
69
 
70
+ <a name="exp_module_Jqgrid_utils--module.exports+update_row_to_api"></a>
71
+
72
+ ### module.exports#update\_row\_to\_api(_self, api, _ids, row) ⏏
73
+ Takes the updated columns data and send it to your API post server
74
+
75
+ **Kind**: Exported function
76
+
77
+ | Param | Type | Description |
78
+ | --- | --- | --- |
79
+ | _self | <code>object</code> | Grid Object (required) |
80
+ | api | <code>string</code> | API URL like https://foo.com (required) |
81
+ | _ids | <code>array</code> | id list, ids from the column header (required) |
82
+ | row | <code>object</code> | settings - extra key:value to send to your server |
83
+
84
+ **Example**
85
+ ```js
86
+ },
87
+ afterSetRow: async function(row)
88
+ {
89
+ const _api = await get_api_url('sapir');
90
+ const api = _api + '/column2';
91
+ let info = {"msg":"failed"};
92
+ var jqu = new Jqgrid_utils();
93
+ info = await jqu.update_row_to_api($grid,,api,['id'],row,{server : '232',db : 'sl_h',table : 'kpi',});
94
+ log.info(JSON.parse(info).msg);
95
+ },
96
+
97
+ afterInsertRow: function( rowid, rowdata, rowelem ) {
98
+ let tr = $("#"+rowid);
99
+ $(tr).data("jqgrid.record_data", rowelem);
100
+ },
101
+ ```
102
+ <a name="exp_module_Jqgrid_utils--module.exports+delete_row_to_api"></a>
103
+
104
+ ### module.exports#delete\_row\_to\_api(_self, api, rowid, _ids, data) ⏏
105
+ After Delete a Grid Row send to and DELETE REST Request
106
+ You need to define loadComplete and afterDelRow
107
+ The Grid data needs to be saved as record within loadComplete
108
+
109
+ **Kind**: Exported function
110
+
111
+ | Param | Type | Description |
112
+ | --- | --- | --- |
113
+ | _self | <code>object</code> | Grid Object (required) |
114
+ | api | <code>string</code> | API URL like https://foo.com (required) |
115
+ | rowid | <code>string</code> | the row id value from afterDelRow (required) |
116
+ | _ids | <code>array</code> | id list, ids from the column header colmodel (required) |
117
+ | data | <code>object</code> | settings - extra key:value to send to your server |
118
+
119
+ **Example**
120
+ ```js
121
+ loadComplete: async function()
122
+ {
123
+ $grid.jqGrid('setGridParam',{record_data:$grid.jqGrid("getGridParam").data});
124
+ },
125
+ afterDelRow: async function(rowid)
126
+ {
127
+ const _api = await get_api_url('sapir');
128
+ const api = _api + '/column2';
129
+ let info = {"msg":"failed"};
130
+ var jqu = new Jqgrid_utils();
131
+
132
+ info = await jqu.delete_row_to_api($grid,api,rowid,['id'],{
133
+ server : '232',
134
+ db : 'sl_h',
135
+ table : 'kpi',
136
+ operator: 'delete',
137
+ });
138
+ log.info(JSON.parse(info).msg);
139
+ },
140
+ ```
68
141
  <a name="exp_module_Jqgrid_utils--module.exports+append_seperator_link_column"></a>
69
142
 
70
143
  ### module.exports#append\_seperator\_link\_column(col_model, url, field_value, base, attr, keys) ⏏
@@ -22,6 +22,191 @@ module.exports = class Vanilla_website_utils
22
22
 
23
23
  }
24
24
 
25
+ /**
26
+ * Takes the updated columns data and send it to your API post server
27
+ @alias module:Jqgrid_utils
28
+ @param {object} - Grid Object (required)
29
+ @param {string} - API URL like https://foo.com (required)
30
+ @param {array} - id list, ids from the column header (required)
31
+ @param {object} - settings - extra key:value to send to your server
32
+
33
+ @example
34
+ },
35
+ afterSetRow: async function(row)
36
+ {
37
+ const _api = await get_api_url('sapir');
38
+ const api = _api + '/column2';
39
+ let info = {"msg":"failed"};
40
+ var jqu = new Jqgrid_utils();
41
+ info = await jqu.update_row_to_api($grid,,api,['id'],row,{server : '232',db : 'sl_h',table : 'kpi',});
42
+ log.info(JSON.parse(info).msg);
43
+ },
44
+
45
+ afterInsertRow: function( rowid, rowdata, rowelem ) {
46
+ let tr = $("#"+rowid);
47
+ $(tr).data("jqgrid.record_data", rowelem);
48
+ },
49
+
50
+
51
+ */
52
+
53
+
54
+ async update_row_to_api(_self, api='',_ids=['id'],row={}, data)
55
+ {
56
+ let self = this;
57
+ let infos = [];
58
+ if(api != '' && Object.keys(row).length > 0 )
59
+ {
60
+ let ids = {};
61
+ let values = {};
62
+ if(row.inputData.oper == 'edit')
63
+ {
64
+ let changed = {};
65
+ const tr = $("#"+row.rowid);
66
+ const rd = $(tr).data("jqgrid.record_data");
67
+
68
+ if(row.inputData.oper == 'edit')
69
+ {
70
+ for(let i in _ids)
71
+ {
72
+ ids[_ids[i]] = row.inputData[_ids[i]];
73
+ }
74
+ }
75
+ else
76
+ {
77
+ ids['id']= '0';
78
+ }
79
+
80
+
81
+ if(rd)
82
+ {
83
+ for(let i in row.inputData)
84
+ {
85
+ if(row.inputData.hasOwnProperty(i) && rd.hasOwnProperty(i))
86
+ {
87
+ if(row.inputData[i] != rd[i])
88
+ {
89
+ changed[i] = row.inputData[i];
90
+ }
91
+ }
92
+ }
93
+ }
94
+ else
95
+ {
96
+ changed =row.inputData;
97
+ }
98
+
99
+ for(let i in changed)
100
+ {
101
+ if( Object.keys(ids).indexOf(i) < 0 && i!= 'oper')
102
+ {
103
+ const col_name = i;
104
+ let col_value = {};
105
+ col_value[col_name] = changed[i];
106
+ data['ids'] = ids;
107
+ data['values'] = col_value;
108
+ data['operator'] = 'edit';
109
+ const info = await self.post_json(api ,JSON.stringify(data));
110
+ infos.push(info);
111
+ }
112
+ }
113
+
114
+ }
115
+ else if(row.inputData.oper == 'add')
116
+ {
117
+ for(let i in row.inputData)
118
+ {
119
+ if(row.inputData[i] && i != 'id' && i != 'oper')
120
+ {
121
+ values[i] = row.inputData[i];
122
+ }
123
+ }
124
+ data['ids'] = ids;
125
+ data['values'] = values;
126
+ data['operator'] = 'add';
127
+ let info = await self.post_json(api ,JSON.stringify(data));
128
+ infos.push(info);
129
+ }
130
+ }
131
+
132
+ return infos;
133
+ }
134
+
135
+
136
+ /**
137
+ * After Delete a Grid Row send to and DELETE REST Request
138
+ * You need to define loadComplete and afterDelRow
139
+ * The Grid data needs to be saved as record within loadComplete
140
+ @alias module:Jqgrid_utils
141
+ @param {object} - Grid Object (required)
142
+ @param {string} - API URL like https://foo.com (required)
143
+ @param {string} - the row id value from afterDelRow (required)
144
+ @param {array} - id list, ids from the column header colmodel (required)
145
+ @param {object} - settings - extra key:value to send to your server
146
+ @example
147
+
148
+ loadComplete: async function()
149
+ {
150
+ $grid.jqGrid('setGridParam',{record_data:$grid.jqGrid("getGridParam").data});
151
+ },
152
+ afterDelRow: async function(rowid)
153
+ {
154
+ const _api = await get_api_url('sapir');
155
+ const api = _api + '/column2';
156
+ let info = {"msg":"failed"};
157
+ var jqu = new Jqgrid_utils();
158
+
159
+ info = await jqu.delete_row_to_api($grid,api,rowid,['id'],{
160
+ server : '232',
161
+ db : 'sl_h',
162
+ table : 'kpi',
163
+ operator: 'delete',
164
+ });
165
+ log.info(JSON.parse(info).msg);
166
+ },
167
+
168
+
169
+
170
+
171
+
172
+ */
173
+
174
+ async delete_row_to_api(_self, api='', rowid, _ids=[], data={})
175
+ {
176
+ let info = {"msg":"failed"};
177
+ let self = this;
178
+ let ids = [];
179
+ let values = {};
180
+ const rd = _self.jqGrid("getGridParam", "record_data");
181
+ for(let i in rd)
182
+ {
183
+ if (rd[i]['id'] === rowid)
184
+ {
185
+ for(let ii in _ids)
186
+ {
187
+ if(rd[i].hasOwnProperty(_ids[ii]))
188
+ {
189
+ values[_ids[ii]] = rd[i][_ids[ii]];
190
+ ids.push(_ids[ii]);
191
+ }
192
+ }
193
+ break;
194
+ }
195
+ }
196
+
197
+
198
+
199
+ if(api != '' && Object.keys(values).length == ids.length )
200
+ {
201
+ data['ids'] = ids;
202
+ data['values'] = values;
203
+ //console.log(data);
204
+ info = await self.adelete_api(api,JSON.stringify(data));
205
+ }
206
+ return info;
207
+ }
208
+
209
+
25
210
 
26
211
 
27
212
  /**
@@ -786,7 +971,13 @@ afterDelRow: async function(row)
786
971
 
787
972
  async adelete_api(url, json = false)
788
973
  {
789
- const ctype = json ? "application/json;charset=UTF-8" : "application/x-www-form-urlencoded";
974
+ let ctype = "application/x-www-form-urlencoded";
975
+ let body = null;
976
+ if(json)
977
+ {
978
+ ctype = "application/json;charset=UTF-8" ;
979
+ body = json;
980
+ }
790
981
  return new Promise((resolve, reject) =>
791
982
  {
792
983
  let xhr = new XMLHttpRequest();
@@ -794,12 +985,11 @@ async adelete_api(url, json = false)
794
985
  xhr.setRequestHeader("Content-type", ctype);
795
986
  xhr.onload = () => resolve(xhr.responseText);
796
987
  xhr.onerror = () => reject(xhr.statusText);
797
- xhr.send(null);
988
+ xhr.send(body);
798
989
  });
799
990
  }
800
991
 
801
992
 
802
-
803
993
  /**
804
994
  * Async Post request used by the update_row function
805
995
  @alias module:Jqgrid_utils
package/jqgrid_utils.js CHANGED
@@ -21,6 +21,191 @@ module.exports = class Vanilla_website_utils
21
21
 
22
22
  }
23
23
 
24
+ /**
25
+ * Takes the updated columns data and send it to your API post server
26
+ @alias module:Jqgrid_utils
27
+ @param {object} - Grid Object (required)
28
+ @param {string} - API URL like https://foo.com (required)
29
+ @param {array} - id list, ids from the column header (required)
30
+ @param {object} - settings - extra key:value to send to your server
31
+
32
+ @example
33
+ },
34
+ afterSetRow: async function(row)
35
+ {
36
+ const _api = await get_api_url('sapir');
37
+ const api = _api + '/column2';
38
+ let info = {"msg":"failed"};
39
+ var jqu = new Jqgrid_utils();
40
+ info = await jqu.update_row_to_api($grid,,api,['id'],row,{server : '232',db : 'sl_h',table : 'kpi',});
41
+ log.info(JSON.parse(info).msg);
42
+ },
43
+
44
+ afterInsertRow: function( rowid, rowdata, rowelem ) {
45
+ let tr = $("#"+rowid);
46
+ $(tr).data("jqgrid.record_data", rowelem);
47
+ },
48
+
49
+
50
+ */
51
+
52
+
53
+ async update_row_to_api(_self, api='',_ids=['id'],row={}, data)
54
+ {
55
+ let self = this;
56
+ let infos = [];
57
+ if(api != '' && Object.keys(row).length > 0 )
58
+ {
59
+ let ids = {};
60
+ let values = {};
61
+ if(row.inputData.oper == 'edit')
62
+ {
63
+ let changed = {};
64
+ const tr = $("#"+row.rowid);
65
+ const rd = $(tr).data("jqgrid.record_data");
66
+
67
+ if(row.inputData.oper == 'edit')
68
+ {
69
+ for(let i in _ids)
70
+ {
71
+ ids[_ids[i]] = row.inputData[_ids[i]];
72
+ }
73
+ }
74
+ else
75
+ {
76
+ ids['id']= '0';
77
+ }
78
+
79
+
80
+ if(rd)
81
+ {
82
+ for(let i in row.inputData)
83
+ {
84
+ if(row.inputData.hasOwnProperty(i) && rd.hasOwnProperty(i))
85
+ {
86
+ if(row.inputData[i] != rd[i])
87
+ {
88
+ changed[i] = row.inputData[i];
89
+ }
90
+ }
91
+ }
92
+ }
93
+ else
94
+ {
95
+ changed =row.inputData;
96
+ }
97
+
98
+ for(let i in changed)
99
+ {
100
+ if( Object.keys(ids).indexOf(i) < 0 && i!= 'oper')
101
+ {
102
+ const col_name = i;
103
+ let col_value = {};
104
+ col_value[col_name] = changed[i];
105
+ data['ids'] = ids;
106
+ data['values'] = col_value;
107
+ data['operator'] = 'edit';
108
+ const info = await self.post_json(api ,JSON.stringify(data));
109
+ infos.push(info);
110
+ }
111
+ }
112
+
113
+ }
114
+ else if(row.inputData.oper == 'add')
115
+ {
116
+ for(let i in row.inputData)
117
+ {
118
+ if(row.inputData[i] && i != 'id' && i != 'oper')
119
+ {
120
+ values[i] = row.inputData[i];
121
+ }
122
+ }
123
+ data['ids'] = ids;
124
+ data['values'] = values;
125
+ data['operator'] = 'add';
126
+ let info = await self.post_json(api ,JSON.stringify(data));
127
+ infos.push(info);
128
+ }
129
+ }
130
+
131
+ return infos;
132
+ }
133
+
134
+
135
+ /**
136
+ * After Delete a Grid Row send to and DELETE REST Request
137
+ * You need to define loadComplete and afterDelRow
138
+ * The Grid data needs to be saved as record within loadComplete
139
+ @alias module:Jqgrid_utils
140
+ @param {object} - Grid Object (required)
141
+ @param {string} - API URL like https://foo.com (required)
142
+ @param {string} - the row id value from afterDelRow (required)
143
+ @param {array} - id list, ids from the column header colmodel (required)
144
+ @param {object} - settings - extra key:value to send to your server
145
+ @example
146
+
147
+ loadComplete: async function()
148
+ {
149
+ $grid.jqGrid('setGridParam',{record_data:$grid.jqGrid("getGridParam").data});
150
+ },
151
+ afterDelRow: async function(rowid)
152
+ {
153
+ const _api = await get_api_url('sapir');
154
+ const api = _api + '/column2';
155
+ let info = {"msg":"failed"};
156
+ var jqu = new Jqgrid_utils();
157
+
158
+ info = await jqu.delete_row_to_api($grid,api,rowid,['id'],{
159
+ server : '232',
160
+ db : 'sl_h',
161
+ table : 'kpi',
162
+ operator: 'delete',
163
+ });
164
+ log.info(JSON.parse(info).msg);
165
+ },
166
+
167
+
168
+
169
+
170
+
171
+ */
172
+
173
+ async delete_row_to_api(_self, api='', rowid, _ids=[], data={})
174
+ {
175
+ let info = {"msg":"failed"};
176
+ let self = this;
177
+ let ids = [];
178
+ let values = {};
179
+ const rd = _self.jqGrid("getGridParam", "record_data");
180
+ for(let i in rd)
181
+ {
182
+ if (rd[i]['id'] === rowid)
183
+ {
184
+ for(let ii in _ids)
185
+ {
186
+ if(rd[i].hasOwnProperty(_ids[ii]))
187
+ {
188
+ values[_ids[ii]] = rd[i][_ids[ii]];
189
+ ids.push(_ids[ii]);
190
+ }
191
+ }
192
+ break;
193
+ }
194
+ }
195
+
196
+
197
+
198
+ if(api != '' && Object.keys(values).length == ids.length )
199
+ {
200
+ data['ids'] = ids;
201
+ data['values'] = values;
202
+ //console.log(data);
203
+ info = await self.adelete_api(api,JSON.stringify(data));
204
+ }
205
+ return info;
206
+ }
207
+
208
+
24
209
 
25
210
 
26
211
  /**
@@ -785,7 +970,13 @@ afterDelRow: async function(row)
785
970
 
786
971
  async adelete_api(url, json = false)
787
972
  {
788
- const ctype = json ? "application/json;charset=UTF-8" : "application/x-www-form-urlencoded";
973
+ let ctype = "application/x-www-form-urlencoded";
974
+ let body = null;
975
+ if(json)
976
+ {
977
+ ctype = "application/json;charset=UTF-8" ;
978
+ body = json;
979
+ }
789
980
  return new Promise((resolve, reject) =>
790
981
  {
791
982
  let xhr = new XMLHttpRequest();
@@ -793,12 +984,11 @@ async adelete_api(url, json = false)
793
984
  xhr.setRequestHeader("Content-type", ctype);
794
985
  xhr.onload = () => resolve(xhr.responseText);
795
986
  xhr.onerror = () => reject(xhr.statusText);
796
- xhr.send(null);
987
+ xhr.send(body);
797
988
  });
798
989
  }
799
990
 
800
991
 
801
-
802
992
  /**
803
993
  * Async Post request used by the update_row function
804
994
  @alias module:Jqgrid_utils
package/package.json CHANGED
@@ -29,5 +29,5 @@
29
29
  {
30
30
  "test": "echo \"Error: no test specified\" && exit 1"
31
31
  },
32
- "version": "1.21.0"
32
+ "version": "1.23.0"
33
33
  }