cronapp-common-js 3.2.1-SP.3 → 3.2.1-SP.30

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.
@@ -1 +1 @@
1
- var ISO_PATTERN=/(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))/,TIME_PATTERN=/PT(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)(?:\.(\d+)?)?S)?/,DEP_PATTERN=/\{\{(.*?)\|raw\}\}/,HTTP_STATUS=/HTTP\/1\.1 (\d+) (.*)/,DS_ID=/[\w\_\.\d]+/;const isCronapiApiPath=e=>/^\/?api\/cronapi\/.*\/?$/.test(e);(function(e){var t={callback:function(){},runOnLoad:!0,frequency:100,previousVisibility:null},a={};a.checkVisibility=function(e,t){if(jQuery.contains(document,e[0])){var n=t.previousVisibility,s=e.is(":visible");t.previousVisibility=s;var r=null==n;r?t.runOnLoad&&t.callback(e,s,r):n!==s&&t.callback(e,s,r),setTimeout(function(){a.checkVisibility(e,t)},t.frequency)}},e.fn.visibilityChanged=function(n){var s=e.extend({},t,n);return this.each(function(){a.checkVisibility(e(this),s)})}})(jQuery);var initDatasource=function(e,t,a,n,s,r,i,o,d,c,l,u){var p=parseInt(9999*Math.random());if(cronapi.internal.isJsonString(a.headers)){let e=JSON.parse(a.headers);e.push({key:"origin-path",type:"string",value:d.path()}),a.headers=JSON.stringify(e)}else{var g="origin-path:"+d.path();a.headers=void 0===a.headers||null===a.headers?g:a.headers.concat(";",g)}var y,h={name:a.name,entity:a.entity,apiVersion:a.apiVersion,enabled:!a.hasOwnProperty("enabled")||"true"===a.enabled,keys:a.keys,endpoint:a.endpoint,lazy:"true"===a.lazy,append:!a.hasOwnProperty("append")||"true"===a.append,prepend:a.hasOwnProperty("prepend")&&""===a.prepend||"true"===a.prepend,watch:a.watch,rowsPerPage:a.rowsPerPage,offset:a.offset,filterURL:a.filter,watchFilter:a.watchFilter,deleteMessage:a.deleteMessage||""===a.deleteMessage?a.deleteMessage:o.instant("General.RemoveData"),headers:a.headers,autoPost:"true"===a.autoPost,autoRefresh:a.autoRefresh!==void 0&&null!==a.autoRefresh?a.autoRefresh:0,onError:a.onError,onAfterFill:a.onAfterFill,onBeforeCreate:a.onBeforeCreate,onAfterCreate:a.onAfterCreate,onBeforeUpdate:a.onBeforeUpdate,onAfterUpdate:a.onAfterUpdate,onBeforeDelete:a.onBeforeDelete,onAfterDelete:a.onAfterDelete,onChangeStatus:a.onChangeStatus,onGet:a.onGet,onPost:a.onPost,onPut:a.onPut,onDelete:a.onDelete,defaultNotSpecifiedErrorMessage:o.instant("General.ErrorOnServerCommunication"),dependentBy:a.dependentBy,dependentLazyPost:a.dependentLazyPost,batchPost:"true"===a.batchpost,dependentLazyPostField:a.dependentLazyPostField,parameters:a.parameters,parametersNullStrategy:a.parametersNullStrategy?a.parametersNullStrategy:"default",parametersExpression:$(t).attr("parameters"),conditionExpression:$(t).attr("condition"),condition:a.condition,orderBy:a.orderBy,loadDataStrategy:a.loadDataStrategy,schema:a.schema?JSON.parse(a.schema):void 0,checkRequired:!a.hasOwnProperty("checkrequired")||""===a.checkrequired||"true"===a.checkrequired,fetchOnVisible:!(a.fetchOnVisible===void 0||null===a.fetchOnVisible)&&"true"===a.fetchOnVisible,offline:!("true"!==a.offline),insideModal:!("true"!==a.insideModal)},f={filter:!0,entity:!0,enabled:!0,parameters:!0};if(e.params){for(var m in e.params)if(e.params.hasOwnProperty(m)){var D=e.params[m];if(m.startsWith("$"+a.name+".")){var M=m.split(".");2==M.length&&("$filterMode"==M[1]?h.startMode=D:(y?y+=";":y="",y+=isNaN(D)?M[1]+"='"+D+"'":M[1]+"="+D))}}y&&(h.parameters=y,h.parametersExpression=y)}var L,p=parseInt(9999*Math.random()),v=n.initDataset(h,e,l,r,u,p,o);a.$observe("filter",function(e){v.isPostingBatchData()||(f.filter?s(function(){f.filter=!1},0):(s.cancel(L),L=s(function(){v.events.overRideRefresh?v.callDataSourceEvents("overRideRefresh","filter",e):v.filter(e,function(e){v.events.refresh&&v.callDataSourceEvents("refresh",e,"filter")}),v.lastFilterParsed=e},100)))}),y||a.$observe("parameters",function(e){v.isPostingBatchData()||v.parameters!=e&&(v.parameters=e,s.cancel(L),L=s(function(){v.callDataSourceEvents("changeDependency","parameters",v.parameters),v.events.overRideRefresh?v.callDataSourceEvents("overRideRefresh","parameters",v.parameters):v.fetch({params:{}},{success:function(e){v.events.refresh&&v.callDataSourceEvents("refresh",e,"parameters")}})},0))});let b={lastCondition:void 0,timeForCondition:void 0,typingSpeedLimit:1e3,maxWaitingValue:1e3,wait:function(){if(this.timeForCondition=0,this.lastCondition){let e=new Date().getTime()-this.lastCondition.getTime();e<this.typingSpeedLimit&&(this.timeForCondition=this.maxWaitingValue)}return this.lastCondition=new Date,this.timeForCondition}};a.$observe("condition",function(e){if(!v.isPostingBatchData()&&v.condition!=e){if(v.condition=e,"button"===v.loadDataStrategy)return;s.cancel(L),L=s(function(){v.callDataSourceEvents("changeDependency","condition",v.condition),v.events.overRideRefresh?v.callDataSourceEvents("overRideRefresh","condition",v.condition):v.fetch({params:{}},{success:function(e){v.events.refresh&&v.callDataSourceEvents("refresh",e,"condition")}})},b.wait())}}),a.$observe("enabled",function(e){var t="true"===e;v.enabled!=t&&(v.enabled=t,v.enabled&&(s.cancel(L),L=s(function(){v.events.overRideRefresh?v.callDataSourceEvents("overRideRefresh","enabled",v.parameters):v.fetch({params:{}},{success:function(e){v.events.refresh&&v.callDataSourceEvents("refresh",e,"enabled")}})},200)))}),a.$observe("entity",function(e){v.entity=e,v.entity.match(DS_ID)&&!isCronapiApiPath(v.entity)&&(v.entity="api/cronapi/odata/v2/"+v.entity.replaceAll(".","/")),f.entity?s(function(){f.entity=!1}):(s.cancel(L),L=s(function(){v.fetch({params:{}},{success:function(e){v.events.refresh&&v.callDataSourceEvents("refresh",e,"entity")}})},200))}),a.$observe("offline",function(e){v.offline="true"===e}),e.$on("$destroy",function(){c[a.name]&&c[a.name+".instanceId"]==p&&(c[a.name].destroy(),delete window[a.name],delete c[a.name],delete c[a.name+".instanceId"])})};angular.module("datasourcejs",[]).factory("DatasetManager",["$http","$q","$timeout","$rootScope","$window","Notification","SyncService",function($http,$q,$timeout,$rootScope,$window,Notification,SyncService){this.datasets={};let DatasetManagerUtil={getMainScope:function(){return angular.element(document.getElementById("main-view")).scope()},resolveExpressionMap:async function(e){let t,a=this.getMainScope();if(cronapi.internal.isJsonString(e)){t={};let s=JSON.parse(e);for(var n in s){let e=s[n];if("blockly"===e.type){let n=this.onMatchRegex(/cronapi.server/g,".run(",".toPromise().disableNotification()");t[e.key]=await a.$eval(n(e.value))}else t[e.key]="expression"===e.type?a.$eval(e.value):e.value}}return t},getHeaders:async function(e){let t;if(e&&0<e.length)if(!cronapi.internal.isJsonString(e)){t={};let n,s=e.trim().split(";");for(var a=0;a<s.length;a++)n=s[a].split(":"),2===n.length&&(t[n[0]]=n[1])}else t=await this.resolveExpressionMap(e);return t&&(t["X-From-DataSource"]="true"),t},onMatchRegex:function(e,t,a){return n=>{let s=e.exec(n);return s&&s.length?n.split(t).join(a+t):n}}};const $httpLegacy=e=>{var t={verb:e.method,successCallback:null,errorCallback:null,success:function(e){return this.successCallback=e,this},error:function(e){return this.errorCallback=e,this}};return DatasetManagerUtil.getHeaders(e.headers).then(function(t){if(e.headers=t||e.headers,e.offlineMode){SyncService.toQueue(e);let t=e.originalObject||e.rawData||e.data;this.successCallback(t,200,null,e)}else{let t=$http(e);t.then(e=>{this.successCallback&&this.successCallback(e.data,e.status,e.headers,e.config)}),t.catch(e=>{this.errorCallback&&this.errorCallback(e.data,e.status,e.headers,e.config)})}}.bind(t)),t};var DataSet=function(name,scope,fetchOnVisible){function reverseArr(e){if(e){for(var t=[],a=e.length-1;0<=a;a--)t.push(e[a]);return t}return[]}function toBase64(e,t){var a=new FileReader;a.readAsDataURL(e),a.onload=function(a){var e=a.target.result.substr(a.target.result.indexOf("base64,")+7);t(e)}}function uuid(){var e,t,a="";for(e=0;32>e;e++)t=0|16*Math.random(),(8==e||12==e||16==e||20==e)&&(a+="-"),a+=(12==e?4:16==e?8|3&t:t).toString(16);return a}var NO_IMAGE_UPLOAD="data:image/svg+xml;utf8;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iaXNvLTg4NTktMSI/Pgo8IS0tIEdlbmVyYXRvcjogQWRvYmUgSWxsdXN0cmF0b3IgMTYuMC4wLCBTVkcgRXhwb3J0IFBsdWctSW4gLiBTVkcgVmVyc2lvbjogNi4wMCBCdWlsZCAwKSAgLS0+CjwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMS4xLy9FTiIgImh0dHA6Ly93d3cudzMub3JnL0dyYXBoaWNzL1NWRy8xLjEvRFREL3N2ZzExLmR0ZCI+CjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgdmVyc2lvbj0iMS4xIiBpZD0iQ2FwYV8xIiB4PSIwcHgiIHk9IjBweCIgd2lkdGg9IjEyOHB4IiBoZWlnaHQ9IjEyOHB4IiB2aWV3Qm94PSIwIDAgNDQuNTAyIDQ0LjUwMiIgc3R5bGU9ImVuYWJsZS1iYWNrZ3JvdW5kOm5ldyAwIDAgNDQuNTAyIDQ0LjUwMjsiIHhtbDpzcGFjZT0icHJlc2VydmUiPgo8Zz4KCTxnPgoJCTxwYXRoIGQ9Ik05Ljg2MiwzNS42MzhoMjQuNzc5YzAtNS41NDYtMy44NjMtMTAuMjAzLTkuMTEzLTExLjYwNGMyLjc1LTEuMjQ4LDQuN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Cw1NDAuMjIzLDMxNy4yNDgsNTI0LjMyNiwyOTcuMzUyICAgeiBNMzYyLjcyOSwyODkuNjQ4Yy0xLjgxMywxLjgwNC0zLjk0OSwyLjcwNy02LjQyLDIuNzA3aC02My45NTN2MTAwLjUwMmMwLDIuNDcxLTAuOTAzLDQuNjEzLTIuNzExLDYuNDIgICBjLTEuODEzLDEuODEzLTMuOTQ5LDIuNzExLTYuNDIsMi43MTFoLTU0LjgyNmMtMi40NzQsMC00LjYxNS0wLjg5Ny02LjQyMy0yLjcxMWMtMS44MDQtMS44MDctMi43MTItMy45NDktMi43MTItNi40MlYyOTIuMzU1ICAgSDE1NS4zMWMtMi42NjIsMC00Ljg1My0wLjg1NS02LjU2My0yLjU2M2MtMS43MTMtMS43MTQtMi41NjgtMy45MDQtMi41NjgtNi41NjZjMC0yLjI4NiwwLjk1LTQuNTcyLDIuODUyLTYuODU1bDEwMC4yMTMtMTAwLjIxICAgYzEuNzEzLTEuNzE0LDMuOTAzLTIuNTcsNi41NjctMi41N2MyLjY2NiwwLDQuODU2LDAuODU2LDYuNTY3LDIuNTdsMTAwLjQ5OSwxMDAuNDk1YzEuNzE0LDEuNzEyLDIuNTYyLDMuOTAxLDIuNTYyLDYuNTcxICAgQzM2NS40MzgsMjg1LjY5NiwzNjQuNTM1LDI4Ny44NDUsMzYyLjcyOSwyODkuNjQ4eiIgZmlsbD0iI2NlY2VjZSIvPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+Cjwvc3ZnPgo=";this.fetchOnVisible=fetchOnVisible,this.parent=$("[name='"+name+"']").parent(),this.fetchOnVisible&&this.parent.visibilityChanged({callback:function(e,t){t&&this.holdServiceCall&&this.holdServi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LTAuNjcyLDEuNS0xLjVTMTIuMTY1LDQwLjE2OSwxMS4zMzYsNDAuMTY5eiIgZmlsbD0iIzkxOTE5MSIvPgoJPC9nPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+Cjwvc3ZnPgo=",this.noFileUpload=NO_FILE_UPLOAD,this.$apply=function(e){scope.safeApply(e)}.bind(scope),this.columns=[],this.data=[],this.name=name,this.keys=[],this.enabled=!0,this.endpoint=null,this.active={},this.inserting=!1,this.editing=!1,this.fetchSize=2,this.observers=[],this.rowsPerPage=null,this.append=!0,this.headers=null,this.responseHeaders=null,this._activeValues=null,this.errorMessage="",this.onError=null,this.links=null,this.loadedFinish=null,this.lastLoadedTime=0,this.lastFilterParsed=null,this.rowsCount=-1,this.events={},this.busy=!1,this.cursor=0,this._savedProps,this.hasMoreResults=!1,this.loaded=!1,this.unregisterDataWatch=null,this.dependentBufferLazyPostData=null,this.lastAction=null,this.dependentData=null,this.hasMemoryData=!1,this.batchPost=!1,this.caseInsensitive=null,this.terms=null,this.checkRequired=!0,this.schema;var _self=this,service=null;this.odataFile=[],this.destroy=function(){},this.init=function(){var dsScope=this;service={save:function(e){return this.call(_self.entity,"POST",e,!0)},update:function(e,t){return this.call(e,"PUT",t,!1)},remove:function(e,t){return this.call(e,"DELETE",t,!0)},call:function(e,t,a){var n={},s=0<=e.indexOf("/cronapi/query/");if(s){n.inputs=[a];var r,i,o={};if(_self.busy=!0,e=e.replace("/specificSearch",""),e=e.replace("/generalSearch",""),_self&&_self.$scope&&_self.$scope.vars)for(var d in o.vars={},_self.$scope.vars)o.vars[d]=_self.$scope.vars[d];for(var c in _self.$scope)_self.$scope[c]&&_self.$scope[c].constructor&&"DataSet"==_self.$scope[c].constructor.name&&(o[c]={},o[c].active=_self.$scope[c].active);n.fields=o}else n=a;var l={};for(var c in _self.copy(n,l,!0),delete l.__original,delete l.__status,delete l.__originalIdx,delete l.__sender,delete l.__$id,delete l.__parentId,delete l.$$hashKey,delete l.__fromMemory,delete l.__odatafiles,delete l.__$masterExpression,l)-1<c.indexOf("__odataFile_")&&(l[c.replace("__odataFile_","")]=void 0,delete l[c]);for(var c in l)if(l.hasOwnProperty(c)){let e=l[c];_self.isAutoGeneratedValue(e)&&delete l[c]}var u=function(e,t,a,n,i){if(_self.busy=!1,r&&(_self.isOData()?null!=e.d&&null!=e.d.result?(_self.normalizeData(e.d.result),r(e.d.result,!0,i)):null==e.d?r(e,!0,i):(_self.normalizeObject(e.d),r(e.d,!0,i)):r(s?e.value:e,!0,i)),s||_self.isOData()){var o=e;_self.isOData()&&(o={},o.commands=e.__callback,_self.normalizeData(o.commands)),_self.$scope.cronapi.evalInContext(JSON.stringify(o))}},p=_self.getParentDatasource();let g=p.getBatchDataItem(n);if(g&&g.result){let e=p.batchServiceData.indexOf(g);p.batchServiceData.splice(e,1),$timeout(()=>{u(g.result)},0),this.$promise={}}else this.$promise=_self.getService(t,n)({method:t,url:_self.removeSlash((window.hostApp||"")+e),data:"DELETE"==t?null:n?JSON.stringify(l):null,headers:_self.headers,rawData:n?l:null,originalObject:n?n:null,urlPart:e,offlineMode:_self.isOfflineMode()}).success(u).error(function(e){_self.busy=!1;var t;t=_self.isOData()?e.error.message.value:s&&e.value?e.value:e,_self.handleError(t),i&&i(t)});return this.$promise.then=function(e){return r=e,this},this.$promise.error=function(e){return i=e,this},this}},this.isAutoGeneratedValue=function(e){return"string"==typeof e&&10<e.length&&(e.startsWith("$autogenerated$")||e.substring(1).startsWith("$autogenerated$"))},this.getIndexedDB=function(e){return window.indexedDB||(window.indexedDB=window.indexedDB||window.mozIndexedDB||window.webkitIndexedDB||window.msIndexedDB,window.IDBTransaction=window.IDBTransaction||window.webkitIDBTransaction||window.msIDBTransaction,window.IDBKeyRange=window.IDBKeyRange||window.webkitIDBKeyRange||window.msIDBKeyRange),{properties:e,successCallback:null,errorCallback:null,type:null,args:null,success:function(e){return this.successCallback=e,this},error:function(e){return this.errorCallback=e,this},post:function(){return this.type="put",this.args=arguments,this},put:function(){return this.type="put",this.args=arguments,this},delete:function(){return this.type="delete",this.args=arguments,this},get:function(){return this.type="getAll",this.args=arguments,this},call:function(){request=window.indexedDB.open(this.properties.dbname,this.properties.dbversion||1),request.onerror=function(e){this.errorCallback&&this.errorCallback(e)}.bind(this),request.onsuccess=function(e){this.proceed(e.target.result)}.bind(this),request.onupgradeneeded=function(e){var t=e.target.result,a=t.createObjectStore(this.properties.objectStore,{keyPath:this.properties.key});a.transaction.oncomplete=function(){var e=t.transaction(this.properties.objectStore,"readwrite").objectStore(this.properties.objectStore);e.add({id:123,name:"Jose"})}.bind(this)}.bind(this)},proceed:function(e){if(this.type){var t=e.transaction(this.properties.objectStore,"readwrite"),a=t.objectStore(this.properties.objectStore),n=a[this.type].apply(a,this.args);n.onsuccess=function(e){this.successCallback&&("put"===this.type?this.successCallback(this.args[0]):this.successCallback(e.target.result))}.bind(this)}else this.successCallback&&this.successCallback()}}},this.batchServiceData=[],this.getBatchService=function(e){return function(t){var a={verb:e,properties:t,successCallback:null,errorCallback:null,success:function(e){return this.successCallback=e,this},error:function(e){return this.errorCallback=e,this}};return $timeout(function(){var n=this.getParentDatasource();let s=t.originalObject||t.rawData||t.data||this.active,r=this.entity;"PUT"==e&&(r=this.getEditionURL(s)),"DELETE"==e&&(r=this.getDeletionURL(s)),0<r.indexOf("/")&&(r=r.substring(r.lastIndexOf("/")+1,r.length)),n.batchServiceData.push({entity:r,data:s,promise:a}),a.successCallback&&a.successCallback.call(this,s,null,null,null,!0)}.bind(this)),a}.bind(this)},this.batchEnabled=function(e){return!!(e&&this.hasPendingChanges())&&null==this.getBatchDataItem(e)},this.getBatchDataItem=function(e){if(e){var t=this.getParentDatasource();for(let a,n=0;n<t.batchServiceData.length;n++)if(a=t.batchServiceData[n].data,a.__$id==e.__$id)return t.batchServiceData[n]}return null},this.performBatchPost=function(e){return new Promise(()=>{let t="batch_"+this.uuidv4(),a="";a+="--"+t+"\n";let n="changeset_"+this.uuidv4();a+="Content-Type: multipart/mixed; boundary="+n+"\n";for(let e,t=0;t<this.batchServiceData.length;t++){e=this.batchServiceData[t],a+="--"+n+"\n",a+="Content-Type: application/http\n",a+="Content-Transfer-Encoding:binary\n",a+=e.promise.properties.method+" "+e.entity+" HTTP/1.1\n",a+="Content-Type: application/json\n",a+="Accept: application/json\n",a+="X-Master-Id: "+e.promise.properties.originalObject.__$id+"\n",e.promise.properties.originalObject.__$masterExpression&&(a+="X-Detail-Fill: "+e.promise.properties.originalObject.__$masterExpression+"\n");let r=e.promise.properties.headers;for(var s in r)r.hasOwnProperty(s)&&(a+=s+": "+r[s]+"\n");"DELETE"!=e.promise.properties.method&&(a+=e.promise.properties.data+"\n")}a+="--"+n+"--\n",a+="--"+t+"--\n",console.log(a);let r=this.entity;0<r.indexOf("/")&&(r=r.substring(0,r.lastIndexOf("/")));let i={};this.copy(this.headers,i),i["Content-Type"]="multipart/mixed; boundary="+t;let o=(e,t,a,n)=>{let s;0<this.batchServiceData.length&&(s=this.batchServiceData[0].promise.errorCallback),s?s(e,t,a,n,!1):this.handleError(e),this.batchServiceData=[]};$httpLegacy({method:"POST",url:_self.removeSlash((window.hostApp||"")+r+"/$batch"),data:a,headers:i,offlineMode:_self.isOfflineMode()}).success(function(t,a,n,s){let r=this.parseBatchResult(t);for(let e=0;e<r.length;e++)if(400<=r[e].status)return void o(r[e].data,r[e].status);for(let e=0;e<this.batchServiceData.length;e++)this.batchServiceData[e].result=r[e]&&null!=r[e].data?r[e].data:this.batchServiceData[e].data;if(e)e();else{let e;0<this.batchServiceData.length&&(e=this.batchServiceData[0].promise.successCallback),e&&(this.batchServiceData.splice(0,1),e(r[0].data,r[0].status,n,s,!1))}}.bind(this)).error(o)})},this.parseBatchResult=function(e){let t,a=[],n=e.split("\n");for(let r,i=0;i<n.length;i++){if(r=n[i],r.startsWith("{")&&a.push({status:t,data:JSON.parse(r)}),r.startsWith("HTTP/1.1")){var s=HTTP_STATUS.exec(r);t=s[1]}r.startsWith("HTTP/1.1")&&0<r.indexOf("No Content")&&a.push({status:t,data:null})}return a},this.uuidv4=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=0|16*Math.random(),a="x"==e?t:8|3&t;return a.toString(16)})},this.getService=function(verb,object){_self=this;var event=eval("this.on"+verb);return"GET"===verb&&(event||this.isLocalData()||this.isNavigatorOffline())?function(e){var t={verb:verb,properties:e,successCallback:null,errorCallback:null,success:function(e){return this.successCallback=e,this},error:function(e){return this.errorCallback=e,this}};return $timeout(function(){var e,t={currentData:this.properties.rawData||this.properties.data||_self.active,filter:this.properties.filter||"",datasource:_self,selectedIndex:_self.cursor,index:_self.cursor,selectedRow:_self.active,item:_self.active,selectedKeys:_self.getKeyValues(_self.active,!0),selectedKey:_self.getFirstKeyValue(_self.active,!0),callback:this.successCallback};if(event)e=_self.$scope.$eval(event,t),e instanceof Promise?e.then(function(e){e&&"[object Array]"!==Object.prototype.toString.call(e)&&(e=[e]),_self.$scope.safeApply(function(){this.successCallback(e)}.bind(this))}.bind(this)).catch(function(e){_self.handleError(e)}.bind(this)):e&&this.successCallback(e);else{let e=_self.getPouchDB();if("GET"==this.verb&&!this.properties.filter)e.allDocs({include_docs:!0,attachments:!0}).catch(this.errorCallback).then(function(e){for(var t=[],a=0;a<e.rows.length;a++)t.push(e.rows[a].doc);e.rows=t,this.successCallback&&this.successCallback(e)}.bind(this));else if("GET"==this.verb){var a=peg$parse(this.properties.filter);e.find({selector:a}).catch(this.errorCallback).then(function(e){e.rows=e.docs,e.total_rows=e.rows.length,this.successCallback&&this.successCallback(e)}.bind(this))}}}.bind(t),0),t}:(this.hasOfflineSupport()&&object&&this.operationPouchDB(verb,object),this.batchEnabled(object)&&"GET"!=verb?this.getBatchService(verb):$httpLegacy)},this.isBusy=function(){return this.busy},this.isLoaded=function(){return this.loaded},this.toString=function(){return"[Datasource]"},this.handleAfterCallBack=function(e,t){if(e)try{var a={currentData:this.data,datasource:this,selectedIndex:this.cursor,index:this.cursor,selectedRow:this.active,item:this.active,selectedKeys:this.getKeyValues(this.active,!0),selectedKey:this.getFirstKeyValue(_self.active,!0),callback:t};this.$scope.$eval(e,a)}catch(t){this.handleError(t)}},this.handleBeforeCallBack=async function(e,t){var a=!0;let n=DatasetManagerUtil.onMatchRegex(/cronapi.server/g,".run(",".toPromise().disableNotification()");if(e)try{var s={currentData:this.data,datasource:this,selectedIndex:this.cursor,index:this.cursor,selectedRow:this.active,item:this.active,selectedKeys:this.getKeyValues(this.active,!0),selectedKey:this.getFirstKeyValue(_self.active,!0),callback:t};await this.$scope.$eval(n(e),s)}catch(t){a=!1,this.handleError(t)}return a},this.handleError=function(e){if(console.log(e),e instanceof XMLDocument){var t=e.getElementsByTagName("message")[0].textContent;e=t,console.log(e)}var a="";if(e)if("[object String]"===Object.prototype.toString.call(e))a=e;else{var t=e.msg||e.desc||e.message||e.error||e.responseText;this.isOData()&&e.error.message&&e.error.message.value&&(t=e.error.message.value),t&&(a=t)}a||(a=this.defaultNotSpecifiedErrorMessage);if(result=/<h1>(.*)<\/h1>/gmi.exec(a),result&&2<=result.length&&(a=result[1]),this.errorMessage=a,!(this.onError&&""!==this.onError))this.onError=function(e){Notification.error(e)};else if("string"==typeof this.onError)try{var n={currentData:this.active,filter:"",error:a,datasource:this,selectedIndex:this.cursor,index:this.cursor,selectedRow:this.active,item:this.active,selectedKeys:this.getKeyValues(this.active,!0),selectedKey:this.getFirstKeyValue(this.active,!0),callback:this.successCallback},s=this.$scope.$eval(this.onError,n);"function"==typeof s&&(this.onError=s)}catch(t){isValid=!1,Notification.error(t)}"function"==typeof this.onError&&this.onError.call(this,a)},this.observers&&0<this.observers.length&&$rootScope.$watch(function(){return this.active}.bind(this),function(e){e&&this.notifyObservers(e)}.bind(this),!0)},this.setFile=function(e,t,a){e&&"pattern"===e.$error||e&&toBase64(e,function(e){this.$apply=function(e){t[a]=e,scope.$apply(t)}.bind(scope),this.$apply(e)})},this.downloadFile=function(e,t){if(void 0!==t){for(var a=(window.hostApp||"")+this.entity+"/download/"+e,n=0;n<t.length;n++)a+="/"+t[n];var s={url:a,method:"GET",responseType:"arraybuffer"};$http(s).then(function(e){var t=new Blob([e.data],{type:"application/*"});$window.open(URL.createObjectURL(t))})}},this.openImage=function(e){if(-1==e.indexOf("https://")&&-1==e.indexOf("http://")){var t=$window.open("","_blank","height=300,width=400");t.document.write("<img src=\""+("data:image/png;base64,"+e)+"\"/>")}else $window.open(e,"_blank","height=300,width=400")},this.byteSize=function(e){function t(e,t){return-1!==t.indexOf(e,t.length-e.length)}function a(e){return t("==",e)?2:t("=",e)?1:0}return angular.isString(e)?function(e){return e.toString().replace(/\B(?=(\d{3})+(?!\d))/g," ")+" bytes"}(function(e){return 3*(e.length/4)-a(e)}(e)):""},this.insert=async function(obj,onSuccess,onError,forceSave){(await this.handleBeforeCallBack(this.onBeforeCreate))&&((this.dependentLazyPost||this.batchPost)&&!forceSave?(obj.__status="inserted",this.dependentLazyPost&&(obj.__parentId=eval(this.dependentLazyPost).active.__$id),this.hasMemoryData=!0,this.notifyPendingChanges(this.hasMemoryData),onSuccess&&onSuccess(obj)):service.save(obj).$promise.error(onError).then(onSuccess))},this.addDependentDatasource=function(dts){this.children||(this.children=[]),this.children.push(dts),this.dependentLazyPost?eval(this.dependentLazyPost).addDependentDatasource(dts):(!this.dependentData&&(this.dependentData=[]),this.dependentData.push(dts))},this.getParentDatasource=function(){return this.dependentLazyPost?eval(this.dependentLazyPost).getParentDatasource():this},this.updateObjectAtIndex=function(e,t,a){t=t||this.data,this.copy(e,t[a]),e.__$id=t[a].__$id,delete t[a].__status,delete t[a].__original,delete t[a].__originalIdx,delete t[a].__odatafiles,delete t[a].__$masterExpression},this.cleanDependentBuffer=function(){var e=[];$(this.data).each(function(){this.__status?"updated"==this.__status&&e.push(this.__original):e.push(this)}),this.data.length=0;for(var t=0;t<e.length;t++)delete e[t].__status,delete e[t].__original,delete e[t].__originalIdx,this.data.push(e[t]);if(this.postDeleteData)for(var t=0;t<this.postDeleteData.length;t++)delete this.postDeleteData[t].__status,delete this.postDeleteData[t].__original,delete this.postDeleteData[t].__originalIdx,this.data.push(this.postDeleteData[t]);this.data&&0<this.data.length?(this.cursor=0,this.active=this.data[0]):(this.cursor=-1,this.active=null),this.busy=!1,this.editing=!1,this.inserting=!1,this.postDeleteData=null,this.hasMemoryData=!1,this.notifyPendingChanges(this.hasMemoryData),this.events.read&&this.callDataSourceEvents("read",this.data),this.events.afterchanges&&this.callDataSourceEvents("afterchanges",this.data)},this.cancelBatchData=function(e){this.dependentData&&$(reverseArr(this.dependentData)).each(function(){this.cleanDependentBuffer()}),this.cleanDependentBuffer(),this.batchServiceData=[],e&&e()},this.flushDependencies=function(e,t){var a=[];if(this.dependentData){var n=function(){reduce(this.dependentData,function(e,n){a.push(e.storeDependentBuffer(function(){n()},void 0,t))}.bind(this),function(){e&&e(a)}.bind(this))}.bind(this);reduce(reverseArr(this.dependentData),function(e,a){e.storeDependentBuffer(function(){a()},!0,t)}.bind(this),function(){n()}.bind(this))}else e&&e(a)},this.postBatchData=function(e,t){let a=!t;t||(this.batchServiceData=[]);let n=()=>{a?(a=!1,this.performBatchPost(function(){this.postBatchData(e,!0)}.bind(this))):e&&e()};this.postingBatch=!0;var s=[],r=function(){this.storeDependentBuffer(function(){s.push(this.storeDependentBuffer(function(){reduce(this.dependentData,function(e,t){s.push(e.storeDependentBuffer(function(){t()},!1,a))}.bind(this),function(){this.postingBatch=!1;for(var e=0;e<s.length;e++)s[e]();n&&n()}.bind(this))}.bind(this),!1,a))}.bind(this),!0,a)}.bind(this);reduce(reverseArr(this.dependentData),function(e,t){e.storeDependentBuffer(function(){t()},!0,a)}.bind(this),function(){r()}.bind(this))};var reduce=function(e,t,a){if(!e||0==e.length)a();else{var n=e.reduce(function(e,a){return e.then(function(){return new Promise(function(e){t(a,e)})})},Promise.resolve());n.then(function(){a()})}};this.storeDependentBuffer=function(callback,onlyRemove,batchMode){var _self=this,dependentDS=eval(_self.dependentLazyPost);this.batchPost&&(dependentDS=this);var array=[];if(!onlyRemove&&(array=array.concat(_self.data),_self.memoryData))for(key in _self.memoryData)if(_self.memoryData.hasOwnProperty(key)){for(var mem=_self.memoryData[key],x=0;x<mem.data.length;x++)mem.data[x].__fromMemory=!0;array=array.concat(mem.data)}_self.postDeleteData&&(array=array.concat(_self.postDeleteData));var func=function(e,t){if(e.__status){if(!_self.parameters&&(_self.dependentLazyPostField&&(e[_self.dependentLazyPostField]=dependentDS.active),-1<_self.entity.indexOf("//"))){var a=dependentDS.getKeyValues(dependentDS.active),n="";for(var s in a)a.hasOwnProperty(s)&&(n+="/"+a[s]);n+="/",_self.entity=_self.entity.replace("//",n)}if(_self.parameters){var r=_self.getParametersMap(e.__parentId?e.__parentId:null);for(var s in r)r.hasOwnProperty(s)&&updateObjectValue(e,s,r[s]);let t=_self.getParametersBatchExpression(e.__parentId?e.__parentId:null);e.__$masterExpression=t}"inserted"==e.__status?function(e){var a;batchMode||(a=_self.processODataFiles(e)),_self.insert(e,function(n,s,r){if(r)return void t();var i=e.__sender,o=_self.getIndexOfListTempBuffer(e,array),d=!1,c=n;0<=o&&(c=array[o],d=array[o].__fromMemory,_self.updateObjectAtIndex(n,array,o)),_self.events.create&&!d&&(i&&(n=array[o],n.__sender=i),_self.callDataSourceEvents("create",n),delete n.__sender),a&&0<a.length?_self.sendODataFiles(a,n,function(e){_self.copy(e.data,c)}.bind(this),function(){t()}):t()},function(){t()},!0)}(e):"updated"==e.__status?function(e){var a;batchMode||(a=_self.processODataFiles(e)),_self.update(e,function(n,s,r){if(r)return void t();var i=e.__sender,o=_self.getIndexOfListTempBuffer(e,array),d=!1,c=n;0<=o&&(c=array[o],d=array[o].__fromMemory,_self.updateObjectAtIndex(n,array,o),n=array[o]),_self.events.update&&!d&&(i&&(n.__sender=i),_self.callDataSourceEvents("update",n),delete n.__sender),a&&0<a.length?_self.sendODataFiles(a,n,function(e){_self.copy(e.data,c)}.bind(this),function(){t()}):t()},function(){t()},!0)}(e):"deleted"==e.__status&&onlyRemove?function(e){_self.remove(e,function(a,n,s){if(s)return void t();if(_self.events.delete){var r={};_self.copy(e,r),delete r.__status,delete r.__original,delete r.__originalIdx,_self.callDataSourceEvents("delete",r)}t()},!0,null,function(){t()})}(e):t()}else t()},resetFunc=function(){onlyRemove||(this.busy=!1,this.editing=!1,this.inserting=!1,this.hasMemoryData=!1,this.memoryData=null,!batchMode&&this.notifyPendingChanges(this.hasMemoryData),this.events.afterchanges&&!batchMode&&this.callDataSourceEvents("afterchanges",this.data))}.bind(this);return reduce(array,func,function(){callback&&callback(),batchMode||(this.postDeleteData=null)}.bind(this)),resetFunc},this.getIndexOfListTempBuffer=function(e,t){t=t||this.data;for(var a=0;a<t.length;a++)if(t[a].__$id&&e.__$id&&t[a].__$id==e.__$id)return a;return-1},this.getObjectAsString=function(e,t){return((null==t||null==t)&&(t=!0),this.isOData())?window.objToOData(e,t):null==e?"":"number"==typeof e?e+"@@number":e instanceof Date?e.toISOString()+"@@datetime":"boolean"==typeof e?e+"@@boolean":e+""},this.update=async function(e,t,a,n){(await this.handleBeforeCallBack(this.onBeforeUpdate))&&((this.dependentLazyPost||this.batchPost)&&!n?t&&t(e):service.update(this.getEditionURL(e,n),e).$promise.error(a).then(t))},this.validateFields=function(e,t){var a=$(e);if(0<a.length&&"checkbox"!==a.get(0).type){var n=$("label[for=\""+a.get(0).id+"\"]"),s=a.get(0).id;return 0<n.length&&(s=n.text(),s&&(s=s.replaceAll("\n","").trim())),t&&(Notification.error(t.replace("{0}",s)),$(a.get(0)).addClass("ng-touched").removeClass("ng-untouched"),a.get(0).focus&&a.get(0).focus()),!1}return!0},this.getPatterns=function(){return $("input[ng-model*=\""+this.name+".\"]").filter(function(){return $(this).attr("pattern")})},this.missingRequiredField=function(e){if(0<this.getPatterns().length)return!1;if(this.checkRequired){var t=this.validateFields("[required][ng-model*=\""+this.name+".\"].ng-invalid-required",e?"":this.translate.instant("FieldIsRequired"));return t=t&&this.validateFields("[required][ng-model*=\""+this.name+".\"].ng-empty",e?"":this.translate.instant("FieldIsRequired")),t=t&&this.validateFields("[ng-model*=\""+this.name+".\"].ng-invalid",e?"":this.translate.instant("FieldIsInvalid")),!t}return!1},this.hasInvalidField=function(){return!(0<this.getPatterns().length)&&!!this.checkRequired&&0<$("input[ng-model*=\""+this.name+".\"]:invalid").not("input[type=checkbox]").not(".ng-empty").length},this.postSilent=function(e,t){this.post(e,t,!0)},this.updateActive=function(e){for(var t in e)e.hasOwnProperty(t)&&"__status"!=t&&(this.active[t]=e[t])},this.processODataFiles=function(e){var t=[];for(var a in e)if(-1<a.indexOf("__odataFile_")){var n={field:a.replace("__odataFile_",""),value:e[a]};t.push(n),e[n.field]=void 0,delete e[a]}return t},this.sendODataFiles=function(e,t,a,n){if(t&&e&&0<e.length){var s=this.entity,r=this.getKeyValues(t),i=["("],o=0;for(var d in r)0<o&&i.push(","),i.push(d),i.push("="),i.push(window.objToOData(r[d])),o++;i.push(")"),s+=i.join("");var c=JSON.parse(localStorage.getItem("_u"));reduce(e,function(e,n){let r=(window.hostApp||"")+s+"/"+e.field+"/$value";if(!_self.isOfflineMode()){var i=e.value,o=new XMLHttpRequest;o.open("PUT",r),o.setRequestHeader("X-Requested-With","XMLHttpRequest"),o.setRequestHeader("X-File-Name",i.name),o.setRequestHeader("Content-Type",(i.type||"application/octet-stream")+";charset=UTF-8"),window.isUsingCookie()||o.setRequestHeader("X-AUTH-TOKEN",c?.token),o.onreadystatechange=function(){if(4===o.readyState&&500===o.status){var r=new DOMParser,i=r.parseFromString(o.response,"text/xml");this.handleError(i)}4===o.readyState&&201===o.status&&service.call(s,"GET",{},!1).$promise.error(function(){Notification.error("Error send file")}).then(function(s){a?a({field:e.field,data:s}):t[e.field]=s[e.field],n()})}.bind(this),o.send(i)}else{let s={method:"PUT",data:e.value,url:r,headers:_self.headers};SyncService.toQueue(s),cronapi.internal.fileToBase64(e.value,s=>{t[e.field]=s,a&&a({field:e.field,data:t}),n()})}}.bind(this),function(){n&&n()}.bind(this))}else n&&n()},this.getFieldSchema=function(e){var t;if(this.schema)for(var a=0;a<this.schema.length;a++)if(this.schema[a].name==e){t=this.schema[a];break}return t},this.asyncPost=function(e,t,a){setTimeout(function(){this.post(e,t,a)}.bind(this),100)},this.copyWithoutAngularObj=function(){var e={};for(var t in this)this.hasOwnProperty(t)&&!t.startsWith("$")&&(e[t]=this[t]);return e},this.post=function(onSuccess,onError,silent,keepBuffer){!silent&&this.missingRequiredField()||!silent&&this.hasInvalidField()||(!keepBuffer&&(this.batchServiceData=[]),this.lastAction="post",this.busy=!0,this.inserting?this.insert(this.active,function(e,t,a){if(a&&this.dependentData&&!this.dependentLazyPost&&!this.batchPost)return void this.flushDependencies(()=>{this.performBatchPost(()=>{this.post(onSuccess,onError,silent,!0)})},!0);this.active.__sender&&(e.__sender=this.active.__sender),this.active.__$id&&(e.__$id=this.active.__$id);var n=function(a){if(this.active=e,this.handleAfterCallBack(this.onAfterCreate),this.onBackNomalState(),onSuccess&&onSuccess(this.active),this.events.create&&t&&(this.callDataSourceEvents("create",this.active),delete _self.active.__sender),this.events.memorycreate&&!t&&this.callDataSourceEvents("memorycreate",this.active),a)for(let e=0;e<a.length;e++)a[e]()}.bind(this),s=function(){this.data.push(e),!this.dependentData||this.dependentLazyPost||this.batchPost?n():this.flushDependencies(n,!1)}.bind(this);if(!t)s();else{var r=this.processODataFiles(this.active);r&&0<r.length?this.sendODataFiles(r,e,function(t){this.copy(t.data,e)}.bind(this),function(){s()}.bind(this)):s()}}.bind(this),onError):this.editing?this.update(this.active,function(obj,hotData,batchPostponed){if(batchPostponed&&this.dependentData&&!this.dependentLazyPost&&!this.batchPost)return void this.flushDependencies(()=>{this.performBatchPost(()=>{this.post(onSuccess,onError,silent,!0)})},batchPostponed);var odataFiles;hotData&&(odataFiles=this.processODataFiles(this.active));var foundRow,keyObj=this.getKeyValues(this.lastActive);this.data.forEach(function(currentRow){var found;if(this.lastActive.__$id&&currentRow.__$id)found=this.lastActive.__$id==currentRow.__$id;else{var dataKeys=this.getKeyValues(currentRow);for(var key in keyObj)if(dataKeys[key]&&dataKeys[key]===keyObj[key])found=!0;else{found=!1;break}}if(found){foundRow=currentRow;var lastActive={};this.copy(this.lastActive,lastActive),this.copy(obj,currentRow),this.lastActive&&this.lastActive.__sender&&(currentRow.__sender=this.lastActive.__sender),this.active=currentRow,(this.dependentLazyPost||this.batchPost)&&!currentRow.__status&&(currentRow.__status="updated",currentRow.__original=lastActive,this.hasMemoryData=!0,this.dependentLazyPost&&(currentRow.__parentId=eval(this.dependentLazyPost).active.__$id)),this.notifyPendingChanges(this.hasMemoryData),this.events.update&&hotData&&(this.callDataSourceEvents("update",this.active),delete this.active.__sender),this.events.memoryupdate&&!hotData&&this.callDataSourceEvents("memoryupdate",this.active)}}.bind(this));var back=function(e){if(foundRow&&this.handleAfterCallBack(this.onAfterUpdate),this.onBackNomalState(),onSuccess&&onSuccess(this.active),e)for(let t=0;t<e.length;t++)e[t]()}.bind(this),func=function(e){hotData?odataFiles&&0<odataFiles.length?this.sendODataFiles(odataFiles,foundRow,function(e){this.copy(e.data,foundRow)}.bind(this),function(){this.events.update&&hotData&&this.callDataSourceEvents("update",foundRow),back(e)}.bind(this)):back(e):back(e)}.bind(this);!this.dependentData||this.dependentLazyPost||this.batchPost?func():this.flushDependencies(func)}.bind(this),onError):0==this.data.length?this.startInserting(this.active,function(){this.post(onSuccess,onError,silent)}.bind(this)):this.startEditing(null,function(){this.post(onSuccess,onError,silent)}.bind(this)))},this.notifyPendingChanges=function(value){console.log("notifyPendingChanges : "+value),this.events.pendingchanges&&this.callDataSourceEvents("pendingchanges",value),this.dependentLazyPost&&eval(this.dependentLazyPost).notifyPendingChanges(value)},this.notifyPendingChanges=function(value){console.log("notifyPendingChanges : "+value),this.events.pendingchanges&&this.callDataSourceEvents("pendingchanges",value),this.dependentLazyPost&&eval(this.dependentLazyPost).notifyPendingChanges(value)},this.getConditionParams=function(){if(this.condition)try{var e=this.$interpolate(this.conditionExpression)(this.$scope),t=JSON.parse(e);if("object"==typeof t){if(t.params){let e;for(var a,n=0;n<t.params.length;n++)a=t.params[n].fieldValue,2<=a.length&&"'"==a.charAt(0)&&"'"==a.charAt(a.length-1)&&(a=a.substring(1,a.length-1)),""!==a&&void 0!==a&&null!==a&&(e?e+="&":e="",e+=t.params[n].fieldName+"="+encodeURIComponent(a));return e}}}catch(t){console.log(t)}},this.getDeletionURL=function(e,t){var a=this.getKeyValues(e.__original?e.__original:e,t),n="";this.isOData()&&(n="(");var s=0;for(var r in a)a.hasOwnProperty(r)&&(this.isOData()?(0<s&&(n+=","),n+=r+"="+this.getObjectAsString(a[r])):n+="/"+a[r],s++);this.isOData()&&(n+=")",n=encodeURI(n));var i=this.entity;this.entity.endsWith("/")&&(i=i.substring(0,i.length-1)),i+=n;let o=this.getConditionParams();return o&&(i=i+"?"+o),i},this.getEditionURL=function(e,t){var a=this.getKeyValues(e.__original?e.__original:e,t),n="";for(var s in this.isOData()&&(n="("),a)a.hasOwnProperty(s)&&(n+=this.isOData()?("("==n?"":",")+s+"="+this.getObjectAsString(a[s]):"/"+a[s]);this.isOData()&&(n+=")",n=encodeURI(n));var r=this.entity;this.entity.endsWith("/")&&(r=r.substring(0,r.length-1)),r+=n;let i=this.getConditionParams();return i&&(r=r+"?"+i),r},this.refreshActive=function(e,t){if(this.active&&"inserted"!=this.active.__status){var a=this.getEditionURL(this.active),n=this.getKeyValues(this.active);this.$promise=this.getService("GET")({method:"GET",url:a,headers:this.headers}).success(function(a){var s=null;this.isOData()?(s=a.d,this.normalizeObject(s)):a&&0<a.length&&(s=a[0]);var r=-1,o=0;this.data.forEach(function(e){var t=!1,a=0,i=0;for(var d in n)i++,e[d]&&e[d]===n[d]&&a++;a==i&&(t=!0),t&&(r=o,s&&(this.copy(s,e),this.copy(s,this.active))),o++}.bind(this)),-1==r?t&&t():(this.events.update&&this.callDataSourceEvents("update",this.active),e&&e(this.active))}.bind(this)).error(function(){t&&t()}.bind(this))}else e&&e(this.active)},this.buildURL=function(e,t){var a=this.getKeyValues(this.active,!1,t);"object"!=typeof e&&(e=[e]);var n="",s=0;for(var r in a){if(a.hasOwnProperty(r)){var i;i=Array.isArray(e)?e[s]:e[r],0<s&&(n+=" and "),n+=r+" eq "+this.getObjectAsString(i)}s++}return n},this.findObj=function(e,t,a,n,s){let r=s||deepCopy(this.keys),i=function(t){for(let a=0;a<r.length;a++)if(objectsAreEqual(e[a],t[r[a]]))return t}.bind(this),o=this.data.filter(i);if(o&&0<o.length)return void(a&&a(o));var d,c=this.buildURL(e,s);d={params:{$filter:c}},(null==c||0==c.length)&&(d={}),this.fetch(d,{success:function(e){if(a){let t=e.filter(i);a(t)}}.bind(this),error:function(){n&&n()}},void 0,{lookup:!0})},this.getColumn=function(e){var t=[];return $.each(this.data,function(a,n){t.push(n[e])}),t},this.onBackNomalState=function(){this.$scope.safeApply(function(){this.busy=!1,this.editing=!1,this.inserting=!1;let e=this.dependentData&&this.dependentData.filter(e=>e.inserting||e.editing);e&&e.forEach(e=>e.cancel()),this.noticeStatusChange()}.bind(this))},this.cancel=function(){this.inserting&&(0<=this.cursor?this.active=this.data[this.cursor]:this.active={}),this.editing&&(this.active=this.lastActive),this.onBackNomalState(),this.lastAction="cancel",this.dependentData&&$(this.dependentData).each(function(){this.cleanDependentBuffer()}),this.batchServiceData=[]},this.removeODataFields=function(e){for(var t in e)e.hasOwnProperty(t)&&e[t]&&e[t].__deferred&&delete e[t];return e},this.retrieveDefaultValues=function(e,t){if(this.isEventData()||this.isLocalData()||this.isOfflineMode())this.$scope.safeApply(function(){this.active={},(this.isLocalData()||this.isOfflineMode())&&(this.active[this.keys[0]]=this.uuidv4()),this.updateWithParams(),t&&t()}.bind(this));else if(e)this.active=e||{},this.updateWithParams(),t&&t();else if(0<=this.entity.indexOf("cronapi")||this.isOData()){var a=this.entity;a+=this.entity.endsWith("/")?"__new__":"/__new__",this.$promise=$httpLegacy({method:"GET",url:this.removeSlash((window.hostApp||"")+a),headers:this.headers}).success(function(e){this.isOData()?(this.active=this.removeODataFields(e.d),this.normalizeData(this.active)):this.active=e,this.updateWithParams(),t&&t()}.bind(this)).error(function(){this.active={},this.updateWithParams(),t&&t()}.bind(this))}else this.active={},this.updateWithParams(),t&&t()};var updateObjectValue=function(e,t,a){for(var n,s=t.split("."),r=0;r<s.length;r++)n=s[r],r==s.length-1?e[n]=a:((void 0===e[n]||null==e[n])&&(e[n]={}),e=e[n])};this.updateWithParams=function(){if(this.parameters){var e=this.getParametersMap();for(var t in e)e.hasOwnProperty(t)&&updateObjectValue(this.active,t,e[t])}},this.resetFieldsStatus=function(){var e=setInterval(function(){$("input[ng-model*=\""+this.name+".\"]").is(":visible")?($("input[ng-model*=\""+this.name+".\"]:invalid:empty").removeClass("ng-invalid ng-invalid-required"),clearInterval(e)):$("input[ng-model*=\""+this.name+".\"].cronMultiSelect")&&clearInterval(e)},100)},this.noticeStatusChange=function(){this.changeTitle(),this.handleBeforeCallBack(this.onChangeStatus)},this.changeTitle=function(){if($("#starter").length&&$("#starter").attr("primary-datasource")===this.name){var e=this.translate.instant($rootScope.viewTitleOnly),t=$rootScope.systemName&&$rootScope.systemName.length?" - "+$rootScope.systemName:"";this.inserting?e+=" - "+this.translate.instant("Inserting"):this.editing&&(e+=" - "+this.translate.instant("Editing")),$("h1.title:first").text(e),window.document.title=e+t}},this.startInserting=function(e,t){this.retrieveDefaultValues(e,function(){if(this.active.__$id||(this.active.__$id=uuid()),this.children&&this.children.length){let e=this.getKeyValues(this.active);for(let t in e)e.hasOwnProperty(t)&&(null==e[t]||null==e[t])&&"_objectKey"==t&&(this.active[t]="$autogenerated$"+this.uuidv4())}this.inserting=!0,this.onStartInserting&&this.onStartInserting(),t&&t(this.active),this.events.creating&&this.callDataSourceEvents("creating",this.active),this.resetFieldsStatus(),this.noticeStatusChange()}.bind(this))},this.operationPouchDB=function(e,t,a){if(!SyncService.synchronizing&&(this.hasOfflineSupport()||this.isLocalData())&&e&&"GET"!==e){let n=this.getPouchDB();"DELETE"==e?n.get(t._objectKey).then(function(e){return n.remove(e)}.bind(this)).then(a).catch(function(e){console.error(e)}):this.$scope.cronapi.internal.updatePouchDB(n,[t],a)}},this.getPouchDB=function(){return cronapi.internal.getPouchDB(_self.localDBName)},this.isNavigatorOffline=function(){return!navigator.onLine},this.hasOfflineSupport=function(){return this.offline},this.isOfflineMode=function(){return this.isNavigatorOffline()&&this.hasOfflineSupport()},this.startEditing=function(e,t){if(e)this.active=this.copy(e),this.lastActive=e;else{if(0==this.data.length)return void this.startInserting(null,t);this.lastActive=this.active,this.active=this.copy(this.active)}this.editing=!0,t&&t(this.active),this.events.editing&&this.callDataSourceEvents("updating",this.active),this.resetFieldsStatus(),this.noticeStatusChange()},this.removeSilent=function(e,t,a){this.remove(e,null,!1,t,a,!0)},this.remove=function(e,t,a,n,s,r){this.busy=!0;var i=async function(e,t){e||(e=this.active);var r=this.getKeyValues(e,a);t=t||function(t,a,s){if(!s){for(var o=0;o<this.data.length;o++){var d;if(e.__$id&&this.data[o].__$id)d=this.data[o].__$id==e.__$id;else{var c=this.getKeyValues(this.data[o]);for(var l in r)if(r.hasOwnProperty(l))if(c[l]&&c[l]===r[l])d=!0;else{d=!1;break}}if(d){if(this.dependentLazyPost||this.batchPost){var u={};this.copy(this.data[o],u),u.__status="deleted",u.__originalIdx=o,this.events.memorydelete&&this.callDataSourceEvents("memorydelete",u),"inserted"!=this.data[o].__status&&(!this.postDeleteData&&(this.postDeleteData=[]),this.postDeleteData.push(u),this.hasMemoryData=!0,this.notifyPendingChanges(this.hasMemoryData))}this.data.splice(o,1);var p=o-1;0>p&&(p=0),p>this.data.length-1&&(p=this.data.length),this.data[p]?(this.active=this.data[p],this.cursor=p):(this.active=null,this.cursor=-1),this.onBackNomalState();break}}this.handleAfterCallBack(this.onAfterDelete),n&&n(e),this.events.delete&&a&&this.callDataSourceEvents("delete",e)}}.bind(this),(await this.handleBeforeCallBack(this.onBeforeDelete))&&((this.dependentLazyPost||this.batchPost)&&!a?t():service.remove(this.getDeletionURL(e,a),e).$promise.error(s).then(t))}.bind(this);if(!a&&!r&&this.deleteMessage&&0<this.deleteMessage.length){let a={title:this.translate.instant("yes"),value:function(){i(e,t)}},n={title:this.translate.instant("no"),primaryValue:"true",value:()=>{this.filter()}};window.cronapi.notification.confirmDialogAlert("warning",this.translate.instant("Users.view.Confirmacao"),this.deleteMessage,[n,a])}else i(e,t)},this.getKeyValues=function(rowData,forceOriginalKeys,useKeys){for(var keys=useKeys||this.keys,keyValues={},i=0;i<keys.length;i++){var key=keys[i],rowKey=null;try{rowKey=Array.isArray(rowData)?eval("rowData[0]."+key):eval("rowData."+key)}catch(t){}keyValues[key]=rowKey}return keyValues}.bind(this),this.getFirstKeyValue=function(rowData,forceOriginalKeys){for(var keys=this.keys,keyValues={},i=0;i<this.keys.length;i++){var key=this.keys[i],rowKey=null;try{rowKey=eval("rowData."+key)}catch(t){}return rowKey}}.bind(this),this.objectIsEquals=function(e,t){var a=this.getKeyValues(e),n=this.getKeyValues(t);for(var s in a)if(a.hasOwnProperty(s)){if(!n.hasOwnProperty(s))return!1;if(a[s]!==n[s])return!1}return!0},this.hasNext=function(){return this.data&&this.cursor<this.data.length-1},this.hasPrevious=function(){return this.data&&0<this.cursor},this.order=function(e){this._savedProps.order=e},this.getActiveValues=function(){return this.active&&!this._activeValues&&$rootScope.$watch(function(){return this.active}.bind(this),function(){this._activeValues=this.getRowValues(this.active)}.bind(this),!0),this._activeValues},this.__defineGetter__("activeValues",function(){return _self.getActiveValues()}),this.getRowValues=function(e){var t=[];for(var a in e)e.hasOwnProperty(a)&&t.push(e[a]);return t},this.next=function(){return this.hasNext()||this.nextPage(),this.active=this.copy(this.data[++this.cursor],{}),this.active},this.nextPage=function(e){var t=(window.hostApp||"")+this.entity;return this.hasNextPage()?void(this.offset=1==this.apiVersion||-1==t.indexOf("/cronapi/")?parseInt(this.offset)+parseInt(this.rowsPerPage):parseInt(this.offset)+1,this._savedProps&&this._savedProps.params&&delete this._savedProps.params.$skip,this.fetch(this._savedProps,{success:function(a){(!a||a.length<parseInt(this.rowsPerPage))&&(1==this.apiVersion||-1==t.indexOf("/cronapi/"))&&(this.offset=parseInt(this.offset)-this.data.length),e&&e()},canceled:function(){e&&e()},error:function(){e&&e()}},!0)):void(e&&e())},this.prevPage=function(){this.append||this.preppend||(this.offset=parseInt(this.offset)-this.data.length,this._savedProps&&this._savedProps.params&&delete this._savedProps.params.$skip,0>this.offset?this.offset=0:0<=this.offset&&this.fetch(this._savedProps,{success:function(e){e&&0!==e.length||(this.offset=0)}},!0))},this.hasNextPage=function(){return this.hasMoreResults&&-1!=this.rowsPerPage},this.hasPrevPage=function(){return 0<this.offset&&!this.append&&!this.prepend},this.previous=function(){if(!this.hasPrevious())throw"Dataset Overflor Error";return this.active=this.copy(this.data[--this.cursor],{}),this.active},this.findObjInDs=function(e,t){var a=!1,n=null;if(null===e||void 0===e)return n;var s=null,r=null;let o=t=>{var n=this.data[t];for(var s in d)a=!!(e.hasOwnProperty(s)&&e[s]===n[s]);return a};if("object"==typeof e&&null!==e){var d;0<this.data.length&&(d=this.getKeyValues(this.data[0]));for(var c=0;c<this.data.length;c++)if(e.__$id&&this.data[c].__$id?(a=e.__$id==this.data[c].__$id,!a&&(a=o(c))):a=o(c),a){s=c,r=this.copy(this.data[s],{});var l=this.getKeyValues(this.data[s]),u=!0;for(var p in l)if(void 0===l[p]){u=!1;break}u||this.fetchChildren()}}else if(Array.isArray(this.keys))for(var c=0;c<this.data.length;c++)this.data[c][this.keys[0]]===e&&(s=c,r=this.copy(this.data[s],{}),a=!0);return null!==r&&(n=r,t&&(n={cursor:s,obj:r})),n},this.goTo=function(e){var t=this.findObjInDs(e,!0);return null===t?t:(this.cursor=t.cursor,this.active=t.obj,this.active)},this.getCursor=function(){return this.cursor},this.filter=function(e,t){var a=this.offset;this.offset=0,this.fetch({path:e},{beforeFill:function(){this.cleanup()},error:function(){this.offset=a},success:function(e){t&&t(e)}})},this.doSearchAll=function(e,t){this.searchTimeout=null;var a=this.offset;this.offset=0,this.fetch({params:{filter:"%"+e+"%",filterCaseInsensitive:!!t}},{beforeFill:function(){this.cleanup()},error:function(){this.offset=a}})},this.searchAll=function(e,t){this.searchTimeout&&(clearTimeout(this.searchTimeout),this.searchTimeout=null),this.searchTimeout=setTimeout(function(){this.doSearchAll(e,t)}.bind(this),500)},this.doSearch=function(e,t){this.searchTimeout=null;var a=this.offset;this.offset=0;var n;this.isOData()?(n={params:{$filter:e}},(null==e||0==e.length)&&(n={})):n={params:{filter:e,filterCaseInsensitive:!!t}},this.fetch(n,{beforeFill:function(){this.cleanup()},error:function(){this.offset=a}})},this.search=function(e,t){this.searchTimeout&&(clearTimeout(this.searchTimeout),this.searchTimeout=null),this.caseInsensitive=t,this.terms=e,this.searchTimeout=setTimeout(function(){this.doSearch(e,t)}.bind(this),500)},this.refresh=function(e,t,a){this.cleanup(),void 0===a&&(a=0),e.length>=a&&this.filter(t+"/"+e)},this.cleanup=function(e){e||(e={}),this.offset=0,this.rowsCount=-1,this.data.length=0,e.ignoreAtive||(this.cursor=-1,this.active={}),this.hasMoreResults=!1},this.current=function(){return this.active||this.data[0]},this.getLink=function(e){if(this.links)for(var t=0;t<this.links.length;t++)if(this.links[t].rel==e)return this.links[t].href},this.isOData=function(){return 0<this.entity.indexOf("odata")},this.isEventData=function(){return void 0!==this.onGET&&null!==this.onGET&&""!==this.onGET},this.isLocalData=function(){return 0==this.entity.indexOf("local://")},this.normalizeValue=function(e,t,a){return(null==t||null==t)&&(t=!1),window.oDataToObj(e,t,a)},this.normalizeObject=function(e){for(var t in e)if(e.hasOwnProperty(t)){var a=e[t];if(a)if("object"==typeof a)this.normalizeObject(a);else{let n=this.getFieldFromSchema(t);e[t]=this.normalizeValue(a,void 0,n)}}},this.normalizeData=function(e){if(e){delete e.__metadata;for(var t=0;t<e.length;t++)this.normalizeObject(e[t])}return e},this.getAllData=function(){var e=[];if(e=e.concat(this.data),this.memoryData)for(key in this.memoryData)if(this.memoryData.hasOwnProperty(key)){var t=this.memoryData[key];t.data&&(e=e.concat(t.data))}return this.postDeleteData&&(e=e.concat(this.postDeleteData)),e},this.getParametersMap=function(parentId){var parameters,obj,mapParams,map={};if(parentId){parameters=this.parametersExpression;for(var arr=eval(this.dependentLazyPost).getAllData(),i=0;i<arr.length;i++)if(arr[i].__$id==parentId){obj=arr[i];break}mapParams=this.getParametersMap()}else parameters=this.parameters;if(parameters&&0<parameters.length)for(var parts=parameters.split(";"),i=0;i<parts.length;i++){var part=parts[i],binary=part.split("=");if(2==binary.length){var value=binary[1];if(!parentId)map[binary[0]]=binary[1]?this.normalizeValue(value,!0):null;else if(binary[1].match(DEP_PATTERN)){var g=DEP_PATTERN.exec(value);if(-1!=g[1].indexOf(".active.")){var field=g[1].replace(this.dependentLazyPost+".active.","");obj&&(map[binary[0]]=obj[field])}else map[binary[0]]=mapParams[binary[0]]}else map[binary[0]]=mapParams[binary[0]]}}return map},this.setParameters=function(e){this.parameters=e,this.fetch({params:{}})},this.getParametersBatchExpression=function(parentId){var parameters,obj,expression="";parameters=this.parametersExpression;let ds=eval(this.dependentLazyPost);if(ds){var arr=ds.getAllData();if(ds.active&&ds.active.__$id==parentId)obj=ds.active;else for(var i=0;i<arr.length;i++)if(arr[i].__$id==parentId){obj=arr[i];break}}if(parameters&&0<parameters.length)for(var parts=parameters.split(";"),i=0;i<parts.length;i++){var part=parts[i],binary=part.split("=");if(2==binary.length){var value=binary[1];if(binary[1].match(DEP_PATTERN)){var g=DEP_PATTERN.exec(value);if(-1!=g[1].indexOf(".active.")){var field=g[1].replace(this.dependentLazyPost+".active.","");obj&&(""!=expression&&(expression+=","),expression+=binary[0]+":$"+parentId+"."+field)}}}}return expression},this.removeSlash=function(e){return 0==e.indexOf("http://")?"http://"+e.substring(7).split("//").join("/"):0==e.indexOf("https://")?"https://"+e.substring(8).split("//").join("/"):e},this.setDataSourceEvents=function(e){this.events=e},this.addDataSourceEvents=function(e){for(var t in e)e.hasOwnProperty(t)&&(this.events[t]||(this.events[t]=[]),"[object Array]"!==Object.prototype.toString.call(this.events[t])&&(this.events[t]=[this.events[t]]),this.events[t].push(e[t]))},this.removeDataSourceEvents=function(e){for(var t in e)if(e.hasOwnProperty(t)){this.events[t]||(this.events[t]=[]),"[object Array]"!==Object.prototype.toString.call(this.events[t])&&(this.events[t]=[this.events[t]]);for(var a=[].concat(this.events[t]),n=0;n<a.length;n++)a[n]==e[t]&&this.events[t].splice(n,1)}},this.callDataSourceEvents=function(e){if(this.events){var t=this.events[e];if(t){"[object Array]"!==Object.prototype.toString.call(t)&&(t=[t]);for(var a=[],n=1;n<arguments.length;n++)a.push(arguments[n]);for(var s=[],n=0;n<t.length;n++)s.push(t[n]);for(var r=0;r<s.length;r++)try{s[r].apply(null,a)}catch(e){console.log("Error","Event no more exist in datasource")}}}},this.storeInMemory=function(e){this.memoryData||(this.memoryData={});var t={data:[],cursor:this.cursor,params:this.getParametersMap(),rowCount:this.getRowsCount()};t.data=deepCopy(this.data,t.data),this.memoryData[e]=t},this.restoreFromMemory=function(e){this.memoryData||(this.memoryData={});var t=this.memoryData[e];return t&&(this.cursor=t.cursor,this.rowsCount=t.rowCount),delete this.memoryData[e],deepCopy(t.data)},this.hasPendingChanges=function(){var e=this.hasMemoryData;return this.children&&$(this.children).each(function(){e=e||this.hasPendingChanges()}),e},this.isPostingBatchData=function(){var isPosting=!0==this.postingBatch;return this.dependentLazyPost&&(isPosting=isPosting||eval(this.dependentLazyPost).isPostingBatchData()),isPosting},this.fetchChildren=function(e){this.children?reduce(this.children,function(e,t){e.fetch({},function(){t()})}.bind(this),function(){e&&e()}.bind(this)):e&&e()};var splitExpression=function(e){var t,a=null;-1==e.indexOf("@=")?-1==e.indexOf("<=")?-1==e.indexOf(">=")?-1==e.indexOf(">")?-1==e.indexOf("<")?(a=e.trim().split("="),t="="):(a=e.trim().split("<"),t="<"):(a=e.trim().split(">"),t=">"):(a=e.trim().split(">="),t=">="):(a=e.trim().split("<="),t="<="):(a=e.trim().split("@="),t="=");var n=typeof this.normalizeValue(a[1],!0);if(this.isOData()){if("="==t&&"string"==n)return"startswith(tolower("+a[0]+"), "+a[1].toLowerCase()+")";if("="==t)return a[0]+" eq "+a[1];if("!="==t)return a[0]+" ne "+a[1];if(">"==t)return a[0]+" gt {"+a[1];if(">="==t)return a[0]+" ge "+a[1];if("<"==t)return a[0]+" lt "+a[1];if("<="==t)return a[0]+" le "+a[1]}else return"string"==n?a[0]+"@"+t+"%"+a[1]+"%":a[0]+t+a[1]}.bind(this),parseFilterExpression=function(e){var t="";if(e){var a=e.split(";"),n=!0;if(0<a.length)for(var s,r=/[\w\d]+=.+/gm,o=0;o<a.length;o++)if(s=a[o].match(r),!s){n=!1;break}if(n)for(var d,o=0;o<a.length;o++)d=splitExpression(a[o]),""!=t&&(t+=this.isOData()?" and ":";"),t+=d;else t=e}return t}.bind(this),getQueryOperator=function(e){return"="==e?" eq ":"!="==e?" ne ":">"==e?" gt ":">="==e?" ge ":"<"==e?" lt ":"<="==e?" le ":void 0}.bind(this),executeRight=function(right){var result="";if(null!=right&&null!=right)if(right.startsWith(":")||right.startsWith("datetimeoffset'")||right.startsWith("datetime'"))result=right;else{if(right&&"string"==typeof right&&2<=right.length&&("'"==right.charAt(0)&&"'"==right.charAt(right.length-1)||"\""==right.charAt(0)&&"\""==right.charAt(right.length-1)))try{result=eval("'"+right.substring(1,right.length-1).replaceAll("'","\\'")+"'")}catch(e){result=eval(right)}else""!=right&&(result=eval(right));result instanceof Date?result="datetimeoffset'"+result.toISOString()+"'":"string"==typeof result?result="'"+result+"'":(void 0===result||null==result)&&(result="null")}return result}.bind(this);this.isEmpty=function(e){return""===e||void 0===e||null===e||"''"===e},this.getFieldFromSchema=function(e){if(this.schema)for(var t=0;t<this.schema.length;t++)if(this.schema[t].name===e)return this.schema[t].type;return null},this.parserCondition=function(e,t,a){var n="",s=e.type;if(t||(t="default"),e.args)for(var r=0;r<e.args.length;r++){var o=e.args[r],d=s;if(o.args&&0<o.args.length){var c=this.parserCondition(o,t);this.isEmpty(c)&&("ignore"==t||"clean"==t)?a&&(a.clean="clean"==t):!this.isEmpty(c)&&(a&&(a.count=a.count?a.count+1:1),""!=n&&(n+=" "+d.toLowerCase()+" "),n+="( "+c+" ) ")}else{var c=executeRight(o.right);if(this.isEmpty(c)&&("ignore"==t||"clean"==t||"wait"==t))a&&(a.clean="clean"==t,a.wait="wait"==t);else if(!this.isEmpty(c)){var l=!0,u="DateTime"===this.getFieldFromSchema(o.left),p=void 0;if(u&&-1===c.indexOf("datetime")&&(p=this.$scope.cronapi.dateTime.getMomentObj(c),l=p.isValid()),!l)"null"===c&&(n+=`${o.left} ${getQueryOperator(o.type)} null`);else if(a&&(a.count=a.count?a.count+1:1),""!=n&&(n+=" "+d.toLowerCase()+" "),"%"==o.type)n+=this.isLocalData()?"contains("+o.left+", "+c.toLowerCase()+")":"substringof("+c.toLowerCase()+", tolower("+o.left+"))";else if(p){var g=p.toDate().getTimezoneOffset(),y=timeZoneOffset-g;p.add(y,"minutes"),n+=o.left+getQueryOperator(o.type)+"datetimeoffset'"+p.toISOString()+"'"}else n+=o.left+getQueryOperator(o.type)+c}}}return n.trim()}.bind(this),this.refreshData=function(e){if(this.lastFetch&&!this.hasMemoryData&&this.enabled&&!this.inserting&&!this.editing){window.Pace&&(window.Pace.options.ajax.trackWebSockets=!1,window.Pace.options.ajax.trackMethods=[]);var t=function(){window.Pace&&(window.Pace.options.ajax.trackWebSockets=!0,window.Pace.options.ajax.trackMethods=["PUT","POST","GET"]),e&&e()};this.lastFilter=null,this.lastFetch.fetchOptions=this.lastFetch.fetchOptions||{},this.lastFetch.fetchOptions.active=this.copy(this.active),this.lastFetch.fetchOptions.active.__$id=void 0,this.fetch(this.lastFetch.properties,{success:t,error:t},this.lastFetch.isNextOrPrev,this.lastFetch.fetchOptions,!0)}else e&&e()},this.startAutoRefresh=function(){0<this.autoRefresh&&setTimeout(function(){this.refreshData(function(){this.startAutoRefresh()}.bind(this))}.bind(this),this.autoRefresh)},this.isParentBusy=function(){return!!this.dependentLazyPost&&(eval(this.dependentLazyPost).busy||eval(this.dependentLazyPost).isParentBusy())},this.fetch=function(properties,callbacksObj,isNextOrPrev,fetchOptions,silent,fromVisibleEvent){fetchOptions||(fetchOptions={});let busy=this.busy,masterDetail=this.parameters&&0<this.parameters.length;if(fetchOptions.ignoreBusy&&(busy=!1),busy||this.postingBatch||!masterDetail&&this.isParentBusy())return void setTimeout(function(){this.fetch(properties,callbacksObj,isNextOrPrev,fetchOptions)}.bind(this),1e3);var callbacks=callbacksObj||{};this.lastFetch={properties:properties,isNextOrPrev:isNextOrPrev,fetchOptions:fetchOptions};var sucessHandler=function(data,headers,raw){var springVersion=!1;this.responseHeaders=headers||{};var total=-1;-1<this.entity.indexOf("//")&&0>this.entity.indexOf("://")&&(data=[]),raw||(data?"[object Array]"!==Object.prototype.toString.call(data)&&(data&&data.links&&"[object Array]"===Object.prototype.toString.call(data.content)?(this.links=data.links,data=data.content,springVersion=!0):this.isOfflineMode()?(total=data.total_rows,data=this.$scope.cronapi.internal.normalizePouchDBData(data.rows,!0)):this.isOData()?(total=parseInt(data.d.__count),data=data.d.results,this.normalizeData(data)):this.isLocalData()?(total=data.total_rows,data=data.rows,this.normalizeData(data)):data=[data]):data=[]);for(var n=0;n<data.length;n++)data[n].__$id||(data[n].__$id=uuid());if(!fetchOptions.lookup&&(this.fetched=!0,callbacks.beforeFill&&callbacks.beforeFill.apply(this,this.data),isNextOrPrev?(this.prepend&&Array.prototype.unshift.apply(this.data,data),this.append&&Array.prototype.push.apply(this.data,data),!this.prepend&&!this.append&&(Array.prototype.push.apply(this.data,data),!fetchOptions.ignoreAtive&&(0<this.data.length?fetchOptions.active?this.goTo(fetchOptions.active):this.$scope.safeApply(()=>{this.active=data[0],this.cursor=0}):(this.active={},this.cursor=-1)))):(this.cleanup(fetchOptions),-1!=total&&(this.rowsCount=total),Array.prototype.push.apply(this.data,data),0<this.data.length&&!fetchOptions.ignoreAtive&&(fetchOptions.active?this.goTo(fetchOptions.active):this.$scope.safeApply(()=>{this.active=data[0],this.cursor=0}))),this.columns=[],0<this.data.length))for(var i=0;i<this.data[0].length;i++)this.columns.push(this.getColumn(i));if(callbacks.success&&callbacks.success.call(this,data),!fetchOptions.lookup){this.events.read&&this.callDataSourceEvents("read",data),this.hasMoreResults=data.length>=this.rowsPerPage,springVersion&&(this.hasMoreResults=null!=this.getLink("next")),this.isOfflineMode()&&(this.hasMoreResults=!1),this.autoPost&&this.startAutoPost(),this.loaded=!0,this.loadedFinish=!0,this.lastLoadedTime=Date.now(),this.handleAfterCallBack(this.onAfterFill);var thisDatasourceName=this.name;this.isOData()||$("datasource").each(function(idx,elem){var dependentBy=null,dependent=window[elem.getAttribute("name")];if(dependent&&""!==elem.getAttribute("dependent-by")&&null!=elem.getAttribute("dependent-by")){try{dependentBy=JSON.parse(elem.getAttribute("dependent-by"))}catch(ex){dependentBy=eval(elem.getAttribute("dependent-by"))}dependentBy?dependentBy.name==thisDatasourceName&&!dependent.filterURL&&eval(dependent.name).fetch():console.log("O dependente "+elem.getAttribute("dependent-by")+" do pai "+thisDatasourceName+" ainda n\xE3o existe.")}})}if("insert"==this.startMode&&(this.startMode=null,this.startInserting()),"edit"==this.startMode&&(this.startMode=null,this.startEditing()),0<this.autoRefresh&&!this.autoRefreshStarted&&(this.autoRefreshStarted=!0,this.startAutoRefresh()),!this.isOfflineMode()&&this.hasOfflineSupport()){var db=this.getPouchDB();this.$scope.cronapi.internal.updatePouchDB(db,data)}}.bind(this);if(this.busy)return void(callbacks.canceled&&callbacks.canceled());if(-1<this.entity.indexOf("//")&&0>this.entity.indexOf("://"))return void(callbacks.canceled&&callbacks.canceled());if(!this.enabled)return this.cleanup(),void(callbacks.canceled&&callbacks.canceled());var props=properties||{};props.params=props.params||{};var resourceURL=(window.hostApp||"")+this.entity+(props.path||this.lastFilterParsed||""),filter="",order="",cleanData=!1,canProceed=!0;if(this.parameters&&0<this.parameters.length){var parsedParameters=fetchOptions.lookup?this.$interpolate(this.parametersExpression)(this.$scope):this.parameters;for(var parts=parsedParameters.split(";"),partsExpression=this.parametersExpression.split(";"),i=0;i<parts.length;i++){var part=parts[i],partExpression=partsExpression[i],binary=part.split("="),binaryExpression=partExpression.split("=");if(2==binary.length){var filterClause,g=DEP_PATTERN.exec(binaryExpression[1]);if(!((this.isEmpty(binary[1])||this.isAutoGeneratedValue(binary[1]))&&this.dependentLazyPost&&g[1]&&g[1].startsWith(this.dependentLazyPost+".")))this.isEmpty(binary[1])?("clean"==this.parametersNullStrategy||"default"==this.parametersNullStrategy)&&(filterClause="null",cleanData=!0):filterClause=this.getObjectAsString(this.normalizeValue(binary[1],!0),!1);else if("clean"==this.parametersNullStrategy||"default"==this.parametersNullStrategy){cleanData=!0;var dds=eval(this.dependentLazyPost);filterClause=dds.active&&dds.active.__$id?eval(this.dependentLazyPost).active.__$id:"memory"}filterClause&&(filterClause=binary[0]+getQueryOperator("=")+filterClause,""!=filter&&(filter+=this.isOData()?" and ":";"),filter+=filterClause)}}}if(!canProceed)return void(callbacks.canceled&&callbacks.canceled());var urlParams;let waitData=!1;if(this.condition){try{var parsedCondition=fetchOptions.lookup?this.$interpolate(this.conditionExpression)(this.$scope):this.condition;var obj=JSON.parse(parsedCondition);if("object"==typeof obj){var resultData={};this.conditionOdata=obj.expression?this.parserCondition(obj.expression,this.parametersNullStrategy,resultData):this.parserCondition(obj,this.parametersNullStrategy,resultData);var filterCount=0;let e=this.conditionExpression.match(/{{(?!null).*?}}/g);if(e&&(filterCount=e.length),!cleanData&&resultData.clean&&(cleanData=!0),!cleanData&&resultData.wait&&(waitData=!0),cleanData||"one"!==this.loadDataStrategy||resultData.count&&!(1>resultData.count)||(cleanData=!0),!cleanData&&"all"===this.loadDataStrategy&&filterCount&&(!resultData.count||resultData.count<filterCount)&&(cleanData=!0),cleanData||"button"!==this.loadDataStrategy||"button"===fetchOptions.origin||(cleanData=!0),obj.params)for(var value,i=0;i<obj.params.length;i++)value=obj.params[i].fieldValue,2<=value.length&&"'"==value.charAt(0)&&"'"==value.charAt(value.length-1)&&(value=value.substring(1,value.length-1)),""!==value&&void 0!==value&&null!==value&&(props.params[obj.params[i].fieldName]=value)}else this.conditionOdata=this.condition}catch(t){console.log(t)}var conditionFilter=parseFilterExpression(this.conditionOdata);conditionFilter&&(""!=filter&&(filter+=this.isOData()?" and ":";"),filter+=conditionFilter)}if(this.orderBy)for(var orderField,orders=this.orderBy.split(";"),i=0;i<orders.length;i++)orderField=orders[i],orderField&&(""!=order&&(order+=this.isOData()?",":";"),order+=this.isOData()?orderField.replace("|ASC"," asc").replace("|DESC"," desc"):orderField);if(this.dependentLazyPost&&!this.parameters&&!this.condition&&!fromVisibleEvent&&eval(this.dependentLazyPost).active){var checkRequestId="",keyDependentLazyPost=this.getKeyValues(eval(this.dependentLazyPost).active);for(var key in keyDependentLazyPost){checkRequestId=keyDependentLazyPost[key];break}if(checkRequestId&&0<checkRequestId.length&&-1==resourceURL.indexOf(checkRequestId))return void(callbacks.canceled&&callbacks.canceled())}0<this.rowsPerPage&&(this.isOData()?((void 0===props.params.$top||null===props.params.$top)&&(props.params.$top=this.rowsPerPage),(void 0===props.params.$skip||null===props.params.$skip)&&(props.params.$skip=parseInt(this.offset)*parseInt(this.rowsPerPage)),props.params.$inlinecount="allpages"):1==this.apiVersion||-1==resourceURL.indexOf("/cronapi/")?(props.params.limit=this.rowsPerPage,props.params.offset=this.offset):(props.params.size=this.rowsPerPage,props.params.page=this.offset));var paramFilter=null;this.isOData()&&props.params.$filter&&(paramFilter=props.params.$filter),!this.isOData()&&props.params.filter&&(paramFilter=props.params.filter),paramFilter&&(filter&&""!=filter?this.isOData()?(filter+=" and (",filter+=paramFilter+")"):(filter+=";",filter+=paramFilter):filter=paramFilter);var paramOrder=null;this.isOData()&&props.params.$orderby&&(paramOrder=props.params.$orderby),!this.isOData()&&props.params.order&&(paramOrder=props.params.order),paramOrder&&(order=paramOrder),filter&&(this.isOData()?props.params.$filter=filter:props.params.filter=filter),order&&(this.isOData()?props.params.$orderby=order:props.params.order=order);var localSuccess;if(this.hasMemoryData&&filter){if(this.memoryData||(this.memoryData={}),this.lastFilter==filter)return void(callbacks.canceled&&callbacks.canceled());var id=filter,mem=this.memoryData[id];if(mem){this.storeInMemory(this.lastFilter);var data=this.restoreFromMemory(id);return this.lastFilter=filter,void sucessHandler(data,null,!0)}localSuccess=function(){this.storeInMemory(this.lastFilter)}.bind(this)}if(this.stopAutoPost(),this._savedProps=props,waitData)return void setTimeout(function(){fetchOptions.ignoreBusy=!0,this.fetch(properties,callbacksObj,isNextOrPrev,fetchOptions)}.bind(this),100);if(cleanData)return localSuccess&&localSuccess(),this.lastFilter=filter,void sucessHandler([],null,!0);this.busy=!0;var httpError=function(e){this.busy=!1,silent||this.handleError(e),callbacks.error&&callbacks.error.call(this,e)}.bind(this);let callService=function(){this.$promise=this.getService("GET")({method:"GET",url:this.removeSlash(resourceURL),params:props.params,headers:this.headers,filter:filter,offlineMode:this.isOfflineMode()}).success(function(e,t,a){localSuccess&&localSuccess(),this.lastFilter=filter,this.busy=!1,a?sucessHandler(e,a()):sucessHandler(e,null)}.bind(this)).error(function(e,t,a,n){httpError(e,t,a,n)}.bind(this))}.bind(this);this.fetchOnVisible&&!this.parent.is(":visible")?this.holdServiceCall=callService:(this.holdServiceCall=void 0,callService())},this.getRowsCount=function(){return-1==this.rowsCount?this.data.length:this.rowsCount},this.notifyObservers=function(){for(var e in this.observers)if(this.observers.hasOwnProperty(e)){var t=this.observers[e];$timeout(function(){t.notify.call(t,this.active)}.bind(this),1)}},this.notify=function(e){if(e){var t=this.watchFilter;t=t.replace(/\{([A-z][A-z|0-9]*)\}/gim,function(t,a){return e.hasOwnProperty(a)?e[a]:""}),this.fetch({params:{q:t}})}},this.addObserver=function(e){this.observers.push(e)},this.sum=function(e){for(var t=0,a=0;a<this.data.length;a++)this.data[a][e]&&(t+=this.data[a][e]);return t},this.copy=function(e,t,a){if(null===e||"[object Object]"!==Object.prototype.toString.call(e))return e;for(var n in t=t||{},e)e.hasOwnProperty(n)&&-1==n.indexOf("$$")&&(t[n]=this.copy(e[n]));if(a)for(var s=0;s<this.keys.length;s++){var n=this.keys[s],r=t[n];(""==r||null==r)&&delete t[n]}return t};var deepCopyArray=function(e,t){if(null===e||"[object Array]"!==Object.prototype.toString.call(e))return e;t=t||[];for(var a=0;a<e.length;a++)t.push(deepCopy(e[a]));return t},deepCopy=function(e,t){if("[object Array]"===Object.prototype.toString.call(e))return deepCopyArray(e,t);if(null===e||"[object Object]"!==Object.prototype.toString.call(e))return e;for(var a in t=t||{},e)e.hasOwnProperty(a)&&(t[a]=deepCopy(e[a]));return t};if(this.startAutoPost=function(){this.unregisterDataWatch=$rootScope.$watch(function(){return this.data}.bind(this),function(e,t){if(!this.enabled)return void this.unregisterDataWatch();var a=e.length-t.length;if(0<a)for(var n=1;n<=a;n++)this.insert(e[e.length-n],function(){});else if(0>a)for(var s=this,r=t.filter(function(t){return 0==e.filter(function(e){return s.objectIsEquals(t,e)}).length}),n=0;n<r.length;n++)this.remove(r[n],function(){})}.bind(this))},this.stopAutoPost=function(){this.unregisterDataWatch&&(this.unregisterDataWatch(),this.unregisterDataWatch=void 0)},this.hasDataBuffered=function(){return!!(this.dependentBufferLazyPostData&&0<this.dependentBufferLazyPostData.length)},window.afterDatasourceCreate){var args=[$q,$timeout,$rootScope,$window,Notification];window.afterDatasourceCreate.apply(this,args)}this.init()};return this.storeDataset=function(e){this.datasets[e.name]=e},this.initDataset=function(props,scope,$compile,$parse,$interpolate,instanceId,translate){var endpoint=props.endpoint?props.endpoint:"",dts=new DataSet(props.name,scope,props.fetchOnVisible);let canStoreDataset=!0;$rootScope[props.name]&&!$rootScope[props.name].insideModal&&props.insideModal?(canStoreDataset=!1,console.log(`%c${translate.instant("Datasource.Error").toUpperCase()} - ${translate.instant("Datasource.Duplicate").toUpperCase()}${props.name.toUpperCase()}`,"background: #000; color: #FFF; font-size:14px;")):($rootScope[props.name]=dts,window[props.name]=dts,$rootScope[props.name+".instanceId"]=instanceId);var defaultApiVersion=1;if(dts.entity=props.entity,dts.localDBName=props.entity,!isCronapiApiPath(dts.entity))if(dts.entity.match(DS_ID))dts.entity="api/cronapi/odata/v2/"+dts.entity.replaceAll(".","/");else if(dts.isLocalData()){var path=dts.entity.substring(dts.entity.indexOf("//")+2,dts.entity.length).split("/");dts.localDBType=dts.entity.substring(0,dts.entity.indexOf("://")),dts.localDBName=path[0],dts.localDBStorage=path[1],dts.localDBVersion=path[2]||1}if(app&&app.config&&app.config.datasourceApiVersion&&(defaultApiVersion=app.config.datasourceApiVersion),dts.translate=translate,dts.apiVersion=props.apiVersion?parseInt(props.apiVersion):defaultApiVersion,dts.keys=props.keys&&0<props.keys.length?props.keys.split(","):[],dts.rowsPerPage=props.rowsPerPage?props.rowsPerPage:100,dts.append=props.append,dts.prepend=props.prepend,dts.endpoint=props.endpoint,dts.filterURL=props.filterURL,dts.autoPost=props.autoPost,dts.autoRefresh=props.autoRefresh,dts.deleteMessage=props.deleteMessage,dts.enabled=props.enabled,dts.offset=props.offset?props.offset:0,dts.onError=props.onError,dts.defaultNotSpecifiedErrorMessage=props.defaultNotSpecifiedErrorMessage,dts.onAfterFill=props.onAfterFill,dts.onBeforeCreate=props.onBeforeCreate,dts.onAfterCreate=props.onAfterCreate,dts.onBeforeUpdate=props.onBeforeUpdate,dts.onAfterUpdate=props.onAfterUpdate,dts.onBeforeDelete=props.onBeforeDelete,dts.onAfterDelete=props.onAfterDelete,dts.onChangeStatus=props.onChangeStatus,dts.onGET=props.onGet,dts.onPOST=props.onPost,dts.onPUT=props.onPut,dts.onDELETE=props.onDelete,dts.dependentBy=props.dependentBy,dts.parameters=props.parameters,dts.parametersNullStrategy=props.parametersNullStrategy,dts.parametersExpression=props.parametersExpression,dts.checkRequired=props.checkRequired,dts.batchPost=props.batchPost,dts.condition=props.condition,dts.conditionExpression=props.conditionExpression,dts.orderBy=props.orderBy,dts.schema=props.schema,dts.startMode=props.startMode,dts.lazy=props.lazy,dts.$compile=$compile,dts.$parse=$parse,dts.$interpolate=$interpolate,dts.loadDataStrategy=props.loadDataStrategy,dts.offline=props.offline,dts.insideModal=props.insideModal,props.dependentLazyPost&&0<props.dependentLazyPost.length&&(dts.dependentLazyPost=props.dependentLazyPost,setTimeout(()=>{eval(dts.dependentLazyPost).addDependentDatasource(dts)},0)),dts.dependentLazyPostField=props.dependentLazyPostField,dts.headers=props.headers,canStoreDataset&&this.storeDataset(dts),dts.allowFetch=!0,dts.dependentBy&&""!==dts.dependentBy&&""!==dts.dependentBy.trim()){dts.allowFetch=!1;var dependentBy=null;try{dependentBy=JSON.parse(dependentBy)}catch(ex){dependentBy=eval(dependentBy)}dependentBy&&dependentBy.loadedFinish&&(dts.allowFetch=!0)}if(!props.lazy&&dts.allowFetch&&"[object String]"!==Object.prototype.toString.call(props.watch)&&!props.filterURL){var queryObj={};setTimeout(function(){dts.fetch({params:queryObj},{success:function(e){e&&0<e.length&&(this.active=e[0],this.cursor=0)}})}.bind(this),0)}return props.lazy&&props.autoPost&&dts.startAutoPost(),props.watch&&"[object String]"===Object.prototype.toString.call(props.watch)&&(this.registerObserver(props.watch,dts),dts.watchFilter=props.watchFilter),props.filterURL&&0<props.filterURL.length&&dts.allowFetch&&dts.filter(props.filterURL),dts},this.registerObserver=function(e,t){this.datasets[e].addObserver(t)},this}]).directive("datasource",["DatasetManager","$timeout","$parse","Notification","$translate","$location","$rootScope","$compile","$interpolate",function(e,t,a,n,s,r,i,o){return{restrict:"E",priority:9999999,scope:!0,template:"",link:function(e,t){(function(e,a,n){$(e).each(function(){var e=$(this),s=$(document.createElement(n),{html:e.html()});$.each(this.attributes,function(){s.attr(this.name,this.value)}),s.attr("inside-modal",0<$(t).closest(".modal").length);var r=e.data("events");if(r)for(var i in r)for(var d in r[i])s[i](r[i][d].handler);o(s)(a),e.replaceWith(s)})})(t,e,"cronapp-datasource")}}}]);let datasourceRepeat=1;app.directive("crnRepeat",["DatasetManager","$compile","$parse","$injector","$rootScope",function(DatasetManager,$compile,$parse,$injector,$rootScope){return{restrict:"A",priority:9999998,terminal:!0,link:function(scope,element,attrs,controllers,transclude){const indexAttribute=(e,t,a)=>{let n=e.parent().find(`[data-repeater=${t}]`);n.each&&n.each((e,t)=>{let n=$(t);n.find(`[${a}]`).each((t,n)=>{let s=$(n),r=s.attr(`${a}`);s.attr(`${a}`,`${r}-cronapp-${e}`)})})};$(window).ready(()=>{datasourceRepeat++;let isDatasource=!1,dataRepeaterId=`datasourceRepeat${datasourceRepeat}`;if(attrs.crnRepeat){if(scope.data=DatasetManager.datasets,scope.data[attrs.crnRepeat])scope[dataRepeaterId]=scope.data[attrs.crnRepeat],isDatasource=!0;else{scope[dataRepeaterId]=[];var value=$parse(attrs.crnRepeat)(scope);value instanceof String&&value.startsWith("[")&&value.endsWith("]")&&(value=eval(value)),scope[dataRepeaterId]=value}isDatasource?(element.attr("ng-init",attrs.crnRepeat+" = {}; "+attrs.crnRepeat+".active = rowData"),element.attr("ng-repeat",`rowData in ${dataRepeaterId}.data`)):element.attr("ng-repeat",`rowData in ${dataRepeaterId}`),element.attr("data-repeater",dataRepeaterId)}var tagName=element[0].tagName;$compile(element,null,9999998)(scope);let watchForRepeater=isDatasource?`${dataRepeaterId}.data`:`${dataRepeaterId}`;scope.$watchCollection(watchForRepeater,function(){if("ion-slide"==tagName.toLowerCase()){var e=$injector.get("$ionicSlideBoxDelegate");e.update()}indexAttribute(element,dataRepeaterId,"id"),indexAttribute(element,dataRepeaterId,"for")})})}}}]).directive("crnDatasource",["DatasetManager","$parse","$rootScope",function(e,t){return{restrict:"A",scope:!0,priority:9999998,link:function(a,n,s){a.data=e.datasets,a.data[s.crnDatasource]?a.datasource=a.data[s.crnDatasource]:(a.datasource={},a.datasource.data=t(s.crnDatasource)(a))}}}]).directive("cronappDatasource",["DatasetManager","$timeout","$parse","Notification","$translate","$location","$rootScope","$compile","$interpolate","SyncService",function(e,t,a,n,s,r,i,o,d){return{restrict:"E",scope:!0,template:"",link:function(c,l,u){initDatasource(c,l,u,e,t,a,n,s,r,i,o,d)}}}]),angular.module("sync.service",[]).service("SyncService",["$http",function(e){let t={start:function(){this.dbSync=this.getSyncServicePouchDB(),this.observeConnection()},observeConnection:async function(){setInterval(()=>this.isNavigatorOffline()||this.synchronizeOfflineData(),15000)},toQueue:function(e){let t={data:e,created:Date.now()};this.dbSync.post(t).catch(e=>console.error(e))},synchronizeOnError:async function(t,e){this.synchronizing=!1,console.log("Error synchronizing doc",e,"response",t)},synchronizeOnSuccess:async function(e,t){try{await this.dbSync.remove(e),this.removeArray(e,t),0<t.length?this.sendData(t[0],t):this.synchronizing=!1}catch(t){this.synchronizing=!1}},canByPassError:function(t){let e=!1;if(t.data&&t.data.error&&t.data.error.message&&t.data.error.message.value){let a=t.data.error.message.value;"N\xE3o foi poss\xEDvel encontrar a entidade requisitada."===a||"Requested entity could not be found."===a?e=!0:void 0}return e},sendData:async function(t,a){let n=t.data;e(n).then(()=>this.synchronizeOnSuccess(t,a)).catch(n=>this.canByPassError(n)&&this.synchronizeOnSuccess(t,a)||this.synchronizeOnError(n,t,a)),console.log(`Synchronization - sended record number ${a.length}`)},optimizeQueue:function(e){let t=e.rows.filter(e=>"DELETE"===e.doc.data.method);t.forEach(async t=>{let a=e.rows.filter(e=>{let a=e.doc.data.originalObject||e.doc.data.rawData,n=t.doc.data.originalObject||t.doc.data.rawData;return a&&n&&a._objectKey===n._objectKey&&"DELETE"!==e.doc.data.method});a.forEach(async t=>{this.dbSync.remove(t.doc),this.removeArray(t,e.rows)})});let a=[];return e.rows.forEach(e=>a.push(e.doc)),a.sort((e,t)=>e.created-t.created),a},synchronizeOfflineData:async function(){try{if(!this.synchronizing){let e=await this.dbSync.allDocs({include_docs:!0,attachments:!0});if(e.rows.length){console.log("Synchronization started"),this.synchronizing=!0;let t=this.optimizeQueue(e);this.sendData(t[0],t)}}}catch(t){console.log(t)}},removeArray(e,t){if(e&&t){let a=t.indexOf(e);-1<a&&t.splice(a,1)}},isNavigatorOffline:function(){return!navigator.onLine},getSyncServicePouchDB:function(){return cronapi.internal.getPouchDB("syncService")},synchronizing:null,dbSync:null,lastStatus:null};return t.start(),t}]);
1
+ var ISO_PATTERN=/(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))/,TIME_PATTERN=/PT(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)(?:\.(\d+)?)?S)?/,DEP_PATTERN=/\{\{(.*?)\|raw\}\}/,HTTP_STATUS=/HTTP\/1\.1 (\d+) (.*)/,DS_ID=/[\w\_\.\d]+/;const isCronapiApiPath=e=>/^\/?api\/cronapi\/.*\/?$/.test(e);(function(e){var t={callback:function(){},runOnLoad:!0,frequency:100,previousVisibility:null},a={};a.checkVisibility=function(e,t){if(jQuery.contains(document,e[0])){var n=t.previousVisibility,s=e.is(":visible");t.previousVisibility=s;var r=null==n;r?t.runOnLoad&&t.callback(e,s,r):n!==s&&t.callback(e,s,r),setTimeout(function(){a.checkVisibility(e,t)},t.frequency)}},e.fn.visibilityChanged=function(n){var s=e.extend({},t,n);return this.each(function(){a.checkVisibility(e(this),s)})}})(jQuery);var initDatasource=function(e,t,a,n,s,r,i,o,d,c,l,u){var p=parseInt(9999*Math.random());if(cronapi.internal.isJsonString(a.headers)){let e=JSON.parse(a.headers);e.push({key:"origin-path",type:"string",value:d.path()}),a.headers=JSON.stringify(e)}else{var g="origin-path:"+d.path();a.headers=void 0===a.headers||null===a.headers?g:a.headers.concat(";",g)}var y,h={name:a.name,entity:a.entity,apiVersion:a.apiVersion,enabled:!a.hasOwnProperty("enabled")||"true"===a.enabled,keys:a.keys,endpoint:a.endpoint,lazy:"true"===a.lazy,append:!a.hasOwnProperty("append")||"true"===a.append,prepend:a.hasOwnProperty("prepend")&&""===a.prepend||"true"===a.prepend,watch:a.watch,rowsPerPage:a.rowsPerPage,offset:a.offset,filterURL:a.filter,watchFilter:a.watchFilter,deleteMessage:a.deleteMessage||""===a.deleteMessage?a.deleteMessage:o.instant("General.RemoveData"),headers:a.headers,autoPost:"true"===a.autoPost,autoRefresh:a.autoRefresh!==void 0&&null!==a.autoRefresh?a.autoRefresh:0,onError:a.onError,onAfterFill:a.onAfterFill,onBeforeCreate:a.onBeforeCreate,onAfterCreate:a.onAfterCreate,onBeforeUpdate:a.onBeforeUpdate,onAfterUpdate:a.onAfterUpdate,onBeforeDelete:a.onBeforeDelete,onAfterDelete:a.onAfterDelete,onChangeStatus:a.onChangeStatus,onGet:a.onGet,onPost:a.onPost,onPut:a.onPut,onDelete:a.onDelete,defaultNotSpecifiedErrorMessage:o.instant("General.ErrorOnServerCommunication"),dependentBy:a.dependentBy,dependentLazyPost:a.dependentLazyPost,batchPost:"true"===a.batchpost,dependentLazyPostField:a.dependentLazyPostField,parameters:a.parameters,parametersNullStrategy:a.parametersNullStrategy?a.parametersNullStrategy:"default",parametersExpression:$(t).attr("parameters"),conditionExpression:$(t).attr("condition"),condition:a.condition,orderBy:a.orderBy,loadDataStrategy:a.loadDataStrategy,schema:a.schema?JSON.parse(a.schema):void 0,checkRequired:!a.hasOwnProperty("checkrequired")||""===a.checkrequired||"true"===a.checkrequired,fetchOnVisible:!(a.fetchOnVisible===void 0||null===a.fetchOnVisible)&&"true"===a.fetchOnVisible,offline:!("true"!==a.offline),insideModal:!("true"!==a.insideModal)},f={filter:!0,entity:!0,enabled:!0,parameters:!0};if(e.params){for(var m in e.params)if(e.params.hasOwnProperty(m)){var D=e.params[m];if(m.startsWith("$"+a.name+".")){var M=m.split(".");2==M.length&&("$filterMode"==M[1]?h.startMode=D:(y?y+=";":y="",y+=isNaN(D)?M[1]+"='"+D+"'":M[1]+"="+D))}}y&&(h.parameters=y,h.parametersExpression=y)}var L,p=parseInt(9999*Math.random()),v=n.initDataset(h,e,l,r,u,p,o);a.$observe("filter",function(e){v.isPostingBatchData()||(f.filter?s(function(){f.filter=!1},0):(s.cancel(L),L=s(function(){v.events.overRideRefresh?v.callDataSourceEvents("overRideRefresh","filter",e):v.filter(e,function(e){v.events.refresh&&v.callDataSourceEvents("refresh",e,"filter")}),v.lastFilterParsed=e},100)))}),y||a.$observe("parameters",function(e){v.isPostingBatchData()||v.parameters!=e&&(v.parameters=e,s.cancel(L),L=s(function(){v.callDataSourceEvents("changeDependency","parameters",v.parameters),v.events.overRideRefresh?v.callDataSourceEvents("overRideRefresh","parameters",v.parameters):v.fetch({params:{}},{success:function(e){v.events.refresh&&v.callDataSourceEvents("refresh",e,"parameters")}})},0))});let b={lastCondition:void 0,timeForCondition:void 0,typingSpeedLimit:1e3,maxWaitingValue:1e3,wait:function(){if(this.timeForCondition=0,this.lastCondition){let e=new Date().getTime()-this.lastCondition.getTime();e<this.typingSpeedLimit&&(this.timeForCondition=this.maxWaitingValue)}return this.lastCondition=new Date,this.timeForCondition}};a.$observe("condition",function(e){if(!v.isPostingBatchData()&&v.condition!=e){if(v.condition=e,"button"===v.loadDataStrategy)return;s.cancel(L),L=s(function(){v.callDataSourceEvents("changeDependency","condition",v.condition),v.events.overRideRefresh?v.callDataSourceEvents("overRideRefresh","condition",v.condition):v.fetch({params:{}},{success:function(e){v.events.refresh&&v.callDataSourceEvents("refresh",e,"condition")}})},b.wait())}}),a.$observe("enabled",function(e){var t="true"===e;v.enabled!=t&&(v.enabled=t,v.enabled&&(s.cancel(L),L=s(function(){v.events.overRideRefresh?v.callDataSourceEvents("overRideRefresh","enabled",v.parameters):v.fetch({params:{}},{success:function(e){v.events.refresh&&v.callDataSourceEvents("refresh",e,"enabled")}})},200)))}),a.$observe("entity",function(e){v.entity=e,v.entity.match(DS_ID)&&!isCronapiApiPath(v.entity)&&(v.entity="api/cronapi/odata/v2/"+v.entity.replaceAll(".","/")),f.entity?s(function(){f.entity=!1}):(s.cancel(L),L=s(function(){v.fetch({params:{}},{success:function(e){v.events.refresh&&v.callDataSourceEvents("refresh",e,"entity")}})},200))}),a.$observe("offline",function(e){v.offline="true"===e}),e.$on("$destroy",function(){c[a.name]&&c[a.name+".instanceId"]==p&&(c[a.name].destroy(),delete window[a.name],delete c[a.name],delete c[a.name+".instanceId"])})};angular.module("datasourcejs",[]).factory("DatasetManager",["$http","$q","$timeout","$rootScope","$window","Notification","SyncService",function($http,$q,$timeout,$rootScope,$window,Notification,SyncService){this.datasets={};let DatasetManagerUtil={getMainScope:function(){return angular.element(document.getElementById("main-view")).scope()},resolveExpressionMap:async function(e){let t,a=this.getMainScope();if(cronapi.internal.isJsonString(e)){t={};let s=JSON.parse(e);for(var n in s){let e=s[n];if("blockly"===e.type){let n=this.onMatchRegex(/cronapi.server/g,".run(",".toPromise().disableNotification()");t[e.key]=await a.$eval(n(e.value))}else t[e.key]="expression"===e.type?a.$eval(e.value):e.value}}return t},getHeaders:async function(e){let t;if(e&&0<e.length)if(!cronapi.internal.isJsonString(e)){t={};let n,s=e.trim().split(";");for(var a=0;a<s.length;a++)n=s[a].split(":"),2===n.length&&(t[n[0]]=n[1])}else t=await this.resolveExpressionMap(e);return t&&(t["X-From-DataSource"]="true"),t},onMatchRegex:function(e,t,a){return n=>{let s=e.exec(n);return s&&s.length?n.split(t).join(a+t):n}}};const $httpLegacy=e=>{var t={verb:e.method,successCallback:null,errorCallback:null,success:function(e){return this.successCallback=e,this},error:function(e){return this.errorCallback=e,this}};return DatasetManagerUtil.getHeaders(e.headers).then(function(t){if(e.headers=t||e.headers,e.offlineMode){SyncService.toQueue(e);let t=e.originalObject||e.rawData||e.data;this.successCallback(t,200,null,e)}else{let t=$http(e);t.then(e=>{this.successCallback&&this.successCallback(e.data,e.status,e.headers,e.config)}),t.catch(e=>{this.errorCallback&&this.errorCallback(e.data,e.status,e.headers,e.config)})}}.bind(t)),t};var DataSet=function(name,scope,fetchOnVisible){function reverseArr(e){if(e){for(var t=[],a=e.length-1;0<=a;a--)t.push(e[a]);return t}return[]}function toBase64(e,t){var a=new FileReader;a.readAsDataURL(e),a.onload=function(a){var e=a.target.result.substr(a.target.result.indexOf("base64,")+7);t(e)}}function uuid(){var e,t,a="";for(e=0;32>e;e++)t=0|16*Math.random(),(8==e||12==e||16==e||20==e)&&(a+="-"),a+=(12==e?4:16==e?8|3&t:t).toString(16);return a}var NO_IMAGE_UPLOAD="data:image/svg+xml;utf8;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iaXNvLTg4NTktMSI/Pgo8IS0tIEdlbmVyYXRvcjogQWRvYmUgSWxsdXN0cmF0b3IgMTYuMC4wLCBTVkcgRXhwb3J0IFBsdWctSW4gLiBTVkcgVmVyc2lvbjogNi4wMCBCdWlsZCAwKSAgLS0+CjwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMS4xLy9FTiIgImh0dHA6Ly93d3cudzMub3JnL0dyYXBoaWNzL1NWRy8xLjEvRFREL3N2ZzExLmR0ZCI+CjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgdmVyc2lvbj0iMS4xIiBpZD0iQ2FwYV8xIiB4PSIwcHgiIHk9IjBweCIgd2lkdGg9IjEyOHB4IiBoZWlnaHQ9IjEyOHB4IiB2aWV3Qm94PSIwIDAgNDQuNTAyIDQ0LjUwMiIgc3R5bGU9ImVuYWJsZS1iYWNrZ3JvdW5kOm5ldyAwIDAgNDQuNTAyIDQ0LjUwMjsiIHhtbDpzc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L2c+CjxnPgo8L2c+CjxnPgo8L2c+Cjwvc3ZnPgo=";this.fetchOnVisible=fetchOnVisible,this.parent=$("[name='"+name+"']").parent(),this.fetchOnVisible&&this.parent.visibilityChanged({callback:function(e,t){t&&this.holdServiceCall&&this.holdServiceCall()}.bind(this),runOnLoad:!1,frequency:100}),this.Notification=Notification,this.$scope=scope,this.noImageUpload="data:image/svg+xml;utf8;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iaXNvLTg4NTktMSI/Pgo8IS0tIEdlbmVyYXRvcjogQWRvYmUgSWxsdXN0cmF0b3IgMTYuMC4wLCBTVkcgRXhwb3J0IFBsdWctSW4gLiBTVkcgVmVyc2lvbjogNi4wMCBCdWlsZCAwKSAgLS0+CjwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMS4xLy9FTiIgImh0dHA6Ly93d3cudzMub3JnL0dyYXBoaWNzL1NWRy8xLjEvRFREL3N2ZzExLmR0ZCI+CjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgdmVyc2lvbj0iMS4xIiBpZD0iQ2FwYV8xIiB4PSIwcHgiIHk9IjBweCIgd2lkdGg9IjEyOHB4IiBoZWlnaHQ9IjEyOHB4IiB2aWV3Qm94PSIwIDAgNDQuNTAyIDQ0LjUwMiIgc3R5bGU9ImVuYWJsZS1iYWNrZ3JvdW5kOm5ldyAwIDAgNDQuNTAyIDQ0LjUwMjsiIHhtbDpzcGFjZT0icHJlc2VydmUiPgo8Zz4KCTxnPgoJCTxwYXRoIGQ9Ik05Ljg2MiwzNS42MzhoMjQuNzc5YzAtNS41NDYtMy44NjMtMTAuMjAzLTkuMTEzLTExLjYwNGMyLjc1LTEuMjQ4LDQuNjY4LTQuMDEzLDQuNjY4LTcuMjI5ICAgIGMwLTQuMzg4LTMuNTU5LTcuOTQy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NmMwLTAuODI4LTAuNjcyLTEuNS0xLjUtMS41Yy0wLjgzLDAtMS41LDAuNjcyLTEuNSwxLjV2OC41NmMwLDEuNTMsMS4yNDQsMi43NzYsMi43NzUsMi43NzZoOC41NjEgICAgYzAuODI4LDAsMS41LTAuNjcyLDEuNS0xLjVTMTIuMTY1LDQwLjE2OSwxMS4zMzYsNDAuMTY5eiIgZmlsbD0iIzkxOTE5MSIvPgoJPC9nPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+Cjwvc3ZnPgo=",this.noFileUpload=NO_FILE_UPLOAD,this.$apply=function(e){scope.safeApply(e)}.bind(scope),this.columns=[],this.data=[],this.name=name,this.keys=[],this.enabled=!0,this.endpoint=null,this.active={},this.inserting=!1,this.editing=!1,this.fetchSize=2,this.observers=[],this.rowsPerPage=null,this.append=!0,this.headers=null,this.responseHeaders=null,this._activeValues=null,this.errorMessage="",this.onError=null,this.links=null,this.loadedFinish=null,this.lastLoadedTime=0,this.lastFilterParsed=null,this.rowsCount=-1,this.events={},this.busy=!1,this.cursor=0,this._savedProps,this.hasMoreResults=!1,this.loaded=!1,this.unregisterDataWatch=null,this.dependentBufferLazyPostData=null,this.lastAction=null,this.dependentData=null,this.hasMemoryData=!1,this.batchPost=!1,this.caseInsensitive=null,this.terms=null,this.checkRequired=!0,this.schema;var _self=this,service=null;this.odataFile=[],this.destroy=function(){},this.init=function(){var dsScope=this;service={save:function(e){return this.call(_self.entity,"POST",e,!0)},update:function(e,t){return this.call(e,"PUT",t,!1)},remove:function(e,t){return this.call(e,"DELETE",t,!0)},call:function(e,t,a){var n={},s=0<=e.indexOf("/cronapi/query/");if(s){n.inputs=[a];var r,i,o={};if(_self.busy=!0,e=e.replace("/specificSearch",""),e=e.replace("/generalSearch",""),_self&&_self.$scope&&_self.$scope.vars)for(var d in o.vars={},_self.$scope.vars)o.vars[d]=_self.$scope.vars[d];for(var c in _self.$scope)_self.$scope[c]&&_self.$scope[c].constructor&&"DataSet"==_self.$scope[c].constructor.name&&(o[c]={},o[c].active=_self.$scope[c].active);n.fields=o}else n=a;var l={};for(var c in _self.copy(n,l,!0),delete l.__original,delete l.__status,delete l.__originalIdx,delete l.__sender,delete l.__$id,delete l.__parentId,delete l.$$hashKey,delete l.__fromMemory,delete l.__odatafiles,delete l.__$masterExpression,l)-1<c.indexOf("__odataFile_")&&(l[c.replace("__odataFile_","")]=void 0,delete l[c]);for(var c in l)if(l.hasOwnProperty(c)){let e=l[c];_self.isAutoGeneratedValue(e)&&delete l[c]}var u=function(e,t,a,n,i){if(_self.busy=!1,r&&(_self.isOData()?null!=e.d&&null!=e.d.result?(_self.normalizeData(e.d.result),r(e.d.result,!0,i)):null==e.d?r(e,!0,i):(_self.normalizeObject(e.d),r(e.d,!0,i)):r(s?e.value:e,!0,i)),s||_self.isOData()){var o=e;_self.isOData()&&(o={},o.commands=e.__callback,_self.normalizeData(o.commands)),_self.$scope.cronapi.evalInContext(JSON.stringify(o))}},p=_self.getParentDatasource();let g=p.getBatchDataItem(n);if(g&&g.result){let e=p.batchServiceData.indexOf(g);p.batchServiceData.splice(e,1),$timeout(()=>{u(g.result)},0),this.$promise={}}else this.$promise=_self.getService(t,n)({method:t,url:_self.removeSlash((window.hostApp||"")+e),data:"DELETE"==t?null:n?JSON.stringify(l):null,headers:_self.headers,rawData:n?l:null,originalObject:n?n:null,urlPart:e,offlineMode:_self.isOfflineMode()}).success(u).error(function(e){_self.busy=!1;var t;t=_self.isOData()?e.error.message.value:s&&e.value?e.value:e,_self.handleError(t),i&&i(t)});return this.$promise.then=function(e){return r=e,this},this.$promise.error=function(e){return i=e,this},this}},this.isAutoGeneratedValue=function(e){return"string"==typeof e&&10<e.length&&(e.startsWith("$autogenerated$")||e.substring(1).startsWith("$autogenerated$"))},this.getIndexedDB=function(e){return window.indexedDB||(window.indexedDB=window.indexedDB||window.mozIndexedDB||window.webkitIndexedDB||window.msIndexedDB,window.IDBTransaction=window.IDBTransaction||window.webkitIDBTransaction||window.msIDBTransaction,window.IDBKeyRange=window.IDBKeyRange||window.webkitIDBKeyRange||window.msIDBKeyRange),{properties:e,successCallback:null,errorCallback:null,type:null,args:null,success:function(e){return this.successCallback=e,this},error:function(e){return this.errorCallback=e,this},post:function(){return this.type="put",this.args=arguments,this},put:function(){return this.type="put",this.args=arguments,this},delete:function(){return this.type="delete",this.args=arguments,this},get:function(){return this.type="getAll",this.args=arguments,this},call:function(){request=window.indexedDB.open(this.properties.dbname,this.properties.dbversion||1),request.onerror=function(e){this.errorCallback&&this.errorCallback(e)}.bind(this),request.onsuccess=function(e){this.proceed(e.target.result)}.bind(this),request.onupgradeneeded=function(e){var t=e.target.result,a=t.createObjectStore(this.properties.objectStore,{keyPath:this.properties.key});a.transaction.oncomplete=function(){var e=t.transaction(this.properties.objectStore,"readwrite").objectStore(this.properties.objectStore);e.add({id:123,name:"Jose"})}.bind(this)}.bind(this)},proceed:function(e){if(this.type){var t=e.transaction(this.properties.objectStore,"readwrite"),a=t.objectStore(this.properties.objectStore),n=a[this.type].apply(a,this.args);n.onsuccess=function(e){this.successCallback&&("put"===this.type?this.successCallback(this.args[0]):this.successCallback(e.target.result))}.bind(this)}else this.successCallback&&this.successCallback()}}},this.batchServiceData=[],this.getBatchService=function(e){return function(t){var a={verb:e,properties:t,successCallback:null,errorCallback:null,success:function(e){return this.successCallback=e,this},error:function(e){return this.errorCallback=e,this}};return $timeout(function(){var n=this.getParentDatasource();let s=t.originalObject||t.rawData||t.data||this.active,r=this.entity;"PUT"==e&&(r=this.getEditionURL(s)),"DELETE"==e&&(r=this.getDeletionURL(s)),0<r.indexOf("/")&&(r=r.substring(r.lastIndexOf("/")+1,r.length)),n.batchServiceData.push({entity:r,data:s,promise:a}),a.successCallback&&a.successCallback.call(this,s,null,null,null,!0)}.bind(this)),a}.bind(this)},this.batchEnabled=function(e){return!!(e&&this.hasPendingChanges())&&null==this.getBatchDataItem(e)},this.getBatchDataItem=function(e){if(e){var t=this.getParentDatasource();for(let a,n=0;n<t.batchServiceData.length;n++)if(a=t.batchServiceData[n].data,a.__$id==e.__$id)return t.batchServiceData[n]}return null},this.performBatchPost=function(e){return new Promise(()=>{let t="batch_"+this.uuidv4(),a="";a+="--"+t+"\n";let n="changeset_"+this.uuidv4();a+="Content-Type: multipart/mixed; boundary="+n+"\n";for(let e,t=0;t<this.batchServiceData.length;t++){e=this.batchServiceData[t],a+="--"+n+"\n",a+="Content-Type: application/http\n",a+="Content-Transfer-Encoding:binary\n",a+=e.promise.properties.method+" "+e.entity+" HTTP/1.1\n",a+="Content-Type: application/json\n",a+="Accept: application/json\n",a+="X-Master-Id: "+e.promise.properties.originalObject.__$id+"\n",e.promise.properties.originalObject.__$masterExpression&&(a+="X-Detail-Fill: "+e.promise.properties.originalObject.__$masterExpression+"\n");let r=e.promise.properties.headers;for(var s in r)r.hasOwnProperty(s)&&(a+=s+": "+r[s]+"\n");"DELETE"!=e.promise.properties.method&&(a+=e.promise.properties.data+"\n")}a+="--"+n+"--\n",a+="--"+t+"--\n",console.log(a);let r=this.entity;0<r.indexOf("/")&&(r=r.substring(0,r.lastIndexOf("/")));let i={};this.copy(this.headers,i),i["Content-Type"]="multipart/mixed; boundary="+t;let o=(e,t,a,n)=>{let s;0<this.batchServiceData.length&&(s=this.batchServiceData[0].promise.errorCallback),s?s(e,t,a,n,!1):this.handleError(e),this.batchServiceData=[]};$httpLegacy({method:"POST",url:_self.removeSlash((window.hostApp||"")+r+"/$batch"),data:a,headers:i,offlineMode:_self.isOfflineMode()}).success(function(t,a,n,s){let r=this.parseBatchResult(t);for(let e=0;e<r.length;e++)if(400<=r[e].status)return void o(r[e].data,r[e].status);for(let e=0;e<this.batchServiceData.length;e++)this.batchServiceData[e].result=r[e]&&null!=r[e].data?r[e].data:this.batchServiceData[e].data;if(e)e();else{let e;0<this.batchServiceData.length&&(e=this.batchServiceData[0].promise.successCallback),e&&(this.batchServiceData.splice(0,1),e(r[0].data,r[0].status,n,s,!1))}}.bind(this)).error(o)})},this.parseBatchResult=function(e){let t,a=[],n=e.split("\n");for(let r,i=0;i<n.length;i++){if(r=n[i],r.startsWith("{")&&a.push({status:t,data:JSON.parse(r)}),r.startsWith("HTTP/1.1")){var s=HTTP_STATUS.exec(r);t=s[1]}r.startsWith("HTTP/1.1")&&0<r.indexOf("No Content")&&a.push({status:t,data:null})}return a},this.uuidv4=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=0|16*Math.random(),a="x"==e?t:8|3&t;return a.toString(16)})},this.getService=function(verb,object){_self=this;var event=eval("this.on"+verb);return"GET"===verb&&(event||this.isLocalData()||this.isNavigatorOffline())?function(e){var t={verb:verb,properties:e,successCallback:null,errorCallback:null,success:function(e){return this.successCallback=e,this},error:function(e){return this.errorCallback=e,this}};return $timeout(function(){var e,t={currentData:this.properties.rawData||this.properties.data||_self.active,filter:this.properties.filter||"",datasource:_self,selectedIndex:_self.cursor,index:_self.cursor,selectedRow:_self.active,item:_self.active,selectedKeys:_self.getKeyValues(_self.active,!0),selectedKey:_self.getFirstKeyValue(_self.active,!0),callback:this.successCallback};if(event)e=_self.$scope.$eval(event,t),e instanceof Promise?e.then(function(e){e&&"[object Array]"!==Object.prototype.toString.call(e)&&(e=[e]),_self.$scope.safeApply(function(){this.successCallback(e)}.bind(this))}.bind(this)).catch(function(e){_self.handleError(e)}.bind(this)):e&&this.successCallback(e);else{let e=_self.getPouchDB();if("GET"==this.verb&&!this.properties.filter)e.allDocs({include_docs:!0,attachments:!0}).catch(this.errorCallback).then(function(e){for(var t=[],a=0;a<e.rows.length;a++)t.push(e.rows[a].doc);e.rows=t,this.successCallback&&this.successCallback(e)}.bind(this));else if("GET"==this.verb){var a=peg$parse(this.properties.filter);e.find({selector:a}).catch(this.errorCallback).then(function(e){e.rows=e.docs,e.total_rows=e.rows.length,this.successCallback&&this.successCallback(e)}.bind(this))}}}.bind(t),0),t}:(this.hasOfflineSupport()&&object&&this.operationPouchDB(verb,object),this.batchEnabled(object)&&"GET"!=verb?this.getBatchService(verb):$httpLegacy)},this.isBusy=function(){return this.busy},this.isLoaded=function(){return this.loaded},this.toString=function(){return"[Datasource]"},this.handleAfterCallBack=function(e,t){if(e)try{var a={currentData:this.data,datasource:this,selectedIndex:this.cursor,index:this.cursor,selectedRow:this.active,item:this.active,selectedKeys:this.getKeyValues(this.active,!0),selectedKey:this.getFirstKeyValue(_self.active,!0),callback:t};this.$scope.$eval(e,a)}catch(t){this.handleError(t)}},this.handleBeforeCallBack=async function(e,t){var a=!0;let n=DatasetManagerUtil.onMatchRegex(/cronapi.server/g,".run(",".toPromise().disableNotification()");if(e)try{var s={currentData:this.data,datasource:this,selectedIndex:this.cursor,index:this.cursor,selectedRow:this.active,item:this.active,selectedKeys:this.getKeyValues(this.active,!0),selectedKey:this.getFirstKeyValue(_self.active,!0),callback:t};await this.$scope.$eval(n(e),s)}catch(t){a=!1,this.handleError(t)}return a},this.handleError=function(e){if(console.log(e),e instanceof XMLDocument){var t=e.getElementsByTagName("message")[0].textContent;e=t,console.log(e)}var a="";if(e)if("[object String]"===Object.prototype.toString.call(e))a=e;else{var t=e.msg||e.desc||e.message||e.error||e.responseText;this.isOData()&&e.error.message&&e.error.message.value&&(t=e.error.message.value),t&&(a=t)}a||(a=this.defaultNotSpecifiedErrorMessage);if(result=/<h1>(.*)<\/h1>/gmi.exec(a),result&&2<=result.length&&(a=result[1]),this.errorMessage=a,!(this.onError&&""!==this.onError))this.onError=function(e){Notification.error(e)};else if("string"==typeof this.onError)try{var n={currentData:this.active,filter:"",error:a,datasource:this,selectedIndex:this.cursor,index:this.cursor,selectedRow:this.active,item:this.active,selectedKeys:this.getKeyValues(this.active,!0),selectedKey:this.getFirstKeyValue(this.active,!0),callback:this.successCallback},s=this.$scope.$eval(this.onError,n);"function"==typeof s&&(this.onError=s)}catch(t){isValid=!1,Notification.error(t)}"function"==typeof this.onError&&this.onError.call(this,a)},this.observers&&0<this.observers.length&&$rootScope.$watch(function(){return this.active}.bind(this),function(e){e&&this.notifyObservers(e)}.bind(this),!0)},this.setFile=function(e,t,a){e&&"pattern"===e.$error||e&&toBase64(e,function(e){this.$apply=function(e){t[a]=e,scope.$apply(t)}.bind(scope),this.$apply(e)})},this.downloadFile=function(e,t){if(void 0!==t){for(var a=(window.hostApp||"")+this.entity+"/download/"+e,n=0;n<t.length;n++)a+="/"+t[n];var s={url:a,method:"GET",responseType:"arraybuffer"};$http(s).then(function(e){var t=new Blob([e.data],{type:"application/*"});$window.open(URL.createObjectURL(t))})}},this.openImage=function(e){if(-1==e.indexOf("https://")&&-1==e.indexOf("http://")){var t=$window.open("","_blank","height=300,width=400");t.document.write("<img src=\""+("data:image/png;base64,"+e)+"\"/>")}else $window.open(e,"_blank","height=300,width=400")},this.byteSize=function(e){function t(e,t){return-1!==t.indexOf(e,t.length-e.length)}function a(e){return t("==",e)?2:t("=",e)?1:0}return angular.isString(e)?function(e){return e.toString().replace(/\B(?=(\d{3})+(?!\d))/g," ")+" bytes"}(function(e){return 3*(e.length/4)-a(e)}(e)):""},this.insert=async function(obj,onSuccess,onError,forceSave){(await this.handleBeforeCallBack(this.onBeforeCreate))&&((this.dependentLazyPost||this.batchPost)&&!forceSave?(obj.__status="inserted",this.dependentLazyPost&&(obj.__parentId=eval(this.dependentLazyPost).active.__$id),this.hasMemoryData=!0,this.notifyPendingChanges(this.hasMemoryData),onSuccess&&onSuccess(obj)):service.save(obj).$promise.error(onError).then(onSuccess))},this.addDependentDatasource=function(dts){this.children||(this.children=[]),this.children.push(dts),this.dependentLazyPost?eval(this.dependentLazyPost).addDependentDatasource(dts):(!this.dependentData&&(this.dependentData=[]),this.dependentData.push(dts))},this.getParentDatasource=function(){return this.dependentLazyPost?eval(this.dependentLazyPost).getParentDatasource():this},this.updateObjectAtIndex=function(e,t,a){t=t||this.data,this.copy(e,t[a]),e.__$id=t[a].__$id,delete t[a].__status,delete t[a].__original,delete t[a].__originalIdx,delete t[a].__odatafiles,delete t[a].__$masterExpression},this.cleanDependentBuffer=function(){var e=[];$(this.data).each(function(){this.__status?"updated"==this.__status&&e.push(this.__original):e.push(this)}),this.data.length=0;for(var t=0;t<e.length;t++)delete e[t].__status,delete e[t].__original,delete e[t].__originalIdx,this.data.push(e[t]);if(this.postDeleteData)for(var t=0;t<this.postDeleteData.length;t++)delete this.postDeleteData[t].__status,delete this.postDeleteData[t].__original,delete this.postDeleteData[t].__originalIdx,this.data.push(this.postDeleteData[t]);this.data&&0<this.data.length?(this.cursor=0,this.active=this.data[0]):(this.cursor=-1,this.active=null),this.busy=!1,this.editing=!1,this.inserting=!1,this.postDeleteData=null,this.hasMemoryData=!1,this.notifyPendingChanges(this.hasMemoryData),this.events.read&&this.callDataSourceEvents("read",this.data),this.events.afterchanges&&this.callDataSourceEvents("afterchanges",this.data)},this.cancelBatchData=function(e){this.dependentData&&$(reverseArr(this.dependentData)).each(function(){this.cleanDependentBuffer()}),this.cleanDependentBuffer(),this.batchServiceData=[],e&&e()},this.flushDependencies=function(e,t){var a=[];if(this.dependentData){var n=function(){reduce(this.dependentData,function(e,n){a.push(e.storeDependentBuffer(function(){n()},void 0,t))}.bind(this),function(){e&&e(a)}.bind(this))}.bind(this);reduce(reverseArr(this.dependentData),function(e,a){e.storeDependentBuffer(function(){a()},!0,t)}.bind(this),function(){n()}.bind(this))}else e&&e(a)},this.postBatchData=function(e,t){let a=!t;t||(this.batchServiceData=[]);let n=()=>{a?(a=!1,this.performBatchPost(function(){this.postBatchData(e,!0)}.bind(this))):e&&e()};this.postingBatch=!0;var s=[],r=function(){this.storeDependentBuffer(function(){s.push(this.storeDependentBuffer(function(){reduce(this.dependentData,function(e,t){s.push(e.storeDependentBuffer(function(){t()},!1,a))}.bind(this),function(){this.postingBatch=!1;for(var e=0;e<s.length;e++)s[e]();n&&n()}.bind(this))}.bind(this),!1,a))}.bind(this),!0,a)}.bind(this);reduce(reverseArr(this.dependentData),function(e,t){e.storeDependentBuffer(function(){t()},!0,a)}.bind(this),function(){r()}.bind(this))};var reduce=function(e,t,a){if(!e||0==e.length)a();else{var n=e.reduce(function(e,a){return e.then(function(){return new Promise(function(e){t(a,e)})})},Promise.resolve());n.then(function(){a()})}};this.storeDependentBuffer=function(callback,onlyRemove,batchMode){var _self=this,dependentDS=eval(_self.dependentLazyPost);this.batchPost&&(dependentDS=this);var array=[];if(!onlyRemove&&(array=array.concat(_self.data),_self.memoryData))for(key in _self.memoryData)if(_self.memoryData.hasOwnProperty(key)){for(var mem=_self.memoryData[key],x=0;x<mem.data.length;x++)mem.data[x].__fromMemory=!0;array=array.concat(mem.data)}_self.postDeleteData&&(array=array.concat(_self.postDeleteData));var func=function(e,t){if(e.__status){if(!_self.parameters&&(_self.dependentLazyPostField&&(e[_self.dependentLazyPostField]=dependentDS.active),-1<_self.entity.indexOf("//"))){var a=dependentDS.getKeyValues(dependentDS.active),n="";for(var s in a)a.hasOwnProperty(s)&&(n+="/"+a[s]);n+="/",_self.entity=_self.entity.replace("//",n)}if(_self.parameters){var r=_self.getParametersMap(e.__parentId?e.__parentId:null);for(var s in r)r.hasOwnProperty(s)&&updateObjectValue(e,s,r[s]);let t=_self.getParametersBatchExpression(e.__parentId?e.__parentId:null);e.__$masterExpression=t}"inserted"==e.__status?function(e){var a;batchMode||(a=_self.processODataFiles(e)),_self.insert(e,function(n,s,r){if(r)return void t();var i=e.__sender,o=_self.getIndexOfListTempBuffer(e,array),d=!1,c=n;0<=o&&(c=array[o],d=array[o].__fromMemory,_self.updateObjectAtIndex(n,array,o)),_self.events.create&&!d&&(i&&(n=array[o],n.__sender=i),_self.callDataSourceEvents("create",n),delete n.__sender),a&&0<a.length?_self.sendODataFiles(a,n,function(e){_self.copy(e.data,c)}.bind(this),function(){t()}):t()},function(){t()},!0)}(e):"updated"==e.__status?function(e){var a;batchMode||(a=_self.processODataFiles(e)),_self.update(e,function(n,s,r){if(r)return void t();var i=e.__sender,o=_self.getIndexOfListTempBuffer(e,array),d=!1,c=n;0<=o&&(c=array[o],d=array[o].__fromMemory,_self.updateObjectAtIndex(n,array,o),n=array[o]),_self.events.update&&!d&&(i&&(n.__sender=i),_self.callDataSourceEvents("update",n),delete n.__sender),a&&0<a.length?_self.sendODataFiles(a,n,function(e){_self.copy(e.data,c)}.bind(this),function(){t()}):t()},function(){t()},!0)}(e):"deleted"==e.__status&&onlyRemove?function(e){_self.remove(e,function(a,n,s){if(s)return void t();if(_self.events.delete){var r={};_self.copy(e,r),delete r.__status,delete r.__original,delete r.__originalIdx,_self.callDataSourceEvents("delete",r)}t()},!0,null,function(){t()})}(e):t()}else t()},resetFunc=function(){onlyRemove||(this.busy=!1,this.editing=!1,this.inserting=!1,this.hasMemoryData=!1,this.memoryData=null,!batchMode&&this.notifyPendingChanges(this.hasMemoryData),this.events.afterchanges&&!batchMode&&this.callDataSourceEvents("afterchanges",this.data))}.bind(this);return reduce(array,func,function(){callback&&callback(),batchMode||(this.postDeleteData=null)}.bind(this)),resetFunc},this.getIndexOfListTempBuffer=function(e,t){t=t||this.data;for(var a=0;a<t.length;a++)if(t[a].__$id&&e.__$id&&t[a].__$id==e.__$id)return a;return-1},this.getObjectAsString=function(e,t){return((null==t||null==t)&&(t=!0),this.isOData())?window.objToOData(e,t):null==e?"":"number"==typeof e?e+"@@number":e instanceof Date?e.toISOString()+"@@datetime":"boolean"==typeof e?e+"@@boolean":e+""},this.update=async function(e,t,a,n){(await this.handleBeforeCallBack(this.onBeforeUpdate))&&((this.dependentLazyPost||this.batchPost)&&!n?t&&t(e):service.update(this.getEditionURL(e,n),e).$promise.error(a).then(t))},this.validateFields=function(e,t){var a=$(e);if(0<a.length&&"checkbox"!==a.get(0).type){var n=$("label[for=\""+a.get(0).id+"\"]"),s=a.get(0).id;return 0<n.length&&(s=n.text(),s&&(s=s.replaceAll("\n","").trim())),t&&(Notification.error(t.replace("{0}",s)),$(a.get(0)).addClass("ng-touched").removeClass("ng-untouched"),a.get(0).focus&&a.get(0).focus()),!1}return!0},this.getPatterns=function(){return $("input[ng-model*=\""+this.name+".\"]").filter(function(){return $(this).attr("pattern")})},this.missingRequiredField=function(e){if(0<this.getPatterns().length)return!1;if(this.checkRequired){var t=this.validateFields("[required][ng-model*=\""+this.name+".\"].ng-invalid-required",e?"":this.translate.instant("FieldIsRequired"));return t=t&&this.validateFields("[required][ng-model*=\""+this.name+".\"].ng-empty",e?"":this.translate.instant("FieldIsRequired")),t=t&&this.validateFields("[ng-model*=\""+this.name+".\"].ng-invalid",e?"":this.translate.instant("FieldIsInvalid")),!t}return!1},this.hasInvalidField=function(){return!(0<this.getPatterns().length)&&!!this.checkRequired&&0<$("input[ng-model*=\""+this.name+".\"]:invalid").not("input[type=checkbox]").not(".ng-empty").length},this.postSilent=function(e,t){this.post(e,t,!0)},this.updateActive=function(e){for(var t in e)e.hasOwnProperty(t)&&"__status"!=t&&(this.active[t]=e[t])},this.processODataFiles=function(e){var t=[];for(var a in e)if(-1<a.indexOf("__odataFile_")){var n={field:a.replace("__odataFile_",""),value:e[a]};t.push(n),e[n.field]=void 0,delete e[a]}return t},this.sendODataFiles=function(e,t,a,n){if(t&&e&&0<e.length){var s=this.entity,r=this.getKeyValues(t),i=["("],o=0;for(var d in r)0<o&&i.push(","),i.push(d),i.push("="),i.push(window.objToOData(r[d])),o++;i.push(")"),s+=i.join("");var c=JSON.parse(localStorage.getItem("_u"));reduce(e,function(e,n){let r=(window.hostApp||"")+s+"/"+e.field+"/$value";if(!_self.isOfflineMode()){var i=e.value,o=new XMLHttpRequest;o.open("PUT",r),o.setRequestHeader("X-Requested-With","XMLHttpRequest"),o.setRequestHeader("X-File-Name",i.name),o.setRequestHeader("Content-Type",(i.type||"application/octet-stream")+";charset=UTF-8"),window.isUsingCookie()||o.setRequestHeader("X-AUTH-TOKEN",c&&c.token?c.token:void 0),o.onreadystatechange=function(){if(4===o.readyState&&500===o.status){var r=new DOMParser,i=r.parseFromString(o.response,"text/xml");this.handleError(i)}4===o.readyState&&201===o.status&&service.call(s,"GET",{},!1).$promise.error(function(){Notification.error("Error send file")}).then(function(s){a?a({field:e.field,data:s}):t[e.field]=s[e.field],n()})}.bind(this),o.send(i)}else{let s={method:"PUT",data:e.value,url:r,headers:_self.headers};SyncService.toQueue(s),cronapi.internal.fileToBase64(e.value,s=>{t[e.field]=s,a&&a({field:e.field,data:t}),n()})}}.bind(this),function(){n&&n()}.bind(this))}else n&&n()},this.getFieldSchema=function(e){var t;if(this.schema)for(var a=0;a<this.schema.length;a++)if(this.schema[a].name==e){t=this.schema[a];break}return t},this.asyncPost=function(e,t,a){setTimeout(function(){this.post(e,t,a)}.bind(this),100)},this.copyWithoutAngularObj=function(){var e={};for(var t in this)this.hasOwnProperty(t)&&!t.startsWith("$")&&(e[t]=this[t]);return e},this.post=function(onSuccess,onError,silent,keepBuffer){!silent&&this.missingRequiredField()||!silent&&this.hasInvalidField()||(!keepBuffer&&(this.batchServiceData=[]),this.lastAction="post",this.busy=!0,this.inserting?this.insert(this.active,function(e,t,a){if(a&&this.dependentData&&!this.dependentLazyPost&&!this.batchPost)return void this.flushDependencies(()=>{this.performBatchPost(()=>{this.post(onSuccess,onError,silent,!0)})},!0);this.active.__sender&&(e.__sender=this.active.__sender),this.active.__$id&&(e.__$id=this.active.__$id);var n=function(a){if(this.active=e,this.handleAfterCallBack(this.onAfterCreate),this.onBackNomalState(),onSuccess&&onSuccess(this.active),this.events.create&&t&&(this.callDataSourceEvents("create",this.active),delete _self.active.__sender),this.events.memorycreate&&!t&&this.callDataSourceEvents("memorycreate",this.active),a)for(let e=0;e<a.length;e++)a[e]()}.bind(this),s=function(){this.data.push(e),!this.dependentData||this.dependentLazyPost||this.batchPost?n():this.flushDependencies(n,!1)}.bind(this);if(!t)s();else{var r=this.processODataFiles(this.active);r&&0<r.length?this.sendODataFiles(r,e,function(t){this.copy(t.data,e)}.bind(this),function(){s()}.bind(this)):s()}}.bind(this),onError):this.editing?this.update(this.active,function(obj,hotData,batchPostponed){if(batchPostponed&&this.dependentData&&!this.dependentLazyPost&&!this.batchPost)return void this.flushDependencies(()=>{this.performBatchPost(()=>{this.post(onSuccess,onError,silent,!0)})},batchPostponed);var odataFiles;hotData&&(odataFiles=this.processODataFiles(this.active));var foundRow,keyObj=this.getKeyValues(this.lastActive);this.data.forEach(function(currentRow){var found;if(this.lastActive.__$id&&currentRow.__$id)found=this.lastActive.__$id==currentRow.__$id;else{var dataKeys=this.getKeyValues(currentRow);for(var key in keyObj)if(dataKeys[key]&&dataKeys[key]===keyObj[key])found=!0;else{found=!1;break}}if(found){foundRow=currentRow;var lastActive={};this.copy(this.lastActive,lastActive),this.copy(obj,currentRow),this.lastActive&&this.lastActive.__sender&&(currentRow.__sender=this.lastActive.__sender),this.active=currentRow,(this.dependentLazyPost||this.batchPost)&&!currentRow.__status&&(currentRow.__status="updated",currentRow.__original=lastActive,this.hasMemoryData=!0,this.dependentLazyPost&&(currentRow.__parentId=eval(this.dependentLazyPost).active.__$id)),this.notifyPendingChanges(this.hasMemoryData),this.events.update&&hotData&&(this.callDataSourceEvents("update",this.active),delete this.active.__sender),this.events.memoryupdate&&!hotData&&this.callDataSourceEvents("memoryupdate",this.active)}}.bind(this));var back=function(e){if(foundRow&&this.handleAfterCallBack(this.onAfterUpdate),this.onBackNomalState(),onSuccess&&onSuccess(this.active),e)for(let t=0;t<e.length;t++)e[t]()}.bind(this),func=function(e){hotData?odataFiles&&0<odataFiles.length?this.sendODataFiles(odataFiles,foundRow,function(e){this.copy(e.data,foundRow)}.bind(this),function(){this.events.update&&hotData&&this.callDataSourceEvents("update",foundRow),back(e)}.bind(this)):back(e):back(e)}.bind(this);!this.dependentData||this.dependentLazyPost||this.batchPost?func():this.flushDependencies(func)}.bind(this),onError):0==this.data.length?this.startInserting(this.active,function(){this.post(onSuccess,onError,silent)}.bind(this)):this.startEditing(null,function(){this.post(onSuccess,onError,silent)}.bind(this)))},this.notifyPendingChanges=function(value){console.log("notifyPendingChanges : "+value),this.events.pendingchanges&&this.callDataSourceEvents("pendingchanges",value),this.dependentLazyPost&&eval(this.dependentLazyPost).notifyPendingChanges(value)},this.notifyPendingChanges=function(value){console.log("notifyPendingChanges : "+value),this.events.pendingchanges&&this.callDataSourceEvents("pendingchanges",value),this.dependentLazyPost&&eval(this.dependentLazyPost).notifyPendingChanges(value)},this.getConditionParams=function(){if(this.condition)try{var e=this.$interpolate(this.conditionExpression)(this.$scope),t=JSON.parse(e);if("object"==typeof t){if(t.params){let e;for(var a,n=0;n<t.params.length;n++)a=t.params[n].fieldValue,2<=a.length&&"'"==a.charAt(0)&&"'"==a.charAt(a.length-1)&&(a=a.substring(1,a.length-1)),""!==a&&void 0!==a&&null!==a&&(e?e+="&":e="",e+=t.params[n].fieldName+"="+encodeURIComponent(a));return e}}}catch(t){console.log(t)}},this.getDeletionURL=function(e,t){var a=this.getKeyValues(e.__original?e.__original:e,t),n="";this.isOData()&&(n="(");var s=0;for(var r in a)a.hasOwnProperty(r)&&(this.isOData()?(0<s&&(n+=","),n+=r+"="+this.getObjectAsString(a[r])):n+="/"+a[r],s++);this.isOData()&&(n+=")",n=encodeURI(n));var i=this.entity;this.entity.endsWith("/")&&(i=i.substring(0,i.length-1)),i+=n;let o=this.getConditionParams();return o&&(i=i+"?"+o),i},this.getEditionURL=function(e,t){var a=this.getKeyValues(e.__original?e.__original:e,t),n="";for(var s in this.isOData()&&(n="("),a)a.hasOwnProperty(s)&&(n+=this.isOData()?("("==n?"":",")+s+"="+this.getObjectAsString(a[s]):"/"+a[s]);this.isOData()&&(n+=")",n=encodeURI(n));var r=this.entity;this.entity.endsWith("/")&&(r=r.substring(0,r.length-1)),r+=n;let i=this.getConditionParams();return i&&(r=r+"?"+i),r},this.refreshActive=function(e,t){if(this.active&&"inserted"!=this.active.__status){var a=this.getEditionURL(this.active),n=this.getKeyValues(this.active);this.$promise=this.getService("GET")({method:"GET",url:a,headers:this.headers}).success(function(a){var s=null;this.isOData()?(s=a.d,this.normalizeObject(s)):a&&0<a.length&&(s=a[0]);var r=-1,o=0;this.data.forEach(function(e){var t=!1,a=0,i=0;for(var d in n)i++,e[d]&&e[d]===n[d]&&a++;a==i&&(t=!0),t&&(r=o,s&&(this.copy(s,e),this.copy(s,this.active))),o++}.bind(this)),-1==r?t&&t():(this.events.update&&this.callDataSourceEvents("update",this.active),e&&e(this.active))}.bind(this)).error(function(){t&&t()}.bind(this))}else e&&e(this.active)},this.buildURL=function(e,t){var a=this.getKeyValues(this.active,!1,t);"object"!=typeof e&&(e=[e]);var n="",s=0;for(var r in a){if(a.hasOwnProperty(r)){var i;i=Array.isArray(e)?e[s]:e[r],0<s&&(n+=" and "),n+=r+" eq "+this.getObjectAsString(i)}s++}return n},this.findObj=function(e,t,a,n,s){let r=s||deepCopy(this.keys),i=function(t){for(let a=0;a<r.length;a++)if(objectsAreEqual(e[a],t[r[a]]))return t}.bind(this),o=this.data.filter(i);if(o&&0<o.length)return void(a&&a(o));var d,c=this.buildURL(e,s);d={params:{$filter:c}},(null==c||0==c.length)&&(d={}),this.fetch(d,{success:function(e){if(a){let t=e.filter(i);a(t)}}.bind(this),error:function(){n&&n()}},void 0,{lookup:!0})},this.getColumn=function(e){var t=[];return $.each(this.data,function(a,n){t.push(n[e])}),t},this.onBackNomalState=function(){this.$scope.safeApply(function(){this.busy=!1,this.editing=!1,this.inserting=!1;let e=this.dependentData&&this.dependentData.filter(e=>e.inserting||e.editing);e&&e.forEach(e=>e.cancel()),this.noticeStatusChange()}.bind(this))},this.cancel=function(){this.inserting&&(0<=this.cursor?this.active=this.data[this.cursor]:this.active={}),this.editing&&(this.active=this.lastActive),this.onBackNomalState(),this.lastAction="cancel",this.dependentData&&$(this.dependentData).each(function(){this.cleanDependentBuffer()}),this.batchServiceData=[]},this.removeODataFields=function(e){for(var t in e)e.hasOwnProperty(t)&&e[t]&&e[t].__deferred&&delete e[t];return e},this.retrieveDefaultValues=function(e,t){if(this.isEventData()||this.isLocalData()||this.isOfflineMode())this.$scope.safeApply(function(){this.active={},(this.isLocalData()||this.isOfflineMode())&&(this.active[this.keys[0]]=this.uuidv4()),this.updateWithParams(),t&&t()}.bind(this));else if(e)this.active=e||{},this.updateWithParams(),t&&t();else if(0<=this.entity.indexOf("cronapi")||this.isOData()){var a=this.entity;a+=this.entity.endsWith("/")?"__new__":"/__new__",this.$promise=$httpLegacy({method:"GET",url:this.removeSlash((window.hostApp||"")+a),headers:this.headers}).success(function(e){this.isOData()?(this.active=this.removeODataFields(e.d),this.normalizeData(this.active)):this.active=e,this.updateWithParams(),t&&t()}.bind(this)).error(function(){this.active={},this.updateWithParams(),t&&t()}.bind(this))}else this.active={},this.updateWithParams(),t&&t()};var updateObjectValue=function(e,t,a){for(var n,s=t.split("."),r=0;r<s.length;r++)n=s[r],r==s.length-1?e[n]=a:((void 0===e[n]||null==e[n])&&(e[n]={}),e=e[n])};this.updateWithParams=function(){if(this.parameters){var e=this.getParametersMap();for(var t in e)e.hasOwnProperty(t)&&updateObjectValue(this.active,t,e[t])}},this.resetFieldsStatus=function(){var e=setInterval(function(){$("input[ng-model*=\""+this.name+".\"]").is(":visible")?($("input[ng-model*=\""+this.name+".\"]:invalid:empty").removeClass("ng-invalid ng-invalid-required"),clearInterval(e)):$("input[ng-model*=\""+this.name+".\"].cronMultiSelect")&&clearInterval(e)},100)},this.noticeStatusChange=function(){this.changeTitle(),this.handleBeforeCallBack(this.onChangeStatus)},this.changeTitle=function(){if($("#starter").length&&$("#starter").attr("primary-datasource")===this.name){var e=this.translate.instant($rootScope.viewTitleOnly),t=$rootScope.systemName&&$rootScope.systemName.length?" - "+$rootScope.systemName:"";this.inserting?e+=" - "+this.translate.instant("Inserting"):this.editing&&(e+=" - "+this.translate.instant("Editing")),$("h1.title:first").text(e),window.document.title=e+t}},this.startInserting=function(e,t){this.retrieveDefaultValues(e,function(){if(this.active.__$id||(this.active.__$id=uuid()),this.children&&this.children.length){let e=this.getKeyValues(this.active);for(let t in e)e.hasOwnProperty(t)&&(null==e[t]||null==e[t])&&"_objectKey"==t&&(this.active[t]="$autogenerated$"+this.uuidv4())}this.inserting=!0,this.onStartInserting&&this.onStartInserting(),t&&t(this.active),this.events.creating&&this.callDataSourceEvents("creating",this.active),this.resetFieldsStatus(),this.noticeStatusChange()}.bind(this))},this.operationPouchDB=function(e,t,a){if(!SyncService.synchronizing&&(this.hasOfflineSupport()||this.isLocalData())&&e&&"GET"!==e){let n=this.getPouchDB();"DELETE"==e?n.get(t._objectKey).then(function(e){return n.remove(e)}.bind(this)).then(a).catch(function(e){console.error(e)}):this.$scope.cronapi.internal.updatePouchDB(n,[t],a)}},this.getPouchDB=function(){return cronapi.internal.getPouchDB(_self.localDBName)},this.isNavigatorOffline=function(){return!navigator.onLine},this.hasOfflineSupport=function(){return this.offline},this.isOfflineMode=function(){return this.isNavigatorOffline()&&this.hasOfflineSupport()},this.startEditing=function(e,t){if(e)this.active=this.copy(e),this.lastActive=e;else{if(0==this.data.length)return void this.startInserting(null,t);this.lastActive=this.active,this.active=this.copy(this.active)}this.editing=!0,t&&t(this.active),this.events.editing&&this.callDataSourceEvents("updating",this.active),this.resetFieldsStatus(),this.noticeStatusChange()},this.removeSilent=function(e,t,a){this.remove(e,null,!1,t,a,!0)},this.remove=function(e,t,a,n,s,r){this.busy=!0;var i=async function(e,t){e||(e=this.active);var r=this.getKeyValues(e,a);t=t||function(t,a,s){if(!s){for(var o=0;o<this.data.length;o++){var d;if(e.__$id&&this.data[o].__$id)d=this.data[o].__$id==e.__$id;else{var c=this.getKeyValues(this.data[o]);for(var l in r)if(r.hasOwnProperty(l))if(c[l]&&c[l]===r[l])d=!0;else{d=!1;break}}if(d){if(this.dependentLazyPost||this.batchPost){var u={};this.copy(this.data[o],u),u.__status="deleted",u.__originalIdx=o,this.events.memorydelete&&this.callDataSourceEvents("memorydelete",u),"inserted"!=this.data[o].__status&&(!this.postDeleteData&&(this.postDeleteData=[]),this.postDeleteData.push(u),this.hasMemoryData=!0,this.notifyPendingChanges(this.hasMemoryData))}this.data.splice(o,1);var p=o-1;0>p&&(p=0),p>this.data.length-1&&(p=this.data.length),this.data[p]?(this.active=this.data[p],this.cursor=p):(this.active=null,this.cursor=-1),this.onBackNomalState();break}}this.handleAfterCallBack(this.onAfterDelete),n&&n(e),this.events.delete&&a&&this.callDataSourceEvents("delete",e)}}.bind(this),(await this.handleBeforeCallBack(this.onBeforeDelete))&&((this.dependentLazyPost||this.batchPost)&&!a?t():service.remove(this.getDeletionURL(e,a),e).$promise.error(s).then(t))}.bind(this);if(!a&&!r&&this.deleteMessage&&0<this.deleteMessage.length){let a={title:this.translate.instant("yes"),value:function(){i(e,t)}},n={title:this.translate.instant("no"),primaryValue:"true",value:()=>{this.filter()}};window.cronapi.notification.confirmDialogAlert("warning",this.translate.instant("Users.view.Confirmacao"),this.deleteMessage,[n,a])}else i(e,t)},this.getKeyValues=function(rowData,forceOriginalKeys,useKeys){for(var keys=useKeys||this.keys,keyValues={},i=0;i<keys.length;i++){var key=keys[i],rowKey=null;try{rowKey=Array.isArray(rowData)?eval("rowData[0]."+key):eval("rowData."+key)}catch(t){}keyValues[key]=rowKey}return keyValues}.bind(this),this.getFirstKeyValue=function(rowData,forceOriginalKeys){for(var keys=this.keys,keyValues={},i=0;i<this.keys.length;i++){var key=this.keys[i],rowKey=null;try{rowKey=eval("rowData."+key)}catch(t){}return rowKey}}.bind(this),this.objectIsEquals=function(e,t){var a=this.getKeyValues(e),n=this.getKeyValues(t);for(var s in a)if(a.hasOwnProperty(s)){if(!n.hasOwnProperty(s))return!1;if(a[s]!==n[s])return!1}return!0},this.hasNext=function(){return this.data&&this.cursor<this.data.length-1},this.hasPrevious=function(){return this.data&&0<this.cursor},this.order=function(e){this._savedProps.order=e},this.getActiveValues=function(){return this.active&&!this._activeValues&&$rootScope.$watch(function(){return this.active}.bind(this),function(){this._activeValues=this.getRowValues(this.active)}.bind(this),!0),this._activeValues},this.__defineGetter__("activeValues",function(){return _self.getActiveValues()}),this.getRowValues=function(e){var t=[];for(var a in e)e.hasOwnProperty(a)&&t.push(e[a]);return t},this.next=function(){return this.hasNext()||this.nextPage(),this.active=this.copy(this.data[++this.cursor],{}),this.active},this.nextPage=function(e){var t=(window.hostApp||"")+this.entity;return this.hasNextPage()?void(this.offset=1==this.apiVersion||-1==t.indexOf("/cronapi/")?parseInt(this.offset)+parseInt(this.rowsPerPage):parseInt(this.offset)+1,this._savedProps&&this._savedProps.params&&delete this._savedProps.params.$skip,this.fetch(this._savedProps,{success:function(a){(!a||a.length<parseInt(this.rowsPerPage))&&(1==this.apiVersion||-1==t.indexOf("/cronapi/"))&&(this.offset=parseInt(this.offset)-this.data.length),e&&e()},canceled:function(){e&&e()},error:function(){e&&e()}},!0)):void(e&&e())},this.prevPage=function(){this.append||this.preppend||(this.offset=parseInt(this.offset)-this.data.length,this._savedProps&&this._savedProps.params&&delete this._savedProps.params.$skip,0>this.offset?this.offset=0:0<=this.offset&&this.fetch(this._savedProps,{success:function(e){e&&0!==e.length||(this.offset=0)}},!0))},this.hasNextPage=function(){return this.hasMoreResults&&-1!=this.rowsPerPage},this.hasPrevPage=function(){return 0<this.offset&&!this.append&&!this.prepend},this.previous=function(){if(!this.hasPrevious())throw"Dataset Overflor Error";return this.active=this.copy(this.data[--this.cursor],{}),this.active},this.findObjInDs=function(e,t){var a=!1,n=null;if(null===e||void 0===e)return n;var s=null,r=null;let o=t=>{var n=this.data[t];for(var s in d)a=!!(e.hasOwnProperty(s)&&e[s]===n[s]);return a};if("object"==typeof e&&null!==e){var d;0<this.data.length&&(d=this.getKeyValues(this.data[0]));for(var c=0;c<this.data.length;c++)if(e.__$id&&this.data[c].__$id?(a=e.__$id==this.data[c].__$id,!a&&(a=o(c))):a=o(c),a){s=c,r=this.copy(this.data[s],{});var l=this.getKeyValues(this.data[s]),u=!0;for(var p in l)if(void 0===l[p]){u=!1;break}u||this.fetchChildren()}}else if(Array.isArray(this.keys))for(var c=0;c<this.data.length;c++)this.data[c][this.keys[0]]===e&&(s=c,r=this.copy(this.data[s],{}),a=!0);return null!==r&&(n=r,t&&(n={cursor:s,obj:r})),n},this.goTo=function(e){var t=this.findObjInDs(e,!0);return null===t?t:(this.cursor=t.cursor,this.active=t.obj,this.active)},this.getCursor=function(){return this.cursor},this.filter=function(e,t){var a=this.offset;this.offset=0,this.fetch({path:e},{beforeFill:function(){this.cleanup()},error:function(){this.offset=a},success:function(e){t&&t(e)}})},this.doSearchAll=function(e,t){this.searchTimeout=null;var a=this.offset;this.offset=0,this.fetch({params:{filter:"%"+e+"%",filterCaseInsensitive:!!t}},{beforeFill:function(){this.cleanup()},error:function(){this.offset=a}})},this.searchAll=function(e,t){this.searchTimeout&&(clearTimeout(this.searchTimeout),this.searchTimeout=null),this.searchTimeout=setTimeout(function(){this.doSearchAll(e,t)}.bind(this),500)},this.doSearch=function(e,t){this.searchTimeout=null;var a=this.offset;this.offset=0;var n;this.isOData()?(n={params:{$filter:e}},(null==e||0==e.length)&&(n={})):n={params:{filter:e,filterCaseInsensitive:!!t}},this.fetch(n,{beforeFill:function(){this.cleanup()},error:function(){this.offset=a}})},this.search=function(e,t){this.searchTimeout&&(clearTimeout(this.searchTimeout),this.searchTimeout=null),this.caseInsensitive=t,this.terms=e,this.searchTimeout=setTimeout(function(){this.doSearch(e,t)}.bind(this),500)},this.refresh=function(e,t,a){this.cleanup(),void 0===a&&(a=0),e.length>=a&&this.filter(t+"/"+e)},this.cleanup=function(e){e||(e={}),this.offset=0,this.rowsCount=-1,this.data.length=0,e.ignoreAtive||(this.cursor=-1,this.active={}),this.hasMoreResults=!1},this.current=function(){return this.active||this.data[0]},this.getLink=function(e){if(this.links)for(var t=0;t<this.links.length;t++)if(this.links[t].rel==e)return this.links[t].href},this.isOData=function(){return 0<this.entity.indexOf("odata")},this.isEventData=function(){return void 0!==this.onGET&&null!==this.onGET&&""!==this.onGET},this.isLocalData=function(){return 0==this.entity.indexOf("local://")},this.normalizeValue=function(e,t,a){return(null==t||null==t)&&(t=!1),window.oDataToObj(e,t,a)},this.normalizeObject=function(e){for(var t in e)if(e.hasOwnProperty(t)){var a=e[t];if(a)if("object"==typeof a)this.normalizeObject(a);else{let n=this.getFieldFromSchema(t);e[t]=this.normalizeValue(a,void 0,n)}}},this.normalizeData=function(e){if(e){delete e.__metadata;for(var t=0;t<e.length;t++)this.normalizeObject(e[t])}return e},this.getAllData=function(){var e=[];if(e=e.concat(this.data),this.memoryData)for(key in this.memoryData)if(this.memoryData.hasOwnProperty(key)){var t=this.memoryData[key];t.data&&(e=e.concat(t.data))}return this.postDeleteData&&(e=e.concat(this.postDeleteData)),e},this.getParametersMap=function(parentId){var parameters,obj,mapParams,map={};if(parentId){parameters=this.parametersExpression;for(var arr=eval(this.dependentLazyPost).getAllData(),i=0;i<arr.length;i++)if(arr[i].__$id==parentId){obj=arr[i];break}mapParams=this.getParametersMap()}else parameters=this.parameters;if(parameters&&0<parameters.length)for(var parts=parameters.split(";"),i=0;i<parts.length;i++){var part=parts[i],binary=part.split("=");if(2==binary.length){var value=binary[1];if(!parentId)map[binary[0]]=binary[1]?this.normalizeValue(value,!0):null;else if(binary[1].match(DEP_PATTERN)){var g=DEP_PATTERN.exec(value);if(-1!=g[1].indexOf(".active.")){var field=g[1].replace(this.dependentLazyPost+".active.","");obj&&(map[binary[0]]=obj[field])}else map[binary[0]]=mapParams[binary[0]]}else map[binary[0]]=mapParams[binary[0]]}}return map},this.setParameters=function(e){this.parameters=e,this.fetch({params:{}})},this.getParametersBatchExpression=function(parentId){var parameters,obj,expression="";parameters=this.parametersExpression;let ds=eval(this.dependentLazyPost);if(ds){var arr=ds.getAllData();if(ds.active&&ds.active.__$id==parentId)obj=ds.active;else for(var i=0;i<arr.length;i++)if(arr[i].__$id==parentId){obj=arr[i];break}}if(parameters&&0<parameters.length)for(var parts=parameters.split(";"),i=0;i<parts.length;i++){var part=parts[i],binary=part.split("=");if(2==binary.length){var value=binary[1];if(binary[1].match(DEP_PATTERN)){var g=DEP_PATTERN.exec(value);if(-1!=g[1].indexOf(".active.")){var field=g[1].replace(this.dependentLazyPost+".active.","");obj&&(""!=expression&&(expression+=","),expression+=binary[0]+":$"+parentId+"."+field)}}}}return expression},this.removeSlash=function(e){return 0==e.indexOf("http://")?"http://"+e.substring(7).split("//").join("/"):0==e.indexOf("https://")?"https://"+e.substring(8).split("//").join("/"):e},this.setDataSourceEvents=function(e){this.events=e},this.addDataSourceEvents=function(e){for(var t in e)e.hasOwnProperty(t)&&(this.events[t]||(this.events[t]=[]),"[object Array]"!==Object.prototype.toString.call(this.events[t])&&(this.events[t]=[this.events[t]]),this.events[t].push(e[t]))},this.removeDataSourceEvents=function(e){for(var t in e)if(e.hasOwnProperty(t)){this.events[t]||(this.events[t]=[]),"[object Array]"!==Object.prototype.toString.call(this.events[t])&&(this.events[t]=[this.events[t]]);for(var a=[].concat(this.events[t]),n=0;n<a.length;n++)a[n]==e[t]&&this.events[t].splice(n,1)}},this.callDataSourceEvents=function(e){if(this.events){var t=this.events[e];if(t){"[object Array]"!==Object.prototype.toString.call(t)&&(t=[t]);for(var a=[],n=1;n<arguments.length;n++)a.push(arguments[n]);for(var s=[],n=0;n<t.length;n++)s.push(t[n]);for(var r=0;r<s.length;r++)try{s[r].apply(null,a)}catch(e){console.log("Error","Event no more exist in datasource")}}}},this.storeInMemory=function(e){this.memoryData||(this.memoryData={});var t={data:[],cursor:this.cursor,params:this.getParametersMap(),rowCount:this.getRowsCount()};t.data=deepCopy(this.data,t.data),this.memoryData[e]=t},this.restoreFromMemory=function(e){this.memoryData||(this.memoryData={});var t=this.memoryData[e];return t&&(this.cursor=t.cursor,this.rowsCount=t.rowCount),delete this.memoryData[e],deepCopy(t.data)},this.hasPendingChanges=function(){var e=this.hasMemoryData;return this.children&&$(this.children).each(function(){e=e||this.hasPendingChanges()}),e},this.isPostingBatchData=function(){var isPosting=!0==this.postingBatch;return this.dependentLazyPost&&(isPosting=isPosting||eval(this.dependentLazyPost).isPostingBatchData()),isPosting},this.fetchChildren=function(e){this.children?reduce(this.children,function(e,t){e.fetch({},function(){t()})}.bind(this),function(){e&&e()}.bind(this)):e&&e()};var splitExpression=function(e){var t,a=null;-1==e.indexOf("@=")?-1==e.indexOf("<=")?-1==e.indexOf(">=")?-1==e.indexOf(">")?-1==e.indexOf("<")?(a=e.trim().split("="),t="="):(a=e.trim().split("<"),t="<"):(a=e.trim().split(">"),t=">"):(a=e.trim().split(">="),t=">="):(a=e.trim().split("<="),t="<="):(a=e.trim().split("@="),t="=");var n=typeof this.normalizeValue(a[1],!0);if(this.isOData()){if("="==t&&"string"==n)return"startswith(tolower("+a[0]+"), "+a[1].toLowerCase()+")";if("="==t)return a[0]+" eq "+a[1];if("!="==t)return a[0]+" ne "+a[1];if(">"==t)return a[0]+" gt {"+a[1];if(">="==t)return a[0]+" ge "+a[1];if("<"==t)return a[0]+" lt "+a[1];if("<="==t)return a[0]+" le "+a[1]}else return"string"==n?a[0]+"@"+t+"%"+a[1]+"%":a[0]+t+a[1]}.bind(this),parseFilterExpression=function(e){var t="";if(e){var a=e.split(";"),n=!0;if(0<a.length)for(var s,r=/[\w\d]+=.+/gm,o=0;o<a.length;o++)if(s=a[o].match(r),!s){n=!1;break}if(n)for(var d,o=0;o<a.length;o++)d=splitExpression(a[o]),""!=t&&(t+=this.isOData()?" and ":";"),t+=d;else t=e}return t}.bind(this),getQueryOperator=function(e){return"="==e?" eq ":"!="==e?" ne ":">"==e?" gt ":">="==e?" ge ":"<"==e?" lt ":"<="==e?" le ":void 0}.bind(this),executeRight=function(right){var result="";if(null!=right&&null!=right)if(right.startsWith(":")||right.startsWith("datetimeoffset'")||right.startsWith("datetime'"))result=right;else{if(right&&"string"==typeof right&&2<=right.length&&("'"==right.charAt(0)&&"'"==right.charAt(right.length-1)||"\""==right.charAt(0)&&"\""==right.charAt(right.length-1)))try{result=eval("'"+right.substring(1,right.length-1).replaceAll("'","\\'")+"'")}catch(e){result=eval(right)}else""!=right&&(result=eval(right));result instanceof Date?result="datetimeoffset'"+result.toISOString()+"'":"string"==typeof result?result="'"+result+"'":(void 0===result||null==result)&&(result="null")}return result}.bind(this);this.isEmpty=function(e){return""===e||void 0===e||null===e||"''"===e},this.getFieldFromSchema=function(e){if(this.schema)for(var t=0;t<this.schema.length;t++)if(this.schema[t].name===e)return this.schema[t].type;return null},this.parserCondition=function(e,t,a){var n="",s=e.type;if(t||(t="default"),e.args)for(var r=0;r<e.args.length;r++){var o=e.args[r],d=s;if(o.args&&0<o.args.length){var c=this.parserCondition(o,t);this.isEmpty(c)&&("ignore"==t||"clean"==t)?a&&(a.clean="clean"==t):!this.isEmpty(c)&&(a&&(a.count=a.count?a.count+1:1),""!=n&&(n+=" "+d.toLowerCase()+" "),n+="( "+c+" ) ")}else{var c=executeRight(o.right);if(this.isEmpty(c)&&("ignore"==t||"clean"==t||"wait"==t))a&&(a.clean="clean"==t,a.wait="wait"==t);else if(!this.isEmpty(c)){var l=!0,u="DateTime"===this.getFieldFromSchema(o.left),p=void 0;if(u&&-1===c.indexOf("datetime")&&(p=this.$scope.cronapi.dateTime.getMomentObj(c),l=p.isValid()),!l)"null"===c&&(n+=`${o.left} ${getQueryOperator(o.type)} null`);else if(a&&(a.count=a.count?a.count+1:1),""!=n&&(n+=" "+d.toLowerCase()+" "),"%"==o.type)n+=this.isLocalData()?"contains("+o.left+", "+c.toLowerCase()+")":"substringof("+c.toLowerCase()+", tolower("+o.left+"))";else if(p){var g=p.toDate().getTimezoneOffset(),y=timeZoneOffset-g;p.add(y,"minutes"),n+=o.left+getQueryOperator(o.type)+"datetimeoffset'"+p.toISOString()+"'"}else n+=o.left+getQueryOperator(o.type)+c}}}return n.trim()}.bind(this),this.refreshData=function(e){if(this.lastFetch&&!this.hasMemoryData&&this.enabled&&!this.inserting&&!this.editing){window.Pace&&(window.Pace.options.ajax.trackWebSockets=!1,window.Pace.options.ajax.trackMethods=[]);var t=function(){window.Pace&&(window.Pace.options.ajax.trackWebSockets=!0,window.Pace.options.ajax.trackMethods=["PUT","POST","GET"]),e&&e()};this.lastFilter=null,this.lastFetch.fetchOptions=this.lastFetch.fetchOptions||{},this.lastFetch.fetchOptions.active=this.copy(this.active),this.lastFetch.fetchOptions.active.__$id=void 0,this.fetch(this.lastFetch.properties,{success:t,error:t},this.lastFetch.isNextOrPrev,this.lastFetch.fetchOptions,!0)}else e&&e()},this.startAutoRefresh=function(){0<this.autoRefresh&&setTimeout(function(){this.refreshData(function(){this.startAutoRefresh()}.bind(this))}.bind(this),this.autoRefresh)},this.isParentBusy=function(){return!!this.dependentLazyPost&&(eval(this.dependentLazyPost).busy||eval(this.dependentLazyPost).isParentBusy())},this.fetch=function(properties,callbacksObj,isNextOrPrev,fetchOptions,silent,fromVisibleEvent){fetchOptions||(fetchOptions={});let busy=this.busy,masterDetail=this.parameters&&0<this.parameters.length;if(fetchOptions.ignoreBusy&&(busy=!1),busy||this.postingBatch||!masterDetail&&this.isParentBusy())return void setTimeout(function(){this.fetch(properties,callbacksObj,isNextOrPrev,fetchOptions)}.bind(this),1e3);var callbacks=callbacksObj||{};this.lastFetch={properties:properties,isNextOrPrev:isNextOrPrev,fetchOptions:fetchOptions};var sucessHandler=function(data,headers,raw){var springVersion=!1;this.responseHeaders=headers||{};var total=-1;-1<this.entity.indexOf("//")&&0>this.entity.indexOf("://")&&(data=[]),raw||(data?"[object Array]"!==Object.prototype.toString.call(data)&&(data&&data.links&&"[object Array]"===Object.prototype.toString.call(data.content)?(this.links=data.links,data=data.content,springVersion=!0):this.isOfflineMode()?(total=data.total_rows,data=this.$scope.cronapi.internal.normalizePouchDBData(data.rows,!0)):this.isOData()?(total=parseInt(data.d.__count),data=data.d.results,this.normalizeData(data)):this.isLocalData()?(total=data.total_rows,data=data.rows,this.normalizeData(data)):data=[data]):data=[]);for(var n=0;n<data.length;n++)data[n].__$id||(data[n].__$id=uuid());if(!fetchOptions.lookup&&(this.fetched=!0,callbacks.beforeFill&&callbacks.beforeFill.apply(this,this.data),isNextOrPrev?(this.prepend&&Array.prototype.unshift.apply(this.data,data),this.append&&Array.prototype.push.apply(this.data,data),!this.prepend&&!this.append&&(Array.prototype.push.apply(this.data,data),!fetchOptions.ignoreAtive&&(0<this.data.length?fetchOptions.active?this.goTo(fetchOptions.active):this.$scope.safeApply(()=>{this.active=data[0],this.cursor=0}):(this.active={},this.cursor=-1)))):(this.cleanup(fetchOptions),-1!=total&&(this.rowsCount=total),Array.prototype.push.apply(this.data,data),0<this.data.length&&!fetchOptions.ignoreAtive&&(fetchOptions.active?this.goTo(fetchOptions.active):this.$scope.safeApply(()=>{this.active=data[0],this.cursor=0}))),this.columns=[],0<this.data.length))for(var i=0;i<this.data[0].length;i++)this.columns.push(this.getColumn(i));if(callbacks.success&&callbacks.success.call(this,data),!fetchOptions.lookup){this.events.read&&this.callDataSourceEvents("read",data),this.hasMoreResults=data.length>=this.rowsPerPage,springVersion&&(this.hasMoreResults=null!=this.getLink("next")),this.isOfflineMode()&&(this.hasMoreResults=!1),this.autoPost&&this.startAutoPost(),this.loaded=!0,this.loadedFinish=!0,this.lastLoadedTime=Date.now(),this.handleAfterCallBack(this.onAfterFill);var thisDatasourceName=this.name;this.isOData()||$("datasource").each(function(idx,elem){var dependentBy=null,dependent=window[elem.getAttribute("name")];if(dependent&&""!==elem.getAttribute("dependent-by")&&null!=elem.getAttribute("dependent-by")){try{dependentBy=JSON.parse(elem.getAttribute("dependent-by"))}catch(ex){dependentBy=eval(elem.getAttribute("dependent-by"))}dependentBy?dependentBy.name==thisDatasourceName&&!dependent.filterURL&&eval(dependent.name).fetch():console.log("O dependente "+elem.getAttribute("dependent-by")+" do pai "+thisDatasourceName+" ainda n\xE3o existe.")}})}if("insert"==this.startMode&&(this.startMode=null,this.startInserting()),"edit"==this.startMode&&(this.startMode=null,this.startEditing()),0<this.autoRefresh&&!this.autoRefreshStarted&&(this.autoRefreshStarted=!0,this.startAutoRefresh()),!this.isOfflineMode()&&this.hasOfflineSupport()){var db=this.getPouchDB();this.$scope.cronapi.internal.updatePouchDB(db,data)}}.bind(this);if(this.busy)return void(callbacks.canceled&&callbacks.canceled());if(-1<this.entity.indexOf("//")&&0>this.entity.indexOf("://"))return void(callbacks.canceled&&callbacks.canceled());if(!this.enabled)return this.cleanup(),void(callbacks.canceled&&callbacks.canceled());var props=properties||{};props.params=props.params||{};var resourceURL=(window.hostApp||"")+this.entity+(props.path||this.lastFilterParsed||""),filter="",order="",cleanData=!1,canProceed=!0;if(this.parameters&&0<this.parameters.length){var parsedParameters=fetchOptions.lookup?this.$interpolate(this.parametersExpression)(this.$scope):this.parameters;for(var parts=parsedParameters.split(";"),partsExpression=this.parametersExpression.split(";"),i=0;i<parts.length;i++){var part=parts[i],partExpression=partsExpression[i],binary=part.split("="),binaryExpression=partExpression.split("=");if(2==binary.length){var filterClause,g=DEP_PATTERN.exec(binaryExpression[1]);if(!((this.isEmpty(binary[1])||this.isAutoGeneratedValue(binary[1]))&&this.dependentLazyPost&&g[1]&&g[1].startsWith(this.dependentLazyPost+".")))this.isEmpty(binary[1])?("clean"==this.parametersNullStrategy||"default"==this.parametersNullStrategy)&&(filterClause="null",cleanData=!0):filterClause=this.getObjectAsString(this.normalizeValue(binary[1],!0),!1);else if("clean"==this.parametersNullStrategy||"default"==this.parametersNullStrategy){cleanData=!0;var dds=eval(this.dependentLazyPost);filterClause=dds.active&&dds.active.__$id?eval(this.dependentLazyPost).active.__$id:"memory"}filterClause&&(filterClause=binary[0]+getQueryOperator("=")+filterClause,""!=filter&&(filter+=this.isOData()?" and ":";"),filter+=filterClause)}}}if(!canProceed)return void(callbacks.canceled&&callbacks.canceled());var urlParams;let waitData=!1;if(this.condition){try{var parsedCondition=fetchOptions.lookup?this.$interpolate(this.conditionExpression)(this.$scope):this.condition;var obj=JSON.parse(parsedCondition);if("object"==typeof obj){var resultData={};this.conditionOdata=obj.expression?this.parserCondition(obj.expression,this.parametersNullStrategy,resultData):this.parserCondition(obj,this.parametersNullStrategy,resultData);var filterCount=0;let e=this.conditionExpression.match(/{{(?!null).*?}}/g);if(e&&(filterCount=e.length),!cleanData&&resultData.clean&&(cleanData=!0),!cleanData&&resultData.wait&&(waitData=!0),cleanData||"one"!==this.loadDataStrategy||resultData.count&&!(1>resultData.count)||(cleanData=!0),!cleanData&&"all"===this.loadDataStrategy&&filterCount&&(!resultData.count||resultData.count<filterCount)&&(cleanData=!0),cleanData||"button"!==this.loadDataStrategy||"button"===fetchOptions.origin||(cleanData=!0),obj.params)for(var value,i=0;i<obj.params.length;i++)value=obj.params[i].fieldValue,2<=value.length&&"'"==value.charAt(0)&&"'"==value.charAt(value.length-1)&&(value=value.substring(1,value.length-1)),""!==value&&void 0!==value&&null!==value&&(props.params[obj.params[i].fieldName]=value)}else this.conditionOdata=this.condition}catch(t){console.log(t)}var conditionFilter=parseFilterExpression(this.conditionOdata);conditionFilter&&(""!=filter&&(filter+=this.isOData()?" and ":";"),filter+=conditionFilter)}if(this.orderBy)for(var orderField,orders=this.orderBy.split(";"),i=0;i<orders.length;i++)orderField=orders[i],orderField&&(""!=order&&(order+=this.isOData()?",":";"),order+=this.isOData()?orderField.replace("|ASC"," asc").replace("|DESC"," desc"):orderField);if(this.dependentLazyPost&&!this.parameters&&!this.condition&&!fromVisibleEvent&&eval(this.dependentLazyPost).active){var checkRequestId="",keyDependentLazyPost=this.getKeyValues(eval(this.dependentLazyPost).active);for(var key in keyDependentLazyPost){checkRequestId=keyDependentLazyPost[key];break}if(checkRequestId&&0<checkRequestId.length&&-1==resourceURL.indexOf(checkRequestId))return void(callbacks.canceled&&callbacks.canceled())}0<this.rowsPerPage&&(this.isOData()?((void 0===props.params.$top||null===props.params.$top)&&(props.params.$top=this.rowsPerPage),(void 0===props.params.$skip||null===props.params.$skip)&&(props.params.$skip=parseInt(this.offset)*parseInt(this.rowsPerPage)),props.params.$inlinecount="allpages"):1==this.apiVersion||-1==resourceURL.indexOf("/cronapi/")?(props.params.limit=this.rowsPerPage,props.params.offset=this.offset):(props.params.size=this.rowsPerPage,props.params.page=this.offset));var paramFilter=null;this.isOData()&&props.params.$filter&&(paramFilter=props.params.$filter),!this.isOData()&&props.params.filter&&(paramFilter=props.params.filter),paramFilter&&(filter&&""!=filter?this.isOData()?(filter+=" and (",filter+=paramFilter+")"):(filter+=";",filter+=paramFilter):filter=paramFilter);var paramOrder=null;this.isOData()&&props.params.$orderby&&(paramOrder=props.params.$orderby),!this.isOData()&&props.params.order&&(paramOrder=props.params.order),paramOrder&&(order=paramOrder),filter&&(this.isOData()?props.params.$filter=filter:props.params.filter=filter),order&&(this.isOData()?props.params.$orderby=order:props.params.order=order);var localSuccess;if(this.hasMemoryData&&filter){if(this.memoryData||(this.memoryData={}),this.lastFilter==filter)return void(callbacks.canceled&&callbacks.canceled());var id=filter,mem=this.memoryData[id];if(mem){this.storeInMemory(this.lastFilter);var data=this.restoreFromMemory(id);return this.lastFilter=filter,void sucessHandler(data,null,!0)}localSuccess=function(){this.storeInMemory(this.lastFilter)}.bind(this)}if(this.stopAutoPost(),this._savedProps=props,waitData)return void setTimeout(function(){fetchOptions.ignoreBusy=!0,this.fetch(properties,callbacksObj,isNextOrPrev,fetchOptions)}.bind(this),100);if(cleanData)return localSuccess&&localSuccess(),this.lastFilter=filter,void sucessHandler([],null,!0);this.busy=!0;var httpError=function(e){this.busy=!1,silent||this.handleError(e),callbacks.error&&callbacks.error.call(this,e)}.bind(this);let callService=function(){this.$promise=this.getService("GET")({method:"GET",url:this.removeSlash(resourceURL),params:props.params,headers:this.headers,filter:filter,offlineMode:this.isOfflineMode()}).success(function(e,t,a){localSuccess&&localSuccess(),this.lastFilter=filter,this.busy=!1,a?sucessHandler(e,a()):sucessHandler(e,null)}.bind(this)).error(function(e,t,a,n){httpError(e,t,a,n)}.bind(this))}.bind(this);this.fetchOnVisible&&!this.parent.is(":visible")?this.holdServiceCall=callService:(this.holdServiceCall=void 0,callService())},this.getRowsCount=function(){return-1==this.rowsCount?this.data.length:this.rowsCount},this.notifyObservers=function(){for(var e in this.observers)if(this.observers.hasOwnProperty(e)){var t=this.observers[e];$timeout(function(){t.notify.call(t,this.active)}.bind(this),1)}},this.notify=function(e){if(e){var t=this.watchFilter;t=t.replace(/\{([A-z][A-z|0-9]*)\}/gim,function(t,a){return e.hasOwnProperty(a)?e[a]:""}),this.fetch({params:{q:t}})}},this.addObserver=function(e){this.observers.push(e)},this.sum=function(e){for(var t=0,a=0;a<this.data.length;a++)this.data[a][e]&&(t+=this.data[a][e]);return t},this.copy=function(e,t,a){if(null===e||"[object Object]"!==Object.prototype.toString.call(e))return e;for(var n in t=t||{},e)e.hasOwnProperty(n)&&-1==n.indexOf("$$")&&(t[n]=this.copy(e[n]));if(a)for(var s=0;s<this.keys.length;s++){var n=this.keys[s],r=t[n];(""==r||null==r)&&delete t[n]}return t};var deepCopyArray=function(e,t){if(null===e||"[object Array]"!==Object.prototype.toString.call(e))return e;t=t||[];for(var a=0;a<e.length;a++)t.push(deepCopy(e[a]));return t},deepCopy=function(e,t){if("[object Array]"===Object.prototype.toString.call(e))return deepCopyArray(e,t);if(null===e||"[object Object]"!==Object.prototype.toString.call(e))return e;for(var a in t=t||{},e)e.hasOwnProperty(a)&&(t[a]=deepCopy(e[a]));return t};if(this.startAutoPost=function(){this.unregisterDataWatch=$rootScope.$watch(function(){return this.data}.bind(this),function(e,t){if(!this.enabled)return void this.unregisterDataWatch();var a=e.length-t.length;if(0<a)for(var n=1;n<=a;n++)this.insert(e[e.length-n],function(){});else if(0>a)for(var s=this,r=t.filter(function(t){return 0==e.filter(function(e){return s.objectIsEquals(t,e)}).length}),n=0;n<r.length;n++)this.remove(r[n],function(){})}.bind(this))},this.stopAutoPost=function(){this.unregisterDataWatch&&(this.unregisterDataWatch(),this.unregisterDataWatch=void 0)},this.hasDataBuffered=function(){return!!(this.dependentBufferLazyPostData&&0<this.dependentBufferLazyPostData.length)},window.afterDatasourceCreate){var args=[$q,$timeout,$rootScope,$window,Notification];window.afterDatasourceCreate.apply(this,args)}this.init()};return this.storeDataset=function(e){this.datasets[e.name]=e},this.initDataset=function(props,scope,$compile,$parse,$interpolate,instanceId,translate){var endpoint=props.endpoint?props.endpoint:"",dts=new DataSet(props.name,scope,props.fetchOnVisible);let canStoreDataset=!0;$rootScope[props.name]&&!$rootScope[props.name].insideModal&&props.insideModal?(canStoreDataset=!1,console.log(`%c${translate.instant("Datasource.Error").toUpperCase()} - ${translate.instant("Datasource.Duplicate").toUpperCase()}${props.name.toUpperCase()}`,"background: #000; color: #FFF; font-size:14px;")):($rootScope[props.name]=dts,window[props.name]=dts,$rootScope[props.name+".instanceId"]=instanceId);var defaultApiVersion=1;if(dts.entity=props.entity,dts.localDBName=props.entity,!isCronapiApiPath(dts.entity))if(dts.entity.match(DS_ID))dts.entity="api/cronapi/odata/v2/"+dts.entity.replaceAll(".","/");else if(dts.isLocalData()){var path=dts.entity.substring(dts.entity.indexOf("//")+2,dts.entity.length).split("/");dts.localDBType=dts.entity.substring(0,dts.entity.indexOf("://")),dts.localDBName=path[0],dts.localDBStorage=path[1],dts.localDBVersion=path[2]||1}if(app&&app.config&&app.config.datasourceApiVersion&&(defaultApiVersion=app.config.datasourceApiVersion),dts.translate=translate,dts.apiVersion=props.apiVersion?parseInt(props.apiVersion):defaultApiVersion,dts.keys=props.keys&&0<props.keys.length?props.keys.split(","):[],dts.rowsPerPage=props.rowsPerPage?props.rowsPerPage:100,dts.append=props.append,dts.prepend=props.prepend,dts.endpoint=props.endpoint,dts.filterURL=props.filterURL,dts.autoPost=props.autoPost,dts.autoRefresh=props.autoRefresh,dts.deleteMessage=props.deleteMessage,dts.enabled=props.enabled,dts.offset=props.offset?props.offset:0,dts.onError=props.onError,dts.defaultNotSpecifiedErrorMessage=props.defaultNotSpecifiedErrorMessage,dts.onAfterFill=props.onAfterFill,dts.onBeforeCreate=props.onBeforeCreate,dts.onAfterCreate=props.onAfterCreate,dts.onBeforeUpdate=props.onBeforeUpdate,dts.onAfterUpdate=props.onAfterUpdate,dts.onBeforeDelete=props.onBeforeDelete,dts.onAfterDelete=props.onAfterDelete,dts.onChangeStatus=props.onChangeStatus,dts.onGET=props.onGet,dts.onPOST=props.onPost,dts.onPUT=props.onPut,dts.onDELETE=props.onDelete,dts.dependentBy=props.dependentBy,dts.parameters=props.parameters,dts.parametersNullStrategy=props.parametersNullStrategy,dts.parametersExpression=props.parametersExpression,dts.checkRequired=props.checkRequired,dts.batchPost=props.batchPost,dts.condition=props.condition,dts.conditionExpression=props.conditionExpression,dts.orderBy=props.orderBy,dts.schema=props.schema,dts.startMode=props.startMode,dts.lazy=props.lazy,dts.$compile=$compile,dts.$parse=$parse,dts.$interpolate=$interpolate,dts.loadDataStrategy=props.loadDataStrategy,dts.offline=props.offline,dts.insideModal=props.insideModal,props.dependentLazyPost&&0<props.dependentLazyPost.length&&(dts.dependentLazyPost=props.dependentLazyPost,setTimeout(()=>{eval(dts.dependentLazyPost).addDependentDatasource(dts)},0)),dts.dependentLazyPostField=props.dependentLazyPostField,dts.headers=props.headers,canStoreDataset&&this.storeDataset(dts),dts.allowFetch=!0,dts.dependentBy&&""!==dts.dependentBy&&""!==dts.dependentBy.trim()){dts.allowFetch=!1;var dependentBy=null;try{dependentBy=JSON.parse(dependentBy)}catch(ex){dependentBy=eval(dependentBy)}dependentBy&&dependentBy.loadedFinish&&(dts.allowFetch=!0)}if(!props.lazy&&dts.allowFetch&&"[object String]"!==Object.prototype.toString.call(props.watch)&&!props.filterURL){var queryObj={};setTimeout(function(){dts.fetch({params:queryObj},{success:function(e){e&&0<e.length&&(this.active=e[0],this.cursor=0)}})}.bind(this),0)}return props.lazy&&props.autoPost&&dts.startAutoPost(),props.watch&&"[object String]"===Object.prototype.toString.call(props.watch)&&(this.registerObserver(props.watch,dts),dts.watchFilter=props.watchFilter),props.filterURL&&0<props.filterURL.length&&dts.allowFetch&&dts.filter(props.filterURL),dts},this.registerObserver=function(e,t){this.datasets[e].addObserver(t)},this}]).directive("datasource",["DatasetManager","$timeout","$parse","Notification","$translate","$location","$rootScope","$compile","$interpolate",function(e,t,a,n,s,r,i,o){return{restrict:"E",priority:9999999,scope:!0,template:"",link:function(e,t){(function(e,a,n){$(e).each(function(){var e=$(this),s=$(document.createElement(n),{html:e.html()});$.each(this.attributes,function(){s.attr(this.name,this.value)}),s.attr("inside-modal",0<$(t).closest(".modal").length);var r=e.data("events");if(r)for(var i in r)for(var d in r[i])s[i](r[i][d].handler);o(s)(a),e.replaceWith(s)})})(t,e,"cronapp-datasource")}}}]);let datasourceRepeat=1;app.directive("crnRepeat",["DatasetManager","$compile","$parse","$injector","$rootScope",function(DatasetManager,$compile,$parse,$injector,$rootScope){return{restrict:"A",priority:9999998,terminal:!0,link:function(scope,element,attrs,controllers,transclude){const indexAttribute=(e,t,a)=>{let n=e.parent().find(`[data-repeater=${t}]`);n.each&&n.each((e,t)=>{let n=$(t);n.find(`[${a}]`).each((t,n)=>{let s=$(n),r=s.attr(`${a}`);s.attr(`${a}`,`${r}-cronapp-${e}`)})})};$(window).ready(()=>{datasourceRepeat++;let isDatasource=!1,dataRepeaterId=`datasourceRepeat${datasourceRepeat}`;if(attrs.crnRepeat){if(scope.data=DatasetManager.datasets,scope.data[attrs.crnRepeat])scope[dataRepeaterId]=scope.data[attrs.crnRepeat],isDatasource=!0;else{scope[dataRepeaterId]=[];var value=$parse(attrs.crnRepeat)(scope);value instanceof String&&value.startsWith("[")&&value.endsWith("]")&&(value=eval(value)),scope[dataRepeaterId]=value}isDatasource?(element.attr("ng-init",attrs.crnRepeat+" = {}; "+attrs.crnRepeat+".active = rowData"),element.attr("ng-repeat",`rowData in ${dataRepeaterId}.data`)):element.attr("ng-repeat",`rowData in ${dataRepeaterId}`),element.attr("data-repeater",dataRepeaterId)}var tagName=element[0].tagName;$compile(element,null,9999998)(scope);let watchForRepeater=isDatasource?`${dataRepeaterId}.data`:`${dataRepeaterId}`;scope.$watchCollection(watchForRepeater,function(){if("ion-slide"==tagName.toLowerCase()){var e=$injector.get("$ionicSlideBoxDelegate");e.update()}indexAttribute(element,dataRepeaterId,"id"),indexAttribute(element,dataRepeaterId,"for")})})}}}]).directive("crnDatasource",["DatasetManager","$parse","$rootScope",function(e,t){return{restrict:"A",scope:!0,priority:9999998,link:function(a,n,s){a.data=e.datasets,a.data[s.crnDatasource]?a.datasource=a.data[s.crnDatasource]:(a.datasource={},a.datasource.data=t(s.crnDatasource)(a))}}}]).directive("cronappDatasource",["DatasetManager","$timeout","$parse","Notification","$translate","$location","$rootScope","$compile","$interpolate","SyncService",function(e,t,a,n,s,r,i,o,d){return{restrict:"E",scope:!0,template:"",link:function(c,l,u){initDatasource(c,l,u,e,t,a,n,s,r,i,o,d)}}}]),angular.module("sync.service",[]).service("SyncService",["$http",function(e){let t={start:function(){this.dbSync=this.getSyncServicePouchDB(),this.observeConnection()},observeConnection:async function(){setInterval(()=>this.isNavigatorOffline()||this.synchronizeOfflineData(),15000)},toQueue:function(e){let t={data:e,created:Date.now()};this.dbSync.post(t).catch(e=>console.error(e))},synchronizeOnError:async function(t,e){this.synchronizing=!1,console.log("Error synchronizing doc",e,"response",t)},synchronizeOnSuccess:async function(e,t){try{await this.dbSync.remove(e),this.removeArray(e,t),0<t.length?this.sendData(t[0],t):this.synchronizing=!1}catch(t){this.synchronizing=!1}},canByPassError:function(t){let e=!1;if(t.data&&t.data.error&&t.data.error.message&&t.data.error.message.value){let a=t.data.error.message.value;"N\xE3o foi poss\xEDvel encontrar a entidade requisitada."===a||"Requested entity could not be found."===a?e=!0:void 0}return e},sendData:async function(t,a){let n=t.data;e(n).then(()=>this.synchronizeOnSuccess(t,a)).catch(n=>this.canByPassError(n)&&this.synchronizeOnSuccess(t,a)||this.synchronizeOnError(n,t,a)),console.log(`Synchronization - sended record number ${a.length}`)},optimizeQueue:function(e){let t=e.rows.filter(e=>"DELETE"===e.doc.data.method);t.forEach(async t=>{let a=e.rows.filter(e=>{let a=e.doc.data.originalObject||e.doc.data.rawData,n=t.doc.data.originalObject||t.doc.data.rawData;return a&&n&&a._objectKey===n._objectKey&&"DELETE"!==e.doc.data.method});a.forEach(async t=>{this.dbSync.remove(t.doc),this.removeArray(t,e.rows)})});let a=[];return e.rows.forEach(e=>a.push(e.doc)),a.sort((e,t)=>e.created-t.created),a},synchronizeOfflineData:async function(){try{if(!this.synchronizing){let e=await this.dbSync.allDocs({include_docs:!0,attachments:!0});if(e.rows.length){console.log("Synchronization started"),this.synchronizing=!0;let t=this.optimizeQueue(e);this.sendData(t[0],t)}}}catch(t){console.log(t)}},removeArray(e,t){if(e&&t){let a=t.indexOf(e);-1<a&&t.splice(a,1)}},isNavigatorOffline:function(){return!navigator.onLine},getSyncServicePouchDB:function(){return cronapi.internal.getPouchDB("syncService")},synchronizing:null,dbSync:null,lastStatus:null};return t.start(),t}]);
package/gulpfile.js CHANGED
@@ -19,6 +19,6 @@ gulp.task('minify-js', function() {
19
19
  .pipe(gulp.dest('dist/js/'));
20
20
  });
21
21
 
22
- gulp.task('build', ['minify-js']);
22
+ gulp.task('build', gulp.series('minify-js'));
23
23
 
24
- gulp.task('default', ['build']);
24
+ gulp.task('default', gulp.series('build'));
@@ -2011,7 +2011,7 @@ angular.module('datasourcejs', [])
2011
2011
  xhr.setRequestHeader('X-File-Name', file.name);
2012
2012
  xhr.setRequestHeader('Content-Type', (file.type||'application/octet-stream') + ';charset=UTF-8' );
2013
2013
  if (!window.isUsingCookie()) {
2014
- xhr.setRequestHeader('X-AUTH-TOKEN', _u?.token);
2014
+ xhr.setRequestHeader('X-AUTH-TOKEN', _u && _u.token ? _u.token : undefined);
2015
2015
  }
2016
2016
 
2017
2017
  xhr.onreadystatechange = function(){
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cronapp-common-js",
3
- "version": "3.2.1-SP.3",
3
+ "version": "3.2.1-SP.30",
4
4
  "description": "Cronapp Commons Functions",
5
5
  "main": "parser.js",
6
6
  "scripts": {
@@ -22,7 +22,7 @@
22
22
  "javascript"
23
23
  ],
24
24
  "devDependencies": {
25
- "gulp": "^3.9.1",
25
+ "gulp": "5.0.0",
26
26
  "gulp-autoprefixer": "^3.1.1",
27
27
  "gulp-babel": "^8.0.0",
28
28
  "gulp-babel-minify": "^0.5.1",