select multple annotations, option to pass confirm delete dialog
This commit is contained in:
parent
96d4dfe71d
commit
03eb3d4a56
4 changed files with 42 additions and 19 deletions
|
|
@ -25,6 +25,7 @@ Ox.ArrayEditable = function(options, self) {
|
|||
var that = Ox.Element({}, self)
|
||||
.defaults({
|
||||
clickLink: null,
|
||||
confirmDeleteDialog: null,
|
||||
editable: true,
|
||||
format: null,
|
||||
getSortValue: null,
|
||||
|
|
@ -120,19 +121,27 @@ Ox.ArrayEditable = function(options, self) {
|
|||
// it is possible to delete an (empty-value) item
|
||||
// by selecting another one
|
||||
id = id || self.options.selected;
|
||||
var position = Ox.getIndexById(self.options.items, id)
|
||||
if (self.options.editable) {
|
||||
self.options.items.splice(position, 1);
|
||||
renderItems();
|
||||
that.triggerEvent('delete', {id: id});
|
||||
self.editing = false;
|
||||
if (self.options.selected == id) {
|
||||
self.selected = -1;
|
||||
self.options.selected = '';
|
||||
} else if (self.options.selected) {
|
||||
self.selected = Ox.getIndexById(self.options.item, self.options.selected)
|
||||
|
||||
(self.options.confirmDeleteDialog ? self.options.confirmDeleteDialog: Ox.noop)({
|
||||
items: Ox.isArray(id) ? id : [id],
|
||||
}, function(result) {
|
||||
if (self.options.editable) {
|
||||
(Ox.isArray(id) ? id : [id]).forEach(id => {
|
||||
var position = Ox.getIndexById(self.options.items, id)
|
||||
self.options.items.splice(position, 1);
|
||||
that.triggerEvent('delete', {id: id});
|
||||
})
|
||||
renderItems();
|
||||
self.editing = false;
|
||||
if (self.options.selected == id) {
|
||||
self.selected = -1;
|
||||
self.options.selected = '';
|
||||
} else if (self.options.selected) {
|
||||
self.selected = Ox.getIndexById(self.options.item, self.options.selected)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
function doubleclick(e) {
|
||||
|
|
@ -290,12 +299,20 @@ Ox.ArrayEditable = function(options, self) {
|
|||
if (!Ox.isArray(self.selected)) {
|
||||
self.selected = [self.selected]
|
||||
}
|
||||
if (self.options.selected.includes(id)) {
|
||||
self.options.selected.pop(id)
|
||||
self.selected.pop(position)
|
||||
} else {
|
||||
self.options.selected.push(id)
|
||||
self.selected.push(position)
|
||||
if (!self.options.selected.includes(id)) {
|
||||
var minPos, maxPos;
|
||||
if (Ox.min(self.selected) > position) {
|
||||
minPos = position
|
||||
maxPos = Ox.min(self.selected)
|
||||
} else {
|
||||
minPos = Ox.max(self.selected) + 1
|
||||
maxPos = position + 1
|
||||
}
|
||||
Ox.range(minPos, maxPos).forEach(pos => {
|
||||
self.selected.push(pos)
|
||||
self.options.selected.push(getId(pos))
|
||||
})
|
||||
|
||||
}
|
||||
that.find('.OxSelected').removeClass('OxSelected').removeClass('OxMultiple');
|
||||
that.find('.OxGroup').removeClass('OxGroup')
|
||||
|
|
@ -371,7 +388,7 @@ Ox.ArrayEditable = function(options, self) {
|
|||
position = $element.data('position');
|
||||
// if clicked on an element
|
||||
if (position != self.selected) {
|
||||
if (e.shiftKey) {
|
||||
if (e.shiftKey && self.selected != -1) {
|
||||
// add/remove item from multiple selection
|
||||
document.getSelection().removeAllRanges();
|
||||
toggleItem(position);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue