Merge "Fix changing the key in dictionary widget"
This commit is contained in:
commit
a08c69b0d2
@ -185,19 +185,31 @@
|
|||||||
var dictionaryModel = Barricade.MutableObject.extend({
|
var dictionaryModel = Barricade.MutableObject.extend({
|
||||||
create: function(json, parameters) {
|
create: function(json, parameters) {
|
||||||
var self = Barricade.MutableObject.create.call(this, json, parameters),
|
var self = Barricade.MutableObject.create.call(this, json, parameters),
|
||||||
_items = {},
|
_items = [],
|
||||||
_elClass = self._elementClass,
|
_elClass = self._elementClass,
|
||||||
baseKey = utils.getMeta(_elClass, 'baseKey') || 'key',
|
baseKey = utils.getMeta(_elClass, 'baseKey') || 'key',
|
||||||
baseName = utils.getMeta(_elClass, 'baseName') || utils.makeTitle(baseKey);
|
baseName = utils.getMeta(_elClass, 'baseName') || utils.makeTitle(baseKey);
|
||||||
|
|
||||||
modelMixin.call(self, 'dictionary');
|
modelMixin.call(self, 'dictionary');
|
||||||
|
|
||||||
|
function makeCacheWrapper(container, key) {
|
||||||
|
var value = container.getByID(key);
|
||||||
|
value.keyValue = function () {
|
||||||
|
if ( arguments.length ) {
|
||||||
|
value.setID(arguments[0]);
|
||||||
|
} else {
|
||||||
|
return value.getID();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
self.add = function(newID) {
|
self.add = function(newID) {
|
||||||
var regexp = new RegExp('(' + baseKey + ')([0-9]+)'),
|
var regexp = new RegExp('(' + baseKey + ')([0-9]+)'),
|
||||||
newValue;
|
newValue;
|
||||||
newID = newID || baseKey + utils.getNextIDSuffix(self, regexp);
|
newID = newID || baseKey + utils.getNextIDSuffix(self, regexp);
|
||||||
if ( _elClass.instanceof(Barricade.ImmutableObject) ) {
|
if (_elClass.instanceof(Barricade.ImmutableObject)) {
|
||||||
if ( 'name' in _elClass._schema ) {
|
if ('name' in _elClass._schema) {
|
||||||
var nameNum = utils.getNextIDSuffix(self, regexp);
|
var nameNum = utils.getNextIDSuffix(self, regexp);
|
||||||
newValue = {name: baseName + nameNum};
|
newValue = {name: baseName + nameNum};
|
||||||
} else {
|
} else {
|
||||||
@ -207,19 +219,12 @@
|
|||||||
newValue = '';
|
newValue = '';
|
||||||
}
|
}
|
||||||
self.push(newValue, utils.extend(self._parameters, {id: newID}));
|
self.push(newValue, utils.extend(self._parameters, {id: newID}));
|
||||||
_items[newID] = self.getByID(newID);
|
_items.push(makeCacheWrapper(self, newID));
|
||||||
};
|
};
|
||||||
self.getValues = function() {
|
self.getValues = function() {
|
||||||
if ( !Object.keys(_items).length ) {
|
if ( !_items.length ) {
|
||||||
self.getIDs().forEach(function(id) {
|
_items = self.toArray().map(function(value) {
|
||||||
_items[id] = self.getByID(id);
|
return makeCacheWrapper(self, value.getID());
|
||||||
_items[id].keyValue = function() {
|
|
||||||
if ( !arguments.length ) {
|
|
||||||
return this.getID();
|
|
||||||
} else {
|
|
||||||
this.setID(arguments[0]);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return _items;
|
return _items;
|
||||||
@ -228,8 +233,9 @@
|
|||||||
return self.toArray();
|
return self.toArray();
|
||||||
};
|
};
|
||||||
self.remove = function(key) {
|
self.remove = function(key) {
|
||||||
delete _items[key];
|
var pos = self.getPosByID(key);
|
||||||
Barricade.MutableObject.remove.call(self, self.getPosByID(key));
|
Barricade.MutableObject.remove.call(self, pos);
|
||||||
|
_items.splice(pos, 1);
|
||||||
};
|
};
|
||||||
meldGroup.call(self);
|
meldGroup.call(self);
|
||||||
return self;
|
return self;
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
<collapsible-group content="value" on-add="value.add()">
|
<collapsible-group content="value" on-add="value.add()">
|
||||||
<div class="three-columns" ng-repeat="(key, subvalue) in value.getValues() track by key">
|
<div class="three-columns" ng-repeat="subvalue in value.getValues() track by subvalue.keyValue()">
|
||||||
<div class="left-column">
|
<div class="left-column">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="elem-{$ $id $}.{$ key $}">
|
<label for="elem-{$ $id $}.{$ subvalue.uid() $}">
|
||||||
<editable ng-model="subvalue.keyValue" ng-model-options="{getterSetter: true}"></editable>
|
<editable ng-model="subvalue.keyValue" ng-model-options="{getterSetter: true}"></editable>
|
||||||
</label>
|
</label>
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<input id="elem-{$ $id $}.{$ key $}" type="text" class="form-control" ng-model="subvalue.value"
|
<input id="elem-{$ $id $}.{$ subvalue.uid() $}" type="text" class="form-control"
|
||||||
ng-model-options="{ getterSetter: true }">
|
ng-model="subvalue.value" ng-model-options="{ getterSetter: true }">
|
||||||
<span class="input-group-btn">
|
<span class="input-group-btn">
|
||||||
<button class="btn btn-default fa fa-minus-circle" type="button"
|
<button class="btn btn-default fa fa-minus-circle" type="button"
|
||||||
ng-click="value.remove(key)"></button>
|
ng-click="value.remove(subvalue.keyValue())"></button>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user