Free javascript Hosting


jxutils-10-0-prod.js

Uploaded on Oct 28 2021 00:41 by xfakhri.madhkourq

"use strict";function ownKeys(t,e){var r,n=Object.keys(t);return Object.getOwnPropertySymbols&&(r=Object.getOwnPropertySymbols(t),e&&(r=r.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,r)),n}function _objectSpread(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?ownKeys(r,!0).forEach(function(e){_defineProperty(t,e,r[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):ownKeys(r).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}function _defineProperty(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function _createClass(e,t,r){return t&&_defineProperties(e.prototype,t),r&&_defineProperties(e,r),e}function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function _formatOnArray(r,n){return toReplace.forEach(function(t){"string"==typeof t||"number"==typeof t?r=(n=r.match(/([%])([a-z]|[\d])+/)[0])?r.split(n).join(String(t)):r:Object.keys(t).forEach(function(e){r=(n=r.match(new RegExp("(%)("+e+")","g"))[0])?r.split(n).join(String(t[e])):r})}),arr}String.prototype.format=function(r){var t=this.toString(),n="";return r&&r.length?"string"==typeof r||"number"==typeof element?t=(n=t.match(/([%])([a-z]|[\d])+/g))?n.reduce(function(e,t){return e.split(t).join(r)},t):t:Array.isArray(r)&&(t=_formatOnArray(t,n)):"object"==_typeof(r)&&Object.keys(r).forEach(function(e){t=(n=t.match(new RegExp("(%)("+e+")","g"))[0])?t.split("%"+e).join(String(r[e])):t}),t},String.prototype.add=function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"";return this.toString()+e},String.prototype.padLeft=function(e,t){var r=void 0!==t?t:"0",n=new Array(1+e).join(r);return(n+this).slice(-n.length)},String.prototype.toDouble=function(){var e=String(this).replace(/[^\d]+/g,""),t=e.substr(0,e.length-2),r="0.".concat(e.substr(e.length-2));return Number(Number(t).toFixed(2))+Number(r)},String.prototype.getDate=function(){return this.substr(0,2)+"/"+this.substr(2,2)+"/"+this.substr(4,4)+" "+this.substr(9,5)},Date.prototype.getArray=function(){var e=String(this.getFullYear()).padStart(4,"0"),t=String(this.getMonth()+1).padStart(2,"0"),r=String(this.getDate()).padStart(2,"0"),n=String(this.getHours()).padStart(2,"0"),o=String(this.getMinutes()).padStart(2,"0"),i=String(this.getSeconds()).padStart(2,"0"),a=new Array;return a.push(e),a.push(t),a.push(r),a.push(n),a.push(o),a.push(i),a},Date.prototype.toSQLDate=function(){return"".concat(this.getArray()[2],"/").concat(this.getArray()[1],"/").concat(this.getArray()[0]," ").concat(this.getArray()[3],":").concat(this.getArray()[4])},Number.prototype.excelToDate=function(){return new Date(Math.round(86400*(this-25569)*1e3))},Number.prototype.excelToSQLDate=function(){return new Date(Math.round(86400*(this-25569)*1e3)).toSQLDate()},Array.prototype.isFieldEquals=function(r,n){return this.map(function(e,t){return e[n]===r[n]?t:void 0}).filter(function(e){return"number"==typeof e})[0]};var ResponseJX=function(){function e(){_classCallCheck(this,e)}return _createClass(e,[{key:"process",value:function(e,t){var r=1<arguments.length&&void 0!==t?t:"SELECT",n=this._buildError(e);if(n)console.error(n);else switch(r){case"SELECT":return this._buildObjectSelect(e);case"ACTION":return this._buildObjectAction(e);case"SAVEINVOICE":return this._buildInvoiceSave(e);case"SAVE":return this._buildObjectSave(e);case"DELETE":return this._buildObjectDelete(e);default:return this._buildObjectDefault(e)}}},{key:"getCookie",value:function(e){if("1"==e.status&&e.responseBody)return"jsessionid=%value".format(e.responseBody.jsessionid);this.buildError(e)}},{key:"_buildObjectSelect",value:function(e){var t=[],r="string"==typeof e?JSON.parse(e):e;r.data?r=r.data.responseBody:r.responseBody&&(r=r.responseBody);var o=r.fieldsMetadata||[],n=r.rows||[];return n.length&&n.forEach(function(r){var n={};o.forEach(function(e,t){return n[e.name]=r[t]}),t.push(n)}),t}},{key:"_buildObjectAction",value:function(e){return JSON.parse(e).statusMessage}},{key:"_buildObjectDelete",value:function(e){return{deleteId:JSON.parse(e).transactionId}}},{key:"_buildObjectDefault",value:function(e){var n=JSON.parse(JSON.stringify(e)).responseBody,o=n.entities.metadata.fields.field.map(function(e){return e.name}),t=Number(n.entities.total),i={},a=[];return t&&1==t?a.push(this._singleBuildObjectDefault(n,o)):t&&1<t&&Array(t).fill().forEach(function(e,t){var r=[];Object.keys(n.entities.entity[t]).forEach(function(e){return r.push(n.entities.entity[t][e].$)}),o.forEach(function(e,t){"_rmd"!==e&&(i[e]=r[t]?r[t]:null)}),a.push(i)}),a}},{key:"_singleBuildObjectDefault",value:function(t,e){var r=[],n={};return Object.keys(t.entities.entity).forEach(function(e){return r.push(t.entities.entity[e].$)}),e.forEach(function(e,t){"_rmd"!==e&&(n[e]=r[t]?r[t]:null)}),n}},{key:"_buildObjectSave",value:function(e){var t={},r="string"==typeof e?JSON.parse(e).responseBody.entities.entity:e.responseBody.entities.entity;return Object.keys(r).forEach(function(e){return t[e]=r[e].$}),t}},{key:"_buildInvoiceSave",value:function(e){return"string"==typeof e?JSON.parse(e).responseBody:e.responseBody}},{key:"_buildError",value:function(e){return!(!((e=JSON.parse(e))&&e.statusMessage&&["0","2"].includes(e.status))||e.responseBody)&&e.statusMessage}}]),e}(),QueryJX=function(){function e(){_classCallCheck(this,e),this._credential={url:""},this._responseProcessor=new ResponseJX,this.lib={MOBILE_LOGIN:"MobileLoginSP.login",DB_EXECUTE_QUERY:"DbExplorerSP.executeQuery",LOGIN_URL:"%url/mge/service.sbr?serviceName=MobileLoginSP.login&outputType=json",COMMON_URL:"/mge/service.sbr?serviceName=%servJX&outputType=json",SELECT:"SELECT",ACTION:"ACTION",CONTENT_TYPE:"Content-Type",ACCEPT:"Accept",APPLICATION_JSON:"application/json",APPLICATION_XML:"application/xml",ACCESS_CORS:"Access-Control-Allow-Origin",JS:"js",JAVA:"java",SQL:"sql",SIM:"S",NAO:"N",POST:"POST",EXECUTE_SQL:'{ "serviceName": "DbExplorerSP.executeQuery", "requestBody": { "sql": "%query" } }'}}return _createClass(e,[{key:"_requestAjax",value:function(n){return regeneratorRuntime.async(function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.abrupt("return",new Promise(function(e,t){var r=new XMLHttpRequest;r.open(n.method,n.url,!0),r.withCredentials=!0,Object.keys(n.headers).forEach(function(e){return r.setRequestHeader(e,n.headers[e])}),r.onload=function(){200<=r.status&&r.status<300?e(r.response):t(r.statusText)},n.data?r.send(n.data):r.send()}));case 4:e.prev=4,e.t0=e.catch(0);case 6:case"end":return e.stop()}},null,null,[[0,4]])}},{key:"login",value:function(t){var r,n,o,i=this;return regeneratorRuntime.async(function(e){for(;;)switch(e.prev=e.next){case 0:this.credential=_objectSpread({},t,{},this._credential),this.credential.url=t.url?t.url:this._credential.url,n={serviceName:this.lib.MOBILE_LOGIN,requestBody:{NOMUSU:{$:this.credential.user},INTERNO:{$:this.credential.key},KEEPCONNECTED:{$:this.lib.SIM}}},o={url:this.lib.LOGIN_URL.format({url:this.credential.url}),method:this.lib.POST.toLowerCase(),data:JSON.stringify(n),headers:(_defineProperty(r={},this.lib.CONTENT_TYPE,this.lib.APPLICATION_JSON),_defineProperty(r,this.lib.ACCESS_CORS,"*"),r),withCredentials:!1},this._requestAjax(o).then(function(e){return i._responseProcessor.getCookie(e)&&(i._credential.cookies=i._responseProcessor.getCookie(e)),i._credential.cookies}).catch(function(e){return console.error(e)});case 5:case"end":return e.stop()}},null,this)}},{key:"select",value:function(t){var r,n,o,i=this,a=arguments;return regeneratorRuntime.async(function(e){for(;;)switch(e.prev=e.next){case 0:return n=1<a.length&&void 0!==a[1]?a[1]:{},this.credential=_objectSpread({},this._credential,{},n),o={url:"".concat(this.credential.url).concat(this.lib.COMMON_URL.toString().format({servJX:this.lib.DB_EXECUTE_QUERY})),method:this.lib.POST,data:this.lib.EXECUTE_SQL.format(t.replace(/(\r\n|\n|\r)/gm,"")),headers:(_defineProperty(r={},this.lib.CONTENT_TYPE,this.lib.APPLICATION_JSON),_defineProperty(r,this.lib.ACCEPT,this.lib.APPLICATION_JSON),r)},e.abrupt("return",this._requestAjax(o).then(function(e){return i._responseProcessor.process(e,i.lib.SELECT)}));case 4:case"end":return e.stop()}},null,this)}},{key:"action",value:function(t){var r,n,o,i,a,s,c,u=this,l=arguments;return regeneratorRuntime.async(function(e){for(;;)switch(e.prev=e.next){case 0:(n=1<l.length&&void 0!==l[1]?l[1]:{resourceID:0,target:this.lib.JS,actionID:0,procName:"",rootEntity:""}).target=n.target?n.target:this.lib.JS,o="",i={},a="application/json",s={clientEvent:[{$:"br.com.sankhya.actionbutton.clientconfirm"}]},e.t0=n.target.toLowerCase(),e.next=e.t0===this.lib.JS?9:e.t0===this.lib.JAVA?12:e.t0===this.lib.SQL?15:26;break;case 9:return i={serviceName:o="ActionButtonsSP.executeScript",requestBody:{runScript:_objectSpread({actionID:n.actionID},this._convertParamAction(t))},clientEventList:s},e.abrupt("break",27);case 12:return i={serviceName:o="ActionButtonsSP.executeJava",requestBody:{javaCall:_objectSpread({actionID:n.actionID},this._convertParamAction(t)),clientEventList:s}},e.abrupt("break",27);case 15:if(n.procName){e.next=20;break}return console.error("PLSQL Actions needs the procName (procedure name)!"),e.abrupt("return");case 20:if(n.rootEntity){e.next=23;break}return console.error("PLSQL Actions needs the rootEntity (procedure instance owner)!"),e.abrupt("return");case 23:return i={serviceName:o="ActionButtonsSP.executeSTP",requestBody:{stpCall:_objectSpread({actionID:n.actionID,rootEntity:n.rootEntity,procName:n.procName},this._convertParamAction(t)),clientEventList:s}},e.abrupt("break",27);case 26:return e.abrupt("break",27);case 27:return c={url:"".concat(this._credential.url).concat(this.lib.COMMON_URL.toString().format({servJX:o}),"&resourceID=").concat(n.resourceID),method:this.lib.POST,data:JSON.stringify(i),headers:(_defineProperty(r={},this.lib.CONTENT_TYPE,a),_defineProperty(r,this.lib.ACCEPT,this.lib.APPLICATION_JSON),r)},e.abrupt("return",this._requestAjax(c).then(function(e){return u._responseProcessor.process(e,u.lib.ACTION)}));case 29:case"end":return e.stop()}},null,this)}},{key:"_convertParamAction",value:function(t){var r={params:{param:[]}};return Object.keys(t).forEach(function(e){return r.params.param.push({type:"string"==typeof t[e]?"S":"I",paramName:e,$:t[e]})}),r}},{key:"save",value:function(t,r,n){var o,i,a,s,c=this;return regeneratorRuntime.async(function(e){for(;;)switch(e.prev=e.next){case 0:o=["nota","cabecalhonota","pedido","orcamento"].includes(String(r).toLowerCase()),i=null,i=o?this._buildInvoice(t,n):this._buildRecord(t,r,n),a="";try{a=decodeURIComponent(document.cookie).split(";").filter(function(e){return e.split("=")[0].trim().includes("JSESSIONID")})[0].split("=")[1].replace(".master","")}catch(e){}return s={url:"".concat(this.credential.url,"/").concat(o?"mgecom":"mge","/service.sbr?serviceName=").concat(o?"CACSP.incluirNota":"CRUDServiceProvider.saveRecord","&outputType=json").concat(o?"&mgeSession="+a:""),method:this.lib.POST,data:JSON.stringify(i),headers:_defineProperty({},this.lib.CONTENT_TYPE,this.lib.APPLICATION_JSON)},e.abrupt("return",this._requestAjax(s).then(function(e){return c._responseProcessor.process(e,o?"SAVEINVOICE":"SAVE")}));case 7:case"end":return e.stop()}},null,this)}},{key:"_buildRecord",value:function(r,e,t){var n,o={serviceName:"CRUDServiceProvider.saveRecord",requestBody:{dataSet:{rootEntity:e,includePresentationFields:"N",dataRow:{localFields:Object.keys(r).reduce(function(e,t){return _objectSpread({},e,_defineProperty({},t.toUpperCase(),{$:String(r[t])}))},{})},entity:{fieldset:{list:Object.keys(r).map(function(e){return e.toUpperCase()}).join(",")}}}}};return t&&(n={},Object.keys(t).forEach(function(e){return n=_objectSpread({},n,_defineProperty({},e.toUpperCase(),{$:String(t[e])}))}),o.requestBody.dataSet.dataRow.key=n),o}},{key:"_buildInvoice",value:function(n,e){var t=n.items,r=e?e.nunota||e.NUNOTA:n.nunota||n.NUNOTA,o=r?{$:String(r)}:{},i=!!n.informarPreco&&Boolean(n.informarPreco);delete n.items,delete n.nunota,delete n.NUNOTA;var a=Object.keys(n).reduce(function(e,t,r){return _objectSpread({},e,_defineProperty({},t.toUpperCase(),n[t]?{$:String(n[t])}:{}))},{NUNOTA:o}),t=t&&t.length?t.map(function(r){return Object.keys(r).reduce(function(e,t){return _objectSpread({},e,_defineProperty({},t.toUpperCase(),null!=r[t]&&null!=r[t]&&["number","string","boolean"].includes(_typeof(r[t]))&&String(r[t]).length?{$:String(r[t])}:{}))},{NUNOTA:o})}):[];return{serviceName:"CACSP.incluirNota",requestBody:{nota:{cabecalho:a,itens:{INFORMARPRECO:String(i),item:t}}}}}},{key:"delete",value:function(t,r){var n,o,i=this;return regeneratorRuntime.async(function(e){for(;;)switch(e.prev=e.next){case 0:if(this.credential=_objectSpread({},this._credential),r){e.next=4;break}return console.error("DELETE method needs the key(s) to find the record!"),e.abrupt("return");case 4:return n={serviceName:"DatasetSP.removeRecord",requestBody:{entityName:t,pks:r instanceof Array?r:[r]}},o={url:"".concat(this.credential.url,"/mge/service.sbr?serviceName=DatasetSP.removeRecord&outputType=json"),method:this.lib.POST,data:JSON.stringify(n),headers:_defineProperty({},this.lib.CONTENT_TYPE,this.lib.APPLICATION_XML)},e.abrupt("return",this._requestAjax(o).then(function(e){return i._responseProcessor.process(e,"DELETE")}));case 7:case"end":return e.stop()}},null,this)}}]),e}(),HostJX=function(){function t(){var e=!(0<arguments.length&&void 0!==arguments[0])||arguments[0];_classCallCheck(this,t),e&&this.removeFrame()}return _createClass(t,[{key:"getURL",value:function(e){return"".concat(window.location.origin).concat(e?"/"+e:"")}},{key:"isElementShowned",value:function(e,t){var r=$(window).scrollTop(),n=r+$(window).height(),o=$(e).offset().top,i=o+$(e).height();return!0===t?r<o&&i<n:o<=n&&r<=i}},{key:"getCookie",value:function(t){var e=decodeURIComponent(document.cookie).split(";"),r="";return e.forEach(function(e){e.split("=")[0].trim()===t&&(r=e.split("=")[1].trim())}),r}},{key:"loadFile",value:function(n){return new Promise(function(e,t){var r=new XMLHttpRequest;r.open("GET",n,!0),r.send(),r.onload=function(){200!=r.status?t(new Error("Error ".concat(r.status,": ").concat(r.statusText))):e(r.responseText)}})}},{key:"removeFrame",value:function(e){var r=this,o=0<arguments.length&&void 0!==e?e:{instance:"",initialPage:"app.jsp",params:void 0,UID:0,nuGdt:0};new Promise(function(t){window.parent.document.getElementsByTagName("body").length&&(window.parent.document.querySelector("div.gwt-PopupPanel.alert-box.box-shadow")&&(window.parent.document.querySelector("div.gwt-PopupPanel.alert-box.box-shadow").style.display="none"),window.parent.document.getElementsByTagName("body")[0].style.overflow="hidden"),window.parent.parent.document.getElementsByTagName("body").length&&(window.parent.parent.document.querySelector("div.gwt-PopupPanel.alert-box.box-shadow")&&(window.parent.parent.document.querySelector("div.gwt-PopupPanel.alert-box.box-shadow").style.display="none"),window.parent.parent.document.getElementsByTagName("body")[0].style.overflow="hidden");var e="";0<(e=window.parent.document.querySelector("div.GI-BUHVBPVC > div > div > div > div > div > table > tbody > tr > td > div")?window.parent.document.querySelector("div.GI-BUHVBPVC > div > div > div > div > div > table > tbody > tr > td > div").title:"string"==typeof o?o:o.instance).length?(new QueryJX).select("SELECT NUGDG FROM TSIGDG WHERE TITULO = '".concat(e,"'")).then(function(e){return t(_objectSpread({},r.__validateOptions(o),{gadGetID:"html5_z6dld",params:void 0,nuGdt:e[0].NUGDG}))}):t(_objectSpread({},r.__validateOptions(o),{gadGetID:"html5_z6dld",params:void 0,nuGdt:o.nuGdt}))}).then(function(n){return setTimeout(function(){var e,t,r;void 0!==window.parent.document.getElementsByClassName("DashWindow")[0]&&(e=Object.keys(n).filter(function(e){return!["params","UID","instance","nuGdg","gadGetID"].includes(e)}).map(function(e){return"&".concat(e,"=").concat(n[e])}).join(""),t=o.initialPage?o.initialPage:"app.jsp",r="/mge/html5component.mge?entryPoint=".concat(t,"&nuGdg=").concat(n.nuGdt).concat(e).concat(n.params?"&params="+window.atob(n.params):""),setTimeout(function(){return window.parent.document.getElementsByClassName("dyna-gadget")[0].innerHTML='<iframe src="'.concat(r,'" class="gwt-Frame" style="width: 100%; height: 100%;"></iframe>')},500),setTimeout(function(){return document.getElementsByClassName("popupContent").length?document.getElementsByClassName("popupContent")[0].parentElement.remove():void 0},3e4),setTimeout(function(){return document.getElementById("stndz-style").parentElement.parentElement.getElementsByTagName("body")[0].style.overflow="hidden"},3e4))})})}},{key:"__validateOptions",value:function(e){return"string"==typeof e?{}:e}},{key:"doDraggable",value:function(e){setTimeout(function(){var t,r=document.querySelector(e),n=0,o=0,i=0,a=0;r&&(t=function e(t){document.addEventListener("mouseup",function(){return document.removeEventListener("mousemove",e)}),r.scrollLeft=a-t.pageX+n,r.scrollTop=i-t.pageY+o},r.addEventListener("mousedown",function(e){e.preventDefault(),o=e.pageY,n=e.pageX,i=r.scrollTop,a=r.scrollLeft,document.addEventListener("mousemove",t)}))},2e3)}},{key:"openNewTab",value:function(e){var t=0<arguments.length&&void 0!==e&&e;(window.parent.parent.document.querySelector(".Taskbar-container")&&!t||t)&&Object.assign(document.createElement("a"),{target:"_blank",href:window.location.href}).click()}},{key:"closeTab",value:function(){window.parent.parent.document.querySelector(".Taskbar-container")?window.parent.parent.document.querySelector("li.ListItem.AppItem.AppItem-selected div.Taskbar-icon.icon-close").click():window.close()}}]),t}(),Caller=function(){function e(){_classCallCheck(this,e)}return _createClass(e,null,[{key:"post",value:function(t,r){var n;return regeneratorRuntime.async(function(e){for(;;)switch(e.prev=e.next){case 0:return n={"Content-Type":"application/json;charset=utf-8","Content-Security-Policy":"connect-src ".concat(t)},e.prev=1,e.next=4,regeneratorRuntime.awrap(window.fetch.bind(window)(t,{method:"POST",headers:n,body:JSON.stringify(r)}));case 4:return e.abrupt("return",e.sent.json());case 7:e.prev=7,e.t0=e.catch(1),console.error(e.t0);case 10:case"end":return e.stop()}},null,null,[[1,7]])}}]),e}();

Back to list