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={};returnd.compare={},d.action={},c.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"},c.default_action=c.none,c.default_compare=function(a,b){returna.getCommand().getPath()===b.getCommand().getPath()&&JSON.stringify(a.getStorage().serialized())===JSON.stringify(b.getStorage().serialized())},d.getAction=function(a,b){vare,f,g;returne=a.getCommand().getLabel(),f=b.getCommand().getLabel(),g=a.getStatus().getLabel()==="on going"?"on going":"not on going",d.action[e]&&d.action[e][g]&&d.action[e][g][f]?d.action[e][g][f](a,b):c.default_action(a,b)},d.canCompare=function(a,b){vare=a.getCommand().getLabel(),f=b.getCommand().getLabel();returnd.compare[e]&&d.compare[f]?d.compare[e][f](a,b):c.default_compare(a,b)},c.validateJobAccordingToJob=function(a,b){returnd.canCompare(a,b)?{action:d.getAction(a,b),job:a}:{action:c.default_action(a,b),job:a}},c.addActionRule=function(a,b,c,e){varf=b?"on going":"not on going";d.action[a]=d.action[a]||{},d.action[a][f]=d.action[a][f]||{},d.action[a][f][c]=e},c.addCompareRule=function(a,b,c){d.compare[a]=d.compare[a]||{},d.compare[a][b]=c},c.addActionRule("saveDocument",!0,"saveDocument",function(a,b){returna.getCommand().getContent()===b.getCommand().getContent()?c.dontAccept():c.wait()}),c.addActionRule("saveDocument",!0,"loadDocument",c.wait),c.addActionRule("saveDocument",!0,"removeDocument",c.wait),c.addActionRule("saveDocument",!1,"saveDocument",c.update),c.addActionRule("saveDocument",!1,"loadDocument",c.wait),c.addActionRule("saveDocument",!1,"removeDocument",c.eliminate),c.addActionRule("loadDocument",!0,"saveDocument",c.wait),c.addActionRule("loadDocument",!0,"loadDocument",c.dontAccept),c.addActionRule("loadDocument",!0,"removeDocument",c.wait),c.addActionRule("loadDocument",!1,"saveDocument",c.wait),c.addActionRule("loadDocument",!1,"loadDocument",c.update),c.addActionRule("loadDocument",!1,"removeDocument",c.wait),c.addActionRule("removeDocument",!0,"loadDocument",c.dontAccept),c.addActionRule("removeDocument",!0,"removeDocument",c.dontAccept),c.addActionRule("removeDocument",!1,"saveDocument",c.eliminate),c.addActionRule("removeDocument",!1,"loadDocument",c.dontAccept),c.addActionRule("removeDocument",!1,"removeDocument",c.update),c.addActionRule("getDocumentList",!0,"getDocumentList",c.dontAccept),c.addActionRule("getDocumentList",!1,"getDocumentList",c.update),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.getJobRules=function(){returny},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}();
\ 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),d.done=a.done,d.fail=a.fail,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.done=function(){},d.fail=function(){},d},i=function(a,b){a=a||{},b=b||{};varc=h(a,b);returnc.addJob=function(a,c){b.jobManager.addJob(u({storage:a,command:c}),b)},c},j=function(a,c){vard={};a=a||{},c=c||{};vare={};returne.commandlist={saveDocument:n,loadDocument:l,removeDocument:m,getDocumentList:k},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.respond({status:p(),value:a}),e.done(a),e.end()},d.fail=function(a){e.option.max_retry===0||e.tried<e.option.max_retry?e.retry():(e.respond({status:q(),error:a}),e.fail(a),e.end())},d.onResponseDo=function(a){e.respond=a},d.onDoneDo=function(a){e.done=a},d.onFailDo=function(a){e.fail=a},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.clone=function(){returnj(d.serialized(),c)},d)},k=function(a,b){varc=j(a,b);a=a||{},b=b||{},c.getLabel=function(){return"getDocumentList"},c.executeOn=function(a){a.getDocumentList(c)},c.canBeRestored=function(){return!1};vard=c.done;returnc.done=function(a){varb;if(a)for(b=0;b<a.length;b+=1)typeofa[b].last_modified!="number"&&(a[b].last_modified=(newDate(a[b].last_modified)).getTime()),typeofa[b].creation_date!="number"&&(a[b].creation_date=(newDate(a[b].creation_date)).getTime());d(a)},c},l=function(a,b){varc=j(a,b);a=a||{},b=b||{},c.getLabel=function(){return"loadDocument"},c.executeOn=function(a){a.loadDocument(c)},c.canBeRestored=function(){return!1};vard=c.done;returnc.done=function(a){a&&(typeofa.last_modified!="number"&&(a.last_modified=(newDate(a.last_modified)).getTime()),typeofa.creation_date!="number"&&(a.creation_date=(newDate(a.creation_date)).getTime())),d(a)},c},m=function(a,b){varc=j(a,b);returna=a||{},b=b||{},c.getLabel=function(){return"removeDocument"},c.executeOn=function(a){a.removeDocument(c)},c},n=function(a,c){vard=j(a,c);a=a||{},c=c||{};vare={};e.content=a.content,d.getLabel=function(){return"saveDocument"},d.getContent=function(){returne.content};varf=d.validate;d.validate=function(a){if(typeofe.content!="string")throwb({command:d,message:"No data to save"});f(a)},d.executeOn=function(a){a.saveDocument(d)};varg=d.serialized;returnd.serialized=function(){vara=g();returna.content=e.content,a},d},o=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.isWaitStatus=function(){return!1},c},p=function(a,b){varc=o(a,b);returna=a||{},b=b||{},c.getLabel=function(){return"done"},c.canStart=function(){return!1},c.canRestart=function(){return!1},c},q=function(a,b){varc=o(a,b);returna=a||{},b=b||{},c.getLabel=function(){return"fail"},c.canStart=function(){return!1},c.canRestart=function(){return!0},c},r=function(a,b){varc=o(a,b);returna=a||{},b=b||{},c.getLabel=function(){return"initial"},c.canStart=function(){return!0},c.canRestart=function(){return!0},c},s=function(a,b){varc=o(a,b);returna=a||{},b=b||{},c.getLabel=function(){return"on going"},c.canStart=function(){return!1},c.canRestart=function(){return!1},c},t=function(a,b){varc=o(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=[],c;for(c=0;c<d.job_id_a.length;c+=1)b.jobManager.jobIdExists(d.job_id_a[c])&&a.push(d.job_id_a[c]);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.isWaitStatus=function(){return!0},c},u=function(a,b){varc={};a=a||{},b=b||{};vard={};returnd.id=b.jobIdHandler.nextId(),d.command=a.command,d.storage=a.storage,d.status=r(),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=t({},b)),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=t({},b)),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=s(),d.command.onRetryDo(function(){vara=d.command.getTried();a=a*a*200,a>1e4&&(a=1e4),c.waitForTime(a)}),d.command.onEndDo(function(){b.jobManager.terminateJob(c)}),d.command.execute(d.storage)},c},v=function(a,b){varc={};a=a||{},b=b||{};vard=[],e=a.name||"",f=a.announcer||{};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(){f.register(c)},c.unregister=function(){f.unregister(c)},c.trigger=function(a){varb;for(b=0;b<d.length;b++)d[b].apply(null,a)},c},w=function(a,b){varc=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}(),d=function(a,b){varc={};a=a||{},b=b||{};vard={};returnc.register=function(a){d[a]||(d[a]=v())},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}(),e=function(a,b){varc={};a=a||{},b=b||{};vard=0;returnc.nextId=function(){returnd=d+1,d},c}(),f=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=[],b.jobManager=c,b.jobIdHandler=c,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(){e.restoreOldJio();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()))},e.restoreOldJio=function(){vara,b;e.lastrestore=e.lastrestore||0;if(e.lastrestore>Date.now()-2e3)return;b=LocalOrCookieStorage.getItem("jio/id_array")||[];for(a=0;a<b.length;a+=1)e.restoreOldJioId(b[a]);e.lastrestore=Date.now()},e.restoreOldJioId=function(a){varb;b=LocalOrCookieStorage.getItem("jio/id/"+a)||0,b<Date.now()-1e4&&(e.restoreOldJobFromJioId(a),e.removeOldJioId(a),e.removeJobArrayFromJioId(a))},e.restoreOldJobFromJioId=function(a){vard,e;e=LocalOrCookieStorage.getItem("jio/job_array/"+a)||[];for(d=0;d<e.length;d+=1){varf=j(e[d].command,b);f.canBeRestored()&&c.addJob(u({storage:x.storage(e[d].storage,b),command:f},b))}},e.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)},e.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}}e.copyJobArrayToLocal()},c.jobIdExists=function(a){varb;for(b=0;b<e.job_a.length;b+=1)if(e.job_a[b].getId()===a)return!0;return!1},c.terminateJob=function(a){e.removeJob(a)},c.addJob=function(a){varb=c.validateJobAccordingToJobList(e.job_a,a);e.appendJob(a,b)},c.validateJobAccordingToJobList=function(a,b){varc,d=[];for(c=0;c<a.length;c+=1)d.push(g.validateJobAccordingToJob(a[c],b));returnd},e.appendJob=function(a,b){varc;if(e.job_a.length!==b.length)thrownewRangeError("Array out of bound");for(c=0;c<b.length;c+=1)if(b[c].action==="dont accept")return;for(c=0;c<b.length;c+=1)switch(b[c].action){case"eliminate":e.removeJob(b[c].job);break;case"update":b[c].job.update(a),e.copyJobArrayToLocal();return;case"wait":a.waitForJob(b[c].job);break;default:}e.job_a.push(a),e.copyJobArrayToLocal()},c}(),g=function(a,b){varc={},d={};returnd.compare={},d.action={},c.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"},c.default_action=c.none,c.default_compare=function(a,b){returna.getCommand().getPath()===b.getCommand().getPath()&&JSON.stringify(a.getStorage().serialized())===JSON.stringify(b.getStorage().serialized())},d.getAction=function(a,b){vare,f,g;returne=a.getCommand().getLabel(),f=b.getCommand().getLabel(),g=a.getStatus().getLabel()==="on going"?"on going":"not on going",d.action[e]&&d.action[e][g]&&d.action[e][g][f]?d.action[e][g][f](a,b):c.default_action(a,b)},d.canCompare=function(a,b){vare=a.getCommand().getLabel(),f=b.getCommand().getLabel();returnd.compare[e]&&d.compare[f]?d.compare[e][f](a,b):c.default_compare(a,b)},c.validateJobAccordingToJob=function(a,b){returnd.canCompare(a,b)?{action:d.getAction(a,b),job:a}:{action:c.default_action(a,b),job:a}},c.addActionRule=function(a,b,c,e){varf=b?"on going":"not on going";d.action[a]=d.action[a]||{},d.action[a][f]=d.action[a][f]||{},d.action[a][f][c]=e},c.addCompareRule=function(a,b,c){d.compare[a]=d.compare[a]||{},d.compare[a][b]=c},c.addActionRule("saveDocument",!0,"saveDocument",function(a,b){returna.getCommand().getContent()===b.getCommand().getContent()?c.dontAccept():c.wait()}),c.addActionRule("saveDocument",!0,"loadDocument",c.wait),c.addActionRule("saveDocument",!0,"removeDocument",c.wait),c.addActionRule("saveDocument",!1,"saveDocument",c.update),c.addActionRule("saveDocument",!1,"loadDocument",c.wait),c.addActionRule("saveDocument",!1,"removeDocument",c.eliminate),c.addActionRule("loadDocument",!0,"saveDocument",c.wait),c.addActionRule("loadDocument",!0,"loadDocument",c.dontAccept),c.addActionRule("loadDocument",!0,"removeDocument",c.wait),c.addActionRule("loadDocument",!1,"saveDocument",c.wait),c.addActionRule("loadDocument",!1,"loadDocument",c.update),c.addActionRule("loadDocument",!1,"removeDocument",c.wait),c.addActionRule("removeDocument",!0,"loadDocument",c.dontAccept),c.addActionRule("removeDocument",!0,"removeDocument",c.dontAccept),c.addActionRule("removeDocument",!1,"saveDocument",c.eliminate),c.addActionRule("removeDocument",!1,"loadDocument",c.dontAccept),c.addActionRule("removeDocument",!1,"removeDocument",c.update),c.addActionRule("getDocumentList",!0,"getDocumentList",c.dontAccept),c.addActionRule("getDocumentList",!1,"getDocumentList",c.update),c}(),h={};a=a||{},b=b||{};vari={},o="jio/id_array";returni.id=null,b.jobManager=f,b.jobIdHandler=e,i.storage=x.storage(a,b),i.init=function(){if(i.id===null){vara,b=LocalOrCookieStorage.getItem(o)||[];i.id=1;for(a=0;a<b.length;a+=1)b[a]>=i.id&&(i.id=b[a]+1);b.push(i.id),LocalOrCookieStorage.setItem(o,b),c.setId(i.id),f.setId(i.id)}},h.start=function(){i.init(),c.start(),f.start()},h.stop=function(){f.stop()},h.close=function(){c.stop(),f.stop(),i.id=null},h.start(),h.getId=function(){returni.id},h.getJobRules=function(){returng},h.validateStorageDescription=function(a){returnx.storage(a,b).isValid()},h.saveDocument=function(a,c,d,e){d=d||{},d.onResponse=d.onResponse||function(){},d.onDone=d.onDone||function(){},d.onFail=d.onFail||function(){},d.max_retry=d.max_retry||0,f.addJob(u({storage:e?x.storage(e,b):i.storage,command:n({path:a,content:c,option:d})},b))},h.loadDocument=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:!1,f.addJob(u({storage:d?x.storage(d,b):i.storage,command:l({path:a,option:c})},b))},h.removeDocument=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,f.addJob(u({storage:d?x.storage(d,b):i.storage,command:m({path:a,option:c})},b))},h.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,f.addJob(u({storage:d?x.storage(d,b):i.storage,command:k({path:a,option:c})},b))},h},x=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"},w(a)},c.addStorageType=function(a,b){b=b||function(){returnnull};if(e[a])throwd({type:a,message:"Already known."});e[a]=b},c}();returnx}();
(function(){vara=function(a,b,c,d,e){varf,g,h,i,j;f=function(b,c){vard=e.newBaseStorage(b,c),f={};returnf.storage_user_array_name="jio/local_user_array",f.storage_file_array_name="jio/local_file_name_array/"+d.getStorageUserName()+"/"+d.getApplicantID(),f.getUserArray=function(){returna.getItem(f.storage_user_array_name)||[]},f.addUser=function(b){varc=f.getUserArray();c.push(b),a.setItem(f.storage_user_array_name,c)},f.userExists=function(a){varb=f.getUserArray(),c,d;for(c=0,d=b.length;c<d;c+=1)if(b[c]===a)return!0;return!1},f.getFileNameArray=function(){returna.getItem(f.storage_file_array_name)||[]},f.addFileName=function(b){varc=f.getFileNameArray();c.push(b),a.setItem(f.storage_file_array_name,c)},f.removeFileName=function(b){varc,d,e=f.getFileNameArray(),g=[];for(c=0,d=e.length;c<d;c+=1)e[c]!==b&&g.push(e[c]);a.setItem(f.storage_file_array_name,g)},d.checkNameAvailability=function(){setTimeout(function(){d.done(!f.userExists(d.getUserName()))},100)},d.saveDocument=function(){setTimeout(function(){varb=null,c="jio/local/"+d.getStorageUserName()+"/"+d.getApplicantID()+"/"+d.getFileName();returnb=a.getItem(c),b?(b.last_modified=Date.now(),b.content=d.getFileContent()):(b={name:d.getFileName(),content:d.getFileContent(),creation_date:Date.now(),last_modified:Date.now()},f.userExists(d.getStorageUserName())||f.addUser(d.getStorageUserName()),f.addFileName(d.getFileName())),a.setItem(c,b),d.done()},100)},d.loadDocument=function(){setTimeout(function(){varb=null,c=d.cloneOptionObject();b=a.getItem("jio/local/"+d.getStorageUserName()+"/"+d.getApplicantID()+"/"+d.getFileName()),b?(c.metadata_only?deleteb.content:c.content_only&&(deleteb.last_modified,deleteb.creation_date),d.done(b)):d.fail({status:404,statusText:"Not Found.",message:'Document "'+d.getFileName()+'" not found in localStorage.'})},100)},d.getDocumentList=function(){setTimeout(function(){varb=[],c=[],e,g,h="key",i="jio/local/"+d.getStorageUserName()+"/"+d.getApplicantID(),j={};c=f.getFileNameArray();for(e=0,g=c.length;e<g;e+=1)j=a.getItem(i+"/"+c[e]),j&&b.push({name:j.name,creation_date:j.creation_date,last_modified:j.last_modified});d.done(b)},100)},d.removeDocument=function(){setTimeout(function(){varb="jio/local/"+d.getStorageUserName()+"/"+d.getApplicantID()+"/"+d.getFileName();returna.deleteItem(b),f.removeFileName(d.getFileName()),d.done()},100)},d},g=function(a,d){varf=e.newBaseStorage(a,d);returnf.mkcol=function(a){vard=b.extend({success:function(){},error:function(){}},a),e=["split_path"],g="temp/path";if(!d.pathsteps)d.pathsteps=1,f.mkcol(d);else{e=d.path.split("/");if(d.pathsteps>=e.length-1)returnd.success();e.length=d.pathsteps+1,d.pathsteps++,g=e.join("/"),b.ajax({url:d.url+g,type:"MKCOL",async:!0,headers:{Authorization:"Basic "+c.encode(d.user_name+":"+d.password),Depth:"1"},success:function(){f.mkcol(d)},error:function(a){d.error()}})}},f.checkNameAvailability=function(){b.ajax({url:f.getStorageURL()+"/dav/"+f.getStorageUserName()+"/",async:!0,type:"PROPFIND",dataType:"xml",headers:{Authorization:"Basic "+c.encode(f.getStorageUserName()+":"+f.getStoragePassword()),Depth:"1"},success:function(a){f.done(!1)},error:function(a){a.status===404?f.done(!0):(a.message='Cannot check availability of "'+f.getUserName()+'" into DAVStorage.',f.fail(a))}})},f.saveDocument=function(){b.ajax({url:f.getStorageURL()+"/dav/"+f.getStorageUserName()+"/"+f.getApplicantID()+"/"+f.getFileName(),type:"PUT",data:f.getFileContent(),async:!0,dataType:"text",headers:{Authorization:"Basic "+c.encode(f.getStorageUserName()+":"+f.getStoragePassword())},success:function(){f.done()},error:function(a){a.message='Cannot save "'+f.getFileName()+'" into DAVStorage.',f.fail(a)}})},f.loadDocument=function(){vara={},d=f.cloneOptionObject(),e=function(){b.ajax({url:f.getStorageURL()+"/dav/"+f.getStorageUserName()+"/"+f.getApplicantID()+"/"+f.getFileName(),type:"GET",async:!0,dataType:"text",headers:{Authorization:"Basic "+c.encode(f.getStorageUserName()+":"+f.getStoragePassword())},success:function(b){a.content=b,f.done(a)},error:function(a){a.status===404?a.message='Document "'+f.getFileName()+'" not found in localStorage.':a.message='Cannot load "'+f.getFileName()+'" from DAVStorage.',f.fail(a)}})};a.name=f.getFileName();if(d.content_only){e();return}b.ajax({url:f.getStorageURL()+"/dav/"+f.getStorageUserName()+"/"+f.getApplicantID()+"/"+f.getFileName(),type:"PROPFIND",async:!0,dataType:"xml",headers:{Authorization:"Basic "+c.encode(f.getStorageUserName()+":"+f.getStoragePassword())},success:function(c){b(c).find("lp1\\:getlastmodified, getlastmodified").each(function(){a.last_modified=b(this).text()}),b(c).find("lp1\\:creationdate, creationdate").each(function(){a.creation_date=b(this).text()}),d.metadata_only?f.done(a):e()},error:function(a){a.message='Cannot load "'+f.getFileName()+'" informations from DAVStorage.',f.fail(a)}})},f.getDocumentList=function(){vara=[],d={},e=[];b.ajax({url:f.getStorageURL()+"/dav/"+f.getStorageUserName()+"/"+f.getApplicantID()+"/",async:!0,type:"PROPFIND",dataType:"xml",headers:{Authorization:"Basic "+c.encode(f.getStorageUserName()+":"+f.getStoragePassword()),Depth:"1"},success:function(c){b(c).find("D\\:response, response").each(function(c,f){if(c>0){d={},b(f).find("D\\:href, href").each(function(){e=b(this).text().split("/"),d.name=e[e.length-1]?e[e.length-1]:e[e.length-2]+"/"});if(d.name===".htaccess"||d.name===".htpasswd")return;b(f).find("lp1\\:getlastmodified, getlastmodified").each(function(){d.last_modified=b(this).text()}),b(f).find("lp1\\:creationdate, creationdate").each(function(){d.creation_date=b(this).text()}),a.push(d)}}),f.done(a)},error:function(a){a.message="Cannot get a document list from DAVStorage.",f.fail(a)}})},f.removeDocument=function(){b.ajax({url:f.getStorageURL()+"/dav/"+f.getStorageUserName()+"/"+f.getApplicantID()+"/"+f.getFileName(),type:"DELETE",async:!0,headers:{Authorization:"Basic "+c.encode(f.getStorageUserName()+":"+f.getStoragePassword())},success:function(){f.done()},error:function(a){a.status===404?f.done():(a.message='Cannot remove "'+f.getFileName()+'" from DAVStorage.',f.fail(a))}})},f},h=function(a,b){varc=e.newBaseStorage(a,b),d={};returnd.storageArray=c.getStorageArray(),d.length=d.storageArray.length,d.return_value_array=[],d.max_tries=c.getMaxTries(),c.setMaxTries(1),d.execJobsFromStorageArray=function(a){varb={},e;for(e=0;e<d.storageArray.length;e+=1)b=c.cloneJob(),b.max_tries=d.max_tries,b.storage=d.storageArray[e],b.callback=a,c.addJob(b)},c.checkNameAvailability=function(){vara="id",b=!1,e=[],f={status:"done"},g=function(a){d.return_value_array.push(a);if(!b){if(a.status==="fail")f.status="fail",e.push(a.error);elseif(a.return_value===!1){c.done(!1),b=!0;return}if(d.return_value_array.length===d.length){f.status==="fail"?c.fail({status:207,statusText:"Multi-Status",message:'Some check availability of "'+c.getUserName()+'" requests have failed.',array:e}):c.done(!0),b=!0;return}}};d.execJobsFromStorageArray(g)},c.saveDocument=function(){vara={status:"done"},b="id",e=!1,f=[],g=function(a){d.return_value_array.push(a),e||(a.status!=="fail"?(c.done(),e=!0):(f.push(a.error),d.return_value_array.length===d.length&&c.fail({status:207,statusText:"Multi-Status",message:'All save "'+c.getFileName()+'" requests have failed.',array:f})))};d.execJobsFromStorageArray(g)},c.loadDocument=function(){vara={},b="id",e=!1,f=[],g={status:"done"},h=function(a){d.return_value_array.push(a),e||(a.status!=="fail"?(c.done(a.return_value),e=!0):(f.push(a.error),d.return_value_array.length===d.length&&c.fail({status:207,statusText:"Multi-Status",message:'All load "'+c.getFileName()+'" requests have failed.',array:f})))};d.execJobsFromStorageArray(h)},c.getDocumentList=function(){vara={status:"done"},b="id",e=!1,f=[],g=function(a){d.return_value_array.push(a),e||(a.status!=="fail"?(c.done(a.return_value),e=!0):(f.push(a.error),d.return_value_array.length===d.length&&c.fail({status:207,statusText:"Multi-Status",message:"All get document list requests have failed",array:f})))};d.execJobsFromStorageArray(g)},c.removeDocument=function(){vara={status:"done"},b="key",e=!1,f=[],g=function(a){d.return_value_array.push(a),e||(a.status!=="fail"?(c.done(),e=!0):(f.push(a.error),d.return_value_array.length===d.length&&c.fail({status:207,statusText:"Multi-Status",message:'All remove "'+c.getFileName()+'" requests have failed.',array:f})))};d.execJobsFromStorageArray(g)},c},i=function(b,c){vard=e.newBaseStorage(b,c),f={};returnf.storage_array_name="jio/indexed_storage_array",f.storage_file_array_name="jio/indexed_file_array/"+JSON.stringify(d.getSecondStorage())+"/"+d.getApplicantID(),f.indexedStorageArrayExists=function(){returna.getItem(f.storage_array_name)?!0:!1},f.getIndexedStorageArray=function(){returna.getItem(f.storage_array_name)||[]},f.addIndexedStorage=function(b){varc=f.getIndexedStorageArray();c.push(JSON.stringify(b)),a.setItem(f.storage_array_name,c)},f.isAnIndexedStorage=function(a){varb=JSON.stringify(a),c,d,e=f.getIndexedStorageArray();for(c=0,d=e.length;c<d;c+=1)if(JSON.stringify(e[c])===b)return!0;return!1},f.fileArrayExists=function(){returna.getItem(f.storage_file_array_name)?!0:!1},f.getFileArray=function(){returna.getItem(f.storage_file_array_name)||[]},f.setFileArray=function(b){returna.setItem(f.storage_file_array_name,b)},f.isFileIndexed=function(a){varb,c,d=f.getFileArray();for(b=0,c=d.length;b<c;b+=1)if(d[b].name===a)return!0;return!1},f.addFile=function(b){varc=f.getFileArray();c.push(b),a.setItem(f.storage_file_array_name,c)},f.removeFile=function(b){varc,d,e=f.getFileArray(),g=[];for(c=0,d=e.length;c<d;c+=1)e[c].name!==b&&g.push(e[c]);a.setItem(f.storage_file_array_name,g)},f.update=function(a){varb=function(a){a.status==="done"&&(f.isAnIndexedStorage(d.getSecondStorage())||f.addIndexedStorage(d.getSecondStorage()),f.setFileArray(a.return_value))},c={storage:d.getSecondStorage(),applicant:{ID:d.getApplicantID()},method:"getDocumentList",max_tries:3,callback:b};d.addJob(c)},d.checkNameAvailability=function(){vara=d.cloneJob();f.update(),a.storage=d.getSecondStorage(),a.callback=function(a){a.status==="done"?d.done(a.return_value):d.fail(a.error)},d.addJob(a)},d.saveDocument=function(){vara=d.cloneJob();a.storage=d.getSecondStorage(),a.callback=function(a){a.status==="done"?(f.isFileIndexed(d.getFileName())||f.addFile({name:d.getFileName(),last_modified:0,creation_date:0}),f.update(),d.done()):d.fail(a.error)},d.addJob(a)},d.loadDocument=function(){vara,b,c,e,g=function(a){a.status==="done"?d.done(a.return_value):d.fail(a.error)},h=function(){e=d.cloneJob(),e.storage=d.getSecondStorage(),e.callback=g,d.addJob(e)},i=d.cloneOptionObject();f.update(),i.metadata_only?setTimeout(function(){if(f.fileArrayExists()){a=f.getFileArray();for(b=0,c=a.length;b<c;b+=1)if(a[b].name===d.getFileName())returnd.done(a[b])}elseh()},100):h()},d.getDocumentList=function(){vara;f.update(),a=setInterval(function(){f.fileArrayExists()&&(d.done(f.getFileArray()),clearInterval(a))},100)},d.removeDocument=function(){vara=d.cloneJob();a.storage=d.getSecondStorage(),a.callback=function(a){a.status==="done"?(f.removeFile(d.getFileName()),f.update(),d.done()):d.fail(a.error)},d.addJob(a)},d},j=function(a,c){varf=e.newBaseStorage(a,c),g={};returng.encrypt_param_object={iv:"kaprWwY/Ucr7pumXoTHbpA",v:1,iter:1e3,ks:256,ts:128,mode:"ccm",adata:"",cipher:"aes",salt:"K4bmZG9d704"},g.decrypt_param_object={iv:"kaprWwY/Ucr7pumXoTHbpA",ks:256,ts:128,salt:"K4bmZG9d704"},g.encrypt=function(a,b,c){vare=d.encrypt(f.getStorageUserName()+":"+f.getStoragePassword(),a,g.encrypt_param_object);b(JSON.parse(e).ct,c)},g.decrypt=function(a,c,e,h){vari,j=b.extend(!0,{},g.decrypt_param_object);j.ct=a||"",j=JSON.stringify(j);try{i=d.decrypt(f.getStorageUserName()+":"+f.getStoragePassword(),j)}catch(k){c({status:0,statusText:"Decrypt Fail",message:"Unable to decrypt."},e,h);return}c(i,e,h)},f.checkNameAvailability=function(){vara=f.cloneJob();a.storage=f.getSecondStorage(),a.callback=function(a){a.status==="done"?f.done(a.return_value):f.fail(a.error)},f.addJob(a)},f.saveDocument=function(){vara,b,c,d=function(){g.encrypt(f.getFileName(),function(a){b=a,e()})},e=function(){g.encrypt(f.getFileContent(),function(a){c=a,h()})},h=function(){a=f.cloneJob(),a.name=b,a.content=c,a.storage=f.getSecondStorage(),a.callback=function(a){a.status==="done"?f.done():f.fail(a.error)},f.addJob(a)};d()},f.loadDocument=function(){vara,b,c=f.cloneOptionObject(),d=function(){g.encrypt(f.getFileName(),function(a){b=a,e()})},e=function(){a=f.cloneJob(),a.name=b,a.storage=f.getSecondStorage(),a.callback=h,f.addJob(a)},h=function(a){a.status==="done"?(a.return_value.name=f.getFileName(),c.metadata_only?f.done(a.return_value):g.decrypt(a.return_value.content,function(b){typeofb=="object"?f.fail({status:0,statusText:"Decrypt Fail",message:"Unable to decrypt"}):(a.return_value.content=b,f.done(a.return_value))})):f.fail(a.error)};d()},f.getDocumentList=function(){vara,b,c,d=0,e,h=!0,i=function(){a=f.cloneJob(),a.storage=f.getSecondStorage(),a.callback=j,f.addJob(a)},j=function(a){if(a.status==="done"){e=a.return_value;for(b=0,c=e.length;b<c;b+=1)g.decrypt(e[b].name,k,b,"name")}elsef.fail(a.error)},k=function(a,b,g){vari;d++;if(typeofa=="object"){h&&f.fail({status:0,statusText:"Decrypt Fail",message:"Unable to decrypt."}),h=!1;return}e[b][g]=a,d===c&&h&&f.done(e)};i()},f.removeDocument=function(){vara,b,c=function(){g.encrypt(f.getFileName(),function(a){b=a,d()})},d=function(){a=f.cloneJob(),a.name=b,a.storage=f.getSecondStorage(),a.callback=e,f.addJob(a)},e=function(a){a.status==="done"?f.done():f.fail(a.error)};c()},f},e.addStorageType("local",f),e.addStorageType("dav",g),e.addStorageType("replicate",h),e.addStorageType("indexed",i),e.addStorageType("crypted",j)};window.requirejs?define("JIOStorages",["LocalOrCookieStorage","jQuery","Base64","SJCL","JIO"],a):a(LocalOrCookieStorage,jQuery,Base64,sjcl,JIO)})();
\ No newline at end of file
(function(a,b,c,d,e){varf=function(b,c){vard=e.storage(b,c,"base"),f={};f.username=b.username||"",f.applicationname=b.applicationname||"untitled";varg="jio/local_user_array",h="jio/local_file_name_array/"+f.username+"/"+f.applicationname,i=d.serialized;returnd.serialized=function(){vara=i();returna.applicationname=f.applicationname,a.username=f.username,a},d.validateState=function(){returnf.username?"":'Need at least one parameter: "username".'},f.getUserArray=function(){returna.getItem(g)||[]},f.addUser=function(b){varc=f.getUserArray();c.push(b),a.setItem(g,c)},f.userExists=function(a){varb=f.getUserArray(),c,d;for(c=0,d=b.length;c<d;c+=1)if(b[c]===a)return!0;return!1},f.getFileNameArray=function(){returna.getItem(h)||[]},f.addFileName=function(b){varc=f.getFileNameArray();c.push(b),a.setItem(h,c)},f.removeFileName=function(b){varc,d,e=f.getFileNameArray(),g=[];for(c=0,d=e.length;c<d;c+=1)e[c]!==b&&g.push(e[c]);a.setItem(h,g)},d.saveDocument=function(b){setTimeout(function(){varc=null,e="jio/local/"+f.username+"/"+f.applicationname+"/"+b.getPath();c=a.getItem(e),c?(c.last_modified=Date.now(),c.content=b.getContent()):(c={name:b.getPath(),content:b.getContent(),creation_date:Date.now(),last_modified:Date.now()},f.userExists(f.username)||f.addUser(f.username),f.addFileName(b.getPath())),a.setItem(e,c),d.done()},100)},d.loadDocument=function(b){setTimeout(function(){varc=null;c=a.getItem("jio/local/"+f.username+"/"+f.applicationname+"/"+b.getPath()),c?(b.getOption("metadata_only")&&deletec.content,d.done(c)):d.fail(b,{status:404,statusText:"Not Found.",message:'Document "'+b.getPath()+'" not found in localStorage.'})},100)},d.getDocumentList=function(b){setTimeout(function(){varc=[],e=[],g,h,i="key",j="jio/local/"+f.username+"/"+f.applicationname,k={};e=f.getFileNameArray();for(g=0,h=e.length;g<h;g+=1)k=a.getItem(j+"/"+e[g]),k&&(b.getOption("metadata_only")?c.push({name:k.name,creation_date:k.creation_date,last_modified:k.last_modified}):c.push({name:k.name,content:k.content,creation_date:k.creation_date,last_modified:k.last_modified}));d.done(c)},100)},d.removeDocument=function(b){setTimeout(function(){varc="jio/local/"+f.username+"/"+f.applicationname+"/"+b.getPath();a.deleteItem(c),f.removeFileName(b.getPath()),d.done()},100)},d};e.addStorageType("local",f);varg=function(a,d){varf=e.storage(a,d,"base"),g={};g.username=a.username||"",g.applicationname=a.applicationname||"untitled",g.url=a.url||"",g.password=a.password||"";varh=f.serialized;returnf.serialized=function(){vara=h();returna.username=g.username,a.applicationname=g.applicationname,a.url=g.url,a.password=g.password,a},f.validateState=function(){returng.username&&g.url?"":'Need at least 2 parameters: "username" and "url".'},f.saveDocument=function(a){b.ajax({url:g.url+"/dav/"+g.username+"/"+g.applicationname+"/"+a.getPath(),type:"PUT",data:a.getContent(),async:!0,dataType:"text",headers:{Authorization:"Basic "+c.encode(g.username+":"+g.password)},success:function(){f.done()},error:function(b){b.message='Cannot save "'+a.getPath()+'" into DAVStorage.',f.fail(b)}})},f.loadDocument=function(a){vard={},e=function(){b.ajax({url:g.url+"/dav/"+g.username+"/"+g.applicationname+"/"+a.getPath(),type:"GET",async:!0,dataType:"text",headers:{Authorization:"Basic "+c.encode(g.username+":"+g.password)},success:function(a){d.content=a,f.done(d)},error:function(b){b.status===404?b.message='Document "'+a.getPath()+'" not found in localStorage.':b.message='Cannot load "'+a.getPath()+'" from DAVStorage.',f.fail(b)}})};d.name=a.getPath(),b.ajax({url:g.url+"/dav/"+g.username+"/"+g.applicationname+"/"+a.getPath(),type:"PROPFIND",async:!0,dataType:"xml",headers:{Authorization:"Basic "+c.encode(g.username+":"+g.password)},success:function(c){b(c).find("lp1\\:getlastmodified, getlastmodified").each(function(){d.last_modified=b(this).text()}),b(c).find("lp1\\:creationdate, creationdate").each(function(){d.creation_date=b(this).text()}),a.getOption("metadata_only")?f.done(d):e()},error:function(b){b.message='Cannot load "'+a.getPath()+'" informations from DAVStorage.',f.fail(b)}})},f.getDocumentList=function(a){vard=[],e={},h=[];b.ajax({url:g.url+"/dav/"+g.username+"/"+g.applicationname+"/",async:!0,type:"PROPFIND",dataType:"xml",headers:{Authorization:"Basic "+c.encode(g.username+":"+g.password),Depth:"1"},success:function(a){b(a).find("D\\:response, response").each(function(a,c){if(a>0){e={},b(c).find("D\\:href, href").each(function(){h=b(this).text().split("/"),e.name=h[h.length-1]?h[h.length-1]:h[h.length-2]+"/"});if(e.name===".htaccess"||e.name===".htpasswd")return;b(c).find("lp1\\:getlastmodified, getlastmodified").each(function(){e.last_modified=b(this).text()}),b(c).find("lp1\\:creationdate, creationdate").each(function(){e.creation_date=b(this).text()}),d.push(e)}}),f.done(d)},error:function(a){a.message="Cannot get a document list from DAVStorage.",f.fail(a)}})},f.removeDocument=function(a){b.ajax({url:g.url+"/dav/"+g.username+"/"+g.applicationname+"/"+a.getPath(),type:"DELETE",async:!0,headers:{Authorization:"Basic "+c.encode(g.username+":"+g.password)},success:function(){f.done()},error:function(a){a.status===404?f.done():(a.message='Cannot remove "'+f.getFileName()+'" from DAVStorage.',f.fail(a))}})},f};e.addStorageType("dav",g);varh=function(a,b){varc=e.storage(a,b,"handler"),d={};returnd.return_value_array=[],d.storagelist=a.storagelist||[],d.nb_storage=d.storagelist.length,d.isTheLast=function(){returnd.return_value_array.length===d.nb_storage},d.doJob=function(a,f){varg=!1,h=[],i,j=function(a){console.log("respond"),d.return_value_array.push(a)},k=function(a){g||(console.log("fail"),h.push(a),d.isTheLast()&&c.fail({status:207,statusText:"Multi-Status",message:f,array:h}))},l=function(a){g||(console.log("done"),g=!0,c.done(a))};a.setMaxRetry(1);for(i=0;i<d.nb_storage;i+=1){varm=a.clone(),n=e.storage(d.storagelist[i],b);m.onResponseDo(j),m.onFailDo(k),m.onDoneDo(l),c.addJob(n,m)}},c.saveDocument=function(a){d.doJob(a.clone(),'All save "'+a.getPath()+'" requests have failed.')},c.loadDocument=function(a){d.doJob(a.clone(),'All load "'+a.getPath()+'" requests have failed.')},c.getDocumentList=function(a){d.doJob(a.clone(),"All get document list requests have failed.")},c.removeDocument=function(a){d.doJob(a.clone(),'All remove "'+a.getPath()+'" requests have failed.')},c};e.addStorageType("replicate",h)})(LocalOrCookieStorage,jQuery,Base64,sjcl,jio);