function PoolObjectViewModel(){self=this;self.selectedPoolObject=ko.observable();self.PoolObjects=ko.observableArray();self.PoolObject=ko.observable();self.skip=0;self.take=10;self.filterOutOrderOnly=!1;self.poolObjectsAvailable=ko.observable(!1);self.commandSelectPoolObject=function(a){self.selectedPoolObject(a);$.mobile.changePage("PoolObjectSummary.html","none",!0,!0)};self.commandGoToCalculation=function(){Log("PoolObject - gotoCalculation");Log(self.PoolObject());Log(PageParameters.createNewCalculation);
CalcViewModel=window.CurrentlyEditedCalculation;PageParameters.createNewCalculation?CalcViewModel.reset():CalcViewModel=window.CurrentlyEditedCalculation;CalcViewModel.setValues(self.PoolObject());window.requestFileSystem?window.requestFileSystem(LocalFileSystem.PERSISTENT,0,function(a){Log("root: "+a.root.fullPath);a.root.getDirectory("ExCalc",{create:!0,exclusive:!1},function(a){a.getFile("blob.html",{create:!0,exclusive:!1},function(a){var b=a.fullPath.replace("blob.html",""),c=new FileTransfer;
a.remove();a=(new Date).getTime();c.download(self.PoolObject().Thumbnail,b+$.md5(self.PoolObject().Thumbnail)+a+"."+self.PoolObject().Thumbnail.split(".").pop(),function(a){Log("download complete: "+a.toURI());CalcViewModel.imageURL(a.toURI());window.CurrentlyEditedCalculation=CalcViewModel;Log("Create new");Log(PageParameters.createNewCalculation);PageParameters.createNewCalculation?$.mobile.changePage("EditCalculation.html","none",!0,!0):$.mobile.changePage("EditCalculation2.html","none",!0,!0)},
function(a){Log("download error source "+a.source);Log("download error target "+a.target);Log("upload error code: "+a.code);window.CurrentlyEditedCalculation=CalcViewModel;$.mobile.changePage("EditCalculation2.html","none",!0,!0)})},function(){Log("blad3")})},function(){Log("blad3")})},function(){Log("blad1")}):(CalcViewModel.imageURL(self.PoolObject().Thumbnail),window.CurrentlyEditedCalculation=CalcViewModel,Log("Create new"),Log(PageParameters.createNewCalculation),PageParameters.createNewCalculation?
$.mobile.changePage("EditCalculation.html","none",!0,!0):$.mobile.changePage("EditCalculation2.html","none",!0,!0))};self.commandDownloadPoolObjects=function(){MainViewModel.checkInternetConnection()&&(Overlay.create(!0,Culture.translations().stringMsgDownloadingPoolObjects),ServiceDataProvider.downloadPoolObjects(self.skip,self.take,self.filterOutOrderOnly).done(function(){setTimeout(function(){Overlay.destroy()},1)}).always(function(a){Log(a);if(this.state()==ASyncState.Resolved)!a.length||a.length<
self.take?self.poolObjectsAvailable(!1):self.poolObjectsAvailable(!0),self.PoolObjects(self.PoolObjects().concat(a)),self.skip+=self.take;else switch(a){case 3015:case 3016:MainViewModel.handleLostSession("PoolObject.html",self.commandDownloadPoolObjects)}}).fail(function(){Overlay.hideLoader();Overlay.showTextOnlyLoader(Culture.translations().stringTextInternetConnectionProblem);setTimeout(function(){Overlay.destroy()},2E3)}))};self.commandDownloadPoolObject=function(){MainViewModel.checkInternetConnection()&&
(Overlay.create(!0,Culture.translations().stringMsgDownloadingPoolObjectDetails),ServiceDataProvider.downloadPoolObject(self.selectedPoolObject().Id).done(function(){setTimeout(function(){Overlay.destroy()},1)}).always(function(a){Log(a);if(this.state()==ASyncState.Resolved)a.transmissionEnum=TransmissionModes.getText(a.Transmission),self.PoolObject(a);else switch(a){case 3015:case 3016:MainViewModel.handleLostSession("PoolObject.html",self.commandDownloadPoolObject)}}).fail(function(){Overlay.hideLoader();
Overlay.showTextOnlyLoader(Culture.translations().stringTextInternetConnectionProblem);setTimeout(function(){Overlay.destroy()},2E3)}))};self.commandRefreshPoolObjects=function(){MainViewModel.checkInternetConnection()&&(Overlay.create(!0,Culture.translations().stringMsgDownloadingPoolObjects),self.skip=0,self.poolObjectsAvailable(!0),window.scrollTo(0,0),ServiceDataProvider.downloadPoolObjects(self.skip,self.take,self.filterOutOrderOnly).done(function(){setTimeout(function(){Overlay.destroy()},1)}).always(function(a){Log(a);
if(this.state()==ASyncState.Resolved)self.PoolObjects([]),self.PoolObjects(self.PoolObjects().concat(a)),self.skip+=self.take;else switch(a){case 3015:case 3016:MainViewModel.handleLostSession("PoolObject.html",self.commandRefreshPoolObjects)}}).fail(function(){Overlay.hideLoader();Overlay.showTextOnlyLoader(Culture.translations().stringTextInternetConnectionProblem);setTimeout(function(){Overlay.destroy()},2E3)}))};self.resetPoolObjectSummary=function(){self.PoolObject(null)}};
