From 748f1c5d337040433c6c441afab579faf5c934e0 Mon Sep 17 00:00:00 2001 From: Alon Levy Date: Mon, 6 Apr 2015 16:21:10 +0300 Subject: client: types: split types.js to form domain_types.js, containing declarative json --- src/client/model/types.js | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/client/model/types.js (limited to 'src/client/model/types.js') 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, + }); +} +) -- cgit v1.3.1