define (["dojo/_base/declare","dojo/dom-style","dijit/_WidgetBase","dojo/query","dojo/request/xhr"],function(declare,domStyle,_WidgetBase,query,xhr) {return declare("core/model",[_WidgetBase],{saving:false,postCreate:function() {this.inherited(arguments);},__doPOST:function(url,data,sync,callback,errorCallBack) {try {this.__doVERB("POST",url,data,sync,callback,errorCallBack)} catch(e) {console.error(e);}},__doGET:function(url,query,sync,callback,errorCallBack) {try {this.__doVERB("GET",url,query,sync,callback,errorCallBack)} catch(e) {console.error(e);}},__doPATCH:function(url,data,sync,callback,errorCallBack) {try {this.__doVERB("PATCH",url,data,sync,callback,errorCallBack)} catch(e) {console.error(e);}},__doPUT:function(url,data,sync,callback,errorCallBack) {try {this.__doVERB("PUT",url,data,sync,callback,errorCallBack)} catch(e) {console.error(e);}},__doDELETE:function(url,data,sync,callback,errorCallBack) {try {this.__doVERB("DELETE",url,data,sync,callback,errorCallBack)} catch(e) {console.error(e);}},__doVERB:function(verb,url,data_or_query,sync,callback,errorCallBack) {var self=this,func,payload,app;data_or_query=data_or_query||{};app=this.__getBaseApp();if(!data_or_query.compid) {if(app.user) {data_or_query.compid=app.user.companyId;}} if(verb=="POST") {payload={method:verb,data:data_or_query,sync:(typeof sync==="undefined"?false:sync),handleAs:'json'};} else if(verb=="GET") {payload={method:verb,sync:(typeof sync==="undefined"?false:sync),handleAs:'json'};if(typeof data_or_query=="string") {payload.data=data_or_query;} else {payload.query=data_or_query;}} else if(verb=="PATCH") {payload={method:verb,data:data_or_query,sync:(typeof sync==="undefined"?false:sync),handleAs:'json'};} else if(verb=="PUT") {payload={method:verb,data:data_or_query,sync:(typeof sync==="undefined"?false:sync),handleAs:'json'};} else if(verb=="DELETE") {payload={method:verb,data:data_or_query,sync:(typeof sync==="undefined"?false:sync),handleAs:'json'};} else {throw "invalid payload provided";} if(!app.csrf) {console.error("no csrf");} payload.headers={"Content-Type":"application/x-www-form-urlencoded","X-CSRF-TOKEN":app.csrf||"",'X-Requested-With':'XMLHttpRequest'};if(app.user&&app.user.companyId) {payload.headers['X-Company-ID']=app.user.companyId;} xhr(url,payload).then(function(o) {if(o.resp!='eureka') {if(errorCallBack) {errorCallBack(o);} else {alert(o.message);}} else {if(o.compid) {if(o.compid!=app.user.companyId) {if(typeof app.companyIdMismatch==="function") {app.companyIdMismatch();return;}}} if(typeof callback==="function") {callback(o);}}},function(err) {if(!self.__parseErrorStatus(err.response,errorCallBack)) {window.trackJs.track(err);}});},__getApp:function() {if(typeof window.app==="object") {if(typeof window.app.appFrame==="object") {if(typeof window.app.appFrame.contentWindow==="object") {if(typeof window.app.appFrame.contentWindow.app==="object") {if(typeof window.app.appFrame.contentWindow.app.App==="object") {return window.app.appFrame.contentWindow.app.App;} return window.app.appFrame.contentWindow.app;} else if(typeof window.app.appFrame.contentWindow._app==="object") {if(typeof window.app.appFrame.contentWindow._app.App==="object") {return window.app.appFrame.contentWindow._app.App;} return window.app.appFrame.contentWindow._app;}}}} if(typeof window.app!=="object") {} if(typeof _app==="object") {if(typeof _app.App==="object") {return _app.App;} if(typeof _app.app==="object") {return _app.app;} return _app;} return window.app;},__getBaseApp:function() {if(typeof window.app==="object") {if(typeof window.app.appFrame==="object") {if(typeof window.app.appFrame.contentWindow==="object") {if(typeof window.app.appFrame.contentWindow.app==="object") {return window.app.appFrame.contentWindow.app;} else if(typeof window.app.appFrame.contentWindow._app==="object") {return window.app.appFrame.contentWindow._app;}}}} if(typeof window.app!=="object") {if(typeof _app==="object") {return _app;}} return window.app;},__parseErrorStatus:function(response,errorCallBack) {var text,app=this.__getApp();if(response.status) {switch(response.status) {case 400:if(typeof errorCallBack==="function") {text=(JSON.parse(response.text)||{});errorCallBack(response);} else {try {app.hideLoader();} finally {text=((JSON.parse(response.text)||{}).error_message||"E999");alert("Sorry we are unable to perform your request, "+text);}} return true;break;case 401:try {if(typeof app.clearNcrTimeCardsIntv()==="function") {app.clearNcrTimeCardsIntv();} if(typeof app.clearSessionIntv==="function") {app.clearSessionIntv();} app.hideLoader();} catch(er) {} finally {if(typeof errorCallBack==="function") {errorCallBack(response);} else {console.error("Your session has timed out. MD1",response);alert("Your session has timed out. MD1");window.location="../login";}} return true;break;case 403:try {if(typeof app.clearNcrTimeCardsIntv()==="function") {app.clearNcrTimeCardsIntv();} if(typeof app.clearSessionIntv==="function") {app.clearSessionIntv();} app.hideLoader();} catch(er) {} finally {if(typeof errorCallBack==="function") {errorCallBack(response);} else {alert("You are not authorized to perform this request.");window.location="../login";}} return true;break;default:try {app.hideLoader();} finally {if(typeof errorCallBack==="function") {errorCallBack(response);return true;} text=((JSON.parse(response.text)||{}).error_message||"E999");alert("Sorry we are unable to perform your request, "+text);} return false;break;}} else {return false;}}});});