add/remove annotations

This commit is contained in:
j 2011-02-11 20:14:32 +05:30
parent bb6ddcc3dd
commit fb6d793772

View file

@ -7690,9 +7690,8 @@ requires
var $input, var $input,
item = self.options.items[pos], item = self.options.items[pos],
$item = self.$items[pos]; $item = self.$items[pos];
Ox.print('****', $item) Ox.print('****', item, $item)
var html = $item.$element.html(), var width = $item.width(), // fixme: don't lookup in DOM
width = $item.width(), // fixme: don't lookup in DOM
height = $item.height(); height = $item.height();
$item $item
.height(height + 8) .height(height + 8)
@ -7756,19 +7755,31 @@ requires
}; };
that.removeItems = function(pos, length) { that.removeItems = function(pos, length) {
Ox.range(pos, pos + length).forEach(function(i) { /*
self.selected.indexOf(i) > -1 && deselect(i); removeItems(ids)
self.$items[i].remove(); or
}); removeItems(pos, length)
self.options.items.splice(pos, length); */
self.$items.splice(pos, length); if(!length) { //pos is list of ids
self.selected.forEach(function(v, i) { pos.forEach(function(id) {
if (v >= pos + length) { var p = getPositionById(id);
self.selected[i] -= length; that.removeItems(p, 1);
} });
}); } else { //remove items from pos to pos+length
updatePositions(); Ox.range(pos, pos + length).forEach(function(i) {
} self.selected.indexOf(i) > -1 && deselect(i);
self.$items[i].remove();
});
self.options.items.splice(pos, length);
self.$items.splice(pos, length);
self.selected.forEach(function(v, i) {
if (v >= pos + length) {
self.selected[i] -= length;
}
});
updatePositions();
}
}
that.scrollToSelection = function() { that.scrollToSelection = function() {
self.selected.length && scrollToPosition(self.selected[0]); self.selected.length && scrollToPosition(self.selected[0]);
@ -10737,6 +10748,10 @@ requires
style: 'symbol', style: 'symbol',
title: 'Add', title: 'Add',
type: 'image' type: 'image'
}).bindEvent({
click: function(event, data) {
that.triggerEvent('add', {value: ''});
}
}) })
], ],
size: 16, size: 16,
@ -10764,10 +10779,15 @@ requires
}) })
.bindEvent({ .bindEvent({
open: function(event, data) { open: function(event, data) {
if (data.ids.length == 1) if (data.ids.length == 1) {
self.$annotations.editItem(data.ids[0]); var pos = Ox.getPositionById(self.$annotations.options('items'), data.ids[0]);
self.$annotations.editItem(pos);
}
},
'delete': function(event, data) {
that.triggerEvent('delete', data);
}, },
//edit: editAnnotation,
select: selectAnnotation, select: selectAnnotation,
submit: updateAnnotation submit: updateAnnotation
}) })
@ -10787,21 +10807,6 @@ requires
.appendTo(self.$annotations); .appendTo(self.$annotations);
}); });
*/ */
/* done in list now
function editAnnotation(event, data) {
return;
var pos = parseInt(data.id),
item = self.options.items[pos];
self.$annotation[pos].html(
new Ox.Input({
height: 128,
type: 'textarea',
value: item.value,
width: self.options.width
})
);
}
*/
function selectAnnotation(event, data) { function selectAnnotation(event, data) {
var item = Ox.getObjectById(self.options.items, data.ids[0]); var item = Ox.getObjectById(self.options.items, data.ids[0]);
that.triggerEvent('select', { that.triggerEvent('select', {
@ -10819,6 +10824,17 @@ requires
} }
that.addItem = function(item) {
var pos = 0;
self.options.items.splice(pos, 0, item);
self.$annotations.addItems(pos, [item]);
self.$annotations.editItem(pos);
}
that.removeItems = function(ids) {
self.$annotations.removeItems(ids);
}
return that; return that;
}; };
@ -11895,9 +11911,20 @@ requires
}, layer) }, layer)
) )
.bindEvent({ .bindEvent({
add: function(event, data) {
data.layer = layer.id;
data.in = self.options.points[0];
data.out = self.options.points[1];
that.triggerEvent('addAnnotation', data);
},
'delete': function(event, data) {
data.layer = layer.id;
that.triggerEvent('removeAnnotations', data);
},
select: selectAnnotation, select: selectAnnotation,
submit: updateAnnotation submit: updateAnnotation
}) });
self.$annotationPanel[i]
.appendTo(self.$annotations); .appendTo(self.$annotations);
}); });
@ -12234,6 +12261,16 @@ requires
} }
}; };
that.addAnnotation = function(layer, item) {
var i = Ox.getPositionById(self.options.layers, layer);
self.$annotationPanel[i].addItem(item);
}
that.removeAnnotations = function(layer, ids) {
var i = Ox.getPositionById(self.options.layers, layer);
self.$annotationPanel[i].removeItems(ids);
}
return that; return that;
}; };