diff --git a/src/main/webapp/resources/js/base/dataset.js b/src/main/webapp/resources/js/base/dataset.js
index 0e60caa..b85b092 100644
--- a/src/main/webapp/resources/js/base/dataset.js
+++ b/src/main/webapp/resources/js/base/dataset.js
@@ -416,6 +416,7 @@ class Dataset {
"onModify",
"onReplace",
"onRemove",
+ "onMove",
"onDirtiesChange",
"onSort"
].forEach(on => {
@@ -756,6 +757,72 @@ class Dataset {
this.onCurrentChange(item);
}
}
+ /**Scrolls up or down depending on the offset and fires the {@link Dataset#onCurrentChange onCurrentChange} event.
+ * If the new position surpasses either top or bottom of the Dataset, the first or last DataItem is set current.
+ * @param {number} offset
+ *
- negative integer to scroll up
+ * - positive integer to scroll down
+ *
+ * @returns {Dataset} this Dataset
+ */
+ scroll(offset) {
+ if (!offset)
+ return this;
+ let items = this.getDataset("item"),
+ length = items.length;
+ if (length < 2)
+ return this;
+
+ let current = items.indexOf(this.getCurrent("item")),
+ pos = current + offset;
+ pos = offset < 0 ? Math.max(0, pos) : Math.min(length - 1, pos);
+ let item = items[pos];
+ if (!item)
+ return this;
+
+ this._current = item;
+ this.onCurrentChange(item);
+
+ return this;
+ }
+
+ /**Moves the item of the Dataset to the position at the index and fires the events of
+ * - {@link Dataset#onDatasetChange onDatasetChange}
+ * - {@link Dataset#onCurrentChange onCurrentChange}
+ * - {@link Dataset#onSelectionChange onSelectionChange}
+ * - {@link Dataset#onDirtyStateChange onDirtyStateChange}
+ * - {@link Dataset#onSort onSort}
+ *
+ * If the index surpasses either top or bottom of the Dataset,
+ * it is adjusted to the start or end of the items.
+ * @param {DataItem} item an item of the Dataset
+ * @param {number} index 0-based index
+ */
+ move(item, index) {
+ if (!item) return this;
+
+ let items = this.getDataset("item"),
+ length = items.length;
+ if (length < 1) return this;
+
+ let pos = this._items.indexOf(item);
+ if (pos < 0) return this;
+
+ index = Math.max(0, index);
+ index = Math.min(length - 1, index);
+ if (pos == index) return this;
+
+ let dest = items[index];
+ index = this._items.indexOf(dest);
+
+ this._items.splice(pos, 1);
+ this._items.splice(index, 0, item);
+
+ this.onMove(item);
+ this.setState();
+
+ return this;
+ }
/**Returns the Dataset's current state in an object.
* The object has the properties as follows.
@@ -1449,6 +1516,11 @@ class Dataset {
*/
onRemove(removed) {this.log("Data removed", removed)}
+ /**Called back when user data are removed.
+ * @param {array} removed array of removed dataItems
+ */
+ onMove(item) {this.log("Data moved", item)}
+
/**Called back when the Dataset gets dirty or not dirty.
* @param {boolean} dirty
* - true if the Dataset is dirty
@@ -1491,6 +1563,7 @@ class DatasetControl {
conf.onDirtiesChange = dirty => this.onDirtiesChange(dirty);
conf.onReplace = obj => this.onReplace(obj);
conf.onSort = status => this.onSort(status);
+ conf.onMove = item => this.onMove(item);
this.dataset = new Dataset(conf);
@@ -1747,6 +1820,10 @@ class DatasetControl {
this.reload({prev: selected.length == this.dataset.length});
}
+ onMove(item) {
+ debug("on move", item);
+ }
+
clear() {
this.dataset.clear();
}