|
@ -262,80 +262,82 @@ ItemSet.prototype.repaint = function repaint() { |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
// show/hide added/changed/removed items
|
|
|
// show/hide added/changed/removed items
|
|
|
Object.keys(queue).forEach(function (id) { |
|
|
|
|
|
//var entry = queue[id];
|
|
|
|
|
|
var action = queue[id]; |
|
|
|
|
|
var item = items[id]; |
|
|
|
|
|
//var item = entry.item;
|
|
|
|
|
|
//noinspection FallthroughInSwitchStatementJS
|
|
|
|
|
|
switch (action) { |
|
|
|
|
|
case 'add': |
|
|
|
|
|
case 'update': |
|
|
|
|
|
var itemData = itemsData && itemsData.get(id, dataOptions); |
|
|
|
|
|
|
|
|
|
|
|
if (itemData) { |
|
|
|
|
|
var type = itemData.type || |
|
|
|
|
|
(itemData.start && itemData.end && 'range') || |
|
|
|
|
|
options.type || |
|
|
|
|
|
'box'; |
|
|
|
|
|
var constructor = ItemSet.types[type]; |
|
|
|
|
|
|
|
|
|
|
|
// TODO: how to handle items with invalid data? hide them and give a warning? or throw an error?
|
|
|
|
|
|
if (item) { |
|
|
|
|
|
// update item
|
|
|
|
|
|
if (!constructor || !(item instanceof constructor)) { |
|
|
|
|
|
// item type has changed, hide and delete the item
|
|
|
|
|
|
changed += item.hide(); |
|
|
|
|
|
item = null; |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
item.data = itemData; // TODO: create a method item.setData ?
|
|
|
|
|
|
changed++; |
|
|
|
|
|
|
|
|
for (var id in queue) { |
|
|
|
|
|
if (queue.hasOwnProperty(id)) { |
|
|
|
|
|
var entry = queue[id], |
|
|
|
|
|
item = items[id], |
|
|
|
|
|
action = entry.action; |
|
|
|
|
|
|
|
|
|
|
|
//noinspection FallthroughInSwitchStatementJS
|
|
|
|
|
|
switch (action) { |
|
|
|
|
|
case 'add': |
|
|
|
|
|
case 'update': |
|
|
|
|
|
var itemData = itemsData && itemsData.get(id, dataOptions); |
|
|
|
|
|
|
|
|
|
|
|
if (itemData) { |
|
|
|
|
|
var type = itemData.type || |
|
|
|
|
|
(itemData.start && itemData.end && 'range') || |
|
|
|
|
|
options.type || |
|
|
|
|
|
'box'; |
|
|
|
|
|
var constructor = ItemSet.types[type]; |
|
|
|
|
|
|
|
|
|
|
|
// TODO: how to handle items with invalid data? hide them and give a warning? or throw an error?
|
|
|
|
|
|
if (item) { |
|
|
|
|
|
// update item
|
|
|
|
|
|
if (!constructor || !(item instanceof constructor)) { |
|
|
|
|
|
// item type has changed, hide and delete the item
|
|
|
|
|
|
changed += item.hide(); |
|
|
|
|
|
item = null; |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
item.data = itemData; // TODO: create a method item.setData ?
|
|
|
|
|
|
changed++; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!item) { |
|
|
|
|
|
// create item
|
|
|
|
|
|
if (constructor) { |
|
|
|
|
|
item = new constructor(me, itemData, options, defaultOptions); |
|
|
|
|
|
item.id = id; |
|
|
|
|
|
changed++; |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
throw new TypeError('Unknown item type "' + type + '"'); |
|
|
|
|
|
|
|
|
if (!item) { |
|
|
|
|
|
// create item
|
|
|
|
|
|
if (constructor) { |
|
|
|
|
|
item = new constructor(me, itemData, options, defaultOptions); |
|
|
|
|
|
item.id = entry.id; // we take entry.id, as id itself is stringified
|
|
|
|
|
|
changed++; |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
throw new TypeError('Unknown item type "' + type + '"'); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// force a repaint (not only a reposition)
|
|
|
|
|
|
item.repaint(); |
|
|
|
|
|
|
|
|
// force a repaint (not only a reposition)
|
|
|
|
|
|
item.repaint(); |
|
|
|
|
|
|
|
|
items[id] = item; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
items[id] = item; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// update queue
|
|
|
|
|
|
delete queue[id]; |
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
// update queue
|
|
|
|
|
|
delete queue[id]; |
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
case 'remove': |
|
|
|
|
|
if (item) { |
|
|
|
|
|
// remove the item from the set selected items
|
|
|
|
|
|
if (item.selected) { |
|
|
|
|
|
me._deselect(id); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
case 'remove': |
|
|
|
|
|
if (item) { |
|
|
|
|
|
// remove the item from the set selected items
|
|
|
|
|
|
if (item.selected) { |
|
|
|
|
|
me._deselect(id); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// remove DOM of the item
|
|
|
|
|
|
changed += item.hide(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// remove DOM of the item
|
|
|
|
|
|
changed += item.hide(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// update lists
|
|
|
|
|
|
delete items[id]; |
|
|
|
|
|
delete queue[id]; |
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
// update lists
|
|
|
|
|
|
delete items[id]; |
|
|
|
|
|
delete queue[id]; |
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
default: |
|
|
|
|
|
console.log('Error: unknown action "' + action + '"'); |
|
|
|
|
|
|
|
|
default: |
|
|
|
|
|
console.log('Error: unknown action "' + action + '"'); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
}); |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// reposition all items. Show items only when in the visible area
|
|
|
// reposition all items. Show items only when in the visible area
|
|
|
util.forEach(this.items, function (item) { |
|
|
util.forEach(this.items, function (item) { |
|
@ -546,7 +548,10 @@ ItemSet.prototype._onRemove = function _onRemove(ids) { |
|
|
ItemSet.prototype._toQueue = function _toQueue(action, ids) { |
|
|
ItemSet.prototype._toQueue = function _toQueue(action, ids) { |
|
|
var queue = this.queue; |
|
|
var queue = this.queue; |
|
|
ids.forEach(function (id) { |
|
|
ids.forEach(function (id) { |
|
|
queue[id] = action; |
|
|
|
|
|
|
|
|
queue[id] = { |
|
|
|
|
|
id: id, |
|
|
|
|
|
action: action |
|
|
|
|
|
}; |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
if (this.controller) { |
|
|
if (this.controller) { |
|
|