diff --git a/index.html b/index.html index d7032ae..36540ff 100644 --- a/index.html +++ b/index.html @@ -70,6 +70,8 @@ + + @@ -85,4 +87,4 @@
- \ No newline at end of file + diff --git a/js/wisegui-node-table.js b/js/wisegui-node-table.js index 58b97d9..b8a88ae 100644 --- a/js/wisegui-node-table.js +++ b/js/wisegui-node-table.js @@ -195,6 +195,12 @@ WiseGuiNodeTable.prototype.getSelectedNodes = function () { return ids; }; +WiseGuiNodeTable.prototype.setSelectedNodes = function (nodeUrnArr) { + this.table.setSelectedRows(function(rowData) { + return _.contains(nodeUrnArr, rowData.id); + }); +}; + WiseGuiNodeTable.prototype.applyFilter = function (fn) { this.table.setFilterFun(fn); }; diff --git a/js/wisegui-nodeselection-load-button.js b/js/wisegui-nodeselection-load-button.js new file mode 100644 index 0000000..9d84e64 --- /dev/null +++ b/js/wisegui-nodeselection-load-button.js @@ -0,0 +1,35 @@ +/** + * ################################################################# + * WiseGuiNodeSelectionLoadButton + * ################################################################# + */ + +var WiseGuiNodeSelectionLoadButton = function(setSelectionCallback) { + var self = this; + this.view = $(''); + this.view.bind('click', this, function(e) { + if (!self.view.attr('disabled')) { + var selections = JSON.parse(window.localStorage.getItem("wisegui.nodeselections")) || {}; + setSelectionCallback(selections); + } + }); + + this.enable = function(enable) { + if (enable) { + self.view.removeAttr('disabled'); + } else { + self.view.attr('disabled', 'disabled'); + } + }; + + this.updateEnabledState = function() { + var savedSelection = window.localStorage.getItem("wisegui.nodeselections"); + this.enable(savedSelection != null && savedSelection !== undefined); + }; + + $(window).bind('wisegui-nodeselection-storage-changed', function (e) { + self.updateEnabledState(); + }); + + this.updateEnabledState(); +}; \ No newline at end of file diff --git a/js/wisegui-nodeselection-save-button.js b/js/wisegui-nodeselection-save-button.js new file mode 100644 index 0000000..b3058a2 --- /dev/null +++ b/js/wisegui-nodeselection-save-button.js @@ -0,0 +1,14 @@ +/** + * ################################################################# + * WiseGuiNodeSelectionSaveButton + * ################################################################# + */ + +var WiseGuiNodeSelectionSaveButton = function(getSelectionCallback) { + this.view = $(''); + this.view.bind('click', this, function(e) { + var selection = getSelectionCallback(); + window.localStorage.setItem("wisegui.nodeselections", JSON.stringify(selection)); + $(window).trigger('wisegui-nodeselection-storage-changed'); + }); +}; \ No newline at end of file diff --git a/js/wisegui-reservation-dialog.js b/js/wisegui-reservation-dialog.js index ef9dbbb..51464a7 100644 --- a/js/wisegui-reservation-dialog.js +++ b/js/wisegui-reservation-dialog.js @@ -349,7 +349,15 @@ WiseGuiReservationDialog.prototype.buildView = function() { e.data.hide(); }); + var nodeSelectionSaveButton = new WiseGuiNodeSelectionSaveButton(function() { + return that.table.getSelectedNodes(); + }); + + var nodeSelectionLoadButton = new WiseGuiNodeSelectionLoadButton(function(selection) { + that.table.setSelectedNodes(selection); + }) + var dialogFooter = $('