forked from edchat/dojo-generate-form
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEditorFactory.js
46 lines (44 loc) · 1.19 KB
/
EditorFactory.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
define([ "dojo/_base/array", //
"dojo/_base/lang",//
"dojo/_base/declare",//
"dojox/mvc/at",//
"dojo/Stateful" //
], function(array, lang, declare, at, Stateful) {
return declare("app.EditorFactory", [Stateful], {
constructor : function() {
this.groupFactories={};
},
addGroupFactory: function(id,factory) {
this.groupFactories[id]=factory;
},
setDefaultGroupFactory: function(id) {
this.defaultGroupFactory=this.groupFactories[id];
},
defaultGroupFactory:null,
create : function(group, modelHandle) {
if (!group) {
return null;
}
if (group.groupType) {
var groupFactory = this.find(group.groupType);
if (groupFactory==null) {
throw new Error("cannot find group factory "+group.groupType);
}
return groupFactory.create(group, modelHandle);
}
else if (lang.isArray(group.attributes)) {
return this.defaultGroupFactory.create(group, modelHandle);
}
},
getGroupFactory: function(group) {
return this.find(group.groupType);
},
getUpdateModelHandle: function(meta) {
var factory=this.attributeFactoryFinder.getFactory(meta);
return factory;
},
find : function(groupType) {
return this.groupFactories[groupType];
}
});
});