-
Notifications
You must be signed in to change notification settings - Fork 0
/
form.js
57 lines (45 loc) · 1.54 KB
/
form.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
'use strict';
const { compileDocumentSelector } = require('minimongo/src/selector');
const Serializable = require('./serializable');
const { arrayOf, identical, polymorphic, categorized, instanceOf } = require('./mappers');
const NamedObjectMap = require('./named_object_map');
const OrOperator = require('./operators/or_operator');
const Fields = require('./fields');
class Form extends Serializable {
set fields(fields) {
this.fieldsMap = NamedObjectMap.fromArray(fields);
}
get fields() {
return [...this.fieldsMap.values()];
}
retrieveAllPossibleFields() {
const fields = this.fields.
map(field =>
[field].concat(field.retrievePossibleInsertionFields()));
return Array.prototype.concat.apply([], fields);
}
isAttachable(document) {
return this.attachableSelector(document);
}
get attachableSelector() {
return this.compiledAttachableSelector ||
(this.compiledAttachableSelector =
compileDocumentSelector(this.attachable.mongoize()));
}
set attachable(attachable) {
this.compiledAttachableSelector = null;
this._attachable = attachable;
}
get attachable() {
return this._attachable;
}
}
Form.property('name', identical);
Form.property('fields', arrayOf(polymorphic(categorized, Fields)));
Form.property('release', identical);
Form.property('deadline', identical);
Form.property('attachable', instanceOf(OrOperator));
Form.property('isRequired', identical);
Form.property('isProtected', identical);
Form.property('metadata', identical);
module.exports = Form;