jqgrid_utils 1.20.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 +85 -0
- package/dist/jqgrid_utils.js +250 -3
- package/jqgrid_utils.js +250 -3
- package/package.json +1 -1
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) ⏏
|
|
@@ -55,6 +57,7 @@ A module for Jqgrid_utils
|
|
|
55
57
|
* [module.exports#put_json(url, data)](#exp_module_Jqgrid_utils--module.exports+put_json) ⇒ <code>object</code> ⏏
|
|
56
58
|
* [module.exports#s_hide_del_icon()](#exp_module_Jqgrid_utils--module.exports+s_hide_del_icon) ⏏
|
|
57
59
|
* [module.exports#hide_del_icon()](#exp_module_Jqgrid_utils--module.exports+hide_del_icon) ⏏
|
|
60
|
+
* [module.exports#add_link_details_csv(col_model, url, edit_field, attr, keys, format, seperator)](#exp_module_Jqgrid_utils--module.exports+add_link_details_csv) ⏏
|
|
58
61
|
* [module.exports#add_link_details(col_model, url, edit_field, attr, keys)](#exp_module_Jqgrid_utils--module.exports+add_link_details) ⏏
|
|
59
62
|
* [module.exports#add_link_details_separator(col_model, url, edit_field, attr, keys)](#exp_module_Jqgrid_utils--module.exports+add_link_details_separator) ⏏
|
|
60
63
|
* [module.exports#add_link_separator(col_model, url, edit_field, fields)](#exp_module_Jqgrid_utils--module.exports+add_link_separator) ⏏
|
|
@@ -64,6 +67,66 @@ A module for Jqgrid_utils
|
|
|
64
67
|
* [module.exports#set_filter(grid, data, fx, append_to)](#exp_module_Jqgrid_utils--module.exports+set_filter) ⏏
|
|
65
68
|
* [module.exports#_filter()](#exp_module_Jqgrid_utils--module.exports+_filter) ⏏
|
|
66
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
|
+
```
|
|
67
130
|
<a name="exp_module_Jqgrid_utils--module.exports+append_seperator_link_column"></a>
|
|
68
131
|
|
|
69
132
|
### module.exports#append\_seperator\_link\_column(col_model, url, field_value, base, attr, keys) ⏏
|
|
@@ -585,6 +648,28 @@ Hide the del iconf rom the grid
|
|
|
585
648
|
var jqu = new Jqgrid_utils();
|
|
586
649
|
await jqu.hide_del_icon();
|
|
587
650
|
```
|
|
651
|
+
<a name="exp_module_Jqgrid_utils--module.exports+add_link_details_csv"></a>
|
|
652
|
+
|
|
653
|
+
### module.exports#add\_link\_details\_csv(col_model, url, edit_field, attr, keys, format, seperator) ⏏
|
|
654
|
+
Convert a cell into a link/url with data from another cell and spit the value by comma - CSV
|
|
655
|
+
|
|
656
|
+
**Kind**: Exported function
|
|
657
|
+
|
|
658
|
+
| Param | Type | Default | Description |
|
|
659
|
+
| --- | --- | --- | --- |
|
|
660
|
+
| col_model | <code>object</code> | | col_model of the grid |
|
|
661
|
+
| url | <code>string</code> | | URL string |
|
|
662
|
+
| edit_field | <code>string</code> | | Column/Cell to use |
|
|
663
|
+
| attr | <code>string</code> | | URL Attributes |
|
|
664
|
+
| keys | <code>object</code> | | keys and fields value to use |
|
|
665
|
+
| format | <code>object</code> | | format info |
|
|
666
|
+
| seperator | <code>string</code> | <code>","</code> | seperator of the cell value to split (default is comma) |
|
|
667
|
+
|
|
668
|
+
**Example**
|
|
669
|
+
```js
|
|
670
|
+
var jqu = new Jqgrid_utils();
|
|
671
|
+
col_model = await jqu.add_link_details_csv(col_model, host + '/html/report.html' , 'tags','target="_blank"',{"tags":"tags"},',');
|
|
672
|
+
```
|
|
588
673
|
<a name="exp_module_Jqgrid_utils--module.exports+add_link_details"></a>
|
|
589
674
|
|
|
590
675
|
### module.exports#add\_link\_details(col_model, url, edit_field, attr, keys) ⏏
|
package/dist/jqgrid_utils.js
CHANGED
|
@@ -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
|
-
|
|
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(
|
|
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
|
|
@@ -872,6 +1026,99 @@ async hide_del_icon()
|
|
|
872
1026
|
}
|
|
873
1027
|
|
|
874
1028
|
|
|
1029
|
+
/**
|
|
1030
|
+
* Convert a cell into a link/url with data from another cell and spit the value by comma - CSV
|
|
1031
|
+
@alias module:Jqgrid_utils
|
|
1032
|
+
@param {object} - col_model of the grid
|
|
1033
|
+
@param {string} - URL string
|
|
1034
|
+
@param {string} - Column/Cell to use
|
|
1035
|
+
@param {string} - URL Attributes
|
|
1036
|
+
@param {object} - keys and fields value to use
|
|
1037
|
+
@param {object} - format info
|
|
1038
|
+
@param {string} - seperator of the cell value to split (default is comma)
|
|
1039
|
+
@example
|
|
1040
|
+
var jqu = new Jqgrid_utils();
|
|
1041
|
+
col_model = await jqu.add_link_details_csv(col_model, host + '/html/report.html' , 'tags','target="_blank"',{"tags":"tags"},',');
|
|
1042
|
+
|
|
1043
|
+
*/
|
|
1044
|
+
async add_link_details_csv(col_model, url, edit_field, attr = '', keys, format, seperator=',')
|
|
1045
|
+
{
|
|
1046
|
+
let self = this;
|
|
1047
|
+
if (url.indexOf('?') > -1)
|
|
1048
|
+
{
|
|
1049
|
+
url = url + '&';
|
|
1050
|
+
}
|
|
1051
|
+
else
|
|
1052
|
+
{
|
|
1053
|
+
url = url + '?';
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1056
|
+
for (let i = 0; i < col_model.length; i++)
|
|
1057
|
+
{
|
|
1058
|
+
if (col_model[i]['name'] === edit_field)
|
|
1059
|
+
{
|
|
1060
|
+
col_model[i]['formatter'] = function(cell_val, obj)
|
|
1061
|
+
{
|
|
1062
|
+
let key_val = cell_val;
|
|
1063
|
+
const _cell_val = self.__cell_format(cell_val, format);
|
|
1064
|
+
const a = _cell_val.split(seperator);
|
|
1065
|
+
let cell_value = '';
|
|
1066
|
+
for(let x in a)
|
|
1067
|
+
{
|
|
1068
|
+
const x_value = a[x].trim();
|
|
1069
|
+
if(x_value)
|
|
1070
|
+
{
|
|
1071
|
+
if (typeof keys === 'object')
|
|
1072
|
+
{
|
|
1073
|
+
let pref = '';
|
|
1074
|
+
for (let ii in keys)
|
|
1075
|
+
{
|
|
1076
|
+
let key = ii;
|
|
1077
|
+
let v = keys[ii];
|
|
1078
|
+
key_val = obj.rowData[v];
|
|
1079
|
+
if (key_val)
|
|
1080
|
+
{
|
|
1081
|
+
if (key.indexOf('=') !== -1)
|
|
1082
|
+
{
|
|
1083
|
+
pref = pref + '' + key + '' + encodeURIComponent(x_value) + '&';
|
|
1084
|
+
}
|
|
1085
|
+
else
|
|
1086
|
+
{
|
|
1087
|
+
pref = pref + '' + key + '=' + encodeURIComponent(x_value) + '&';
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
if (pref.slice(-1) === '&')
|
|
1092
|
+
{
|
|
1093
|
+
pref = pref.slice(0, -1);
|
|
1094
|
+
}
|
|
1095
|
+
cell_value += '<a ' + attr + 'href="' + url + pref + '"> ' + x_value + '</a>' + seperator + ' ';
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
cell_val = cell_value.trim();
|
|
1099
|
+
if(cell_val.slice(-1) === seperator) //remove last seperator
|
|
1100
|
+
{
|
|
1101
|
+
cell_val = cell_val.slice(0, -1);
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1104
|
+
}
|
|
1105
|
+
|
|
1106
|
+
if(cell_val)
|
|
1107
|
+
{
|
|
1108
|
+
return cell_val;
|
|
1109
|
+
}
|
|
1110
|
+
else
|
|
1111
|
+
{
|
|
1112
|
+
return _cell_val;
|
|
1113
|
+
}
|
|
1114
|
+
};
|
|
1115
|
+
}
|
|
1116
|
+
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
return col_model;
|
|
1120
|
+
}
|
|
1121
|
+
|
|
875
1122
|
|
|
876
1123
|
/**
|
|
877
1124
|
* Convert a cell into a link/url with data from another cell
|
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
|
-
|
|
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(
|
|
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
|
|
@@ -871,6 +1025,99 @@ async hide_del_icon()
|
|
|
871
1025
|
}
|
|
872
1026
|
|
|
873
1027
|
|
|
1028
|
+
/**
|
|
1029
|
+
* Convert a cell into a link/url with data from another cell and spit the value by comma - CSV
|
|
1030
|
+
@alias module:Jqgrid_utils
|
|
1031
|
+
@param {object} - col_model of the grid
|
|
1032
|
+
@param {string} - URL string
|
|
1033
|
+
@param {string} - Column/Cell to use
|
|
1034
|
+
@param {string} - URL Attributes
|
|
1035
|
+
@param {object} - keys and fields value to use
|
|
1036
|
+
@param {object} - format info
|
|
1037
|
+
@param {string} - seperator of the cell value to split (default is comma)
|
|
1038
|
+
@example
|
|
1039
|
+
var jqu = new Jqgrid_utils();
|
|
1040
|
+
col_model = await jqu.add_link_details_csv(col_model, host + '/html/report.html' , 'tags','target="_blank"',{"tags":"tags"},',');
|
|
1041
|
+
|
|
1042
|
+
*/
|
|
1043
|
+
async add_link_details_csv(col_model, url, edit_field, attr = '', keys, format, seperator=',')
|
|
1044
|
+
{
|
|
1045
|
+
let self = this;
|
|
1046
|
+
if (url.indexOf('?') > -1)
|
|
1047
|
+
{
|
|
1048
|
+
url = url + '&';
|
|
1049
|
+
}
|
|
1050
|
+
else
|
|
1051
|
+
{
|
|
1052
|
+
url = url + '?';
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
for (let i = 0; i < col_model.length; i++)
|
|
1056
|
+
{
|
|
1057
|
+
if (col_model[i]['name'] === edit_field)
|
|
1058
|
+
{
|
|
1059
|
+
col_model[i]['formatter'] = function(cell_val, obj)
|
|
1060
|
+
{
|
|
1061
|
+
let key_val = cell_val;
|
|
1062
|
+
const _cell_val = self.__cell_format(cell_val, format);
|
|
1063
|
+
const a = _cell_val.split(seperator);
|
|
1064
|
+
let cell_value = '';
|
|
1065
|
+
for(let x in a)
|
|
1066
|
+
{
|
|
1067
|
+
const x_value = a[x].trim();
|
|
1068
|
+
if(x_value)
|
|
1069
|
+
{
|
|
1070
|
+
if (typeof keys === 'object')
|
|
1071
|
+
{
|
|
1072
|
+
let pref = '';
|
|
1073
|
+
for (let ii in keys)
|
|
1074
|
+
{
|
|
1075
|
+
let key = ii;
|
|
1076
|
+
let v = keys[ii];
|
|
1077
|
+
key_val = obj.rowData[v];
|
|
1078
|
+
if (key_val)
|
|
1079
|
+
{
|
|
1080
|
+
if (key.indexOf('=') !== -1)
|
|
1081
|
+
{
|
|
1082
|
+
pref = pref + '' + key + '' + encodeURIComponent(x_value) + '&';
|
|
1083
|
+
}
|
|
1084
|
+
else
|
|
1085
|
+
{
|
|
1086
|
+
pref = pref + '' + key + '=' + encodeURIComponent(x_value) + '&';
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
if (pref.slice(-1) === '&')
|
|
1091
|
+
{
|
|
1092
|
+
pref = pref.slice(0, -1);
|
|
1093
|
+
}
|
|
1094
|
+
cell_value += '<a ' + attr + 'href="' + url + pref + '"> ' + x_value + '</a>' + seperator + ' ';
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
cell_val = cell_value.trim();
|
|
1098
|
+
if(cell_val.slice(-1) === seperator) //remove last seperator
|
|
1099
|
+
{
|
|
1100
|
+
cell_val = cell_val.slice(0, -1);
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
if(cell_val)
|
|
1106
|
+
{
|
|
1107
|
+
return cell_val;
|
|
1108
|
+
}
|
|
1109
|
+
else
|
|
1110
|
+
{
|
|
1111
|
+
return _cell_val;
|
|
1112
|
+
}
|
|
1113
|
+
};
|
|
1114
|
+
}
|
|
1115
|
+
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1118
|
+
return col_model;
|
|
1119
|
+
}
|
|
1120
|
+
|
|
874
1121
|
|
|
875
1122
|
/**
|
|
876
1123
|
* Convert a cell into a link/url with data from another cell
|
package/package.json
CHANGED