update item by reference not index

This commit is contained in:
j 2012-01-24 15:29:29 +05:30
parent 129b8154fb
commit 5f849abee3

View file

@ -336,7 +336,7 @@ Ox.AnnotationFolder = function(options, self) {
if (index == -1) { if (index == -1) {
places.push(Ox.extend({ places.push(Ox.extend({
annotationIds: [item.id] annotationIds: [item.id]
}, item.place)) }, item.place));
} else { } else {
places[index].annotationIds.push(item.id); places[index].annotationIds.push(item.id);
} }
@ -449,9 +449,9 @@ Ox.AnnotationFolder = function(options, self) {
self.setOption = function(key, value) { self.setOption = function(key, value) {
if (['in', 'out'].indexOf(key) > -1 && self.editing) { if (['in', 'out'].indexOf(key) > -1 && self.editing) {
var index = Ox.getIndexById(self.options.items, self.options.selected); var item = Ox.getObjectById(self.options.items, self.options.selected);
self.options.items[index][key] = value; item[key] = value;
self.options.items[index].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') {
@ -534,9 +534,11 @@ Ox.AnnotationFolder = function(options, self) {
}; };
*/ */
that.updateItem = function(item) { that.updateItem = function(data) {
var index = Ox.getIndexById(self.options.items, item.id); var item = Ox.getObjectById(self.options.items, data.id);
self.options.items[index] = item; Ox.forEach(data, function(value, key) {
item[key] = value;
});
updateAnnotations(); updateAnnotations();
if (self.widget && item[self.options.type]) { if (self.widget && item[self.options.type]) {
// if updating has made the item match // if updating has made the item match
@ -544,7 +546,7 @@ Ox.AnnotationFolder = function(options, self) {
self.$widget.options({selected: item[self.options.type].id}); self.$widget.options({selected: item[self.options.type].id});
} }
return that; return that;
} };
return that; return that;