summaryrefslogtreecommitdiff
path: root/src/client/model/types.js
diff options
context:
space:
mode:
authorAlon Levy <alon@pobox.com>2015-04-06 16:21:10 +0300
committerAlon Levy <alon@pobox.com>2015-04-06 16:21:10 +0300
commit748f1c5d337040433c6c441afab579faf5c934e0 (patch)
tree59d0fc1a044aea66e626ad5f05dcdacb61ed02a8 /src/client/model/types.js
parenta2ef6be2c52e0421fccddf45fd1563f49f4475c4 (diff)
client: types: split types.js to form domain_types.js, containing declarative jsontoday-is-not-the-day
Diffstat (limited to 'src/client/model/types.js')
-rw-r--r--src/client/model/types.js40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/client/model/types.js b/src/client/model/types.js
new file mode 100644
index 00000000..867969ea
--- /dev/null
+++ b/src/client/model/types.js
@@ -0,0 +1,40 @@
+define(['underscore', 'util', 'model/domain_types'],
+function(_, util, domain_types)
+{
+
+var nodetypes,
+ all_attributes,
+ type_attributes = domain_types.type_attributes,
+ attribute_titles = domain_types.attribute_titles;
+
+nodetypes = _.keys(type_attributes);
+
+if (undefined === type_attributes['_defaults']) {
+ type_attributes['_defaults'] = {
+ 'title': 'default',
+ 'attributes':['description', 'url']
+ };
+}
+
+_.pluck(_.values(type_attributes), 'attributes').map(function (attributes) {
+ attributes.push('name');
+ attributes.push('type');
+ attributes.sort();
+ });
+
+all_attributes = _.union(_.flatten(_.pluck(_.values(type_attributes), 'attributes'))).sort();
+
+util.assert(_.isEqual(all_attributes, _.keys(attribute_titles).sort()));
+
+return (
+ {
+ nodetypes: nodetypes,
+ type_attributes: function (type) {
+ util.assert(!type || type[0] !== '_', 'invalid type name');
+ return type_attributes[type && type_attributes.hasOwnProperty(type) ? type : '_defaults'].attributes;
+ },
+ all_attributes: all_attributes,
+ attribute_titles: attribute_titles,
+ });
+}
+)