diff --git a/merlin/static/merlin/js/lib/barricade.js b/merlin/static/merlin/js/lib/barricade.js index 226d117..9998b3a 100644 --- a/merlin/static/merlin/js/lib/barricade.js +++ b/merlin/static/merlin/js/lib/barricade.js @@ -178,9 +178,16 @@ var Barricade = (function () { return id; }; - this.hasID = function() { - return id !== undefined; - }; + /** + * Checks whether the ID is set for this item. + * @method hasID + * @memberof Barricade.Identifiable + * @instance + * @returns {Boolean} + */ + this.hasID = function() { + return id !== undefined; + }; /** * Sets the ID. diff --git a/merlin/static/merlin/js/merlin.field.models.js b/merlin/static/merlin/js/merlin.field.models.js index e68fd13..7b4f81d 100644 --- a/merlin/static/merlin/js/merlin.field.models.js +++ b/merlin/static/merlin/js/merlin.field.models.js @@ -9,6 +9,27 @@ return this; }); + var restrictedChoicesMixin = Barricade.Blueprint.create(function() { + var values = this.getEnumValues(), + labels = this.getEnumLabels(), + items = {}; + + values.forEach(function(value, index) { + items[value] = labels[index]; + }); + + this.getLabel = function(value) { + return items[value]; + }; + + this.getValues = function() { + return values; + }; + + this.setType('choices'); + return this; + }); + var modelMixin = Barricade.Blueprint.create(function(type) { this.value = function() { if ( !arguments.length ) { @@ -28,7 +49,7 @@ }; this.isAtomic = function() { - return ['number', 'string', 'text'].indexOf(this.getType()) > -1; + return ['number', 'string', 'text', 'choices'].indexOf(this.getType()) > -1; }; this.getTitle = function() { var title = utils.getMeta(this, 'title'); @@ -43,6 +64,9 @@ return title; }; wildcardMixin.call(this); + if ( this.getEnumValues ) { + restrictedChoicesMixin.call(this); + } return this; }); diff --git a/merlin/static/merlin/js/merlin.init.js b/merlin/static/merlin/js/merlin.init.js index 7319457..ec77095 100644 --- a/merlin/static/merlin/js/merlin.init.js +++ b/merlin/static/merlin/js/merlin.init.js @@ -6,7 +6,7 @@ .run(function($http, $templateCache) { var fields = ['dictionary', 'frozendict', 'list', 'string', - 'text', 'group', 'number' + 'text', 'group', 'number', 'choices' ]; fields.forEach(function(field) { var base = '/static/merlin/templates/fields/'; diff --git a/merlin/static/merlin/templates/fields/choices.html b/merlin/static/merlin/templates/fields/choices.html new file mode 100644 index 0000000..a00fa7a --- /dev/null +++ b/merlin/static/merlin/templates/fields/choices.html @@ -0,0 +1,9 @@ +
+ + +