functionparseStringToObject(a){varb=function(){vara,b,c=[],d=arguments;for(a=0;a<d.length;a+=1)for(b=0;b<d[a].length;b+=1)c.push(d[a][b]);returnc},c=function(a,b,c){vard={type:"simple",key:a,value:b};returnvoid0!==c&&(d.operator=c),d},d=function(a){return"NOT"===a.operator?a.query_list[0]:{type:"complex",operator:"NOT",query_list:[a]}},e=function(a,c){vard,e=[];for(d=0;d<c.length;d+=1)c[d].operator===a?e=b(e,c[d].query_list):e.push(c[d]);return{type:"complex",operator:a,query_list:e}},f=function(a,b){varc;if("complex"===a.type){for(c=0;c<a.query_list.length;++c)f(a.query_list[c],b);return!0}return"simple"!==a.type||a.key?!1:(a.key=b,!0)},g=function(){functiona(){this.yy={}}varb=function(a,b,c,d){for(c=c||{},d=a.length;d--;c[a[d]]=b);returnc},g=[1,5],h=[1,7],i=[1,8],j=[1,10],k=[1,12],l=[1,6,7,15],m=[1,6,7,9,12,14,15,16,19,21],n=[1,6,7,9,11,12,14,15,16,19,21],o=[2,17],p={trace:function(){},yy:{},symbols_:{error:2,begin:3,search_text:4,end:5,EOF:6,NEWLINE:7,and_expression:8,OR:9,boolean_expression:10,AND:11,NOT:12,expression:13,LEFT_PARENTHESE:14,RIGHT_PARENTHESE:15,WORD:16,DEFINITION:17,value:18,OPERATOR:19,string:20,QUOTE:21,QUOTED_STRING:22,$accept:0,$end:1},terminals_:{2:"error",6:"EOF",7:"NEWLINE",9:"OR",11:"AND",12:"NOT",14:"LEFT_PARENTHESE",15:"RIGHT_PARENTHESE",16:"WORD",17:"DEFINITION",19:"OPERATOR",21:"QUOTE",22:"QUOTED_STRING"},productions_:[0,[3,2],[5,0],[5,1],[5,1],[4,1],[4,2],[4,3],[8,1],[8,3],[10,2],[10,1],[13,3],[13,3],[13,1],[18,2],[18,1],[20,1],[20,3]],performAction:function(a,b,g,h,i,j,k){varl=j.length-1;switch(i){case1:returnj[l-1];case5:case8:case11:case14:case16:this.$=j[l];break;case6:this.$=e("OR",[j[l-1],j[l]]);break;case7:this.$=e("OR",[j[l-2],j[l]]);break;case9:this.$=e("AND",[j[l-2],j[l]]);break;case10:this.$=d(j[l]);break;case12:this.$=j[l-1];break;case13:f(j[l],j[l-2]),this.$=j[l];break;case15:j[l].operator=j[l-1],this.$=j[l];break;case17:this.$=c("",j[l]);break;case18:this.$=c("",j[l-1])}},table:[{3:1,4:2,8:3,10:4,12:g,13:6,14:h,16:i,18:9,19:j,20:11,21:k},{1:[3]},{1:[2,2],5:13,6:[1,14],7:[1,15]},b(l,[2,5],{8:3,10:4,13:6,18:9,20:11,4:16,9:[1,17],12:g,14:h,16:i,19:j,21:k}),b(m,[2,8],{11:[1,18]}),{13:19,14:h,16:i,18:9,19:j,20:11,21:k},b(n,[2,11]),{4:20,8:3,10:4,12:g,13:6,14:h,16:i,18:9,19:j,20:11,21:k},b(n,o,{17:[1,21]}),b(n,[2,14]),{16:[1,23],20:22,21:k},b(n,[2,16]),{22:[1,24]},{1:[2,1]},{1:[2,3]},{1:[2,4]},b(l,[2,6]),{4:25,8:3,10:4,12:g,13:6,14:h,16:i,18:9,19:j,20:11,21:k},{8:26,10:4,12:g,13:6,14:h,16:i,18:9,19:j,20:11,21:k},b(n,[2,10]),{15:[1,27]},{13:28,14:h,16:i,18:9,19:j,20:11,21:k},b(n,[2,15]),b(n,o),{21:[1,29]},b(l,[2,7]),b(m,[2,9]),b(n,[2,12]),b(n,[2,13]),b(n,[2,18])],defaultActions:{13:[2,1],14:[2,3],15:[2,4]},parseError:function(a,b){functionc(a,b){this.message=a,this.hash=b}if(!b.recoverable)throwc.prototype=newError,newc(a,b);this.trace(a)},parse:function(a){varb=this,c=[0],d=[null],e=[],f=this.table,g="",h=0,i=0,j=0,k=2,l=1,m=e.slice.call(arguments,1),n=Object.create(this.lexer),o={yy:{}};for(varpinthis.yy)Object.prototype.hasOwnProperty.call(this.yy,p)&&(o.yy[p]=this.yy[p]);n.setInput(a,o.yy),o.yy.lexer=n,o.yy.parser=this,"undefined"==typeofn.yylloc&&(n.yylloc={});varq=n.yylloc;e.push(q);varr=n.options&&n.options.ranges;"function"==typeofo.yy.parseError?this.parseError=o.yy.parseError:this.parseError=Object.getPrototypeOf(this).parseError;for(vars,t,u,v,w,x,y,z,A,B=function(){vara;returna=n.lex()||l,"number"!=typeofa&&(a=b.symbols_[a]||a),a},C={};;){if(u=c[c.length-1],this.defaultActions[u]?v=this.defaultActions[u]:((null===s||"undefined"==typeofs)&&(s=B()),v=f[u]&&f[u][s]),"undefined"==typeofv||!v.length||!v[0]){varD="";A=[];for(xinf[u])this.terminals_[x]&&x>k&&A.push("'"+this.terminals_[x]+"'");D=n.showPosition?"Parse error on line "+(h+1)+":\n"+n.showPosition()+"\nExpecting "+A.join(", ")+", got '"+(this.terminals_[s]||s)+"'":"Parse error on line "+(h+1)+": Unexpected "+(s==l?"end of input":"'"+(this.terminals_[s]||s)+"'"),this.parseError(D,{text:n.match,token:this.terminals_[s]||s,line:n.yylineno,loc:q,expected:A})}if(v[0]instanceofArray&&v.length>1)thrownewError("Parse Error: multiple actions possible at state: "+u+", token: "+s);switch(v[0]){case1:c.push(s),d.push(n.yytext),e.push(n.yylloc),c.push(v[1]),s=null,t?(s=t,t=null):(i=n.yyleng,g=n.yytext,h=n.yylineno,q=n.yylloc,j>0&&j--);break;case2:if(y=this.productions_[v[1]][1],C.$=d[d.length-y],C._$={first_line:e[e.length-(y||1)].first_line,last_line:e[e.length-1].last_line,first_column:e[e.length-(y||1)].first_column,last_column:e[e.length-1].last_column},r&&(C._$.range=[e[e.length-(y||1)].range[0],e[e.length-1].range[1]]),w=this.performAction.apply(C,[g,i,h,o.yy,v[1],d,e].concat(m)),"undefined"!=typeofw)returnw;y&&(c=c.slice(0,-1*y*2),d=d.slice(0,-1*y),e=e.slice(0,-1*y)),c.push(this.productions_[v[1]][0]),d.push(C.$),e.push(C._$),z=f[c[c.length-2]][c[c.length-1]],c.push(z);break;case3:return!0}}return!0}},q=function(){vara={EOF:1,parseError:function(a,b){if(!this.yy.parser)thrownewError(a);this.yy.parser.parseError(a,b)},setInput:function(a,b){returnthis.yy=b||this.yy||{},this._input=a,this._more=this._backtrack=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},input:function(){vara=this._input[0];this.yytext+=a,this.yyleng++,this.offset++,this.match+=a,this.matched+=a;varb=a.match(/(?:\r\n?|\n).*/g);returnb?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),a},unput:function(a){varb=a.length,c=a.split(/(?:\r\n?|\n)/g);this._input=a+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-b),this.offset-=b;vard=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),c.length-1&&(this.yylineno-=c.length-1);vare=this.yylloc.range;returnthis.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:c?(c.length===d.length?this.yylloc.first_column:0)+d[d.length-c.length].length-c[0].length:this.yylloc.first_column-b},this.options.ranges&&(this.yylloc.range=[e[0],e[0]+this.yyleng-b]),this.yyleng=this.yytext.length,this},more:function(){returnthis._more=!0,this},reject:function(){returnthis.options.backtrack_lexer?(this._backtrack=!0,this):this.parseError("Lexical error on line "+(this.yylineno+1)+". You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},less:function(a){this.unput(this.match.slice(a))},pastInput:function(){vara=this.matched.substr(0,this.matched.length-this.match.length);return(a.length>20?"...":"")+a.substr(-20).replace(/\n/g,"")},upcomingInput:function(){vara=this.match;returna.length<20&&(a+=this._input.substr(0,20-a.length)),(a.substr(0,20)+(a.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){vara=this.pastInput(),b=newArray(a.length+1).join("-");returna+this.upcomingInput()+"\n"+b+"^"},test_match:function(a,b){varc,d,e;if(this.options.backtrack_lexer&&(e={yylineno:this.yylineno,yylloc:{first_line:this.yylloc.first_line,last_line:this.last_line,first_column:this.yylloc.first_column,last_column:this.yylloc.last_column},yytext:this.yytext,match:this.match,matches:this.matches,matched:this.matched,yyleng:this.yyleng,offset:this.offset,_more:this._more,_input:this._input,yy:this.yy,conditionStack:this.conditionStack.slice(0),done:this.done},this.options.ranges&&(e.yylloc.range=this.yylloc.range.slice(0))),d=a[0].match(/(?:\r\n?|\n).*/g),d&&(this.yylineno+=d.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:d?d[d.length-1].length-d[d.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+a[0].length},this.yytext+=a[0],this.match+=a[0],this.matches=a,this.yyleng=this.yytext.length,this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]),this._more=!1,this._backtrack=!1,this._input=this._input.slice(a[0].length),this.matched+=a[0],c=this.performAction.call(this,this.yy,this,b,this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),c)returnc;if(this._backtrack){for(varfine)this[f]=e[f];return!1}return!1},next:function(){if(this.done)returnthis.EOF;this._input||(this.done=!0);vara,b,c,d;this._more||(this.yytext="",this.match="");for(vare=this._currentRules(),f=0;f<e.length;f++)if(c=this._input.match(this.rules[e[f]]),c&&(!b||c[0].length>b[0].length)){if(b=c,d=f,this.options.backtrack_lexer){if(a=this.test_match(c,e[f]),a!==!1)returna;if(this._backtrack){b=!1;continue}return!1}if(!this.options.flex)break}returnb?(a=this.test_match(b,e[d]),a!==!1?a:!1):""===this._input?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+". Unrecognized text.\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){vara=this.next();returna?a:this.lex()},begin:function(a){this.conditionStack.push(a)},popState:function(){vara=this.conditionStack.length-1;returna>0?this.conditionStack.pop():this.conditionStack[0]},_currentRules:function(){returnthis.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]?this.conditions[this.conditionStack[this.conditionStack.length-1]].rules:this.conditions.INITIAL.rules},topState:function(a){returna=this.conditionStack.length-1-Math.abs(a||0),a>=0?this.conditionStack[a]:"INITIAL"},pushState:function(a){this.begin(a)},stateStackSize:function(){returnthis.conditionStack.length},options:{},performAction:function(a,b,c,d){switch(c){case0:returnthis.begin("letsquote"),"QUOTE";case1:returnthis.popState(),this.begin("endquote"),"QUOTED_STRING";case2:returnthis.popState(),"QUOTE";case3:break;case4:return"LEFT_PARENTHESE";case5:return"RIGHT_PARENTHESE";case6:return"AND";case7:return"OR";case8:return"NOT";case9:return"DEFINITION";case10:return19;case11:return16;case12:return6}},rules:[/^(?:")/,/^(?:(\\"|[^"])*)/,/^(?:")/,/^(?:[^\S]+)/,/^(?:\()/,/^(?:\))/,/^(?:AND\b)/,/^(?:OR\b)/,/^(?:NOT\b)/,/^(?::)/,/^(?:(!?=|<=?|>=?))/,/^(?:[^\s\n"():><!=]+)/,/^(?:$)/],conditions:{endquote:{rules:[2],inclusive:!1},letsquote:{rules:[1],inclusive:!1},INITIAL:{rules:[0,3,4,5,6,7,8,9,10,11,12],inclusive:!0}}};returna}();returnp.lexer=q,a.prototype=p,p.Parser=a,newa}();returng.parse(a)}!function(a,b,c){"use strict";functiond(a){varb,c=[];if(void0===a)returnvoid0;for(Array.isArray(a)||(a=[a]),b=0;b<a.length;b+=1)"object"==typeofa[b]?c[b]=a[b].content:c[b]=a[b];returnc}functione(a,b){varc;if("descending"===b)c=1;else{if("ascending"!==b)thrownewTypeError("Query.sortFunction(): Argument 2 must be 'ascending' or 'descending'");c=-1}returnfunction(b,e){varf,g;for(b=d(b[a])||[],e=d(e[a])||[],g=b.length>e.length?b.length:e.length,f=0;g>f;f+=1){if(void0===b[f])returnc;if(void0===e[f])return-c;if(b[f]>e[f])return-c;if(b[f]<e[f])returnc}return0}}functionf(a,b){varc;if(!Array.isArray(a))thrownewTypeError("jioquery.sortOn(): Argument 1 is not of type 'array'");for(c=a.length-1;c>=0;c-=1)b.sort(e(a[c][0],a[c][1]));returnb}functiong(a,b){if(!Array.isArray(a))thrownewTypeError("jioquery.limit(): Argument 1 is not of type 'array'");if(!Array.isArray(b))thrownewTypeError("jioquery.limit(): Argument 2 is not of type 'array'");returnb.splice(0,a[0]),a[1]&&b.splice(a[1]),b}functionh(a,b){varc,d,e;if(!Array.isArray(a))thrownewTypeError("jioquery.select(): Argument 1 is not of type Array");if(!Array.isArray(b))thrownewTypeError("jioquery.select(): Argument 2 is not of type Array");for(c=0;c<b.length;c+=1){for(e={},d=0;d<a.length;d+=1)b[c].hasOwnProperty([a[d]])&&(e[a[d]]=b[c][a[d]]);for(dine)if(e.hasOwnProperty(d)){b[c]=e;break}}returnb}functioni(){}functionj(){}functionk(a){returna.replace(t,"\\$&")}functionl(a,b){a.super_=b,a.prototype=Object.create(b.prototype,{constructor:{configurable:!0,enumerable:!1,writable:!0,value:a}})}functionm(a,b){if("string"!=typeofa)thrownewTypeError("jioquery.searchTextToRegExp(): Argument 1 is not of type 'string'");returnb===!1?newRegExp("^"+k(a)+"$"):newRegExp("^"+k(a).replace(u,".*").replace(v,".")+"$")}functionn(a,b){i.call(this),this.operator=a.operator,this.query_list=a.query_list||[],this.query_list=this.query_list.map(function(a){returnj.create(a,b)})}functiono(a){varb=[];if("complex"===a.type)returnb.push("("),(a.query_list||[]).forEach(function(c){b.push(o(c)),b.push(a.operator)}),b.length-=1,b.push(")"),b.join("");if("simple"===a.type)return(a.key?a.key+": ":"")+(a.operator||"")+' "'+a.value+'"';thrownewTypeError("This object is not a query")}functionp(a){varb;if(void0!==a){if("object"!=typeofa)thrownewTypeError("SimpleQuery().create(): key_schema is not of type 'object'");if(void0===a.key_set)thrownewTypeError("SimpleQuery().create(): key_schema has no 'key_set' property");for(bina)if(a.hasOwnProperty(b))switch(b){case"key_set":case"cast_lookup":case"match_lookup":break;default:thrownewTypeError("SimpleQuery().create(): key_schema has unknown property '"+b+"'")}}}functionq(a,b){i.call(this),p(b),this._key_schema=b||{},this.operator=a.operator,this.key=a.key,this.value=a.value}functionr(a){varb;if(void0===a.read_from)thrownewTypeError("Custom key is missing the read_from property");for(bina)if(a.hasOwnProperty(b))switch(b){case"read_from":case"cast_to":case"equal_match":break;default:thrownewTypeError("Custom key has unknown property '"+b+"'")}}vars={},t=/[\-\[\]{}()*+?.,\\\^$|#\s]/g,u=/%/g,v=/_/g,w=/^(?:AND|OR|NOT)$/i,x=/^(?:!?=|<=?|>=?)$/i;i.prototype.exec=function(b,c){if(!Array.isArray(b))thrownewTypeError("Query().exec(): Argument 1 is not of type 'array'");if(void0===c&&(c={}),"object"!=typeofc)thrownewTypeError("Query().exec(): Optional argument 2 is not of type 'object'");vard,e=this;for(d=b.length-1;d>=0;d-=1)e.match(b[d])||b.splice(d,1);returnc.sort_on&&f(c.sort_on,b),c.limit&&g(c.limit,b),h(c.select_list||[],b),(newa.Queue).push(function(){returnb})},i.prototype.match=function(){return!0},i.prototype.parse=function(b){functionc(b,d){functionf(a){i.push(function(){returnb.parsed=h.query_list[a],c(b,d)}).push(function(){h.query_list[a]=b.parsed})}varg,h=b.parsed,i=newa.Queue;if("complex"===h.type){for(g=0;g<h.query_list.length;g+=1)f(g);returni.push(function(){returnb.parsed=h,e.onParseComplexQuery(b,d)})}return"simple"===h.type?e.onParseSimpleQuery(b,d):void0}vard,e=this;returnd={parsed:JSON.parse(JSON.stringify(e.serialized()))},(newa.Queue).push(function(){returne.onParseStart(d,b)}).push(function(){returnc(d,b)}).push(function(){returne.onParseEnd(d,b)}).push(function(){returnd.parsed})},i.prototype.toString=function(){return""},i.prototype.serialized=function(){returnvoid0},l(n,i),n.prototype.operator="AND",n.prototype.type="complex",n.prototype.match=function(a){varb=this.operator;returnw.test(b)||(b="AND"),this[b.toUpperCase()](a)},n.prototype.toString=function(){vara=[],b=this.operator;return"NOT"===this.operator?(a.push("NOT ("),a.push(this.query_list[0].toString()),a.push(")"),a.join("")):(this.query_list.forEach(function(c){a.push("("),a.push(c.toString()),a.push(")"),a.push(b)}),a.length-=1,a.join(""))},n.prototype.serialized=function(){vara={type:"complex",operator:this.operator,query_list:[]};returnthis.query_list.forEach(function(b){a.query_list.push("function"==typeofb.toJSON?b.toJSON():b)}),a},n.prototype.toJSON=n.prototype.serialized,n.prototype.AND=function(a){for(varb=!0,c=0;b&&c!==this.query_list.length;)b=this.query_list[c].match(a),c+=1;returnb},n.prototype.OR=function(a){for(varb=!1,c=0;!b&&c!==this.query_list.length;)b=this.query_list[c].match(a),c+=1;returnb},n.prototype.NOT=function(a){return!this.query_list[0].match(a)},j.create=function(a,b){if(""===a)returnnewi;if("string"==typeofa&&(a=c(a)),"string"==typeof(a||{}).type&&s[a.type])returnnews[a.type](a,b);thrownewTypeError("QueryFactory.create(): Argument 1 is not a search text or a parsable object")},l(q,i),q.prototype.type="simple",q.prototype.match=function(a){varb=null,c=null,d=null,e=null,f=this.operator,g=null,h=this.key;if(x.test(f)||(f=u.test(this.value)?"like":"="),e=this[f],this._key_schema.key_set&&void0!==this._key_schema.key_set[h]&&(h=this._key_schema.key_set[h]),"object"==typeofh){if(r(h),b=a[h.read_from],c=h.equal_match,"string"==typeofc&&(c=this._key_schema.match_lookup[c]),void0!==c&&(e="="===f||"like"===f?c:e),g=this.value,d=h.cast_to){"string"==typeofd&&(d=this._key_schema.cast_lookup[d]);try{g=d(g)}catch(i){g=void0}try{b=d(b)}catch(i){b=void0}}}elseb=a[h],g=this.value;returnvoid0===b||void0===g?!1:e(b,g)},q.prototype.toString=function(){return(this.key?this.key+":":"")+(this.operator?""+this.operator:"")+' "'+this.value+'"'},q.prototype.serialized=function(){vara={type:"simple",key:this.key,value:this.value};returnvoid0!==this.operator&&(a.operator=this.operator),a},q.prototype.toJSON=q.prototype.serialized,q.prototype["="]=function(a,b){varc,d;for(Array.isArray(a)||(a=[a]),d=0;d<a.length;d+=1){if(c=a[d],"object"==typeofc&&c.hasOwnProperty("content")&&(c=c.content),"function"==typeofc.cmp)return0===c.cmp(b);if(b.toString()===c.toString())return!0}return!1},q.prototype.like=function(a,b){varc,d;for(Array.isArray(a)||(a=[a]),d=0;d<a.length;d+=1){if(c=a[d],"object"==typeofc&&c.hasOwnProperty("content")&&(c=c.content),"function"==typeofc.cmp)return0===c.cmp(b);if(m(b.toString()).test(c.toString()))return!0}return!1},q.prototype["!="]=function(a,b){varc,d;for(Array.isArray(a)||(a=[a]),d=0;d<a.length;d+=1){if(c=a[d],"object"==typeofc&&c.hasOwnProperty("content")&&(c=c.content),"function"==typeofc.cmp)return0!==c.cmp(b);if(b.toString()===c.toString())return!1}return!0},q.prototype["<"]=function(a,b){varc;returnArray.isArray(a)||(a=[a]),c=a[0],"object"==typeofc&&c.hasOwnProperty("content")&&(c=c.content),"function"==typeofc.cmp?c.cmp(b)<0:b>c},q.prototype["<="]=function(a,b){varc;returnArray.isArray(a)||(a=[a]),c=a[0],"object"==typeofc&&c.hasOwnProperty("content")&&(c=c.content),"function"==typeofc.cmp?c.cmp(b)<=0:b>=c},q.prototype[">"]=function(a,b){varc;returnArray.isArray(a)||(a=[a]),c=a[0],"object"==typeofc&&c.hasOwnProperty("content")&&(c=c.content),"function"==typeofc.cmp?c.cmp(b)>0:c>b},q.prototype[">="]=function(a,b){varc;returnArray.isArray(a)||(a=[a]),c=a[0],"object"==typeofc&&c.hasOwnProperty("content")&&(c=c.content),"function"==typeofc.cmp?c.cmp(b)>=0:c>=b},s.simple=q,s.complex=n,i.parseStringToObject=c,i.objectToSearchText=o,b.Query=i,b.SimpleQuery=q,b.ComplexQuery=n,b.QueryFactory=j}(RSVP,window,parseStringToObject),function(a,b){"use strict";varc,d="year",e="month",f="day",g="hour",h="minute",i="second",j="millisecond",k={year:0,month:1,day:2,hour:3,minute:4,second:5,millisecond:6},l=function(a,b){returnk[a]<k[b]?a:b};c=function(a){if(!(thisinstanceofc))returnnewc(a);if(ainstanceofc)returnthis.mom=a.mom.clone(),void(this._precision=a._precision);if(void0===a)returnthis.mom=b(),voidthis.setPrecision(j);if(this.mom=null,this._str=a,a.match(/\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+\-][0-2]\d:[0-5]\d|Z)/)||a.match(/\d\d\d\d-\d\d-\d\d\d\d:\d\d:\d\d\.\d\d\d/)?(this.mom=b(a),this.setPrecision(j)):a.match(/\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+\-][0-2]\d:[0-5]\d|Z)/)||a.match(/\d\d\d\d-\d\d-\d\d\d\d:\d\d:\d\d/)?(this.mom=b(a),this.setPrecision(i)):a.match(/\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+\-][0-2]\d:[0-5]\d|Z)/)||a.match(/\d\d\d\d-\d\d-\d\d\d\d:\d\d/)?(this.mom=b(a),this.setPrecision(h)):a.match(/\d\d\d\d-\d\d-\d\d\d\d/)?(this.mom=b(a),this.setPrecision(g)):a.match(/\d\d\d\d-\d\d-\d\d/)?(this.mom=b(a),this.setPrecision(f)):a.match(/\d\d\d\d-\d\d/)?(this.mom=b(a),this.setPrecision(e)):a.match(/\d\d\d\d/)&&(this.mom=b(a,"YYYY"),this.setPrecision(d)),!this.mom)thrownewError("Cannot parse: "+a)},c.prototype.setPrecision=function(a){this._precision=a},c.prototype.getPrecision=function(){returnthis._precision},c.prototype.cmp=function(a){varb=this.mom,c=a.mom,d=l(this._precision,a._precision);returnb.isBefore(c,d)?-1:b.isSame(c,d)?0:1},c.prototype.toPrecisionString=function(a){varb;if(a=a||this._precision,b={millisecond:"YYYY-MM-DD HH:mm:ss.SSS",second:"YYYY-MM-DD HH:mm:ss",minute:"YYYY-MM-DD HH:mm",hour:"YYYY-MM-DD HH",day:"YYYY-MM-DD",month:"YYYY-MM",year:"YYYY"}[a],!b)thrownewTypeError("Unsupported precision value '"+a+"'");returnthis.mom.format(b)},c.prototype.toString=function(){returnthis._str},a.jiodate={JIODate:c,YEAR:d,MONTH:e,DAY:f,HOUR:g,MIN:h,SEC:i,MSEC:j}}(window,moment),function(a,b,c,d,e,f,g,h,i,j){"use strict";functionk(a,b){if(void0!==a&&"string"!=typeofa)thrownewTypeError("You must pass a string.");this.message=a||"Default Message",this.status_code=b||500}functionl(a){varc=newXMLHttpRequest;returnnewb.Promise(function(b,d,e){varf,g=newStreamBuffers.WritableStreamBuffer;if(c.open(a.type||"GET",a.url,!0),c.responseType=a.dataType||"","object"==typeofa.headers&&null!==a.headers)for(fina.headers)a.headers.hasOwnProperty(f)&&c.setRequestHeader(f,a.headers[f]);if(c.setRequestHeader("Accept","*/*"),c.addEventListener("load",function(a){returna.target.status>=400?d(a):voidb(a)}),c.addEventListener("error",d),c.addEventListener("progress",e),"object"==typeofa.xhrFields&&null!==a.xhrFields)for(fina.xhrFields)a.xhrFields.hasOwnProperty(f)&&(c[f]=a.xhrFields[f]);"function"==typeofa.beforeSend&&a.beforeSend(c),a.datainstanceofFormData?(c.setRequestHeader("Content-Type","multipart/form-data; boundary="+a.data.getBoundary()),a.data.pipe(g),c.send(g.getContents())):c.send(a.data)},function(){c.abort()})}functionm(a,c){vard=newg;returnnewb.Promise(function(b,e,f){d.addEventListener("load",b),d.addEventListener("error",e),d.addEventListener("progress",f),d.readAsText(a,c)},function(){d.abort()})}functionn(a){varc=newg;returnnewb.Promise(function(b,d,e){c.addEventListener("load",b),c.addEventListener("error",d),c.addEventListener("progress",e),c.readAsArrayBuffer(a)},function(){c.abort()})}functiono(a){varc=newg;returnnewb.Promise(function(b,d,e){c.addEventListener("load",b),c.addEventListener("error",d),c.addEventListener("progress",e),c.readAsDataURL(a)},function(){c.abort()})}functionp(a){varb,c,d,e,f;if(void0===a)returnvoid0;if(a.constructor===Object){for(c=Object.keys(a).sort(),f=[],d=0;d<c.length;d+=1)b=c[d],e=p(a[b]),void0!==e&&f.push(p(b)+":"+e);return"{"+f.join(",")+"}"}if(a.constructor===Array){for(f=[],d=0;d<a.length;d+=1)f.push(p(a[d]));return"["+f.join(",")+"]"}returnJSON.stringify(a)}functionq(a){if("data:"===a)returnnewc;varb,d=f(a.split(",")[1]),e=a.split(",")[0].split(":")[1],g=newh(d.length),j=newi(g);for(e=e.slice(0,e.length-";base64".length),b=0;b<d.length;b+=1)j[b]=d.charCodeAt(b);returnnewc([g],{type:e})}functionr(a,b,c){if("string"!=typeofa[0]||""===a[0])throwneww.util.jIOError("Document id must be a non empty string on '"+b.__type+"."+c+"'.",400)}functions(a,b,c){if("string"!=typeofa[1]||""===a[1])throwneww.util.jIOError("Attachment id must be a non empty string on '"+b.__type+"."+c+"'.",400)}functiont(a,c,d,e){returna.prototype[c]=function(){vara,f=arguments,g=this;return(newb.Queue).push(function(){returnvoid0!==d?d.apply(g.__storage,[f,g,c]):void0}).push(function(b){vard=g.__storage[c];if(a=b,void0===d)throwneww.util.jIOError("Capacity '"+c+"' is not implemented on '"+g.__type+"'",501);returnd.apply(g.__storage,f)}).push(function(b){returnvoid0!==e?e.call(g,f,b,a):b})},this}functionu(a,b){returnthisinstanceofu?(this.__type=a,void(this.__storage=b)):newu}functionv(){returnthisinstanceofv?void(this.__storage_types={}):newv}void0===a.openDatabase&&(a.openDatabase=function(){thrownewError("WebSQL is not supported by "+j.userAgent)});varw,x={};k.prototype=newError,k.prototype.constructor=k,x.jIOError=k,x.ajax=l,x.readBlobAsText=m,x.readBlobAsArrayBuffer=n,x.readBlobAsDataURL=o,x.stringify=p,x.dataURItoBlob=q,t(u,"put",r,function(a){returna[0]}),t(u,"get",r),t(u,"bulk"),t(u,"remove",r,function(a){returna[0]}),u.prototype.post=function(){vara=this,c=arguments;return(newb.Queue).push(function(){varb=a.__storage.post;if(void0===b)throwneww.util.jIOError("Capacity 'post' is not implemented on '"+a.__type+"'",501);returna.__storage.post.apply(a.__storage,c)})},t(u,"putAttachment",function(a,b,d){r(a,b,d),s(a,b,d);vare=a[3]||{};if("string"==typeofa[2])a[2]=newc([a[2]],{type:e._content_type||e._mimetype||"text/plain;charset=utf-8"});elseif(!(a[2]instanceofc))throwneww.util.jIOError("Attachment content is not a blob",400)}),t(u,"removeAttachment",function(a,b,c){r(a,b,c),s(a,b,c)}),t(u,"getAttachment",function(a,b,c){vard="blob";returnr(a,b,c),s(a,b,c),void0!==a[2]&&(d=a[2].format||d,deletea[2].format),d},function(a,d,e){varf;if(!(dinstanceofc))throwneww.util.jIOError("'getAttachment' ("+a[0]+" , "+a[1]+") on '"+this.__type+"' does not return a Blob.",501);if("blob"===e)f=d;elseif("data_url"===e)f=(newb.Queue).push(function(){returnw.util.readBlobAsDataURL(d)}).push(function(a){returna.target.result});elseif("array_buffer"===e)f=(newb.Queue).push(function(){returnw.util.readBlobAsArrayBuffer(d)}).push(function(a){returna.target.result});elseif("text"===e)f=(newb.Queue).push(function(){returnw.util.readBlobAsText(d)}).push(function(a){returna.target.result});else{if("json"!==e)throwneww.util.jIOError(this.__type+".getAttachment format: '"+e+"' is not supported",400);f=(newb.Queue).push(function(){returnw.util.readBlobAsText(d)}).push(function(a){returnJSON.parse(a.target.result)})}returnf}),u.prototype.buildQuery=function(){vara=this.__storage.buildQuery,c=this,d=arguments;if(void0===a)throwneww.util.jIOError("Capacity 'buildQuery' is not implemented on '"+this.__type+"'",501);return(newb.Queue).push(function(){returna.apply(c.__storage,d)})},u.prototype.hasCapacity=function(a){varb=this.__storage.hasCapacity,c=this.__storage[a];if(void0!==c)return!0;if(void0===b||!b.apply(this.__storage,arguments))throwneww.util.jIOError("Capacity '"+a+"' is not implemented on '"+this.__type+"'",501);return!0},u.prototype.allDocs=function(a){varc=this;returnvoid0===a&&(a={}),(newb.Queue).push(function(){return!c.hasCapacity("list")||void0!==a.query&&!c.hasCapacity("query")||void0!==a.sort_on&&!c.hasCapacity("sort")||void0!==a.select_list&&!c.hasCapacity("select")||void0!==a.include_docs&&!c.hasCapacity("include")||void0!==a.limit&&!c.hasCapacity("limit")?void0:c.buildQuery(a)}).push(function(a){return{data:{rows:a,total_rows:a.length}}})},t(u,"allAttachments",r),t(u,"repair"),u.prototype.repair=function(){vara=this,c=arguments;return(newb.Queue).push(function(){varb=a.__storage.repair;returnvoid0!==b?a.__storage.repair.apply(a.__storage,c):void0})},v.prototype.createJIO=function(a,b){if("string"!=typeofa.type)thrownewTypeError("Invalid storage description");if(!this.__storage_types[a.type])thrownewTypeError("Unknown storage '"+a.type+"'");returnnewu(a.type,newthis.__storage_types[a.type](a,b))},v.prototype.addStorage=function(a,b){if("string"!=typeofa)thrownewTypeError("jIO.addStorage(): Argument 1 is not of type 'string'");if("function"!=typeofb)thrownewTypeError("jIO.addStorage(): Argument 2 is not of type 'function'");if(void0!==this.__storage_types[a])thrownewTypeError("jIO.addStorage(): Storage type already exists");this.__storage_types[a]=b},v.prototype.util=x,v.prototype.QueryFactory=d,v.prototype.Query=e,w=newv,a.jIO=w}(window,RSVP,Blob,QueryFactory,Query,atob,FileReader,ArrayBuffer,Uint8Array,navigator),function(a,b,c,d){"use strict";functione(a){returnh.digestFromString(a)}functionf(a){returnh.digestFromArrayBuffer(a)}functiong(b){if(this._query_options=b.query||{},this._local_sub_storage=a.createJIO(b.local_sub_storage),this._remote_sub_storage=a.createJIO(b.remote_sub_storage),this._signature_hash="_replicate_"+e(d(b.local_sub_storage)+d(b.remote_sub_storage)+d(this._query_options)),this._signature_sub_storage=a.createJIO({type:"document",document_id:this._signature_hash,sub_storage:b.signature_storage||b.local_sub_storage}),this._use_remote_post=b.use_remote_post||!1,this._conflict_handling=b.conflict_handling||0,this._conflict_handling!==i&&this._conflict_handling!==j&&this._conflict_handling!==k&&this._conflict_handling!==l)thrownewa.util.jIOError("Unsupported conflict handling: "+this._conflict_handling,400);this._check_local_modification=b.check_local_modification,void0===this._check_local_modification&&(this._check_local_modification=!0),this._check_local_creation=b.check_local_creation,void0===this._check_local_creation&&(this._check_local_creation=!0),this._check_local_deletion=b.check_local_deletion,void0===this._check_local_deletion&&(this._check_local_deletion=!0),this._check_remote_modification=b.check_remote_modification,void0===this._check_remote_modification&&(this._check_remote_modification=!0),this._check_remote_creation=b.check_remote_creation,void0===this._check_remote_creation&&(this._check_remote_creation=!0),this._check_remote_deletion=b.check_remote_deletion,void0===this._check_remote_deletion&&(this._check_remote_deletion=!0),this._check_local_attachment_modification=b.check_local_attachment_modification,void0===this._check_local_attachment_modification&&(this._check_local_attachment_modification=!1),this._check_local_attachment_creation=b.check_local_attachment_creation,void0===this._check_local_attachment_creation&&(this._check_local_attachment_creation=!1),this._check_local_attachment_deletion=b.check_local_attachment_deletion,void0===this._check_local_attachment_deletion&&(this._check_local_attachment_deletion=!1),this._check_remote_attachment_modification=b.check_remote_attachment_modification,void0===this._check_remote_attachment_modification&&(this._check_remote_attachment_modification=!1),this._check_remote_attachment_creation=b.check_remote_attachment_creation,void0===this._check_remote_attachment_creation&&(this._check_remote_attachment_creation=!1),this._check_remote_attachment_deletion=b.check_remote_attachment_deletion,void0===this._check_remote_attachment_deletion&&(this._check_remote_attachment_deletion=!1)}varh=newc,i=0,j=1,k=2,l=3;g.prototype.remove=function(b){if(b===this._signature_hash)thrownewa.util.jIOError(this._signature_hash+" is frozen",403);returnthis._local_sub_storage.remove.apply(this._local_sub_storage,arguments)},g.prototype.post=function(){returnthis._local_sub_storage.post.apply(this._local_sub_storage,arguments)},g.prototype.put=function(b){if(b===this._signature_hash)thrownewa.util.jIOError(this._signature_hash+" is frozen",403);returnthis._local_sub_storage.put.apply(this._local_sub_storage,arguments)},g.prototype.get=function(){returnthis._local_sub_storage.get.apply(this._local_sub_storage,arguments)},g.prototype.getAttachment=function(){returnthis._local_sub_storage.getAttachment.apply(this._local_sub_storage,arguments)},g.prototype.allAttachments=function(){returnthis._local_sub_storage.allAttachments.apply(this._local_sub_storage,arguments)},g.prototype.putAttachment=function(b){if(b===this._signature_hash)thrownewa.util.jIOError(this._signature_hash+" is frozen",403);returnthis._local_sub_storage.putAttachment.apply(this._local_sub_storage,arguments)},g.prototype.removeAttachment=function(b){if(b===this._signature_hash)thrownewa.util.jIOError(this._signature_hash+" is frozen",403);returnthis._local_sub_storage.removeAttachment.apply(this._local_sub_storage,arguments)},g.prototype.hasCapacity=function(){returnthis._local_sub_storage.hasCapacity.apply(this._local_sub_storage,arguments);
},g.prototype.buildQuery=function(){returnthis._local_sub_storage.buildQuery.apply(this._local_sub_storage,arguments)},g.prototype.repair=function(){functionc(a,b,c,d){returnb.removeAttachment(c,d).push(function(){returnw._signature_sub_storage.removeAttachment(c,d)}).push(function(){a[d]=null})}functiong(a,b,c,d,e,f){returnb.putAttachment(e,f,c).push(function(){returnw._signature_sub_storage.putAttachment(e,f,JSON.stringify({hash:d}))}).push(function(){a[f]=null})}functionh(b,d,e,h,i,j,k,l,m,n,o){varp;returnj.getAttachment(k,l).push(function(b){returnp=b,a.util.readBlobAsArrayBuffer(p)}).push(function(a){returnf(a.target.result)},function(b){if(binstanceofa.util.jIOError&&404===b.status_code)returnp=null,null;throwb}).push(function(f){if(e===f)returnnull===e?w._signature_sub_storage.removeAttachment(k,l).push(function(){b[k]=null}):w._signature_sub_storage.putAttachment(k,l,JSON.stringify({hash:e})).push(function(){y[k]=null});if(f===d||m===!0)returnnull===e?c(b,j,k,l):g(b,j,h,e,k,l);if(o!==!0){if(n===!0||null===e)returnnull===f?c(b,i,k,l):g(b,i,p,f,k,l);if(null===f)returng(b,j,h,e,k,l);thrownewa.util.jIOError("Conflict on '"+k+"' with attachment '"+l+"'",409)}})}functioni(c,d,e,g,i,j,k,l,m,n,o){varp,q;d.push(function(){if(n===!0)returnb.all([e.getAttachment(i,j),{hash:null}]);if(o===!0)returnb.all([e.getAttachment(i,j),w._signature_sub_storage.getAttachment(i,j,{format:"json"})]);thrownewa.util.jIOError("Unexpected call of checkAttachmentSignatureDifference",409)}).push(function(b){returnp=b[0],q=b[1].hash,a.util.readBlobAsArrayBuffer(p)}).push(function(a){varb=a.target.result,d=f(b);returnd!==q?h(c,q,d,p,e,g,i,j,k,l,m):void0})}functionm(a,b,c,d,e,f,g,i,j){vark;b.push(function(){returnw._signature_sub_storage.getAttachment(d,e,{format:"json"})}).push(function(b){returnk=b.hash,h(a,k,null,null,f,c,d,e,g,i,j)})}functionn(c,d,e,f,g){varh=newb.Queue;returnh.push(function(){returnb.all([e.allAttachments(d).push(void0,function(b){if(binstanceofa.util.jIOError&&404===b.status_code)return{};throwb}),w._signature_sub_storage.allAttachments(d).push(void0,function(b){if(binstanceofa.util.jIOError&&404===b.status_code)return{};throwb})])}).push(function(a){varb,j,k,l={},n={};for(kina[0])a[0].hasOwnProperty(k)&&(c.hasOwnProperty(k)||(l[k]=null));for(kina[1])a[1].hasOwnProperty(k)&&(c.hasOwnProperty(k)||(n[k]=null));for(kinl)l.hasOwnProperty(k)&&(b=n.hasOwnProperty(k)&&g.check_modification,j=!n.hasOwnProperty(k)&&g.check_creation,(b===!0||j===!0)&&i(c,h,e,f,d,k,g.conflict_force,g.conflict_revert,g.conflict_ignore,j,b));if(g.check_deletion===!0)for(kinn)n.hasOwnProperty(k)&&(l.hasOwnProperty(k)||m(c,h,f,d,k,e,g.conflict_force,g.conflict_revert,g.conflict_ignore))})}functiono(a){varc={};return(newb.Queue).push(function(){returnw._check_local_attachment_modification||w._check_local_attachment_creation||w._check_local_attachment_deletion?n(c,a,w._local_sub_storage,w._remote_sub_storage,{conflict_force:w._conflict_handling===j,conflict_revert:w._conflict_handling===k,conflict_ignore:w._conflict_handling===l,check_modification:w._check_local_attachment_modification,check_creation:w._check_local_attachment_creation,check_deletion:w._check_local_attachment_deletion}):void0}).push(function(){returnw._check_remote_attachment_modification||w._check_remote_attachment_creation||w._check_remote_attachment_deletion?n(c,a,w._remote_sub_storage,w._local_sub_storage,{use_revert_post:w._use_remote_post,conflict_force:w._conflict_handling===k,conflict_revert:w._conflict_handling===j,conflict_ignore:w._conflict_handling===l,check_modification:w._check_remote_attachment_modification,check_creation:w._check_remote_attachment_creation,check_deletion:w._check_remote_attachment_deletion}):void0})}functionp(a,c,d,e,f,g){varh,i,j=!0;returnvoid0===g&&(g={}),h=g.use_post?c.post(d).push(function(b){returnj=!1,i=b,a.put(i,d)}).push(function(){returna.allAttachments(f)}).push(function(c){functiond(b){g.push(function(){returna.getAttachment(f,b)}).push(function(c){returna.putAttachment(i,b,c)})}vare,g=newb.Queue;for(einc)c.hasOwnProperty(e)&&d(e);returng}).push(function(){returna.remove(f)}).push(function(){returnw._signature_sub_storage.remove(f)}).push(function(){returnj=!0,w._signature_sub_storage.put(i,{hash:e})}).push(function(){y[i]=null}):c.put(f,d).push(function(){returnw._signature_sub_storage.put(f,{hash:e})}),h.push(function(){j&&(y[f]=null)})}functionq(b,c){returno(c).push(function(){returnb.allAttachments(c)}).push(function(a){return"{}"===JSON.stringify(a)?b.remove(c).push(function(){returnw._signature_sub_storage.remove(c)}):void0},function(b){if(!(binstanceofa.util.jIOError&&404===b.status_code))throwb}).push(function(){y[c]=null})}functionr(b,c,f,g,h,i,j,k,l,m){returnh.get(i).push(function(a){return[a,e(d(a))]},function(b){if(binstanceofa.util.jIOError&&404===b.status_code)return[null,null];throwb}).push(function(e){varn=e[0],o=e[1];if(c===o)returnnull===c?w._signature_sub_storage.remove(i).push(function(){y[i]=null}):w._signature_sub_storage.put(i,{hash:c}).push(function(){y[i]=null});if(o===b||j===!0)returnnull===c?q(h,i):p(g,h,f,c,i,{use_post:m.use_post&&null===o});if(l!==!0){if(k===!0||null===c)returnnull===o?q(g,i):p(h,g,n,o,i,{use_post:m.use_revert_post&&null===c});if(null===o)returnp(g,h,f,c,i,{use_post:m.use_post});thrownewa.util.jIOError("Conflict on '"+i+"': "+d(f||"")+" !== "+d(n||""),409)}})}functions(a,b,c,d,e,f,g,h){vari;a.push(function(){returnw._signature_sub_storage.get(c)}).push(function(a){returni=a.hash,r(i,null,null,d,b,c,e,f,g,h)})}functiont(c,f,g,h,i,j,k,l,m,n,o){c.push(function(){if(l===!0)returnb.all([n(h),{hash:null}]);if(m===!0)returnb.all([n(h),w._signature_sub_storage.get(h)]);thrownewa.util.jIOError("Unexpected call of checkSignatureDifference",409)}).push(function(a){varb=a[0],c=e(d(b)),l=a[1].hash;returnc!==l?r(l,c,b,f,g,h,i,j,k,o):void0})}functionu(a,c,d,e,f,g,h,i,j){a.push(function(){returnc.bulk(e)}).push(function(a){functionk(b){returnfunction(c){if(c!==e[b].parameter_list[0])thrownewError("Does not access expected ID "+c);returna[b]}}varl,m=newb.Queue;for(l=0;l<a.length;l+=1)t(m,c,d,e[l].parameter_list[0],h,i,j,f[l].is_creation,f[l].is_modification,k(l),g);returnm})}functionv(a,c,d){vare=newb.Queue;returnd.hasOwnProperty("use_post")||(d.use_post=!1),d.hasOwnProperty("use_revert_post")||(d.use_revert_post=!1),e.push(function(){returnb.all([a.allDocs(w._query_options),w._signature_sub_storage.allDocs()])}).push(function(b){varf,g,h,i,j={},k=[],l=[],m={};for(f=0;f<b[0].data.total_rows;f+=1)y.hasOwnProperty(b[0].data.rows[f].id)||(j[b[0].data.rows[f].id]=f);for(f=0;f<b[1].data.total_rows;f+=1)y.hasOwnProperty(b[1].data.rows[f].id)||(m[b[1].data.rows[f].id]=f);for(iinj)j.hasOwnProperty(i)&&(g=m.hasOwnProperty(i)&&d.check_modification,h=!m.hasOwnProperty(i)&&d.check_creation,(g===!0||h===!0)&&(d.use_bulk_get===!0?(k.push({method:"get",parameter_list:[i]}),l.push({is_creation:h,is_modification:g})):t(e,a,c,i,d.conflict_force,d.conflict_revert,d.conflict_ignore,h,g,a.get.bind(a),d)));if(d.check_deletion===!0)for(iinm)m.hasOwnProperty(i)&&(j.hasOwnProperty(i)||s(e,c,i,a,d.conflict_force,d.conflict_revert,d.conflict_ignore,d));d.use_bulk_get===!0&&0!==k.length&&u(e,a,c,k,l,d,d.conflict_force,d.conflict_revert,d.conflict_ignore)})}varw=this,x=arguments,y={};returny[w._signature_hash]=null,(newb.Queue).push(function(){returnw._signature_sub_storage.__storage._sub_storage.get(w._signature_hash)}).push(void0,function(b){if(binstanceofa.util.jIOError&&404===b.status_code)returnw._signature_sub_storage.__storage._sub_storage.put(w._signature_hash,{});throwb}).push(function(){returnb.all([w._local_sub_storage.repair.apply(w._local_sub_storage,x),w._remote_sub_storage.repair.apply(w._remote_sub_storage,x)])}).push(function(){returnw._check_local_modification||w._check_local_creation||w._check_local_deletion?v(w._local_sub_storage,w._remote_sub_storage,{use_post:w._use_remote_post,conflict_force:w._conflict_handling===j,conflict_revert:w._conflict_handling===k,conflict_ignore:w._conflict_handling===l,check_modification:w._check_local_modification,check_creation:w._check_local_creation,check_deletion:w._check_local_deletion}):void0}).push(function(){varb=!1;try{b=w._remote_sub_storage.hasCapacity("bulk_get")}catch(c){if(!(cinstanceofa.util.jIOError&&501===c.status_code))throwc}returnw._check_remote_modification||w._check_remote_creation||w._check_remote_deletion?v(w._remote_sub_storage,w._local_sub_storage,{use_bulk_get:b,use_revert_post:w._use_remote_post,conflict_force:w._conflict_handling===k,conflict_revert:w._conflict_handling===j,conflict_ignore:w._conflict_handling===l,check_modification:w._check_remote_modification,check_creation:w._check_remote_creation,check_deletion:w._check_remote_deletion}):void0}).push(function(){returnw._check_local_attachment_modification||w._check_local_attachment_creation||w._check_local_attachment_deletion||w._check_remote_attachment_modification||w._check_remote_attachment_creation||w._check_remote_attachment_deletion?w._signature_sub_storage.allDocs().push(function(a){functionc(a){e.push(function(){returno(a)})}vard,e=newb.Queue;for(d=0;d<a.data.total_rows;d+=1)c(a.data.rows[d].id);returne}):void0})},a.addStorage("replicate",g)}(jIO,RSVP,Rusha,jIO.util.stringify),function(a){"use strict";functionb(b){this._sub_storage=a.createJIO(b.sub_storage)}b.prototype.get=function(){returnthis._sub_storage.get.apply(this._sub_storage,arguments)},b.prototype.allAttachments=function(){returnthis._sub_storage.allAttachments.apply(this._sub_storage,arguments)},b.prototype.post=function(a){functionb(){return("0000"+Math.floor(65536*Math.random()).toString(16)).slice(-4)}varc=b()+b()+"-"+b()+"-"+b()+"-"+b()+"-"+b()+b()+b();returnthis.put(c,a)},b.prototype.put=function(){returnthis._sub_storage.put.apply(this._sub_storage,arguments)},b.prototype.remove=function(){returnthis._sub_storage.remove.apply(this._sub_storage,arguments)},b.prototype.getAttachment=function(){returnthis._sub_storage.getAttachment.apply(this._sub_storage,arguments)},b.prototype.putAttachment=function(){returnthis._sub_storage.putAttachment.apply(this._sub_storage,arguments)},b.prototype.removeAttachment=function(){returnthis._sub_storage.removeAttachment.apply(this._sub_storage,arguments)},b.prototype.repair=function(){returnthis._sub_storage.repair.apply(this._sub_storage,arguments)},b.prototype.hasCapacity=function(a){returnthis._sub_storage.hasCapacity(a)},b.prototype.buildQuery=function(){returnthis._sub_storage.buildQuery.apply(this._sub_storage,arguments)},a.addStorage("uuid",b)}(jIO),function(a,b,c){"use strict";functiond(){this._database={}}d.prototype.put=function(a,c){returnthis._database.hasOwnProperty(a)||(this._database[a]={attachments:{}}),this._database[a].doc=b.stringify(c),a},d.prototype.get=function(c){try{returnb.parse(this._database[c].doc)}catch(d){if(dinstanceofTypeError)thrownewa.util.jIOError("Cannot find document: "+c,404);throwd}},d.prototype.allAttachments=function(b){varc,d={};try{for(cinthis._database[b].attachments)this._database[b].attachments.hasOwnProperty(c)&&(d[c]={})}catch(e){if(einstanceofTypeError)thrownewa.util.jIOError("Cannot find document: "+b,404);throwe}returnd},d.prototype.remove=function(a){returndeletethis._database[a],a},d.prototype.getAttachment=function(b,c){try{vard=this._database[b].attachments[c];if(void0===d)thrownewa.util.jIOError("Cannot find attachment: "+b+" , "+c,404);returna.util.dataURItoBlob(d)}catch(e){if(einstanceofTypeError)thrownewa.util.jIOError("Cannot find attachment: "+b+" , "+c,404);throwe}},d.prototype.putAttachment=function(b,d,e){varf;try{f=this._database[b].attachments}catch(g){if(ginstanceofTypeError)thrownewa.util.jIOError("Cannot find document: "+b,404);throwg}return(newc.Queue).push(function(){returna.util.readBlobAsDataURL(e)}).push(function(a){f[d]=a.target.result})},d.prototype.removeAttachment=function(b,c){try{deletethis._database[b].attachments[c]}catch(d){if(dinstanceofTypeError)thrownewa.util.jIOError("Cannot find document: "+b,404);throwd}},d.prototype.hasCapacity=function(a){return"list"===a||"include"===a},d.prototype.buildQuery=function(a){varc,d=[];for(cinthis._database)this._database.hasOwnProperty(c)&&(a.include_docs===!0?d.push({id:c,value:{},doc:b.parse(this._database[c].doc)}):d.push({id:c,value:{}}));returnd},a.addStorage("memory",d)}(jIO,JSON,RSVP),function(a,b,c,d,e,f,g,h){"use strict";functioni(b){return(newd.Queue).push(function(){returna.util.ajax({type:"GET",url:b._url,xhrFields:{withCredentials:b._thisCredentials},headers:b._headers})}).push(function(a){returnJSON.parse(a.target.responseText)})}functionj(c,e,f){returnvoid0===f&&(f={}),i(c).push(function(g){return(newd.Queue).push(function(){returna.util.ajax({type:"GET",url:b.parse(g._links.traverse.href).expand({relative_url:e,view:f._view}),xhrFields:{withCredentials:c._thisCredentials},headers:c._headers})}).push(void0,function(b){if(void0!==b.target&&404===b.target.status)thrownewa.util.jIOError("Cannot find document: "+e,404);throwb})})}functionk(a){return(newd.Queue).push(function(){varb,c,d,f,g=a._embedded._view,h={portal_type:a._links.type.name},i={};a._links.hasOwnProperty("parent")&&(h.parent_relative_url=newe(a._links.parent.href).segment(2)),i.form_id={key:[g.form_id.key],"default":g.form_id["default"]};for(cing)g.hasOwnProperty(c)&&(b=g[c],d=0,0===c.indexOf("my_")&&b.editable&&(d=3),0===c.indexOf("your_")&&(d=5),0!==d&&q.hasOwnProperty(b.type)&&(i[c.substring(d)]={"default":b["default"],key:b.key},h[c.substring(d)]=b["default"]));returnf={data:h,form_data:i},g.hasOwnProperty("_actions")&&g._actions.hasOwnProperty("put")&&(f.action_href=g._actions.put.href),f})}functionl(b,c){returnb.getAttachment(c,"view").push(function(b){returna.util.readBlobAsText(b)}).push(function(a){returnJSON.parse(a.target.result)}).push(function(a){returnk(a)})}functionm(a){if("string"!=typeofa.url||!a.url)thrownewTypeError("ERP5 'url' must be a string which contains more than one character.");this._url=a.url,this._default_view_reference=a.default_view_reference,this._headers=null,this._thisCredentials=!0,void0!==a.login&&void0!==a.password&&(this._headers={Authorization:"Basic "+btoa(a.login+":"+a.password)},this._thisCredentials=!1)}functionn(a){returna.data}functiono(a){returnainstanceofg&&"local_roles"===a.key?a.value:void0}functionp(a){varb,c,d=!0,e=[];if(ainstanceofh&&"OR"===a.operator){for(b=0;b<a.query_list.length;b+=1)c=a.query_list[b],cinstanceofg&&"local_roles"===c.key?e.push(c.value):d=!1;if(d)returne}}varq={StringField:null,EmailField:null,IntegerField:null,FloatField:null,TextAreaField:null};m.prototype.get=function(a){returnl(this,a).push(function(a){returnn(a)})},m.prototype.bulk=function(b){vare,f=this,g=[];for(e=0;e<b.length;e+=1){if("get"!==b[e].method)thrownewError("ERP5Storage: not supported "+b[e].method+" in bulk");g.push({relative_url:b[e].parameter_list[0],view:f._default_view_reference})}returni(f).push(function(b){vard=newc;returnd.append("bulk_list",JSON.stringify(g)),a.util.ajax({type:"POST",url:b._actions.bulk.href,data:d,xhrFields:{withCredentials:f._thisCredentials},headers:f._headers})}).push(function(a){functionb(a){returnk(a).push(function(a){returnn(a)})}varc=[],f=JSON.parse(a.target.responseText);for(e=0;e<f.result_list.length;e+=1)c.push(b(f.result_list[e]));returnd.all(c)})},m.prototype.post=function(b){vard,f=this;returni(this).push(function(d){vare=newc;returne.append("portal_type",b.portal_type),e.append("parent_relative_url",b.parent_relative_url),a.util.ajax({type:"POST",url:d._actions.add.href,data:e,xhrFields:{withCredentials:f._thisCredentials},headers:f._headers})}).push(function(a){varc=a.target.getResponseHeader("X-Location"),g=newe(c);returnd=g.segment(2),f.put(d,b)}).push(function(){returnd})},m.prototype.put=function(b,c){vard=this;returnl(d,b).push(function(e){varg,h=e.form_data,i={};i[h.form_id.key]=h.form_id["default"];for(ginc)if(c.hasOwnProperty(g)){if("form_id"===g)thrownewa.util.jIOError("ERP5: forbidden property: "+g,400);if("portal_type"!==g&&"parent_relative_url"!==g){if(!h.hasOwnProperty(g))thrownewa.util.jIOError("ERP5: can not store property: "+g,400);i[h[g].key]=c[g]}}if(!e.hasOwnProperty("action_href"))thrownewa.util.jIOError("ERP5: can not modify document: "+b,403);returnd.putAttachment(b,e.action_href,newf([JSON.stringify(i)],{type:"application/json"}))})},m.prototype.allAttachments=function(a){varb=this;returnj(this,a).push(function(){returnvoid0===b._default_view_reference?{links:{}}:{view:{},links:{}}})},m.prototype.getAttachment=function(b,c,e){varg=this;if(void0===e&&(e={}),"view"===c){if(void0===this._default_view_reference)thrownewa.util.jIOError("Cannot find attachment view for: "+b,404);returnj(this,b,{_view:this._default_view_reference}).push(function(a){varb=JSON.parse(a.target.responseText);returnnewf([JSON.stringify(b)],{type:"application/hal+json"})})}if("links"===c)returnj(this,b).push(function(a){returnnewf([JSON.stringify(JSON.parse(a.target.responseText))],{type:"application/hal+json"})});if(0===c.indexOf(this._url))return(newd.Queue).push(function(){varb,d,f,h={type:"GET",dataType:"blob",url:c,xhrFields:{withCredentials:g._thisCredentials},headers:g._headers};if(void0!==e.start||void0!==e.end){if(b=e.start||0,d=e.end,void0!==d&&0>d)thrownewa.util.jIOError("end must be positive",400);if(0>b)f="bytes="+b;elseif(void0===d)f="bytes="+b+"-";else{if(b>d)thrownewa.util.jIOError("start is greater than end",400);f="bytes="+b+"-"+d}void0===g._headers?h.headers={Range:f}:h.headers.Range=f}returna.util.ajax(h)}).push(function(a){returnvoid0===a.target.response?newf([a.target.responseText],{type:a.target.getResponseHeader("Content-Type")}):a.target.response});thrownewa.util.jIOError("ERP5: not support get attachment: "+c,400)},m.prototype.putAttachment=function(b,e,f){varg=this;if(0!==e.indexOf(this._url))thrownewa.util.jIOError("Can not store outside ERP5: "+e,400);return(newd.Queue).push(function(){returna.util.readBlobAsText(f)}).push(function(b){vard,f,h,i,j=JSON.parse(b.target.result),k=newc;for(hinj)if(j.hasOwnProperty(h))for(d=Array.isArray(j[h])?j[h]:[j[h]],f=0;f<d.length;f+=1)i=d[f],"object"==typeofi?k.append(h,a.util.dataURItoBlob(i.url),i.file_name):k.append(h,i);returna.util.ajax({type:"POST",url:e,data:k,xhrFields:{withCredentials:g._thisCredentials},headers:g._headers})})},m.prototype.hasCapacity=function(a){return"list"===a||"query"===a||"select"===a||"limit"===a||"sort"===a||"bulk_get"===a},m.prototype.buildQuery=function(c){vard=this;returni(this).push(function(e){varf,g,i,j,k,l=c.query,m=[];if(c.query)if(g=a.QueryFactory.create(c.query),j=o(g))l=void0,k=j;elseif(j=p(g))l=void0,k=j;elseif(ginstanceofh&&"AND"===g.operator)for(f=0;f<g.query_list.length;f+=1)i=g.query_list[f],j=o(i),j?(k=j,g.query_list.splice(f,1),l=a.Query.objectToSearchText(g),f=g.query_list.length):(j=p(i),j&&(k=j,g.query_list.splice(f,1),l=a.Query.objectToSearchText(g),f=g.query_list.length));if(c.sort_on)for(f=0;f<c.sort_on.length;f+=1)m.push(JSON.stringify(c.sort_on[f]));returna.util.ajax({type:"GET",url:b.parse(e._links.raw_search.href).expand({query:l,select_list:c.select_list||["title","reference"],limit:c.limit,sort_on:m,local_roles:k}),xhrFields:{withCredentials:d._thisCredentials},headers:d._headers})}).push(function(a){returnJSON.parse(a.target.responseText)}).push(function(a){varb,c,d,f=a._embedded.contents,g=f.length,h=[];for(b=0;g>b;b+=1)d=f[b],c=newe(d._links.self.href),deleted._links,h.push({id:c.segment(2),value:d});returnh})},a.addStorage("erp5",m)}(jIO,UriTemplate,FormData,RSVP,URI,Blob,SimpleQuery,ComplexQuery),function(a,b,c,d,e){"use strict";functionf(b){this._sub_storage=a.createJIO(b.sub_storage),this._document_id=b.document_id,this._repair_attachment=b.repair_attachment||!1}functiong(a,b){returnvoid0===b?"jio_document/"+d(a)+h:"jio_attachment/"+d(a)+"/"+d(b)}varh=".json",i=newRegExp("^jio_document/([\\w=]+)"+h+"$"),j=newRegExp("^jio_attachment/([\\w=]+)/([\\w=]+)$");f.prototype.get=function(a){returnthis._sub_storage.getAttachment(this._document_id,g(a),{format:"json"})},f.prototype.allAttachments=function(a){returnthis._sub_storage.allAttachments(this._document_id).push(function(b){vard,e,f={};for(einb)if(b.hasOwnProperty(e)&&j.test(e)){d=j.exec(e);try{c(d[1])===a&&(f[c(d[2])]={})}catch(g){if(!ginstanceofReferenceError)throwg}}returnf})},f.prototype.put=function(a,c){returnthis._sub_storage.putAttachment(this._document_id,g(a),newb([JSON.stringify(c)],{type:"application/json"})).push(function(){returna})},f.prototype.remove=function(a){varb=this;returnthis.allAttachments(a).push(function(c){vard,f=[];for(dinc)c.hasOwnProperty(d)&&f.push(b.removeAttachment(a,d));returne.all(f)}).push(function(){returnb._sub_storage.removeAttachment(b._document_id,g(a))}).push(function(){returna})},f.prototype.repair=function(){vara=this;returnthis._sub_storage.repair.apply(this._sub_storage,arguments).push(function(b){returna._repair_attachment?a._sub_storage.allAttachments(a._document_id).push(function(b){vard,f,g,h,k=[],l={},m={};for(hinb)if(b.hasOwnProperty(h))if(d=void0,f=void0,i.test(h)){try{d=c(i.exec(h)[1])}catch(n){if(!ninstanceofReferenceError)thrown}void0!==d&&(l[d]=null)}elseif(j.test(h)){g=j.exec(h);try{d=c(g[1]),f=c(g[2])}catch(n){if(!ninstanceofReferenceError)thrown}void0!==f&&(l.hasOwnProperty(d)||(m.hasOwnProperty(d)||(m[d]={}),m[d][f]=null))}for(dinm)if(m.hasOwnProperty(d)&&!l.hasOwnProperty(d))for(finm[d])m[d].hasOwnProperty(f)&&k.push(a.removeAttachment(d,f));returne.all(k)}):b})},f.prototype.hasCapacity=function(a){return"list"===a},f.prototype.buildQuery=function(){returnthis._sub_storage.allAttachments(this._document_id).push(function(a){varb,d=[];for(bina)if(a.hasOwnProperty(b)&&i.test(b))try{d.push({id:c(i.exec(b)[1]),value:{}})}catch(e){if(!einstanceofReferenceError)throwe}returnd})},f.prototype.getAttachment=function(a,b){returnthis._sub_storage.getAttachment(this._document_id,g(a,b))},f.prototype.putAttachment=function(a,b,c){returnthis._sub_storage.putAttachment(this._document_id,g(a,b),c)},f.prototype.removeAttachment=function(a,b){returnthis._sub_storage.removeAttachment(this._document_id,g(a,b))},a.addStorage("document",f)}(jIO,Blob,atob,btoa,RSVP),function(a,b){"use strict";functionc(b){this._sub_storage=a.createJIO(b.sub_storage),this._key_schema=b.key_schema}c.prototype.get=function(){returnthis._sub_storage.get.apply(this._sub_storage,arguments)},c.prototype.allAttachments=function(){returnthis._sub_storage.allAttachments.apply(this._sub_storage,arguments)},c.prototype.post=function(){returnthis._sub_storage.post.apply(this._sub_storage,arguments)},c.prototype.put=function(){returnthis._sub_storage.put.apply(this._sub_storage,arguments)},c.prototype.remove=function(){returnthis._sub_storage.remove.apply(this._sub_storage,arguments)},c.prototype.getAttachment=function(){returnthis._sub_storage.getAttachment.apply(this._sub_storage,arguments)},c.prototype.putAttachment=function(){returnthis._sub_storage.putAttachment.apply(this._sub_storage,arguments)},c.prototype.removeAttachment=function(){returnthis._sub_storage.removeAttachment.apply(this._sub_storage,arguments)},c.prototype.repair=function(){returnthis._sub_storage.repair.apply(this._sub_storage,arguments)},c.prototype.hasCapacity=function(a){varb=["limit","sort","select","query"];return-1!==b.indexOf(a)?!0:"list"===a?this._sub_storage.hasCapacity(a):!1},c.prototype.buildQuery=function(c){vard=this._sub_storage,e=this,f={},g=!1,h=!1;if(d.hasCapacity("list")){try{void0!==c.query&&!d.hasCapacity("query")||void0!==c.sort_on&&!d.hasCapacity("sort")||void0!==c.select_list&&!d.hasCapacity("select")||void0!==c.limit&&!d.hasCapacity("limit")||(f.query=c.query,f.sort_on=c.sort_on,f.select_list=c.select_list,f.limit=c.limit)}catch(i){if(!(iinstanceofa.util.jIOError&&501===i.status_code))throwi;g=!0}try{(g||c.include_docs===!0)&&d.hasCapacity("include")&&(f.include_docs=!0)}catch(i){if(!(iinstanceofa.util.jIOError&&501===i.status_code))throwi;h=!0}returnd.buildQuery(f).push(function(c){functione(b){vare=c[b].id;returnd.get(e).push(function(a){returna._id=e,a},function(b){if(!(binstanceofa.util.jIOError&&404===b.status_code))throwb})}varf,g,i=[c];if(h){for(f=c.length,g=0;f>g;g+=1)i.push(e(g));c=b.all(i)}returnc}).push(function(a){varb,c,d;if(h){for(b=a[0],c=b.length,d=0;c>d;d+=1)b[d].doc=a[d+1];a=b}returna}).push(function(b){vard,f,h=[];if(g){for(d=b.length,f=0;d>f;f+=1)b[f].doc.__id=b[f].id,h.push(b[f].doc);c.select_list&&c.select_list.push("__id"),b=a.QueryFactory.create(c.query||"",e._key_schema).exec(h,c)}returnb}).push(function(a){varb,d,e,f=[];if(g){for(d=a.length,e=0;d>e;e+=1){if(b={id:a[e].__id,value:c.select_list?a[e]:{},doc:{}},c.select_list&&deleteb.value.__id,c.include_docs)thrownewError("QueryStorage does not support include docs");f.push(b)}a=f}returna})}},a.addStorage("query",c)}(jIO,RSVP),function(a,b,c,d){"use strict";functione(a){a.sessiononly===!0?this._storage=b:this._storage=c}functionf(b){if("/"!==b)thrownewa.util.jIOError("id "+b+" is forbidden (!== /)",400)}e.prototype.get=function(a){returnf(a),{}},e.prototype.allAttachments=function(a){f(a);varb,c={};for(binthis._storage)this._storage.hasOwnProperty(b)&&(c[b]={});returnc},e.prototype.getAttachment=function(b,c){f(b);vard=this._storage.getItem(c);if(null===d)thrownewa.util.jIOError("Cannot find attachment "+c,404);returna.util.dataURItoBlob(d)},e.prototype.putAttachment=function(b,c,e){varg=this;returnf(b),(newd.Queue).push(function(){returna.util.readBlobAsDataURL(e)}).push(function(a){g._storage.setItem(c,a.target.result)})},e.prototype.removeAttachment=function(a,b){returnf(a),this._storage.removeItem(b)},e.prototype.hasCapacity=function(a){return"list"===a},e.prototype.buildQuery=function(){return[{id:"/",value:{}}]},a.addStorage("local",e)}(jIO,sessionStorage,localStorage,RSVP),function(a,b,c,d,e,f,g){"use strict";functionh(b){varc,g=[];for(cinb._mapping_dict)if(b._mapping_dict.hasOwnProperty(c)){if("equalValue"===b._mapping_dict[c][0]){if(void0===b._mapping_dict[c][1])thrownewa.util.jIOError("equalValue has not parameter",400);b._default_mapping[c]=b._mapping_dict[c][1],g.push(newd({key:c,value:b._mapping_dict[c][1],type:"simple"}))}if("equalSubId"===b._mapping_dict[c][0]){if(void0!==b._property_for_sub_id)thrownewa.util.jIOError("equalSubId can be defined one time",400);b._property_for_sub_id=c}}void0!==b._query.query&&g.push(f.create(b._query.query)),g.length>1?b._query.query=newe({type:"complex",query_list:g,operator:"AND"}):1===g.length&&(b._query.query=g[0])}functioni(b){this._mapping_dict=b.mapping_dict||{},this._sub_storage=a.createJIO(b.sub_storage),this._map_all_property=void0!==b.map_all_property?b.map_all_property:!0,this._attachment_mapping_dict=b.attachment_mapping_dict||{},this._query=b.query||{},this._map_id=b.map_id,this._id_mapped=void0!==b.map_id?b.map_id[1]:!1,void0!==this._query.query&&(this._query.query=f.create(this._query.query)),this._default_mapping={},h(this)}functionj(a,b,d,e){varf=a._attachment_mapping_dict;returnvoid0!==f&&void0!==f[d]&&void0!==f[d][e]&&void0!==f[d][e].uri_template?c.parse(f[d][e].uri_template).expand({id:b}):d}functionk(c,f,h){vari;return(newb.Queue).push(function(){if(void0!==c._property_for_sub_id&&void0!==h&&void0!==h[c._property_for_sub_id])returnh[c._property_for_sub_id];if(!c._id_mapped)returnf;if("equalSubProperty"===c._map_id[0])returni=newd({key:c._map_id[1],value:f,type:"simple"}),void0!==c._query.query&&(i=newe({operator:"AND",query_list:[i,c._query.query],type:"complex"})),i=g.objectToSearchText(i),c._sub_storage.allDocs({query:i,sort_on:c._query.sort_on,select_list:c._query.select_list,limit:c._query.limit}).push(function(b){if(0===b.data.rows.length)thrownewa.util.jIOError("Can not find id",404);if(b.data.rows.length>1)thrownewTypeError("id must be unique field: "+f+", result:"+b.data.rows.toString());returnb.data.rows[0].id});thrownewa.util.jIOError("Unsuported option: "+c._mapping_dict.id,400)})}functionl(b,c,d,e){varf,g;if(void0!==b._mapping_dict[c]){if(f=b._mapping_dict[c][0],g=b._mapping_dict[c][1],"equalSubProperty"===f)returnd[g]=e[c],g;if("equalValue"===f)returnd[c]=g,c;if("ignore"===f||"equalSubId"===f)return!1}if(!b._map_all_property)return!1;if(b._map_all_property)returnd[c]=e[c],c;thrownewa.util.jIOError("Unsuported option(s): "+b._mapping_dict[c],400)}functionm(a,b,c,d){vare,f;if(void0!==a._mapping_dict[b]){if(e=a._mapping_dict[b][0],f=a._mapping_dict[b][1],"equalSubProperty"===e)returnc.hasOwnProperty(f)&&(d[b]=c[f]),f;if("equalValue"===e)returnb;if("ignore"===e)returnb}returna._map_all_property?(c.hasOwnProperty(b)&&(d[b]=c[b]),b):!1}functionn(a,b,c){vard,e={},f=[a._id_mapped];for(dina._mapping_dict)a._mapping_dict.hasOwnProperty(d)&&f.push(m(a,d,b,e));if(a._map_all_property)for(dinb)b.hasOwnProperty(d)&&f.indexOf(d)<0&&(e[d]=b[d]);returnvoid0!==a._property_for_sub_id&&void0!==c&&(e[a._property_for_sub_id]=c),e}functiono(a,b,c){vard,e={};for(dinb)b.hasOwnProperty(d)&&l(a,d,e,b);for(dina._default_mapping)a._default_mapping.hasOwnProperty(d)&&(e[d]=a._default_mapping[d]);returna._id_mapped&&void0!==c&&(e[a._id_mapped]=c),e}functionp(a,b,c){returnk(a,b[0]).push(function(d){returnb[0]=d,b[1]=j(a,d,b[1],c),a._sub_storage[c+"Attachment"].apply(a._sub_storage,b)})}i.prototype.get=function(a){varb=this;returnk(this,a).push(function(a){returnb._sub_storage.get(a).push(function(c){returnn(b,c,a)})})},i.prototype.post=function(b){varc=o(this,b),d=b[this._property_for_sub_id];if(this._property_for_sub_id&&void0!==d)returnthis._sub_storage.put(d,c);if(!this._id_mapped||void0!==b[this._id_mapped])returnthis._sub_storage.post(c);thrownewa.util.jIOError("post is not supported with id mapped",400)},i.prototype.put=function(b,c){vard=this,e=o(this,c,b);returnk(this,b,c).push(function(a){returnd._sub_storage.put(a,e)}).push(void0,function(b){if(binstanceofa.util.jIOError&&404===b.status_code)returnd._sub_storage.post(e);throwb}).push(function(){returnb})},i.prototype.remove=function(a){varb=this;returnk(this,a).push(function(a){returnb._sub_storage.remove(a)}).push(function(){returna})},i.prototype.putAttachment=function(a,b){returnp(this,arguments,"put",a).push(function(){returnb})},i.prototype.getAttachment=function(){returnp(this,arguments,"get")},i.prototype.removeAttachment=function(a,b){returnp(this,arguments,"remove",a).push(function(){returnb})},i.prototype.allAttachments=function(a){varb,c=this;returnk(c,a).push(function(a){returnb=a,c._sub_storage.allAttachments(b)}).push(function(a){vard,e={},f={};for(dinc._attachment_mapping_dict)c._attachment_mapping_dict.hasOwnProperty(d)&&(f[j(c,b,d,"get")]=d);for(dina)a.hasOwnProperty(d)&&(f.hasOwnProperty(d)?e[f[d]]={}:e[d]={});returne})},i.prototype.hasCapacity=function(a){returnthis._sub_storage.hasCapacity(a)},i.prototype.repair=function(){returnthis._sub_storage.repair.apply(this._sub_storage,arguments)},i.prototype.bulk=function(a){functionc(a){returnk(d,a.parameter_list[0]).push(function(b){return{method:a.method,parameter_list:[b]}})}vard=this;return(newb.Queue).push(function(){vard=a.map(c);returnb.all(d)}).push(function(a){returnd._sub_storage.bulk(a)}).push(function(a){varb,c=[];for(b=0;b<a.length;b+=1)c.push(n(d,a[b]));returnc})},i.prototype.buildQuery=function(a){functionb(a){varc,d,e,f=[];if("complex"===a.type){for(c=0;c<a.query_list.length;c+=1)e=b(a.query_list[c]),e&&f.push(e);returna.query_list=f,a}returnd=m(i,a.key,{},{}),
},g.prototype.buildQuery=function(){returnthis._local_sub_storage.buildQuery.apply(this._local_sub_storage,arguments)},g.prototype.repair=function(){functionc(a,b,c,d){returnb.removeAttachment(c,d).push(function(){returnw._signature_sub_storage.removeAttachment(c,d)}).push(function(){a[d]=null})}functiong(a,b,c,d,e,f){returnb.putAttachment(e,f,c).push(function(){returnw._signature_sub_storage.putAttachment(e,f,JSON.stringify({hash:d}))}).push(function(){a[f]=null})}functionh(b,d,e,h,i,j,k,l,m,n,o){varp;returnj.getAttachment(k,l).push(function(b){returnp=b,a.util.readBlobAsArrayBuffer(p)}).push(function(a){returnf(a.target.result)},function(b){if(binstanceofa.util.jIOError&&404===b.status_code)returnp=null,null;throwb}).push(function(f){if(e===f)returnnull===e?w._signature_sub_storage.removeAttachment(k,l).push(function(){b[k]=null}):w._signature_sub_storage.putAttachment(k,l,JSON.stringify({hash:e})).push(function(){y[k]=null});if(f===d||m===!0)returnnull===e?c(b,j,k,l):g(b,j,h,e,k,l);if(o!==!0){if(n===!0||null===e)returnnull===f?c(b,i,k,l):g(b,i,p,f,k,l);if(null===f)returng(b,j,h,e,k,l);thrownewa.util.jIOError("Conflict on '"+k+"' with attachment '"+l+"'",409)}})}functioni(c,d,e,g,i,j,k,l,m,n,o){varp,q;d.push(function(){if(n===!0)returnb.all([e.getAttachment(i,j),{hash:null}]);if(o===!0)returnb.all([e.getAttachment(i,j),w._signature_sub_storage.getAttachment(i,j,{format:"json"})]);thrownewa.util.jIOError("Unexpected call of checkAttachmentSignatureDifference",409)}).push(function(b){returnp=b[0],q=b[1].hash,a.util.readBlobAsArrayBuffer(p)}).push(function(a){varb=a.target.result,d=f(b);returnd!==q?h(c,q,d,p,e,g,i,j,k,l,m):void0})}functionm(a,b,c,d,e,f,g,i,j){vark;b.push(function(){returnw._signature_sub_storage.getAttachment(d,e,{format:"json"})}).push(function(b){returnk=b.hash,h(a,k,null,null,f,c,d,e,g,i,j)})}functionn(c,d,e,f,g){varh=newb.Queue;returnh.push(function(){returnb.all([e.allAttachments(d).push(void0,function(b){if(binstanceofa.util.jIOError&&404===b.status_code)return{};throwb}),w._signature_sub_storage.allAttachments(d).push(void0,function(b){if(binstanceofa.util.jIOError&&404===b.status_code)return{};throwb})])}).push(function(a){varb,j,k,l={},n={};for(kina[0])a[0].hasOwnProperty(k)&&(c.hasOwnProperty(k)||(l[k]=null));for(kina[1])a[1].hasOwnProperty(k)&&(c.hasOwnProperty(k)||(n[k]=null));for(kinl)l.hasOwnProperty(k)&&(b=n.hasOwnProperty(k)&&g.check_modification,j=!n.hasOwnProperty(k)&&g.check_creation,(b===!0||j===!0)&&i(c,h,e,f,d,k,g.conflict_force,g.conflict_revert,g.conflict_ignore,j,b));if(g.check_deletion===!0)for(kinn)n.hasOwnProperty(k)&&(l.hasOwnProperty(k)||m(c,h,f,d,k,e,g.conflict_force,g.conflict_revert,g.conflict_ignore))})}functiono(a){varc={};return(newb.Queue).push(function(){returnw._check_local_attachment_modification||w._check_local_attachment_creation||w._check_local_attachment_deletion?n(c,a,w._local_sub_storage,w._remote_sub_storage,{conflict_force:w._conflict_handling===j,conflict_revert:w._conflict_handling===k,conflict_ignore:w._conflict_handling===l,check_modification:w._check_local_attachment_modification,check_creation:w._check_local_attachment_creation,check_deletion:w._check_local_attachment_deletion}):void0}).push(function(){returnw._check_remote_attachment_modification||w._check_remote_attachment_creation||w._check_remote_attachment_deletion?n(c,a,w._remote_sub_storage,w._local_sub_storage,{use_revert_post:w._use_remote_post,conflict_force:w._conflict_handling===k,conflict_revert:w._conflict_handling===j,conflict_ignore:w._conflict_handling===l,check_modification:w._check_remote_attachment_modification,check_creation:w._check_remote_attachment_creation,check_deletion:w._check_remote_attachment_deletion}):void0})}functionp(a,c,d,e,f,g){varh,i,j=!0;returnvoid0===g&&(g={}),h=g.use_post?c.post(d).push(function(b){returnj=!1,i=b,a.put(i,d)}).push(function(){returna.allAttachments(f)}).push(function(c){functiond(b){g.push(function(){returna.getAttachment(f,b)}).push(function(c){returna.putAttachment(i,b,c)})}vare,g=newb.Queue;for(einc)c.hasOwnProperty(e)&&d(e);returng}).push(function(){returna.remove(f)}).push(function(){returnw._signature_sub_storage.remove(f)}).push(function(){returnj=!0,w._signature_sub_storage.put(i,{hash:e})}).push(function(){y[i]=null}):c.put(f,d).push(function(){returnw._signature_sub_storage.put(f,{hash:e})}),h.push(function(){j&&(y[f]=null)})}functionq(b,c){returno(c).push(function(){returnb.allAttachments(c)}).push(function(a){return"{}"===JSON.stringify(a)?b.remove(c).push(function(){returnw._signature_sub_storage.remove(c)}):void0},function(b){if(!(binstanceofa.util.jIOError&&404===b.status_code))throwb}).push(function(){y[c]=null})}functionr(b,c,f,g,h,i,j,k,l,m){returnh.get(i).push(function(a){return[a,e(d(a))]},function(b){if(binstanceofa.util.jIOError&&404===b.status_code)return[null,null];throwb}).push(function(e){varn=e[0],o=e[1];if(c===o)returnnull===c?w._signature_sub_storage.remove(i).push(function(){y[i]=null}):w._signature_sub_storage.put(i,{hash:c}).push(function(){y[i]=null});if(o===b||j===!0)returnnull===c?q(h,i):p(g,h,f,c,i,{use_post:m.use_post&&null===o});if(l!==!0){if(k===!0||null===c)returnnull===o?q(g,i):p(h,g,n,o,i,{use_post:m.use_revert_post&&null===c});if(null===o)returnp(g,h,f,c,i,{use_post:m.use_post});thrownewa.util.jIOError("Conflict on '"+i+"': "+d(f||"")+" !== "+d(n||""),409)}})}functions(a,b,c,d,e,f,g,h){vari;a.push(function(){returnw._signature_sub_storage.get(c)}).push(function(a){returni=a.hash,r(i,null,null,d,b,c,e,f,g,h)})}functiont(c,f,g,h,i,j,k,l,m,n,o){c.push(function(){if(l===!0)returnb.all([n(h),{hash:null}]);if(m===!0)returnb.all([n(h),w._signature_sub_storage.get(h)]);thrownewa.util.jIOError("Unexpected call of checkSignatureDifference",409)}).push(function(a){varb=a[0],c=e(d(b)),l=a[1].hash;returnc!==l?r(l,c,b,f,g,h,i,j,k,o):void0})}functionu(a,c,d,e,f,g,h,i,j){a.push(function(){returnc.bulk(e)}).push(function(a){functionk(b){returnfunction(c){if(c!==e[b].parameter_list[0])thrownewError("Does not access expected ID "+c);returna[b]}}varl,m=newb.Queue;for(l=0;l<a.length;l+=1)t(m,c,d,e[l].parameter_list[0],h,i,j,f[l].is_creation,f[l].is_modification,k(l),g);returnm})}functionv(a,c,d){vare=newb.Queue;returnd.hasOwnProperty("use_post")||(d.use_post=!1),d.hasOwnProperty("use_revert_post")||(d.use_revert_post=!1),e.push(function(){returnb.all([a.allDocs(w._query_options),w._signature_sub_storage.allDocs()])}).push(function(b){varf,g,h,i,j={},k=[],l=[],m={};for(f=0;f<b[0].data.total_rows;f+=1)y.hasOwnProperty(b[0].data.rows[f].id)||(j[b[0].data.rows[f].id]=f);for(f=0;f<b[1].data.total_rows;f+=1)y.hasOwnProperty(b[1].data.rows[f].id)||(m[b[1].data.rows[f].id]=f);for(iinj)j.hasOwnProperty(i)&&(g=m.hasOwnProperty(i)&&d.check_modification,h=!m.hasOwnProperty(i)&&d.check_creation,(g===!0||h===!0)&&(d.use_bulk_get===!0?(k.push({method:"get",parameter_list:[i]}),l.push({is_creation:h,is_modification:g})):t(e,a,c,i,d.conflict_force,d.conflict_revert,d.conflict_ignore,h,g,a.get.bind(a),d)));if(d.check_deletion===!0)for(iinm)m.hasOwnProperty(i)&&(j.hasOwnProperty(i)||s(e,c,i,a,d.conflict_force,d.conflict_revert,d.conflict_ignore,d));d.use_bulk_get===!0&&0!==k.length&&u(e,a,c,k,l,d,d.conflict_force,d.conflict_revert,d.conflict_ignore)})}varw=this,x=arguments,y={};returny[w._signature_hash]=null,(newb.Queue).push(function(){returnw._signature_sub_storage.__storage._sub_storage.get(w._signature_hash)}).push(void0,function(b){if(binstanceofa.util.jIOError&&404===b.status_code)returnw._signature_sub_storage.__storage._sub_storage.put(w._signature_hash,{});throwb}).push(function(){returnb.all([w._local_sub_storage.repair.apply(w._local_sub_storage,x),w._remote_sub_storage.repair.apply(w._remote_sub_storage,x)])}).push(function(){returnw._check_local_modification||w._check_local_creation||w._check_local_deletion?v(w._local_sub_storage,w._remote_sub_storage,{use_post:w._use_remote_post,conflict_force:w._conflict_handling===j,conflict_revert:w._conflict_handling===k,conflict_ignore:w._conflict_handling===l,check_modification:w._check_local_modification,check_creation:w._check_local_creation,check_deletion:w._check_local_deletion}):void0}).push(function(){varb=!1;try{b=w._remote_sub_storage.hasCapacity("bulk_get")}catch(c){if(!(cinstanceofa.util.jIOError&&501===c.status_code))throwc}returnw._check_remote_modification||w._check_remote_creation||w._check_remote_deletion?v(w._remote_sub_storage,w._local_sub_storage,{use_bulk_get:b,use_revert_post:w._use_remote_post,conflict_force:w._conflict_handling===k,conflict_revert:w._conflict_handling===j,conflict_ignore:w._conflict_handling===l,check_modification:w._check_remote_modification,check_creation:w._check_remote_creation,check_deletion:w._check_remote_deletion}):void0}).push(function(){returnw._check_local_attachment_modification||w._check_local_attachment_creation||w._check_local_attachment_deletion||w._check_remote_attachment_modification||w._check_remote_attachment_creation||w._check_remote_attachment_deletion?w._signature_sub_storage.allDocs().push(function(a){functionc(a){e.push(function(){returno(a)})}vard,e=newb.Queue;for(d=0;d<a.data.total_rows;d+=1)c(a.data.rows[d].id);returne}):void0})},a.addStorage("replicate",g)}(jIO,RSVP,Rusha,jIO.util.stringify),function(a){"use strict";functionb(b){this._sub_storage=a.createJIO(b.sub_storage)}b.prototype.get=function(){returnthis._sub_storage.get.apply(this._sub_storage,arguments)},b.prototype.allAttachments=function(){returnthis._sub_storage.allAttachments.apply(this._sub_storage,arguments)},b.prototype.post=function(a){functionb(){return("0000"+Math.floor(65536*Math.random()).toString(16)).slice(-4)}varc=b()+b()+"-"+b()+"-"+b()+"-"+b()+"-"+b()+b()+b();returnthis.put(c,a)},b.prototype.put=function(){returnthis._sub_storage.put.apply(this._sub_storage,arguments)},b.prototype.remove=function(){returnthis._sub_storage.remove.apply(this._sub_storage,arguments)},b.prototype.getAttachment=function(){returnthis._sub_storage.getAttachment.apply(this._sub_storage,arguments)},b.prototype.putAttachment=function(){returnthis._sub_storage.putAttachment.apply(this._sub_storage,arguments)},b.prototype.removeAttachment=function(){returnthis._sub_storage.removeAttachment.apply(this._sub_storage,arguments)},b.prototype.repair=function(){returnthis._sub_storage.repair.apply(this._sub_storage,arguments)},b.prototype.hasCapacity=function(a){returnthis._sub_storage.hasCapacity(a)},b.prototype.buildQuery=function(){returnthis._sub_storage.buildQuery.apply(this._sub_storage,arguments)},a.addStorage("uuid",b)}(jIO),function(a,b,c){"use strict";functiond(){this._database={}}d.prototype.put=function(a,c){returnthis._database.hasOwnProperty(a)||(this._database[a]={attachments:{}}),this._database[a].doc=b.stringify(c),a},d.prototype.get=function(c){try{returnb.parse(this._database[c].doc)}catch(d){if(dinstanceofTypeError)thrownewa.util.jIOError("Cannot find document: "+c,404);throwd}},d.prototype.allAttachments=function(b){varc,d={};try{for(cinthis._database[b].attachments)this._database[b].attachments.hasOwnProperty(c)&&(d[c]={})}catch(e){if(einstanceofTypeError)thrownewa.util.jIOError("Cannot find document: "+b,404);throwe}returnd},d.prototype.remove=function(a){returndeletethis._database[a],a},d.prototype.getAttachment=function(b,c){try{vard=this._database[b].attachments[c];if(void0===d)thrownewa.util.jIOError("Cannot find attachment: "+b+" , "+c,404);returna.util.dataURItoBlob(d)}catch(e){if(einstanceofTypeError)thrownewa.util.jIOError("Cannot find attachment: "+b+" , "+c,404);throwe}},d.prototype.putAttachment=function(b,d,e){varf;try{f=this._database[b].attachments}catch(g){if(ginstanceofTypeError)thrownewa.util.jIOError("Cannot find document: "+b,404);throwg}return(newc.Queue).push(function(){returna.util.readBlobAsDataURL(e)}).push(function(a){f[d]=a.target.result})},d.prototype.removeAttachment=function(b,c){try{deletethis._database[b].attachments[c]}catch(d){if(dinstanceofTypeError)thrownewa.util.jIOError("Cannot find document: "+b,404);throwd}},d.prototype.hasCapacity=function(a){return"list"===a||"include"===a},d.prototype.buildQuery=function(a){varc,d=[];for(cinthis._database)this._database.hasOwnProperty(c)&&(a.include_docs===!0?d.push({id:c,value:{},doc:b.parse(this._database[c].doc)}):d.push({id:c,value:{}}));returnd},a.addStorage("memory",d)}(jIO,JSON,RSVP),function(a,b,c,d,e,f,g,h){"use strict";functioni(b){return(newd.Queue).push(function(){returna.util.ajax({type:"GET",url:b._url,xhrFields:{withCredentials:b._thisCredentials},headers:b._headers})}).push(function(a){returnJSON.parse(a.target.responseText)})}functionj(c,e,f){returnvoid0===f&&(f={}),i(c).push(function(g){return(newd.Queue).push(function(){returna.util.ajax({type:"GET",url:b.parse(g._links.traverse.href).expand({relative_url:e,view:f._view}),xhrFields:{withCredentials:c._thisCredentials},headers:c._headers})}).push(void0,function(b){if(void0!==b.target&&404===b.target.status)thrownewa.util.jIOError("Cannot find document: "+e,404);throwb})})}functionk(a){return(newd.Queue).push(function(){varb,c,d,f,g=a._embedded._view,h={portal_type:a._links.type.name},i={};a._links.hasOwnProperty("parent")&&(h.parent_relative_url=newe(a._links.parent.href).segment(2)),i.form_id={key:[g.form_id.key],"default":g.form_id["default"]};for(cing)g.hasOwnProperty(c)&&(b=g[c],d=0,0===c.indexOf("my_")&&b.editable&&(d=3),0===c.indexOf("your_")&&(d=5),0!==d&&q.hasOwnProperty(b.type)&&(i[c.substring(d)]={"default":b["default"],key:b.key},h[c.substring(d)]=b["default"]));returnf={data:h,form_data:i},g.hasOwnProperty("_actions")&&g._actions.hasOwnProperty("put")&&(f.action_href=g._actions.put.href),f})}functionl(b,c){returnb.getAttachment(c,"view").push(function(b){returna.util.readBlobAsText(b)}).push(function(a){returnJSON.parse(a.target.result)}).push(function(a){returnk(a)})}functionm(a){if("string"!=typeofa.url||!a.url)thrownewTypeError("ERP5 'url' must be a string which contains more than one character.");this._url=a.url,this._default_view_reference=a.default_view_reference,this._headers=null,this._thisCredentials=!0,void0!==a.login&&void0!==a.password&&(this._headers={Authorization:"Basic "+btoa(a.login+":"+a.password)},this._thisCredentials=!1)}functionn(a){returna.data}functiono(a){returnainstanceofg&&"local_roles"===a.key?a.value:void0}functionp(a){varb,c,d=!0,e=[];if(ainstanceofh&&"OR"===a.operator){for(b=0;b<a.query_list.length;b+=1)c=a.query_list[b],cinstanceofg&&"local_roles"===c.key?e.push(c.value):d=!1;if(d)returne}}varq={StringField:null,EmailField:null,IntegerField:null,FloatField:null,TextAreaField:null};m.prototype.get=function(a){returnl(this,a).push(function(a){returnn(a)})},m.prototype.bulk=function(b){vare,f=this,g=[];for(e=0;e<b.length;e+=1){if("get"!==b[e].method)thrownewError("ERP5Storage: not supported "+b[e].method+" in bulk");g.push({relative_url:b[e].parameter_list[0],view:f._default_view_reference})}returni(f).push(function(b){vard=newc;returnd.append("bulk_list",JSON.stringify(g)),a.util.ajax({type:"POST",url:b._actions.bulk.href,data:d,xhrFields:{withCredentials:f._thisCredentials},headers:f._headers})}).push(function(a){functionb(a){returnk(a).push(function(a){returnn(a)})}varc=[],f=JSON.parse(a.target.responseText);for(e=0;e<f.result_list.length;e+=1)c.push(b(f.result_list[e]));returnd.all(c)})},m.prototype.post=function(b){vard,f=this;returni(this).push(function(d){vare=newc;returne.append("portal_type",b.portal_type),e.append("parent_relative_url",b.parent_relative_url),a.util.ajax({type:"POST",url:d._actions.add.href,data:e,xhrFields:{withCredentials:f._thisCredentials},headers:f._headers})}).push(function(a){varc=a.target.getResponseHeader("X-Location"),g=newe(c);returnd=g.segment(2),f.put(d,b)}).push(function(){returnd})},m.prototype.put=function(b,c){vard=this;returnl(d,b).push(function(e){varg,h=e.form_data,i={};i[h.form_id.key]=h.form_id["default"];for(ginc)if(c.hasOwnProperty(g)){if("form_id"===g)thrownewa.util.jIOError("ERP5: forbidden property: "+g,400);if("portal_type"!==g&&"parent_relative_url"!==g){if(!h.hasOwnProperty(g))thrownewa.util.jIOError("ERP5: can not store property: "+g,400);i[h[g].key]=c[g]}}if(!e.hasOwnProperty("action_href"))thrownewa.util.jIOError("ERP5: can not modify document: "+b,403);returnd.putAttachment(b,e.action_href,newf([JSON.stringify(i)],{type:"application/json"}))})},m.prototype.allAttachments=function(a){varb=this;returnj(this,a).push(function(){returnvoid0===b._default_view_reference?{links:{}}:{view:{},links:{}}})},m.prototype.getAttachment=function(b,c,e){varg=this;if(void0===e&&(e={}),"view"===c){if(void0===this._default_view_reference)thrownewa.util.jIOError("Cannot find attachment view for: "+b,404);returnj(this,b,{_view:this._default_view_reference}).push(function(a){varb=JSON.parse(a.target.responseText);returnnewf([JSON.stringify(b)],{type:"application/hal+json"})})}if("links"===c)returnj(this,b).push(function(a){returnnewf([JSON.stringify(JSON.parse(a.target.responseText))],{type:"application/hal+json"})});if(0===c.indexOf(this._url))return(newd.Queue).push(function(){varb,d,f,h={type:"GET",dataType:"blob",url:c,xhrFields:{withCredentials:g._thisCredentials},headers:g._headers};if(void0!==e.start||void0!==e.end){if(b=e.start||0,d=e.end,void0!==d&&0>d)thrownewa.util.jIOError("end must be positive",400);if(0>b)f="bytes="+b;elseif(void0===d)f="bytes="+b+"-";else{if(b>d)thrownewa.util.jIOError("start is greater than end",400);f="bytes="+b+"-"+d}void0===g._headers?h.headers={Range:f}:h.headers.Range=f}returna.util.ajax(h)}).push(function(a){returnvoid0===a.target.response?newf([a.target.responseText],{type:a.target.getResponseHeader("Content-Type")}):a.target.response});thrownewa.util.jIOError("ERP5: not support get attachment: "+c,400)},m.prototype.putAttachment=function(b,e,f){varg=this;if(0!==e.indexOf(this._url))thrownewa.util.jIOError("Can not store outside ERP5: "+e,400);return(newd.Queue).push(function(){returna.util.readBlobAsText(f)}).push(function(b){vard,f,h,i,j=JSON.parse(b.target.result),k=newc;for(hinj)if(j.hasOwnProperty(h))for(d=Array.isArray(j[h])?j[h]:[j[h]],f=0;f<d.length;f+=1)i=d[f],"object"==typeofi?k.append(h,a.util.dataURItoBlob(i.url),i.file_name):k.append(h,i);returna.util.ajax({type:"POST",url:e,data:k,xhrFields:{withCredentials:g._thisCredentials},headers:g._headers})})},m.prototype.hasCapacity=function(a){return"list"===a||"query"===a||"select"===a||"limit"===a||"sort"===a||"bulk_get"===a},m.prototype.buildQuery=function(c){vard=this;returni(this).push(function(e){varf,g,i,j,k,l=c.query,m=[];if(c.query)if(g=a.QueryFactory.create(c.query),j=o(g))l=void0,k=j;elseif(j=p(g))l=void0,k=j;elseif(ginstanceofh&&"AND"===g.operator)for(f=0;f<g.query_list.length;f+=1)i=g.query_list[f],j=o(i),j?(k=j,g.query_list.splice(f,1),l=a.Query.objectToSearchText(g),f=g.query_list.length):(j=p(i),j&&(k=j,g.query_list.splice(f,1),l=a.Query.objectToSearchText(g),f=g.query_list.length));if(c.sort_on)for(f=0;f<c.sort_on.length;f+=1)m.push(JSON.stringify(c.sort_on[f]));returna.util.ajax({type:"GET",url:b.parse(e._links.raw_search.href).expand({query:l,select_list:c.select_list||["title","reference"],limit:c.limit,sort_on:m,local_roles:k}),xhrFields:{withCredentials:d._thisCredentials},headers:d._headers})}).push(function(a){returnJSON.parse(a.target.responseText)}).push(function(a){varb,c,d,f=a._embedded.contents,g=f.length,h=[];for(b=0;g>b;b+=1)d=f[b],c=newe(d._links.self.href),deleted._links,h.push({id:c.segment(2),value:d});returnh})},a.addStorage("erp5",m)}(jIO,UriTemplate,FormData,RSVP,URI,Blob,SimpleQuery,ComplexQuery),function(a,b,c,d,e){"use strict";functionf(b){this._sub_storage=a.createJIO(b.sub_storage),this._document_id=b.document_id,this._repair_attachment=b.repair_attachment||!1}functiong(a,b){returnvoid0===b?"jio_document/"+d(a)+h:"jio_attachment/"+d(a)+"/"+d(b)}varh=".json",i=newRegExp("^jio_document/([\\w=]+)"+h+"$"),j=newRegExp("^jio_attachment/([\\w=]+)/([\\w=]+)$");f.prototype.get=function(a){returnthis._sub_storage.getAttachment(this._document_id,g(a),{format:"json"})},f.prototype.allAttachments=function(a){returnthis._sub_storage.allAttachments(this._document_id).push(function(b){vard,e,f={};for(einb)if(b.hasOwnProperty(e)&&j.test(e)){d=j.exec(e);try{c(d[1])===a&&(f[c(d[2])]={})}catch(g){if(!ginstanceofReferenceError)throwg}}returnf})},f.prototype.put=function(a,c){returnthis._sub_storage.putAttachment(this._document_id,g(a),newb([JSON.stringify(c)],{type:"application/json"})).push(function(){returna})},f.prototype.remove=function(a){varb=this;returnthis.allAttachments(a).push(function(c){vard,f=[];for(dinc)c.hasOwnProperty(d)&&f.push(b.removeAttachment(a,d));returne.all(f)}).push(function(){returnb._sub_storage.removeAttachment(b._document_id,g(a))}).push(function(){returna})},f.prototype.repair=function(){vara=this;returnthis._sub_storage.repair.apply(this._sub_storage,arguments).push(function(b){returna._repair_attachment?a._sub_storage.allAttachments(a._document_id).push(function(b){vard,f,g,h,k=[],l={},m={};for(hinb)if(b.hasOwnProperty(h))if(d=void0,f=void0,i.test(h)){try{d=c(i.exec(h)[1])}catch(n){if(!ninstanceofReferenceError)thrown}void0!==d&&(l[d]=null)}elseif(j.test(h)){g=j.exec(h);try{d=c(g[1]),f=c(g[2])}catch(n){if(!ninstanceofReferenceError)thrown}void0!==f&&(l.hasOwnProperty(d)||(m.hasOwnProperty(d)||(m[d]={}),m[d][f]=null))}for(dinm)if(m.hasOwnProperty(d)&&!l.hasOwnProperty(d))for(finm[d])m[d].hasOwnProperty(f)&&k.push(a.removeAttachment(d,f));returne.all(k)}):b})},f.prototype.hasCapacity=function(a){return"list"===a},f.prototype.buildQuery=function(){returnthis._sub_storage.allAttachments(this._document_id).push(function(a){varb,d=[];for(bina)if(a.hasOwnProperty(b)&&i.test(b))try{d.push({id:c(i.exec(b)[1]),value:{}})}catch(e){if(!einstanceofReferenceError)throwe}returnd})},f.prototype.getAttachment=function(a,b){returnthis._sub_storage.getAttachment(this._document_id,g(a,b))},f.prototype.putAttachment=function(a,b,c){returnthis._sub_storage.putAttachment(this._document_id,g(a,b),c)},f.prototype.removeAttachment=function(a,b){returnthis._sub_storage.removeAttachment(this._document_id,g(a,b))},a.addStorage("document",f)}(jIO,Blob,atob,btoa,RSVP),function(a,b){"use strict";functionc(b){this._sub_storage=a.createJIO(b.sub_storage),this._key_schema=b.key_schema}c.prototype.get=function(){returnthis._sub_storage.get.apply(this._sub_storage,arguments)},c.prototype.allAttachments=function(){returnthis._sub_storage.allAttachments.apply(this._sub_storage,arguments)},c.prototype.post=function(){returnthis._sub_storage.post.apply(this._sub_storage,arguments)},c.prototype.put=function(){returnthis._sub_storage.put.apply(this._sub_storage,arguments)},c.prototype.remove=function(){returnthis._sub_storage.remove.apply(this._sub_storage,arguments)},c.prototype.getAttachment=function(){returnthis._sub_storage.getAttachment.apply(this._sub_storage,arguments)},c.prototype.putAttachment=function(){returnthis._sub_storage.putAttachment.apply(this._sub_storage,arguments)},c.prototype.removeAttachment=function(){returnthis._sub_storage.removeAttachment.apply(this._sub_storage,arguments)},c.prototype.repair=function(){returnthis._sub_storage.repair.apply(this._sub_storage,arguments)},c.prototype.hasCapacity=function(a){varb=["limit","sort","select","query"];return-1!==b.indexOf(a)?!0:"list"===a?this._sub_storage.hasCapacity(a):!1},c.prototype.buildQuery=function(c){vard=this._sub_storage,e=this,f={},g=!1,h=!1;if(d.hasCapacity("list")){try{void0!==c.query&&!d.hasCapacity("query")||void0!==c.sort_on&&!d.hasCapacity("sort")||void0!==c.select_list&&!d.hasCapacity("select")||void0!==c.limit&&!d.hasCapacity("limit")||(f.query=c.query,f.sort_on=c.sort_on,f.select_list=c.select_list,f.limit=c.limit)}catch(i){if(!(iinstanceofa.util.jIOError&&501===i.status_code))throwi;g=!0}try{(g||c.include_docs===!0)&&d.hasCapacity("include")&&(f.include_docs=!0)}catch(i){if(!(iinstanceofa.util.jIOError&&501===i.status_code))throwi;h=!0}returnd.buildQuery(f).push(function(c){functione(b){vare=c[b].id;returnd.get(e).push(function(a){returna._id=e,a},function(b){if(!(binstanceofa.util.jIOError&&404===b.status_code))throwb})}varf,g,i=[c];if(h){for(f=c.length,g=0;f>g;g+=1)i.push(e(g));c=b.all(i)}returnc}).push(function(a){varb,c,d;if(h){for(b=a[0],c=b.length,d=0;c>d;d+=1)b[d].doc=a[d+1];a=b}returna}).push(function(b){vard,f,h=[];if(g){for(d=b.length,f=0;d>f;f+=1)b[f].doc.__id=b[f].id,h.push(b[f].doc);c.select_list&&c.select_list.push("__id"),b=a.QueryFactory.create(c.query||"",e._key_schema).exec(h,c)}returnb}).push(function(a){varb,d,e,f=[];if(g){for(d=a.length,e=0;d>e;e+=1){if(b={id:a[e].__id,value:c.select_list?a[e]:{},doc:{}},c.select_list&&deleteb.value.__id,c.include_docs)thrownewError("QueryStorage does not support include docs");f.push(b)}a=f}returna})}},a.addStorage("query",c)}(jIO,RSVP),function(a,b,c,d){"use strict";functione(a){a.sessiononly===!0?this._storage=b:this._storage=c}functionf(b){if("/"!==b)thrownewa.util.jIOError("id "+b+" is forbidden (!== /)",400)}e.prototype.get=function(a){returnf(a),{}},e.prototype.allAttachments=function(a){f(a);varb,c={};for(binthis._storage)this._storage.hasOwnProperty(b)&&(c[b]={});returnc},e.prototype.getAttachment=function(b,c){f(b);vard=this._storage.getItem(c);if(null===d)thrownewa.util.jIOError("Cannot find attachment "+c,404);returna.util.dataURItoBlob(d)},e.prototype.putAttachment=function(b,c,e){varg=this;returnf(b),(newd.Queue).push(function(){returna.util.readBlobAsDataURL(e)}).push(function(a){g._storage.setItem(c,a.target.result)})},e.prototype.removeAttachment=function(a,b){returnf(a),this._storage.removeItem(b)},e.prototype.hasCapacity=function(a){return"list"===a},e.prototype.buildQuery=function(){return[{id:"/",value:{}}]},a.addStorage("local",e)}(jIO,sessionStorage,localStorage,RSVP),function(a,b,c,d,e,f,g){"use strict";functionh(b,c,f){varh;if(b._no_sub_query_id)thrownewa.util.jIOError("no sub query id active",404);returnh=newd({key:f,value:c,type:"simple"}),void0!==b._query.query&&(h=newe({operator:"AND",query_list:[h,b._query.query],type:"complex"})),h=g.objectToSearchText(h),b._sub_storage.allDocs({query:h,sort_on:b._query.sort_on,select_list:b._query.select_list,limit:b._query.limit}).push(function(b){if(0===b.data.rows.length)thrownewa.util.jIOError("Can not find id",404);if(b.data.rows.length>1)thrownewTypeError("id must be unique field: "+f+", result:"+b.data.rows.toString());returnb.data.rows[0].id})}functioni(b){varc,g=[];for(cinb._mapping_dict)if(b._mapping_dict.hasOwnProperty(c)){if("equalValue"===b._mapping_dict[c][0]){if(void0===b._mapping_dict[c][1])thrownewa.util.jIOError("equalValue has not parameter",400);b._default_mapping[c]=b._mapping_dict[c][1],g.push(newd({key:c,value:b._mapping_dict[c][1],type:"simple"}))}if("equalSubId"===b._mapping_dict[c][0]){if(void0!==b._property_for_sub_id)thrownewa.util.jIOError("equalSubId can be defined one time",400);b._property_for_sub_id=c}}void0!==b._query.query&&g.push(f.create(b._query.query)),g.length>1?b._query.query=newe({type:"complex",query_list:g,operator:"AND"}):1===g.length&&(b._query.query=g[0])}functionj(b){this._mapping_dict=b.property||{},this._sub_storage=a.createJIO(b.sub_storage),this._map_all_property=void0!==b.map_all_property?b.map_all_property:!0,this._no_sub_query_id=b.no_sub_query_id,this._attachment_mapping_dict=b.attachment||{},this._query=b.query||{},this._map_id=b.id||["equalSubId"],this._id_mapped=void0!==b.id?b.id[1]:!1,void0!==this._query.query&&(this._query.query=f.create(this._query.query)),this._default_mapping={},i(this)}functionk(a,b,d,e){varf=a._attachment_mapping_dict;returnvoid0!==f&&void0!==f[d]&&void0!==f[d][e]&&void0!==f[d][e].uri_template?c.parse(f[d][e].uri_template).expand({id:b}):d}functionl(a,c,d){return(newb.Queue).push(function(){varb=a._map_id||["equalSubId"];returna._property_for_sub_id&&void0!==d&&d.hasOwnProperty(a._property_for_sub_id)?d[a._property_for_sub_id]:r[b[0]].mapToSubId(a,d,c,b[1])})}functionm(a,b,c,d,e){varf=a._mapping_dict[b]||["keep"];returnr[f[0]].mapToSubProperty(b,c,d,f[1],e)}functionn(a,b,c,d,e){varf=a._mapping_dict[b]||["keep"];returnr[f[0]].mapToMainProperty(b,c,d,f[1],e)}functiono(a,b,c){vard,e={},f=[a._id_mapped];for(dina._mapping_dict)a._mapping_dict.hasOwnProperty(d)&&f.push(n(a,d,b,e,c));if(a._map_all_property)for(dinb)b.hasOwnProperty(d)&&f.indexOf(d)<0&&(e[d]=b[d]);returnvoid0!==a._map_for_sub_storage_id&&(e[a._map_for_sub_storage_id]=c),e}functionp(a,b,c){vard,e={};for(dinb)b.hasOwnProperty(d)&&m(a,d,e,b,c);for(dina._default_mapping)a._default_mapping.hasOwnProperty(d)&&(e[d]=a._default_mapping[d]);return"equalSubProperty"===a._map_id[0]&&void0!==c&&(e[a._map_id[1]]=c),e}functionq(a,b,c){returnl(a,b[0]).push(function(d){returnb[0]=d,b[1]=k(a,d,b[1],c),a._sub_storage[c+"Attachment"].apply(a._sub_storage,b)})}varr={equalSubProperty:{mapToSubProperty:function(a,b,c,d,e){returnb[d]=c[a],d},mapToMainProperty:function(a,b,c,d,e){returnb.hasOwnProperty(d)&&(c[a]=b[d]),d},mapToSubId:function(a,b,c,d){if(void0!==b){if(a._property_for_sub_id&&b.hasOwnProperty(a._property_for_sub_id))returnb[a._property_for_sub_id];if(b.hasOwnProperty(d))returnb[d]}returnh(a,c,a._map_id[1])},mapToId:function(a,b,c,d){returnb[d]}},equalValue:{mapToSubProperty:function(a,b,c,d){returnb[a]=d,a},mapToMainProperty:function(a){returna}},ignore:{mapToSubProperty:function(){return!1},mapToMainProperty:function(a){returna}},equalSubId:{mapToSubProperty:function(a,b,c){returnb[a]=c[a],a},mapToMainProperty:function(a,b,c,d,e){returnvoid0===e&&b.hasOwnProperty(a)?c[a]=b[a]:c[a]=e,a},mapToSubId:function(a,b,c,d){returnc},mapToId:function(a,b,c){returnc}},keep:{mapToSubProperty:function(a,b,c){returnb[a]=c[a],a},mapToMainProperty:function(a,b,c){returnc[a]=b[a],a}},switchPropertyValue:{mapToSubProperty:function(a,b,c,d){returnb[d[0]]=d[1][c[a]],d[0]},mapToMainProperty:function(a,b,c,d){vare,f=b[d[0]];for(eind[1])if(d[1].hasOwnProperty(e)&&f===d[1][e])returnc[a]=e,a}}};j.prototype.get=function(a){varb=this;returnl(this,a).push(function(a){returnb._sub_storage.get(a).push(function(c){returno(b,c,a)})})},j.prototype.post=function(b){varc=p(this,b),d=b[this._property_for_sub_id];if(this._property_for_sub_id&&void0!==d)returnthis._sub_storage.put(d,c);if(!this._id_mapped||void0!==b[this._id_mapped])returnthis._sub_storage.post(c);thrownewa.util.jIOError("post is not supported with id mapped",400)},j.prototype.put=function(b,c){vard=this,e=p(this,c,b);returnl(this,b,c).push(function(a){returnd._sub_storage.put(a,e)}).push(void0,function(b){if(binstanceofa.util.jIOError&&404===b.status_code)returnd._sub_storage.post(e);throwb}).push(function(){returnb})},j.prototype.remove=function(a){varb=this;returnl(this,a).push(function(a){returnb._sub_storage.remove(a)}).push(function(){returna})},j.prototype.putAttachment=function(a,b){returnq(this,arguments,"put",a).push(function(){returnb})},j.prototype.getAttachment=function(){returnq(this,arguments,"get")},j.prototype.removeAttachment=function(a,b){returnq(this,arguments,"remove",a).push(function(){returnb})},j.prototype.allAttachments=function(a){varb,c=this;returnl(c,a).push(function(a){returnb=a,c._sub_storage.allAttachments(b)}).push(function(a){vard,e={},f={};for(dinc._attachment_mapping_dict)c._attachment_mapping_dict.hasOwnProperty(d)&&(f[k(c,b,d,"get")]=d);for(dina)a.hasOwnProperty(d)&&(f.hasOwnProperty(d)?e[f[d]]={}:e[d]={});
functionparseStringToObject(a){varb=function(){vara,b,c=[],d=arguments;for(a=0;a<d.length;a+=1)for(b=0;b<d[a].length;b+=1)c.push(d[a][b]);returnc},c=function(a,b,c){vard={type:"simple",key:a,value:b};returnvoid0!==c&&(d.operator=c),d},d=function(a){return"NOT"===a.operator?a.query_list[0]:{type:"complex",operator:"NOT",query_list:[a]}},e=function(a,c){vard,e=[];for(d=0;d<c.length;d+=1)c[d].operator===a?e=b(e,c[d].query_list):e.push(c[d]);return{type:"complex",operator:a,query_list:e}},f=function(a,b){varc;if("complex"===a.type){for(c=0;c<a.query_list.length;++c)f(a.query_list[c],b);return!0}return"simple"!==a.type||a.key?!1:(a.key=b,!0)},g=function(){functiona(){this.yy={}}varb=function(a,b,c,d){for(c=c||{},d=a.length;d--;c[a[d]]=b);returnc},g=[1,5],h=[1,7],i=[1,8],j=[1,10],k=[1,12],l=[1,6,7,15],m=[1,6,7,9,12,14,15,16,19,21],n=[1,6,7,9,11,12,14,15,16,19,21],o=[2,17],p={trace:function(){},yy:{},symbols_:{error:2,begin:3,search_text:4,end:5,EOF:6,NEWLINE:7,and_expression:8,OR:9,boolean_expression:10,AND:11,NOT:12,expression:13,LEFT_PARENTHESE:14,RIGHT_PARENTHESE:15,WORD:16,DEFINITION:17,value:18,OPERATOR:19,string:20,QUOTE:21,QUOTED_STRING:22,$accept:0,$end:1},terminals_:{2:"error",6:"EOF",7:"NEWLINE",9:"OR",11:"AND",12:"NOT",14:"LEFT_PARENTHESE",15:"RIGHT_PARENTHESE",16:"WORD",17:"DEFINITION",19:"OPERATOR",21:"QUOTE",22:"QUOTED_STRING"},productions_:[0,[3,2],[5,0],[5,1],[5,1],[4,1],[4,2],[4,3],[8,1],[8,3],[10,2],[10,1],[13,3],[13,3],[13,1],[18,2],[18,1],[20,1],[20,3]],performAction:function(a,b,g,h,i,j,k){varl=j.length-1;switch(i){case1:returnj[l-1];case5:case8:case11:case14:case16:this.$=j[l];break;case6:this.$=e("OR",[j[l-1],j[l]]);break;case7:this.$=e("OR",[j[l-2],j[l]]);break;case9:this.$=e("AND",[j[l-2],j[l]]);break;case10:this.$=d(j[l]);break;case12:this.$=j[l-1];break;case13:f(j[l],j[l-2]),this.$=j[l];break;case15:j[l].operator=j[l-1],this.$=j[l];break;case17:this.$=c("",j[l]);break;case18:this.$=c("",j[l-1])}},table:[{3:1,4:2,8:3,10:4,12:g,13:6,14:h,16:i,18:9,19:j,20:11,21:k},{1:[3]},{1:[2,2],5:13,6:[1,14],7:[1,15]},b(l,[2,5],{8:3,10:4,13:6,18:9,20:11,4:16,9:[1,17],12:g,14:h,16:i,19:j,21:k}),b(m,[2,8],{11:[1,18]}),{13:19,14:h,16:i,18:9,19:j,20:11,21:k},b(n,[2,11]),{4:20,8:3,10:4,12:g,13:6,14:h,16:i,18:9,19:j,20:11,21:k},b(n,o,{17:[1,21]}),b(n,[2,14]),{16:[1,23],20:22,21:k},b(n,[2,16]),{22:[1,24]},{1:[2,1]},{1:[2,3]},{1:[2,4]},b(l,[2,6]),{4:25,8:3,10:4,12:g,13:6,14:h,16:i,18:9,19:j,20:11,21:k},{8:26,10:4,12:g,13:6,14:h,16:i,18:9,19:j,20:11,21:k},b(n,[2,10]),{15:[1,27]},{13:28,14:h,16:i,18:9,19:j,20:11,21:k},b(n,[2,15]),b(n,o),{21:[1,29]},b(l,[2,7]),b(m,[2,9]),b(n,[2,12]),b(n,[2,13]),b(n,[2,18])],defaultActions:{13:[2,1],14:[2,3],15:[2,4]},parseError:function(a,b){functionc(a,b){this.message=a,this.hash=b}if(!b.recoverable)throwc.prototype=newError,newc(a,b);this.trace(a)},parse:function(a){varb=this,c=[0],d=[null],e=[],f=this.table,g="",h=0,i=0,j=0,k=2,l=1,m=e.slice.call(arguments,1),n=Object.create(this.lexer),o={yy:{}};for(varpinthis.yy)Object.prototype.hasOwnProperty.call(this.yy,p)&&(o.yy[p]=this.yy[p]);n.setInput(a,o.yy),o.yy.lexer=n,o.yy.parser=this,"undefined"==typeofn.yylloc&&(n.yylloc={});varq=n.yylloc;e.push(q);varr=n.options&&n.options.ranges;"function"==typeofo.yy.parseError?this.parseError=o.yy.parseError:this.parseError=Object.getPrototypeOf(this).parseError;for(vars,t,u,v,w,x,y,z,A,B=function(){vara;returna=n.lex()||l,"number"!=typeofa&&(a=b.symbols_[a]||a),a},C={};;){if(u=c[c.length-1],this.defaultActions[u]?v=this.defaultActions[u]:((null===s||"undefined"==typeofs)&&(s=B()),v=f[u]&&f[u][s]),"undefined"==typeofv||!v.length||!v[0]){varD="";A=[];for(xinf[u])this.terminals_[x]&&x>k&&A.push("'"+this.terminals_[x]+"'");D=n.showPosition?"Parse error on line "+(h+1)+":\n"+n.showPosition()+"\nExpecting "+A.join(", ")+", got '"+(this.terminals_[s]||s)+"'":"Parse error on line "+(h+1)+": Unexpected "+(s==l?"end of input":"'"+(this.terminals_[s]||s)+"'"),this.parseError(D,{text:n.match,token:this.terminals_[s]||s,line:n.yylineno,loc:q,expected:A})}if(v[0]instanceofArray&&v.length>1)thrownewError("Parse Error: multiple actions possible at state: "+u+", token: "+s);switch(v[0]){case1:c.push(s),d.push(n.yytext),e.push(n.yylloc),c.push(v[1]),s=null,t?(s=t,t=null):(i=n.yyleng,g=n.yytext,h=n.yylineno,q=n.yylloc,j>0&&j--);break;case2:if(y=this.productions_[v[1]][1],C.$=d[d.length-y],C._$={first_line:e[e.length-(y||1)].first_line,last_line:e[e.length-1].last_line,first_column:e[e.length-(y||1)].first_column,last_column:e[e.length-1].last_column},r&&(C._$.range=[e[e.length-(y||1)].range[0],e[e.length-1].range[1]]),w=this.performAction.apply(C,[g,i,h,o.yy,v[1],d,e].concat(m)),"undefined"!=typeofw)returnw;y&&(c=c.slice(0,-1*y*2),d=d.slice(0,-1*y),e=e.slice(0,-1*y)),c.push(this.productions_[v[1]][0]),d.push(C.$),e.push(C._$),z=f[c[c.length-2]][c[c.length-1]],c.push(z);break;case3:return!0}}return!0}},q=function(){vara={EOF:1,parseError:function(a,b){if(!this.yy.parser)thrownewError(a);this.yy.parser.parseError(a,b)},setInput:function(a,b){returnthis.yy=b||this.yy||{},this._input=a,this._more=this._backtrack=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},input:function(){vara=this._input[0];this.yytext+=a,this.yyleng++,this.offset++,this.match+=a,this.matched+=a;varb=a.match(/(?:\r\n?|\n).*/g);returnb?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),a},unput:function(a){varb=a.length,c=a.split(/(?:\r\n?|\n)/g);this._input=a+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-b),this.offset-=b;vard=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),c.length-1&&(this.yylineno-=c.length-1);vare=this.yylloc.range;returnthis.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:c?(c.length===d.length?this.yylloc.first_column:0)+d[d.length-c.length].length-c[0].length:this.yylloc.first_column-b},this.options.ranges&&(this.yylloc.range=[e[0],e[0]+this.yyleng-b]),this.yyleng=this.yytext.length,this},more:function(){returnthis._more=!0,this},reject:function(){returnthis.options.backtrack_lexer?(this._backtrack=!0,this):this.parseError("Lexical error on line "+(this.yylineno+1)+". You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},less:function(a){this.unput(this.match.slice(a))},pastInput:function(){vara=this.matched.substr(0,this.matched.length-this.match.length);return(a.length>20?"...":"")+a.substr(-20).replace(/\n/g,"")},upcomingInput:function(){vara=this.match;returna.length<20&&(a+=this._input.substr(0,20-a.length)),(a.substr(0,20)+(a.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){vara=this.pastInput(),b=newArray(a.length+1).join("-");returna+this.upcomingInput()+"\n"+b+"^"},test_match:function(a,b){varc,d,e;if(this.options.backtrack_lexer&&(e={yylineno:this.yylineno,yylloc:{first_line:this.yylloc.first_line,last_line:this.last_line,first_column:this.yylloc.first_column,last_column:this.yylloc.last_column},yytext:this.yytext,match:this.match,matches:this.matches,matched:this.matched,yyleng:this.yyleng,offset:this.offset,_more:this._more,_input:this._input,yy:this.yy,conditionStack:this.conditionStack.slice(0),done:this.done},this.options.ranges&&(e.yylloc.range=this.yylloc.range.slice(0))),d=a[0].match(/(?:\r\n?|\n).*/g),d&&(this.yylineno+=d.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:d?d[d.length-1].length-d[d.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+a[0].length},this.yytext+=a[0],this.match+=a[0],this.matches=a,this.yyleng=this.yytext.length,this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]),this._more=!1,this._backtrack=!1,this._input=this._input.slice(a[0].length),this.matched+=a[0],c=this.performAction.call(this,this.yy,this,b,this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),c)returnc;if(this._backtrack){for(varfine)this[f]=e[f];return!1}return!1},next:function(){if(this.done)returnthis.EOF;this._input||(this.done=!0);vara,b,c,d;this._more||(this.yytext="",this.match="");for(vare=this._currentRules(),f=0;f<e.length;f++)if(c=this._input.match(this.rules[e[f]]),c&&(!b||c[0].length>b[0].length)){if(b=c,d=f,this.options.backtrack_lexer){if(a=this.test_match(c,e[f]),a!==!1)returna;if(this._backtrack){b=!1;continue}return!1}if(!this.options.flex)break}returnb?(a=this.test_match(b,e[d]),a!==!1?a:!1):""===this._input?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+". Unrecognized text.\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){vara=this.next();returna?a:this.lex()},begin:function(a){this.conditionStack.push(a)},popState:function(){vara=this.conditionStack.length-1;returna>0?this.conditionStack.pop():this.conditionStack[0]},_currentRules:function(){returnthis.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]?this.conditions[this.conditionStack[this.conditionStack.length-1]].rules:this.conditions.INITIAL.rules},topState:function(a){returna=this.conditionStack.length-1-Math.abs(a||0),a>=0?this.conditionStack[a]:"INITIAL"},pushState:function(a){this.begin(a)},stateStackSize:function(){returnthis.conditionStack.length},options:{},performAction:function(a,b,c,d){switch(c){case0:returnthis.begin("letsquote"),"QUOTE";case1:returnthis.popState(),this.begin("endquote"),"QUOTED_STRING";case2:returnthis.popState(),"QUOTE";case3:break;case4:return"LEFT_PARENTHESE";case5:return"RIGHT_PARENTHESE";case6:return"AND";case7:return"OR";case8:return"NOT";case9:return"DEFINITION";case10:return19;case11:return16;case12:return6}},rules:[/^(?:")/,/^(?:(\\"|[^"])*)/,/^(?:")/,/^(?:[^\S]+)/,/^(?:\()/,/^(?:\))/,/^(?:AND\b)/,/^(?:OR\b)/,/^(?:NOT\b)/,/^(?::)/,/^(?:(!?=|<=?|>=?))/,/^(?:[^\s\n"():><!=]+)/,/^(?:$)/],conditions:{endquote:{rules:[2],inclusive:!1},letsquote:{rules:[1],inclusive:!1},INITIAL:{rules:[0,3,4,5,6,7,8,9,10,11,12],inclusive:!0}}};returna}();returnp.lexer=q,a.prototype=p,p.Parser=a,newa}();returng.parse(a)}!function(a,b,c){"use strict";functiond(a){varb,c=[];if(void0===a)returnvoid0;for(Array.isArray(a)||(a=[a]),b=0;b<a.length;b+=1)"object"==typeofa[b]?c[b]=a[b].content:c[b]=a[b];returnc}functione(a,b){varc;if("descending"===b)c=1;else{if("ascending"!==b)thrownewTypeError("Query.sortFunction(): Argument 2 must be 'ascending' or 'descending'");c=-1}returnfunction(b,e){varf,g;for(b=d(b[a])||[],e=d(e[a])||[],g=b.length>e.length?b.length:e.length,f=0;g>f;f+=1){if(void0===b[f])returnc;if(void0===e[f])return-c;if(b[f]>e[f])return-c;if(b[f]<e[f])returnc}return0}}functionf(a,b){varc;if(!Array.isArray(a))thrownewTypeError("jioquery.sortOn(): Argument 1 is not of type 'array'");for(c=a.length-1;c>=0;c-=1)b.sort(e(a[c][0],a[c][1]));returnb}functiong(a,b){if(!Array.isArray(a))thrownewTypeError("jioquery.limit(): Argument 1 is not of type 'array'");if(!Array.isArray(b))thrownewTypeError("jioquery.limit(): Argument 2 is not of type 'array'");returnb.splice(0,a[0]),a[1]&&b.splice(a[1]),b}functionh(a,b){varc,d,e;if(!Array.isArray(a))thrownewTypeError("jioquery.select(): Argument 1 is not of type Array");if(!Array.isArray(b))thrownewTypeError("jioquery.select(): Argument 2 is not of type Array");for(c=0;c<b.length;c+=1){for(e={},d=0;d<a.length;d+=1)b[c].hasOwnProperty([a[d]])&&(e[a[d]]=b[c][a[d]]);for(dine)if(e.hasOwnProperty(d)){b[c]=e;break}}returnb}functioni(){}functionj(){}functionk(a){returna.replace(t,"\\$&")}functionl(a,b){a.super_=b,a.prototype=Object.create(b.prototype,{constructor:{configurable:!0,enumerable:!1,writable:!0,value:a}})}functionm(a,b){if("string"!=typeofa)thrownewTypeError("jioquery.searchTextToRegExp(): Argument 1 is not of type 'string'");returnb===!1?newRegExp("^"+k(a)+"$"):newRegExp("^"+k(a).replace(u,".*").replace(v,".")+"$")}functionn(a,b){i.call(this),this.operator=a.operator,this.query_list=a.query_list||[],this.query_list=this.query_list.map(function(a){returnj.create(a,b)})}functiono(a){varb=[];if("complex"===a.type)returnb.push("("),(a.query_list||[]).forEach(function(c){b.push(o(c)),b.push(a.operator)}),b.length-=1,b.push(")"),b.join("");if("simple"===a.type)return(a.key?a.key+": ":"")+(a.operator||"")+' "'+a.value+'"';thrownewTypeError("This object is not a query")}functionp(a){varb;if(void0!==a){if("object"!=typeofa)thrownewTypeError("SimpleQuery().create(): key_schema is not of type 'object'");if(void0===a.key_set)thrownewTypeError("SimpleQuery().create(): key_schema has no 'key_set' property");for(bina)if(a.hasOwnProperty(b))switch(b){case"key_set":case"cast_lookup":case"match_lookup":break;default:thrownewTypeError("SimpleQuery().create(): key_schema has unknown property '"+b+"'")}}}functionq(a,b){i.call(this),p(b),this._key_schema=b||{},this.operator=a.operator,this.key=a.key,this.value=a.value}functionr(a){varb;if(void0===a.read_from)thrownewTypeError("Custom key is missing the read_from property");for(bina)if(a.hasOwnProperty(b))switch(b){case"read_from":case"cast_to":case"equal_match":break;default:thrownewTypeError("Custom key has unknown property '"+b+"'")}}vars={},t=/[\-\[\]{}()*+?.,\\\^$|#\s]/g,u=/%/g,v=/_/g,w=/^(?:AND|OR|NOT)$/i,x=/^(?:!?=|<=?|>=?)$/i;i.prototype.exec=function(b,c){if(!Array.isArray(b))thrownewTypeError("Query().exec(): Argument 1 is not of type 'array'");if(void0===c&&(c={}),"object"!=typeofc)thrownewTypeError("Query().exec(): Optional argument 2 is not of type 'object'");vard,e=this;for(d=b.length-1;d>=0;d-=1)e.match(b[d])||b.splice(d,1);returnc.sort_on&&f(c.sort_on,b),c.limit&&g(c.limit,b),h(c.select_list||[],b),(newa.Queue).push(function(){returnb})},i.prototype.match=function(){return!0},i.prototype.parse=function(b){functionc(b,d){functionf(a){i.push(function(){returnb.parsed=h.query_list[a],c(b,d)}).push(function(){h.query_list[a]=b.parsed})}varg,h=b.parsed,i=newa.Queue;if("complex"===h.type){for(g=0;g<h.query_list.length;g+=1)f(g);returni.push(function(){returnb.parsed=h,e.onParseComplexQuery(b,d)})}return"simple"===h.type?e.onParseSimpleQuery(b,d):void0}vard,e=this;returnd={parsed:JSON.parse(JSON.stringify(e.serialized()))},(newa.Queue).push(function(){returne.onParseStart(d,b)}).push(function(){returnc(d,b)}).push(function(){returne.onParseEnd(d,b)}).push(function(){returnd.parsed})},i.prototype.toString=function(){return""},i.prototype.serialized=function(){returnvoid0},l(n,i),n.prototype.operator="AND",n.prototype.type="complex",n.prototype.match=function(a){varb=this.operator;returnw.test(b)||(b="AND"),this[b.toUpperCase()](a)},n.prototype.toString=function(){vara=[],b=this.operator;return"NOT"===this.operator?(a.push("NOT ("),a.push(this.query_list[0].toString()),a.push(")"),a.join("")):(this.query_list.forEach(function(c){a.push("("),a.push(c.toString()),a.push(")"),a.push(b)}),a.length-=1,a.join(""))},n.prototype.serialized=function(){vara={type:"complex",operator:this.operator,query_list:[]};returnthis.query_list.forEach(function(b){a.query_list.push("function"==typeofb.toJSON?b.toJSON():b)}),a},n.prototype.toJSON=n.prototype.serialized,n.prototype.AND=function(a){for(varb=!0,c=0;b&&c!==this.query_list.length;)b=this.query_list[c].match(a),c+=1;returnb},n.prototype.OR=function(a){for(varb=!1,c=0;!b&&c!==this.query_list.length;)b=this.query_list[c].match(a),c+=1;returnb},n.prototype.NOT=function(a){return!this.query_list[0].match(a)},j.create=function(a,b){if(""===a)returnnewi;if("string"==typeofa&&(a=c(a)),"string"==typeof(a||{}).type&&s[a.type])returnnews[a.type](a,b);thrownewTypeError("QueryFactory.create(): Argument 1 is not a search text or a parsable object")},l(q,i),q.prototype.type="simple",q.prototype.match=function(a){varb=null,c=null,d=null,e=null,f=this.operator,g=null,h=this.key;if(x.test(f)||(f=u.test(this.value)?"like":"="),e=this[f],this._key_schema.key_set&&void0!==this._key_schema.key_set[h]&&(h=this._key_schema.key_set[h]),"object"==typeofh){if(r(h),b=a[h.read_from],c=h.equal_match,"string"==typeofc&&(c=this._key_schema.match_lookup[c]),void0!==c&&(e="="===f||"like"===f?c:e),g=this.value,d=h.cast_to){"string"==typeofd&&(d=this._key_schema.cast_lookup[d]);try{g=d(g)}catch(i){g=void0}try{b=d(b)}catch(i){b=void0}}}elseb=a[h],g=this.value;returnvoid0===b||void0===g?!1:e(b,g)},q.prototype.toString=function(){return(this.key?this.key+":":"")+(this.operator?""+this.operator:"")+' "'+this.value+'"'},q.prototype.serialized=function(){vara={type:"simple",key:this.key,value:this.value};returnvoid0!==this.operator&&(a.operator=this.operator),a},q.prototype.toJSON=q.prototype.serialized,q.prototype["="]=function(a,b){varc,d;for(Array.isArray(a)||(a=[a]),d=0;d<a.length;d+=1){if(c=a[d],"object"==typeofc&&c.hasOwnProperty("content")&&(c=c.content),"function"==typeofc.cmp)return0===c.cmp(b);if(b.toString()===c.toString())return!0}return!1},q.prototype.like=function(a,b){varc,d;for(Array.isArray(a)||(a=[a]),d=0;d<a.length;d+=1){if(c=a[d],"object"==typeofc&&c.hasOwnProperty("content")&&(c=c.content),"function"==typeofc.cmp)return0===c.cmp(b);if(m(b.toString()).test(c.toString()))return!0}return!1},q.prototype["!="]=function(a,b){varc,d;for(Array.isArray(a)||(a=[a]),d=0;d<a.length;d+=1){if(c=a[d],"object"==typeofc&&c.hasOwnProperty("content")&&(c=c.content),"function"==typeofc.cmp)return0!==c.cmp(b);if(b.toString()===c.toString())return!1}return!0},q.prototype["<"]=function(a,b){varc;returnArray.isArray(a)||(a=[a]),c=a[0],"object"==typeofc&&c.hasOwnProperty("content")&&(c=c.content),"function"==typeofc.cmp?c.cmp(b)<0:b>c},q.prototype["<="]=function(a,b){varc;returnArray.isArray(a)||(a=[a]),c=a[0],"object"==typeofc&&c.hasOwnProperty("content")&&(c=c.content),"function"==typeofc.cmp?c.cmp(b)<=0:b>=c},q.prototype[">"]=function(a,b){varc;returnArray.isArray(a)||(a=[a]),c=a[0],"object"==typeofc&&c.hasOwnProperty("content")&&(c=c.content),"function"==typeofc.cmp?c.cmp(b)>0:c>b},q.prototype[">="]=function(a,b){varc;returnArray.isArray(a)||(a=[a]),c=a[0],"object"==typeofc&&c.hasOwnProperty("content")&&(c=c.content),"function"==typeofc.cmp?c.cmp(b)>=0:c>=b},s.simple=q,s.complex=n,i.parseStringToObject=c,i.objectToSearchText=o,b.Query=i,b.SimpleQuery=q,b.ComplexQuery=n,b.QueryFactory=j}(RSVP,window,parseStringToObject),function(a,b){"use strict";varc,d="year",e="month",f="day",g="hour",h="minute",i="second",j="millisecond",k={year:0,month:1,day:2,hour:3,minute:4,second:5,millisecond:6},l=function(a,b){returnk[a]<k[b]?a:b};c=function(a){if(!(thisinstanceofc))returnnewc(a);if(ainstanceofc)returnthis.mom=a.mom.clone(),void(this._precision=a._precision);if(void0===a)returnthis.mom=b(),voidthis.setPrecision(j);if(this.mom=null,this._str=a,a.match(/\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+\-][0-2]\d:[0-5]\d|Z)/)||a.match(/\d\d\d\d-\d\d-\d\d\d\d:\d\d:\d\d\.\d\d\d/)?(this.mom=b(a),this.setPrecision(j)):a.match(/\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+\-][0-2]\d:[0-5]\d|Z)/)||a.match(/\d\d\d\d-\d\d-\d\d\d\d:\d\d:\d\d/)?(this.mom=b(a),this.setPrecision(i)):a.match(/\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+\-][0-2]\d:[0-5]\d|Z)/)||a.match(/\d\d\d\d-\d\d-\d\d\d\d:\d\d/)?(this.mom=b(a),this.setPrecision(h)):a.match(/\d\d\d\d-\d\d-\d\d\d\d/)?(this.mom=b(a),this.setPrecision(g)):a.match(/\d\d\d\d-\d\d-\d\d/)?(this.mom=b(a),this.setPrecision(f)):a.match(/\d\d\d\d-\d\d/)?(this.mom=b(a),this.setPrecision(e)):a.match(/\d\d\d\d/)&&(this.mom=b(a,"YYYY"),this.setPrecision(d)),!this.mom)thrownewError("Cannot parse: "+a)},c.prototype.setPrecision=function(a){this._precision=a},c.prototype.getPrecision=function(){returnthis._precision},c.prototype.cmp=function(a){varb=this.mom,c=a.mom,d=l(this._precision,a._precision);returnb.isBefore(c,d)?-1:b.isSame(c,d)?0:1},c.prototype.toPrecisionString=function(a){varb;if(a=a||this._precision,b={millisecond:"YYYY-MM-DD HH:mm:ss.SSS",second:"YYYY-MM-DD HH:mm:ss",minute:"YYYY-MM-DD HH:mm",hour:"YYYY-MM-DD HH",day:"YYYY-MM-DD",month:"YYYY-MM",year:"YYYY"}[a],!b)thrownewTypeError("Unsupported precision value '"+a+"'");returnthis.mom.format(b)},c.prototype.toString=function(){returnthis._str},a.jiodate={JIODate:c,YEAR:d,MONTH:e,DAY:f,HOUR:g,MIN:h,SEC:i,MSEC:j}}(window,moment),function(a,b,c,d,e,f,g,h,i,j){"use strict";functionk(a,b){if(void0!==a&&"string"!=typeofa)thrownewTypeError("You must pass a string.");this.message=a||"Default Message",this.status_code=b||500}functionl(a){varc=newXMLHttpRequest;returnnewb.Promise(function(b,d,e){varf,g=newStreamBuffers.WritableStreamBuffer;if(c.open(a.type||"GET",a.url,!0),c.responseType=a.dataType||"","object"==typeofa.headers&&null!==a.headers)for(fina.headers)a.headers.hasOwnProperty(f)&&c.setRequestHeader(f,a.headers[f]);if(c.setRequestHeader("Accept","*/*"),c.addEventListener("load",function(a){returna.target.status>=400?d(a):voidb(a)}),c.addEventListener("error",d),c.addEventListener("progress",e),"object"==typeofa.xhrFields&&null!==a.xhrFields)for(fina.xhrFields)a.xhrFields.hasOwnProperty(f)&&(c[f]=a.xhrFields[f]);"function"==typeofa.beforeSend&&a.beforeSend(c),a.datainstanceofFormData?(c.setRequestHeader("Content-Type","multipart/form-data; boundary="+a.data.getBoundary()),a.data.pipe(g),c.send(g.getContents())):c.send(a.data)},function(){c.abort()})}functionm(a,c){vard=newg;returnnewb.Promise(function(b,e,f){d.addEventListener("load",b),d.addEventListener("error",e),d.addEventListener("progress",f),d.readAsText(a,c)},function(){d.abort()})}functionn(a){varc=newg;returnnewb.Promise(function(b,d,e){c.addEventListener("load",b),c.addEventListener("error",d),c.addEventListener("progress",e),c.readAsArrayBuffer(a)},function(){c.abort()})}functiono(a){varc=newg;returnnewb.Promise(function(b,d,e){c.addEventListener("load",b),c.addEventListener("error",d),c.addEventListener("progress",e),c.readAsDataURL(a)},function(){c.abort()})}functionp(a){varb,c,d,e,f;if(void0===a)returnvoid0;if(a.constructor===Object){for(c=Object.keys(a).sort(),f=[],d=0;d<c.length;d+=1)b=c[d],e=p(a[b]),void0!==e&&f.push(p(b)+":"+e);return"{"+f.join(",")+"}"}if(a.constructor===Array){for(f=[],d=0;d<a.length;d+=1)f.push(p(a[d]));return"["+f.join(",")+"]"}returnJSON.stringify(a)}functionq(a){if("data:"===a)returnnewc;varb,d=f(a.split(",")[1]),e=a.split(",")[0].split(":")[1],g=newh(d.length),j=newi(g);for(e=e.slice(0,e.length-";base64".length),b=0;b<d.length;b+=1)j[b]=d.charCodeAt(b);returnnewc([g],{type:e})}functionr(a,b,c){if("string"!=typeofa[0]||""===a[0])throwneww.util.jIOError("Document id must be a non empty string on '"+b.__type+"."+c+"'.",400)}functions(a,b,c){if("string"!=typeofa[1]||""===a[1])throwneww.util.jIOError("Attachment id must be a non empty string on '"+b.__type+"."+c+"'.",400)}functiont(a,c,d,e){returna.prototype[c]=function(){vara,f=arguments,g=this;return(newb.Queue).push(function(){returnvoid0!==d?d.apply(g.__storage,[f,g,c]):void0}).push(function(b){vard=g.__storage[c];if(a=b,void0===d)throwneww.util.jIOError("Capacity '"+c+"' is not implemented on '"+g.__type+"'",501);returnd.apply(g.__storage,f)}).push(function(b){returnvoid0!==e?e.call(g,f,b,a):b})},this}functionu(a,b){returnthisinstanceofu?(this.__type=a,void(this.__storage=b)):newu}functionv(){returnthisinstanceofv?void(this.__storage_types={}):newv}void0===a.openDatabase&&(a.openDatabase=function(){thrownewError("WebSQL is not supported by "+j.userAgent)});varw,x={};k.prototype=newError,k.prototype.constructor=k,x.jIOError=k,x.ajax=l,x.readBlobAsText=m,x.readBlobAsArrayBuffer=n,x.readBlobAsDataURL=o,x.stringify=p,x.dataURItoBlob=q,t(u,"put",r,function(a){returna[0]}),t(u,"get",r),t(u,"bulk"),t(u,"remove",r,function(a){returna[0]}),u.prototype.post=function(){vara=this,c=arguments;return(newb.Queue).push(function(){varb=a.__storage.post;if(void0===b)throwneww.util.jIOError("Capacity 'post' is not implemented on '"+a.__type+"'",501);returna.__storage.post.apply(a.__storage,c)})},t(u,"putAttachment",function(a,b,d){r(a,b,d),s(a,b,d);vare=a[3]||{};if("string"==typeofa[2])a[2]=newc([a[2]],{type:e._content_type||e._mimetype||"text/plain;charset=utf-8"});elseif(!(a[2]instanceofc))throwneww.util.jIOError("Attachment content is not a blob",400)}),t(u,"removeAttachment",function(a,b,c){r(a,b,c),s(a,b,c)}),t(u,"getAttachment",function(a,b,c){vard="blob";returnr(a,b,c),s(a,b,c),void0!==a[2]&&(d=a[2].format||d,deletea[2].format),d},function(a,d,e){varf;if(!(dinstanceofc))throwneww.util.jIOError("'getAttachment' ("+a[0]+" , "+a[1]+") on '"+this.__type+"' does not return a Blob.",501);if("blob"===e)f=d;elseif("data_url"===e)f=(newb.Queue).push(function(){returnw.util.readBlobAsDataURL(d)}).push(function(a){returna.target.result});elseif("array_buffer"===e)f=(newb.Queue).push(function(){returnw.util.readBlobAsArrayBuffer(d)}).push(function(a){returna.target.result});elseif("text"===e)f=(newb.Queue).push(function(){returnw.util.readBlobAsText(d)}).push(function(a){returna.target.result});else{if("json"!==e)throwneww.util.jIOError(this.__type+".getAttachment format: '"+e+"' is not supported",400);f=(newb.Queue).push(function(){returnw.util.readBlobAsText(d)}).push(function(a){returnJSON.parse(a.target.result)})}returnf}),u.prototype.buildQuery=function(){vara=this.__storage.buildQuery,c=this,d=arguments;if(void0===a)throwneww.util.jIOError("Capacity 'buildQuery' is not implemented on '"+this.__type+"'",501);return(newb.Queue).push(function(){returna.apply(c.__storage,d)})},u.prototype.hasCapacity=function(a){varb=this.__storage.hasCapacity,c=this.__storage[a];if(void0!==c)return!0;if(void0===b||!b.apply(this.__storage,arguments))throwneww.util.jIOError("Capacity '"+a+"' is not implemented on '"+this.__type+"'",501);return!0},u.prototype.allDocs=function(a){varc=this;returnvoid0===a&&(a={}),(newb.Queue).push(function(){return!c.hasCapacity("list")||void0!==a.query&&!c.hasCapacity("query")||void0!==a.sort_on&&!c.hasCapacity("sort")||void0!==a.select_list&&!c.hasCapacity("select")||void0!==a.include_docs&&!c.hasCapacity("include")||void0!==a.limit&&!c.hasCapacity("limit")?void0:c.buildQuery(a)}).push(function(a){return{data:{rows:a,total_rows:a.length}}})},t(u,"allAttachments",r),t(u,"repair"),u.prototype.repair=function(){vara=this,c=arguments;return(newb.Queue).push(function(){varb=a.__storage.repair;returnvoid0!==b?a.__storage.repair.apply(a.__storage,c):void0})},v.prototype.createJIO=function(a,b){if("string"!=typeofa.type)thrownewTypeError("Invalid storage description");if(!this.__storage_types[a.type])thrownewTypeError("Unknown storage '"+a.type+"'");returnnewu(a.type,newthis.__storage_types[a.type](a,b))},v.prototype.addStorage=function(a,b){if("string"!=typeofa)thrownewTypeError("jIO.addStorage(): Argument 1 is not of type 'string'");if("function"!=typeofb)thrownewTypeError("jIO.addStorage(): Argument 2 is not of type 'function'");if(void0!==this.__storage_types[a])thrownewTypeError("jIO.addStorage(): Storage type already exists");this.__storage_types[a]=b},v.prototype.util=x,v.prototype.QueryFactory=d,v.prototype.Query=e,w=newv,a.jIO=w}(window,RSVP,Blob,QueryFactory,Query,atob,FileReader,ArrayBuffer,Uint8Array,navigator),function(a,b,c,d){"use strict";functione(a){returnh.digestFromString(a)}functionf(a){returnh.digestFromArrayBuffer(a)}functiong(b){if(this._query_options=b.query||{},this._local_sub_storage=a.createJIO(b.local_sub_storage),this._remote_sub_storage=a.createJIO(b.remote_sub_storage),this._signature_hash="_replicate_"+e(d(b.local_sub_storage)+d(b.remote_sub_storage)+d(this._query_options)),this._signature_sub_storage=a.createJIO({type:"document",document_id:this._signature_hash,sub_storage:b.signature_storage||b.local_sub_storage}),this._use_remote_post=b.use_remote_post||!1,this._conflict_handling=b.conflict_handling||0,this._conflict_handling!==i&&this._conflict_handling!==j&&this._conflict_handling!==k&&this._conflict_handling!==l)thrownewa.util.jIOError("Unsupported conflict handling: "+this._conflict_handling,400);this._check_local_modification=b.check_local_modification,void0===this._check_local_modification&&(this._check_local_modification=!0),this._check_local_creation=b.check_local_creation,void0===this._check_local_creation&&(this._check_local_creation=!0),this._check_local_deletion=b.check_local_deletion,void0===this._check_local_deletion&&(this._check_local_deletion=!0),this._check_remote_modification=b.check_remote_modification,void0===this._check_remote_modification&&(this._check_remote_modification=!0),this._check_remote_creation=b.check_remote_creation,void0===this._check_remote_creation&&(this._check_remote_creation=!0),this._check_remote_deletion=b.check_remote_deletion,void0===this._check_remote_deletion&&(this._check_remote_deletion=!0),this._check_local_attachment_modification=b.check_local_attachment_modification,void0===this._check_local_attachment_modification&&(this._check_local_attachment_modification=!1),this._check_local_attachment_creation=b.check_local_attachment_creation,void0===this._check_local_attachment_creation&&(this._check_local_attachment_creation=!1),this._check_local_attachment_deletion=b.check_local_attachment_deletion,void0===this._check_local_attachment_deletion&&(this._check_local_attachment_deletion=!1),this._check_remote_attachment_modification=b.check_remote_attachment_modification,void0===this._check_remote_attachment_modification&&(this._check_remote_attachment_modification=!1),this._check_remote_attachment_creation=b.check_remote_attachment_creation,void0===this._check_remote_attachment_creation&&(this._check_remote_attachment_creation=!1),this._check_remote_attachment_deletion=b.check_remote_attachment_deletion,void0===this._check_remote_attachment_deletion&&(this._check_remote_attachment_deletion=!1)}varh=newc,i=0,j=1,k=2,l=3;g.prototype.remove=function(b){if(b===this._signature_hash)thrownewa.util.jIOError(this._signature_hash+" is frozen",403);returnthis._local_sub_storage.remove.apply(this._local_sub_storage,arguments)},g.prototype.post=function(){returnthis._local_sub_storage.post.apply(this._local_sub_storage,arguments)},g.prototype.put=function(b){if(b===this._signature_hash)thrownewa.util.jIOError(this._signature_hash+" is frozen",403);returnthis._local_sub_storage.put.apply(this._local_sub_storage,arguments)},g.prototype.get=function(){returnthis._local_sub_storage.get.apply(this._local_sub_storage,arguments)},g.prototype.getAttachment=function(){returnthis._local_sub_storage.getAttachment.apply(this._local_sub_storage,arguments)},g.prototype.allAttachments=function(){returnthis._local_sub_storage.allAttachments.apply(this._local_sub_storage,arguments)},g.prototype.putAttachment=function(b){if(b===this._signature_hash)thrownewa.util.jIOError(this._signature_hash+" is frozen",403);returnthis._local_sub_storage.putAttachment.apply(this._local_sub_storage,arguments)},g.prototype.removeAttachment=function(b){if(b===this._signature_hash)thrownewa.util.jIOError(this._signature_hash+" is frozen",403);returnthis._local_sub_storage.removeAttachment.apply(this._local_sub_storage,arguments)},g.prototype.hasCapacity=function(){returnthis._local_sub_storage.hasCapacity.apply(this._local_sub_storage,arguments);
},g.prototype.buildQuery=function(){returnthis._local_sub_storage.buildQuery.apply(this._local_sub_storage,arguments)},g.prototype.repair=function(){functionc(a,b,c,d){returnb.removeAttachment(c,d).push(function(){returnw._signature_sub_storage.removeAttachment(c,d)}).push(function(){a[d]=null})}functiong(a,b,c,d,e,f){returnb.putAttachment(e,f,c).push(function(){returnw._signature_sub_storage.putAttachment(e,f,JSON.stringify({hash:d}))}).push(function(){a[f]=null})}functionh(b,d,e,h,i,j,k,l,m,n,o){varp;returnj.getAttachment(k,l).push(function(b){returnp=b,a.util.readBlobAsArrayBuffer(p)}).push(function(a){returnf(a.target.result)},function(b){if(binstanceofa.util.jIOError&&404===b.status_code)returnp=null,null;throwb}).push(function(f){if(e===f)returnnull===e?w._signature_sub_storage.removeAttachment(k,l).push(function(){b[k]=null}):w._signature_sub_storage.putAttachment(k,l,JSON.stringify({hash:e})).push(function(){y[k]=null});if(f===d||m===!0)returnnull===e?c(b,j,k,l):g(b,j,h,e,k,l);if(o!==!0){if(n===!0||null===e)returnnull===f?c(b,i,k,l):g(b,i,p,f,k,l);if(null===f)returng(b,j,h,e,k,l);thrownewa.util.jIOError("Conflict on '"+k+"' with attachment '"+l+"'",409)}})}functioni(c,d,e,g,i,j,k,l,m,n,o){varp,q;d.push(function(){if(n===!0)returnb.all([e.getAttachment(i,j),{hash:null}]);if(o===!0)returnb.all([e.getAttachment(i,j),w._signature_sub_storage.getAttachment(i,j,{format:"json"})]);thrownewa.util.jIOError("Unexpected call of checkAttachmentSignatureDifference",409)}).push(function(b){returnp=b[0],q=b[1].hash,a.util.readBlobAsArrayBuffer(p)}).push(function(a){varb=a.target.result,d=f(b);returnd!==q?h(c,q,d,p,e,g,i,j,k,l,m):void0})}functionm(a,b,c,d,e,f,g,i,j){vark;b.push(function(){returnw._signature_sub_storage.getAttachment(d,e,{format:"json"})}).push(function(b){returnk=b.hash,h(a,k,null,null,f,c,d,e,g,i,j)})}functionn(c,d,e,f,g){varh=newb.Queue;returnh.push(function(){returnb.all([e.allAttachments(d).push(void0,function(b){if(binstanceofa.util.jIOError&&404===b.status_code)return{};throwb}),w._signature_sub_storage.allAttachments(d).push(void0,function(b){if(binstanceofa.util.jIOError&&404===b.status_code)return{};throwb})])}).push(function(a){varb,j,k,l={},n={};for(kina[0])a[0].hasOwnProperty(k)&&(c.hasOwnProperty(k)||(l[k]=null));for(kina[1])a[1].hasOwnProperty(k)&&(c.hasOwnProperty(k)||(n[k]=null));for(kinl)l.hasOwnProperty(k)&&(b=n.hasOwnProperty(k)&&g.check_modification,j=!n.hasOwnProperty(k)&&g.check_creation,(b===!0||j===!0)&&i(c,h,e,f,d,k,g.conflict_force,g.conflict_revert,g.conflict_ignore,j,b));if(g.check_deletion===!0)for(kinn)n.hasOwnProperty(k)&&(l.hasOwnProperty(k)||m(c,h,f,d,k,e,g.conflict_force,g.conflict_revert,g.conflict_ignore))})}functiono(a){varc={};return(newb.Queue).push(function(){returnw._check_local_attachment_modification||w._check_local_attachment_creation||w._check_local_attachment_deletion?n(c,a,w._local_sub_storage,w._remote_sub_storage,{conflict_force:w._conflict_handling===j,conflict_revert:w._conflict_handling===k,conflict_ignore:w._conflict_handling===l,check_modification:w._check_local_attachment_modification,check_creation:w._check_local_attachment_creation,check_deletion:w._check_local_attachment_deletion}):void0}).push(function(){returnw._check_remote_attachment_modification||w._check_remote_attachment_creation||w._check_remote_attachment_deletion?n(c,a,w._remote_sub_storage,w._local_sub_storage,{use_revert_post:w._use_remote_post,conflict_force:w._conflict_handling===k,conflict_revert:w._conflict_handling===j,conflict_ignore:w._conflict_handling===l,check_modification:w._check_remote_attachment_modification,check_creation:w._check_remote_attachment_creation,check_deletion:w._check_remote_attachment_deletion}):void0})}functionp(a,c,d,e,f,g){varh,i,j=!0;returnvoid0===g&&(g={}),h=g.use_post?c.post(d).push(function(b){returnj=!1,i=b,a.put(i,d)}).push(function(){returna.allAttachments(f)}).push(function(c){functiond(b){g.push(function(){returna.getAttachment(f,b)}).push(function(c){returna.putAttachment(i,b,c)})}vare,g=newb.Queue;for(einc)c.hasOwnProperty(e)&&d(e);returng}).push(function(){returna.remove(f)}).push(function(){returnw._signature_sub_storage.remove(f)}).push(function(){returnj=!0,w._signature_sub_storage.put(i,{hash:e})}).push(function(){y[i]=null}):c.put(f,d).push(function(){returnw._signature_sub_storage.put(f,{hash:e})}),h.push(function(){j&&(y[f]=null)})}functionq(b,c){returno(c).push(function(){returnb.allAttachments(c)}).push(function(a){return"{}"===JSON.stringify(a)?b.remove(c).push(function(){returnw._signature_sub_storage.remove(c)}):void0},function(b){if(!(binstanceofa.util.jIOError&&404===b.status_code))throwb}).push(function(){y[c]=null})}functionr(b,c,f,g,h,i,j,k,l,m){returnh.get(i).push(function(a){return[a,e(d(a))]},function(b){if(binstanceofa.util.jIOError&&404===b.status_code)return[null,null];throwb}).push(function(e){varn=e[0],o=e[1];if(c===o)returnnull===c?w._signature_sub_storage.remove(i).push(function(){y[i]=null}):w._signature_sub_storage.put(i,{hash:c}).push(function(){y[i]=null});if(o===b||j===!0)returnnull===c?q(h,i):p(g,h,f,c,i,{use_post:m.use_post&&null===o});if(l!==!0){if(k===!0||null===c)returnnull===o?q(g,i):p(h,g,n,o,i,{use_post:m.use_revert_post&&null===c});if(null===o)returnp(g,h,f,c,i,{use_post:m.use_post});thrownewa.util.jIOError("Conflict on '"+i+"': "+d(f||"")+" !== "+d(n||""),409)}})}functions(a,b,c,d,e,f,g,h){vari;a.push(function(){returnw._signature_sub_storage.get(c)}).push(function(a){returni=a.hash,r(i,null,null,d,b,c,e,f,g,h)})}functiont(c,f,g,h,i,j,k,l,m,n,o){c.push(function(){if(l===!0)returnb.all([n(h),{hash:null}]);if(m===!0)returnb.all([n(h),w._signature_sub_storage.get(h)]);thrownewa.util.jIOError("Unexpected call of checkSignatureDifference",409)}).push(function(a){varb=a[0],c=e(d(b)),l=a[1].hash;returnc!==l?r(l,c,b,f,g,h,i,j,k,o):void0})}functionu(a,c,d,e,f,g,h,i,j){a.push(function(){returnc.bulk(e)}).push(function(a){functionk(b){returnfunction(c){if(c!==e[b].parameter_list[0])thrownewError("Does not access expected ID "+c);returna[b]}}varl,m=newb.Queue;for(l=0;l<a.length;l+=1)t(m,c,d,e[l].parameter_list[0],h,i,j,f[l].is_creation,f[l].is_modification,k(l),g);returnm})}functionv(a,c,d){vare=newb.Queue;returnd.hasOwnProperty("use_post")||(d.use_post=!1),d.hasOwnProperty("use_revert_post")||(d.use_revert_post=!1),e.push(function(){returnb.all([a.allDocs(w._query_options),w._signature_sub_storage.allDocs()])}).push(function(b){varf,g,h,i,j={},k=[],l=[],m={};for(f=0;f<b[0].data.total_rows;f+=1)y.hasOwnProperty(b[0].data.rows[f].id)||(j[b[0].data.rows[f].id]=f);for(f=0;f<b[1].data.total_rows;f+=1)y.hasOwnProperty(b[1].data.rows[f].id)||(m[b[1].data.rows[f].id]=f);for(iinj)j.hasOwnProperty(i)&&(g=m.hasOwnProperty(i)&&d.check_modification,h=!m.hasOwnProperty(i)&&d.check_creation,(g===!0||h===!0)&&(d.use_bulk_get===!0?(k.push({method:"get",parameter_list:[i]}),l.push({is_creation:h,is_modification:g})):t(e,a,c,i,d.conflict_force,d.conflict_revert,d.conflict_ignore,h,g,a.get.bind(a),d)));if(d.check_deletion===!0)for(iinm)m.hasOwnProperty(i)&&(j.hasOwnProperty(i)||s(e,c,i,a,d.conflict_force,d.conflict_revert,d.conflict_ignore,d));d.use_bulk_get===!0&&0!==k.length&&u(e,a,c,k,l,d,d.conflict_force,d.conflict_revert,d.conflict_ignore)})}varw=this,x=arguments,y={};returny[w._signature_hash]=null,(newb.Queue).push(function(){returnw._signature_sub_storage.__storage._sub_storage.get(w._signature_hash)}).push(void0,function(b){if(binstanceofa.util.jIOError&&404===b.status_code)returnw._signature_sub_storage.__storage._sub_storage.put(w._signature_hash,{});throwb}).push(function(){returnb.all([w._local_sub_storage.repair.apply(w._local_sub_storage,x),w._remote_sub_storage.repair.apply(w._remote_sub_storage,x)])}).push(function(){returnw._check_local_modification||w._check_local_creation||w._check_local_deletion?v(w._local_sub_storage,w._remote_sub_storage,{use_post:w._use_remote_post,conflict_force:w._conflict_handling===j,conflict_revert:w._conflict_handling===k,conflict_ignore:w._conflict_handling===l,check_modification:w._check_local_modification,check_creation:w._check_local_creation,check_deletion:w._check_local_deletion}):void0}).push(function(){varb=!1;try{b=w._remote_sub_storage.hasCapacity("bulk_get")}catch(c){if(!(cinstanceofa.util.jIOError&&501===c.status_code))throwc}returnw._check_remote_modification||w._check_remote_creation||w._check_remote_deletion?v(w._remote_sub_storage,w._local_sub_storage,{use_bulk_get:b,use_revert_post:w._use_remote_post,conflict_force:w._conflict_handling===k,conflict_revert:w._conflict_handling===j,conflict_ignore:w._conflict_handling===l,check_modification:w._check_remote_modification,check_creation:w._check_remote_creation,check_deletion:w._check_remote_deletion}):void0}).push(function(){returnw._check_local_attachment_modification||w._check_local_attachment_creation||w._check_local_attachment_deletion||w._check_remote_attachment_modification||w._check_remote_attachment_creation||w._check_remote_attachment_deletion?w._signature_sub_storage.allDocs().push(function(a){functionc(a){e.push(function(){returno(a)})}vard,e=newb.Queue;for(d=0;d<a.data.total_rows;d+=1)c(a.data.rows[d].id);returne}):void0})},a.addStorage("replicate",g)}(jIO,RSVP,Rusha,jIO.util.stringify),function(a){"use strict";functionb(b){this._sub_storage=a.createJIO(b.sub_storage)}b.prototype.get=function(){returnthis._sub_storage.get.apply(this._sub_storage,arguments)},b.prototype.allAttachments=function(){returnthis._sub_storage.allAttachments.apply(this._sub_storage,arguments)},b.prototype.post=function(a){functionb(){return("0000"+Math.floor(65536*Math.random()).toString(16)).slice(-4)}varc=b()+b()+"-"+b()+"-"+b()+"-"+b()+"-"+b()+b()+b();returnthis.put(c,a)},b.prototype.put=function(){returnthis._sub_storage.put.apply(this._sub_storage,arguments)},b.prototype.remove=function(){returnthis._sub_storage.remove.apply(this._sub_storage,arguments)},b.prototype.getAttachment=function(){returnthis._sub_storage.getAttachment.apply(this._sub_storage,arguments)},b.prototype.putAttachment=function(){returnthis._sub_storage.putAttachment.apply(this._sub_storage,arguments)},b.prototype.removeAttachment=function(){returnthis._sub_storage.removeAttachment.apply(this._sub_storage,arguments)},b.prototype.repair=function(){returnthis._sub_storage.repair.apply(this._sub_storage,arguments)},b.prototype.hasCapacity=function(a){returnthis._sub_storage.hasCapacity(a)},b.prototype.buildQuery=function(){returnthis._sub_storage.buildQuery.apply(this._sub_storage,arguments)},a.addStorage("uuid",b)}(jIO),function(a,b,c){"use strict";functiond(){this._database={}}d.prototype.put=function(a,c){returnthis._database.hasOwnProperty(a)||(this._database[a]={attachments:{}}),this._database[a].doc=b.stringify(c),a},d.prototype.get=function(c){try{returnb.parse(this._database[c].doc)}catch(d){if(dinstanceofTypeError)thrownewa.util.jIOError("Cannot find document: "+c,404);throwd}},d.prototype.allAttachments=function(b){varc,d={};try{for(cinthis._database[b].attachments)this._database[b].attachments.hasOwnProperty(c)&&(d[c]={})}catch(e){if(einstanceofTypeError)thrownewa.util.jIOError("Cannot find document: "+b,404);throwe}returnd},d.prototype.remove=function(a){returndeletethis._database[a],a},d.prototype.getAttachment=function(b,c){try{vard=this._database[b].attachments[c];if(void0===d)thrownewa.util.jIOError("Cannot find attachment: "+b+" , "+c,404);returna.util.dataURItoBlob(d)}catch(e){if(einstanceofTypeError)thrownewa.util.jIOError("Cannot find attachment: "+b+" , "+c,404);throwe}},d.prototype.putAttachment=function(b,d,e){varf;try{f=this._database[b].attachments}catch(g){if(ginstanceofTypeError)thrownewa.util.jIOError("Cannot find document: "+b,404);throwg}return(newc.Queue).push(function(){returna.util.readBlobAsDataURL(e)}).push(function(a){f[d]=a.target.result})},d.prototype.removeAttachment=function(b,c){try{deletethis._database[b].attachments[c]}catch(d){if(dinstanceofTypeError)thrownewa.util.jIOError("Cannot find document: "+b,404);throwd}},d.prototype.hasCapacity=function(a){return"list"===a||"include"===a},d.prototype.buildQuery=function(a){varc,d=[];for(cinthis._database)this._database.hasOwnProperty(c)&&(a.include_docs===!0?d.push({id:c,value:{},doc:b.parse(this._database[c].doc)}):d.push({id:c,value:{}}));returnd},a.addStorage("memory",d)}(jIO,JSON,RSVP),function(a,b,c,d,e,f,g,h){"use strict";functioni(b){return(newd.Queue).push(function(){returna.util.ajax({type:"GET",url:b._url,xhrFields:{withCredentials:b._thisCredentials},headers:b._headers})}).push(function(a){returnJSON.parse(a.target.responseText)})}functionj(c,e,f){returnvoid0===f&&(f={}),i(c).push(function(g){return(newd.Queue).push(function(){returna.util.ajax({type:"GET",url:b.parse(g._links.traverse.href).expand({relative_url:e,view:f._view}),xhrFields:{withCredentials:c._thisCredentials},headers:c._headers})}).push(void0,function(b){if(void0!==b.target&&404===b.target.status)thrownewa.util.jIOError("Cannot find document: "+e,404);throwb})})}functionk(a){return(newd.Queue).push(function(){varb,c,d,f,g=a._embedded._view,h={portal_type:a._links.type.name},i={};a._links.hasOwnProperty("parent")&&(h.parent_relative_url=newe(a._links.parent.href).segment(2)),i.form_id={key:[g.form_id.key],"default":g.form_id["default"]};for(cing)g.hasOwnProperty(c)&&(b=g[c],d=0,0===c.indexOf("my_")&&b.editable&&(d=3),0===c.indexOf("your_")&&(d=5),0!==d&&q.hasOwnProperty(b.type)&&(i[c.substring(d)]={"default":b["default"],key:b.key},h[c.substring(d)]=b["default"]));returnf={data:h,form_data:i},g.hasOwnProperty("_actions")&&g._actions.hasOwnProperty("put")&&(f.action_href=g._actions.put.href),f})}functionl(b,c){returnb.getAttachment(c,"view").push(function(b){returna.util.readBlobAsText(b)}).push(function(a){returnJSON.parse(a.target.result)}).push(function(a){returnk(a)})}functionm(a){if("string"!=typeofa.url||!a.url)thrownewTypeError("ERP5 'url' must be a string which contains more than one character.");this._url=a.url,this._default_view_reference=a.default_view_reference,this._headers=null,this._thisCredentials=!0,void0!==a.login&&void0!==a.password&&(this._headers={Authorization:"Basic "+btoa(a.login+":"+a.password)},this._thisCredentials=!1)}functionn(a){returna.data}functiono(a){returnainstanceofg&&"local_roles"===a.key?a.value:void0}functionp(a){varb,c,d=!0,e=[];if(ainstanceofh&&"OR"===a.operator){for(b=0;b<a.query_list.length;b+=1)c=a.query_list[b],cinstanceofg&&"local_roles"===c.key?e.push(c.value):d=!1;if(d)returne}}varq={StringField:null,EmailField:null,IntegerField:null,FloatField:null,TextAreaField:null};m.prototype.get=function(a){returnl(this,a).push(function(a){returnn(a)})},m.prototype.bulk=function(b){vare,f=this,g=[];for(e=0;e<b.length;e+=1){if("get"!==b[e].method)thrownewError("ERP5Storage: not supported "+b[e].method+" in bulk");g.push({relative_url:b[e].parameter_list[0],view:f._default_view_reference})}returni(f).push(function(b){vard=newc;returnd.append("bulk_list",JSON.stringify(g)),a.util.ajax({type:"POST",url:b._actions.bulk.href,data:d,xhrFields:{withCredentials:f._thisCredentials},headers:f._headers})}).push(function(a){functionb(a){returnk(a).push(function(a){returnn(a)})}varc=[],f=JSON.parse(a.target.responseText);for(e=0;e<f.result_list.length;e+=1)c.push(b(f.result_list[e]));returnd.all(c)})},m.prototype.post=function(b){vard,f=this;returni(this).push(function(d){vare=newc;returne.append("portal_type",b.portal_type),e.append("parent_relative_url",b.parent_relative_url),a.util.ajax({type:"POST",url:d._actions.add.href,data:e,xhrFields:{withCredentials:f._thisCredentials},headers:f._headers})}).push(function(a){varc=a.target.getResponseHeader("X-Location"),g=newe(c);returnd=g.segment(2),f.put(d,b)}).push(function(){returnd})},m.prototype.put=function(b,c){vard=this;returnl(d,b).push(function(e){varg,h=e.form_data,i={};i[h.form_id.key]=h.form_id["default"];for(ginc)if(c.hasOwnProperty(g)){if("form_id"===g)thrownewa.util.jIOError("ERP5: forbidden property: "+g,400);if("portal_type"!==g&&"parent_relative_url"!==g){if(!h.hasOwnProperty(g))thrownewa.util.jIOError("ERP5: can not store property: "+g,400);i[h[g].key]=c[g]}}if(!e.hasOwnProperty("action_href"))thrownewa.util.jIOError("ERP5: can not modify document: "+b,403);returnd.putAttachment(b,e.action_href,newf([JSON.stringify(i)],{type:"application/json"}))})},m.prototype.allAttachments=function(a){varb=this;returnj(this,a).push(function(){returnvoid0===b._default_view_reference?{links:{}}:{view:{},links:{}}})},m.prototype.getAttachment=function(b,c,e){varg=this;if(void0===e&&(e={}),"view"===c){if(void0===this._default_view_reference)thrownewa.util.jIOError("Cannot find attachment view for: "+b,404);returnj(this,b,{_view:this._default_view_reference}).push(function(a){varb=JSON.parse(a.target.responseText);returnnewf([JSON.stringify(b)],{type:"application/hal+json"})})}if("links"===c)returnj(this,b).push(function(a){returnnewf([JSON.stringify(JSON.parse(a.target.responseText))],{type:"application/hal+json"})});if(0===c.indexOf(this._url))return(newd.Queue).push(function(){varb,d,f,h={type:"GET",dataType:"blob",url:c,xhrFields:{withCredentials:g._thisCredentials},headers:g._headers};if(void0!==e.start||void0!==e.end){if(b=e.start||0,d=e.end,void0!==d&&0>d)thrownewa.util.jIOError("end must be positive",400);if(0>b)f="bytes="+b;elseif(void0===d)f="bytes="+b+"-";else{if(b>d)thrownewa.util.jIOError("start is greater than end",400);f="bytes="+b+"-"+d}void0===g._headers?h.headers={Range:f}:h.headers.Range=f}returna.util.ajax(h)}).push(function(a){returnvoid0===a.target.response?newf([a.target.responseText],{type:a.target.getResponseHeader("Content-Type")}):a.target.response});thrownewa.util.jIOError("ERP5: not support get attachment: "+c,400)},m.prototype.putAttachment=function(b,e,f){varg=this;if(0!==e.indexOf(this._url))thrownewa.util.jIOError("Can not store outside ERP5: "+e,400);return(newd.Queue).push(function(){returna.util.readBlobAsText(f)}).push(function(b){vard,f,h,i,j=JSON.parse(b.target.result),k=newc;for(hinj)if(j.hasOwnProperty(h))for(d=Array.isArray(j[h])?j[h]:[j[h]],f=0;f<d.length;f+=1)i=d[f],"object"==typeofi?k.append(h,a.util.dataURItoBlob(i.url),i.file_name):k.append(h,i);returna.util.ajax({type:"POST",url:e,data:k,xhrFields:{withCredentials:g._thisCredentials},headers:g._headers})})},m.prototype.hasCapacity=function(a){return"list"===a||"query"===a||"select"===a||"limit"===a||"sort"===a||"bulk_get"===a},m.prototype.buildQuery=function(c){vard=this;returni(this).push(function(e){varf,g,i,j,k,l=c.query,m=[];if(c.query)if(g=a.QueryFactory.create(c.query),j=o(g))l=void0,k=j;elseif(j=p(g))l=void0,k=j;elseif(ginstanceofh&&"AND"===g.operator)for(f=0;f<g.query_list.length;f+=1)i=g.query_list[f],j=o(i),j?(k=j,g.query_list.splice(f,1),l=a.Query.objectToSearchText(g),f=g.query_list.length):(j=p(i),j&&(k=j,g.query_list.splice(f,1),l=a.Query.objectToSearchText(g),f=g.query_list.length));if(c.sort_on)for(f=0;f<c.sort_on.length;f+=1)m.push(JSON.stringify(c.sort_on[f]));returna.util.ajax({type:"GET",url:b.parse(e._links.raw_search.href).expand({query:l,select_list:c.select_list||["title","reference"],limit:c.limit,sort_on:m,local_roles:k}),xhrFields:{withCredentials:d._thisCredentials},headers:d._headers})}).push(function(a){returnJSON.parse(a.target.responseText)}).push(function(a){varb,c,d,f=a._embedded.contents,g=f.length,h=[];for(b=0;g>b;b+=1)d=f[b],c=newe(d._links.self.href),deleted._links,h.push({id:c.segment(2),value:d});returnh})},a.addStorage("erp5",m)}(jIO,UriTemplate,FormData,RSVP,URI,Blob,SimpleQuery,ComplexQuery),function(a,b,c,d,e){"use strict";functionf(b){this._sub_storage=a.createJIO(b.sub_storage),this._document_id=b.document_id,this._repair_attachment=b.repair_attachment||!1}functiong(a,b){returnvoid0===b?"jio_document/"+d(a)+h:"jio_attachment/"+d(a)+"/"+d(b)}varh=".json",i=newRegExp("^jio_document/([\\w=]+)"+h+"$"),j=newRegExp("^jio_attachment/([\\w=]+)/([\\w=]+)$");f.prototype.get=function(a){returnthis._sub_storage.getAttachment(this._document_id,g(a),{format:"json"})},f.prototype.allAttachments=function(a){returnthis._sub_storage.allAttachments(this._document_id).push(function(b){vard,e,f={};for(einb)if(b.hasOwnProperty(e)&&j.test(e)){d=j.exec(e);try{c(d[1])===a&&(f[c(d[2])]={})}catch(g){if(!ginstanceofReferenceError)throwg}}returnf})},f.prototype.put=function(a,c){returnthis._sub_storage.putAttachment(this._document_id,g(a),newb([JSON.stringify(c)],{type:"application/json"})).push(function(){returna})},f.prototype.remove=function(a){varb=this;returnthis.allAttachments(a).push(function(c){vard,f=[];for(dinc)c.hasOwnProperty(d)&&f.push(b.removeAttachment(a,d));returne.all(f)}).push(function(){returnb._sub_storage.removeAttachment(b._document_id,g(a))}).push(function(){returna})},f.prototype.repair=function(){vara=this;returnthis._sub_storage.repair.apply(this._sub_storage,arguments).push(function(b){returna._repair_attachment?a._sub_storage.allAttachments(a._document_id).push(function(b){vard,f,g,h,k=[],l={},m={};for(hinb)if(b.hasOwnProperty(h))if(d=void0,f=void0,i.test(h)){try{d=c(i.exec(h)[1])}catch(n){if(!ninstanceofReferenceError)thrown}void0!==d&&(l[d]=null)}elseif(j.test(h)){g=j.exec(h);try{d=c(g[1]),f=c(g[2])}catch(n){if(!ninstanceofReferenceError)thrown}void0!==f&&(l.hasOwnProperty(d)||(m.hasOwnProperty(d)||(m[d]={}),m[d][f]=null))}for(dinm)if(m.hasOwnProperty(d)&&!l.hasOwnProperty(d))for(finm[d])m[d].hasOwnProperty(f)&&k.push(a.removeAttachment(d,f));returne.all(k)}):b})},f.prototype.hasCapacity=function(a){return"list"===a},f.prototype.buildQuery=function(){returnthis._sub_storage.allAttachments(this._document_id).push(function(a){varb,d=[];for(bina)if(a.hasOwnProperty(b)&&i.test(b))try{d.push({id:c(i.exec(b)[1]),value:{}})}catch(e){if(!einstanceofReferenceError)throwe}returnd})},f.prototype.getAttachment=function(a,b){returnthis._sub_storage.getAttachment(this._document_id,g(a,b))},f.prototype.putAttachment=function(a,b,c){returnthis._sub_storage.putAttachment(this._document_id,g(a,b),c)},f.prototype.removeAttachment=function(a,b){returnthis._sub_storage.removeAttachment(this._document_id,g(a,b))},a.addStorage("document",f)}(jIO,Blob,atob,btoa,RSVP),function(a,b){"use strict";functionc(b){this._sub_storage=a.createJIO(b.sub_storage),this._key_schema=b.key_schema}c.prototype.get=function(){returnthis._sub_storage.get.apply(this._sub_storage,arguments)},c.prototype.allAttachments=function(){returnthis._sub_storage.allAttachments.apply(this._sub_storage,arguments)},c.prototype.post=function(){returnthis._sub_storage.post.apply(this._sub_storage,arguments)},c.prototype.put=function(){returnthis._sub_storage.put.apply(this._sub_storage,arguments)},c.prototype.remove=function(){returnthis._sub_storage.remove.apply(this._sub_storage,arguments)},c.prototype.getAttachment=function(){returnthis._sub_storage.getAttachment.apply(this._sub_storage,arguments)},c.prototype.putAttachment=function(){returnthis._sub_storage.putAttachment.apply(this._sub_storage,arguments)},c.prototype.removeAttachment=function(){returnthis._sub_storage.removeAttachment.apply(this._sub_storage,arguments)},c.prototype.repair=function(){returnthis._sub_storage.repair.apply(this._sub_storage,arguments)},c.prototype.hasCapacity=function(a){varb=["limit","sort","select","query"];return-1!==b.indexOf(a)?!0:"list"===a?this._sub_storage.hasCapacity(a):!1},c.prototype.buildQuery=function(c){vard=this._sub_storage,e=this,f={},g=!1,h=!1;if(d.hasCapacity("list")){try{void0!==c.query&&!d.hasCapacity("query")||void0!==c.sort_on&&!d.hasCapacity("sort")||void0!==c.select_list&&!d.hasCapacity("select")||void0!==c.limit&&!d.hasCapacity("limit")||(f.query=c.query,f.sort_on=c.sort_on,f.select_list=c.select_list,f.limit=c.limit)}catch(i){if(!(iinstanceofa.util.jIOError&&501===i.status_code))throwi;g=!0}try{(g||c.include_docs===!0)&&d.hasCapacity("include")&&(f.include_docs=!0)}catch(i){if(!(iinstanceofa.util.jIOError&&501===i.status_code))throwi;h=!0}returnd.buildQuery(f).push(function(c){functione(b){vare=c[b].id;returnd.get(e).push(function(a){returna._id=e,a},function(b){if(!(binstanceofa.util.jIOError&&404===b.status_code))throwb})}varf,g,i=[c];if(h){for(f=c.length,g=0;f>g;g+=1)i.push(e(g));c=b.all(i)}returnc}).push(function(a){varb,c,d;if(h){for(b=a[0],c=b.length,d=0;c>d;d+=1)b[d].doc=a[d+1];a=b}returna}).push(function(b){vard,f,h=[];if(g){for(d=b.length,f=0;d>f;f+=1)b[f].doc.__id=b[f].id,h.push(b[f].doc);c.select_list&&c.select_list.push("__id"),b=a.QueryFactory.create(c.query||"",e._key_schema).exec(h,c)}returnb}).push(function(a){varb,d,e,f=[];if(g){for(d=a.length,e=0;d>e;e+=1){if(b={id:a[e].__id,value:c.select_list?a[e]:{},doc:{}},c.select_list&&deleteb.value.__id,c.include_docs)thrownewError("QueryStorage does not support include docs");f.push(b)}a=f}returna})}},a.addStorage("query",c)}(jIO,RSVP),function(a,b,c,d){"use strict";functione(a){a.sessiononly===!0?this._storage=b:this._storage=c}functionf(b){if("/"!==b)thrownewa.util.jIOError("id "+b+" is forbidden (!== /)",400)}e.prototype.get=function(a){returnf(a),{}},e.prototype.allAttachments=function(a){f(a);varb,c={};for(binthis._storage)this._storage.hasOwnProperty(b)&&(c[b]={});returnc},e.prototype.getAttachment=function(b,c){f(b);vard=this._storage.getItem(c);if(null===d)thrownewa.util.jIOError("Cannot find attachment "+c,404);returna.util.dataURItoBlob(d)},e.prototype.putAttachment=function(b,c,e){varg=this;returnf(b),(newd.Queue).push(function(){returna.util.readBlobAsDataURL(e)}).push(function(a){g._storage.setItem(c,a.target.result)})},e.prototype.removeAttachment=function(a,b){returnf(a),this._storage.removeItem(b)},e.prototype.hasCapacity=function(a){return"list"===a},e.prototype.buildQuery=function(){return[{id:"/",value:{}}]},a.addStorage("local",e)}(jIO,sessionStorage,localStorage,RSVP),function(a,b,c,d,e,f,g){"use strict";functionh(b){varc,g=[];for(cinb._mapping_dict)if(b._mapping_dict.hasOwnProperty(c)){if("equalValue"===b._mapping_dict[c][0]){if(void0===b._mapping_dict[c][1])thrownewa.util.jIOError("equalValue has not parameter",400);b._default_mapping[c]=b._mapping_dict[c][1],g.push(newd({key:c,value:b._mapping_dict[c][1],type:"simple"}))}if("equalSubId"===b._mapping_dict[c][0]){if(void0!==b._property_for_sub_id)thrownewa.util.jIOError("equalSubId can be defined one time",400);b._property_for_sub_id=c}}void0!==b._query.query&&g.push(f.create(b._query.query)),g.length>1?b._query.query=newe({type:"complex",query_list:g,operator:"AND"}):1===g.length&&(b._query.query=g[0])}functioni(b){this._mapping_dict=b.mapping_dict||{},this._sub_storage=a.createJIO(b.sub_storage),this._map_all_property=void0!==b.map_all_property?b.map_all_property:!0,this._attachment_mapping_dict=b.attachment_mapping_dict||{},this._query=b.query||{},this._map_id=b.map_id,this._id_mapped=void0!==b.map_id?b.map_id[1]:!1,void0!==this._query.query&&(this._query.query=f.create(this._query.query)),this._default_mapping={},h(this)}functionj(a,b,d,e){varf=a._attachment_mapping_dict;returnvoid0!==f&&void0!==f[d]&&void0!==f[d][e]&&void0!==f[d][e].uri_template?c.parse(f[d][e].uri_template).expand({id:b}):d}functionk(c,f,h){vari;return(newb.Queue).push(function(){if(void0!==c._property_for_sub_id&&void0!==h&&void0!==h[c._property_for_sub_id])returnh[c._property_for_sub_id];if(!c._id_mapped)returnf;if("equalSubProperty"===c._map_id[0])returni=newd({key:c._map_id[1],value:f,type:"simple"}),void0!==c._query.query&&(i=newe({operator:"AND",query_list:[i,c._query.query],type:"complex"})),i=g.objectToSearchText(i),c._sub_storage.allDocs({query:i,sort_on:c._query.sort_on,select_list:c._query.select_list,limit:c._query.limit}).push(function(b){if(0===b.data.rows.length)thrownewa.util.jIOError("Can not find id",404);if(b.data.rows.length>1)thrownewTypeError("id must be unique field: "+f+", result:"+b.data.rows.toString());returnb.data.rows[0].id});thrownewa.util.jIOError("Unsuported option: "+c._mapping_dict.id,400)})}functionl(b,c,d,e){varf,g;if(void0!==b._mapping_dict[c]){if(f=b._mapping_dict[c][0],g=b._mapping_dict[c][1],"equalSubProperty"===f)returnd[g]=e[c],g;if("equalValue"===f)returnd[c]=g,c;if("ignore"===f||"equalSubId"===f)return!1}if(!b._map_all_property)return!1;if(b._map_all_property)returnd[c]=e[c],c;thrownewa.util.jIOError("Unsuported option(s): "+b._mapping_dict[c],400)}functionm(a,b,c,d){vare,f;if(void0!==a._mapping_dict[b]){if(e=a._mapping_dict[b][0],f=a._mapping_dict[b][1],"equalSubProperty"===e)returnc.hasOwnProperty(f)&&(d[b]=c[f]),f;if("equalValue"===e)returnb;if("ignore"===e)returnb}returna._map_all_property?(c.hasOwnProperty(b)&&(d[b]=c[b]),b):!1}functionn(a,b,c){vard,e={},f=[a._id_mapped];for(dina._mapping_dict)a._mapping_dict.hasOwnProperty(d)&&f.push(m(a,d,b,e));if(a._map_all_property)for(dinb)b.hasOwnProperty(d)&&f.indexOf(d)<0&&(e[d]=b[d]);returnvoid0!==a._property_for_sub_id&&void0!==c&&(e[a._property_for_sub_id]=c),e}functiono(a,b,c){vard,e={};for(dinb)b.hasOwnProperty(d)&&l(a,d,e,b);for(dina._default_mapping)a._default_mapping.hasOwnProperty(d)&&(e[d]=a._default_mapping[d]);returna._id_mapped&&void0!==c&&(e[a._id_mapped]=c),e}functionp(a,b,c){returnk(a,b[0]).push(function(d){returnb[0]=d,b[1]=j(a,d,b[1],c),a._sub_storage[c+"Attachment"].apply(a._sub_storage,b)})}i.prototype.get=function(a){varb=this;returnk(this,a).push(function(a){returnb._sub_storage.get(a).push(function(c){returnn(b,c,a)})})},i.prototype.post=function(b){varc=o(this,b),d=b[this._property_for_sub_id];if(this._property_for_sub_id&&void0!==d)returnthis._sub_storage.put(d,c);if(!this._id_mapped||void0!==b[this._id_mapped])returnthis._sub_storage.post(c);thrownewa.util.jIOError("post is not supported with id mapped",400)},i.prototype.put=function(b,c){vard=this,e=o(this,c,b);returnk(this,b,c).push(function(a){returnd._sub_storage.put(a,e)}).push(void0,function(b){if(binstanceofa.util.jIOError&&404===b.status_code)returnd._sub_storage.post(e);throwb}).push(function(){returnb})},i.prototype.remove=function(a){varb=this;returnk(this,a).push(function(a){returnb._sub_storage.remove(a)}).push(function(){returna})},i.prototype.putAttachment=function(a,b){returnp(this,arguments,"put",a).push(function(){returnb})},i.prototype.getAttachment=function(){returnp(this,arguments,"get")},i.prototype.removeAttachment=function(a,b){returnp(this,arguments,"remove",a).push(function(){returnb})},i.prototype.allAttachments=function(a){varb,c=this;returnk(c,a).push(function(a){returnb=a,c._sub_storage.allAttachments(b)}).push(function(a){vard,e={},f={};for(dinc._attachment_mapping_dict)c._attachment_mapping_dict.hasOwnProperty(d)&&(f[j(c,b,d,"get")]=d);for(dina)a.hasOwnProperty(d)&&(f.hasOwnProperty(d)?e[f[d]]={}:e[d]={});returne})},i.prototype.hasCapacity=function(a){returnthis._sub_storage.hasCapacity(a)},i.prototype.repair=function(){returnthis._sub_storage.repair.apply(this._sub_storage,arguments)},i.prototype.bulk=function(a){functionc(a){returnk(d,a.parameter_list[0]).push(function(b){return{method:a.method,parameter_list:[b]}})}vard=this;return(newb.Queue).push(function(){vard=a.map(c);returnb.all(d)}).push(function(a){returnd._sub_storage.bulk(a)}).push(function(a){varb,c=[];for(b=0;b<a.length;b+=1)c.push(n(d,a[b]));returnc})},i.prototype.buildQuery=function(a){functionb(a){varc,d,e,f=[];if("complex"===a.type){for(c=0;c<a.query_list.length;c+=1)e=b(a.query_list[c]),e&&f.push(e);returna.query_list=f,a}returnd=m(i,a.key,{},{}),
},g.prototype.buildQuery=function(){returnthis._local_sub_storage.buildQuery.apply(this._local_sub_storage,arguments)},g.prototype.repair=function(){functionc(a,b,c,d){returnb.removeAttachment(c,d).push(function(){returnw._signature_sub_storage.removeAttachment(c,d)}).push(function(){a[d]=null})}functiong(a,b,c,d,e,f){returnb.putAttachment(e,f,c).push(function(){returnw._signature_sub_storage.putAttachment(e,f,JSON.stringify({hash:d}))}).push(function(){a[f]=null})}functionh(b,d,e,h,i,j,k,l,m,n,o){varp;returnj.getAttachment(k,l).push(function(b){returnp=b,a.util.readBlobAsArrayBuffer(p)}).push(function(a){returnf(a.target.result)},function(b){if(binstanceofa.util.jIOError&&404===b.status_code)returnp=null,null;throwb}).push(function(f){if(e===f)returnnull===e?w._signature_sub_storage.removeAttachment(k,l).push(function(){b[k]=null}):w._signature_sub_storage.putAttachment(k,l,JSON.stringify({hash:e})).push(function(){y[k]=null});if(f===d||m===!0)returnnull===e?c(b,j,k,l):g(b,j,h,e,k,l);if(o!==!0){if(n===!0||null===e)returnnull===f?c(b,i,k,l):g(b,i,p,f,k,l);if(null===f)returng(b,j,h,e,k,l);thrownewa.util.jIOError("Conflict on '"+k+"' with attachment '"+l+"'",409)}})}functioni(c,d,e,g,i,j,k,l,m,n,o){varp,q;d.push(function(){if(n===!0)returnb.all([e.getAttachment(i,j),{hash:null}]);if(o===!0)returnb.all([e.getAttachment(i,j),w._signature_sub_storage.getAttachment(i,j,{format:"json"})]);thrownewa.util.jIOError("Unexpected call of checkAttachmentSignatureDifference",409)}).push(function(b){returnp=b[0],q=b[1].hash,a.util.readBlobAsArrayBuffer(p)}).push(function(a){varb=a.target.result,d=f(b);returnd!==q?h(c,q,d,p,e,g,i,j,k,l,m):void0})}functionm(a,b,c,d,e,f,g,i,j){vark;b.push(function(){returnw._signature_sub_storage.getAttachment(d,e,{format:"json"})}).push(function(b){returnk=b.hash,h(a,k,null,null,f,c,d,e,g,i,j)})}functionn(c,d,e,f,g){varh=newb.Queue;returnh.push(function(){returnb.all([e.allAttachments(d).push(void0,function(b){if(binstanceofa.util.jIOError&&404===b.status_code)return{};throwb}),w._signature_sub_storage.allAttachments(d).push(void0,function(b){if(binstanceofa.util.jIOError&&404===b.status_code)return{};throwb})])}).push(function(a){varb,j,k,l={},n={};for(kina[0])a[0].hasOwnProperty(k)&&(c.hasOwnProperty(k)||(l[k]=null));for(kina[1])a[1].hasOwnProperty(k)&&(c.hasOwnProperty(k)||(n[k]=null));for(kinl)l.hasOwnProperty(k)&&(b=n.hasOwnProperty(k)&&g.check_modification,j=!n.hasOwnProperty(k)&&g.check_creation,(b===!0||j===!0)&&i(c,h,e,f,d,k,g.conflict_force,g.conflict_revert,g.conflict_ignore,j,b));if(g.check_deletion===!0)for(kinn)n.hasOwnProperty(k)&&(l.hasOwnProperty(k)||m(c,h,f,d,k,e,g.conflict_force,g.conflict_revert,g.conflict_ignore))})}functiono(a){varc={};return(newb.Queue).push(function(){returnw._check_local_attachment_modification||w._check_local_attachment_creation||w._check_local_attachment_deletion?n(c,a,w._local_sub_storage,w._remote_sub_storage,{conflict_force:w._conflict_handling===j,conflict_revert:w._conflict_handling===k,conflict_ignore:w._conflict_handling===l,check_modification:w._check_local_attachment_modification,check_creation:w._check_local_attachment_creation,check_deletion:w._check_local_attachment_deletion}):void0}).push(function(){returnw._check_remote_attachment_modification||w._check_remote_attachment_creation||w._check_remote_attachment_deletion?n(c,a,w._remote_sub_storage,w._local_sub_storage,{use_revert_post:w._use_remote_post,conflict_force:w._conflict_handling===k,conflict_revert:w._conflict_handling===j,conflict_ignore:w._conflict_handling===l,check_modification:w._check_remote_attachment_modification,check_creation:w._check_remote_attachment_creation,check_deletion:w._check_remote_attachment_deletion}):void0})}functionp(a,c,d,e,f,g){varh,i,j=!0;returnvoid0===g&&(g={}),h=g.use_post?c.post(d).push(function(b){returnj=!1,i=b,a.put(i,d)}).push(function(){returna.allAttachments(f)}).push(function(c){functiond(b){g.push(function(){returna.getAttachment(f,b)}).push(function(c){returna.putAttachment(i,b,c)})}vare,g=newb.Queue;for(einc)c.hasOwnProperty(e)&&d(e);returng}).push(function(){returna.remove(f)}).push(function(){returnw._signature_sub_storage.remove(f)}).push(function(){returnj=!0,w._signature_sub_storage.put(i,{hash:e})}).push(function(){y[i]=null}):c.put(f,d).push(function(){returnw._signature_sub_storage.put(f,{hash:e})}),h.push(function(){j&&(y[f]=null)})}functionq(b,c){returno(c).push(function(){returnb.allAttachments(c)}).push(function(a){return"{}"===JSON.stringify(a)?b.remove(c).push(function(){returnw._signature_sub_storage.remove(c)}):void0},function(b){if(!(binstanceofa.util.jIOError&&404===b.status_code))throwb}).push(function(){y[c]=null})}functionr(b,c,f,g,h,i,j,k,l,m){returnh.get(i).push(function(a){return[a,e(d(a))]},function(b){if(binstanceofa.util.jIOError&&404===b.status_code)return[null,null];throwb}).push(function(e){varn=e[0],o=e[1];if(c===o)returnnull===c?w._signature_sub_storage.remove(i).push(function(){y[i]=null}):w._signature_sub_storage.put(i,{hash:c}).push(function(){y[i]=null});if(o===b||j===!0)returnnull===c?q(h,i):p(g,h,f,c,i,{use_post:m.use_post&&null===o});if(l!==!0){if(k===!0||null===c)returnnull===o?q(g,i):p(h,g,n,o,i,{use_post:m.use_revert_post&&null===c});if(null===o)returnp(g,h,f,c,i,{use_post:m.use_post});thrownewa.util.jIOError("Conflict on '"+i+"': "+d(f||"")+" !== "+d(n||""),409)}})}functions(a,b,c,d,e,f,g,h){vari;a.push(function(){returnw._signature_sub_storage.get(c)}).push(function(a){returni=a.hash,r(i,null,null,d,b,c,e,f,g,h)})}functiont(c,f,g,h,i,j,k,l,m,n,o){c.push(function(){if(l===!0)returnb.all([n(h),{hash:null}]);if(m===!0)returnb.all([n(h),w._signature_sub_storage.get(h)]);thrownewa.util.jIOError("Unexpected call of checkSignatureDifference",409)}).push(function(a){varb=a[0],c=e(d(b)),l=a[1].hash;returnc!==l?r(l,c,b,f,g,h,i,j,k,o):void0})}functionu(a,c,d,e,f,g,h,i,j){a.push(function(){returnc.bulk(e)}).push(function(a){functionk(b){returnfunction(c){if(c!==e[b].parameter_list[0])thrownewError("Does not access expected ID "+c);returna[b]}}varl,m=newb.Queue;for(l=0;l<a.length;l+=1)t(m,c,d,e[l].parameter_list[0],h,i,j,f[l].is_creation,f[l].is_modification,k(l),g);returnm})}functionv(a,c,d){vare=newb.Queue;returnd.hasOwnProperty("use_post")||(d.use_post=!1),d.hasOwnProperty("use_revert_post")||(d.use_revert_post=!1),e.push(function(){returnb.all([a.allDocs(w._query_options),w._signature_sub_storage.allDocs()])}).push(function(b){varf,g,h,i,j={},k=[],l=[],m={};for(f=0;f<b[0].data.total_rows;f+=1)y.hasOwnProperty(b[0].data.rows[f].id)||(j[b[0].data.rows[f].id]=f);for(f=0;f<b[1].data.total_rows;f+=1)y.hasOwnProperty(b[1].data.rows[f].id)||(m[b[1].data.rows[f].id]=f);for(iinj)j.hasOwnProperty(i)&&(g=m.hasOwnProperty(i)&&d.check_modification,h=!m.hasOwnProperty(i)&&d.check_creation,(g===!0||h===!0)&&(d.use_bulk_get===!0?(k.push({method:"get",parameter_list:[i]}),l.push({is_creation:h,is_modification:g})):t(e,a,c,i,d.conflict_force,d.conflict_revert,d.conflict_ignore,h,g,a.get.bind(a),d)));if(d.check_deletion===!0)for(iinm)m.hasOwnProperty(i)&&(j.hasOwnProperty(i)||s(e,c,i,a,d.conflict_force,d.conflict_revert,d.conflict_ignore,d));d.use_bulk_get===!0&&0!==k.length&&u(e,a,c,k,l,d,d.conflict_force,d.conflict_revert,d.conflict_ignore)})}varw=this,x=arguments,y={};returny[w._signature_hash]=null,(newb.Queue).push(function(){returnw._signature_sub_storage.__storage._sub_storage.get(w._signature_hash)}).push(void0,function(b){if(binstanceofa.util.jIOError&&404===b.status_code)returnw._signature_sub_storage.__storage._sub_storage.put(w._signature_hash,{});throwb}).push(function(){returnb.all([w._local_sub_storage.repair.apply(w._local_sub_storage,x),w._remote_sub_storage.repair.apply(w._remote_sub_storage,x)])}).push(function(){returnw._check_local_modification||w._check_local_creation||w._check_local_deletion?v(w._local_sub_storage,w._remote_sub_storage,{use_post:w._use_remote_post,conflict_force:w._conflict_handling===j,conflict_revert:w._conflict_handling===k,conflict_ignore:w._conflict_handling===l,check_modification:w._check_local_modification,check_creation:w._check_local_creation,check_deletion:w._check_local_deletion}):void0}).push(function(){varb=!1;try{b=w._remote_sub_storage.hasCapacity("bulk_get")}catch(c){if(!(cinstanceofa.util.jIOError&&501===c.status_code))throwc}returnw._check_remote_modification||w._check_remote_creation||w._check_remote_deletion?v(w._remote_sub_storage,w._local_sub_storage,{use_bulk_get:b,use_revert_post:w._use_remote_post,conflict_force:w._conflict_handling===k,conflict_revert:w._conflict_handling===j,conflict_ignore:w._conflict_handling===l,check_modification:w._check_remote_modification,check_creation:w._check_remote_creation,check_deletion:w._check_remote_deletion}):void0}).push(function(){returnw._check_local_attachment_modification||w._check_local_attachment_creation||w._check_local_attachment_deletion||w._check_remote_attachment_modification||w._check_remote_attachment_creation||w._check_remote_attachment_deletion?w._signature_sub_storage.allDocs().push(function(a){functionc(a){e.push(function(){returno(a)})}vard,e=newb.Queue;for(d=0;d<a.data.total_rows;d+=1)c(a.data.rows[d].id);returne}):void0})},a.addStorage("replicate",g)}(jIO,RSVP,Rusha,jIO.util.stringify),function(a){"use strict";functionb(b){this._sub_storage=a.createJIO(b.sub_storage)}b.prototype.get=function(){returnthis._sub_storage.get.apply(this._sub_storage,arguments)},b.prototype.allAttachments=function(){returnthis._sub_storage.allAttachments.apply(this._sub_storage,arguments)},b.prototype.post=function(a){functionb(){return("0000"+Math.floor(65536*Math.random()).toString(16)).slice(-4)}varc=b()+b()+"-"+b()+"-"+b()+"-"+b()+"-"+b()+b()+b();returnthis.put(c,a)},b.prototype.put=function(){returnthis._sub_storage.put.apply(this._sub_storage,arguments)},b.prototype.remove=function(){returnthis._sub_storage.remove.apply(this._sub_storage,arguments)},b.prototype.getAttachment=function(){returnthis._sub_storage.getAttachment.apply(this._sub_storage,arguments)},b.prototype.putAttachment=function(){returnthis._sub_storage.putAttachment.apply(this._sub_storage,arguments)},b.prototype.removeAttachment=function(){returnthis._sub_storage.removeAttachment.apply(this._sub_storage,arguments)},b.prototype.repair=function(){returnthis._sub_storage.repair.apply(this._sub_storage,arguments)},b.prototype.hasCapacity=function(a){returnthis._sub_storage.hasCapacity(a)},b.prototype.buildQuery=function(){returnthis._sub_storage.buildQuery.apply(this._sub_storage,arguments)},a.addStorage("uuid",b)}(jIO),function(a,b,c){"use strict";functiond(){this._database={}}d.prototype.put=function(a,c){returnthis._database.hasOwnProperty(a)||(this._database[a]={attachments:{}}),this._database[a].doc=b.stringify(c),a},d.prototype.get=function(c){try{returnb.parse(this._database[c].doc)}catch(d){if(dinstanceofTypeError)thrownewa.util.jIOError("Cannot find document: "+c,404);throwd}},d.prototype.allAttachments=function(b){varc,d={};try{for(cinthis._database[b].attachments)this._database[b].attachments.hasOwnProperty(c)&&(d[c]={})}catch(e){if(einstanceofTypeError)thrownewa.util.jIOError("Cannot find document: "+b,404);throwe}returnd},d.prototype.remove=function(a){returndeletethis._database[a],a},d.prototype.getAttachment=function(b,c){try{vard=this._database[b].attachments[c];if(void0===d)thrownewa.util.jIOError("Cannot find attachment: "+b+" , "+c,404);returna.util.dataURItoBlob(d)}catch(e){if(einstanceofTypeError)thrownewa.util.jIOError("Cannot find attachment: "+b+" , "+c,404);throwe}},d.prototype.putAttachment=function(b,d,e){varf;try{f=this._database[b].attachments}catch(g){if(ginstanceofTypeError)thrownewa.util.jIOError("Cannot find document: "+b,404);throwg}return(newc.Queue).push(function(){returna.util.readBlobAsDataURL(e)}).push(function(a){f[d]=a.target.result})},d.prototype.removeAttachment=function(b,c){try{deletethis._database[b].attachments[c]}catch(d){if(dinstanceofTypeError)thrownewa.util.jIOError("Cannot find document: "+b,404);throwd}},d.prototype.hasCapacity=function(a){return"list"===a||"include"===a},d.prototype.buildQuery=function(a){varc,d=[];for(cinthis._database)this._database.hasOwnProperty(c)&&(a.include_docs===!0?d.push({id:c,value:{},doc:b.parse(this._database[c].doc)}):d.push({id:c,value:{}}));returnd},a.addStorage("memory",d)}(jIO,JSON,RSVP),function(a,b,c,d,e,f,g,h){"use strict";functioni(b){return(newd.Queue).push(function(){returna.util.ajax({type:"GET",url:b._url,xhrFields:{withCredentials:b._thisCredentials},headers:b._headers})}).push(function(a){returnJSON.parse(a.target.responseText)})}functionj(c,e,f){returnvoid0===f&&(f={}),i(c).push(function(g){return(newd.Queue).push(function(){returna.util.ajax({type:"GET",url:b.parse(g._links.traverse.href).expand({relative_url:e,view:f._view}),xhrFields:{withCredentials:c._thisCredentials},headers:c._headers})}).push(void0,function(b){if(void0!==b.target&&404===b.target.status)thrownewa.util.jIOError("Cannot find document: "+e,404);throwb})})}functionk(a){return(newd.Queue).push(function(){varb,c,d,f,g=a._embedded._view,h={portal_type:a._links.type.name},i={};a._links.hasOwnProperty("parent")&&(h.parent_relative_url=newe(a._links.parent.href).segment(2)),i.form_id={key:[g.form_id.key],"default":g.form_id["default"]};for(cing)g.hasOwnProperty(c)&&(b=g[c],d=0,0===c.indexOf("my_")&&b.editable&&(d=3),0===c.indexOf("your_")&&(d=5),0!==d&&q.hasOwnProperty(b.type)&&(i[c.substring(d)]={"default":b["default"],key:b.key},h[c.substring(d)]=b["default"]));returnf={data:h,form_data:i},g.hasOwnProperty("_actions")&&g._actions.hasOwnProperty("put")&&(f.action_href=g._actions.put.href),f})}functionl(b,c){returnb.getAttachment(c,"view").push(function(b){returna.util.readBlobAsText(b)}).push(function(a){returnJSON.parse(a.target.result)}).push(function(a){returnk(a)})}functionm(a){if("string"!=typeofa.url||!a.url)thrownewTypeError("ERP5 'url' must be a string which contains more than one character.");this._url=a.url,this._default_view_reference=a.default_view_reference,this._headers=null,this._thisCredentials=!0,void0!==a.login&&void0!==a.password&&(this._headers={Authorization:"Basic "+btoa(a.login+":"+a.password)},this._thisCredentials=!1)}functionn(a){returna.data}functiono(a){returnainstanceofg&&"local_roles"===a.key?a.value:void0}functionp(a){varb,c,d=!0,e=[];if(ainstanceofh&&"OR"===a.operator){for(b=0;b<a.query_list.length;b+=1)c=a.query_list[b],cinstanceofg&&"local_roles"===c.key?e.push(c.value):d=!1;if(d)returne}}varq={StringField:null,EmailField:null,IntegerField:null,FloatField:null,TextAreaField:null};m.prototype.get=function(a){returnl(this,a).push(function(a){returnn(a)})},m.prototype.bulk=function(b){vare,f=this,g=[];for(e=0;e<b.length;e+=1){if("get"!==b[e].method)thrownewError("ERP5Storage: not supported "+b[e].method+" in bulk");g.push({relative_url:b[e].parameter_list[0],view:f._default_view_reference})}returni(f).push(function(b){vard=newc;returnd.append("bulk_list",JSON.stringify(g)),a.util.ajax({type:"POST",url:b._actions.bulk.href,data:d,xhrFields:{withCredentials:f._thisCredentials},headers:f._headers})}).push(function(a){functionb(a){returnk(a).push(function(a){returnn(a)})}varc=[],f=JSON.parse(a.target.responseText);for(e=0;e<f.result_list.length;e+=1)c.push(b(f.result_list[e]));returnd.all(c)})},m.prototype.post=function(b){vard,f=this;returni(this).push(function(d){vare=newc;returne.append("portal_type",b.portal_type),e.append("parent_relative_url",b.parent_relative_url),a.util.ajax({type:"POST",url:d._actions.add.href,data:e,xhrFields:{withCredentials:f._thisCredentials},headers:f._headers})}).push(function(a){varc=a.target.getResponseHeader("X-Location"),g=newe(c);returnd=g.segment(2),f.put(d,b)}).push(function(){returnd})},m.prototype.put=function(b,c){vard=this;returnl(d,b).push(function(e){varg,h=e.form_data,i={};i[h.form_id.key]=h.form_id["default"];for(ginc)if(c.hasOwnProperty(g)){if("form_id"===g)thrownewa.util.jIOError("ERP5: forbidden property: "+g,400);if("portal_type"!==g&&"parent_relative_url"!==g){if(!h.hasOwnProperty(g))thrownewa.util.jIOError("ERP5: can not store property: "+g,400);i[h[g].key]=c[g]}}if(!e.hasOwnProperty("action_href"))thrownewa.util.jIOError("ERP5: can not modify document: "+b,403);returnd.putAttachment(b,e.action_href,newf([JSON.stringify(i)],{type:"application/json"}))})},m.prototype.allAttachments=function(a){varb=this;returnj(this,a).push(function(){returnvoid0===b._default_view_reference?{links:{}}:{view:{},links:{}}})},m.prototype.getAttachment=function(b,c,e){varg=this;if(void0===e&&(e={}),"view"===c){if(void0===this._default_view_reference)thrownewa.util.jIOError("Cannot find attachment view for: "+b,404);returnj(this,b,{_view:this._default_view_reference}).push(function(a){varb=JSON.parse(a.target.responseText);returnnewf([JSON.stringify(b)],{type:"application/hal+json"})})}if("links"===c)returnj(this,b).push(function(a){returnnewf([JSON.stringify(JSON.parse(a.target.responseText))],{type:"application/hal+json"})});if(0===c.indexOf(this._url))return(newd.Queue).push(function(){varb,d,f,h={type:"GET",dataType:"blob",url:c,xhrFields:{withCredentials:g._thisCredentials},headers:g._headers};if(void0!==e.start||void0!==e.end){if(b=e.start||0,d=e.end,void0!==d&&0>d)thrownewa.util.jIOError("end must be positive",400);if(0>b)f="bytes="+b;elseif(void0===d)f="bytes="+b+"-";else{if(b>d)thrownewa.util.jIOError("start is greater than end",400);f="bytes="+b+"-"+d}void0===g._headers?h.headers={Range:f}:h.headers.Range=f}returna.util.ajax(h)}).push(function(a){returnvoid0===a.target.response?newf([a.target.responseText],{type:a.target.getResponseHeader("Content-Type")}):a.target.response});thrownewa.util.jIOError("ERP5: not support get attachment: "+c,400)},m.prototype.putAttachment=function(b,e,f){varg=this;if(0!==e.indexOf(this._url))thrownewa.util.jIOError("Can not store outside ERP5: "+e,400);return(newd.Queue).push(function(){returna.util.readBlobAsText(f)}).push(function(b){vard,f,h,i,j=JSON.parse(b.target.result),k=newc;for(hinj)if(j.hasOwnProperty(h))for(d=Array.isArray(j[h])?j[h]:[j[h]],f=0;f<d.length;f+=1)i=d[f],"object"==typeofi?k.append(h,a.util.dataURItoBlob(i.url),i.file_name):k.append(h,i);returna.util.ajax({type:"POST",url:e,data:k,xhrFields:{withCredentials:g._thisCredentials},headers:g._headers})})},m.prototype.hasCapacity=function(a){return"list"===a||"query"===a||"select"===a||"limit"===a||"sort"===a||"bulk_get"===a},m.prototype.buildQuery=function(c){vard=this;returni(this).push(function(e){varf,g,i,j,k,l=c.query,m=[];if(c.query)if(g=a.QueryFactory.create(c.query),j=o(g))l=void0,k=j;elseif(j=p(g))l=void0,k=j;elseif(ginstanceofh&&"AND"===g.operator)for(f=0;f<g.query_list.length;f+=1)i=g.query_list[f],j=o(i),j?(k=j,g.query_list.splice(f,1),l=a.Query.objectToSearchText(g),f=g.query_list.length):(j=p(i),j&&(k=j,g.query_list.splice(f,1),l=a.Query.objectToSearchText(g),f=g.query_list.length));if(c.sort_on)for(f=0;f<c.sort_on.length;f+=1)m.push(JSON.stringify(c.sort_on[f]));returna.util.ajax({type:"GET",url:b.parse(e._links.raw_search.href).expand({query:l,select_list:c.select_list||["title","reference"],limit:c.limit,sort_on:m,local_roles:k}),xhrFields:{withCredentials:d._thisCredentials},headers:d._headers})}).push(function(a){returnJSON.parse(a.target.responseText)}).push(function(a){varb,c,d,f=a._embedded.contents,g=f.length,h=[];for(b=0;g>b;b+=1)d=f[b],c=newe(d._links.self.href),deleted._links,h.push({id:c.segment(2),value:d});returnh})},a.addStorage("erp5",m)}(jIO,UriTemplate,FormData,RSVP,URI,Blob,SimpleQuery,ComplexQuery),function(a,b,c,d,e){"use strict";functionf(b){this._sub_storage=a.createJIO(b.sub_storage),this._document_id=b.document_id,this._repair_attachment=b.repair_attachment||!1}functiong(a,b){returnvoid0===b?"jio_document/"+d(a)+h:"jio_attachment/"+d(a)+"/"+d(b)}varh=".json",i=newRegExp("^jio_document/([\\w=]+)"+h+"$"),j=newRegExp("^jio_attachment/([\\w=]+)/([\\w=]+)$");f.prototype.get=function(a){returnthis._sub_storage.getAttachment(this._document_id,g(a),{format:"json"})},f.prototype.allAttachments=function(a){returnthis._sub_storage.allAttachments(this._document_id).push(function(b){vard,e,f={};for(einb)if(b.hasOwnProperty(e)&&j.test(e)){d=j.exec(e);try{c(d[1])===a&&(f[c(d[2])]={})}catch(g){if(!ginstanceofReferenceError)throwg}}returnf})},f.prototype.put=function(a,c){returnthis._sub_storage.putAttachment(this._document_id,g(a),newb([JSON.stringify(c)],{type:"application/json"})).push(function(){returna})},f.prototype.remove=function(a){varb=this;returnthis.allAttachments(a).push(function(c){vard,f=[];for(dinc)c.hasOwnProperty(d)&&f.push(b.removeAttachment(a,d));returne.all(f)}).push(function(){returnb._sub_storage.removeAttachment(b._document_id,g(a))}).push(function(){returna})},f.prototype.repair=function(){vara=this;returnthis._sub_storage.repair.apply(this._sub_storage,arguments).push(function(b){returna._repair_attachment?a._sub_storage.allAttachments(a._document_id).push(function(b){vard,f,g,h,k=[],l={},m={};for(hinb)if(b.hasOwnProperty(h))if(d=void0,f=void0,i.test(h)){try{d=c(i.exec(h)[1])}catch(n){if(!ninstanceofReferenceError)thrown}void0!==d&&(l[d]=null)}elseif(j.test(h)){g=j.exec(h);try{d=c(g[1]),f=c(g[2])}catch(n){if(!ninstanceofReferenceError)thrown}void0!==f&&(l.hasOwnProperty(d)||(m.hasOwnProperty(d)||(m[d]={}),m[d][f]=null))}for(dinm)if(m.hasOwnProperty(d)&&!l.hasOwnProperty(d))for(finm[d])m[d].hasOwnProperty(f)&&k.push(a.removeAttachment(d,f));returne.all(k)}):b})},f.prototype.hasCapacity=function(a){return"list"===a},f.prototype.buildQuery=function(){returnthis._sub_storage.allAttachments(this._document_id).push(function(a){varb,d=[];for(bina)if(a.hasOwnProperty(b)&&i.test(b))try{d.push({id:c(i.exec(b)[1]),value:{}})}catch(e){if(!einstanceofReferenceError)throwe}returnd})},f.prototype.getAttachment=function(a,b){returnthis._sub_storage.getAttachment(this._document_id,g(a,b))},f.prototype.putAttachment=function(a,b,c){returnthis._sub_storage.putAttachment(this._document_id,g(a,b),c)},f.prototype.removeAttachment=function(a,b){returnthis._sub_storage.removeAttachment(this._document_id,g(a,b))},a.addStorage("document",f)}(jIO,Blob,atob,btoa,RSVP),function(a,b){"use strict";functionc(b){this._sub_storage=a.createJIO(b.sub_storage),this._key_schema=b.key_schema}c.prototype.get=function(){returnthis._sub_storage.get.apply(this._sub_storage,arguments)},c.prototype.allAttachments=function(){returnthis._sub_storage.allAttachments.apply(this._sub_storage,arguments)},c.prototype.post=function(){returnthis._sub_storage.post.apply(this._sub_storage,arguments)},c.prototype.put=function(){returnthis._sub_storage.put.apply(this._sub_storage,arguments)},c.prototype.remove=function(){returnthis._sub_storage.remove.apply(this._sub_storage,arguments)},c.prototype.getAttachment=function(){returnthis._sub_storage.getAttachment.apply(this._sub_storage,arguments)},c.prototype.putAttachment=function(){returnthis._sub_storage.putAttachment.apply(this._sub_storage,arguments)},c.prototype.removeAttachment=function(){returnthis._sub_storage.removeAttachment.apply(this._sub_storage,arguments)},c.prototype.repair=function(){returnthis._sub_storage.repair.apply(this._sub_storage,arguments)},c.prototype.hasCapacity=function(a){varb=["limit","sort","select","query"];return-1!==b.indexOf(a)?!0:"list"===a?this._sub_storage.hasCapacity(a):!1},c.prototype.buildQuery=function(c){vard=this._sub_storage,e=this,f={},g=!1,h=!1;if(d.hasCapacity("list")){try{void0!==c.query&&!d.hasCapacity("query")||void0!==c.sort_on&&!d.hasCapacity("sort")||void0!==c.select_list&&!d.hasCapacity("select")||void0!==c.limit&&!d.hasCapacity("limit")||(f.query=c.query,f.sort_on=c.sort_on,f.select_list=c.select_list,f.limit=c.limit)}catch(i){if(!(iinstanceofa.util.jIOError&&501===i.status_code))throwi;g=!0}try{(g||c.include_docs===!0)&&d.hasCapacity("include")&&(f.include_docs=!0)}catch(i){if(!(iinstanceofa.util.jIOError&&501===i.status_code))throwi;h=!0}returnd.buildQuery(f).push(function(c){functione(b){vare=c[b].id;returnd.get(e).push(function(a){returna._id=e,a},function(b){if(!(binstanceofa.util.jIOError&&404===b.status_code))throwb})}varf,g,i=[c];if(h){for(f=c.length,g=0;f>g;g+=1)i.push(e(g));c=b.all(i)}returnc}).push(function(a){varb,c,d;if(h){for(b=a[0],c=b.length,d=0;c>d;d+=1)b[d].doc=a[d+1];a=b}returna}).push(function(b){vard,f,h=[];if(g){for(d=b.length,f=0;d>f;f+=1)b[f].doc.__id=b[f].id,h.push(b[f].doc);c.select_list&&c.select_list.push("__id"),b=a.QueryFactory.create(c.query||"",e._key_schema).exec(h,c)}returnb}).push(function(a){varb,d,e,f=[];if(g){for(d=a.length,e=0;d>e;e+=1){if(b={id:a[e].__id,value:c.select_list?a[e]:{},doc:{}},c.select_list&&deleteb.value.__id,c.include_docs)thrownewError("QueryStorage does not support include docs");f.push(b)}a=f}returna})}},a.addStorage("query",c)}(jIO,RSVP),function(a,b,c,d){"use strict";functione(a){a.sessiononly===!0?this._storage=b:this._storage=c}functionf(b){if("/"!==b)thrownewa.util.jIOError("id "+b+" is forbidden (!== /)",400)}e.prototype.get=function(a){returnf(a),{}},e.prototype.allAttachments=function(a){f(a);varb,c={};for(binthis._storage)this._storage.hasOwnProperty(b)&&(c[b]={});returnc},e.prototype.getAttachment=function(b,c){f(b);vard=this._storage.getItem(c);if(null===d)thrownewa.util.jIOError("Cannot find attachment "+c,404);returna.util.dataURItoBlob(d)},e.prototype.putAttachment=function(b,c,e){varg=this;returnf(b),(newd.Queue).push(function(){returna.util.readBlobAsDataURL(e)}).push(function(a){g._storage.setItem(c,a.target.result)})},e.prototype.removeAttachment=function(a,b){returnf(a),this._storage.removeItem(b)},e.prototype.hasCapacity=function(a){return"list"===a},e.prototype.buildQuery=function(){return[{id:"/",value:{}}]},a.addStorage("local",e)}(jIO,sessionStorage,localStorage,RSVP),function(a,b,c,d,e,f,g){"use strict";functionh(b,c,f){varh;if(b._no_sub_query_id)thrownewa.util.jIOError("no sub query id active",404);returnh=newd({key:f,value:c,type:"simple"}),void0!==b._query.query&&(h=newe({operator:"AND",query_list:[h,b._query.query],type:"complex"})),h=g.objectToSearchText(h),b._sub_storage.allDocs({query:h,sort_on:b._query.sort_on,select_list:b._query.select_list,limit:b._query.limit}).push(function(b){if(0===b.data.rows.length)thrownewa.util.jIOError("Can not find id",404);if(b.data.rows.length>1)thrownewTypeError("id must be unique field: "+f+", result:"+b.data.rows.toString());returnb.data.rows[0].id})}functioni(b){varc,g=[];for(cinb._mapping_dict)if(b._mapping_dict.hasOwnProperty(c)){if("equalValue"===b._mapping_dict[c][0]){if(void0===b._mapping_dict[c][1])thrownewa.util.jIOError("equalValue has not parameter",400);b._default_mapping[c]=b._mapping_dict[c][1],g.push(newd({key:c,value:b._mapping_dict[c][1],type:"simple"}))}if("equalSubId"===b._mapping_dict[c][0]){if(void0!==b._property_for_sub_id)thrownewa.util.jIOError("equalSubId can be defined one time",400);b._property_for_sub_id=c}}void0!==b._query.query&&g.push(f.create(b._query.query)),g.length>1?b._query.query=newe({type:"complex",query_list:g,operator:"AND"}):1===g.length&&(b._query.query=g[0])}functionj(b){this._mapping_dict=b.property||{},this._sub_storage=a.createJIO(b.sub_storage),this._map_all_property=void0!==b.map_all_property?b.map_all_property:!0,this._no_sub_query_id=b.no_sub_query_id,this._attachment_mapping_dict=b.attachment||{},this._query=b.query||{},this._map_id=b.id||["equalSubId"],this._id_mapped=void0!==b.id?b.id[1]:!1,void0!==this._query.query&&(this._query.query=f.create(this._query.query)),this._default_mapping={},i(this)}functionk(a,b,d,e){varf=a._attachment_mapping_dict;returnvoid0!==f&&void0!==f[d]&&void0!==f[d][e]&&void0!==f[d][e].uri_template?c.parse(f[d][e].uri_template).expand({id:b}):d}functionl(a,c,d){return(newb.Queue).push(function(){varb=a._map_id||["equalSubId"];returna._property_for_sub_id&&void0!==d&&d.hasOwnProperty(a._property_for_sub_id)?d[a._property_for_sub_id]:r[b[0]].mapToSubId(a,d,c,b[1])})}functionm(a,b,c,d,e){varf=a._mapping_dict[b]||["keep"];returnr[f[0]].mapToSubProperty(b,c,d,f[1],e)}functionn(a,b,c,d,e){varf=a._mapping_dict[b]||["keep"];returnr[f[0]].mapToMainProperty(b,c,d,f[1],e)}functiono(a,b,c){vard,e={},f=[a._id_mapped];for(dina._mapping_dict)a._mapping_dict.hasOwnProperty(d)&&f.push(n(a,d,b,e,c));if(a._map_all_property)for(dinb)b.hasOwnProperty(d)&&f.indexOf(d)<0&&(e[d]=b[d]);returnvoid0!==a._map_for_sub_storage_id&&(e[a._map_for_sub_storage_id]=c),e}functionp(a,b,c){vard,e={};for(dinb)b.hasOwnProperty(d)&&m(a,d,e,b,c);for(dina._default_mapping)a._default_mapping.hasOwnProperty(d)&&(e[d]=a._default_mapping[d]);return"equalSubProperty"===a._map_id[0]&&void0!==c&&(e[a._map_id[1]]=c),e}functionq(a,b,c){returnl(a,b[0]).push(function(d){returnb[0]=d,b[1]=k(a,d,b[1],c),a._sub_storage[c+"Attachment"].apply(a._sub_storage,b)})}varr={equalSubProperty:{mapToSubProperty:function(a,b,c,d,e){returnb[d]=c[a],d},mapToMainProperty:function(a,b,c,d,e){returnb.hasOwnProperty(d)&&(c[a]=b[d]),d},mapToSubId:function(a,b,c,d){if(void0!==b){if(a._property_for_sub_id&&b.hasOwnProperty(a._property_for_sub_id))returnb[a._property_for_sub_id];if(b.hasOwnProperty(d))returnb[d]}returnh(a,c,a._map_id[1])},mapToId:function(a,b,c,d){returnb[d]}},equalValue:{mapToSubProperty:function(a,b,c,d){returnb[a]=d,a},mapToMainProperty:function(a){returna}},ignore:{mapToSubProperty:function(){return!1},mapToMainProperty:function(a){returna}},equalSubId:{mapToSubProperty:function(a,b,c){returnb[a]=c[a],a},mapToMainProperty:function(a,b,c,d,e){returnvoid0===e&&b.hasOwnProperty(a)?c[a]=b[a]:c[a]=e,a},mapToSubId:function(a,b,c,d){returnc},mapToId:function(a,b,c){returnc}},keep:{mapToSubProperty:function(a,b,c){returnb[a]=c[a],a},mapToMainProperty:function(a,b,c){returnc[a]=b[a],a}},switchPropertyValue:{mapToSubProperty:function(a,b,c,d){returnb[d[0]]=d[1][c[a]],d[0]},mapToMainProperty:function(a,b,c,d){vare,f=b[d[0]];for(eind[1])if(d[1].hasOwnProperty(e)&&f===d[1][e])returnc[a]=e,a}}};j.prototype.get=function(a){varb=this;returnl(this,a).push(function(a){returnb._sub_storage.get(a).push(function(c){returno(b,c,a)})})},j.prototype.post=function(b){varc=p(this,b),d=b[this._property_for_sub_id];if(this._property_for_sub_id&&void0!==d)returnthis._sub_storage.put(d,c);if(!this._id_mapped||void0!==b[this._id_mapped])returnthis._sub_storage.post(c);thrownewa.util.jIOError("post is not supported with id mapped",400)},j.prototype.put=function(b,c){vard=this,e=p(this,c,b);returnl(this,b,c).push(function(a){returnd._sub_storage.put(a,e)}).push(void0,function(b){if(binstanceofa.util.jIOError&&404===b.status_code)returnd._sub_storage.post(e);throwb}).push(function(){returnb})},j.prototype.remove=function(a){varb=this;returnl(this,a).push(function(a){returnb._sub_storage.remove(a)}).push(function(){returna})},j.prototype.putAttachment=function(a,b){returnq(this,arguments,"put",a).push(function(){returnb})},j.prototype.getAttachment=function(){returnq(this,arguments,"get")},j.prototype.removeAttachment=function(a,b){returnq(this,arguments,"remove",a).push(function(){returnb})},j.prototype.allAttachments=function(a){varb,c=this;returnl(c,a).push(function(a){returnb=a,c._sub_storage.allAttachments(b)}).push(function(a){vard,e={},f={};for(dinc._attachment_mapping_dict)c._attachment_mapping_dict.hasOwnProperty(d)&&(f[k(c,b,d,"get")]=d);for(dina)a.hasOwnProperty(d)&&(f.hasOwnProperty(d)?e[f[d]]={}:e[d]={});