Show drop-down widget for @enum mixins
Change-Id: Ied834c055eabcb6bbd12ed1c388a854befd7c0b7
This commit is contained in:
parent
5a138fe066
commit
a849faa7a9
@ -178,6 +178,13 @@ var Barricade = (function () {
|
||||
return id;
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks whether the ID is set for this item.
|
||||
* @method hasID
|
||||
* @memberof Barricade.Identifiable
|
||||
* @instance
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
this.hasID = function() {
|
||||
return id !== undefined;
|
||||
};
|
||||
|
@ -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;
|
||||
});
|
||||
|
||||
|
@ -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/';
|
||||
|
9
merlin/static/merlin/templates/fields/choices.html
Normal file
9
merlin/static/merlin/templates/fields/choices.html
Normal 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>
|
Loading…
Reference in New Issue
Block a user