jqgrid_utils 1.21.0 → 1.22.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(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
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,66 @@ 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(col_model, api, _ids) ⏏
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
+ | 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 |
82
+
83
+ **Example**
84
+ ```js
85
+ },
86
+ afterSetRow: async function(row)
87
+ {
88
+ const _api = await get_api_url('sapir');
89
+ const api = _api + '/column2';
90
+ let info = {"msg":"failed"};
91
+ 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);
94
+ },
95
+
96
+ afterInsertRow: function( rowid, rowdata, rowelem ) {
97
+ let tr = $("#"+rowid);
98
+ $(tr).data("jqgrid.record_data", rowelem);
99
+ },
100
+ ```
101
+ <a name="exp_module_Jqgrid_utils--module.exports+delete_row_to_api"></a>
102
+
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
105
+
106
+ **Kind**: Exported function
107
+
108
+ | Param | Type | Description |
109
+ | --- | --- | --- |
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
+ },
129
+ ```
68
130
  <a name="exp_module_Jqgrid_utils--module.exports+append_seperator_link_column"></a>
69
131
 
70
132
  ### module.exports#append\_seperator\_link\_column(col_model, url, field_value, base, attr, keys) ⏏
@@ -22,6 +22,155 @@ 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 {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(col_model,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(col_model, 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
+ * 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)
140
+ @param {object} - settings - extra key:value to send to your server
141
+ @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
+
157
+ async delete_row_to_api(col_model,api='', ids=[], data={})
158
+ {
159
+ let info = {"msg":"failed"};
160
+ let self = this;
161
+ if(api != '')
162
+ {
163
+ data['values'] = ids;
164
+ if(! data.hasOwnProperty("id"))
165
+ {
166
+ data['id'] = 'id';
167
+ }
168
+ info = await self.adelete_api(api,JSON.stringify(data));
169
+ }
170
+ return info;
171
+ }
172
+
173
+
25
174
 
26
175
 
27
176
  /**
@@ -786,7 +935,13 @@ afterDelRow: async function(row)
786
935
 
787
936
  async adelete_api(url, json = false)
788
937
  {
789
- const ctype = json ? "application/json;charset=UTF-8" : "application/x-www-form-urlencoded";
938
+ let ctype = "application/x-www-form-urlencoded";
939
+ let body = null;
940
+ if(json)
941
+ {
942
+ ctype = "application/json;charset=UTF-8" ;
943
+ body = json;
944
+ }
790
945
  return new Promise((resolve, reject) =>
791
946
  {
792
947
  let xhr = new XMLHttpRequest();
@@ -794,12 +949,11 @@ async adelete_api(url, json = false)
794
949
  xhr.setRequestHeader("Content-type", ctype);
795
950
  xhr.onload = () => resolve(xhr.responseText);
796
951
  xhr.onerror = () => reject(xhr.statusText);
797
- xhr.send(null);
952
+ xhr.send(body);
798
953
  });
799
954
  }
800
955
 
801
956
 
802
-
803
957
  /**
804
958
  * Async Post request used by the update_row function
805
959
  @alias module:Jqgrid_utils
package/jqgrid_utils.js CHANGED
@@ -21,6 +21,155 @@ 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 {string} - API URL like https://foo.com (required)
28
+ @param {array} - id list, ids from the column header (required)
29
+ @param {object} - settings - extra key:value to send to your server
30
+
31
+ @example
32
+ },
33
+ afterSetRow: async function(row)
34
+ {
35
+ const _api = await get_api_url('sapir');
36
+ const api = _api + '/column2';
37
+ let info = {"msg":"failed"};
38
+ 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);
41
+ },
42
+
43
+ afterInsertRow: function( rowid, rowdata, rowelem ) {
44
+ let tr = $("#"+rowid);
45
+ $(tr).data("jqgrid.record_data", rowelem);
46
+ },
47
+
48
+
49
+ */
50
+
51
+
52
+ async update_row_to_api(col_model, api='',_ids=['id'],row={}, data)
53
+ {
54
+ let self = this;
55
+ let infos = [];
56
+ if(api != '' && Object.keys(row).length > 0 )
57
+ {
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')
67
+ {
68
+ for(let i in _ids)
69
+ {
70
+ ids[_ids[i]] = row.inputData[_ids[i]];
71
+ }
72
+ }
73
+ else
74
+ {
75
+ ids['id']= '0';
76
+ }
77
+
78
+
79
+ if(rd)
80
+ {
81
+ for(let i in row.inputData)
82
+ {
83
+ if(row.inputData.hasOwnProperty(i) && rd.hasOwnProperty(i))
84
+ {
85
+ if(row.inputData[i] != rd[i])
86
+ {
87
+ changed[i] = row.inputData[i];
88
+ }
89
+ }
90
+ }
91
+ }
92
+ else
93
+ {
94
+ changed =row.inputData;
95
+ }
96
+
97
+ for(let i in changed)
98
+ {
99
+ if( Object.keys(ids).indexOf(i) < 0 && i!= 'oper')
100
+ {
101
+ const col_name = i;
102
+ let col_value = {};
103
+ col_value[col_name] = changed[i];
104
+ data['ids'] = ids;
105
+ data['values'] = col_value;
106
+ data['operator'] = 'edit';
107
+ const info = await self.post_json(api ,JSON.stringify(data));
108
+ infos.push(info);
109
+ }
110
+ }
111
+
112
+ }
113
+ else if(row.inputData.oper == 'add')
114
+ {
115
+ for(let i in row.inputData)
116
+ {
117
+ if(row.inputData[i] && i != 'id' && i != 'oper')
118
+ {
119
+ values[i] = row.inputData[i];
120
+ }
121
+ }
122
+ data['ids'] = ids;
123
+ data['values'] = values;
124
+ data['operator'] = 'add';
125
+ let info = await self.post_json(api ,JSON.stringify(data));
126
+ infos.push(info);
127
+ }
128
+ }
129
+
130
+ return infos;
131
+ }
132
+
133
+
134
+ /**
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)
139
+ @param {object} - settings - extra key:value to send to your server
140
+ @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
+
156
+ async delete_row_to_api(col_model,api='', ids=[], data={})
157
+ {
158
+ let info = {"msg":"failed"};
159
+ let self = this;
160
+ if(api != '')
161
+ {
162
+ data['values'] = ids;
163
+ if(! data.hasOwnProperty("id"))
164
+ {
165
+ data['id'] = 'id';
166
+ }
167
+ info = await self.adelete_api(api,JSON.stringify(data));
168
+ }
169
+ return info;
170
+ }
171
+
172
+
24
173
 
25
174
 
26
175
  /**
@@ -785,7 +934,13 @@ afterDelRow: async function(row)
785
934
 
786
935
  async adelete_api(url, json = false)
787
936
  {
788
- const ctype = json ? "application/json;charset=UTF-8" : "application/x-www-form-urlencoded";
937
+ let ctype = "application/x-www-form-urlencoded";
938
+ let body = null;
939
+ if(json)
940
+ {
941
+ ctype = "application/json;charset=UTF-8" ;
942
+ body = json;
943
+ }
789
944
  return new Promise((resolve, reject) =>
790
945
  {
791
946
  let xhr = new XMLHttpRequest();
@@ -793,12 +948,11 @@ async adelete_api(url, json = false)
793
948
  xhr.setRequestHeader("Content-type", ctype);
794
949
  xhr.onload = () => resolve(xhr.responseText);
795
950
  xhr.onerror = () => reject(xhr.statusText);
796
- xhr.send(null);
951
+ xhr.send(body);
797
952
  });
798
953
  }
799
954
 
800
955
 
801
-
802
956
  /**
803
957
  * Async Post request used by the update_row function
804
958
  @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.22.0"
33
33
  }