Changeset View
Changeset View
Standalone View
Standalone View
lib/chip-types/field.js
"use strict"; | |||||
const locreq = require("locreq")(__dirname); | const locreq = require("locreq")(__dirname); | ||||
const default_methods = require("./field-type-default-methods.js"); | const default_methods = require("./field-type-default-methods.js"); | ||||
const FieldType = locreq("lib/chip-types/field-type.js"); | const FieldType = locreq("lib/chip-types/field-type.js"); | ||||
function Field(app, declaration, collection) { | function Field(app, declaration, collection) { | ||||
this.name = declaration.name; | this.name = declaration.name; | ||||
this.declaration = declaration; | this.declaration = declaration; | ||||
this.type = new FieldType(app, declaration.type); | this.type = new FieldType(app, declaration.type); | ||||
this.value_path = this.name + (this.type.value_path_after_field_name || ""); | this.value_path = this.name + (this.type.value_path_after_field_name || ""); | ||||
this.required = declaration.required || false; | this.required = declaration.required || false; | ||||
this.params = declaration.params || {}; | this.params = declaration.params || {}; | ||||
this.type.init(collection, declaration.name, this.params); | this.type.init(collection, declaration.name, this.params); | ||||
const self = this; | const self = this; | ||||
for (const method_name in default_methods) { | for (const method_name in default_methods) { | ||||
this[method_name] = (function(method_name) { | this[method_name] = (function(_method_name) { | ||||
return function() { | return function() { | ||||
const arguments_array = Array.from(arguments); | const arguments_array = Array.from(arguments); | ||||
arguments_array.splice(1, 0, self.params); | arguments_array.splice(1, 0, self.params); | ||||
return self.type[method_name].apply(self.type, arguments_array); | return self.type[_method_name].apply( | ||||
self.type, | |||||
arguments_array | |||||
); | |||||
}; | }; | ||||
})(method_name); | })(method_name); | ||||
} | } | ||||
this.get_specification = function() { | this.get_specification = function() { | ||||
return { | return { | ||||
name: this.name, | name: this.name, | ||||
type: this.type, | type: this.type, | ||||
Show All 18 Lines |