varJIO=function(){vara=function(a,b){varc={job_method_object:{checkNameAvailability:{},saveDocument:{},loadDocument:{},getDocumentList:{},removeDocument:{}}},d={job_managing_method:{canSelect:function(a,b){returnJSON.stringify(a.storage)===JSON.stringify(b.storage)&&JSON.stringify(a.applicant)===JSON.stringify(b.applicant)&&a.name===b.name?!0:!1},canRemoveFailOrDone:function(a,b){returna.status==="fail"||a.status==="done"?!0:!1},canEliminate:function(a,b){returna.status!=="on_going"&&(a.method==="removeDocument"&&b.method==="saveDocument"||a.method==="saveDocument"&&b.method==="removeDocument")?!0:!1},canReplace:function(a,b){returna.status!=="on_going"&&a.method===b.method&&a.date<b.date?!0:!1},cannotAccept:function(a,b){if(a.status!=="on_going"){if(a.method==="removeDocument"&&b.method==="loadDocument")return!0}else{if(a.method===b.method==="loadDocument")return!0;if(a.method==="removeDocument"&&(b.method==="loadDocument"||b.method==="removeDocument"))return!0;if(a.method===b.method==="saveDocument"&&a.content===b.content)return!0;if(a.method===b.method==="getDocumentList"||a.method===b.method==="checkNameAvailability")return!0}return!1},mustWait:function(a,b){returna.method==="getDocumentList"||a.method==="checkNameAvailability"||b.method==="getDocumentList"||b.method==="checkNameAvailability"?!1:!0}},queue_id:1,storage_type_object:{},max_wait_time:1e4},e,f,g,h,i,j,k,l;returne=function(a,c){vard={},e={},f={},g,h;returne.eventAction=function(a){returnh=a&&f[a],h||(g=b.Callbacks(),h={publish:g.fire,subscribe:g.add,unsubscribe:g.remove},a&&(f[a]=h)),h},d.publish=function(a,b){e.eventAction(a).publish(b)},d.subscribe=function(a,b){returne.eventAction(a).subscribe(b),b},d.unsubscribe=function(a,b){e.eventAction(a).unsubscribe(b)},d},f=function(a,c){vard=b.extend(!0,{},a);returnd.id=0,d.status="initial",d.date=Date.now(),d},g=function(e,g){varh={},i={},k="jio/id_array";returnh.init=function(b){varc,d=function(){},f;i.use_local_storage&&(f=a.getItem(k)||[],e.publisher&&(i.publisher=e.publisher),i.jio_id=b.jio_id,i.job_object_name="jio/job_object/"+i.jio_id,f.push(i.jio_id),a.setItem(k,f)),i.job_object={},h.copyJobQueueToLocalStorage();for(cini.recovered_job_object)i.recovered_job_object[c].callback=d,h.addJob(i.recovered_job_object[c])},h.close=function(){JSON.stringify(i.job_object)==="{}"&&a.deleteItem(i.job_object_name)},h.getNewQueueID=function(){varb=null,c=0,e=a.getItem(k)||[];for(b=0;b<e.length;b+=1)e[b]>=d.queue_id&&(d.queue_id=e[b]+1);returnc=d.queue_id,d.queue_id++,c},h.recoverOlderJobObject=function(){varb=null,c=[],d=!1,e;if(i.use_local_storage){e=a.getItem(k)||[];for(b=0;b<e.length;b+=1)a.getItem("jio/id/"+e[b])<Date.now()-1e4?(a.deleteItem("jio/id/"+e[b]),i.recovered_job_object=a.getItem("jio/job_object/"+e[b]),a.deleteItem("jio/job_object/"+e[b]),d=!0):c.push(e[b]);d&&a.setItem(k,c)}},h.isThereJobsWhere=function(a){varb="id";if(!a)return!0;for(bini.job_object)if(a(i.job_object[b]))return!0;return!1},h.copyJobQueueToLocalStorage=function(){returni.use_local_storage?a.setItem(i.job_object_name,i.job_object):!1},h.createJob=function(a){returnh.addJob(f(a))},h.addJob=function(a){varb=!0,c=[],e=[],f=[],g=null,k="id";for(kini.job_object){if(d.job_managing_method.canRemoveFailOrDone(i.job_object[k],a)){f.push(k);continue}if(d.job_managing_method.canSelect(i.job_object[k],a)){if(d.job_managing_method.canEliminate(i.job_object[k],a)){c.push(k);continue}if(d.job_managing_method.canReplace(i.job_object[k],a)){g=j({queue:h,job:i.job_object[k]}),g.replace(a),b=!1;break}if(d.job_managing_method.cannotAccept(i.job_object[k],a))return!1;if(d.job_managing_method.mustWait(i.job_object[k],a)){e.push(k);continue}}}if(b){for(k=0;k<c.length;k+=1)g=j({queue:h,job:i.job_object[c[k]]}),g.eliminate();if(e.length>0){a.status="wait",a.waiting_for={job_id_array:e};for(k=0;k<e.length;k+=1)i.job_object[e[k]]&&(i.job_object[e[k]].max_tries=1)}for(k=0;k<f.length;k+=1)h.removeJob(i.job_object[f[k]]);a.id=i.job_id,a.tries=0,i.job_id++,i.job_object[a.id]=a}returnh.copyJobQueueToLocalStorage(),!0},h.removeJob=function(a){varc=b.extend({where:function(a){return!0}},a),d,e=!1,f="key";if(c.job)i.job_object[c.job.id]&&c.where(i.job_object[c.job.id])&&(deletei.job_object[c.job.id],e=!0);elsefor(fini.job_object)c.where(i.job_object[f])&&(deletei.job_object[f],e=!0);e||console.error("No jobs was found, when trying to remove some."),h.copyJobQueueToLocalStorage()},h.resetAll=function(){vara="id";for(aini.job_object)i.job_object[a].status="initial";h.copyJobQueueToLocalStorage()},h.invokeAll=function(){vara="id",b,c;for(aini.job_object){c=!1;if(i.job_object[a].status==="initial")h.invoke(i.job_object[a]);elseif(i.job_object[a].status==="wait"){c=!0;if(i.job_object[a].waiting_for.job_id_array)for(b=0;b<i.job_object[a].waiting_for.job_id_array.length;b+=1)if(i.job_object[i.job_object[a].waiting_for.job_id_array[b]]){c=!1;break}i.job_object[a].waiting_for.time&&i.job_object[a].waiting_for.time>Date.now()&&(c=!1),c&&h.invoke(i.job_object[a])}}this.copyJobQueueToLocalStorage()},h.invoke=function(a){varb;if(!c.job_method_object[a.method])return!1;h.isThereJobsWhere(function(b){returnb.method===a.method&&b.method==="initial"})?a.status="on_going":(a.status="on_going",i.publisher.publish(c.job_method_object[a.method]["start_"+a.method])),b=j({queue:this,job:a}),b.execute()},h.ended=function(a){vard=b.extend(!0,{},a);h.removeJob({job:d});if(!c.job_method_object[d.method])return!1;if(!h.isThereJobsWhere(function(a){returna.method===d.method&&a.status==="on_going"||a.status==="initial"})){i.publisher.publish(c.job_method_object[d.method]["stop_"+d.method]);return}},h.clean=function(){h.removeJob(undefined,{where:function(a){returna.status==="fail"}})},i.use_local_storage=e.options.use_local_storage,i.publisher=e.publisher,i.job_id=1,i.jio_id=0,i.job_object_name="",i.job_object={},i.recovered_job_object={},h},h=function(a,b){varc={},d={};returnd.interval=200,d.id=null,d.queue=a.queue,c.setIntervalDelay=function(a){d.interval=a},c.start=function(){returnd.id?!1:(d.id=setInterval(function(){d.queue.recoverOlderJobObject(),d.queue.invokeAll()},d.interval),!0)},c.stop=function(){returnd.id?(clearInterval(d.id),d.id=null,!0):!1},c},i=function(){varb={},c={};returnc.interval=400,c.id=null,b.start=function(a){returnc.id?!1:(b.touch(a),c.id=setInterval(function(){b.touch(a)},c.interval),!0)},b.stop=function(){returnc.id?(clearInterval(c.id),c.id=null,!0):!1},b.touch=function(b){a.setItem("jio/id/"+b,Date.now())},b},j=function(a){varc={},e={};returne.job=a.job,e.callback=a.job.callback,e.queue=a.queue,e.res={status:"done",message:""},e.sorted=!1,e.limited=!1,e.research_done=!1,e.fail_checkNameAvailability=function(){e.res.message="Unable to check name availability."},e.done_checkNameAvailability=function(a){e.res.message=e.job.user_name+" is "+(a?"":"not ")+"available.",e.res.return_value=a},e.fail_loadDocument=function(){e.res.message="Unable to load document."},e.done_loadDocument=function(a){e.res.message="Document loaded.",e.res.return_value=a,e.res.return_value.last_modified=(newDate(e.res.return_value.last_modified)).getTime(),e.res.return_value.creation_date=(newDate(e.res.return_value.creation_date)).getTime()},e.fail_saveDocument=function(){e.res.message="Unable to save document."},e.done_saveDocument=function(){e.res.message="Document saved."},e.fail_getDocumentList=function(){e.res.message="Unable to retrieve document list."},e.done_getDocumentList=function(a){varb;e.res.message="Document list received.",e.res.return_value=a;for(b=0;b<e.res.return_value.length;b+=1)typeofe.res.return_value[b].last_modified!="number"&&(e.res.return_value[b].last_modified=(newDate(e.res.return_value[b].last_modified)).getTime()),typeofe.res.return_value[b].creation_date!="number"&&(e.res.return_value[b].creation_date=(newDate(e.res.return_value[b].creation_date)).getTime());!e.sorted&&typeofe.job.sort!="undefined"&&c.sortDocumentArray(e.res.return_value),!e.limited&&typeofe.job.limit!="undefined"&&typeofe.job.limit.begin!="undefined"&&typeofe.job.limit.end!="undefined"&&(e.res.return_value=c.limitDocumentArray(e.res.return_value)),!e.research_done&&typeofe.job.search!="undefined"&&(e.res.return_value=c.searchDocumentArray(e.res.return_value))},e.fail_removeDocument=function(){e.res.message="Unable to removed document."},e.done_removeDocument=function(){e.res.message="Document removed."},e.retryLater=function(){vara=e.job.tries*e.job.tries*1e3;a>d.max_wait_time&&(a=d.max_wait_time),e.job.status="wait",e.job.waiting_for={time:Date.now()+a}},c.cloneJob=function(){returnb.extend(!0,{},e.job)},c.getUserName=function(){returne.job.user_name||""},c.getApplicantID=function(){returne.job.applicant.ID||""},c.getStorageUserName=function(){returne.job.storage.user_name||""},c.getStoragePassword=function(){returne.job.storage.password||""},c.getStorageURL=function(){returne.job.storage.url||""},c.getSecondStorage=function(){returne.job.storage.storage||{}},c.getStorageArray=function(){returne.job.storage.storage_array||[]},c.getFileName=function(){returne.job.name||""},c.getFileContent=function(){returne.job.content||""},c.cloneOptionObject=function(){returnb.extend(!0,{},e.job.options)},c.getMaxTries=function(){returne.job.max_tries},c.getTries=function(){returne.job.tries||0},c.setMaxTries=function(a){e.job.max_tries=a},c.addJob=function(a){returne.queue.createJob(a)},c.eliminate=function(){e.job.max_tries=1,e.job.tries=1,c.fail("Job Stopped!",0)},c.replace=function(a){e.job.tries=0,e.job.date=a.date,e.job.callback=a.callback,e.res.status="fail",e.res.message="Job Stopped!",e.res.error={},e.res.error.status=0,e.res.error.statusText="Replaced",e.res.error.message="The job was replaced by a newer one.",e["fail_"+e.job.method](),e.callback(e.res)},c.fail=function(a){e.res.status="fail",e.res.error=a,e.res.error.status=e.res.error.status||0,e.res.error.statusText=e.res.error.statusText||"Unknown Error",e.res.error.array=e.res.error.array||[],e.res.error.message=e.res.error.message||"",!e.job.max_tries||e.job.tries<e.job.max_tries?e.retryLater():(e.job.status="fail",e["fail_"+e.job.method](),e.queue.ended(e.job),e.callback(e.res))},c.done=function(a){e.job.status="done",e["done_"+e.job.method](a),e.queue.ended(e.job),e.callback(e.res)},c.execute=function(){returne.job.tries=c.getTries()+1,d.storage_type_object[e.job.storage.type]?d.storage_type_object[e.job.storage.type]({job:e.job,queue:e.queue})[e.job.method]():null},c.checkNameAvailability=function(){c.fail({status:0,statusText:"Undefined Method",message:"This method must be redefined!"})},c.loadDocument=function(){c.fail({status:0,statusText:"Undefined Method",message:"This method must be redefined!"})},c.saveDocument=function(){c.fail({status:0,statusText:"Undefined Method",message:"This method must be redefined!"})},c.getDocumentList=function(){c.fail({status:0,statusText:"Undefined Method",message:"This method must be redefined!"})},c.removeDocument=function(){c.fail({status:0,statusText:"Undefined Method",message:"This method must be redefined!"})},c.sortDocumentArray=function(a){a.sort(function(a,b){varc,d;for(cine.job.sort){varf=e.job.sort[c]==="descending"?-1:1;if(a[c]===b[c])continue;returna[c]>b[c]?f:-f}return0}),c.sortDone()},c.sortDone=function(){e.sorted=!0},c.limitDocumentArray=function(a){returnc.limitDone(),a.slice(e.job.limit.begin,e.job.limit.end)},c.limitDone=function(){e.limited=!0},c.searchDocumentArray=function(a){varb,d,f=[];for(b=0;b<a.length;b+=1)for(dine.job.search){if(typeofa[b][d]=="undefined")continue;if(a[b][d].search(e.job.search[d])>-1){f.push(a[b]);break}}returnc.researchDone(),f},c.researchDone=function(){e.research_done=!0},c},k=function(a,c){varf={},j={};j.wrongParametersError=function(a){varb="Method: "+a.method+", One or some parameters are undefined.";returnconsole.error(b),a.callback({status:"fail",error:{status:0,statusText:"Undefined Parameter",message:b}}),null},f.getID=function(){returnj.id},f.start=function(){returnj.id!==0?!1:(j.id=j.queue.getNewQueueID(),j.queue.init({jio_id:j.id}),j.updater&&j.updater.start(j.id),j.listener.start(),j.ready=!0,f.isReady())},f.stop=function(){returnj.queue.close(),j.listener.stop(),j.updater&&j.updater.stop(),j.ready=!1,j.id=0,!0},f.kill=function(){returnj.queue.close(),j.listener.stop(),j.updater&&j.updater.stop(),j.ready=!1,!0},f.isReady=function(){returnj.ready},f.publish=function(a,b){if(!f.isReady())return;returnj.pubsub.publish(a,b)},f.subscribe=function(a,b){returnj.pubsub.subscribe(a,b)},f.unsubscribe=function(a,b){returnj.pubsub.unsubscribe(a,b)},f.checkNameAvailability=function(a){varc=b.extend(!0,{user_name:j.storage.user_name,storage:j.storage,applicant:j.applicant,method:"checkNameAvailability",callback:function(){}},a);returnf.isReady()&&c.user_name&&c.storage&&c.applicant?j.queue.createJob(c):j.wrongParametersError(c)},f.saveDocument=function(a){varc=b.extend(!0,{storage:j.storage,applicant:j.applicant,content:"",method:"saveDocument",callback:function(){}},a);returnf.isReady()&&c.name&&c.storage&&c.applicant?j.queue.createJob(c):j.wrongParametersError(c)},f.loadDocument=function(a){varc=b.extend(!0,{storage:j.storage,applicant:j.applicant,method:"loadDocument",callback:function(){}},a);returnf.isReady()&&c.name&&c.storage&&c.applicant?j.queue.createJob(c):j.wrongParametersError(c)},f.getDocumentList=function(a){varc=b.extend(!0,{storage:j.storage,applicant:j.applicant,method:"getDocumentList",callback:function(){}},a);returnf.isReady()&&c.storage&&c.applicant?j.queue.createJob(c):j.wrongParametersError(c)},f.removeDocument=function(a){varc=b.extend(!0,{storage:j.storage,applicant:j.applicant,method:"removeDocument",callback:function(){}},a);returnf.isReady()&&c.name&&c.storage&&c.applicant?j.queue.createJob(c):j.wrongParametersError(c)};vark=b.extend(!0,{use_local_storage:!0},a.options);returntypeofa.storage=="string"&&(a.storage=JSON.parse(a.storage)),typeofa.applicant=="string"&&(a.applicant=JSON.parse(a.applicant)),j.storage=a.storage,j.applicant=a.applicant,j.id=0,j.pubsub=e({options:k}),j.queue=g({publisher:j.pubsub,options:k}),j.listener=h({queue:j.queue,options:k}),j.ready=!1,k.use_local_storage?j.updater=i({options:k}):j.updater=null,j.storage&&!d.storage_type_object[j.storage.type]&&console.error('Unknown storage type "'+j.storage.type+'"'),f.start(),f},l=function(a,e){varf={};returnf.newJio=function(a,c,d){vare=b.extend(!0,{use_local_storage:!0},d);returnk({storage:a,applicant:c,options:e})},f.newBaseStorage=function(a,b){returnj(a,b)},f.addStorageType=function(a,b){returna&&b?(d.storage_type_object[a]=b,!0):!1},f.getGlobalObject=function(){returnd},f.getConstObject=function(){returnb.extend(!0,{},c)},f},l()};returnwindow.requirejs?(define("JIO",["LocalOrCookieStorage","jQuery"],a),undefined):a(LocalOrCookieStorage,jQuery)}();
\ No newline at end of file
varjio=function(){vara=function(a,b){varc={};a=a||{},b=b||{};vard={};returnd.path=a.path||"",d.option=a.option||{},d.respond=d.option.onResponse||function(){},d.done=d.option.onDone||function(){},d.fail=d.option.onFail||function(){},d.end=function(){},c.getLabel=function(){return"command"},c.getPath=function(){returnd.path},c.getOption=function(a){returnd.option[a]},c.validate=function(a){c.validateState()},c.execute=function(a){c.validate(a),a.execute(c)},c.executeOn=function(a){},c.validateState=function(){if(d.path==="")throwg({command:c,message:"Path is empty"})},c.done=function(a){console.log("test"),d.done(a),d.respond({value:a}),d.end()},c.fail=function(a){d.fail(a),d.respond({error:a}),d.end()},c.onEndDo=function(a){d.end=a},c.serialized=function(){return{label:c.getLabel(),path:d.path,option:d.option}},c},b=function(b,c){vard=a(b,c);returnb=b||{},c=c||{},d.label=function(){return"getDocumentList"},d.executeOn=function(a){a.getDocumentList(d)},d},c=function(b,c){vard=a(b,c);returnb=b||{},c=c||{},d.label=function(){return"loadDocument"},d.executeOn=function(a){a.loadDocument(d)},d},d=function(b,c){vard=a(b,c);returnb=b||{},c=c||{},d.label=function(){return"removeDocument"},d.executeOn=function(a){a.removeDocument(d)},d},e=function(b,c){vard=a(b,c);b=b||{},c=c||{};vare=b.content;d.label=function(){return"saveDocument"},d.getContent=function(){returne};varf=d.validate;returnd.validate=function(a){if(typeofe!="string")throwg({command:d,message:"No data to save"});f(a)},d.executeOn=function(a){a.saveDocument(d)},d},f=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},g=function(a,b){varc=f(a,b);a=a||{};vard=a.command;returnc.name="invalidCommandState",c.toString=function(){returnc.name+": "+d.getLabel()+", "+c.message},c},h=function(a,b){varc=f(a,b);a=a||{};vard=a.storage.getType();returnc.name="invalidStorage",c.toString=function(){returnc.name+": "+'Type "'+d+'", '+c.message},c},i=function(a,b){varc=f(a,b),d=a.type;returnc.name="invalidStorageType",c.toString=function(){returnc.name+": "+d+", "+c.message},c},j=function(a,b){varc=f(a,b);returnc.name="jobNotReadyException",c},k=function(a,b){varc=f(a,b);returnc.name="tooMuchTriesJobException",c},l=function(a,b){varc=f(a,b);returnc.name="invalidJobException",c},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=a.job_id_array||[],e=0;returnc.getLabel=function(){return"wait"},c.waitForJob=function(a){varb;for(b=0;b<d.length;b+=1)if(d[b]===a.getId())return;d.push(a.getId())},c.dontWaitForJob=function(a){varb,c=[];for(b=0;b<d.length;b+=1)d[b]!==a.getId()&&c.push(d[b]);d=c},c.waitForTime=function(a){e=Date.now()+a},c.stopWaitForTime=function(){e=0},c.canStart=function(){returnd.length===0&&Date.now()>=e},c.canRestart=function(){return!1},c.serialized=function(){return{label:c.getLabel(),waitfortime:e,waitforjob:d}},c},s=function(a,b){varc={};a=a||{},b=b||{};vard={};returnd.type=a.type||"",c.getType=function(){returnd.type},c.execute=function(a){a.executeOn(c)},c.isValid=function(){return!0},c.validate=function(a){a.validate(c)},c.serialized=function(){return{type:c.getType()}},c.saveDocument=function(a){throwh({storage:c,message:"Unknown storage."})},c.loadDocument=function(a){c.saveDocument()},c.removeDocument=function(a){c.saveDocument()},c.getDocumentList=function(a){c.saveDocument()},c},t=function(a,b){varc=s(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},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,f){varg=function(a,b){varc={};a=a||{},b=b||{};vard={};returnd.id=m.nextId(),d.command=a.command,d.storage=a.storage,d.status=p(),d.tried=0,d.max_retry=0,d.date=newDate,function(){if(!d.storage)throwl({job:c,message:"No storage set"});if(!d.command)throwl({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.isReady=function(){returnd.tried===0?d.status.canStart():d.status.canRestart()},c.serialized=function(){return{id:d.id,date:d.date.getTime(),tried:d.tried,max_retry:d.max_retry,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.date=a.getDate()},c.execute=function(){if(d.max_retry!==0&&d.tried>=d.max_retry)throwk({job:c,message:"The job was invoked too much time."});if(!c.isReady())throwj({message:"Can not execute this job."});d.status=q(),d.tried++,d.command.onEndDo(function(){n.terminateJob(c)}),d.command.execute(d.storage)},c},h=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(){i.register(c)},c.unregister=function(){i.unregister(c)},c.trigger=function(a){varb;for(b=0;b<d.length;b++)d[b].apply(null,a)},c},i=function(a,b){varc={};a=a||{},b=b||{};vard={};returnc.register=function(a){d[a]||(d[a]=h())},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}(),m=function(a,b){varc={};a=a||{},b=b||{};vard=0;returnc.nextId=function(){returnd=d+1,d},c}(),n=function(a,b){varc={};a=a||{},b=b||{};vard="jio/job_array",e={};returne.id=a.id,e.interval_id=null,e.interval=200,e.job_a=[],e.getJobArrayName=function(){returnd+"/"+e.id},e.getJobArray=function(){returnLocalOrCookieStorage.getItem(e.getJobArrayName())||[]},e.copyJobArrayToLocal=function(){vara=[],b;for(b=0;b<e.job_a.length;b+=1)a.push(e.job_a[b].serialized());LocalOrCookieStorage.setItem(e.getJobArrayName(),a)},e.removeJob=function(a){varb,c=[];for(b=0;b<e.job_a.length;b+=1)e.job_a[b]!==a&&c.push(e.job_a[b]);e.job_a=c,e.copyJobArrayToLocal()},c.setId=function(a){e.id=a},c.start=function(){vara;e.interval_id===null&&(e.interval_id=setInterval(function(){for(a=0;a<e.job_a.length;a+=1)c.execute(e.job_a[a])},e.interval))},c.stop=function(){e.interval_id!==null&&(clearInterval(e.interval_id),e.interval_id=null,e.job_a.length===0&&LocalOrCookieStorage.deleteItem(e.getJobArrayName()))},c.execute=function(a){try{a.execute()}catch(b){switch(b.name){case"jobNotReadyException":break;case"tooMuchTriesJobException":break;default:throwb}}e.copyJobArrayToLocal()},c.terminateJob=function(a){e.removeJob(a),e.copyJobArrayToLocal()},c.addJob=function(a){varb=c.validateJobAccordingToJobList(e.job_a,a);e.manage(a,b),e.copyJobArrayToLocal()},c.validateJobAccordingToJobList=function(a,b){varc,d=[];for(c=0;c<a.length;c+=1)d.push(o.validateJobAccordingToJob(a[c],b));returnd},e.manage=function(a,b){vard;if(e.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"replace":a.update(b[d].job),e.copyJobArrayToLocal();return;case"wait":a.waitForJob(b[d].job);break;default:}e.job_a.push(a),e.copyJobArrayToLocal()},c.eliminate=function(a){varb,c=[];for(b=0;b<e.job_a.length;b+=1)e.job_a[b].getId()!==a.getId()&&c.push(e.job_a[b]);e.job_a=c},c}(),o=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())===JSON.stringify(b.getStorage())},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="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{returnd.action[c][f][e](a,b)}catch(g){returnd.default_action}},d.canCompare=function(a,b){varc=d.stringifyJobForCompare(a,b);returnd.compare[c]?d.compare[c](a,b):d.default_compare(a,b)},c.validateJobAccordingToJob=function(a,b){varc=d.stringifyJobForAction(a,b);returnd.canCompare(a,b)?{action:d.getAction(a,b),job:a}:{action:d.default_action,job:a}},c}(),s={};a=a||{},f=f||{};vart={},v="jio/id_array";returnt.id=1,t.storage=w.storage(a,s),function(){vara,b=LocalOrCookieStorage.getItem(v)||[];for(a=0;a<b.length;a+=1)b[a]>=t.id&&(t.id=b[a]+1);b.push(t.id),LocalOrCookieStorage.setItem(v,b)}(),function(){u.setId(t.id),u.start(),n.setId(t.id),n.start()}(),s.start=function(){n.start()},s.stop=function(){n.stop()},s.getId=function(){returnt.id},s.validateStorageDescription=function(a){returnw.storage(a.type)(a).isValid()},s.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,console.log("add job save: "+JSON.stringify(t.storage.serialized())),n.addJob(g({storage:d?w.storage(d):t.storage,command:e({path:a,content:b,option:c})}))},s.loadDocument=function(a,b,d){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,n.addJob(g({storage:d?w.storage(d):t.storage,command:c({path:a,option:b})}))},s.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,n.addJob(g({storage:c?w.storage(c):t.storage,command:d({path:a,option:b})}))},s.getDocumentList=function(a,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,c.metadata_only=c.metadata_only!==undefined?c.metadata_only:!0,n.addJob(g({storage:d?w.storage(d):t.storage,command:b({path:a,option:c})}))},s},w=function(a,b){varc={};a=a||{},b=b||{};vard={base:s,handler:t};returnc.storage=function(a,b){a=a||{};varc=a.type||"base";if(!d[c])throwi({type:c});returnconsole.log("create storage: "+JSON.stringify(a)+JSON.stringify(b)),d[c](a,b)},c.newJio=function(a){varb=a;returntypeofb=="string"&&(b=JSON.parse(b)),b=b||{type:"base"},console.log("new jio: storage: "+JSON.stringify(a)),v(a)},c.addStorageType=function(a,b){b=b||function(){returnnull};if(d[a])throwi({type:a,message:"Already known."});d[a]=b,console.log("adding: "+a)},c}();returnw}();