jqgrid_utils 1.38.0 → 1.38.1

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
@@ -32,6 +32,7 @@ A module for Jqgrid_utils
32
32
 
33
33
 
34
34
  * [Jqgrid_utils](#module_Jqgrid_utils)
35
+ * [module.exports#format_currency_on_value(col_model, edit_field, currency)](#exp_module_Jqgrid_utils--module.exports+format_currency_on_value) ⏏
35
36
  * [module.exports#format_currency(col_model, edit_field, currency)](#exp_module_Jqgrid_utils--module.exports+format_currency) ⏏
36
37
  * [module.exports#add_checkbox(col_model, field_name)](#exp_module_Jqgrid_utils--module.exports+add_checkbox) ⏏
37
38
  * [module.exports#add_class(col_model, field_name, class_name)](#exp_module_Jqgrid_utils--module.exports+add_class) ⏏
@@ -93,6 +94,25 @@ A module for Jqgrid_utils
93
94
  * [module.exports#set_filter(grid, data, fx, append_to)](#exp_module_Jqgrid_utils--module.exports+set_filter) ⏏
94
95
  * [module.exports#_filter()](#exp_module_Jqgrid_utils--module.exports+_filter) ⏏
95
96
 
97
+ <a name="exp_module_Jqgrid_utils--module.exports+format_currency_on_value"></a>
98
+
99
+ ### module.exports#format\_currency\_on\_value(col_model, edit_field, currency) ⏏
100
+ Format a number into a currency if have value, otherwise return empty
101
+
102
+ **Kind**: Exported function
103
+
104
+ | Param | Type | Default | Description |
105
+ | --- | --- | --- | --- |
106
+ | col_model | <code>object</code> | | col_model of the grid |
107
+ | edit_field | <code>string</code> | | name of column to be formatter |
108
+ | currency | <code>string</code> | <code>&quot;$&quot;</code> | currency symbol, default is $ |
109
+
110
+ **Example**
111
+ ```js
112
+ var jqu = new Jqgrid_utils();
113
+ let _data = await jqu.format_currency(this,'my_field','$');
114
+ console.log(_data);
115
+ ```
96
116
  <a name="exp_module_Jqgrid_utils--module.exports+format_currency"></a>
97
117
 
98
118
  ### module.exports#format\_currency(col_model, edit_field, currency) ⏏
@@ -16,6 +16,65 @@ module.exports = class Vanilla_website_utils {
16
16
  }
17
17
  }
18
18
 
19
+ /**
20
+ * Format a number into a currency if have value, otherwise return empty
21
+ @alias module:Jqgrid_utils
22
+ @param {object} - col_model of the grid
23
+ @param {string} - name of column to be formatter
24
+ @param {string} - currency symbol, default is $
25
+ @example
26
+ var jqu = new Jqgrid_utils();
27
+ let _data = await jqu.format_currency(this,'my_field','$');
28
+ console.log(_data);
29
+ */
30
+ async format_currency_on_value(col_model, edit_field, currency = "$") {
31
+ for (let i = 0; i < col_model.length; i++) {
32
+ if (col_model[i]["name"] === edit_field) {
33
+ col_model[i]["formatoptions"] = {
34
+ prefix: currency,
35
+ decimalSeparator: ".",
36
+ thousandsSeparator: ",",
37
+ decimalPlaces: 2,
38
+ };
39
+ col_model[i]["formatter"] = function (cellvalue, options, rowObject) {
40
+ if (
41
+ cellvalue === null ||
42
+ cellvalue === undefined ||
43
+ cellvalue === ""
44
+ ) {
45
+ return ""; // Return an empty string for no value
46
+ } else if (parseFloat(cellvalue) === 0) {
47
+ return ""; // Return an empty string for zero value
48
+ } else {
49
+ // Apply currency formatting
50
+ var currency = options.colModel.formatoptions.prefix; // Get currency symbol
51
+ var decimalSeparator =
52
+ options.colModel.formatoptions.decimalSeparator;
53
+ var thousandsSeparator =
54
+ options.colModel.formatoptions.thousandsSeparator;
55
+ var decimalPlaces = options.colModel.formatoptions.decimalPlaces;
56
+
57
+ // Implement your currency formatting logic here
58
+ // (This is a simplified example; you might need a more robust formatting function)
59
+ var formattedValue = parseFloat(cellvalue).toFixed(decimalPlaces);
60
+ formattedValue = formattedValue.replace(".", decimalSeparator);
61
+
62
+ // Add thousands separator
63
+ var parts = formattedValue.split(decimalSeparator);
64
+ parts[0] = parts[0].replace(
65
+ /\B(?=(\d{3})+(?!\d))/g,
66
+ thousandsSeparator,
67
+ );
68
+ formattedValue = parts.join(decimalSeparator);
69
+
70
+ return currency + formattedValue; // Return formatted value
71
+ }
72
+ };
73
+ }
74
+ }
75
+ return col_model;
76
+ }
77
+
19
78
  /**
20
79
  * Format a number into a currency
21
80
  @alias module:Jqgrid_utils
@@ -1 +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 format_currency(e,t,r="$"){for(let n=0;n<e.length;n++)e[n].name===t&&(e[n].formatter="currency",e[n].formatoptions={prefix:r,decimalSeparator:".",thousandsSeparator:",",decimalPlaces:2});return e}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)}));
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,a){function n(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 n(t[o][1][e]||e)}),c,c.exports,e,t,r,a)}return r[o].exports}for(var i="function"==typeof require&&require,o=0;o<a.length;o++)n(a[o]);return n}({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 format_currency_on_value(e,t,r="$"){for(let a=0;a<e.length;a++)e[a].name===t&&(e[a].formatoptions={prefix:r,decimalSeparator:".",thousandsSeparator:",",decimalPlaces:2},e[a].formatter=function(e,t,r){if(null==e||""===e)return"";if(0===parseFloat(e))return"";var a=t.colModel.formatoptions.prefix,n=t.colModel.formatoptions.decimalSeparator,i=t.colModel.formatoptions.thousandsSeparator,o=t.colModel.formatoptions.decimalPlaces,s=parseFloat(e).toFixed(o),l=(s=s.replace(".",n)).split(n);return l[0]=l[0].replace(/\B(?=(\d{3})+(?!\d))/g,i),a+(s=l.join(n))});return e}async format_currency(e,t,r="$"){for(let a=0;a<e.length;a++)e[a].name===t&&(e[a].formatter="currency",e[a].formatoptions={prefix:r,decimalSeparator:".",thousandsSeparator:",",decimalPlaces:2});return e}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 a=0;a<e.length;a++)e[a].name===t&&(e[a].classes?e[a].classes+=" "+r:e[a].classes=r);return e}async _grid_substract_on(e,t=[],r=[],a,n=!1){return await this.grid_substract_on(e,t,r,a,n)}async grid_substract_on(e,t=[],r=[],a,n=!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 a in o)if(o[a].hasOwnProperty(t[e])){let n=o[a][t[e]];"string"==typeof n&&is_digit(n)&&(n=parseFloat(n)),r+=n}r!=Math.floor(r)&&(r=r.toFixed(2)),s[t[e]]=r,l=r}for(let e in r){let t=0;for(let a in o)if(o[a].hasOwnProperty(r[e])){let n=o[a][r[e]];"string"==typeof n&&is_digit(n)&&(n=parseFloat(n)),t+=n}t!=Math.floor(t)&&(t=t.toFixed(2)),s[r[e]]=t,d=t}let c=l-d;return n&&c<0&&(c=0),s[a]=c,i.jqGrid("footerData","set",s),s}_grid_ratio_on(e,t,r,a){return this.grid_ratio_on(e,t,r,a)}async grid_ratio_on(e,t,r,a){jQuery("#grid").jqGrid("getGridParam","data");let n=jQuery(e),i=n.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),n.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),a=r.jqGrid("getGridParam","data"),n={invdate:"Total"};for(let e in t){let r=0;for(let n in a){let i=0;if(a[n].hasOwnProperty(t[e])){let o=a[n][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)),n[t[e]]=r}return r.jqGrid("footerData","set",n),n}_grid_avg_on(e,t=[]){return this.grid_avg_on(e,t)}async grid_avg_on(e,t=[]){let r=jQuery(e),a=r.jqGrid("getGridParam","data"),n=0,i={invdate:"Total"};for(let e in t){let r=0;for(let i in a)if(a[i].hasOwnProperty(t[e])){let o=a[i][t[e]];"string"==typeof o&&is_digit(o)&&(o=parseFloat(o)),r+=o,n++}r/=n,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),a=r.jqGrid("getGridParam","data"),n={},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 a)if(a[e].hasOwnProperty(t)){let n=a[e][t];"string"==typeof n?is_digit(n)&&(n=parseFloat(n),r+=n,i++):(r+=n,i++)}n[t]=r}for(let e in s){let t=s[e],r=n[t]/(n[o]/100);r=r.toFixed(2),footer[t]=r+"%"}r.jqGrid("footerData","set",footer)}async update_row_to_api(e,t="",r=["id"],a={},n){let i=this,o=[],s={},l={},d={};const c=e.jqGrid("getGridParam","record_data");if(""!=t&&Object.keys(a).length>0&&"edit"==a.inputData.oper){for(let e in c)if(c[e].id===a.rowid){for(let t in r)c[e].hasOwnProperty(r[t])&&(s[r[t]]=c[e][r[t]]);for(let t in a.inputData)"oper"!=t&&Object.keys(s).indexOf(t)<0&&a.inputData[t]!=c[e][t]&&(d[t]=a.inputData[t])}for(let e in d)if(Object.keys(s).indexOf(e)<0&&"oper"!=e){let r={};r[e]=d[e],n.ids=s,n.values=r,n.operator="edit";const a=await i.post_json(t,JSON.stringify(n));o.push(a)}}else if(""!=t&&Object.keys(a).length>0&&"add"==a.inputData.oper){for(let e in a.inputData)a.inputData[e]&&"id"!=e&&"oper"!=e&&(l[e]=a.inputData[e]);n.ids=s,n.values=l,n.operator="add";let e=await i.post_json(t,JSON.stringify(n));o.push(e)}return o}async delete_row_to_api(e,t="",r,a=[],n={}){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 a)d[e].hasOwnProperty(a[t])&&(l[a[t]]=d[e][a[t]],s.push(a[t]));break}return""!=t&&Object.keys(l).length==s.length&&(n.ids=s,n.values=l,i=await o.adelete_api(t,JSON.stringify(n))),i}async append_seperator_link_column(e,t,r,a,n="",i){t+="/";return a.formatter=function(e,a){let o=r;if("object"==typeof i){let r="";for(let e in i){let t=e,n=i[e],o=a.rowData[n];o&&o&&(r+=""!=t?t+"/"+encodeURIComponent(o)+"/":encodeURIComponent(o))}r&&("&"!==r.slice(-1)&&"/"!==r.slice(-1)||(r=r.slice(0,-1)),e="<a "+n+'href="'+t+r+'"> '+o+"</a>")}return e},e.push(a),e}async add_edit(e,t,r,a){for(let n=0;n<e.length;n++)e[n].name===t&&(Object.assign(e[n],r),Object.assign(e[n],a));return e}async add_textarea(e,t,r='style="width:100%;height:100px"'){for(let a=0;a<e.length;a++)e[a].name===t&&(e[a].formatter=function(e){return"<textarea "+r+">"+e+"</textarea>"});return e}async get_col_model_from_data(e,t,r=[],a=[]){let n=[];for(let e in t){const r=Object.keys(t[e]);for(let e in r){const t=r[e];n.push(t)}}n=n.filter(((e,t)=>n.indexOf(e)===t));let i=[];for(let e in a)i.push(a[e].name);let o=n.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++)a.push({name:o[e],label:o[e]});return a}binary_replace(e,t="zero",r="one"){let a=t;return 1!=e&&0!=e||1==e&&(a=r),a}_date112_to_DMY(e,t="/"){let r=e;if(e.length>=8&&-1===e.indexOf(t)){let a=[];a.push(e.substr(6,2)),a.push(e.substr(4,2)),a.push(e.substr(0,4)),r=a.join(t)}return r}async date112_to_DMY(e,t,r="/"){for(let a=0;a<e.length;a++)e[a].name===t&&(e[a].formatter=function(e,t){if(e){let t=e=e.toString();if(e.length>=8&&-1===e.indexOf(r)){let a=[];a.push(e.substr(6,2)),a.push(e.substr(4,2)),a.push(e.substr(0,4)),t=a.join(r)}return t}return e});return e}async add_formatter(e,t,r){for(let a=0;a<e.length;a++)e[a].name===t&&r.hasOwnProperty("formatter")&&r.hasOwnProperty("formatoptions")&&(e[a].formatter=r.formatter,e[a].formatoptions=r.formatoptions,e[a].edittype=r.formatter,e[a].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 a,n,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"),m=parseInt(f.match(l))||1!=p.length&&f.match(s)&&Date.parse(f),h=parseInt(u.match(l))||m&&u.match(s)&&Date.parse(u)||null;if(h){if(m<h)return-r;if(m>h)return r}for(var y=0,g=Math.max(p.length,_.length);y<g;y++){if(a=!(p[y]||"").match(d)&&parseFloat(p[y])||p[y]||0,n=!(_[y]||"").match(d)&&parseFloat(_[y])||_[y]||0,isNaN(a)!==isNaN(n))return isNaN(a)?r:-r;if(typeof a!=typeof n&&(a+="",n+=""),a<n)return-r;if(a>n)return r}return 0});return e}async add_html_formatter(e,t,r){for(let a=0;a<e.length;a++)e[a].name===t&&(e[a].formatter=function(e,t){return r});return e}async add_ok_button(e,t){let r=this;for(let a=0;a<e.length;a++)t.indexOf(e[a].name)>-1&&(e[a].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"),a=t,n=[];for(let e in r)if(r[e].hasOwnProperty("id")){let t=[r[e].id];for(let n in a)r[e].hasOwnProperty(a[n])?t.push(r[e][a[n]]):t.push("");var i=t.filter((function(e,t,r){return""!==e}));Object.keys(i).length>1&&n.push(t)}return n}async get_filled_cell_data(e,t=[]){let r=jQuery(e).jqGrid("getGridParam","data"),a=t,n=[];for(let e in r)if(r[e].hasOwnProperty("id")){let t={id:r[e].id};for(let n in a)r[e].hasOwnProperty(a[n])&&""!=r[e][a[n]]&&(t[a[n]]=r[e][a[n]]);Object.keys(t).length>1&&n.push(t)}return n}async set_link(e,t,r,a=""){for(let n=0;n<e.length;n++)e[n].name===t&&(e[n].formatter=function(e,t){return'<a class="gl" '+a+'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 a=0;a=0===t.length?r.jqGrid("getGridParam","records"):t.length;const n=/\d.*x/,i=r.jqGrid("getGridParam","caption").replace(n,"");r.jqGrid("setCaption",i+" "+a+"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 a=t||this.page;a+=r?"-"+r+"-w-":"-grid-w-";for(let t=0;t<=e.length;t++)if(e[t]&&e[t].name){const r=e[t].name,n=localStorage.getItem(a+r);n&&(e[t].width=n)}return e}resize_cell(e,t,r=!1){const a=jQuery(this).jqGrid("getGridParam","colModel");if(a[t]&&a[t].name){const n=a[t].name;let i=(r||localStorage.getItem("page"))+"-"+this.id+"-w-"+n;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={},a="";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,a=await this.put_json(t,JSON.stringify(r))}return a}async update_row(e,t,r={}){let a="";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,a=await this.post_json(t,JSON.stringify(r)),a}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",a=null;return t&&(r="application/json;charset=UTF-8",a=t),new Promise(((t,n)=>{let i=new XMLHttpRequest;i.open("DELETE",e),i.setRequestHeader("Content-type",r),i.onload=()=>t(i.responseText),i.onerror=()=>n(i.statusText),i.send(a)}))}async post_json(e,t){return new Promise(((r,a)=>{let n=new XMLHttpRequest;n.open("POST",e),n.setRequestHeader("Content-type","application/json"),n.onload=()=>r(n.responseText),n.onerror=()=>a(n.statusText),n.send(t)}))}async put_json(e,t){return new Promise(((r,a)=>{let n=new XMLHttpRequest;n.open("PUT",e),n.setRequestHeader("Content-type","application/json"),n.onload=()=>r(n.responseText),n.onerror=()=>a(n.statusText),n.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,a="",n,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 n){let e="";for(let t in n){let a=t,i=n[t];l=r.rowData[i],l&&(e=-1!==a.indexOf("=")?e+""+a+encodeURIComponent(s)+"&":e+""+a+"="+encodeURIComponent(s)+"&")}"&"===e.slice(-1)&&(e=e.slice(0,-1)),f+="<a "+a+'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,a){const n=jQuery(e).jqGrid("getGridParam","data");for(let i in n)n[i][t]!=n[i][r]&&(jQuery(e).jqGrid("setCell",n[i].id,t,"",a),jQuery(e).jqGrid("setCell",n[i].id,r,"",a))}async compare_smaller(e,t,r,a){const n=jQuery(e).jqGrid("getGridParam","data");for(let i in n)n[i][t]<n[i][r]&&(jQuery(e).jqGrid("setCell",n[i].id,t,"",a),jQuery(e).jqGrid("setCell",n[i].id,r,"",a))}async compare_bigger(e,t,r,a){const n=jQuery(e).jqGrid("getGridParam","data");for(let i in n)n[i][t]>n[i][r]&&(jQuery(e).jqGrid("setCell",n[i].id,t,"",a),jQuery(e).jqGrid("setCell",n[i].id,r,"",a))}async set_styles(e,t="styles"){const r=jQuery(e).jqGrid("getGridParam","data");for(let a in r)if(r[a][t]){const n=JSON.parse(r[a][t]);for(let t in n){const i=r[a].id,o=t;r[a].hasOwnProperty(o)&&jQuery(e).jqGrid("setCell",i,o,"",n[t])}}}async set_classes(e,t){const r=jQuery(e).getDataIDs();for(var a=0;a<r.length;a+=1){const t=jQuery(e).getRowData(r[a]);var n=jQuery("#"+r[a],jQuery(e));n.removeClass("ui-widget-content"),n.addClass(t.class)}}async add_link_details(e,t,r,a="",n,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 n){let d="";for(let e in n){let t=e,a=n[e];s=r.rowData[a],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 "+a+'href="'+t+d+'"> '+r+"</a>":""}}return l?e:""});return e}async add_link_details_separator(e,t,r,a="",n,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 n){let l="";for(let e in n){let t=e,a=n[e];s=r.rowData[a],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 "+a+'href="'+t+l+'"> '+r+"</a>"}}return e});return e}async add_link_separator(e,t,r,a,n=""){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 a)for(let t in a[e]){if("field"===t){i+=r.rowData[a[e][t]]}if("extension"===t&&(i+=a[e][t]),"fields"===t){i+="?";for(let n in a[e][t]){let o=r.rowData[a[e][t][n]];i=i+""+n+"="+encodeURIComponent(o)+"&"}}}return i&&("&"!==i.slice(-1)&&"/"!==i.slice(-1)||(i=i.slice(0,-1)),e="<a "+n+'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,a,n=""){n=""!=n?n+" ":"",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:n+t,colModel:a,datatype:"json",url:r,gridview:!0,rownumbers:!0,autoencode:!0,sortname:"c1",sortorder:"desc"})}async add_image(e,t,r,a=!1){void 0===r&&(r=60);for(let n=0;n<e.length;n++)e[n].name===t&&(e[n].picture=!0,e[n].width=r,e[n].height=r,e[n].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"))?a?'<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,a="#filter"){jQuery(e).jqGrid("setGridParam",{fdata:t});let n=document.querySelector(a);for(const e in t)for(let a in r)r[a].push(t[e][a]);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 a=document.createElement("ul"),i=document.createElement("lh");i.innerHTML=t,a.appendChild(i);for(let n in r[t]){let i=document.createElement("li"),o=document.createElement("label");o.innerHTML=r[t][n];let s=document.createElement("input");s.setAttribute("type","checkbox"),s.setAttribute("class",t),s.setAttribute("id",t+"_"+r[t][n]),o.setAttribute("for",t+"_"+r[t][n]),s.value=r[t][n],s.onchange=async()=>{await this._filter(e,r)},i.appendChild(o),i.appendChild(s),a.appendChild(i)}n.appendChild(a)}}async _filter(e,t){let r=[],a=jQuery(e).jqGrid("getGridParam","fdata"),n=[];for(let e in t){let t=document.querySelectorAll("."+e);n[e]=[];for(let r in t)t[r].checked&&n[e].push(t[r].value)}for(let e in a){let i=!1;for(let r in t)-1!=n[r].indexOf(a[e][r])&&(i=!0);i&&r.push(a[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,65 @@ module.exports = class Vanilla_website_utils {
15
15
  }
16
16
  }
17
17
 
18
+ /**
19
+ * Format a number into a currency if have value, otherwise return empty
20
+ @alias module:Jqgrid_utils
21
+ @param {object} - col_model of the grid
22
+ @param {string} - name of column to be formatter
23
+ @param {string} - currency symbol, default is $
24
+ @example
25
+ var jqu = new Jqgrid_utils();
26
+ let _data = await jqu.format_currency(this,'my_field','$');
27
+ console.log(_data);
28
+ */
29
+ async format_currency_on_value(col_model, edit_field, currency = "$") {
30
+ for (let i = 0; i < col_model.length; i++) {
31
+ if (col_model[i]["name"] === edit_field) {
32
+ col_model[i]["formatoptions"] = {
33
+ prefix: currency,
34
+ decimalSeparator: ".",
35
+ thousandsSeparator: ",",
36
+ decimalPlaces: 2,
37
+ };
38
+ col_model[i]["formatter"] = function (cellvalue, options, rowObject) {
39
+ if (
40
+ cellvalue === null ||
41
+ cellvalue === undefined ||
42
+ cellvalue === ""
43
+ ) {
44
+ return ""; // Return an empty string for no value
45
+ } else if (parseFloat(cellvalue) === 0) {
46
+ return ""; // Return an empty string for zero value
47
+ } else {
48
+ // Apply currency formatting
49
+ var currency = options.colModel.formatoptions.prefix; // Get currency symbol
50
+ var decimalSeparator =
51
+ options.colModel.formatoptions.decimalSeparator;
52
+ var thousandsSeparator =
53
+ options.colModel.formatoptions.thousandsSeparator;
54
+ var decimalPlaces = options.colModel.formatoptions.decimalPlaces;
55
+
56
+ // Implement your currency formatting logic here
57
+ // (This is a simplified example; you might need a more robust formatting function)
58
+ var formattedValue = parseFloat(cellvalue).toFixed(decimalPlaces);
59
+ formattedValue = formattedValue.replace(".", decimalSeparator);
60
+
61
+ // Add thousands separator
62
+ var parts = formattedValue.split(decimalSeparator);
63
+ parts[0] = parts[0].replace(
64
+ /\B(?=(\d{3})+(?!\d))/g,
65
+ thousandsSeparator,
66
+ );
67
+ formattedValue = parts.join(decimalSeparator);
68
+
69
+ return currency + formattedValue; // Return formatted value
70
+ }
71
+ };
72
+ }
73
+ }
74
+ return col_model;
75
+ }
76
+
18
77
  /**
19
78
  * Format a number into a currency
20
79
  @alias module:Jqgrid_utils
package/package.json CHANGED
@@ -26,6 +26,6 @@
26
26
  "url": "https://github.com/myridia/jqgrid_utils"
27
27
  },
28
28
 
29
- "version": "1.38.0"
29
+ "version": "1.38.1"
30
30
 
31
31
  }