Browse Source

Implemented function `select` for the Timeline

css_transitions
josdejong 10 years ago
parent
commit
93e2bd4b3c
5 changed files with 111 additions and 3 deletions
  1. +1
    -1
      src/module/header.js
  2. +9
    -0
      src/timeline/Timeline.js
  3. +9
    -0
      src/timeline/component/Group.js
  4. +20
    -0
      src/timeline/component/GroupSet.js
  5. +72
    -2
      src/timeline/component/ItemSet.js

+ 1
- 1
src/module/header.js View File

@ -8,7 +8,7 @@
* @date @@date
*
* @license
* Copyright (C) 2011-2013 Almende B.V, http://almende.com
* Copyright (C) 2011-2014 Almende B.V, http://almende.com
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy

+ 9
- 0
src/timeline/Timeline.js View File

@ -340,3 +340,12 @@ Timeline.prototype.getItemRange = function getItemRange() {
max: (max != null) ? new Date(max) : null
};
};
/**
* Change the item selection, and/or get currently selected items
* @param {Array} [ids] An array with zero or more ids of the items to be selected.
* @return {Array} ids The ids of the selected items
*/
Timeline.prototype.select = function select(ids) {
return this.content ? this.content.select(ids) : [];
};

+ 9
- 0
src/timeline/component/Group.js View File

@ -75,6 +75,15 @@ Group.prototype.setItems = function setItems(items) {
}
};
/**
* Change the item selection, and/or get currently selected items
* @param {Array} [ids] An array with zero or more ids of the items to be selected.
* @return {Array} ids The ids of the selected items
*/
Group.prototype.select = function select(ids) {
return this.itemset ? this.itemset.select(ids) : [];
};
/**
* Repaint the item
* @return {Boolean} changed

+ 20
- 0
src/timeline/component/GroupSet.js View File

@ -149,6 +149,26 @@ GroupSet.prototype.getGroups = function getGroups() {
return this.groupsData;
};
/**
* Change the item selection, and/or get currently selected items
* @param {Array} [ids] An array with zero or more ids of the items to be selected.
* @return {Array} ids The ids of the selected items
*/
GroupSet.prototype.select = function select(ids) {
var selection = [],
groups = this.groups;
// iterate over each of the groups
for (var id in groups) {
if (groups.hasOwnProperty(id)) {
var group = groups[id];
selection = selection.concat(group.select(ids));
}
}
return selection;
};
/**
* Repaint the component
* @return {Boolean} changed

+ 72
- 2
src/timeline/component/ItemSet.js View File

@ -53,8 +53,9 @@ function ItemSet(parent, depends, options) {
}
};
this.items = {}; // object with an Item for every data item
this.queue = {}; // queue with id/actions: 'add', 'update', 'delete'
this.items = {}; // object with an Item for every data item
this.selection = []; // list with the ids of all selected nodes
this.queue = {}; // queue with id/actions: 'add', 'update', 'delete'
this.stack = new Stack(this, Object.create(this.options));
this.conversion = null;
@ -110,6 +111,69 @@ ItemSet.prototype.setRange = function setRange(range) {
this.range = range;
};
/**
* Change the item selection, and/or get currently selected items
* @param {Array} [ids] An array with zero or more ids of the items to be selected.
* @return {Array} ids The ids of the selected items
*/
ItemSet.prototype.select = function select(ids) {
var i, ii, id, item, selection;
if (ids) {
if (!Array.isArray(ids)) {
throw new TypeError('Array expected');
}
// unselect currently selected items
for (i = 0, ii = this.selection.length; i < ii; i++) {
id = this.selection[i];
item = this.items[id];
if (item) item.unselect();
}
// select items
this.selection = [];
for (i = 0, ii = ids.length; i < ii; i++) {
id = ids[i];
item = this.items[id];
if (item) {
this.selection.push(id);
item.select();
}
}
// trigger a select event
selection = this.selection.concat([]);
events.trigger(this, 'select', {
ids: selection
});
if (this.controller) {
this.requestRepaint();
}
}
else {
selection = this.selection.concat([]);
}
return selection;
};
/**
* Deselect a selected item
* @param {String | Number} id
* @private
*/
ItemSet.prototype._deselect = function _deselect(id) {
var selection = this.selection;
for (var i = 0, ii = selection.length; i < ii; i++) {
if (selection[i] == id) { // non-strict comparison!
selection.splice(i, 1);
break;
}
}
};
/**
* Repaint the component
* @return {Boolean} changed
@ -234,6 +298,7 @@ ItemSet.prototype.repaint = function repaint() {
// create item
if (constructor) {
item = new constructor(me, itemData, options, defaultOptions);
item.id = id;
changed++;
}
else {
@ -253,6 +318,11 @@ ItemSet.prototype.repaint = function repaint() {
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();
}

Loading…
Cancel
Save