jqgrid_utils 1.22.0 → 1.24.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,8 +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(col_model, api, _ids)](#exp_module_Jqgrid_utils--module.exports+update_row_to_api) ⏏
31
- * [module.exports#delete_row_to_api(col_model, api, ids)](#exp_module_Jqgrid_utils--module.exports+delete_row_to_api) ⏏
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) ⏏
32
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) ⏏
33
33
  * [module.exports#add_edit(col_model)](#exp_module_Jqgrid_utils--module.exports+add_edit) ⏏
34
34
  * [module.exports#add_textarea(col_model, edit_field)](#exp_module_Jqgrid_utils--module.exports+add_textarea) ⏏
@@ -69,63 +69,79 @@ A module for Jqgrid_utils
69
69
 
70
70
  <a name="exp_module_Jqgrid_utils--module.exports+update_row_to_api"></a>
71
71
 
72
- ### module.exports#update\_row\_to\_api(col_model, api, _ids) ⏏
72
+ ### module.exports#update\_row\_to\_api(_self, api, _ids, row) ⏏
73
73
  Takes the updated columns data and send it to your API post server
74
+ loadComplete: async function() for the old record needs to be called, see example !
74
75
 
75
76
  **Kind**: Exported function
76
77
 
77
78
  | Param | Type | Description |
78
79
  | --- | --- | --- |
79
- | col_model | <code>string</code> | API URL like https://foo.com (required) |
80
- | api | <code>array</code> | id list, ids from the column header (required) |
81
- | _ids | <code>object</code> | settings - extra key:value to send to your server |
80
+ | _self | <code>object</code> | Grid Object (required) |
81
+ | api | <code>string</code> | API URL like https://foo.com (required) |
82
+ | _ids | <code>array</code> | id list, ids from the column header (required) |
83
+ | row | <code>object</code> | settings - extra key:value to send to your server |
82
84
 
83
85
  **Example**
84
86
  ```js
85
- },
87
+ var jqu = new Jqgrid_utils({page:page});
88
+
89
+ ....},
90
+ loadComplete: async function()
91
+ {
92
+ $grid.jqGrid('setGridParam',{record_data:$grid.jqGrid("getGridParam").data});
93
+ },
86
94
  afterSetRow: async function(row)
87
95
  {
88
96
  const _api = await get_api_url('sapir');
89
97
  const api = _api + '/column2';
90
98
  let info = {"msg":"failed"};
91
99
  var jqu = new Jqgrid_utils();
92
- info = await jqu.update_row_to_api(col_model,api,['id'],row,{server : '232',db : 'sl_h',table : 'kpi',});
93
- log.info(JSON.parse(info).msg);
100
+ info = await jqu.update_row_to_api($grid, api,['id'],row,{server : '232',db : 'sl_h',table : 'kpi',});
101
+ for(let i in info)
102
+ {
103
+ log.info(info[i]);
104
+ }
94
105
  },
95
-
96
- afterInsertRow: function( rowid, rowdata, rowelem ) {
97
- let tr = $("#"+rowid);
98
- $(tr).data("jqgrid.record_data", rowelem);
99
- },
100
106
  ```
101
107
  <a name="exp_module_Jqgrid_utils--module.exports+delete_row_to_api"></a>
102
108
 
103
- ### module.exports#delete\_row\_to\_api(col_model, api, ids) ⏏
104
- Take your row id value and send it to your delete post API server
109
+ ### module.exports#delete\_row\_to\_api(_self, api, rowid, _ids, data) ⏏
110
+ After Delete a Grid Row send to and DELETE REST Request
111
+ You need to define loadComplete and afterDelRow
112
+ The Grid data needs to be saved as record within loadComplete
105
113
 
106
114
  **Kind**: Exported function
107
115
 
108
116
  | Param | Type | Description |
109
117
  | --- | --- | --- |
110
- | col_model | <code>string</code> | API URL like https://foo.com |
111
- | api | <code>array</code> | id list, ids from the column header (required) |
112
- | ids | <code>object</code> | settings - extra key:value to send to your server |
113
-
114
- **Example**
115
- ```js
116
- afterDelRow: async function(rowid){
117
- const _api = await get_api_url('sapir');
118
- const api = _api + '/column2';
119
- let info = {"msg":"failed"};
120
- var jqu = new Jqgrid_utils();
121
- info = await jqu.delete_row_to_api(col_model,api,[rowid],{
122
- server : '232',
123
- db : 'sl_h',
124
- table : 'kpi',
125
- operator: 'delete',
126
- });
127
- log.info(JSON.parse(info).msg);
128
- },
118
+ | _self | <code>object</code> | Grid Object (required) |
119
+ | api | <code>string</code> | API URL like https://foo.com (required) |
120
+ | rowid | <code>string</code> | the row id value from afterDelRow (required) |
121
+ | _ids | <code>array</code> | id list, ids from the column header colmodel (required) |
122
+ | data | <code>object</code> | settings - extra key:value to send to your server |
123
+
124
+ **Example**
125
+ ```js
126
+ loadComplete: async function()
127
+ {
128
+ $grid.jqGrid('setGridParam',{record_data:$grid.jqGrid("getGridParam").data});
129
+ },
130
+ afterDelRow: async function(rowid)
131
+ {
132
+ const _api = await get_api_url('sapir');
133
+ const api = _api + '/column2';
134
+ let info = {"msg":"failed"};
135
+ var jqu = new Jqgrid_utils();
136
+
137
+ info = await jqu.delete_row_to_api($grid,api,rowid,['id'],{
138
+ server : '232',
139
+ db : 'sl_h',
140
+ table : 'kpi',
141
+ operator: 'delete',
142
+ });
143
+ log.info(JSON.parse(info).msg);
144
+ },
129
145
  ```
130
146
  <a name="exp_module_Jqgrid_utils--module.exports+append_seperator_link_column"></a>
131
147
 
@@ -24,76 +24,79 @@ module.exports = class Vanilla_website_utils
24
24
 
25
25
  /**
26
26
  * Takes the updated columns data and send it to your API post server
27
+ * loadComplete: async function() for the old record needs to be called, see example !
27
28
  @alias module:Jqgrid_utils
29
+ @param {object} - Grid Object (required)
28
30
  @param {string} - API URL like https://foo.com (required)
29
31
  @param {array} - id list, ids from the column header (required)
30
32
  @param {object} - settings - extra key:value to send to your server
31
33
 
32
- @example
33
- },
34
+ @example
35
+ var jqu = new Jqgrid_utils({page:page});
36
+
37
+ ....},
38
+ loadComplete: async function()
39
+ {
40
+ $grid.jqGrid('setGridParam',{record_data:$grid.jqGrid("getGridParam").data});
41
+ },
34
42
  afterSetRow: async function(row)
35
43
  {
36
44
  const _api = await get_api_url('sapir');
37
45
  const api = _api + '/column2';
38
46
  let info = {"msg":"failed"};
39
47
  var jqu = new Jqgrid_utils();
40
- info = await jqu.update_row_to_api(col_model,api,['id'],row,{server : '232',db : 'sl_h',table : 'kpi',});
41
- log.info(JSON.parse(info).msg);
48
+ info = await jqu.update_row_to_api($grid, api,['id'],row,{server : '232',db : 'sl_h',table : 'kpi',});
49
+ for(let i in info)
50
+ {
51
+ log.info(info[i]);
52
+ }
42
53
  },
43
-
44
- afterInsertRow: function( rowid, rowdata, rowelem ) {
45
- let tr = $("#"+rowid);
46
- $(tr).data("jqgrid.record_data", rowelem);
47
- },
48
-
49
-
50
54
  */
51
55
 
52
56
 
53
- async update_row_to_api(col_model, api='',_ids=['id'],row={}, data)
57
+ async update_row_to_api(_self, api='',_ids=['id'],row={}, data)
54
58
  {
55
- let self = this;
56
- let infos = [];
57
- if(api != '' && Object.keys(row).length > 0 )
59
+ let self = this;
60
+ let infos = [];
61
+ let ids = {};
62
+ let values = {};
63
+ let changed = {};
64
+ const rd = _self.jqGrid("getGridParam", "record_data");
65
+
66
+ if(api != '' && Object.keys(row).length > 0 && row.inputData.oper == 'edit')
67
+ {
68
+ for(let i in rd)
58
69
  {
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')
70
+ if (rd[i]['id'] === row.rowid)
68
71
  {
69
- for(let i in _ids)
72
+
73
+ for(let ii in _ids)
70
74
  {
71
- ids[_ids[i]] = row.inputData[_ids[i]];
75
+ if(rd[i].hasOwnProperty(_ids[ii]))
76
+ {
77
+ ids[_ids[ii]] = rd[i][_ids[ii]];
78
+ }
72
79
  }
73
- }
74
- else
75
- {
76
- ids['id']= '0';
77
- }
78
-
79
80
 
80
- if(rd)
81
- {
82
- for(let i in row.inputData)
81
+ for(let iii in row.inputData)
83
82
  {
84
- if(row.inputData.hasOwnProperty(i) && rd.hasOwnProperty(i))
83
+ if(iii != 'oper')
85
84
  {
86
- if(row.inputData[i] != rd[i])
85
+ if(Object.keys(ids).indexOf(iii) < 0)
87
86
  {
88
- changed[i] = row.inputData[i];
89
- }
87
+ //console.log(iii);
88
+ //console.log(row.inputData[iii]);
89
+ //console.log(rd[i][iii]);
90
+ if(row.inputData[iii] != rd[i][iii])
91
+ {
92
+ changed[iii] = row.inputData[iii];
93
+ }
94
+ }
90
95
  }
91
96
  }
92
- }
93
- else
94
- {
95
- changed =row.inputData;
96
- }
97
+ }
98
+ }
99
+
97
100
 
98
101
  for(let i in changed)
99
102
  {
@@ -105,14 +108,19 @@ module.exports = class Vanilla_website_utils
105
108
  data['ids'] = ids;
106
109
  data['values'] = col_value;
107
110
  data['operator'] = 'edit';
111
+ //console.log(data)
108
112
  const info = await self.post_json(api ,JSON.stringify(data));
109
113
  infos.push(info);
110
114
  }
111
115
  }
116
+
117
+
118
+
112
119
 
113
- }
114
- else if(row.inputData.oper == 'add')
115
- {
120
+ }
121
+ else if(api != '' && Object.keys(row).length > 0 && row.inputData.oper == 'add')
122
+ {
123
+ console.log("...add");
116
124
  for(let i in row.inputData)
117
125
  {
118
126
  if(row.inputData[i] && i != 'id' && i != 'oper')
@@ -123,51 +131,87 @@ module.exports = class Vanilla_website_utils
123
131
  data['ids'] = ids;
124
132
  data['values'] = values;
125
133
  data['operator'] = 'add';
134
+ //console.log(data);
126
135
  let info = await self.post_json(api ,JSON.stringify(data));
127
136
  infos.push(info);
128
- }
129
- }
137
+
138
+ }
130
139
 
131
140
  return infos;
132
141
  }
133
142
 
134
143
 
135
144
  /**
136
- * Take your row id value and send it to your delete post API server
137
- @alias module:Jqgrid_utils
138
- @param {string} - API URL like https://foo.com
139
- @param {array} - id list, ids from the column header (required)
145
+ * After Delete a Grid Row send to and DELETE REST Request
146
+ * You need to define loadComplete and afterDelRow
147
+ * The Grid data needs to be saved as record within loadComplete
148
+ @alias module:Jqgrid_utils
149
+ @param {object} - Grid Object (required)
150
+ @param {string} - API URL like https://foo.com (required)
151
+ @param {string} - the row id value from afterDelRow (required)
152
+ @param {array} - id list, ids from the column header colmodel (required)
140
153
  @param {object} - settings - extra key:value to send to your server
141
154
  @example
142
- afterDelRow: async function(rowid){
143
- const _api = await get_api_url('sapir');
144
- const api = _api + '/column2';
145
- let info = {"msg":"failed"};
146
- var jqu = new Jqgrid_utils();
147
- info = await jqu.delete_row_to_api(col_model,api,[rowid],{
148
- server : '232',
149
- db : 'sl_h',
150
- table : 'kpi',
151
- operator: 'delete',
152
- });
153
- log.info(JSON.parse(info).msg);
154
- },
155
+
156
+ loadComplete: async function()
157
+ {
158
+ $grid.jqGrid('setGridParam',{record_data:$grid.jqGrid("getGridParam").data});
159
+ },
160
+ afterDelRow: async function(rowid)
161
+ {
162
+ const _api = await get_api_url('sapir');
163
+ const api = _api + '/column2';
164
+ let info = {"msg":"failed"};
165
+ var jqu = new Jqgrid_utils();
166
+
167
+ info = await jqu.delete_row_to_api($grid,api,rowid,['id'],{
168
+ server : '232',
169
+ db : 'sl_h',
170
+ table : 'kpi',
171
+ operator: 'delete',
172
+ });
173
+ log.info(JSON.parse(info).msg);
174
+ },
175
+
176
+
177
+
178
+
179
+
155
180
  */
156
181
 
157
- async delete_row_to_api(col_model,api='', ids=[], data={})
158
- {
159
- let info = {"msg":"failed"};
160
- let self = this;
161
- if(api != '')
182
+ async delete_row_to_api(_self, api='', rowid, _ids=[], data={})
162
183
  {
163
- data['values'] = ids;
164
- if(! data.hasOwnProperty("id"))
184
+ let info = {"msg":"failed"};
185
+ let self = this;
186
+ let ids = [];
187
+ let values = {};
188
+ const rd = _self.jqGrid("getGridParam", "record_data");
189
+ for(let i in rd)
190
+ {
191
+ if (rd[i]['id'] === rowid)
192
+ {
193
+ for(let ii in _ids)
194
+ {
195
+ if(rd[i].hasOwnProperty(_ids[ii]))
196
+ {
197
+ values[_ids[ii]] = rd[i][_ids[ii]];
198
+ ids.push(_ids[ii]);
199
+ }
200
+ }
201
+ break;
202
+ }
203
+ }
204
+
205
+
206
+
207
+ if(api != '' && Object.keys(values).length == ids.length )
165
208
  {
166
- data['id'] = 'id';
209
+ data['ids'] = ids;
210
+ data['values'] = values;
211
+ //console.log(data);
212
+ info = await self.adelete_api(api,JSON.stringify(data));
167
213
  }
168
- info = await self.adelete_api(api,JSON.stringify(data));
169
- }
170
- return info;
214
+ return info;
171
215
  }
172
216
 
173
217
 
package/jqgrid_utils.js CHANGED
@@ -23,76 +23,79 @@ module.exports = class Vanilla_website_utils
23
23
 
24
24
  /**
25
25
  * Takes the updated columns data and send it to your API post server
26
+ * loadComplete: async function() for the old record needs to be called, see example !
26
27
  @alias module:Jqgrid_utils
28
+ @param {object} - Grid Object (required)
27
29
  @param {string} - API URL like https://foo.com (required)
28
30
  @param {array} - id list, ids from the column header (required)
29
31
  @param {object} - settings - extra key:value to send to your server
30
32
 
31
- @example
32
- },
33
+ @example
34
+ var jqu = new Jqgrid_utils({page:page});
35
+
36
+ ....},
37
+ loadComplete: async function()
38
+ {
39
+ $grid.jqGrid('setGridParam',{record_data:$grid.jqGrid("getGridParam").data});
40
+ },
33
41
  afterSetRow: async function(row)
34
42
  {
35
43
  const _api = await get_api_url('sapir');
36
44
  const api = _api + '/column2';
37
45
  let info = {"msg":"failed"};
38
46
  var jqu = new Jqgrid_utils();
39
- info = await jqu.update_row_to_api(col_model,api,['id'],row,{server : '232',db : 'sl_h',table : 'kpi',});
40
- log.info(JSON.parse(info).msg);
47
+ info = await jqu.update_row_to_api($grid, api,['id'],row,{server : '232',db : 'sl_h',table : 'kpi',});
48
+ for(let i in info)
49
+ {
50
+ log.info(info[i]);
51
+ }
41
52
  },
42
-
43
- afterInsertRow: function( rowid, rowdata, rowelem ) {
44
- let tr = $("#"+rowid);
45
- $(tr).data("jqgrid.record_data", rowelem);
46
- },
47
-
48
-
49
53
  */
50
54
 
51
55
 
52
- async update_row_to_api(col_model, api='',_ids=['id'],row={}, data)
56
+ async update_row_to_api(_self, api='',_ids=['id'],row={}, data)
53
57
  {
54
- let self = this;
55
- let infos = [];
56
- if(api != '' && Object.keys(row).length > 0 )
58
+ let self = this;
59
+ let infos = [];
60
+ let ids = {};
61
+ let values = {};
62
+ let changed = {};
63
+ const rd = _self.jqGrid("getGridParam", "record_data");
64
+
65
+ if(api != '' && Object.keys(row).length > 0 && row.inputData.oper == 'edit')
66
+ {
67
+ for(let i in rd)
57
68
  {
58
- let ids = {};
59
- let values = {};
60
- if(row.inputData.oper == 'edit')
61
- {
62
- let changed = {};
63
- const tr = $("#"+row.rowid);
64
- const rd = $(tr).data("jqgrid.record_data");
65
-
66
- if(row.inputData.oper == 'edit')
69
+ if (rd[i]['id'] === row.rowid)
67
70
  {
68
- for(let i in _ids)
71
+
72
+ for(let ii in _ids)
69
73
  {
70
- ids[_ids[i]] = row.inputData[_ids[i]];
74
+ if(rd[i].hasOwnProperty(_ids[ii]))
75
+ {
76
+ ids[_ids[ii]] = rd[i][_ids[ii]];
77
+ }
71
78
  }
72
- }
73
- else
74
- {
75
- ids['id']= '0';
76
- }
77
-
78
79
 
79
- if(rd)
80
- {
81
- for(let i in row.inputData)
80
+ for(let iii in row.inputData)
82
81
  {
83
- if(row.inputData.hasOwnProperty(i) && rd.hasOwnProperty(i))
82
+ if(iii != 'oper')
84
83
  {
85
- if(row.inputData[i] != rd[i])
84
+ if(Object.keys(ids).indexOf(iii) < 0)
86
85
  {
87
- changed[i] = row.inputData[i];
88
- }
86
+ //console.log(iii);
87
+ //console.log(row.inputData[iii]);
88
+ //console.log(rd[i][iii]);
89
+ if(row.inputData[iii] != rd[i][iii])
90
+ {
91
+ changed[iii] = row.inputData[iii];
92
+ }
93
+ }
89
94
  }
90
95
  }
91
- }
92
- else
93
- {
94
- changed =row.inputData;
95
- }
96
+ }
97
+ }
98
+
96
99
 
97
100
  for(let i in changed)
98
101
  {
@@ -104,14 +107,19 @@ module.exports = class Vanilla_website_utils
104
107
  data['ids'] = ids;
105
108
  data['values'] = col_value;
106
109
  data['operator'] = 'edit';
110
+ //console.log(data)
107
111
  const info = await self.post_json(api ,JSON.stringify(data));
108
112
  infos.push(info);
109
113
  }
110
114
  }
115
+
116
+
117
+
111
118
 
112
- }
113
- else if(row.inputData.oper == 'add')
114
- {
119
+ }
120
+ else if(api != '' && Object.keys(row).length > 0 && row.inputData.oper == 'add')
121
+ {
122
+ console.log("...add");
115
123
  for(let i in row.inputData)
116
124
  {
117
125
  if(row.inputData[i] && i != 'id' && i != 'oper')
@@ -122,51 +130,87 @@ module.exports = class Vanilla_website_utils
122
130
  data['ids'] = ids;
123
131
  data['values'] = values;
124
132
  data['operator'] = 'add';
133
+ //console.log(data);
125
134
  let info = await self.post_json(api ,JSON.stringify(data));
126
135
  infos.push(info);
127
- }
128
- }
136
+
137
+ }
129
138
 
130
139
  return infos;
131
140
  }
132
141
 
133
142
 
134
143
  /**
135
- * Take your row id value and send it to your delete post API server
136
- @alias module:Jqgrid_utils
137
- @param {string} - API URL like https://foo.com
138
- @param {array} - id list, ids from the column header (required)
144
+ * After Delete a Grid Row send to and DELETE REST Request
145
+ * You need to define loadComplete and afterDelRow
146
+ * The Grid data needs to be saved as record within loadComplete
147
+ @alias module:Jqgrid_utils
148
+ @param {object} - Grid Object (required)
149
+ @param {string} - API URL like https://foo.com (required)
150
+ @param {string} - the row id value from afterDelRow (required)
151
+ @param {array} - id list, ids from the column header colmodel (required)
139
152
  @param {object} - settings - extra key:value to send to your server
140
153
  @example
141
- afterDelRow: async function(rowid){
142
- const _api = await get_api_url('sapir');
143
- const api = _api + '/column2';
144
- let info = {"msg":"failed"};
145
- var jqu = new Jqgrid_utils();
146
- info = await jqu.delete_row_to_api(col_model,api,[rowid],{
147
- server : '232',
148
- db : 'sl_h',
149
- table : 'kpi',
150
- operator: 'delete',
151
- });
152
- log.info(JSON.parse(info).msg);
153
- },
154
+
155
+ loadComplete: async function()
156
+ {
157
+ $grid.jqGrid('setGridParam',{record_data:$grid.jqGrid("getGridParam").data});
158
+ },
159
+ afterDelRow: async function(rowid)
160
+ {
161
+ const _api = await get_api_url('sapir');
162
+ const api = _api + '/column2';
163
+ let info = {"msg":"failed"};
164
+ var jqu = new Jqgrid_utils();
165
+
166
+ info = await jqu.delete_row_to_api($grid,api,rowid,['id'],{
167
+ server : '232',
168
+ db : 'sl_h',
169
+ table : 'kpi',
170
+ operator: 'delete',
171
+ });
172
+ log.info(JSON.parse(info).msg);
173
+ },
174
+
175
+
176
+
177
+
178
+
154
179
  */
155
180
 
156
- async delete_row_to_api(col_model,api='', ids=[], data={})
157
- {
158
- let info = {"msg":"failed"};
159
- let self = this;
160
- if(api != '')
181
+ async delete_row_to_api(_self, api='', rowid, _ids=[], data={})
161
182
  {
162
- data['values'] = ids;
163
- if(! data.hasOwnProperty("id"))
183
+ let info = {"msg":"failed"};
184
+ let self = this;
185
+ let ids = [];
186
+ let values = {};
187
+ const rd = _self.jqGrid("getGridParam", "record_data");
188
+ for(let i in rd)
189
+ {
190
+ if (rd[i]['id'] === rowid)
191
+ {
192
+ for(let ii in _ids)
193
+ {
194
+ if(rd[i].hasOwnProperty(_ids[ii]))
195
+ {
196
+ values[_ids[ii]] = rd[i][_ids[ii]];
197
+ ids.push(_ids[ii]);
198
+ }
199
+ }
200
+ break;
201
+ }
202
+ }
203
+
204
+
205
+
206
+ if(api != '' && Object.keys(values).length == ids.length )
164
207
  {
165
- data['id'] = 'id';
208
+ data['ids'] = ids;
209
+ data['values'] = values;
210
+ //console.log(data);
211
+ info = await self.adelete_api(api,JSON.stringify(data));
166
212
  }
167
- info = await self.adelete_api(api,JSON.stringify(data));
168
- }
169
- return info;
213
+ return info;
170
214
  }
171
215
 
172
216
 
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.22.0"
32
+ "version": "1.24.0"
33
33
  }