/
AttributeFactoryFinder.js
76 lines (74 loc) · 2.13 KB
/
AttributeFactoryFinder.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
define([ "dojo/_base/array", //
"dojo/_base/lang",//
"dojo/_base/declare",//
"dojo/Stateful"//
], function (array, lang, declare, Stateful) {
// module:
// gform/AttributeFactoryFinder
return declare(Stateful, {
// summary:
// Manages all attributeFactories.
// description:
// used internally by EditorFactory.
// tags:
// deprecated
constructor: function (kwArgs) {
this.attributeFactoryMap={};
lang.mixin(this, kwArgs);
},
attributeFactoryMap:null,
addAttributeFactory: function (/*gform/api/AttributeFactory*/factory) {
// summary:
// Add attributeFactory.
// editor:
// the id referenced by schema attributes.
// factory:
// the attributeFactory.
this.attributeFactoryMap[factory.id] = factory;
},
getAttributeFactories: function () {
// summary:
// get all registered factories. This does not include factories added solely by id.
// returns: [gform/api/AttributeFactory]
// attributeFactories
return this.attributeFactories;
},
getAttributeFactoryMap: function () {
// summary:
// get the mapping of id to factoriy.
// returns: Object
// map of id to attributeFactory
return this.attributeFactoryMap;
},
getFactory: function (attribute) {
// summary:
// get factory for attribute.
// attribute:
// the attribute to find a factory for
// returns: gform/api/AttributeFactory
// attributeFactory for attribute
var factory = this.attributeFactoryMap[attribute.editor] || null;
if (factory && factory.handles(attribute)) {
return factory;
}
if (factory && attribute.array && !attribute.elementEditor) {
// TODO this seems wrong. Don't change the schema.
attribute.elementEditor = attribute.editor;
delete attribute.editor;
} else if (factory) {
console.log("editor " + attribute.editor + " cannot handle attribute " + attribute.code);
return null;
}
if (!factory) {
var factories = array.filter(this.attributeFactories,
function (af) {
return af.handles && af.handles(attribute);
});
if (factories.length > 0) {
factory = factories[0];
}
}
return factory;
}
});
});