varjio=function(){vara=function(a,b){varc={};returna=a||{},b=b||{},c.name="jioException",c.message=a.message||"Unknown Reason.",c.toString=function(){returnc.name+": "+c.message},c},b=function(b,c){vard=a(b,c);b=b||{};vare=b.command;returnd.name="invalidCommandState",d.toString=function(){returnd.name+": "+e.getLabel()+", "+d.message},d},c=function(b,c){vard=a(b,c);b=b||{};vare=b.storage.getType();returnd.name="invalidStorage",d.toString=function(){returnd.name+": "+'Type "'+e+'", '+d.message},d},d=function(b,c){vard=a(b,c),e=b.type;returnd.name="invalidStorageType",d.toString=function(){returnd.name+": "+e+", "+d.message},d},e=function(b,c){vard=a(b,c);returnd.name="jobNotReadyException",d},f=function(b,c){vard=a(b,c);returnd.name="tooMuchTriesJobException",d},g=function(b,c){vard=a(b,c);returnd.name="invalidJobException",d},h=function(a,b){vard={};a=a||{},b=b||{};vare={};returne.type=a.type||"",d.getType=function(){returne.type},d.setType=function(a){e.type=a},d.execute=function(a){a.executeOn(d)},d.isValid=function(){return!0},d.validate=function(a){a.validate(d)},d.serialized=function(){return{type:d.getType()}},d.saveDocument=function(a){throwc({storage:d,message:"Unknown storage."})},d.loadDocument=function(a){d.saveDocument()},d.removeDocument=function(a){d.saveDocument()},d.getDocumentList=function(a){d.saveDocument()},d},i=function(a,b){varc=h(a,b);a=a||{},b=b||{};vard={};returnd.storage_a=a.storagelist||[],c.beforeExecute=function(a,b){},c.execute=function(a,b){vare;c.validate(a),c.beforeExecute(a,b);for(e=0;e<d.storage_a.length;e++)d.storage_a[e].execute(a);c.afterExecute(a,b)},c.afterExecute=function(a,b){c.done()},c.serialized=function(){return{type:d.type,storagelist:d.storagelist}},c},j=function(a,c){vard=function(a,c){vard={};a=a||{},c=c||{};vare={};returne.commandlist={saveDocument:l,loadDocument:i,removeDocument:j,getDocumentList:h},a.label&&e.commandlist[a.label]?(e.label=a.label,deletea.label,e.commandlist[e.label](a,c)):(e.path=a.path||"",e.tried=0,e.option=a.option||{},e.respond=e.option.onResponse||function(){},e.done=e.option.onDone||function(){},e.fail=e.option.onFail||function(){},e.retry=function(){d.setMaxRetry(-1),d.fail({status:0,statusText:"Fail Retry",message:"Impossible to retry."})},e.end=function(){},d.getLabel=function(){return"command"},d.getPath=function(){returne.path},d.getOption=function(a){returne.option[a]},d.validate=function(a){d.validateState()},d.getTried=function(){returne.tried},d.setMaxRetry=function(a){e.option.max_retry=a},d.execute=function(a){d.validate(a),e.tried++,a.execute(d)},d.executeOn=function(a){},d.validateState=function(){if(e.path==="")throwb({command:d,message:"Path is empty"})},d.done=function(a){console.log("done"),e.done(a),e.respond({status:n(),value:a}),e.end()},d.fail=function(a){e.option.max_retry===0||e.tried<e.option.max_retry?e.retry():(console.log("fail"),e.fail(a),e.respond({status:o(),error:a}),e.end())},d.onEndDo=function(a){e.end=a},d.onRetryDo=function(a){e.retry=a},d.serialized=function(){return{label:d.getLabel(),tried:e.tried,max_retry:e.max_retry,path:e.path,option:e.option}},d)},h=function(a,b){varc=d(a,b);returna=a||{},b=b||{},c.getLabel=function(){return"getDocumentList"},c.executeOn=function(a){a.getDocumentList(c)},c},i=function(a,b){varc=d(a,b);returna=a||{},b=b||{},c.getLabel=function(){return"loadDocument"},c.executeOn=function(a){a.loadDocument(c)},c},j=function(a,b){varc=d(a,b);returna=a||{},b=b||{},c.getLabel=function(){return"removeDocument"},c.executeOn=function(a){a.removeDocument(c)},c},l=function(a,c){vare=d(a,c);a=a||{},c=c||{};varf=a.content;e.getLabel=function(){return"saveDocument"},e.getContent=function(){returnf};varg=e.validate;returne.validate=function(a){if(typeoff!="string")throwb({command:e,message:"No data to save"});g(a)},e.executeOn=function(a){a.saveDocument(e)},e},m=function(a,b){varc={};returna=a||{},b=b||{},c.getLabel=function(){return"job status"},c.canStart=function(){},c.canRestart=function(){},c.serialized=function(){return{label:c.getLabel()}},c},n=function(a,b){varc=m(a,b);returna=a||{},b=b||{},c.getLabel=function(){return"done"},c.canStart=function(){return!1},c.canRestart=function(){return!1},c},o=function(a,b){varc=m(a,b);returna=a||{},b=b||{},c.getLabel=function(){return"fail"},c.canStart=function(){return!1},c.canRestart=function(){return!0},c},p=function(a,b){varc=m(a,b);returna=a||{},b=b||{},c.getLabel=function(){return"initial"},c.canStart=function(){return!0},c.canRestart=function(){return!0},c},q=function(a,b){varc=m(a,b);returna=a||{},b=b||{},c.getLabel=function(){return"on going"},c.canStart=function(){return!1},c.canRestart=function(){return!1},c},r=function(a,b){varc=m(a,b);a=a||{},b=b||{};vard={};returnd.job_id_a=a.job_id_array||[],d.threshold=0,c.getLabel=function(){return"wait"},d.refreshJobIdArray=function(){vara=[],b;for(b=0;b<d.job_id_a.length;b+=1)x.jobIdExists(d.job_id_a[b])&&a.push(d.job_id_a[b]);d.job_id_a=a},c.waitForJob=function(a){varb;for(b=0;b<d.job_id_a.length;b+=1)if(d.job_id_a[b]===a.getId())return;d.job_id_a.push(a.getId())},c.dontWaitForJob=function(a){varb,c=[];for(b=0;b<d.job_id_a.length;b+=1)d.job_id_a[b]!==a.getId()&&c.push(d.job_id_a[b]);d.job_id_a=c},c.waitForTime=function(a){d.threshold=Date.now()+a},c.stopWaitForTime=function(){d.threshold=0},c.canStart=function(){returnd.refreshJobIdArray(),console.log(d.job_id_a),d.job_id_a.length===0&&Date.now()>=d.threshold},c.canRestart=function(){returnc.canStart()},c.serialized=function(){return{label:c.getLabel(),waitfortime:d.threshold,waitforjob:d.job_id_a}},c},s=function(a,b){varc={};a=a||{},b=b||{};vard={};returnd.id=w.nextId(),d.command=a.command,d.storage=a.storage,d.status=p(),d.date=newDate,function(){if(!d.storage)throwg({job:c,message:"No storage set"});if(!d.command)throwg({job:c,message:"No command set"})}(),c.getCommand=function(){returnd.command},c.getStatus=function(){returnd.status},c.getId=function(){returnd.id},c.getStorage=function(){returnd.storage},c.getDate=function(){returnd.date},c.isReady=function(){returnd.tried===0?d.status.canStart():d.status.canRestart()},c.serialized=function(){return{id:d.id,date:d.date.getTime(),status:d.status.serialized(),command:d.command.serialized(),storage:d.storage.serialized()}},c.waitForJob=function(a){d.status.getLabel()!=="wait"&&(d.status=r()),d.status.waitForJob(a)},c.dontWaitFor=function(a){d.status.getLabel()==="wait"&&d.status.dontWaitForJob(a)},c.waitForTime=function(a){d.status.getLabel()!=="wait"&&(d.status=r()),d.status.waitForTime(a)},c.stopWaitForTime=function(){d.status.getLabel()==="wait"&&d.status.stopWaitForTime()},c.update=function(a){console.log("updating"),d.command.setMaxRetry(-1),d.command.fail({status:0,statusText:"Replaced",message:"Job has been replaced by another one."}),d.date=a.getDate(),d.command=a.getCommand(),d.status=a.getStatus()},c.execute=function(){if(d.max_retry!==0&&d.tried>=d.max_retry)throwf({job:c,message:"The job was invoked too much time."});if(!c.isReady())throwe({message:"Can not execute this job."});d.status=q(),d.command.onRetryDo(function(){vara=d.command.getTried();a=a*a*200,a>1e4&&(a=1e4),c.waitForTime(a)}),d.command.onEndDo(function(){x.terminateJob(c)}),d.command.execute(d.storage)},c},t=function(a,b){varc={};a=a||{},b=b||{};vard=[],e=a.name||"";returnc.add=function(a){d.push(a)},c.remove=function(a){varb,c=[];for(b=0;b<d.length;b+=1)d[b]!==a&&c.push(d[b]);d=c},c.register=function(){v.register(c)},c.unregister=function(){v.unregister(c)},c.trigger=function(a){varb;for(b=0;b<d.length;b++)d[b].apply(null,a)},c},u=function(a,b){varc={};a=a||{},b=b||{};vard={};returnd.id=a.id||0,d.interval=400,d.interval_id=null,d.touch=function(){LocalOrCookieStorage.setItem("jio/id/"+d.id,Date.now())},c.setId=function(a){d.id=a},c.setIntervalDelay=function(a){d.interval=a},c.getIntervalDelay=function(){returnd.interval},c.start=function(){d.interval_id||(d.touch(),d.interval_id=setInterval(function(){d.touch()},d.interval))},c.stop=function(){d.interval_id!==null&&(clearInterval(d.interval_id),d.interval_id=null)},c}(),v=function(a,b){varc={};a=a||{},b=b||{};vard={};returnc.register=function(a){d[a]||(d[a]=t())},c.unregister=function(a){d[a]&&deleted[a]},c.at=function(a){returnd[a]},c.on=function(a,b){c.register(a),c.at(a).add(b)},c.trigger=function(a,b){c.at(a).trigger(b)},c}(),w=function(a,b){varc={};a=a||{},b=b||{};vard=0;returnc.nextId=function(){returnd=d+1,d},c}(),x=function(a,b){varc={};a=a||{},b=b||{};vare="jio/job_array",f={};returnf.id=a.id,f.interval_id=null,f.interval=200,f.job_a=[],f.getJobArrayName=function(){returne+"/"+f.id},f.getJobArray=function(){returnLocalOrCookieStorage.getItem(f.getJobArrayName())||[]},f.copyJobArrayToLocal=function(){vara=[],b;for(b=0;b<f.job_a.length;b+=1)a.push(f.job_a[b].serialized());LocalOrCookieStorage.setItem(f.getJobArrayName(),a)},f.removeJob=function(a){varb,c=[];for(b=0;b<f.job_a.length;b+=1)f.job_a[b]!==a&&c.push(f.job_a[b]);f.job_a=c,f.copyJobArrayToLocal()},c.setId=function(a){f.id=a},c.start=function(){vara;f.interval_id===null&&(f.interval_id=setInterval(function(){f.restoreOldJio();for(a=0;a<f.job_a.length;a+=1)c.execute(f.job_a[a])},f.interval))},c.stop=function(){f.interval_id!==null&&(clearInterval(f.interval_id),f.interval_id=null,f.job_a.length===0&&LocalOrCookieStorage.deleteItem(f.getJobArrayName()))},f.restoreOldJio=function(){vara,b;f.lastrestore=f.lastrestore||0;if(f.lastrestore>Date.now()-2e3)return;b=LocalOrCookieStorage.getItem("jio/id_array")||[];for(a=0;a<b.length;a+=1)f.restoreOldJioId(b[a]);f.lastrestore=Date.now()},f.restoreOldJioId=function(a){varb;b=LocalOrCookieStorage.getItem("jio/id/"+a)||0,b<Date.now()-1e4&&(f.restoreOldJobFromJioId(a),f.removeOldJioId(a))},f.restoreOldJobFromJioId=function(a){varb,e;e=LocalOrCookieStorage.getItem("jio/job_array/"+a)||[];for(b=0;b<e.length;b+=1)c.addJob(s({storage:k.storage(e[b]),command:d(e[b].command)}))},f.removeOldJioId=function(a){varb,c,d=[];c=LocalOrCookieStorage.getItem("jio/id_array")||[];for(b=0;b<c.length;b+=1)c[b]!==a&&d.push(c[b]);LocalOrCookieStorage.setItem("jio/id_array",d)},c.execute=function(a){try{a.execute()}catch(b){switch(b.name){case"jobNotReadyException":break;case"tooMuchTriesJobException":break;default:throwb}}f.copyJobArrayToLocal()},c.jobIdExists=function(a){varb;for(b=0;b<f.job_a.length;b+=1)if(f.job_a[b].getId()===a)returnconsole.log("found"),!0;returnconsole.log("not found"),!1},c.terminateJob=function(a){f.removeJob(a),f.copyJobArrayToLocal()},c.addJob=function(a){varb=c.validateJobAccordingToJobList(f.job_a,a);f.manage(a,b)},c.validateJobAccordingToJobList=function(a,b){varc,d=[];for(c=0;c<a.length;c+=1)d.push(y.validateJobAccordingToJob(a[c],b));returnd},f.manage=function(a,b){vard;if(f.job_a.length!==b.length)thrownewRangeError("Array out of bound");for(d=0;d<b.length;d+=1)if(b[d].action==="dont accept")return;console.log("managing "+JSON.stringify(b));for(d=0;d<b.length;d+=1)switch(b[d].action){case"eliminate":console.log("eliminating"),c.eliminate(b[d].job);break;case"update":b[d].job.update(a),f.copyJobArrayToLocal();return;case"wait":console.log("wait"),a.waitForJob(b[d].job);break;default:}f.job_a.push(a),f.copyJobArrayToLocal()},c.eliminate=function(a){varb,c=[];for(b=0;b<f.job_a.length;b+=1)f.job_a[b].getId()!==a.getId()&&(c.push(f.job_a[b]),console.log("add: "+f.job_a[b].getId()+" -> it is not "+a.getId()));f.job_a=c,f.copyJobArrayToLocal()},c}(),y=function(a,b){varc={},d={};returnc.eliminate=function(){return"eliminate"},c.update=function(){return"update"},c.dontAccept=function(){return"dont accept"},c.wait=function(){return"wait"},c.none=function(){return"none"},d.compare={},d.default_compare=function(a,b){returna.getCommand().getPath()===b.getCommand().getPath()&&JSON.stringify(a.getStorage().serialized())===JSON.stringify(b.getStorage().serialized())},d.action={saveDocument:{"on going":{saveDocument:function(a,b){returna.getCommand().getContent()===b.getCommand().getContent()?c.dontAccept():c.wait()},loadDocument:c.wait,removeDocument:c.wait,getDocumentList:c.none},"not on going":{saveDocument:c.update,loadDocument:c.wait,removeDocument:c.eliminate,getDocumentList:c.none}},loadDocument:{"on going":{saveDocument:c.wait,loadDocument:c.dontAccept,removeDocument:c.wait,getDocumentList:c.none},"not on going":{saveDocument:c.wait,loadDocument:c.update,removeDocument:c.wait,getDocumentList:c.none}},removeDocument:{"on going":{saveDocument:c.wait,loadDocument:c.dontAccept,removeDocument:c.dontAccept,getDocumentList:c.none},"not on going":{saveDocument:c.eliminate,loadDocument:c.dontAccept,removeDocument:c.update,getDocumentList:c.none}},getDocumentList:{"on going":{saveDocument:c.none,loadDocument:c.none,removeDocument:c.none,getDocumentList:c.dontAccept},"not on going":{saveDocument:c.none,loadDocument:c.none,removeDocument:c.none,getDocumentList:c.update}}},d.default_action=c.none,d.getAction=function(a,b){varc,e,f;c=a.getCommand().getLabel(),e=b.getCommand().getLabel(),f=a.getStatus().getLabel()==="on going"?"on going":"not on going";try{returnconsole.log(c),console.log(e),console.log(f),d.action[c][f][e](a,b)}catch(g){if(g.name==="TypeError")returnd.default_action(a,b);throwg}},d.canCompare=function(a,b){varc=a.getCommand().getLabel(),e=b.getCommand().getLabel();try{returnd.compare[c][e](a,b)}catch(f){if(f.name==="TypeError")returnd.default_compare(a,b);throwf}},c.validateJobAccordingToJob=function(a,b){returnd.canCompare(a,b)?{action:d.getAction(a,b),job:a}:{action:d.default_action(a,b),job:a}},c}(),z={};a=a||{},c=c||{};varA={},B="jio/id_array";returnA.id=1,A.storage=k.storage(a,z),function(){vara,b=LocalOrCookieStorage.getItem(B)||[];for(a=0;a<b.length;a+=1)b[a]>=A.id&&(A.id=b[a]+1);b.push(A.id),LocalOrCookieStorage.setItem(B,b)}(),function(){u.setId(A.id),u.start(),x.setId(A.id),x.start()}(),z.start=function(){x.start()},z.stop=function(){x.stop()},z.getId=function(){returnA.id},z.validateStorageDescription=function(a){returnk.storage(a.type)(a).isValid()},z.saveDocument=function(a,b,c,d){c=c||{},c.onResponse=c.onResponse||function(){},c.onDone=c.onDone||function(){},c.onFail=c.onFail||function(){},c.max_retry=c.max_retry||0,x.addJob(s({storage:d?k.storage(d):A.storage,command:l({path:a,content:b,option:c})}))},z.loadDocument=function(a,b,c){b=b||{},b.onResponse=b.onResponse||function(){},b.onDone=b.onDone||function(){},b.onFail=b.onFail||function(){},b.max_retry=b.max_retry||0,b.metadata_only=b.metadata_only!==undefined?b.metadata_only:!1,x.addJob(s({storage:c?k.storage(c):A.storage,command:i({path:a,option:b})}))},z.removeDocument=function(a,b,c){b=b||{},b.onResponse=b.onResponse||function(){},b.onDone=b.onDone||function(){},b.onFail=b.onFail||function(){},b.max_retry=b.max_retry||0,x.addJob(s({storage:c?k.storage(c):A.storage,command:j({path:a,option:b})}))},z.getDocumentList=function(a,b,c){b=b||{},b.onResponse=b.onResponse||function(){},b.onDone=b.onDone||function(){},b.onFail=b.onFail||function(){},b.max_retry=b.max_retry||0,b.metadata_only=b.metadata_only!==undefined?b.metadata_only:!0,x.addJob(s({storage:c?k.storage(c):A.storage,command:h({path:a,option:b})}))},z},k=function(a,b){varc={};a=a||{},b=b||{};vare={base:h,handler:i};returnc.storage=function(a,b){a=a||{};varc=a.type||"base";if(!e[c])throwd({type:c,message:"Storage does not exists."});returne[c](a,b)},c.newJio=function(a){varb=a;returntypeofb=="string"&&(b=JSON.parse(b)),b=b||{type:"base"},j(a)},c.addStorageType=function(a,b){b=b||function(){returnnull};if(e[a])throwd({type:a,message:"Already known."});e[a]=b},c}();returnk}();
\ No newline at end of file
varjio=function(){vara=function(a,b){varc={};returna=a||{},b=b||{},c.name="jioException",c.message=a.message||"Unknown Reason.",c.toString=function(){returnc.name+": "+c.message},c},b=function(b,c){vard=a(b,c);b=b||{};vare=b.command;returnd.name="invalidCommandState",d.toString=function(){returnd.name+": "+e.getLabel()+", "+d.message},d},c=function(b,c){vard=a(b,c);b=b||{};vare=b.storage.getType();returnd.name="invalidStorage",d.toString=function(){returnd.name+": "+'Type "'+e+'", '+d.message},d},d=function(b,c){vard=a(b,c),e=b.type;returnd.name="invalidStorageType",d.toString=function(){returnd.name+": "+e+", "+d.message},d},e=function(b,c){vard=a(b,c);returnd.name="jobNotReadyException",d},f=function(b,c){vard=a(b,c);returnd.name="tooMuchTriesJobException",d},g=function(b,c){vard=a(b,c);returnd.name="invalidJobException",d},h=function(a,b){vard={};a=a||{},b=b||{};vare={};returne.type=a.type||"",d.getType=function(){returne.type},d.setType=function(a){e.type=a},d.execute=function(a){d.validate(a),a.executeOn(d)},d.isValid=function(){return!0},d.validate=function(a){varb=d.validateState();if(b)throwc({storage:d,message:b});a.validate(d)},d.serialized=function(){return{type:d.getType()}},d.saveDocument=function(a){throwc({storage:d,message:"Unknown storage."})},d.loadDocument=function(a){d.saveDocument()},d.removeDocument=function(a){d.saveDocument()},d.getDocumentList=function(a){d.saveDocument()},d.validateState=function(){return""},d},i=function(a,b){varc=h(a,b);a=a||{},b=b||{};vard={};returnd.storage_a=a.storagelist||[],c.beforeExecute=function(a){},c.execute=function(a){varb;c.validate(a),c.beforeExecute(a);for(b=0;b<d.storage_a.length;b++)d.storage_a[b].execute(a);c.afterExecute(a)},c.afterExecute=function(a){a.done()},c.serialized=function(){return{type:d.type,storagelist:d.storagelist}},c},j=function(a,c){vard=function(a,c){vard={};a=a||{},c=c||{};vare={};returne.commandlist={saveDocument:l,loadDocument:i,removeDocument:j,getDocumentList:h},a.label&&e.commandlist[a.label]?(e.label=a.label,deletea.label,e.commandlist[e.label](a,c)):(e.path=a.path||"",e.tried=0,e.option=a.option||{},e.respond=e.option.onResponse||function(){},e.done=e.option.onDone||function(){},e.fail=e.option.onFail||function(){},e.retry=function(){d.setMaxRetry(-1),d.fail({status:0,statusText:"Fail Retry",message:"Impossible to retry."})},e.end=function(){},d.getLabel=function(){return"command"},d.getPath=function(){returne.path},d.getOption=function(a){returne.option[a]},d.validate=function(a){d.validateState()},d.getTried=function(){returne.tried},d.setMaxRetry=function(a){e.option.max_retry=a},d.execute=function(a){d.validate(a),e.tried++,a.execute(d)},d.executeOn=function(a){},d.validateState=function(){if(e.path==="")throwb({command:d,message:"Path is empty"})},d.done=function(a){e.done(a),e.respond({status:n(),value:a}),e.end()},d.fail=function(a){e.option.max_retry===0||e.tried<e.option.max_retry?e.retry():(e.fail(a),e.respond({status:o(),error:a}),e.end())},d.onEndDo=function(a){e.end=a},d.onRetryDo=function(a){e.retry=a},d.serialized=function(){return{label:d.getLabel(),tried:e.tried,max_retry:e.max_retry,path:e.path,option:e.option}},d.canBeRestored=function(){return!0},d)},h=function(a,b){varc=d(a,b);returna=a||{},b=b||{},c.getLabel=function(){return"getDocumentList"},c.executeOn=function(a){a.getDocumentList(c)},c.canBeRestored=function(){return!1},c},i=function(a,b){varc=d(a,b);returna=a||{},b=b||{},c.getLabel=function(){return"loadDocument"},c.executeOn=function(a){a.loadDocument(c)},c.canBeRestored=function(){return!1},c},j=function(a,b){varc=d(a,b);returna=a||{},b=b||{},c.getLabel=function(){return"removeDocument"},c.executeOn=function(a){a.removeDocument(c)},c},l=function(a,c){vare=d(a,c);a=a||{},c=c||{};varf={};f.content=a.content,e.getLabel=function(){return"saveDocument"},e.getContent=function(){returnf.content};varg=e.validate;e.validate=function(a){if(typeoff.content!="string")throwb({command:e,message:"No data to save"});g(a)},e.executeOn=function(a){a.saveDocument(e)};varh=e.serialized;returne.serialized=function(){vara=h();returna.content=f.content,a},e},m=function(a,b){varc={};returna=a||{},b=b||{},c.getLabel=function(){return"job status"},c.canStart=function(){},c.canRestart=function(){},c.serialized=function(){return{label:c.getLabel()}},c},n=function(a,b){varc=m(a,b);returna=a||{},b=b||{},c.getLabel=function(){return"done"},c.canStart=function(){return!1},c.canRestart=function(){return!1},c},o=function(a,b){varc=m(a,b);returna=a||{},b=b||{},c.getLabel=function(){return"fail"},c.canStart=function(){return!1},c.canRestart=function(){return!0},c},p=function(a,b){varc=m(a,b);returna=a||{},b=b||{},c.getLabel=function(){return"initial"},c.canStart=function(){return!0},c.canRestart=function(){return!0},c},q=function(a,b){varc=m(a,b);returna=a||{},b=b||{},c.getLabel=function(){return"on going"},c.canStart=function(){return!1},c.canRestart=function(){return!1},c},r=function(a,b){varc=m(a,b);a=a||{},b=b||{};vard={};returnd.job_id_a=a.job_id_array||[],d.threshold=0,c.getLabel=function(){return"wait"},d.refreshJobIdArray=function(){vara=[],b;for(b=0;b<d.job_id_a.length;b+=1)x.jobIdExists(d.job_id_a[b])&&a.push(d.job_id_a[b]);d.job_id_a=a},c.waitForJob=function(a){varb;for(b=0;b<d.job_id_a.length;b+=1)if(d.job_id_a[b]===a.getId())return;d.job_id_a.push(a.getId())},c.dontWaitForJob=function(a){varb,c=[];for(b=0;b<d.job_id_a.length;b+=1)d.job_id_a[b]!==a.getId()&&c.push(d.job_id_a[b]);d.job_id_a=c},c.waitForTime=function(a){d.threshold=Date.now()+a},c.stopWaitForTime=function(){d.threshold=0},c.canStart=function(){returnd.refreshJobIdArray(),d.job_id_a.length===0&&Date.now()>=d.threshold},c.canRestart=function(){returnc.canStart()},c.serialized=function(){return{label:c.getLabel(),waitfortime:d.threshold,waitforjob:d.job_id_a}},c},s=function(a,b){varc={};a=a||{},b=b||{};vard={};returnd.id=w.nextId(),d.command=a.command,d.storage=a.storage,d.status=p(),d.date=newDate,function(){if(!d.storage)throwg({job:c,message:"No storage set"});if(!d.command)throwg({job:c,message:"No command set"})}(),c.getCommand=function(){returnd.command},c.getStatus=function(){returnd.status},c.getId=function(){returnd.id},c.getStorage=function(){returnd.storage},c.getDate=function(){returnd.date},c.isReady=function(){returnd.tried===0?d.status.canStart():d.status.canRestart()},c.serialized=function(){return{id:d.id,date:d.date.getTime(),status:d.status.serialized(),command:d.command.serialized(),storage:d.storage.serialized()}},c.waitForJob=function(a){d.status.getLabel()!=="wait"&&(d.status=r()),d.status.waitForJob(a)},c.dontWaitFor=function(a){d.status.getLabel()==="wait"&&d.status.dontWaitForJob(a)},c.waitForTime=function(a){d.status.getLabel()!=="wait"&&(d.status=r()),d.status.waitForTime(a)},c.stopWaitForTime=function(){d.status.getLabel()==="wait"&&d.status.stopWaitForTime()},c.update=function(a){d.command.setMaxRetry(-1),d.command.fail({status:0,statusText:"Replaced",message:"Job has been replaced by another one."}),d.date=a.getDate(),d.command=a.getCommand(),d.status=a.getStatus()},c.execute=function(){if(d.max_retry!==0&&d.tried>=d.max_retry)throwf({job:c,message:"The job was invoked too much time."});if(!c.isReady())throwe({message:"Can not execute this job."});d.status=q(),d.command.onRetryDo(function(){vara=d.command.getTried();a=a*a*200,a>1e4&&(a=1e4),c.waitForTime(a)}),d.command.onEndDo(function(){x.terminateJob(c)}),d.command.execute(d.storage)},c},t=function(a,b){varc={};a=a||{},b=b||{};vard=[],e=a.name||"";returnc.add=function(a){d.push(a)},c.remove=function(a){varb,c=[];for(b=0;b<d.length;b+=1)d[b]!==a&&c.push(d[b]);d=c},c.register=function(){v.register(c)},c.unregister=function(){v.unregister(c)},c.trigger=function(a){varb;for(b=0;b<d.length;b++)d[b].apply(null,a)},c},u=function(a,b){varc={};a=a||{},b=b||{};vard={};returnd.id=a.id||0,d.interval=400,d.interval_id=null,d.touch=function(){LocalOrCookieStorage.setItem("jio/id/"+d.id,Date.now())},c.setId=function(a){d.id=a},c.setIntervalDelay=function(a){d.interval=a},c.getIntervalDelay=function(){returnd.interval},c.start=function(){d.interval_id||(d.touch(),d.interval_id=setInterval(function(){d.touch()},d.interval))},c.stop=function(){d.interval_id!==null&&(clearInterval(d.interval_id),d.interval_id=null)},c}(),v=function(a,b){varc={};a=a||{},b=b||{};vard={};returnc.register=function(a){d[a]||(d[a]=t())},c.unregister=function(a){d[a]&&deleted[a]},c.at=function(a){returnd[a]},c.on=function(a,b){c.register(a),c.at(a).add(b)},c.trigger=function(a,b){c.at(a).trigger(b)},c}(),w=function(a,b){varc={};a=a||{},b=b||{};vard=0;returnc.nextId=function(){returnd=d+1,d},c}(),x=function(a,b){varc={};a=a||{},b=b||{};vare="jio/job_array",f={};returnf.id=a.id,f.interval_id=null,f.interval=200,f.job_a=[],f.getJobArrayName=function(){returne+"/"+f.id},f.getJobArray=function(){returnLocalOrCookieStorage.getItem(f.getJobArrayName())||[]},f.copyJobArrayToLocal=function(){vara=[],b;for(b=0;b<f.job_a.length;b+=1)a.push(f.job_a[b].serialized());LocalOrCookieStorage.setItem(f.getJobArrayName(),a)},f.removeJob=function(a){varb,c=[];for(b=0;b<f.job_a.length;b+=1)f.job_a[b]!==a&&c.push(f.job_a[b]);f.job_a=c,f.copyJobArrayToLocal()},c.setId=function(a){f.id=a},c.start=function(){vara;f.interval_id===null&&(f.interval_id=setInterval(function(){f.restoreOldJio();for(a=0;a<f.job_a.length;a+=1)c.execute(f.job_a[a])},f.interval))},c.stop=function(){f.interval_id!==null&&(clearInterval(f.interval_id),f.interval_id=null,f.job_a.length===0&&LocalOrCookieStorage.deleteItem(f.getJobArrayName()))},f.restoreOldJio=function(){vara,b;f.lastrestore=f.lastrestore||0;if(f.lastrestore>Date.now()-2e3)return;b=LocalOrCookieStorage.getItem("jio/id_array")||[];for(a=0;a<b.length;a+=1)f.restoreOldJioId(b[a]);f.lastrestore=Date.now()},f.restoreOldJioId=function(a){varb;b=LocalOrCookieStorage.getItem("jio/id/"+a)||0,b<Date.now()-1e4&&(f.restoreOldJobFromJioId(a),f.removeOldJioId(a),f.removeJobArrayFromJioId(a))},f.restoreOldJobFromJioId=function(a){varb,e;e=LocalOrCookieStorage.getItem("jio/job_array/"+a)||[];for(b=0;b<e.length;b+=1){varf=d(e[b].command);f.canBeRestored()&&c.addJob(s({storage:k.storage(e[b].storage),command:f}))}},f.removeOldJioId=function(a){varb,c,d=[];c=LocalOrCookieStorage.getItem("jio/id_array")||[];for(b=0;b<c.length;b+=1)c[b]!==a&&d.push(c[b]);LocalOrCookieStorage.setItem("jio/id_array",d),LocalOrCookieStorage.deleteItem("jio/id/"+a)},f.removeJobArrayFromJioId=function(a){LocalOrCookieStorage.deleteItem("jio/job_array/"+a)},c.execute=function(a){try{a.execute()}catch(b){switch(b.name){case"jobNotReadyException":break;case"tooMuchTriesJobException":break;default:throwb}}f.copyJobArrayToLocal()},c.jobIdExists=function(a){varb;for(b=0;b<f.job_a.length;b+=1)if(f.job_a[b].getId()===a)return!0;return!1},c.terminateJob=function(a){f.removeJob(a),f.copyJobArrayToLocal()},c.addJob=function(a){varb=c.validateJobAccordingToJobList(f.job_a,a);f.manage(a,b)},c.validateJobAccordingToJobList=function(a,b){varc,d=[];for(c=0;c<a.length;c+=1)d.push(y.validateJobAccordingToJob(a[c],b));returnd},f.manage=function(a,b){vard;if(f.job_a.length!==b.length)thrownewRangeError("Array out of bound");for(d=0;d<b.length;d+=1)if(b[d].action==="dont accept")return;for(d=0;d<b.length;d+=1)switch(b[d].action){case"eliminate":c.eliminate(b[d].job);break;case"update":b[d].job.update(a),f.copyJobArrayToLocal();return;case"wait":a.waitForJob(b[d].job);break;default:}f.job_a.push(a),f.copyJobArrayToLocal()},c.eliminate=function(a){varb,c=[];for(b=0;b<f.job_a.length;b+=1)f.job_a[b].getId()!==a.getId()&&c.push(f.job_a[b]);f.job_a=c,f.copyJobArrayToLocal()},c}(),y=function(a,b){varc={},d={};returnc.eliminate=function(){return"eliminate"},c.update=function(){return"update"},c.dontAccept=function(){return"dont accept"},c.wait=function(){return"wait"},c.none=function(){return"none"},d.compare={},d.default_compare=function(a,b){returna.getCommand().getPath()===b.getCommand().getPath()&&JSON.stringify(a.getStorage().serialized())===JSON.stringify(b.getStorage().serialized())},d.action={saveDocument:{"on going":{saveDocument:function(a,b){returna.getCommand().getContent()===b.getCommand().getContent()?c.dontAccept():c.wait()},loadDocument:c.wait,removeDocument:c.wait,getDocumentList:c.none},"not on going":{saveDocument:c.update,loadDocument:c.wait,removeDocument:c.eliminate,getDocumentList:c.none}},loadDocument:{"on going":{saveDocument:c.wait,loadDocument:c.dontAccept,removeDocument:c.wait,getDocumentList:c.none},"not on going":{saveDocument:c.wait,loadDocument:c.update,removeDocument:c.wait,getDocumentList:c.none}},removeDocument:{"on going":{saveDocument:c.wait,loadDocument:c.dontAccept,removeDocument:c.dontAccept,getDocumentList:c.none},"not on going":{saveDocument:c.eliminate,loadDocument:c.dontAccept,removeDocument:c.update,getDocumentList:c.none}},getDocumentList:{"on going":{saveDocument:c.none,loadDocument:c.none,removeDocument:c.none,getDocumentList:c.dontAccept},"not on going":{saveDocument:c.none,loadDocument:c.none,removeDocument:c.none,getDocumentList:c.update}}},d.default_action=c.none,d.getAction=function(a,b){varc,e,f;returnc=a.getCommand().getLabel(),e=b.getCommand().getLabel(),f=a.getStatus().getLabel()==="on going"?"on going":"not on going",d.action[c]&&d.action[c][f]&&d.action[c][f][e]?d.action[c][f][e](a,b):d.default_action(a,b)},d.canCompare=function(a,b){varc=a.getCommand().getLabel(),e=b.getCommand().getLabel();returnd.compare[c]&&d.compare[e]?d.compare[c][e](a,b):d.default_compare(a,b)},c.validateJobAccordingToJob=function(a,b){returnd.canCompare(a,b)?{action:d.getAction(a,b),job:a}:{action:d.default_action(a,b),job:a}},c}(),z={};a=a||{},c=c||{};varA={},B="jio/id_array";returnA.id=null,A.storage=k.storage(a),A.init=function(){if(A.id===null){vara,b=LocalOrCookieStorage.getItem(B)||[];A.id=1;for(a=0;a<b.length;a+=1)b[a]>=A.id&&(A.id=b[a]+1);b.push(A.id),LocalOrCookieStorage.setItem(B,b),u.setId(A.id),x.setId(A.id)}},z.start=function(){A.init(),u.start(),x.start()},z.stop=function(){x.stop()},z.close=function(){u.stop(),x.stop(),A.id=null},z.start(),z.getId=function(){returnA.id},z.validateStorageDescription=function(a){returnk.storage(a.type)(a).isValid()},z.saveDocument=function(a,b,c,d){c=c||{},c.onResponse=c.onResponse||function(){},c.onDone=c.onDone||function(){},c.onFail=c.onFail||function(){},c.max_retry=c.max_retry||0,x.addJob(s({storage:d?k.storage(d):A.storage,command:l({path:a,content:b,option:c})}))},z.loadDocument=function(a,b,c){b=b||{},b.onResponse=b.onResponse||function(){},b.onDone=b.onDone||function(){},b.onFail=b.onFail||function(){},b.max_retry=b.max_retry||0,b.metadata_only=b.metadata_only!==undefined?b.metadata_only:!1,x.addJob(s({storage:c?k.storage(c):A.storage,command:i({path:a,option:b})}))},z.removeDocument=function(a,b,c){b=b||{},b.onResponse=b.onResponse||function(){},b.onDone=b.onDone||function(){},b.onFail=b.onFail||function(){},b.max_retry=b.max_retry||0,x.addJob(s({storage:c?k.storage(c):A.storage,command:j({path:a,option:b})}))},z.getDocumentList=function(a,b,c){b=b||{},b.onResponse=b.onResponse||function(){},b.onDone=b.onDone||function(){},b.onFail=b.onFail||function(){},b.max_retry=b.max_retry||0,b.metadata_only=b.metadata_only!==undefined?b.metadata_only:!0,x.addJob(s({storage:c?k.storage(c):A.storage,command:h({path:a,option:b})}))},z},k=function(a,b){varc={};a=a||{},b=b||{};vare={base:h,handler:i};returnc.storage=function(a,b,c){a=a||{};varf=c||a.type||"base";if(!e[f])throwd({type:f,message:"Storage does not exists."});returne[f](a,b)},c.newJio=function(a){varb=a;returntypeofb=="string"&&(b=JSON.parse(b)),b=b||{type:"base"},j(a)},c.addStorageType=function(a,b){b=b||function(){returnnull};if(e[a])throwd({type:a,message:"Already known."});e[a]=b},c}();returnk}();