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

View file

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

View file

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