Show drop-down widget for @enum mixins

Change-Id: Ied834c055eabcb6bbd12ed1c388a854befd7c0b7
This commit is contained in:
Timur Sufiev 2015-03-11 16:19:04 +03:00
parent 5a138fe066
commit a849faa7a9
4 changed files with 45 additions and 5 deletions

View File

@ -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.

View File

@ -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;
});

View File

@ -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/';

View File

@ -0,0 +1,9 @@
<div class="form-group">
<label for="elem-{$ $id $}.$index">{$ title $}</label>
<select id="elem-{$ $id $}.$index" class="form-control"
ng-model="value.value" ng-model-options="{getterSetter: true}">
<option ng-repeat="option in value.getValues()"
value="{$ option $}"
ng-selected="value.get() == option">{$ value.getLabel(option) $}</option>
</select>
</div>