update item by id not position

This commit is contained in:
j 2020-09-22 12:48:08 +02:00
parent c2d35e615d
commit 009cdd68c3
3 changed files with 23 additions and 12 deletions

View file

@ -220,10 +220,11 @@ Ox.ArrayEditable = function(options, self) {
}, 250);
},
cancel: function(data) {
var id = $(this).data('id');
self.editing = false;
that.gainFocus();
data.value === ''
? submitItem(i, '')
? submitItem(id, '')
: that.triggerEvent('blur', data);
},
change: function(data) {
@ -247,9 +248,10 @@ Ox.ArrayEditable = function(options, self) {
that.triggerEvent('open');
},
submit: function(data) {
var id = $(this).data('id');
self.editing = false;
that.gainFocus();
submitItem(i, data.value);
submitItem(id, data.value);
}
})
.appendTo(that);
@ -364,8 +366,9 @@ Ox.ArrayEditable = function(options, self) {
}
}
function submitItem(position, value) {
var item = self.options.items[position];
function submitItem(id, value) {
var item = Ox.getObjectById(self.options.items, id);
Ox.Log('AE', 'submitItem', id, item)
if (value === '') {
deleteItem(item.id);
} else {

View file

@ -71,8 +71,10 @@ Ox.AnnotationFolder = function(options, self) {
}
if (['in', 'out'].indexOf(key) > -1 && self.editing) {
var item = Ox.getObjectById(self.options.items, self.options.selected);
item[key] = value;
item.duration = self.options.out - self.options['in'];
if (item) {
item[key] = value;
item.duration = self.options.out - self.options['in'];
}
self.points = getPoints();
}
if (key == 'in') {
@ -620,10 +622,12 @@ Ox.AnnotationFolder = function(options, self) {
function submitAnnotation(data) {
var item = Ox.getObjectById(self.options.items, data.id);
item.value = data.value;
self.editing = false;
self.options.sort == 'text' && self.$annotations.reloadItems();
that.triggerEvent('submit', item);
if (item) {
item.value = data.value;
self.editing = false;
self.options.sort == 'text' && self.$annotations.reloadItems();
that.triggerEvent('submit', item);
}
}
function toggleLayer() {
@ -749,6 +753,7 @@ Ox.AnnotationFolder = function(options, self) {
(id, data) -> <o> update item
@*/
that.updateItem = function(id, data) {
Ox.Log('AF', 'updateItem', id, data)
var item = Ox.getObjectById(self.options.items, id);
Ox.forEach(data, function(value, key) {
item[key] = value;
@ -760,7 +765,7 @@ Ox.AnnotationFolder = function(options, self) {
if (id != item.id) {
self.$annotations.find('.OxEditableElement').each(function() {
var $element = $(this);
if ($element.data('id') == self.options.selected) {
if ($element.data('id') == id) {
$element.data({id: item.id});
}
});

View file

@ -737,7 +737,10 @@ Ox.AnnotationPanel = function(options, self) {
@*/
that.blurItem = function() {
self.editing = false;
getFolder(self.options.selected).blurItem();
var $folder = getFolder(self.options.selected)
if ($folder) {
$folder.blurItem();
}
renderEditMenu();
return that;
};