Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

loco-js-model

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

loco-js-model - npm Package Compare versions

Comparing version 0.0.3 to 0.1.0

.browserslistrc

1874

dist/loco-model.js

@@ -1,1873 +0,1 @@

(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
else if(typeof exports === 'object')
exports["LocoModel"] = factory();
else
root["LocoModel"] = factory();
})(this, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 6);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Base", function() { return Base; });
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__validators__ = __webpack_require__(3);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__validators___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0__validators__);
var Base;
Base = (function() {
Base.sharedInstances = {};
Base.instance = function(obj, attr, opts) {
var sharedInstance, validatorName;
validatorName = this.identity;
if (this.sharedInstances[validatorName] == null) {
this.sharedInstances[validatorName] = new __WEBPACK_IMPORTED_MODULE_0__validators__["Validators"][validatorName];
}
sharedInstance = this.sharedInstances[validatorName];
sharedInstance.assignAttribs(obj, attr, opts);
return sharedInstance;
};
function Base() {
this.obj = null;
this.attr = null;
this.val = null;
this.opts = null;
}
Base.prototype.assignAttribs = function(obj, attr, opts) {
this.obj = obj;
this.attr = attr;
this.val = this.obj[this.attr];
return this.opts = opts;
};
return Base;
})();
/***/ }),
/* 1 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var LocalEnv = {
loco: {
getLocale: function getLocale() {
return 'en';
},
protocolWithHost: null
},
scope: null
};
var Env = function Env() {
if (typeof App === 'undefined') {
return LocalEnv;
}
return App.Env;
};
exports.Env = Env;
/***/ }),
/* 2 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.I18n = undefined;
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _en = __webpack_require__(9);
var I18n = function I18n() {
if (typeof App !== 'undefined') {
return _extends({ en: _en.en }, App.I18n);
}
return { en: _en.en };
};
exports.I18n = I18n;
/***/ }),
/* 3 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Validators = undefined;
var _absence = __webpack_require__(8);
var _confirmation = __webpack_require__(10);
var _exclusion = __webpack_require__(11);
var _format = __webpack_require__(12);
var _inclusion = __webpack_require__(13);
var _length = __webpack_require__(4);
var _numericality = __webpack_require__(14);
var _presence = __webpack_require__(15);
var _size = __webpack_require__(16);
var Validators = {
Absence: _absence.Absence,
Confirmation: _confirmation.Confirmation,
Exclusion: _exclusion.Exclusion,
Format: _format.Format,
Inclusion: _inclusion.Inclusion,
Length: _length.Length,
Numericality: _numericality.Numericality,
Presence: _presence.Presence,
Size: _size.Size
};
exports.Validators = Validators;
/***/ }),
/* 4 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Length", function() { return Length; });
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__base_coffee__ = __webpack_require__(0);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__i18n__ = __webpack_require__(2);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__i18n___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_1__i18n__);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__env__ = __webpack_require__(1);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__env___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_2__env__);
var Length,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Length = (function(superClass) {
extend(Length, superClass);
Length.identity = "Length";
function Length() {
Length.__super__.constructor.call(this);
}
Length.prototype.validate = function() {
var message;
if (this.val == null) {
return;
}
message = (this._range()[0] != null) && (this._range()[1] != null) && this._range()[0] === this._range()[1] && this.val.length !== this._range()[0] ? this._selectErrorMessage('wrong_length', this._range()[0]) : (this._range()[0] != null) && this.val.length < this._range()[0] ? this._selectErrorMessage('too_short', this._range()[0]) : (this._range()[1] != null) && this.val.length > this._range()[1] ? this._selectErrorMessage('too_long', this._range()[1]) : null;
if (message === null) {
return;
}
return this.obj.addErrorMessage(message, {
"for": this.attr
});
};
Length.prototype._range = function() {
var from, to;
from = this.opts.minimum || this.opts.is || ((this.opts.within != null) && this.opts.within[0]) || null;
to = this.opts.maximum || this.opts.is || ((this.opts.within != null) && this.opts.within[1]) || null;
return [from, to];
};
Length.prototype._selectErrorMessage = function(msg, val) {
var i, len, message, ref, variant;
if (val === 1) {
return Object(__WEBPACK_IMPORTED_MODULE_1__i18n__["I18n"])()[Object(__WEBPACK_IMPORTED_MODULE_2__env__["Env"])().loco.getLocale()].errors.messages[msg].one;
}
message = null;
ref = ['few', 'many'];
for (i = 0, len = ref.length; i < len; i++) {
variant = ref[i];
if (this._checkVariant(variant, val)) {
message = Object(__WEBPACK_IMPORTED_MODULE_1__i18n__["I18n"])()[Object(__WEBPACK_IMPORTED_MODULE_2__env__["Env"])().loco.getLocale()].errors.messages[msg][variant];
break;
}
}
if (message == null) {
message = Object(__WEBPACK_IMPORTED_MODULE_1__i18n__["I18n"])()[Object(__WEBPACK_IMPORTED_MODULE_2__env__["Env"])().loco.getLocale()].errors.messages[msg].other;
}
if (this.opts.message != null) {
message = this.opts.message;
}
if (/%{count}/.exec(message)) {
message = message.replace('%{count}', val);
}
return message;
};
Length.prototype._checkVariant = function(variant, val) {
if (Object(__WEBPACK_IMPORTED_MODULE_1__i18n__["I18n"])()[Object(__WEBPACK_IMPORTED_MODULE_2__env__["Env"])().loco.getLocale()].variants[variant] == null) {
return;
}
return Object(__WEBPACK_IMPORTED_MODULE_1__i18n__["I18n"])()[Object(__WEBPACK_IMPORTED_MODULE_2__env__["Env"])().loco.getLocale()].variants[variant](val);
};
return Length;
})(__WEBPACK_IMPORTED_MODULE_0__base_coffee__["Base"]);
/***/ }),
/* 5 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "IdentityMap", function() { return IdentityMap; });
var IdentityMap;
IdentityMap = (function() {
function IdentityMap() {}
IdentityMap.imap = {};
IdentityMap.clear = function() {
return this.imap = {};
};
IdentityMap.add = function(obj) {
var identity;
identity = obj.getIdentity();
if (this.imap[identity] == null) {
this.imap[identity] = {};
}
if (this.imap[identity][obj.id] == null) {
this.imap[identity][obj.id] = [];
}
return this.imap[identity][obj.id][0] = obj;
};
IdentityMap.connect = function(obj, opts) {
var model;
if (opts == null) {
opts = {};
}
model = opts["with"];
this.add(model);
return this.imap[model.getIdentity()][model.id].push(obj);
};
IdentityMap.addCollection = function(identity, opts) {
if (opts == null) {
opts = {};
}
if (this.imap[identity] == null) {
this.imap[identity] = {};
}
if (this.imap[identity]["collection"] == null) {
this.imap[identity]["collection"] = [];
}
if (this.imap[identity]["collection"].indexOf(opts.to) !== -1) {
return;
}
return this.imap[identity]["collection"].push(opts.to);
};
IdentityMap.all = function(identity) {
var arr, id, objs, ref;
if (this.imap[identity] == null) {
return null;
}
arr = [];
ref = this.imap[identity];
for (id in ref) {
objs = ref[id];
if (id === "collection") {
continue;
}
arr.push(objs[0]);
}
return arr;
};
IdentityMap.find = function(klass, id) {
if (this.imap[klass] && this.imap[klass][id]) {
return this.imap[klass][id][0];
} else {
return null;
}
};
IdentityMap.findConnected = function(klass, id) {
var arr;
if (this.imap[klass] && this.imap[klass][id] && this.imap[klass][id].length > 1) {
arr = this.imap[klass][id];
return arr.slice(1, +(arr.length - 1) + 1 || 9e9);
} else {
return [];
}
};
return IdentityMap;
})();
/***/ }),
/* 6 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Validators = exports.IdentityMap = exports.Base = undefined;
var _base = __webpack_require__(7);
var _identity_map = __webpack_require__(5);
var _base2 = __webpack_require__(0);
var _validators = __webpack_require__(3);
_validators.Validators.Base = _base2.Base;
exports.Base = _base.Base;
exports.IdentityMap = _identity_map.IdentityMap;
exports.Validators = _validators.Validators;
/***/ }),
/* 7 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Base", function() { return Base; });
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__validators__ = __webpack_require__(3);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__validators___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0__validators__);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__env__ = __webpack_require__(1);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__env___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_1__env__);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__utils__ = __webpack_require__(17);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__utils___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_2__utils__);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__identity_map_coffee__ = __webpack_require__(5);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__models__ = __webpack_require__(19);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__models___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_4__models__);
var Base;
Base = (function() {
function Base(data) {
if (data == null) {
data = {};
}
this.id = null;
this.errors = null;
this.resource = data.resource;
if (this.constructor.attributes != null) {
this.__initAttributes();
}
if (data != null) {
this.__assignAttributes(data);
}
}
Base.all = function(opts) {
if (opts == null) {
opts = {};
}
return this.get("all", opts);
};
Base.find = function(idOrObj) {
var id, req, urlParams;
urlParams = {};
if (typeof idOrObj === "object") {
urlParams = idOrObj;
id = idOrObj.id;
delete urlParams.id;
} else {
id = idOrObj;
}
req = new XMLHttpRequest();
req.open('GET', (this.__getResourcesUrl(urlParams)) + "/" + id);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json");
req.send(JSON.stringify(urlParams));
return new Promise((function(_this) {
return function(resolve, reject) {
req.onerror = function(e) {
return reject(e);
};
return req.onload = function(e) {
var obj, record;
record = JSON.parse(e.target.response);
obj = _this.__initSubclass(record);
__WEBPACK_IMPORTED_MODULE_3__identity_map_coffee__["IdentityMap"].add(obj);
return resolve(obj);
};
};
})(this));
};
Base.get = function(action, opts) {
if (opts == null) {
opts = {};
}
return this.__send("GET", action, opts);
};
Base.post = function(action, opts) {
if (opts == null) {
opts = {};
}
return this.__send("POST", action, opts);
};
Base.put = function(action, opts) {
if (opts == null) {
opts = {};
}
return this.__send("PUT", action, opts);
};
Base["delete"] = function(action, opts) {
if (opts == null) {
opts = {};
}
return this.__send("DELETE", action, opts);
};
Base.getIdentity = function() {
if (this.identity != null) {
return this.identity;
} else {
throw "Specify Model's @identity!";
}
};
Base.getRemoteName = function() {
if (this.remoteName != null) {
return this.remoteName;
} else {
return this.getIdentity();
}
};
Base.getAttribRemoteName = function(attrib) {
if (this.attributes == null) {
return null;
}
if (this.attributes[attrib] == null) {
return null;
}
if (this.attributes[attrib].remoteName == null) {
return attrib;
}
return this.attributes[attrib].remoteName;
};
Base.getResourcesUrlParams = function() {
var match, params, regexp, url;
url = this.__getResourcesUrl();
regexp = /:(\w+)\/?/;
params = [];
while (match = regexp.exec(url)) {
params.push(match[1]);
url = url.replace(match[0], match[1]);
}
return params;
};
Base.__getResourcesUrl = function(opts) {
var match, resourcesUrl;
if (opts == null) {
opts = {};
}
resourcesUrl = this.resources == null ? "/" + (this.getRemoteName().toLowerCase()) + "s" : opts.resource ? this.resources[opts.resource].url : (Object(__WEBPACK_IMPORTED_MODULE_1__env__["Env"])().scope != null) && (this.resources[Object(__WEBPACK_IMPORTED_MODULE_1__env__["Env"])().scope] != null) ? this.resources[Object(__WEBPACK_IMPORTED_MODULE_1__env__["Env"])().scope].url : this.resources.url;
if (Object(__WEBPACK_IMPORTED_MODULE_1__env__["Env"])().loco.protocolWithHost != null) {
resourcesUrl = "" + (Object(__WEBPACK_IMPORTED_MODULE_1__env__["Env"])().loco.protocolWithHost) + resourcesUrl;
}
match = /:(\w+)\/?/.exec(resourcesUrl);
if (match == null) {
return resourcesUrl;
}
if (opts[match[1]] != null) {
resourcesUrl = resourcesUrl.replace(":" + match[1], opts[match[1]]);
delete opts[match[1]];
} else if ((opts.obj != null) && (opts.obj[match[1]] != null)) {
resourcesUrl = resourcesUrl.replace(":" + match[1], opts.obj[match[1]]);
}
return resourcesUrl;
};
Base.__initSubclass = function(params) {
var model, parts;
if (params == null) {
params = {};
}
parts = this.getIdentity().split(".");
if (parts.length === 1) {
model = Object(__WEBPACK_IMPORTED_MODULE_4__models__["Models"])()[parts[0]];
if (model == null) {
return new this(params);
}
return new model(params);
}
model = Object(__WEBPACK_IMPORTED_MODULE_4__models__["Models"])()[parts[0]][parts[1]];
return new model(params);
};
Base.__page = function(i, opts, reqOpts, resp) {
var data, httpMethod, key, ref, ref1, req, url, val;
if (opts == null) {
opts = {};
}
if (reqOpts == null) {
reqOpts = {};
}
if (resp == null) {
resp = {
resources: [],
count: 0
};
}
httpMethod = reqOpts.method || "GET";
url = reqOpts.url || this.__getResourcesUrl(opts);
data = {};
if (reqOpts.data != null) {
ref = reqOpts.data;
for (key in ref) {
val = ref[key];
if (key === "resource") {
continue;
}
data[key] = val;
}
}
data[this.__getPaginationParam()] = i;
if (httpMethod === 'GET') {
url = url + '?' + __WEBPACK_IMPORTED_MODULE_2__utils__["Utils"].Obj.toURIParams(data);
}
req = new XMLHttpRequest();
req.open(httpMethod, url);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json");
req.setRequestHeader("X-CSRF-Token", (ref1 = document.querySelector("meta[name='csrf-token']")) != null ? ref1.content : void 0);
req.send(JSON.stringify(data));
return new Promise((function(_this) {
return function(resolve, reject) {
req.onerror = function(e) {
return reject(e);
};
return req.onload = function(e) {
var j, len, obj, record, ref2;
data = JSON.parse(e.target.response);
resp.count = data.count;
for (key in data) {
val = data[key];
if (['resources', 'count'].indexOf(key) === -1) {
resp[key] = val;
}
}
ref2 = data.resources;
for (j = 0, len = ref2.length; j < len; j++) {
record = ref2[j];
obj = _this.__initSubclass(record);
if (opts.resource != null) {
obj.resource = opts.resource;
}
__WEBPACK_IMPORTED_MODULE_3__identity_map_coffee__["IdentityMap"].add(obj);
resp.resources.push(obj);
}
return resolve(resp);
};
};
})(this));
};
Base.__paginate = function(opts, reqOpts) {
var pageNum, perPage, ref;
perPage = this.__getPaginationPer();
pageNum = (ref = opts.page) != null ? ref : 1;
return this.__page(pageNum, opts, reqOpts).then((function(_this) {
return function(data) {
var func, i, j, max, promise, ref1;
if (opts.page != null) {
return Promise.resolve(data);
}
if (data.count <= perPage) {
return Promise.resolve(data);
}
max = parseInt(data.count / perPage);
if (max !== data.count / perPage) {
max += 1;
}
promise = Promise.resolve(data);
if (max === 1) {
return promise;
}
for (i = j = 2, ref1 = max; 2 <= ref1 ? j <= ref1 : j >= ref1; i = 2 <= ref1 ? ++j : --j) {
func = function(i) {
return promise = promise.then(function(arr) {
return _this.__page(i, opts, reqOpts, data);
});
};
func(i);
}
return promise;
};
})(this));
};
Base.__getPaginationParam = function() {
var defaultParam, param, ref, ref1, ref2, ref3;
defaultParam = 'page';
if ((Object(__WEBPACK_IMPORTED_MODULE_1__env__["Env"])().scope != null) && (this.resources != null) && (this.resources[Object(__WEBPACK_IMPORTED_MODULE_1__env__["Env"])().scope] != null)) {
param = (ref = this.resources[Object(__WEBPACK_IMPORTED_MODULE_1__env__["Env"])().scope]) != null ? (ref1 = ref.paginate) != null ? ref1.param : void 0 : void 0;
return param != null ? param : defaultParam;
}
if (((ref2 = this.resources) != null ? (ref3 = ref2.paginate) != null ? ref3.param : void 0 : void 0) != null) {
return this.resources.paginate.param;
}
return defaultParam;
};
Base.__getPaginationPer = function() {
var ref, ref1, ref2, ref3;
if ((Object(__WEBPACK_IMPORTED_MODULE_1__env__["Env"])().scope != null) && (this.resources != null) && (this.resources[Object(__WEBPACK_IMPORTED_MODULE_1__env__["Env"])().scope] != null)) {
return (ref = this.resources[Object(__WEBPACK_IMPORTED_MODULE_1__env__["Env"])().scope]) != null ? (ref1 = ref.paginate) != null ? ref1.per : void 0 : void 0;
}
if (((ref2 = this.resources) != null ? (ref3 = ref2.paginate) != null ? ref3.per : void 0 : void 0) != null) {
return this.resources.paginate.per;
}
return null;
};
Base.__send = function(method, action, opts) {
var reqOpts, url;
url = this.__getResourcesUrl(opts);
if (action !== "all") {
url = url + "/" + action;
}
reqOpts = {
method: method,
url: url,
data: opts
};
return this.__paginate(opts, reqOpts);
};
Base.prototype.setResource = function(name) {
return this.resource = name;
};
Base.prototype.getIdentity = function() {
return this.constructor.getIdentity();
};
Base.prototype.getAttrRemoteName = function(attr) {
if (this.constructor.attributes == null) {
return null;
}
if (this.constructor.attributes[attr] == null) {
return null;
}
return this.constructor.attributes[attr].remoteName || attr;
};
Base.prototype.getAttrName = function(remoteName) {
var config, name, ref;
if (this.constructor.attributes == null) {
return remoteName;
}
if (this.constructor.attributes[remoteName] != null) {
return remoteName;
}
ref = this.constructor.attributes;
for (name in ref) {
config = ref[name];
if (config.remoteName === remoteName) {
return name;
}
}
return remoteName;
};
Base.prototype.getAttrType = function(attrName) {
if (this.constructor.attributes == null) {
return null;
}
if (this.constructor.attributes[attrName] == null) {
return null;
}
return this.constructor.attributes[attrName].type;
};
Base.prototype.assignAttr = function(attrName, val) {
var attrType;
attrType = this.getAttrType(attrName);
if (val == null) {
this[attrName] = null;
return;
}
switch (attrType) {
case "Date":
val = new Date(Date.parse(val));
break;
case "Integer":
case "Int":
val = parseInt(val);
break;
case "Float":
val = parseFloat(val);
break;
case "Boolean":
case "Bool":
val = typeof val === 'boolean' ? val : Boolean(parseInt(val));
break;
case "Number":
val = Number(val);
break;
case "String":
val = String(val);
}
return this[attrName] = val;
};
Base.prototype.attributes = function() {
var _, attribs, name, ref;
attribs = {
id: this.id
};
if (this.constructor.attributes == null) {
return attribs;
}
ref = this.constructor.attributes;
for (name in ref) {
_ = ref[name];
attribs[name] = this[name];
}
return attribs;
};
Base.prototype.isValid = function() {
var config, j, len, meth, name, pvs, ref, ref1, ref2, validationName, validationSettings, validator;
if (this.constructor.attributes == null) {
return true;
}
this.errors = null;
ref = this.constructor.attributes;
for (name in ref) {
config = ref[name];
if (config.validations == null) {
continue;
}
ref1 = config.validations;
for (validationName in ref1) {
validationSettings = ref1[validationName];
if ((this.id != null) && validationSettings.on === "create") {
continue;
}
if ((this.id == null) && validationSettings.on === "update") {
continue;
}
if ((validationSettings["if"] != null) && !validationSettings["if"](this)) {
continue;
}
validator = validationName.charAt(0).toUpperCase() + validationName.slice(1);
if (__WEBPACK_IMPORTED_MODULE_0__validators__["Validators"][validator] == null) {
console.log("Warning! \"" + validator + "\" validator is not implemented!");
continue;
}
pvs = this.__processedValidationSettings(validationSettings);
__WEBPACK_IMPORTED_MODULE_0__validators__["Validators"][validator].instance(this, name, pvs).validate();
}
}
if (this.constructor.validate != null) {
ref2 = this.constructor.validate;
for (j = 0, len = ref2.length; j < len; j++) {
meth = ref2[j];
this[meth]();
}
}
if (this.errors != null) {
return false;
} else {
return true;
}
};
Base.prototype.isInvalid = function() {
return !this.isValid();
};
Base.prototype.isEmpty = function() {
var name, ref, val;
ref = this.attributes();
for (name in ref) {
val = ref[name];
if (this[name] !== null) {
return false;
}
}
return true;
};
Base.prototype.addErrorMessage = function(message, opts) {
if (opts == null) {
opts = {};
}
if (this.errors == null) {
this.errors = {};
}
if (this.errors[opts["for"]] == null) {
this.errors[opts["for"]] = [];
}
return this.errors[opts["for"]].push(message);
};
Base.prototype.save = function() {
var httpMeth, ref, req;
httpMeth = this.id != null ? "PUT" : "POST";
req = new XMLHttpRequest();
req.open(httpMeth, this.__getResourceUrl());
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json");
req.setRequestHeader("X-CSRF-Token", (ref = document.querySelector("meta[name='csrf-token']")) != null ? ref.content : void 0);
req.send(JSON.stringify(this.serialize()));
return new Promise((function(_this) {
return function(resolve, reject) {
req.onerror = function(e) {
return reject(e);
};
return req.onload = function(e) {
var data;
data = JSON.parse(e.target.response);
if (data.success) {
resolve(data);
return;
}
if (data.errors != null) {
_this.__assignRemoteErrorMessages(data.errors);
}
return resolve(data);
};
};
})(this));
};
Base.prototype.updateAttribute = function(attr) {
var ref, req;
req = new XMLHttpRequest();
req.open('PUT', this.__getResourceUrl());
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json");
req.setRequestHeader("X-CSRF-Token", (ref = document.querySelector("meta[name='csrf-token']")) != null ? ref.content : void 0);
req.send(JSON.stringify(this.serialize(attr)));
return new Promise((function(_this) {
return function(resolve, reject) {
req.onerror = function(e) {
return reject(e);
};
return req.onload = function(e) {
var data;
if (e.target.status >= 200 && e.target.status < 400) {
data = JSON.parse(e.target.response);
if (data.success) {
resolve(data);
return;
}
if (data.errors != null) {
_this.__assignRemoteErrorMessages(data.errors);
}
return resolve(data);
} else if (e.target.status >= 500) {
return reject(e);
}
};
};
})(this));
};
Base.prototype.serialize = function(attr) {
var _, attribs, hash, mainKey, remoteName;
if (attr == null) {
attr = null;
}
if (this.constructor.attributes == null) {
return {};
}
hash = {};
mainKey = this.constructor.getRemoteName().toLowerCase();
hash[mainKey] = {};
attribs = {};
if (attr != null) {
attribs[attr] = null;
} else {
attribs = this.constructor.attributes;
}
for (attr in attribs) {
_ = attribs[attr];
remoteName = this.getAttrRemoteName(attr);
hash[mainKey][remoteName] = this[attr];
}
return hash;
};
Base.prototype.reload = function() {
var findParams, j, len, param, ref;
findParams = {
id: this.id
};
ref = this.constructor.getResourcesUrlParams();
for (j = 0, len = ref.length; j < len; j++) {
param = ref[j];
findParams[param] = this[param];
}
return this.constructor.find(findParams);
};
Base.prototype.changes = function() {
var currentObj, name, ref, result, val;
result = {};
currentObj = __WEBPACK_IMPORTED_MODULE_3__identity_map_coffee__["IdentityMap"].find(this.getIdentity(), this.id);
ref = this.attributes();
for (name in ref) {
val = ref[name];
if (val !== currentObj[name]) {
if ((val != null) && val.constructor === Date && currentObj[name] - val === 0) {
continue;
}
if (val !== currentObj[name]) {
result[name] = {
is: currentObj[name],
was: val
};
}
}
}
return result;
};
Base.prototype.applyChanges = function() {
var name, ref, results, vals;
ref = this.changes();
results = [];
for (name in ref) {
vals = ref[name];
results.push(this[name] = vals.is);
}
return results;
};
Base.prototype.toKey = function() {
return (this.getIdentity().toLowerCase()) + "_" + this.id;
};
Base.prototype.get = function(action, data) {
if (data == null) {
data = {};
}
return this.__send("GET", action, data);
};
Base.prototype.post = function(action, data) {
if (data == null) {
data = {};
}
return this.__send("POST", action, data);
};
Base.prototype.put = function(action, data) {
if (data == null) {
data = {};
}
return this.__send("PUT", action, data);
};
Base.prototype.patch = function(action, data) {
if (data == null) {
data = {};
}
return this.__send("PATCH", action, data);
};
Base.prototype["delete"] = function(action, data) {
if (data == null) {
data = {};
}
return this.__send("DELETE", action, data);
};
Base.prototype.__send = function(method, action, data) {
var ref, req, url;
url = this.__getResourceUrl();
if (action != null) {
url = url + "/" + action;
}
req = new XMLHttpRequest();
req.open(method, url);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json");
req.setRequestHeader("X-CSRF-Token", (ref = document.querySelector("meta[name='csrf-token']")) != null ? ref.content : void 0);
req.send(JSON.stringify(data));
return new Promise(function(resolve, reject) {
req.onerror = function(e) {
return reject(e);
};
return req.onload = function(e) {
if (e.target.status >= 200 && e.target.status < 400) {
data = JSON.parse(e.target.response);
return resolve(data);
} else if (e.target.status >= 500) {
return reject(e);
}
};
});
};
Base.prototype.__assignAttributes = function(data) {
var attrName, key, results, val;
results = [];
for (key in data) {
val = data[key];
attrName = this.getAttrName(key);
results.push(this.assignAttr(attrName, val));
}
return results;
};
Base.prototype.__initAttributes = function() {
var config, name, ref, results;
ref = this.constructor.attributes;
results = [];
for (name in ref) {
config = ref[name];
results.push(this[name] = null);
}
return results;
};
Base.prototype.__assignRemoteErrorMessages = function(remoteErrors) {
var attr, error, errors, remoteName, results;
results = [];
for (remoteName in remoteErrors) {
errors = remoteErrors[remoteName];
attr = this.getAttrName(remoteName);
results.push((function() {
var j, len, results1;
results1 = [];
for (j = 0, len = errors.length; j < len; j++) {
error = errors[j];
results1.push(this.addErrorMessage(error, {
"for": attr
}));
}
return results1;
}).call(this));
}
return results;
};
Base.prototype.__getResourceUrl = function() {
var url;
url = this.constructor.__getResourcesUrl({
resource: this.resource,
obj: this
});
if (this.id == null) {
return url;
}
return url + "/" + this.id;
};
Base.prototype.__processedValidationSettings = function(validationSettings) {
var confName, confVal, res;
res = {};
for (confName in validationSettings) {
confVal = validationSettings[confName];
if (typeof confVal === 'function') {
res[confName] = confVal(this);
} else {
res[confName] = confVal;
}
}
return res;
};
return Base;
})();
/***/ }),
/* 8 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Absence", function() { return Absence; });
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__base_coffee__ = __webpack_require__(0);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__i18n__ = __webpack_require__(2);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__i18n___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_1__i18n__);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__env__ = __webpack_require__(1);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__env___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_2__env__);
var Absence,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Absence = (function(superClass) {
extend(Absence, superClass);
Absence.identity = "Absence";
function Absence() {
Absence.__super__.constructor.call(this);
}
Absence.prototype.validate = function() {
switch (typeof this.val) {
case 'string':
if ((this.val != null) && this.val.length === 0) {
return;
}
break;
default:
if (this.val == null) {
return;
}
}
return this._addErrorMessage();
};
Absence.prototype._addErrorMessage = function() {
var message;
message = this.opts.message != null ? this.opts.message : Object(__WEBPACK_IMPORTED_MODULE_1__i18n__["I18n"])()[Object(__WEBPACK_IMPORTED_MODULE_2__env__["Env"])().loco.getLocale()].errors.messages.present;
return this.obj.addErrorMessage(message, {
"for": this.attr
});
};
return Absence;
})(__WEBPACK_IMPORTED_MODULE_0__base_coffee__["Base"]);
/***/ }),
/* 9 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "en", function() { return en; });
var en;
en = {
variants: {},
models: {},
attributes: {},
errors: {
messages: {
accepted: "must be accepted",
blank: "can't be blank",
confirmation: "doesn't match %{attribute}",
empty: "can't be empty",
equal_to: "must be equal to %{count}",
even: "must be even",
exclusion: "is reserved",
greater_than: "must be greater than %{count}",
greater_than_or_equal_to: "must be greater than or equal to %{count}",
inclusion: "is not included in the list",
invalid: "is invalid",
less_than: "must be less than %{count}",
less_than_or_equal_to: "must be less than or equal to %{count}",
not_a_number: "is not a number",
not_an_integer: "must be an integer",
odd: "must be odd",
present: "must be blank",
too_long: {
one: "is too long (maximum is 1 character)",
other: "is too long (maximum is %{count} characters)"
},
too_short: {
one: "is too short (minimum is 1 character)",
other: "is too short (minimum is %{count} characters)"
},
wrong_length: {
one: "is the wrong length (should be 1 character)",
other: "is the wrong length (should be %{count} characters)"
},
other_than: "must be other than %{count}"
}
}
};
/***/ }),
/* 10 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Confirmation", function() { return Confirmation; });
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__base_coffee__ = __webpack_require__(0);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__i18n__ = __webpack_require__(2);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__i18n___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_1__i18n__);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__env__ = __webpack_require__(1);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__env___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_2__env__);
var Confirmation,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Confirmation = (function(superClass) {
extend(Confirmation, superClass);
Confirmation.identity = "Confirmation";
function Confirmation() {
Confirmation.__super__.constructor.call(this);
}
Confirmation.prototype.validate = function() {
var properVal;
properVal = this.obj[this._properAttr()];
if ((this.val != null) && (properVal != null) && this.val === properVal) {
return;
}
return this._addErrorMessage();
};
Confirmation.prototype._addErrorMessage = function() {
var attrName, attrNames, defaultAttrName, message;
defaultAttrName = this.attr.charAt(0).toUpperCase() + this.attr.slice(1);
attrNames = Object(__WEBPACK_IMPORTED_MODULE_1__i18n__["I18n"])()[Object(__WEBPACK_IMPORTED_MODULE_2__env__["Env"])().loco.getLocale()].attributes[this.obj.getIdentity()];
attrName = (attrNames && attrNames[this.attr]) || defaultAttrName;
message = this.opts.message != null ? this.opts.message : Object(__WEBPACK_IMPORTED_MODULE_1__i18n__["I18n"])()[Object(__WEBPACK_IMPORTED_MODULE_2__env__["Env"])().loco.getLocale()].errors.messages.confirmation;
message = message.replace('%{attribute}', attrName);
return this.obj.addErrorMessage(message, {
"for": this._properAttr()
});
};
Confirmation.prototype._properAttr = function() {
return this.attr + "Confirmation";
};
return Confirmation;
})(__WEBPACK_IMPORTED_MODULE_0__base_coffee__["Base"]);
/***/ }),
/* 11 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Exclusion", function() { return Exclusion; });
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__base_coffee__ = __webpack_require__(0);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__i18n__ = __webpack_require__(2);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__i18n___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_1__i18n__);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__env__ = __webpack_require__(1);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__env___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_2__env__);
var Exclusion,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Exclusion = (function(superClass) {
extend(Exclusion, superClass);
Exclusion.identity = "Exclusion";
function Exclusion() {
Exclusion.__super__.constructor.call(this);
}
Exclusion.prototype.validate = function() {
var set;
set = this.opts["in"] || this.opts.within || [];
if (set.indexOf(this.val) === -1) {
return;
}
return this._addErrorMessage();
};
Exclusion.prototype._addErrorMessage = function() {
var message;
message = this.opts.message != null ? this.opts.message : Object(__WEBPACK_IMPORTED_MODULE_1__i18n__["I18n"])()[Object(__WEBPACK_IMPORTED_MODULE_2__env__["Env"])().loco.getLocale()].errors.messages.exclusion;
return this.obj.addErrorMessage(message, {
"for": this.attr
});
};
return Exclusion;
})(__WEBPACK_IMPORTED_MODULE_0__base_coffee__["Base"]);
/***/ }),
/* 12 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Format", function() { return Format; });
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__base_coffee__ = __webpack_require__(0);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__i18n__ = __webpack_require__(2);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__i18n___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_1__i18n__);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__env__ = __webpack_require__(1);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__env___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_2__env__);
var Format,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Format = (function(superClass) {
extend(Format, superClass);
Format.identity = "Format";
function Format() {
Format.__super__.constructor.call(this);
}
Format.prototype.validate = function() {
var match;
match = this.opts["with"].exec(this.val);
if (match != null) {
return;
}
return this._addErrorMessage();
};
Format.prototype._addErrorMessage = function() {
var message;
message = this.opts.message != null ? this.opts.message : Object(__WEBPACK_IMPORTED_MODULE_1__i18n__["I18n"])()[Object(__WEBPACK_IMPORTED_MODULE_2__env__["Env"])().loco.getLocale()].errors.messages.invalid;
return this.obj.addErrorMessage(message, {
"for": this.attr
});
};
return Format;
})(__WEBPACK_IMPORTED_MODULE_0__base_coffee__["Base"]);
/***/ }),
/* 13 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Inclusion", function() { return Inclusion; });
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__base_coffee__ = __webpack_require__(0);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__i18n__ = __webpack_require__(2);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__i18n___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_1__i18n__);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__env__ = __webpack_require__(1);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__env___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_2__env__);
var Inclusion,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Inclusion = (function(superClass) {
extend(Inclusion, superClass);
Inclusion.identity = "Inclusion";
function Inclusion() {
Inclusion.__super__.constructor.call(this);
}
Inclusion.prototype.validate = function() {
var set;
set = this.opts["in"] || this.opts.within || [];
if (set.indexOf(this.val) !== -1) {
return;
}
return this._addErrorMessage();
};
Inclusion.prototype._addErrorMessage = function() {
var message;
message = this.opts.message != null ? this.opts.message : Object(__WEBPACK_IMPORTED_MODULE_1__i18n__["I18n"])()[Object(__WEBPACK_IMPORTED_MODULE_2__env__["Env"])().loco.getLocale()].errors.messages.inclusion;
return this.obj.addErrorMessage(message, {
"for": this.attr
});
};
return Inclusion;
})(__WEBPACK_IMPORTED_MODULE_0__base_coffee__["Base"]);
/***/ }),
/* 14 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Numericality", function() { return Numericality; });
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__base_coffee__ = __webpack_require__(0);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__i18n__ = __webpack_require__(2);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__i18n___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_1__i18n__);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__env__ = __webpack_require__(1);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__env___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_2__env__);
var Numericality,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Numericality = (function(superClass) {
extend(Numericality, superClass);
Numericality.identity = "Numericality";
function Numericality() {
Numericality.__super__.constructor.call(this);
}
Numericality.prototype.validate = function() {
if (isNaN(this.val)) {
return this._addNaNErrorMessage();
} else if ((this.opts.only_integer != null) && Number(this.val) !== parseInt(this.val)) {
return this._addIntErrorMessage();
} else if ((this.opts.greater_than != null) && Number(this.val) <= this.opts.greater_than) {
return this._addGreatherThanErrorMessage();
} else if ((this.opts.greater_than_or_equal_to != null) && Number(this.val) < this.opts.greater_than_or_equal_to) {
return this._addGreatherThanOrEqualToErrorMessage();
} else if ((this.opts.equal_to != null) && Number(this.val) !== this.opts.equal_to) {
return this._addEqualToErrorMessage();
} else if ((this.opts.less_than != null) && Number(this.val) >= this.opts.less_than) {
return this._addLessThanErrorMessage();
} else if ((this.opts.less_than_or_equal_to != null) && Number(this.val) > this.opts.less_than_or_equal_to) {
return this._addLessThanOrEqualToErrorMessage();
} else if ((this.opts.other_than != null) && Number(this.val) === this.opts.other_than) {
return this._addOtherThanErrorMessage();
} else if ((this.opts.odd != null) && Number(this.val) % 2 !== 1) {
return this._addOddErrorMessage();
} else if ((this.opts.even != null) && Number(this.val) % 2 !== 0) {
return this._addEvenErrorMessage();
}
};
Numericality.prototype._addNaNErrorMessage = function() {
var message;
message = this.opts.message != null ? this.opts.message : Object(__WEBPACK_IMPORTED_MODULE_1__i18n__["I18n"])()[Object(__WEBPACK_IMPORTED_MODULE_2__env__["Env"])().loco.getLocale()].errors.messages.not_a_number;
return this.obj.addErrorMessage(message, {
"for": this.attr
});
};
Numericality.prototype._addIntErrorMessage = function() {
var message;
message = Object(__WEBPACK_IMPORTED_MODULE_1__i18n__["I18n"])()[Object(__WEBPACK_IMPORTED_MODULE_2__env__["Env"])().loco.getLocale()].errors.messages.not_an_integer;
return this.obj.addErrorMessage(message, {
"for": this.attr
});
};
Numericality.prototype._addGreatherThanErrorMessage = function() {
var message;
message = Object(__WEBPACK_IMPORTED_MODULE_1__i18n__["I18n"])()[Object(__WEBPACK_IMPORTED_MODULE_2__env__["Env"])().loco.getLocale()].errors.messages.greater_than;
message = message.replace('%{count}', this.opts.greater_than);
return this.obj.addErrorMessage(message, {
"for": this.attr
});
};
Numericality.prototype._addGreatherThanOrEqualToErrorMessage = function() {
var message;
message = Object(__WEBPACK_IMPORTED_MODULE_1__i18n__["I18n"])()[Object(__WEBPACK_IMPORTED_MODULE_2__env__["Env"])().loco.getLocale()].errors.messages.greater_than_or_equal_to;
message = message.replace('%{count}', this.opts.greater_than_or_equal_to);
return this.obj.addErrorMessage(message, {
"for": this.attr
});
};
Numericality.prototype._addEqualToErrorMessage = function() {
var message;
message = Object(__WEBPACK_IMPORTED_MODULE_1__i18n__["I18n"])()[Object(__WEBPACK_IMPORTED_MODULE_2__env__["Env"])().loco.getLocale()].errors.messages.equal_to;
message = message.replace('%{count}', this.opts.equal_to);
return this.obj.addErrorMessage(message, {
"for": this.attr
});
};
Numericality.prototype._addLessThanErrorMessage = function() {
var message;
message = Object(__WEBPACK_IMPORTED_MODULE_1__i18n__["I18n"])()[Object(__WEBPACK_IMPORTED_MODULE_2__env__["Env"])().loco.getLocale()].errors.messages.less_than;
message = message.replace('%{count}', this.opts.less_than);
return this.obj.addErrorMessage(message, {
"for": this.attr
});
};
Numericality.prototype._addLessThanOrEqualToErrorMessage = function() {
var message;
message = Object(__WEBPACK_IMPORTED_MODULE_1__i18n__["I18n"])()[Object(__WEBPACK_IMPORTED_MODULE_2__env__["Env"])().loco.getLocale()].errors.messages.less_than_or_equal_to;
message = message.replace('%{count}', this.opts.less_than_or_equal_to);
return this.obj.addErrorMessage(message, {
"for": this.attr
});
};
Numericality.prototype._addOtherThanErrorMessage = function() {
var message;
message = Object(__WEBPACK_IMPORTED_MODULE_1__i18n__["I18n"])()[Object(__WEBPACK_IMPORTED_MODULE_2__env__["Env"])().loco.getLocale()].errors.messages.other_than;
message = message.replace('%{count}', this.opts.other_than);
return this.obj.addErrorMessage(message, {
"for": this.attr
});
};
Numericality.prototype._addOddErrorMessage = function() {
var message;
message = Object(__WEBPACK_IMPORTED_MODULE_1__i18n__["I18n"])()[Object(__WEBPACK_IMPORTED_MODULE_2__env__["Env"])().loco.getLocale()].errors.messages.odd;
return this.obj.addErrorMessage(message, {
"for": this.attr
});
};
Numericality.prototype._addEvenErrorMessage = function() {
var message;
message = Object(__WEBPACK_IMPORTED_MODULE_1__i18n__["I18n"])()[Object(__WEBPACK_IMPORTED_MODULE_2__env__["Env"])().loco.getLocale()].errors.messages.even;
return this.obj.addErrorMessage(message, {
"for": this.attr
});
};
return Numericality;
})(__WEBPACK_IMPORTED_MODULE_0__base_coffee__["Base"]);
/***/ }),
/* 15 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Presence", function() { return Presence; });
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__base_coffee__ = __webpack_require__(0);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__i18n__ = __webpack_require__(2);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__i18n___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_1__i18n__);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__env__ = __webpack_require__(1);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__env___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_2__env__);
var Presence,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Presence = (function(superClass) {
extend(Presence, superClass);
Presence.identity = "Presence";
function Presence() {
Presence.__super__.constructor.call(this);
}
Presence.prototype.validate = function() {
switch (typeof this.val) {
case 'string':
if ((this.val != null) && this.val.length > 0) {
return;
}
break;
default:
if (this.val != null) {
return;
}
}
return this._addErrorMessage();
};
Presence.prototype._addErrorMessage = function() {
var message;
message = this.opts.message != null ? this.opts.message : Object(__WEBPACK_IMPORTED_MODULE_1__i18n__["I18n"])()[Object(__WEBPACK_IMPORTED_MODULE_2__env__["Env"])().loco.getLocale()].errors.messages.blank;
return this.obj.addErrorMessage(message, {
"for": this.attr
});
};
return Presence;
})(__WEBPACK_IMPORTED_MODULE_0__base_coffee__["Base"]);
/***/ }),
/* 16 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Size", function() { return Size; });
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__base_coffee__ = __webpack_require__(0);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__length_coffee__ = __webpack_require__(4);
var Size,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Size = (function(superClass) {
extend(Size, superClass);
Size.identity = "Size";
function Size() {
Size.__super__.constructor.call(this);
}
Size.prototype.validate = function() {
return __WEBPACK_IMPORTED_MODULE_1__length_coffee__["Length"].instance(this.obj, this.attr, this.opts).validate();
};
return Size;
})(__WEBPACK_IMPORTED_MODULE_0__base_coffee__["Base"]);
/***/ }),
/* 17 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Utils = undefined;
var _obj = __webpack_require__(18);
var Utils = {
Obj: _obj.Obj
};
exports.Utils = Utils;
/***/ }),
/* 18 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Obj", function() { return Obj; });
var Obj;
Obj = (function() {
function Obj() {}
Obj.toURIParams = function(obj) {
var key, str, val;
str = "";
for (key in obj) {
val = obj[key];
if (str !== "") {
str += "&";
}
str += key + "=" + encodeURIComponent(val);
}
return str;
};
return Obj;
})();
/***/ }),
/* 19 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var Models = function Models() {
if (typeof App === 'undefined') {
return {};
}
return App.Models;
};
exports.Models = Models;
/***/ })
/******/ ]);
});
!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 o=r[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,e),o.l=!0,o.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,o=r(3),s=r.n(o);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,o;return o=this.identity,null==this.sharedInstances[o]&&(this.sharedInstances[o]=new s.a[o]),n=this.sharedInstances[o],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";Object.defineProperty(e,"__esModule",{value:!0});var n=r(4),o=function(t){return t&&t.__esModule?t:{default:t}}(n),s={loco:o.default,scope:null},i=function(){return"undefined"==typeof App?s:App.Env};e.default=i},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t},o=r(10),s=function(t){return t&&t.__esModule?t:{default:t}}(o),i=function(){return"undefined"!=typeof App?n({en:s.default},App.I18n):{en:s.default}};e.default=i},function(t,e,r){"use strict";function n(t){return t&&t.__esModule?t:{default:t}}Object.defineProperty(e,"__esModule",{value:!0});var o=r(9),s=n(o),i=r(11),u=n(i),a=r(12),l=n(a),c=r(13),p=n(c),h=r(14),f=n(h),d=r(5),_=n(d),g=r(15),v=n(g),y=r(16),m=n(y),b=r(17),M=n(b),E={Absence:s.default,Confirmation:u.default,Exclusion:l.default,Format:p.default,Inclusion:f.default,Length:_.default,Numericality:v.default,Presence:m.default,Size:M.default};e.default=E},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n={getLocale:function(){return"en"},protocolWithHost:null};e.default=n},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n,o=r(0),s=r(2),i=r.n(s),u=r(1),a=r.n(u),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="Length",e.prototype.validate=function(){var t;if(null!=this.val&&null!==(t=null!=this._range()[0]&&null!=this._range()[1]&&this._range()[0]===this._range()[1]&&this.val.length!==this._range()[0]?this._selectErrorMessage("wrong_length",this._range()[0]):null!=this._range()[0]&&this.val.length<this._range()[0]?this._selectErrorMessage("too_short",this._range()[0]):null!=this._range()[1]&&this.val.length>this._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,o,s,u;if(1===e)return i()()[a()().loco.getLocale()].errors.messages[t].one;for(o=null,s=["few","many"],r=0,n=s.length;r<n;r++)if(u=s[r],this._checkVariant(u,e)){o=i()()[a()().loco.getLocale()].errors.messages[t][u];break}return null==o&&(o=i()()[a()().loco.getLocale()].errors.messages[t].other),null!=this.opts.message&&(o=this.opts.message),/%{count}/.exec(o)&&(o=o.replace("%{count}",e)),o},e.prototype._checkVariant=function(t,e){if(null!=i()()[a()().loco.getLocale()].variants[t])return i()()[a()().loco.getLocale()].variants[t](e)},e}(o.default),e.default=n},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n;n=function(){function t(){}return t.imap={},t.clear=function(){return this.imap={}},t.add=function(t){var e;return e=t.getIdentity(),null==this.imap[e]&&(this.imap[e]={}),null==this.imap[e][t.id]&&(this.imap[e][t.id]=[]),this.imap[e][t.id][0]=t},t.connect=function(t,e){var r;return null==e&&(e={}),r=e.with,this.add(r),this.imap[r.getIdentity()][r.id].push(t)},t.addCollection=function(t,e){if(null==e&&(e={}),null==this.imap[t]&&(this.imap[t]={}),null==this.imap[t].collection&&(this.imap[t].collection=[]),-1===this.imap[t].collection.indexOf(e.to))return this.imap[t].collection.push(e.to)},t.all=function(t){var e,r,n,o;if(null==this.imap[t])return null;e=[],o=this.imap[t];for(r in o)n=o[r],"collection"!==r&&e.push(n[0]);return e},t.find=function(t,e){return this.imap[t]&&this.imap[t][e]?this.imap[t][e][0]:null},t.findConnected=function(t,e){var r;return this.imap[t]&&this.imap[t][e]&&this.imap[t][e].length>1?(r=this.imap[t][e],r.slice(1,+(r.length-1)+1||9e9)):[]},t}(),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.IdentityMap=e.Config=e.Base=void 0;var o=r(8),s=n(o),i=r(6),u=n(i),a=r(0),l=n(a),c=r(3),p=n(c),h=r(4),f=n(h);p.default.Base=l.default,e.Base=s.default,e.Config=f.default,e.IdentityMap=u.default,e.Validators=p.default},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n,o=r(3),s=r.n(o),i=r(1),u=r.n(i),a=r(18),l=r.n(a),c=r(6),p=r(20),h=r.n(p);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.all=function(t){return null==t&&(t={}),this.get("all",t)},t.find=function(t){var e,r,n;return n={},"object"==typeof t?(n=t,e=t.id,delete n.id):e=t,r=new XMLHttpRequest,r.open("GET",this.__getResourcesUrl(n)+"/"+e),r.setRequestHeader("Accept","application/json"),r.setRequestHeader("Content-Type","application/json"),r.send(JSON.stringify(n)),new Promise(function(t){return function(e,n){return r.onerror=function(t){return n(t)},r.onload=function(r){var n,o;return o=JSON.parse(r.target.response),n=t.__initSubclass(o),c.default.add(n),e(n)}}}(this))},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.delete=function(t,e){return null==e&&(e={}),this.__send("DELETE",t,e)},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.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(){var t,e,r,n;for(n=this.__getResourcesUrl(),r=/:(\w+)\/?/,e=[];t=r.exec(n);)e.push(t[1]),n=n.replace(t[0],t[1]);return e},t.__getResourcesUrl=function(t){var e,r;return null==t&&(t={}),r=null==this.resources?"/"+this.getRemoteName().toLowerCase()+"s":t.resource?this.resources[t.resource].url:null!=u()().scope&&null!=this.resources[u()().scope]?this.resources[u()().scope].url:this.resources.url,null!=u()().loco.protocolWithHost&&(r=""+u()().loco.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=h()()[r[0]],null==e?new this(t):new e(t)):new(e=h()()[r[0]][r[1]])(t)},t.__page=function(t,e,r,n){var o,s,i,u,a,p,h,f;if(null==e&&(e={}),null==r&&(r={}),null==n&&(n={resources:[],count:0}),s=r.method||"GET",h=r.url||this.__getResourcesUrl(e),o={},null!=r.data){u=r.data;for(i in u)f=u[i],"resource"!==i&&(o[i]=f)}return o[this.__getPaginationParam()]=t,"GET"===s&&(h=h+"?"+l.a.Obj.toURIParams(o)),p=new XMLHttpRequest,p.open(s,h),p.setRequestHeader("Accept","application/json"),p.setRequestHeader("Content-Type","application/json"),p.setRequestHeader("X-CSRF-Token",null!=(a=document.querySelector("meta[name='csrf-token']"))?a.content:void 0),p.send(JSON.stringify(o)),new Promise(function(t){return function(r,s){return p.onerror=function(t){return s(t)},p.onload=function(s){var u,a,l,p,h;o=JSON.parse(s.target.response),n.count=o.count;for(i in o)f=o[i],-1===["resources","count"].indexOf(i)&&(n[i]=f);for(h=o.resources,u=0,a=h.length;u<a;u++)p=h[u],l=t.__initSubclass(p),null!=e.resource&&(l.resource=e.resource),c.default.add(l),n.resources.push(l);return r(n)}}}(this))},t.__paginate=function(t,e){var r,n,o;return n=this.__getPaginationPer(),r=null!=(o=t.page)?o:1,this.__page(r,t,e).then(function(r){return function(o){var s,i,u,a,l;if(null!=t.page)return Promise.resolve(o);if(o.count<=n)return Promise.resolve(o);if(u=parseInt(o.count/n),u!==o.count/n&&(u+=1),a=Promise.resolve(o),1===u)return a;for(s=i=2,l=u;2<=l?i<=l:i>=l;s=2<=l?++i:--i)(function(n){return a=a.then(function(s){return r.__page(n,t,e,o)})})(s);return a}}(this))},t.__getPaginationParam=function(){var t,e,r,n,o,s;return t="page",null!=u()().scope&&null!=this.resources&&null!=this.resources[u()().scope]?(e=null!=(r=this.resources[u()().scope])&&null!=(n=r.paginate)?n.param:void 0,null!=e?e:t):null!=(null!=(o=this.resources)&&null!=(s=o.paginate)?s.param:void 0)?this.resources.paginate.param:t},t.__getPaginationPer=function(){var t,e,r,n;return null!=u()().scope&&null!=this.resources&&null!=this.resources[u()().scope]?null!=(t=this.resources[u()().scope])&&null!=(e=t.paginate)?e.per:void 0:null!=(null!=(r=this.resources)&&null!=(n=r.paginate)?n.per:void 0)?this.resources.paginate.per:null},t.__send=function(t,e,r){var n,o;return o=this.__getResourcesUrl(r),"all"!==e&&(o=o+"/"+e),n={method:t,url:o,data:r},this.__paginate(r,n)},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,o,i,u,a,l,c,p,h;if(null==this.constructor.attributes)return!0;this.errors=null,u=this.constructor.attributes;for(o in u)if(t=u[o],null!=t.validations){a=t.validations;for(c in a)p=a[c],null!=this.id&&"create"===p.on||null==this.id&&"update"===p.on||(null==p.if||p.if(this))&&(h=c.charAt(0).toUpperCase()+c.slice(1),null!=s.a[h]?(i=this.__processedValidationSettings(p),s.a[h].instance(this,o,i).validate()):console.log('Warning! "'+h+'" validator is not implemented!'))}if(null!=this.constructor.validate)for(l=this.constructor.validate,e=0,r=l.length;e<r;e++)n=l[e],this[n]();return null==this.errors},t.prototype.isInvalid=function(){return!this.isValid()},t.prototype.isEmpty=function(){var t,e;e=this.attributes();for(t in e)if(e[t],null!==this[t])return!1;return!0},t.prototype.addErrorMessage=function(t,e){return null==e&&(e={}),null==this.errors&&(this.errors={}),null==this.errors[e.for]&&(this.errors[e.for]=[]),this.errors[e.for].push(t)},t.prototype.save=function(){var t,e,r;return t=null!=this.id?"PUT":"POST",r=new XMLHttpRequest,r.open(t,this.__getResourceUrl()),r.setRequestHeader("Accept","application/json"),r.setRequestHeader("Content-Type","application/json"),r.setRequestHeader("X-CSRF-Token",null!=(e=document.querySelector("meta[name='csrf-token']"))?e.content:void 0),r.send(JSON.stringify(this.serialize())),new Promise(function(t){return function(e,n){return r.onerror=function(t){return n(t)},r.onload=function(r){var n;return n=JSON.parse(r.target.response),n.success?void e(n):(null!=n.errors&&t.__assignRemoteErrorMessages(n.errors),e(n))}}}(this))},t.prototype.updateAttribute=function(t){var e,r;return r=new XMLHttpRequest,r.open("PUT",this.__getResourceUrl()),r.setRequestHeader("Accept","application/json"),r.setRequestHeader("Content-Type","application/json"),r.setRequestHeader("X-CSRF-Token",null!=(e=document.querySelector("meta[name='csrf-token']"))?e.content:void 0),r.send(JSON.stringify(this.serialize(t))),new Promise(function(t){return function(e,n){return r.onerror=function(t){return n(t)},r.onload=function(r){var o;return r.target.status>=200&&r.target.status<400?(o=JSON.parse(r.target.response),o.success?void e(o):(null!=o.errors&&t.__assignRemoteErrorMessages(o.errors),e(o))):r.target.status>=500?n(r):void 0}}}(this))},t.prototype.serialize=function(t){var e,r,n,o;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],o=this.getAttrRemoteName(t),r[n][o]=this[t];return r},t.prototype.reload=function(){var t,e,r,n,o;for(t={id:this.id},o=this.constructor.getResourcesUrlParams(),e=0,r=o.length;e<r;e++)n=o[e],t[n]=this[n];return this.constructor.find(t)},t.prototype.changes=function(){var t,e,r,n,o;n={},t=c.default.find(this.getIdentity(),this.id),r=this.attributes();for(e in r)if((o=r[e])!==t[e]){if(null!=o&&o.constructor===Date&&t[e]-o==0)continue;o!==t[e]&&(n[e]={is:t[e],was:o})}return n},t.prototype.applyChanges=function(){var t,e,r,n;e=this.changes(),r=[];for(t in e)n=e[t],r.push(this[t]=n.is);return r},t.prototype.toKey=function(){return this.getIdentity().toLowerCase()+"_"+this.id},t.prototype.get=function(t,e){return null==e&&(e={}),this.__send("GET",t,e)},t.prototype.post=function(t,e){return null==e&&(e={}),this.__send("POST",t,e)},t.prototype.put=function(t,e){return null==e&&(e={}),this.__send("PUT",t,e)},t.prototype.patch=function(t,e){return null==e&&(e={}),this.__send("PATCH",t,e)},t.prototype.delete=function(t,e){return null==e&&(e={}),this.__send("DELETE",t,e)},t.prototype.__send=function(t,e,r){var n,o,s;return s=this.__getResourceUrl(),null!=e&&(s=s+"/"+e),o=new XMLHttpRequest,o.open(t,s),o.setRequestHeader("Accept","application/json"),o.setRequestHeader("Content-Type","application/json"),o.setRequestHeader("X-CSRF-Token",null!=(n=document.querySelector("meta[name='csrf-token']"))?n.content:void 0),o.send(JSON.stringify(r)),new Promise(function(t,e){return o.onerror=function(t){return e(t)},o.onload=function(n){return n.target.status>=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,o;n=[];for(r in t)o=t[r],e=this.getAttrName(r),n.push(this.assignAttr(e,o));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,o,s;s=[];for(o in t)n=t[o],e=this.getAttrName(o),s.push(function(){var t,o,s;for(s=[],t=0,o=n.length;t<o;t++)r=n[t],s.push(this.addErrorMessage(r,{for:e}));return s}.call(this));return s},t.prototype.__getResourceUrl=function(){var t;return t=this.constructor.__getResourcesUrl({resource:this.resource,obj:this}),null==this.id?t:t+"/"+this.id},t.prototype.__processedValidationSettings=function(t){var e,r,n;n={};for(e in t)r=t[e],n[e]="function"==typeof r?r(this):r;return n},t}(),e.default=n},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n,o=r(0),s=r(2),i=r.n(s),u=r(1),a=r.n(u),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="Absence",e.prototype.validate=function(){switch(typeof this.val){case"string":if(null!=this.val&&0===this.val.length)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()().loco.getLocale()].errors.messages.present,this.obj.addErrorMessage(t,{for:this.attr})},e}(o.default),e.default=n},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n;n={variants:{},models:{},attributes:{},errors:{messages:{accepted:"must be accepted",blank:"can't be blank",confirmation:"doesn't match %{attribute}",empty:"can't be empty",equal_to:"must be equal to %{count}",even:"must be even",exclusion:"is reserved",greater_than:"must be greater than %{count}",greater_than_or_equal_to:"must be greater than or equal to %{count}",inclusion:"is not included in the list",invalid:"is invalid",less_than:"must be less than %{count}",less_than_or_equal_to:"must be less than or equal to %{count}",not_a_number:"is not a number",not_an_integer:"must be an integer",odd:"must be odd",present:"must be blank",too_long:{one:"is too long (maximum is 1 character)",other:"is too long (maximum is %{count} characters)"},too_short:{one:"is too short (minimum is 1 character)",other:"is too short (minimum is %{count} characters)"},wrong_length:{one:"is the wrong length (should be 1 character)",other:"is the wrong length (should be %{count} characters)"},other_than:"must be other than %{count}"}}},e.default=n},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n,o=r(0),s=r(2),i=r.n(s),u=r(1),a=r.n(u),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="Confirmation",e.prototype.validate=function(){var t;if(t=this.obj[this._properAttr()],null==this.val||null==t||this.val!==t)return this._addErrorMessage()},e.prototype._addErrorMessage=function(){var t,e,r,n;return r=this.attr.charAt(0).toUpperCase()+this.attr.slice(1),e=i()()[a()().loco.getLocale()].attributes[this.obj.getIdentity()],t=e&&e[this.attr]||r,n=null!=this.opts.message?this.opts.message:i()()[a()().loco.getLocale()].errors.messages.confirmation,n=n.replace("%{attribute}",t),this.obj.addErrorMessage(n,{for:this._properAttr()})},e.prototype._properAttr=function(){return this.attr+"Confirmation"},e}(o.default),e.default=n},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n,o=r(0),s=r(2),i=r.n(s),u=r(1),a=r.n(u),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="Exclusion",e.prototype.validate=function(){var t;if(t=this.opts.in||this.opts.within||[],-1!==t.indexOf(this.val))return this._addErrorMessage()},e.prototype._addErrorMessage=function(){var t;return t=null!=this.opts.message?this.opts.message:i()()[a()().loco.getLocale()].errors.messages.exclusion,this.obj.addErrorMessage(t,{for:this.attr})},e}(o.default),e.default=n},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n,o=r(0),s=r(2),i=r.n(s),u=r(1),a=r.n(u),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="Format",e.prototype.validate=function(){if(null==this.opts.with.exec(this.val))return this._addErrorMessage()},e.prototype._addErrorMessage=function(){var t;return t=null!=this.opts.message?this.opts.message:i()()[a()().loco.getLocale()].errors.messages.invalid,this.obj.addErrorMessage(t,{for:this.attr})},e}(o.default),e.default=n},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n,o=r(0),s=r(2),i=r.n(s),u=r(1),a=r.n(u),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="Inclusion",e.prototype.validate=function(){var t;if(t=this.opts.in||this.opts.within||[],-1===t.indexOf(this.val))return this._addErrorMessage()},e.prototype._addErrorMessage=function(){var t;return t=null!=this.opts.message?this.opts.message:i()()[a()().loco.getLocale()].errors.messages.inclusion,this.obj.addErrorMessage(t,{for:this.attr})},e}(o.default),e.default=n},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n,o=r(0),s=r(2),i=r.n(s),u=r(1),a=r.n(u),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="Numericality",e.prototype.validate=function(){return isNaN(this.val)?this._addNaNErrorMessage():null!=this.opts.only_integer&&Number(this.val)!==parseInt(this.val)?this._addIntErrorMessage():null!=this.opts.greater_than&&Number(this.val)<=this.opts.greater_than?this._addGreatherThanErrorMessage():null!=this.opts.greater_than_or_equal_to&&Number(this.val)<this.opts.greater_than_or_equal_to?this._addGreatherThanOrEqualToErrorMessage():null!=this.opts.equal_to&&Number(this.val)!==this.opts.equal_to?this._addEqualToErrorMessage():null!=this.opts.less_than&&Number(this.val)>=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()().loco.getLocale()].errors.messages.not_a_number,this.obj.addErrorMessage(t,{for:this.attr})},e.prototype._addIntErrorMessage=function(){var t;return t=i()()[a()().loco.getLocale()].errors.messages.not_an_integer,this.obj.addErrorMessage(t,{for:this.attr})},e.prototype._addGreatherThanErrorMessage=function(){var t;return t=i()()[a()().loco.getLocale()].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()().loco.getLocale()].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()().loco.getLocale()].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()().loco.getLocale()].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()().loco.getLocale()].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()().loco.getLocale()].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()().loco.getLocale()].errors.messages.odd,this.obj.addErrorMessage(t,{for:this.attr})},e.prototype._addEvenErrorMessage=function(){var t;return t=i()()[a()().loco.getLocale()].errors.messages.even,this.obj.addErrorMessage(t,{for:this.attr})},e}(o.default),e.default=n},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n,o=r(0),s=r(2),i=r.n(s),u=r(1),a=r.n(u),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()().loco.getLocale()].errors.messages.blank,this.obj.addErrorMessage(t,{for:this.attr})},e}(o.default),e.default=n},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n,o=r(0),s=r(5),i=function(t,e){function r(){this.constructor=t}for(var n in e)u.call(e,n)&&(t[n]=e[n]);return r.prototype=e.prototype,t.prototype=new r,t.__super__=e.prototype,t},u={}.hasOwnProperty;n=function(t){function e(){e.__super__.constructor.call(this)}return i(e,t),e.identity="Size",e.prototype.validate=function(){return s.default.instance(this.obj,this.attr,this.opts).validate()},e}(o.default),e.default=n},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n=r(19),o=function(t){return t&&t.__esModule?t:{default:t}}(n),s={Obj:o.default};e.default=s},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n;n=function(){function t(){}return t.toURIParams=function(t){var e,r,n;r="";for(e in t)n=t[e],""!==r&&(r+="&"),r+=e+"="+encodeURIComponent(n);return r},t}(),e.default=n},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n=function(){return"undefined"==typeof App?{}:App.Models};e.default=n}])});
{
"name": "loco-js-model",
"version": "0.0.3",
"version": "0.1.0",
"description": "Model part of loco-js",
"main": "dist/loco-model.js",
"scripts": {
"start": "node server.js",
"build": "webpack --config webpack.config.js"
"start": "node dev/server.js",
"build": "webpack -p --config webpack.config.js"
},

@@ -31,5 +31,5 @@ "repository": {

"express": "^4.16.2",
"webpack": "^3.8.1",
"webpack-dev-middleware": "^1.12.0"
"webpack": "^3.10.0",
"webpack-dev-middleware": "^2.0.3"
}
}

@@ -0,16 +1,10 @@

import Config from './config';
const LocalEnv = {
loco: {
getLocale: () => { return 'en' },
protocolWithHost: null
},
loco: Config,
scope: null
};
const Env = () => {
if(typeof App === 'undefined') {
return LocalEnv
}
return App.Env
}
const Env = () => (typeof App === 'undefined') ? LocalEnv : App.Env;
export {Env};
export default Env;

@@ -1,10 +0,5 @@

import {en} from './locales/en.coffee';
import en from './locales/en.coffee';
const I18n = () => {
if(typeof App !== 'undefined') {
return {en, ...App.I18n}
}
return {en}
}
const I18n = () => (typeof App !== 'undefined') ? {en, ...App.I18n} : {en};
export {I18n};
export default I18n;

@@ -1,8 +0,3 @@

const Models = () => {
if(typeof App === 'undefined') {
return {}
}
return App.Models
}
const Models = () => (typeof App === 'undefined') ? {} : App.Models;
export {Models};
export default Models;

@@ -1,2 +0,2 @@

import {Obj} from './utils/obj.coffee';
import Obj from './utils/obj.coffee';

@@ -7,2 +7,2 @@ const Utils = {

export {Utils};
export default Utils;

@@ -1,10 +0,10 @@

import {Absence} from './validators/absence.coffee';
import {Confirmation} from './validators/confirmation.coffee';
import {Exclusion} from './validators/exclusion.coffee';
import {Format} from './validators/format.coffee';
import {Inclusion} from './validators/inclusion.coffee';
import {Length} from './validators/length.coffee';
import {Numericality} from './validators/numericality.coffee';
import {Presence} from './validators/presence.coffee';
import {Size} from './validators/size.coffee';
import Absence from './validators/absence.coffee';
import Confirmation from './validators/confirmation.coffee';
import Exclusion from './validators/exclusion.coffee';
import Format from './validators/format.coffee';
import Inclusion from './validators/inclusion.coffee';
import Length from './validators/length.coffee';
import Numericality from './validators/numericality.coffee';
import Presence from './validators/presence.coffee';
import Size from './validators/size.coffee';

@@ -23,2 +23,2 @@ const Validators = {

export {Validators};
export default Validators;
var path = require('path');
module.exports = {
entry: './index.js',
entry: './src/index.js',
module: {

@@ -11,4 +11,3 @@ rules: [

use: [
{
loader: 'coffee-loader',
{ loader: 'coffee-loader',
options: {

@@ -15,0 +14,0 @@ transpile: {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc