jqgrid_utils 1.40.2 → 1.41.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -164,6 +164,7 @@ A module for Jqgrid_utils
164
164
  * [module.exports#binary_replace(cell_value, a, b)](#exp_module_Jqgrid_utils--module.exports+binary_replace) ⏏
165
165
  * [module.exports#_date112_to_DMY(cell_value, seperator)](#exp_module_Jqgrid_utils--module.exports+_date112_to_DMY) ⏏
166
166
  * [module.exports#date112_to_DMY(col_model, edit_field, seperator)](#exp_module_Jqgrid_utils--module.exports+date112_to_DMY) ⏏
167
+ * [module.exports#set_col_model(col_model, edit_field, key, value)](#exp_module_Jqgrid_utils--module.exports+set_col_model) ⏏
167
168
  * [module.exports#add_formatter(col_model, edit_field, formatter)](#exp_module_Jqgrid_utils--module.exports+add_formatter) ⏏
168
169
  * [module.exports#natural_sort(col_model, column_name)](#exp_module_Jqgrid_utils--module.exports+natural_sort) ⇒ <code>array</code> ⏏
169
170
  * [module.exports#add_html_formatter(col_model, edit_field, html)](#exp_module_Jqgrid_utils--module.exports+add_html_formatter) ⇒ <code>array</code> ⏏
@@ -655,6 +656,30 @@ var jqu = new Jqgrid_utils();
655
656
  let _data = await jqu.date112_to_DMY(this,'field','/');
656
657
  console.log(_data);
657
658
  ```
659
+ <a name="exp_module_Jqgrid_utils--module.exports+set_col_model"></a>
660
+
661
+ ### module.exports#set\_col\_model(col_model, edit_field, key, value) ⏏
662
+ Set col_model
663
+
664
+ **Kind**: Exported function
665
+
666
+ | Param | Type | Description |
667
+ | --- | --- | --- |
668
+ | col_model | <code>array</code> | grid col_model |
669
+ | edit_field | <code>string</code> | string columns names what will be formatted |
670
+ | key | <code>string</code> | key of the model |
671
+ | value | <code>string</code> | value of the model |
672
+
673
+ **Example**
674
+ ```js
675
+ var jqu = new Jqgrid_utils();
676
+ col_model = await jqu.set_col_model(
677
+ col_model,
678
+ "to_close",
679
+ "editable",
680
+ true,
681
+ );
682
+ ```
658
683
  <a name="exp_module_Jqgrid_utils--module.exports+add_formatter"></a>
659
684
 
660
685
  ### module.exports#add\_formatter(col_model, edit_field, formatter) ⏏
@@ -881,7 +881,11 @@ console.log(_data);
881
881
  */
882
882
  _date112_to_DMY(cell_value, seperator = "/") {
883
883
  let value = cell_value;
884
- if (cell_value.length >= 8 && cell_value.indexOf(seperator) === -1) {
884
+ cell_value = String(cell_value);
885
+ if (
886
+ cell_value.trim().length >= 8 &&
887
+ cell_value.trim().indexOf(seperator) === -1
888
+ ) {
885
889
  let a = [];
886
890
  a.push(cell_value.substr(6, 2));
887
891
  a.push(cell_value.substr(4, 2));
@@ -906,7 +910,11 @@ console.log(_data);
906
910
  for (let i = 0; i < col_model.length; i++) {
907
911
  if (col_model[i]["name"] === edit_field) {
908
912
  col_model[i]["formatter"] = function (cell_value, o) {
909
- if (cell_value) {
913
+ cell_value = String(cell_value);
914
+ if (
915
+ cell_value.trim().length >= 8 &&
916
+ cell_value.trim().indexOf(seperator) === -1
917
+ ) {
910
918
  cell_value = cell_value.toString();
911
919
  let value = cell_value;
912
920
  if (
@@ -929,6 +937,34 @@ console.log(_data);
929
937
  return col_model;
930
938
  }
931
939
 
940
+ /**
941
+ * Set col_model
942
+ @alias module:Jqgrid_utils
943
+ @param {array} - grid col_model
944
+ @param {string} - string columns names what will be formatted
945
+ @param {string} - key of the model
946
+ @param {string} - value of the model
947
+
948
+ @example
949
+ var jqu = new Jqgrid_utils();
950
+ col_model = await jqu.set_col_model(
951
+ col_model,
952
+ "to_close",
953
+ "editable",
954
+ true,
955
+ );
956
+
957
+ */
958
+
959
+ async set_col_model(col_model, edit_field, key, value) {
960
+ for (let i = 0; i < col_model.length; i++) {
961
+ if (col_model[i]["name"] === edit_field) {
962
+ col_model[i][key] = value;
963
+ }
964
+ }
965
+ return col_model;
966
+ }
967
+
932
968
  /**
933
969
  * Add Formatter
934
970
  @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,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=[],r="",a=[]){return await this.grid_sum_on(e,t,r,a)}async grid_sum_on(e,t=[],r="",a=[]){let n=jQuery(e),i=n.jqGrid("getGridParam","data"),o={invdate:"Total"};for(let e in t){let n=0;for(let r in i){let o=0;if(i[r].hasOwnProperty(t[e])){let s=i[r][t[e]],l=!0;for(let e=0;e<a.length;e++)for(let t in a[e])if(i[r][t]===a[e][t]){l=!1;break}if(s&&l){if("string"==typeof s)if(this.is_html(s)){const e=(new DOMParser).parseFromString(s,"text/html").querySelectorAll("a"),t=Array.from(e).map((e=>e.text));if(t.length){const e=t[0].replace(",","");is_digit(e)&&(o=parseFloat(e))}}else is_digit(s)&&(o=parseFloat(s));else"number"==typeof s&&(o=s);n+=o}}}n!=Math.floor(n)&&(n=n.toFixed(2)),o[t[e]]=""!=r?r+""+this._format_number_with_commas(n):n}return n.jqGrid("footerData","set",o),o}_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}_format_number_with_commas(e){const t=e.toString().split(".");return t[0]=t[0].replace(/\B(?=(\d{3})+(?!\d))/g,","),t.join(".")}__cell_format(e,t){if("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>';else if("$"==t&&e){e=t+""+this._format_number_with_commas(e)}return 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)}));
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_on_value(e,t,r="$"){for(let n=0;n<e.length;n++)e[n].name===t&&(e[n].formatoptions={prefix:r,decimalSeparator:".",thousandsSeparator:",",decimalPlaces:2},e[n].formatter=function(e,t,r){if(null==e||""===e)return"";if(0===parseFloat(e))return"";var n=t.colModel.formatoptions.prefix,a=t.colModel.formatoptions.decimalSeparator,i=t.colModel.formatoptions.thousandsSeparator,o=t.colModel.formatoptions.decimalPlaces,s=parseFloat(e).toFixed(o),l=(s=s.replace(".",a)).split(a);return l[0]=l[0].replace(/\B(?=(\d{3})+(?!\d))/g,i),n+(s=l.join(a))});return e}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=[],r="",n=[]){return await this.grid_sum_on(e,t,r,n)}async grid_sum_on(e,t=[],r="",n=[]){let a=jQuery(e),i=a.jqGrid("getGridParam","data"),o={invdate:"Total"};for(let e in t){let a=0;for(let r in i){let o=0;if(i[r].hasOwnProperty(t[e])){let s=i[r][t[e]],l=!0;for(let e=0;e<n.length;e++)for(let t in n[e])if(i[r][t]===n[e][t]){l=!1;break}if(s&&l){if("string"==typeof s)if(this.is_html(s)){const e=(new DOMParser).parseFromString(s,"text/html").querySelectorAll("a"),t=Array.from(e).map(e=>e.text);if(t.length){const e=t[0].replace(",","");is_digit(e)&&(o=parseFloat(e))}}else is_digit(s)&&(o=parseFloat(s));else"number"==typeof s&&(o=s);a+=o}}}a!=Math.floor(a)&&(a=a.toFixed(2)),o[t[e]]=""!=r?r+""+this._format_number_with_commas(a):a}return a.jqGrid("footerData","set",o),o}_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=String(e)).trim().length>=8&&-1===e.trim().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=String(e)).trim().length>=8&&-1===e.trim().indexOf(r)){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 set_col_model(e,t,r,n){for(let a=0;a<e.length;a++)e[a].name===t&&(e[a][r]=n);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"),m=u.replace(i,"\0$1\0").replace(/\0$/,"").replace(/^\0/,"").split("\0"),_=parseInt(f.match(l))||1!=p.length&&f.match(s)&&Date.parse(f),h=parseInt(u.match(l))||_&&u.match(s)&&Date.parse(u)||null;if(h){if(_<h)return-r;if(_>h)return r}for(var y=0,g=Math.max(p.length,m.length);y<g;y++){if(n=!(p[y]||"").match(d)&&parseFloat(p[y])||p[y]||0,a=!(m[y]||"").match(d)&&parseFloat(m[y])||m[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}_format_number_with_commas(e){const t=e.toString().split(".");return t[0]=t[0].replace(/\B(?=(\d{3})+(?!\d))/g,","),t.join(".")}__cell_format(e,t){if("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>';else if("$"==t&&e){e=t+""+this._format_number_with_commas(e)}return 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)});
Binary file
package/jqgrid_utils.js CHANGED
@@ -880,7 +880,11 @@ console.log(_data);
880
880
  */
881
881
  _date112_to_DMY(cell_value, seperator = "/") {
882
882
  let value = cell_value;
883
- if (cell_value.length >= 8 && cell_value.indexOf(seperator) === -1) {
883
+ cell_value = String(cell_value);
884
+ if (
885
+ cell_value.trim().length >= 8 &&
886
+ cell_value.trim().indexOf(seperator) === -1
887
+ ) {
884
888
  let a = [];
885
889
  a.push(cell_value.substr(6, 2));
886
890
  a.push(cell_value.substr(4, 2));
@@ -905,7 +909,11 @@ console.log(_data);
905
909
  for (let i = 0; i < col_model.length; i++) {
906
910
  if (col_model[i]["name"] === edit_field) {
907
911
  col_model[i]["formatter"] = function (cell_value, o) {
908
- if (cell_value) {
912
+ cell_value = String(cell_value);
913
+ if (
914
+ cell_value.trim().length >= 8 &&
915
+ cell_value.trim().indexOf(seperator) === -1
916
+ ) {
909
917
  cell_value = cell_value.toString();
910
918
  let value = cell_value;
911
919
  if (
@@ -928,6 +936,34 @@ console.log(_data);
928
936
  return col_model;
929
937
  }
930
938
 
939
+ /**
940
+ * Set col_model
941
+ @alias module:Jqgrid_utils
942
+ @param {array} - grid col_model
943
+ @param {string} - string columns names what will be formatted
944
+ @param {string} - key of the model
945
+ @param {string} - value of the model
946
+
947
+ @example
948
+ var jqu = new Jqgrid_utils();
949
+ col_model = await jqu.set_col_model(
950
+ col_model,
951
+ "to_close",
952
+ "editable",
953
+ true,
954
+ );
955
+
956
+ */
957
+
958
+ async set_col_model(col_model, edit_field, key, value) {
959
+ for (let i = 0; i < col_model.length; i++) {
960
+ if (col_model[i]["name"] === edit_field) {
961
+ col_model[i][key] = value;
962
+ }
963
+ }
964
+ return col_model;
965
+ }
966
+
931
967
  /**
932
968
  * Add Formatter
933
969
  @alias module:Jqgrid_utils
package/package.json CHANGED
@@ -26,6 +26,8 @@
26
26
  "url": "https://github.com/myridia/jqgrid_utils"
27
27
  },
28
28
 
29
- "version": "1.40.2"
29
+ "version": "1.41.0"
30
+
31
+
30
32
 
31
33
  }
Binary file