!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.LocoModel=e():t.LocoModel=e()}("undefined"!=typeof self?self:this,function(){return function(t){function e(n){if(r[n])return r[n].exports;var s=r[n]={i:n,l:!1,exports:{}};return t[n].call(s.exports,s,s.exports,e),s.l=!0,s.exports}var r={};return e.m=t,e.c=r,e.d=function(t,r,n){e.o(t,r)||Object.defineProperty(t,r,{configurable:!1,enumerable:!0,get:n})},e.n=function(t){var r=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(r,"a",r),r},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=7)}([function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n,s=r(3),o=r.n(s);n=function(){function t(){this.obj=null,this.attr=null,this.val=null,this.opts=null}return t.sharedInstances={},t.instance=function(t,e,r){var n,s;return s=this.identity,null==this.sharedInstances[s]&&(this.sharedInstances[s]=new o.a[s]),n=this.sharedInstances[s],n.assignAttribs(t,e,r),n},t.prototype.assignAttribs=function(t,e,r){return this.obj=t,this.attr=e,this.val=this.obj[this.attr],this.opts=r},t}(),e.default=n},function(t,e,r){"use strict";function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0});var s=function(){function t(t,e){for(var r=0;rthis._range()[1]?this._selectErrorMessage("too_long",this._range()[1]):null))return this.obj.addErrorMessage(t,{for:this.attr})},e.prototype._range=function(){var t,e;return t=this.opts.minimum||this.opts.is||null!=this.opts.within&&this.opts.within[0]||null,e=this.opts.maximum||this.opts.is||null!=this.opts.within&&this.opts.within[1]||null,[t,e]},e.prototype._selectErrorMessage=function(t,e){var r,n,s,o,a;if(1===e)return i.a[u.a.locale].errors.messages[t].one;for(s=null,o=["few","many"],r=0,n=o.length;r1?(r=this.imap[t][e],r.slice(1,+(r.length-1)+1||9e9)):[]},t}(),e.default=n},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n={};e.default=n},function(t,e,r){"use strict";function n(t){return t&&t.__esModule?t:{default:t}}Object.defineProperty(e,"__esModule",{value:!0}),e.Validators=e.Models=e.IdentityMap=e.I18n=e.Config=e.Base=void 0;var s=r(8),o=n(s),i=r(5),a=n(i),u=r(0),l=n(u),c=r(3),h=n(c),p=r(1),f=n(p),d=r(2),_=n(d),g=r(6),m=n(g);h.default.Base=l.default,m.default.Base=o.default,e.Base=o.default,e.Config=f.default,e.I18n=_.default,e.IdentityMap=a.default,e.Models=m.default,e.Validators=h.default},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n,s=r(3),o=r.n(s),i=r(1),a=r.n(i),u=r(5),l=r(6),c=r.n(l),h=r(18);r.n(h);n=function(){function t(t){null==t&&(t={}),this.id=null,this.errors=null,this.resource=t.resource,null!=this.constructor.attributes&&this.__initAttributes(),null!=t&&this.__assignAttributes(t)}return t.getIdentity=function(){if(null!=this.identity)return this.identity;throw"Specify Model's @identity!"},t.getRemoteName=function(){return null!=this.remoteName?this.remoteName:this.getIdentity()},t.all=function(t){return null==t&&(t={}),this.get("all",t)},t.get=function(t,e){return null==e&&(e={}),this.__send("GET",t,e)},t.post=function(t,e){return null==e&&(e={}),this.__send("POST",t,e)},t.put=function(t,e){return null==e&&(e={}),this.__send("PUT",t,e)},t.patch=function(t,e){return null==e&&(e={}),this.__send("PATCH",t,e)},t.delete=function(t,e){return null==e&&(e={}),this.__send("DELETE",t,e)},t.find=function(t){var e,r,n;return n={},"object"==typeof t?(n=t,e=t.id,delete n.id):e=t,r=Object(h.sendReq)("GET",this.__getResourcesUrl(n)+"/"+e,n),new Promise(function(e){return function(n,s){return r.onerror=function(t){return s(t)},r.onload=function(r){var s;return s=JSON.parse(r.target.response),n(e.__initFromJSON(s,t.resource))}}}(this))},t.getAttribRemoteName=function(t){return null==this.attributes?null:null==this.attributes[t]?null:null==this.attributes[t].remoteName?t:this.attributes[t].remoteName},t.getResourcesUrlParams=function(t){var e,r,n,s;for(s=this.__getResourcesUrl({resource:t.resource}),n=/:(\w+)\/?/,r=[];e=n.exec(s);)r.push(e[1]),s=s.replace(e[0],e[1]);return r},t.__getResourcesUrl=function(t){var e,r;return r=null==this.resources?"/"+this.getRemoteName().toLowerCase()+"s":t.resource?this.resources[t.resource].url:null!=a.a.scope&&null!=this.resources[a.a.scope]?this.resources[a.a.scope].url:this.resources.url,null!=a.a.protocolWithHost&&(r=""+a.a.protocolWithHost+r),null==(e=/:(\w+)\/?/.exec(r))?r:(null!=t[e[1]]?(r=r.replace(":"+e[1],t[e[1]]),delete t[e[1]]):null!=t.obj&&null!=t.obj[e[1]]&&(r=r.replace(":"+e[1],t.obj[e[1]])),r)},t.__initSubclass=function(t){var e,r;return null==t&&(t={}),r=this.getIdentity().split("."),1===r.length?(e=c.a[r[0]],null==e?new this(t):new e(t)):new(e=c.a[r[0]][r[1]])(t)},t.__page=function(t,e,r){var n,s;return s=e.url,e.params[e.pageParam]=t,n=Object(h.sendReq)(e.method,s,e.params),new Promise(function(t){return function(s,o){return n.onerror=function(t){return o(t)},n.onload=function(n){var o,i,a,u,l,c,h,p,f,d;if(o=JSON.parse(n.target.response),o.constructor===Array)for(i=0,l=o.length;i=u;s=2<=u?++o:--o)(function(t){return a=a.then(function(s){return r.__page(t,e,n)})})(s);return a}}(this))},t.__getPaginationParam=function(t){var e,r,n,s,o,i;return e="page",null!=t&&null!=this.resources&&this.resources[t]?(null!=(r=this.resources[t].paginate)?r.param:void 0)||e:null!=a.a.scope&&null!=this.resources&&null!=this.resources[a.a.scope]?(null!=(n=this.resources[a.a.scope])&&null!=(s=n.paginate)?s.param:void 0)||e:null!=(null!=(o=this.resources)&&null!=(i=o.paginate)?i.param:void 0)?this.resources.paginate.param:e},t.__getPaginationPer=function(t){var e,r,n,s,o;return null!=t&&null!=this.resources&&this.resources[t]?null!=(e=this.resources[t].paginate)?e.per:void 0:null!=a.a.scope&&null!=this.resources&&null!=this.resources[a.a.scope]?null!=(r=this.resources[a.a.scope])&&null!=(n=r.paginate)?n.per:void 0:null!=(null!=(s=this.resources)&&null!=(o=s.paginate)?o.per:void 0)?this.resources.paginate.per:null},t.__send=function(t,e,r){var n,s;return s=this.__getResourcesUrl(r),"all"!==e&&(s=s+"/"+e),n={method:t,url:s,params:r,resource:r.resource,perPage:this.__getPaginationPer(r.resource),pageNum:r.page,pageParam:this.__getPaginationParam(r.resource),total:r.total||r.count},this.__paginate(n)},t.__initFromJSON=function(t,e){var r;return r=this.__initSubclass(t),r.resource=e,u.default.add(r),r},t.prototype.setResource=function(t){return this.resource=t},t.prototype.getIdentity=function(){return this.constructor.getIdentity()},t.prototype.getAttrRemoteName=function(t){return null==this.constructor.attributes?null:null==this.constructor.attributes[t]?null:this.constructor.attributes[t].remoteName||t},t.prototype.getAttrName=function(t){var e,r,n;if(null==this.constructor.attributes)return t;if(null!=this.constructor.attributes[t])return t;n=this.constructor.attributes;for(r in n)if(e=n[r],e.remoteName===t)return r;return t},t.prototype.getAttrType=function(t){return null==this.constructor.attributes?null:null==this.constructor.attributes[t]?null:this.constructor.attributes[t].type},t.prototype.assignAttr=function(t,e){var r;if(r=this.getAttrType(t),null==e)return void(this[t]=null);switch(r){case"Date":e=new Date(Date.parse(e));break;case"Integer":case"Int":e=parseInt(e);break;case"Float":e=parseFloat(e);break;case"Boolean":case"Bool":e="boolean"==typeof e?e:Boolean(parseInt(e));break;case"Number":e=Number(e);break;case"String":e=String(e)}return this[t]=e},t.prototype.attributes=function(){var t,e,r;if(t={id:this.id},null==this.constructor.attributes)return t;r=this.constructor.attributes;for(e in r)r[e],t[e]=this[e];return t},t.prototype.isValid=function(){var t,e,r,n,s,i,a,u,l,c,h,p;if(null==this.constructor.attributes)return!0;this.errors=null,a=this.constructor.attributes;for(s in a)if(t=a[s],null!=t.validations){u=t.validations;for(c in u)h=u[c],null!=this.id&&"create"===h.on||null==this.id&&"update"===h.on||(null==h.if||h.if(this))&&(p=c.charAt(0).toUpperCase()+c.slice(1),null!=o.a[p]?(i=this.__processedValidationSettings(h),o.a[p].instance(this,s,i).validate()):console.warn('"'+p+'" validator is not implemented!'))}if(null!=this.constructor.validate)for(l=this.constructor.validate,e=0,r=l.length;e=200&&e.target.status<400?(s=JSON.parse(e.target.response),s.success?void r(s):(null!=s.errors&&t.__assignRemoteErrorMessages(s.errors),r(s))):e.target.status>=500?n(e):void 0}}}(this))},t.prototype.serialize=function(t){var e,r,n,s;if(null==t&&(t=null),null==this.constructor.attributes)return{};r={},n=this.constructor.getRemoteName().toLowerCase(),r[n]={},e={},null!=t?e[t]=null:e=this.constructor.attributes;for(t in e)e[t],s=this.getAttrRemoteName(t),r[n][s]=this[t];return r},t.prototype.reload=function(){var t,e,r,n,s;for(t={id:this.id,resource:this.resource},s=this.constructor.getResourcesUrlParams({resource:this.resource}),e=0,r=s.length;e=200&&n.target.status<400?(r=JSON.parse(n.target.response),t(r)):n.target.status>=500?e(n):void 0}})},t.prototype.__assignAttributes=function(t){var e,r,n,s;n=[];for(r in t)s=t[r],e=this.getAttrName(r),n.push(this.assignAttr(e,s));return n},t.prototype.__initAttributes=function(){var t,e,r;e=this.constructor.attributes,r=[];for(t in e)e[t],r.push(this[t]=null);return r},t.prototype.__assignRemoteErrorMessages=function(t){var e,r,n,s,o;o=[];for(s in t)n=t[s],e=this.getAttrName(s),o.push(function(){var t,s,o;for(o=[],t=0,s=n.length;t=this.opts.less_than?this._addLessThanErrorMessage():null!=this.opts.less_than_or_equal_to&&Number(this.val)>this.opts.less_than_or_equal_to?this._addLessThanOrEqualToErrorMessage():null!=this.opts.other_than&&Number(this.val)===this.opts.other_than?this._addOtherThanErrorMessage():null!=this.opts.odd&&Number(this.val)%2!=1?this._addOddErrorMessage():null!=this.opts.even&&Number(this.val)%2!=0?this._addEvenErrorMessage():void 0},e.prototype._addNaNErrorMessage=function(){var t;return t=null!=this.opts.message?this.opts.message:i.a[u.a.locale].errors.messages.not_a_number,this.obj.addErrorMessage(t,{for:this.attr})},e.prototype._addIntErrorMessage=function(){var t;return t=i.a[u.a.locale].errors.messages.not_an_integer,this.obj.addErrorMessage(t,{for:this.attr})},e.prototype._addGreatherThanErrorMessage=function(){var t;return t=i.a[u.a.locale].errors.messages.greater_than,t=t.replace("%{count}",this.opts.greater_than),this.obj.addErrorMessage(t,{for:this.attr})},e.prototype._addGreatherThanOrEqualToErrorMessage=function(){var t;return t=i.a[u.a.locale].errors.messages.greater_than_or_equal_to,t=t.replace("%{count}",this.opts.greater_than_or_equal_to),this.obj.addErrorMessage(t,{for:this.attr})},e.prototype._addEqualToErrorMessage=function(){var t;return t=i.a[u.a.locale].errors.messages.equal_to,t=t.replace("%{count}",this.opts.equal_to),this.obj.addErrorMessage(t,{for:this.attr})},e.prototype._addLessThanErrorMessage=function(){var t;return t=i.a[u.a.locale].errors.messages.less_than,t=t.replace("%{count}",this.opts.less_than),this.obj.addErrorMessage(t,{for:this.attr})},e.prototype._addLessThanOrEqualToErrorMessage=function(){var t;return t=i.a[u.a.locale].errors.messages.less_than_or_equal_to,t=t.replace("%{count}",this.opts.less_than_or_equal_to),this.obj.addErrorMessage(t,{for:this.attr})},e.prototype._addOtherThanErrorMessage=function(){var t;return t=i.a[u.a.locale].errors.messages.other_than,t=t.replace("%{count}",this.opts.other_than),this.obj.addErrorMessage(t,{for:this.attr})},e.prototype._addOddErrorMessage=function(){var t;return t=i.a[u.a.locale].errors.messages.odd,this.obj.addErrorMessage(t,{for:this.attr})},e.prototype._addEvenErrorMessage=function(){var t;return t=i.a[u.a.locale].errors.messages.even,this.obj.addErrorMessage(t,{for:this.attr})},e}(s.default),e.default=n},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n,s=r(0),o=r(2),i=r.n(o),a=r(1),u=r.n(a),l=function(t,e){function r(){this.constructor=t}for(var n in e)c.call(e,n)&&(t[n]=e[n]);return r.prototype=e.prototype,t.prototype=new r,t.__super__=e.prototype,t},c={}.hasOwnProperty;n=function(t){function e(){e.__super__.constructor.call(this)}return l(e,t),e.identity="Presence",e.prototype.validate=function(){switch(typeof this.val){case"string":if(null!=this.val&&this.val.length>0)return;break;default:if(null!=this.val)return}return this._addErrorMessage()},e.prototype._addErrorMessage=function(){var t;return t=null!=this.opts.message?this.opts.message:i.a[u.a.locale].errors.messages.blank,this.obj.addErrorMessage(t,{for:this.attr})},e}(s.default),e.default=n},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n,s=r(0),o=r(4),i=function(t,e){function r(){this.constructor=t}for(var n in e)a.call(e,n)&&(t[n]=e[n]);return r.prototype=e.prototype,t.prototype=new r,t.__super__=e.prototype,t},a={}.hasOwnProperty;n=function(t){function e(){e.__super__.constructor.call(this)}return i(e,t),e.identity="Size",e.prototype.validate=function(){return o.default.instance(this.obj,this.attr,this.opts).validate()},e}(s.default),e.default=n},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.sendReq=void 0;var n=r(19),s=function(t){var e={};if(!t)return e;var r=["resource","total","count"];return Object.keys(t).forEach(function(n){-1===r.indexOf(n)&&(e[n]=t[n])}),e},o=e.sendReq=function(t,e,r){var o=s(r),i="GET"===t?e+"?"+(0,n.toURIParams)(o):e,a=document.querySelector("meta[name='csrf-token']"),u=new XMLHttpRequest;return u.open(t,i),u.setRequestHeader("Accept","application/json"),u.setRequestHeader("Content-Type","application/json"),a&&u.setRequestHeader("X-CSRF-Token",a.content),u.send(JSON.stringify(o)),u};e.default=o},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n=e.toURIParams=function(t){var e="";return Object.keys(t).forEach(function(r){""!==e&&(e+="&"),e=""+e+r+"="+encodeURIComponent(t[r])}),e};e.default=n}])});