forked from Meteor-Community-Packages/meteor-autoform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautoform-formdata.js
46 lines (40 loc) · 959 Bytes
/
autoform-formdata.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
FormData = function afFormData() {
var self = this;
self.forms = {};
};
FormData.prototype.initForm = function fdInitForm(formId) {
var self = this;
if (self.forms[formId])
return;
self.forms[formId] = {
sourceDoc: null,
deps: {
sourceDoc: new Deps.Dependency
}
};
};
FormData.prototype.sourceDoc = function fdSourceDoc(formId, sourceDoc) {
var self = this;
self.initForm(formId);
if (sourceDoc) {
//setter
self.forms[formId].sourceDoc = sourceDoc;
self.forms[formId].deps.sourceDoc.changed();
} else {
//getter
self.forms[formId].deps.sourceDoc.depend();
return self.forms[formId].sourceDoc;
}
};
FormData.prototype.getDocCountForField = function fdGetDocCountForField(formId, field) {
var self = this;
var mDoc = self.sourceDoc(formId);
var docCount;
if (mDoc) {
var keyInfo = mDoc.getInfoForKey(field);
if (keyInfo && _.isArray(keyInfo.value)) {
docCount = keyInfo.value.length
}
}
return docCount;
};