jqgrid_utils 1.35.2 → 1.37.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/.github/workflows/npm.yml +24 -12
- package/README.md +41 -0
- package/_README.md +4 -0
- package/dist/jqgrid_utils.js +46 -1
- package/dist/jqgrid_utils.min.js +1 -0
- package/jqgrid_utils.js +46 -1
- package/make_doc.sh +6 -3
- package/make_min.sh +6 -0
- package/package.json +4 -9
- package/{make.sh → watch.sh} +2 -0
- package/.hgignore +0 -17
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
name: Publish Package to npmjs
|
|
2
2
|
on: push
|
|
3
|
+
permissions:
|
|
4
|
+
id-token: write # Required for OIDC
|
|
5
|
+
contents: read
|
|
3
6
|
jobs:
|
|
4
7
|
build:
|
|
5
8
|
if: github.repository_owner == 'myridia'
|
|
@@ -8,16 +11,25 @@ jobs:
|
|
|
8
11
|
contents: read
|
|
9
12
|
id-token: write
|
|
10
13
|
steps:
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
- run: npm ci
|
|
19
|
-
- run: npm publish --provenance --access public
|
|
20
|
-
env:
|
|
21
|
-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
14
|
+
- name: Request OIDC token
|
|
15
|
+
id: oidc-token
|
|
16
|
+
uses: actions/github-script@v7
|
|
17
|
+
with:
|
|
18
|
+
script: |
|
|
19
|
+
const token = await core.getIDToken();
|
|
20
|
+
core.info(`OIDC token: ${token.substring(0,20)}...`);
|
|
22
21
|
|
|
23
|
-
|
|
22
|
+
- name: checkout
|
|
23
|
+
uses: actions/checkout@v4
|
|
24
|
+
- name: setup
|
|
25
|
+
uses: actions/setup-node@v4
|
|
26
|
+
with:
|
|
27
|
+
node-version: '24.x' # Your node version
|
|
28
|
+
registry-url: 'https://registry.npmjs.org'
|
|
29
|
+
always-auth: true
|
|
30
|
+
|
|
31
|
+
- run: npm install --package-lock-only
|
|
32
|
+
- run: npm ci
|
|
33
|
+
- run: npm run build --if-present
|
|
34
|
+
- run: npm publish --provenance --access public
|
|
35
|
+
|
package/README.md
CHANGED
|
@@ -19,6 +19,10 @@ Convenient Functions for free jqGrid
|
|
|
19
19
|
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
+
# Documentation
|
|
23
|
+
https://github.com/myridia/jqgrid_utils/blob/main/README.md
|
|
24
|
+
|
|
25
|
+
# Source code:
|
|
22
26
|
Source: https://github.com/myridia/jqgrid_utils/actions
|
|
23
27
|
|
|
24
28
|
<a name="module_Jqgrid_utils"></a>
|
|
@@ -28,6 +32,8 @@ A module for Jqgrid_utils
|
|
|
28
32
|
|
|
29
33
|
|
|
30
34
|
* [Jqgrid_utils](#module_Jqgrid_utils)
|
|
35
|
+
* [module.exports#add_checkbox(col_model, field_name)](#exp_module_Jqgrid_utils--module.exports+add_checkbox) ⏏
|
|
36
|
+
* [module.exports#add_class(col_model, field_name, class_name)](#exp_module_Jqgrid_utils--module.exports+add_class) ⏏
|
|
31
37
|
* [module.exports#_grid_substract_on()](#exp_module_Jqgrid_utils--module.exports+_grid_substract_on) ⏏
|
|
32
38
|
* [module.exports#grid_substract_on(grid, minuend, subtrahend, difference, no_negative)](#exp_module_Jqgrid_utils--module.exports+grid_substract_on) ⏏
|
|
33
39
|
* [module.exports#_grid_ratio_on()](#exp_module_Jqgrid_utils--module.exports+_grid_ratio_on) ⏏
|
|
@@ -86,6 +92,41 @@ A module for Jqgrid_utils
|
|
|
86
92
|
* [module.exports#set_filter(grid, data, fx, append_to)](#exp_module_Jqgrid_utils--module.exports+set_filter) ⏏
|
|
87
93
|
* [module.exports#_filter()](#exp_module_Jqgrid_utils--module.exports+_filter) ⏏
|
|
88
94
|
|
|
95
|
+
<a name="exp_module_Jqgrid_utils--module.exports+add_checkbox"></a>
|
|
96
|
+
|
|
97
|
+
### module.exports#add\_checkbox(col_model, field_name) ⏏
|
|
98
|
+
Add a Checkbox to the Model
|
|
99
|
+
|
|
100
|
+
**Kind**: Exported function
|
|
101
|
+
|
|
102
|
+
| Param | Type | Description |
|
|
103
|
+
| --- | --- | --- |
|
|
104
|
+
| col_model | <code>array</code> | grid col_model |
|
|
105
|
+
| field_name | <code>string</code> | column_name |
|
|
106
|
+
|
|
107
|
+
**Example**
|
|
108
|
+
```js
|
|
109
|
+
var jqu = new Jqgrid_utils();
|
|
110
|
+
ol_model = await jqu.add_checkbox(col_model, "closed");
|
|
111
|
+
```
|
|
112
|
+
<a name="exp_module_Jqgrid_utils--module.exports+add_class"></a>
|
|
113
|
+
|
|
114
|
+
### module.exports#add\_class(col_model, field_name, class_name) ⏏
|
|
115
|
+
Add a Class to the Model
|
|
116
|
+
|
|
117
|
+
**Kind**: Exported function
|
|
118
|
+
|
|
119
|
+
| Param | Type | Description |
|
|
120
|
+
| --- | --- | --- |
|
|
121
|
+
| col_model | <code>array</code> | grid col_model |
|
|
122
|
+
| field_name | <code>string</code> | column_name |
|
|
123
|
+
| class_name | <code>string</code> | class_name |
|
|
124
|
+
|
|
125
|
+
**Example**
|
|
126
|
+
```js
|
|
127
|
+
var jqu = new Jqgrid_utils();
|
|
128
|
+
col_model = await jqu.add_class(col_model,field_name,class_name)
|
|
129
|
+
```
|
|
89
130
|
<a name="exp_module_Jqgrid_utils--module.exports+_grid_substract_on"></a>
|
|
90
131
|
|
|
91
132
|
### module.exports#\_grid\_substract\_on() ⏏
|
package/_README.md
CHANGED
package/dist/jqgrid_utils.js
CHANGED
|
@@ -16,6 +16,51 @@ module.exports = class Vanilla_website_utils {
|
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
/**
|
|
20
|
+
* Add a Checkbox to the Model
|
|
21
|
+
@alias module:Jqgrid_utils
|
|
22
|
+
@param {array} - grid col_model
|
|
23
|
+
@param {string} - column_name
|
|
24
|
+
@example
|
|
25
|
+
var jqu = new Jqgrid_utils();
|
|
26
|
+
ol_model = await jqu.add_checkbox(col_model, "closed");
|
|
27
|
+
*/
|
|
28
|
+
async add_checkbox(col_model, field_name) {
|
|
29
|
+
for (let i = 0; i < col_model.length; i++) {
|
|
30
|
+
if (col_model[i]["name"] === field_name) {
|
|
31
|
+
col_model[i]["formatter"] = "checkbox";
|
|
32
|
+
col_model[i]["formatoptions"] = { disabled: false };
|
|
33
|
+
col_model[i]["edittype"] = "checkbox";
|
|
34
|
+
col_model[i]["editoptions"] = { value: "Yes:No", defaultValue: "Yes" };
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return col_model;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Add a Class to the Model
|
|
42
|
+
@alias module:Jqgrid_utils
|
|
43
|
+
@param {array} - grid col_model
|
|
44
|
+
@param {string} - column_name
|
|
45
|
+
@param {string} - class_name
|
|
46
|
+
@example
|
|
47
|
+
var jqu = new Jqgrid_utils();
|
|
48
|
+
col_model = await jqu.add_class(col_model,field_name,class_name)
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
async add_class(col_model, field_name, class_name) {
|
|
52
|
+
for (let i = 0; i < col_model.length; i++) {
|
|
53
|
+
if (col_model[i]["name"] === field_name) {
|
|
54
|
+
if (col_model[i]["classes"]) {
|
|
55
|
+
col_model[i]["classes"] += " " + class_name;
|
|
56
|
+
} else {
|
|
57
|
+
col_model[i]["classes"] = class_name;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return col_model;
|
|
62
|
+
}
|
|
63
|
+
|
|
19
64
|
/**
|
|
20
65
|
* Syncron Alias grid_sum_on
|
|
21
66
|
@alias module:Jqgrid_utils
|
|
@@ -1614,7 +1659,7 @@ var jqu = new Jqgrid_utils();
|
|
|
1614
1659
|
await jqu.set_classes("#grid");
|
|
1615
1660
|
},
|
|
1616
1661
|
*/
|
|
1617
|
-
async set_classes(grid_id) {
|
|
1662
|
+
async set_classes(grid_id, field) {
|
|
1618
1663
|
const rows = jQuery(grid_id).getDataIDs();
|
|
1619
1664
|
for (var i = 0; i < rows.length; i = i + 1) {
|
|
1620
1665
|
const row = jQuery(grid_id).getRowData(rows[i]);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).Jqgrid_utils=e()}}((function(){return function e(t,r,n){function a(o,s){if(!r[o]){if(!t[o]){var l="function"==typeof require&&require;if(!s&&l)return l(o,!0);if(i)return i(o,!0);var d=new Error("Cannot find module '"+o+"'");throw d.code="MODULE_NOT_FOUND",d}var c=r[o]={exports:{}};t[o][0].call(c.exports,(function(e){return a(t[o][1][e]||e)}),c,c.exports,e,t,r,n)}return r[o].exports}for(var i="function"==typeof require&&require,o=0;o<n.length;o++)a(n[o]);return a}({1:[function(e,t,r){"use strict";t.exports=class{constructor(e=!1){e&&e.hasOwnProperty("page")&&(this.page=e.page,localStorage.setItem("page",this.page))}async add_checkbox(e,t){for(let r=0;r<e.length;r++)e[r].name===t&&(e[r].formatter="checkbox",e[r].formatoptions={disabled:!1},e[r].edittype="checkbox",e[r].editoptions={value:"Yes:No",defaultValue:"Yes"});return e}async add_class(e,t,r){for(let n=0;n<e.length;n++)e[n].name===t&&(e[n].classes?e[n].classes+=" "+r:e[n].classes=r);return e}async _grid_substract_on(e,t=[],r=[],n,a=!1){return await this.grid_substract_on(e,t,r,n,a)}async grid_substract_on(e,t=[],r=[],n,a=!1){let i=jQuery(e),o=i.jqGrid("getGridParam","data"),s={invdate:"Total"},l=0,d=0;for(let e in t){let r=0;for(let n in o)if(o[n].hasOwnProperty(t[e])){let a=o[n][t[e]];"string"==typeof a&&is_digit(a)&&(a=parseFloat(a)),r+=a}r!=Math.floor(r)&&(r=r.toFixed(2)),s[t[e]]=r,l=r}for(let e in r){let t=0;for(let n in o)if(o[n].hasOwnProperty(r[e])){let a=o[n][r[e]];"string"==typeof a&&is_digit(a)&&(a=parseFloat(a)),t+=a}t!=Math.floor(t)&&(t=t.toFixed(2)),s[r[e]]=t,d=t}let c=l-d;return a&&c<0&&(c=0),s[n]=c,i.jqGrid("footerData","set",s),s}_grid_ratio_on(e,t,r,n){return this.grid_ratio_on(e,t,r,n)}async grid_ratio_on(e,t,r,n){jQuery("#grid").jqGrid("getGridParam","data");let a=jQuery(e),i=a.jqGrid("getGridParam","data"),o={invdate:"Total"};fraction_sum=0,denominator_sum=0,ratio_sum=0;for(let e in i)i[e].hasOwnProperty(t)&&(fraction_sum+=i[e][t]),i[e].hasOwnProperty(r)&&(denominator_sum+=i[e][r]);return o.qc_eta_ratio=(fraction_sum/denominator_sum).toFixed(2),a.jqGrid("footerData","set",o),o}is_html(e){let t=!1;try{const r=(new DOMParser).parseFromString(e,"text/html");Array.from(r.body.childNodes).some((e=>1===e.nodeType))&&(t=!0)}catch(e){}return t}async _grid_sum_on(e,t=[]){return await this.grid_sum_on(e,t)}async grid_sum_on(e,t=[]){let r=jQuery(e),n=r.jqGrid("getGridParam","data"),a={invdate:"Total"};for(let e in t){let r=0;for(let a in n){let i=0;if(n[a].hasOwnProperty(t[e])){let o=n[a][t[e]];if(o){if("string"==typeof o)if(this.is_html(o)){const e=(new DOMParser).parseFromString(o,"text/html").querySelectorAll("a"),t=Array.from(e).map((e=>e.text));if(t.length){const e=t[0].replace(",","");is_digit(e)&&(i=parseFloat(e))}}else is_digit(o)&&(i=parseFloat(o));else"number"==typeof o&&(i=o);r+=i}}}r!=Math.floor(r)&&(r=r.toFixed(2)),a[t[e]]=r}return r.jqGrid("footerData","set",a),a}_grid_avg_on(e,t=[]){return this.grid_avg_on(e,t)}async grid_avg_on(e,t=[]){let r=jQuery(e),n=r.jqGrid("getGridParam","data"),a=0,i={invdate:"Total"};for(let e in t){let r=0;for(let i in n)if(n[i].hasOwnProperty(t[e])){let o=n[i][t[e]];"string"==typeof o&&is_digit(o)&&(o=parseFloat(o)),r+=o,a++}r/=a,r!=Math.floor(r)&&(r=r.toFixed(2)),i[t[e]]=r}return r.jqGrid("footerData","set",i),i}_grid_percent_on(e,t){return grid_percent_on(e,t)}async grid_percent_on(e,t){let r=jQuery(e),n=r.jqGrid("getGridParam","data"),a={},i=t.id?t.id:"invate";footer[i]="Total";let o=t.total,s=JSON.parse(JSON.stringify(t.percent));s.push(o);for(let e in s){let t=s[e],r=0,i=0;for(let e in n)if(n[e].hasOwnProperty(t)){let a=n[e][t];"string"==typeof a?is_digit(a)&&(a=parseFloat(a),r+=a,i++):(r+=a,i++)}a[t]=r}for(let e in s){let t=s[e],r=a[t]/(a[o]/100);r=r.toFixed(2),footer[t]=r+"%"}r.jqGrid("footerData","set",footer)}async update_row_to_api(e,t="",r=["id"],n={},a){let i=this,o=[],s={},l={},d={};const c=e.jqGrid("getGridParam","record_data");if(""!=t&&Object.keys(n).length>0&&"edit"==n.inputData.oper){for(let e in c)if(c[e].id===n.rowid){for(let t in r)c[e].hasOwnProperty(r[t])&&(s[r[t]]=c[e][r[t]]);for(let t in n.inputData)"oper"!=t&&Object.keys(s).indexOf(t)<0&&n.inputData[t]!=c[e][t]&&(d[t]=n.inputData[t])}for(let e in d)if(Object.keys(s).indexOf(e)<0&&"oper"!=e){let r={};r[e]=d[e],a.ids=s,a.values=r,a.operator="edit";const n=await i.post_json(t,JSON.stringify(a));o.push(n)}}else if(""!=t&&Object.keys(n).length>0&&"add"==n.inputData.oper){for(let e in n.inputData)n.inputData[e]&&"id"!=e&&"oper"!=e&&(l[e]=n.inputData[e]);a.ids=s,a.values=l,a.operator="add";let e=await i.post_json(t,JSON.stringify(a));o.push(e)}return o}async delete_row_to_api(e,t="",r,n=[],a={}){let i={msg:"failed"},o=this,s=[],l={};const d=e.jqGrid("getGridParam","record_data");for(let e in d)if(d[e].id===r){for(let t in n)d[e].hasOwnProperty(n[t])&&(l[n[t]]=d[e][n[t]],s.push(n[t]));break}return""!=t&&Object.keys(l).length==s.length&&(a.ids=s,a.values=l,i=await o.adelete_api(t,JSON.stringify(a))),i}async append_seperator_link_column(e,t,r,n,a="",i){t+="/";return n.formatter=function(e,n){let o=r;if("object"==typeof i){let r="";for(let e in i){let t=e,a=i[e],o=n.rowData[a];o&&o&&(r+=""!=t?t+"/"+encodeURIComponent(o)+"/":encodeURIComponent(o))}r&&("&"!==r.slice(-1)&&"/"!==r.slice(-1)||(r=r.slice(0,-1)),e="<a "+a+'href="'+t+r+'"> '+o+"</a>")}return e},e.push(n),e}async add_edit(e,t,r,n){for(let a=0;a<e.length;a++)e[a].name===t&&(Object.assign(e[a],r),Object.assign(e[a],n));return e}async add_textarea(e,t,r='style="width:100%;height:100px"'){for(let n=0;n<e.length;n++)e[n].name===t&&(e[n].formatter=function(e){return"<textarea "+r+">"+e+"</textarea>"});return e}async get_col_model_from_data(e,t,r=[],n=[]){let a=[];for(let e in t){const r=Object.keys(t[e]);for(let e in r){const t=r[e];a.push(t)}}a=a.filter(((e,t)=>a.indexOf(e)===t));let i=[];for(let e in n)i.push(n[e].name);let o=a.filter((e=>!i.includes(e)));const s=new Set(r);o=o.filter((e=>!s.has(e))),o.sort();for(let e=0;e<o.length;e++)n.push({name:o[e],label:o[e]});return n}binary_replace(e,t="zero",r="one"){let n=t;return 1!=e&&0!=e||1==e&&(n=r),n}_date112_to_DMY(e,t="/"){let r=e;if(e.length>=8&&-1===e.indexOf(t)){let n=[];n.push(e.substr(6,2)),n.push(e.substr(4,2)),n.push(e.substr(0,4)),r=n.join(t)}return r}async date112_to_DMY(e,t,r="/"){for(let n=0;n<e.length;n++)e[n].name===t&&(e[n].formatter=function(e,t){if(e){let t=e=e.toString();if(e.length>=8&&-1===e.indexOf(r)){let n=[];n.push(e.substr(6,2)),n.push(e.substr(4,2)),n.push(e.substr(0,4)),t=n.join(r)}return t}return e});return e}async add_formatter(e,t,r){for(let n=0;n<e.length;n++)e[n].name===t&&r.hasOwnProperty("formatter")&&r.hasOwnProperty("formatoptions")&&(e[n].formatter=r.formatter,e[n].formatoptions=r.formatoptions,e[n].edittype=r.formatter,e[n].editoptions=r.formatoptions);return e}async natural_sort(e,t){for(let r=0;r<e.length;r++)e[r].name===t&&(e[r].sortfunc=function(e,t,r){void 0===r&&(r=1);var n,a,i=/(^-?[0-9]+(\.?[0-9]*)[df]?e?[0-9]?$|^0x[0-9a-f]+$|[0-9]+)/gi,o=/(^[ ]*|[ ]*$)/g,s=/(^([\w ]+,?[\w ]+)?[\w ]+,?[\w ]+\d+:\d+(:\d+)?[\w ]?|^\d{1,4}[\/\-]\d{1,4}[\/\-]\d{1,4}|^\w+, \w+ \d+, \d{4})/,l=/^0x[0-9a-f]+$/i,d=/^0/,c=function(e){return self.insensitive&&(""+e).toLowerCase()||""+e},f=c(e).replace(o,"")||"",u=c(t).replace(o,"")||"",p=f.replace(i,"\0$1\0").replace(/\0$/,"").replace(/^\0/,"").split("\0"),_=u.replace(i,"\0$1\0").replace(/\0$/,"").replace(/^\0/,"").split("\0"),h=parseInt(f.match(l))||1!=p.length&&f.match(s)&&Date.parse(f),m=parseInt(u.match(l))||h&&u.match(s)&&Date.parse(u)||null;if(m){if(h<m)return-r;if(h>m)return r}for(var y=0,g=Math.max(p.length,_.length);y<g;y++){if(n=!(p[y]||"").match(d)&&parseFloat(p[y])||p[y]||0,a=!(_[y]||"").match(d)&&parseFloat(_[y])||_[y]||0,isNaN(n)!==isNaN(a))return isNaN(n)?r:-r;if(typeof n!=typeof a&&(n+="",a+=""),n<a)return-r;if(n>a)return r}return 0});return e}async add_html_formatter(e,t,r){for(let n=0;n<e.length;n++)e[n].name===t&&(e[n].formatter=function(e,t){return r});return e}async add_ok_button(e,t){let r=this;for(let n=0;n<e.length;n++)t.indexOf(e[n].name)>-1&&(e[n].formatter=function(e){return null!=e?r.__cell_format(e,"format_ok"):""});return e}async get_filled_cell_table_data(e,t=[]){let r=jQuery(e).jqGrid("getGridParam","data"),n=t,a=[];for(let e in r)if(r[e].hasOwnProperty("id")){let t=[r[e].id];for(let a in n)r[e].hasOwnProperty(n[a])?t.push(r[e][n[a]]):t.push("");var i=t.filter((function(e,t,r){return""!==e}));Object.keys(i).length>1&&a.push(t)}return a}async get_filled_cell_data(e,t=[]){let r=jQuery(e).jqGrid("getGridParam","data"),n=t,a=[];for(let e in r)if(r[e].hasOwnProperty("id")){let t={id:r[e].id};for(let a in n)r[e].hasOwnProperty(n[a])&&""!=r[e][n[a]]&&(t[n[a]]=r[e][n[a]]);Object.keys(t).length>1&&a.push(t)}return a}async set_link(e,t,r,n=""){for(let a=0;a<e.length;a++)e[a].name===t&&(e[a].formatter=function(e,t){return'<a class="gl" '+n+'href="'+t.rowData[r]+'">'+e+"</a>"});return e}async hide_all_columns_except(e,t){for(let r=0;r<e.length;r++)t.indexOf(e[r].name)>-1?e[r].hidden=!1:e[r].hidden=!0;return e}async hide_column(e,t){for(let r=0;r<e.length;r++)e[r].name===t&&(e[r].hidden=!0);return e}s_grid_set_caption(e,t=[]){this.grid_set_captionn(e,[])}async grid_set_caption(e,t=[]){if(e){const r=jQuery(e);let n=0;n=0===t.length?r.jqGrid("getGridParam","records"):t.length;const a=/\d.*x/,i=r.jqGrid("getGridParam","caption").replace(a,"");r.jqGrid("setCaption",i+" "+n+"x")}}s_resize_saved_cell_width(e,t=!1,r=!1){this.grid_set_caption(e,t,r)}async resize_saved_cell_width(e,t=!1,r=!1){let n=t||this.page;n+=r?"-"+r+"-w-":"-grid-w-";for(let t=0;t<=e.length;t++)if(e[t]&&e[t].name){const r=e[t].name,a=localStorage.getItem(n+r);a&&(e[t].width=a)}return e}resize_cell(e,t,r=!1){const n=jQuery(this).jqGrid("getGridParam","colModel");if(n[t]&&n[t].name){const a=n[t].name;let i=(r||localStorage.getItem("page"))+"-"+this.id+"-w-"+a;localStorage.setItem(i,e);localStorage.getItem(i)}}async upsert_row(e,t,r={}){if(e.rowid.startsWith("jqg")){return await this.insert_row(e,t)}return await this.update_row(e,t)}async insert_row(e,t){let r={},n="";if(e.inputData.hasOwnProperty("id")){r._id="id",r._id_val=e.inputData.id;for(let t in e.inputData)r[t]=e.inputData[t];delete r.id,delete r.oper,n=await this.put_json(t,JSON.stringify(r))}return n}async update_row(e,t,r={}){let n="";r._id||(r._id="id"),r._id_val=e.inputData.id;for(let t in e.inputData)r[t]=e.inputData[t];return delete r.id,delete r.oper,n=await this.post_json(t,JSON.stringify(r)),n}async delete_row(e,t){let r="";return t.indexOf("?")>-1?t+="&_id="+encodeURIComponent(unescape(e)):t+="?_id="+encodeURIComponent(unescape(e)),r=JSON.parse(await this.adelete_api(t)),r.message}async adelete_api(e,t=!1){let r="application/x-www-form-urlencoded",n=null;return t&&(r="application/json;charset=UTF-8",n=t),new Promise(((t,a)=>{let i=new XMLHttpRequest;i.open("DELETE",e),i.setRequestHeader("Content-type",r),i.onload=()=>t(i.responseText),i.onerror=()=>a(i.statusText),i.send(n)}))}async post_json(e,t){return new Promise(((r,n)=>{let a=new XMLHttpRequest;a.open("POST",e),a.setRequestHeader("Content-type","application/json"),a.onload=()=>r(a.responseText),a.onerror=()=>n(a.statusText),a.send(t)}))}async put_json(e,t){return new Promise(((r,n)=>{let a=new XMLHttpRequest;a.open("PUT",e),a.setRequestHeader("Content-type","application/json"),a.onload=()=>r(a.responseText),a.onerror=()=>n(a.statusText),a.send(t)}))}s_hide_del_icon(){hide_del_icon()}async hide_del_icon(){jQuery(".ui-inline-del").each((function(e){jQuery(this).html("")}))}async add_link_details_csv(e,t,r,n="",a,i,o=","){let s=this;t.indexOf("?")>-1?t+="&":t+="?";for(let l=0;l<e.length;l++)e[l].name===r&&(e[l].formatter=function(e,r){let l=e;const d=s.__cell_format(e,i),c=d.split(o);let f="";for(let i in c){const s=c[i].trim();if(s&&"object"==typeof a){let e="";for(let t in a){let n=t,i=a[t];l=r.rowData[i],l&&(e=-1!==n.indexOf("=")?e+""+n+encodeURIComponent(s)+"&":e+""+n+"="+encodeURIComponent(s)+"&")}"&"===e.slice(-1)&&(e=e.slice(0,-1)),f+="<a "+n+'href="'+t+e+'"> '+s+"</a>"+o+" "}(e=f.trim()).slice(-1)===o&&(e=e.slice(0,-1))}return e||d});return e}async compare(e,t,r,n){const a=jQuery(e).jqGrid("getGridParam","data");for(let i in a)a[i][t]!=a[i][r]&&(jQuery(e).jqGrid("setCell",a[i].id,t,"",n),jQuery(e).jqGrid("setCell",a[i].id,r,"",n))}async compare_smaller(e,t,r,n){const a=jQuery(e).jqGrid("getGridParam","data");for(let i in a)a[i][t]<a[i][r]&&(jQuery(e).jqGrid("setCell",a[i].id,t,"",n),jQuery(e).jqGrid("setCell",a[i].id,r,"",n))}async compare_bigger(e,t,r,n){const a=jQuery(e).jqGrid("getGridParam","data");for(let i in a)a[i][t]>a[i][r]&&(jQuery(e).jqGrid("setCell",a[i].id,t,"",n),jQuery(e).jqGrid("setCell",a[i].id,r,"",n))}async set_styles(e,t="styles"){const r=jQuery(e).jqGrid("getGridParam","data");for(let n in r)if(r[n][t]){const a=JSON.parse(r[n][t]);for(let t in a){const i=r[n].id,o=t;r[n].hasOwnProperty(o)&&jQuery(e).jqGrid("setCell",i,o,"",a[t])}}}async set_classes(e,t){const r=jQuery(e).getDataIDs();for(var n=0;n<r.length;n+=1){const t=jQuery(e).getRowData(r[n]);var a=jQuery("#"+r[n],jQuery(e));a.removeClass("ui-widget-content"),a.addClass(t.class)}}async add_link_details(e,t,r,n="",a,i){let o=this;t.indexOf("?")>-1?t+="&":t+="?";for(let s=0;s<e.length;s++)e[s].name===r&&(e[s].formatter=function(e,r){let s="";(e=String(e))&&(s=e);let l="";if(e&&(l=e.toString()),"object"==typeof a){let d="";for(let e in a){let t=e,n=a[e];s=r.rowData[n],s&&s&&(d=-1!==t.indexOf("=")?d+""+t+encodeURIComponent(s)+"&":d+""+t+"="+encodeURIComponent(s)+"&")}if(d){"&"===d.slice(-1)&&(d=d.slice(0,-1));const r=o.__cell_format(e,i);e=""!=l&&r&&l?"<a "+n+'href="'+t+d+'"> '+r+"</a>":""}}return l?e:""});return e}async add_link_details_separator(e,t,r,n="",a,i){t+="/";let o=this;for(let s=0;s<e.length;s++)e[s].name===r&&(e[s].formatter=function(e,r){let s=e;if("object"==typeof a){let l="";for(let e in a){let t=e,n=a[e];s=r.rowData[n],s&&s&&(l+=""!=t?t+"/"+encodeURIComponent(s)+"/":encodeURIComponent(s))}if(l){"&"!==l.slice(-1)&&"/"!==l.slice(-1)||(l=l.slice(0,-1));const r=o.__cell_format(e,i);e="<a "+n+'href="'+t+l+'"> '+r+"</a>"}}return e});return e}async add_link_separator(e,t,r,n,a=""){t+="/";for(let i=0;i<e.length;i++)e[i].name===r&&(e[i].formatter=function(e,r){let i="";for(let e in n)for(let t in n[e]){if("field"===t){i+=r.rowData[n[e][t]]}if("extension"===t&&(i+=n[e][t]),"fields"===t){i+="?";for(let a in n[e][t]){let o=r.rowData[n[e][t][a]];i=i+""+a+"="+encodeURIComponent(o)+"&"}}}return i&&("&"!==i.slice(-1)&&"/"!==i.slice(-1)||(i=i.slice(0,-1)),e="<a "+a+'href="'+t+i+'"> '+e+"</a>"),e});return e}__cell_format(e,t){return"format_ok"==t&&(e=0==e||"fail"===e?'<i data-check="failed" class="fa fa-times-circle" aria-hidden="true" style="color:#ff0000;"></i>':'<i data-check="ok" class="fa fa-check-circle" aria-hidden="true" style="color:#008000;"></i>'),e}async subgrid(e,t,r,n,a=""){a=""!=a?a+" ":"",t?r+=t:t="";let i=jQuery("<table style='margin: 5px 0' class='"+e+"_t'></table>");i.appendTo("#"+jQuery.jgrid.jqID(e)),i.jqGrid({caption:a+t,colModel:n,datatype:"json",url:r,gridview:!0,rownumbers:!0,autoencode:!0,sortname:"c1",sortorder:"desc"})}async add_image(e,t,r,n=!1){void 0===r&&(r=60);for(let a=0;a<e.length;a++)e[a].name===t&&(e[a].picture=!0,e[a].width=r,e[a].height=r,e[a].formatter=function(e){const t=e.toLowerCase();return(t.startsWith("https://",0)||t.startsWith("http://",0))&&(t.includes(".png")||t.includes(".jpg")||t.includes(".jpeg")||t.includes(".gif")||t.includes(".svg")||t.includes(".svgz")||t.includes(".webp"))?n?'<a target="blank" href="'+e+'"><img src="'+e+'" alt="my image" width="'+r+'" /></a>':'<img src="'+e+'" alt="my image" width="'+r+'" />':e});return e}async set_filter(e,t,r,n="#filter"){jQuery(e).jqGrid("setGridParam",{fdata:t});let a=document.querySelector(n);for(const e in t)for(let n in r)r[n].push(t[e][n]);for(let e in r)r[e]=r[e].filter(((e,t,r)=>r.indexOf(e)===t)),r[e].sort();for(let t in r){let n=document.createElement("ul"),i=document.createElement("lh");i.innerHTML=t,n.appendChild(i);for(let a in r[t]){let i=document.createElement("li"),o=document.createElement("label");o.innerHTML=r[t][a];let s=document.createElement("input");s.setAttribute("type","checkbox"),s.setAttribute("class",t),s.setAttribute("id",t+"_"+r[t][a]),o.setAttribute("for",t+"_"+r[t][a]),s.value=r[t][a],s.onchange=async()=>{await this._filter(e,r)},i.appendChild(o),i.appendChild(s),n.appendChild(i)}a.appendChild(n)}}async _filter(e,t){let r=[],n=jQuery(e).jqGrid("getGridParam","fdata"),a=[];for(let e in t){let t=document.querySelectorAll("."+e);a[e]=[];for(let r in t)t[r].checked&&a[e].push(t[r].value)}for(let e in n){let i=!1;for(let r in t)-1!=a[r].indexOf(n[e][r])&&(i=!0);i&&r.push(n[e])}jQuery(e).jqGrid("clearGridData"),jQuery(e).jqGrid("setGridParam",{data:r}),jQuery(e).trigger("reloadGrid")}}},{}]},{},[1])(1)}));
|
package/jqgrid_utils.js
CHANGED
|
@@ -15,6 +15,51 @@ module.exports = class Vanilla_website_utils {
|
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Add a Checkbox to the Model
|
|
20
|
+
@alias module:Jqgrid_utils
|
|
21
|
+
@param {array} - grid col_model
|
|
22
|
+
@param {string} - column_name
|
|
23
|
+
@example
|
|
24
|
+
var jqu = new Jqgrid_utils();
|
|
25
|
+
ol_model = await jqu.add_checkbox(col_model, "closed");
|
|
26
|
+
*/
|
|
27
|
+
async add_checkbox(col_model, field_name) {
|
|
28
|
+
for (let i = 0; i < col_model.length; i++) {
|
|
29
|
+
if (col_model[i]["name"] === field_name) {
|
|
30
|
+
col_model[i]["formatter"] = "checkbox";
|
|
31
|
+
col_model[i]["formatoptions"] = { disabled: false };
|
|
32
|
+
col_model[i]["edittype"] = "checkbox";
|
|
33
|
+
col_model[i]["editoptions"] = { value: "Yes:No", defaultValue: "Yes" };
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return col_model;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Add a Class to the Model
|
|
41
|
+
@alias module:Jqgrid_utils
|
|
42
|
+
@param {array} - grid col_model
|
|
43
|
+
@param {string} - column_name
|
|
44
|
+
@param {string} - class_name
|
|
45
|
+
@example
|
|
46
|
+
var jqu = new Jqgrid_utils();
|
|
47
|
+
col_model = await jqu.add_class(col_model,field_name,class_name)
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
async add_class(col_model, field_name, class_name) {
|
|
51
|
+
for (let i = 0; i < col_model.length; i++) {
|
|
52
|
+
if (col_model[i]["name"] === field_name) {
|
|
53
|
+
if (col_model[i]["classes"]) {
|
|
54
|
+
col_model[i]["classes"] += " " + class_name;
|
|
55
|
+
} else {
|
|
56
|
+
col_model[i]["classes"] = class_name;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return col_model;
|
|
61
|
+
}
|
|
62
|
+
|
|
18
63
|
/**
|
|
19
64
|
* Syncron Alias grid_sum_on
|
|
20
65
|
@alias module:Jqgrid_utils
|
|
@@ -1613,7 +1658,7 @@ var jqu = new Jqgrid_utils();
|
|
|
1613
1658
|
await jqu.set_classes("#grid");
|
|
1614
1659
|
},
|
|
1615
1660
|
*/
|
|
1616
|
-
async set_classes(grid_id) {
|
|
1661
|
+
async set_classes(grid_id, field) {
|
|
1617
1662
|
const rows = jQuery(grid_id).getDataIDs();
|
|
1618
1663
|
for (var i = 0; i < rows.length; i = i + 1) {
|
|
1619
1664
|
const row = jQuery(grid_id).getRowData(rows[i]);
|
package/make_doc.sh
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
#!/bin/bash
|
|
2
|
-
|
|
3
|
-
# install
|
|
4
|
-
#
|
|
2
|
+
# Run this at the end of your dev cycle
|
|
3
|
+
# sudo npm install --save-dev jsdoc-to-markdown -g
|
|
4
|
+
#terser dist/jqgrid_utils.js -o dist/jqgrid_utils.min.js -c -m
|
|
5
5
|
|
|
6
6
|
cp _README.md README.md
|
|
7
7
|
jsdoc2md jqgrid_utils.js >> README.md
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
package/make_min.sh
ADDED
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author":
|
|
3
3
|
{
|
|
4
|
-
"name": "
|
|
4
|
+
"name": "info@myridia.com",
|
|
5
5
|
"url": "https://www.npmjs.com/package/jqgrid_utils"
|
|
6
6
|
},
|
|
7
7
|
"dependencies":
|
|
8
8
|
{},
|
|
9
9
|
"deprecated": false,
|
|
10
10
|
"description": "Convenient Functions for the Free jqGrid",
|
|
11
|
-
"homepage": "https://
|
|
11
|
+
"homepage": "https://jqgrid-utils.myridia.com",
|
|
12
12
|
"license": "GPL-3.0-or-later",
|
|
13
13
|
"main": "jqgrid_utils.js",
|
|
14
14
|
"name": "jqgrid_utils",
|
|
@@ -22,15 +22,10 @@
|
|
|
22
22
|
],
|
|
23
23
|
"repository":
|
|
24
24
|
{
|
|
25
|
-
"type": "
|
|
25
|
+
"type": "git",
|
|
26
26
|
"url": "https://github.com/myridia/jqgrid_utils"
|
|
27
27
|
},
|
|
28
|
-
"scripts":
|
|
29
|
-
{
|
|
30
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
31
|
-
},
|
|
32
|
-
|
|
33
|
-
"version": "1.35.2"
|
|
34
28
|
|
|
29
|
+
"version": "1.37.0"
|
|
35
30
|
|
|
36
31
|
}
|
package/{make.sh → watch.sh}
RENAMED