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.fileName===b.fileName?!0:!1},canRemoveFailOrDone:function(a,b){returna.status==="fail"||a.status==="done"?!0:!1},canEliminate:function(a,b){returna.status!=="ongoing"&&(a.method==="removeDocument"&&b.method==="saveDocument"||a.method==="saveDocument"&&b.method==="removeDocument")?!0:!1},canReplace:function(a,b){returna.status!=="ongoing"&&a.method===b.method&&a.date<b.date?!0:!1},cannotAccept:function(a,b){if(a.status!=="ongoing"){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.fileContent===b.fileContent)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/idarray";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/jobobject/"+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/jobobject/"+e[b]),a.deleteItem("jio/jobobject/"+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.waitingFor={jobIdArray:e};for(k=0;k<e.length;k+=1)i.job_object[e[k]]&&(i.job_object[e[k]].maxtries=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].waitingFor.jobIdArray)for(b=0;b<i.job_object[a].waitingFor.jobIdArray.length;b+=1)if(i.job_object[i.job_object[a].waitingFor.jobIdArray[b]]){c=!1;break}i.job_object[a].waitingFor.time&&i.job_object[a].waitingFor.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="ongoing":(a.status="ongoing",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==="ongoing"||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.userName+" 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.lastModified=(newDate(e.res.return_value.lastModified)).getTime(),e.res.return_value.creationDate=(newDate(e.res.return_value.creationDate)).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].lastModified!="number"&&(e.res.return_value[b].lastModified=(newDate(e.res.return_value[b].lastModified)).getTime()),typeofe.res.return_value[b].creationDate!="number"&&(e.res.return_value[b].creationDate=(newDate(e.res.return_value[b].creationDate)).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.waitingFor={time:Date.now()+a}},c.cloneJob=function(){returnb.extend(!0,{},e.job)},c.getUserName=function(){returne.job.userName||""},c.getApplicantID=function(){returne.job.applicant.ID||""},c.getStorageUserName=function(){returne.job.storage.userName||""},c.getStoragePassword=function(){returne.job.storage.password||""},c.getStorageLocation=function(){returne.job.storage.location||""},c.getSecondStorage=function(){returne.job.storage.storage||{}},c.getStorageArray=function(){returne.job.storage.storageArray||[]},c.getFileName=function(){returne.job.fileName||""},c.getFileContent=function(){returne.job.fileContent||""},c.cloneOptionObject=function(){returnb.extend(!0,{},e.job.options)},c.getMaxTries=function(){returne.job.maxtries},c.getTries=function(){returne.job.tries||0},c.setMaxTries=function(a){e.job.maxtries=a},c.addJob=function(a){returne.queue.createJob(a)},c.eliminate=function(){e.job.maxtries=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.maxtries||e.job.tries<e.job.maxtries?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,{userName:j.storage.userName,storage:j.storage,applicant:j.applicant,method:"checkNameAvailability",callback:function(){}},a);returnf.isReady()&&c.userName&&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,fileContent:"",method:"saveDocument",callback:function(){}},a);returnf.isReady()&&c.fileName&&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.fileName&&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.fileName&&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.createNew=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={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)}();
(function(){vara=function(a,b,c,d){vare,f,g,h,i;e=function(b,d){vare=c.newBaseStorage(b,d),f={};returnf.storage_user_array_name="jio/localuserarray",f.storage_file_array_name="jio/localfilenamearray/"+e.getStorageUserName()+"/"+e.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.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)},e.checkNameAvailability=function(){setTimeout(function(){vara,b,c=f.getUserArray();for(a=0,b=c.length;a<b;a+=1)if(c[a]===e.getUserName()){e.done(!1);return}e.done(!0)},100)},e.saveDocument=function(){setTimeout(function(){varb=null,c="jio/local/"+e.getStorageUserName()+"/"+e.getApplicantID()+"/"+e.getFileName();returnb=a.getItem(c),b?(b.lastModified=Date.now(),b.fileContent=e.getFileContent()):(b={fileName:e.getFileName(),fileContent:e.getFileContent(),creationDate:Date.now(),lastModified:Date.now()},f.addFileName(e.getFileName())),a.setItem(c,b),e.done()},100)},e.loadDocument=function(){setTimeout(function(){varb=null,c=e.cloneOptionObject();b=a.getItem("jio/local/"+e.getStorageUserName()+"/"+e.getApplicantID()+"/"+e.getFileName()),b?(c.metadata_only?deleteb.fileContent:c.content_only&&(deleteb.lastModified,deleteb.creationDate),e.done(b)):e.fail({status:404,statusText:"Not Found.",message:'Document "'+e.getFileName()+'" not found in localStorage.'})},100)},e.getDocumentList=function(){setTimeout(function(){varb=[],c=[],d,g,h="key",i="jio/local/"+e.getStorageUserName()+"/"+e.getApplicantID(),j={};c=f.getFileNameArray();for(d=0,g=c.length;d<g;d+=1)j=a.getItem(i+"/"+c[d]),b.push({fileName:j.fileName,creationDate:j.creationDate,lastModified:j.lastModified});e.done(b)},100)},e.removeDocument=function(){setTimeout(function(){varb="jio/local/"+e.getStorageUserName()+"/"+e.getApplicantID()+"/"+e.getFileName();returna.deleteItem(b),f.removeFileName(e.getFileName()),e.done()},100)},e},f=function(a,e){varf=c.newBaseStorage(a,e);returnf.mkcol=function(a){varc=d.extend({success:function(){},error:function(){}},a),e=["splitedpath"],g="temp/path";if(!c.pathsteps)c.pathsteps=1,f.mkcol(c);else{e=c.path.split("/");if(c.pathsteps>=e.length-1)returnc.success();e.length=c.pathsteps+1,c.pathsteps++,g=e.join("/"),d.ajax({url:c.location+g,type:"MKCOL",async:!0,headers:{Authorization:"Basic "+b.encode(c.userName+":"+c.password),Depth:"1"},success:function(){f.mkcol(c)},error:function(a){c.error()}})}},f.checkNameAvailability=function(){d.ajax({url:f.getStorageLocation()+"/dav/"+f.getStorageUserName()+"/",async:!0,type:"PROPFIND",dataType:"xml",headers:{Authorization:"Basic "+b.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(){d.ajax({url:f.getStorageLocation()+"/dav/"+f.getStorageUserName()+"/"+f.getApplicantID()+"/"+f.getFileName(),type:"PUT",data:f.getFileContent(),async:!0,dataType:"text",headers:{Authorization:"Basic "+b.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={},c=f.cloneOptionObject(),e=function(){d.ajax({url:f.getStorageLocation()+"/dav/"+f.getStorageUserName()+"/"+f.getApplicantID()+"/"+f.getFileName(),type:"GET",async:!0,dataType:"text",headers:{Authorization:"Basic "+b.encode(f.getStorageUserName()+":"+f.getStoragePassword())},success:function(b){a.fileContent=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.fileName=f.getFileName();if(c.content_only){e();return}d.ajax({url:f.getStorageLocation()+"/dav/"+f.getStorageUserName()+"/"+f.getApplicantID()+"/"+f.getFileName(),type:"PROPFIND",async:!0,dataType:"xml",headers:{Authorization:"Basic "+b.encode(f.getStorageUserName()+":"+f.getStoragePassword())},success:function(b){d(b).find("lp1\\:getlastmodified, getlastmodified").each(function(){a.lastModified=d(this).text()}),d(b).find("lp1\\:creationdate, creationdate").each(function(){a.creationDate=d(this).text()}),c.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=[],c={},e=[];d.ajax({url:f.getStorageLocation()+"/dav/"+f.getStorageUserName()+"/"+f.getApplicantID()+"/",async:!0,type:"PROPFIND",dataType:"xml",headers:{Authorization:"Basic "+b.encode(f.getStorageUserName()+":"+f.getStoragePassword()),Depth:"1"},success:function(b){d(b).find("D\\:response, response").each(function(b,f){if(b>0){c={},d(f).find("D\\:href, href").each(function(){e=d(this).text().split("/"),c.fileName=e[e.length-1]?e[e.length-1]:e[e.length-2]+"/"});if(c.fileName===".htaccess"||c.fileName===".htpasswd")return;d(f).find("lp1\\:getlastmodified, getlastmodified").each(function(){c.lastModified=d(this).text()}),d(f).find("lp1\\:creationdate, creationdate").each(function(){c.creationDate=d(this).text()}),a.push(c)}}),f.done(a)},error:function(a){a.message="Cannot get a document list from DAVStorage.",f.fail(a)}})},f.removeDocument=function(){d.ajax({url:f.getStorageLocation()+"/dav/"+f.getStorageUserName()+"/"+f.getApplicantID()+"/"+f.getFileName(),type:"DELETE",async:!0,headers:{Authorization:"Basic "+b.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},g=function(a,b){vard=c.newBaseStorage(a,b),e={};returne.storageArray=d.getStorageArray(),e.length=e.storageArray.length,e.returnsValuesArray=[],e.maxtries=d.getMaxTries(),d.setMaxTries(1),e.execJobsFromStorageArray=function(a){varb={},c;for(c=0;c<e.storageArray.length;c+=1)b=d.cloneJob(),b.maxtries=e.maxtries,b.storage=e.storageArray[c],b.callback=a,d.addJob(b)},d.checkNameAvailability=function(){vara="id",b=!1,c=[],f={status:"done"},g=function(a){e.returnsValuesArray.push(a);if(!b){if(a.status==="fail")f.status="fail",c.push(a.error);elseif(a.return_value===!1){d.done(!1),b=!0;return}if(e.returnsValuesArray.length===e.length){f.status==="fail"?d.fail({status:207,statusText:"Multi-Status",message:'Some check availability of "'+d.getUserName()+'" requests have failed.',array:c}):d.done(!0),b=!0;return}}};e.execJobsFromStorageArray(g)},d.saveDocument=function(){vara={status:"done"},b="id",c=!1,f=[],g=function(a){e.returnsValuesArray.push(a),c||(a.status!=="fail"?(d.done(),c=!0):(f.push(a.error),e.returnsValuesArray.length===e.length&&d.fail({status:207,statusText:"Multi-Status",message:'All save "'+d.getFileName()+'" requests have failed.',array:f})))};e.execJobsFromStorageArray(g)},d.loadDocument=function(){vara={},b="id",c=!1,f=[],g={status:"done"},h=function(a){e.returnsValuesArray.push(a),c||(a.status!=="fail"?(d.done(a.return_value),c=!0):(f.push(a.error),e.returnsValuesArray.length===e.length&&d.fail({status:207,statusText:"Multi-Status",message:'All load "'+d.getFileName()+'" requests have failed.',array:f})))};e.execJobsFromStorageArray(h)},d.getDocumentList=function(){vara={status:"done"},b="id",c=!1,f=[],g=function(a){e.returnsValuesArray.push(a),c||(a.status!=="fail"?(d.done(a.return_value),c=!0):(f.push(a.error),e.returnsValuesArray.length===e.length&&d.fail({status:207,statusText:"Multi-Status",message:"All get document list requests have failed",array:f})))};e.execJobsFromStorageArray(g)},d.removeDocument=function(){vara={status:"done"},b="key",c=!1,f=[],g=function(a){e.returnsValuesArray.push(a),c||(a.status!=="fail"?(d.done(),c=!0):(f.push(a.error),e.returnsValuesArray.length===e.length&&d.fail({status:207,statusText:"Multi-Status",message:'All remove "'+d.getFileName()+'" requests have failed.',array:f})))};e.execJobsFromStorageArray(g)},d},h=function(b,d){vare=c.newBaseStorage(b,d),f={};returnf.storage_array_name="jio/indexedstoragearray",f.storage_file_array_name="jio/indexedfilearray/"+JSON.stringify(e.getSecondStorage())+"/"+e.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].fileName===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].fileName!==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(e.getSecondStorage())||f.addIndexedStorage(e.getSecondStorage()),f.setFileArray(a.return_value))},c={storage:e.getSecondStorage(),applicant:{ID:e.getApplicantID()},method:"getDocumentList",maxtries:3,callback:b};e.addJob(c)},e.checkNameAvailability=function(){vara=e.cloneJob();f.update(),a.storage=e.getSecondStorage(),a.callback=function(a){a.status==="done"?e.done(a.return_value):e.fail(a.error)},e.addJob(a)},e.saveDocument=function(){vara=e.cloneJob();a.storage=e.getSecondStorage(),a.callback=function(a){a.status==="done"?(f.isFileIndexed(e.getFileName())||f.addFile({fileName:e.getFileName(),lastModified:0,creationDate:0}),f.update(),e.done()):e.fail(a.error)},e.addJob(a)},e.loadDocument=function(){vara,b,c,d,g=function(a){a.status==="done"?e.done(a.return_value):e.fail(a.error)},h=function(){d=e.cloneJob(),d.storage=e.getSecondStorage(),d.callback=g,console.log(d),e.addJob(d)},i=e.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].fileName===e.getFileName())returne.done(a[b])}elseh()},100):h()},e.getDocumentList=function(){vara;f.update(),a=setInterval(function(){f.fileArrayExists()&&(e.done(f.getFileArray()),clearInterval(a))},100)},e.removeDocument=function(){vara=e.cloneJob();a.storage=e.getSecondStorage(),a.callback=function(a){a.status==="done"?(f.removeFile(e.getFileName()),f.update(),e.done()):e.fail(a.error)},e.addJob(a)},e},c.addStorageType("local",e),c.addStorageType("dav",f),c.addStorageType("replicate",g),c.addStorageType("indexed",h)};window.requirejs?define("JIOStorages",["LocalOrCookieStorage","Base64","JIO","jQuery"],a):a(LocalOrCookieStorage,Base64,JIO,jQuery)})();
\ No newline at end of file
(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)})();