forked from edchat/dojo-generate-form
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeta.js
57 lines (53 loc) · 1.32 KB
/
meta.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
define([ "dojo/_base/array", "dojo/_base/lang", "dojo/_base/declare" ], function(array, lang,
declare, Container, at, domConstruct,
Stateful) {
var Meta= declare("kkk", [ ], {
primitiveTypes: [
"string","boolean","date","number"
],
defaults:{
"string":"",
"number":0,
"boolean":false,
"date":null
},
getDefaultAttributeValue : function(attribute) {
var defaultValue=this.defaults[attribute.type];
return defaultValue;
},
getPrimitiveType : function(attribute) {
return this.normalizedPrimitiveType(this.getType(attribute));
},
getType : function(attribute) {
if (!attribute.type) {
return null;
}
if (typeof attribute.type == "string") {
return attribute.type;
}else{
return attribute.type.code;
}
},
getTypeAttribute: function(attribute,attributeCode) {
if (typeof attribute.type == "string") {
return attribute[attributeCode];
}else{
return attribute.type[attributeCode];
}
},
isType : function(attribute,typeCode) {
return typeCode==this.getType(attribute);
},
normalizedPrimitiveType: function(code) {
var matches= array.filter(this.primitiveTypes,function(type) {
return type==code;
});
if (matches.length==1) {
return matches[0];
}else{
return null;
}
}
});
return new Meta();
});