Skip to content
This repository has been archived by the owner on Sep 21, 2022. It is now read-only.

Commit

Permalink
Working on Save node selections in browser storage #117
Browse files Browse the repository at this point in the history
- node selections in the "MakeReservationDialog" can now be saved on loaded using the local storage
- functionality is implemented in two button classes

Still to do:

- allow saving/loading multiple different configurations named by the user
- allow saving/loading reservation-specific configurations
- embed functionality in different contexts (e.g., flash/reset/... controls), e.g. by embedding it into the wisegui-node-table.js instead of the reservation dialog
  • Loading branch information
danbim committed Sep 23, 2014
1 parent e947109 commit 7348510
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 2 deletions.
4 changes: 3 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@
<script type="text/javascript" src="js/wisegui-reservation-dialog.js"></script>
<script type="text/javascript" src="js/wisegui-google-maps-view.js"></script>
<script type="text/javascript" src="js/wisegui-nodeselection-dialog.js"></script>
<script type="text/javascript" src="js/wisegui-nodeselection-save-button.js"></script>
<script type="text/javascript" src="js/wisegui-nodeselection-load-button.js"></script>
<script type="text/javascript" src="js/wisegui-console-view.js"></script>
<script type="text/javascript" src="js/wisegui-flash-view.js"></script>
<script type="text/javascript" src="js/wisegui-reset-view.js"></script>
Expand All @@ -85,4 +87,4 @@
<div id="WiseGuiContainer" class="container"></div>
</body>

</html>
</html>
6 changes: 6 additions & 0 deletions js/wisegui-node-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down
35 changes: 35 additions & 0 deletions js/wisegui-nodeselection-load-button.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* #################################################################
* WiseGuiNodeSelectionLoadButton
* #################################################################
*/

var WiseGuiNodeSelectionLoadButton = function(setSelectionCallback) {
var self = this;
this.view = $('<button class="btn">Load Selection</button>');
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();
};
14 changes: 14 additions & 0 deletions js/wisegui-nodeselection-save-button.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* #################################################################
* WiseGuiNodeSelectionSaveButton
* #################################################################
*/

var WiseGuiNodeSelectionSaveButton = function(getSelectionCallback) {
this.view = $('<button class="btn">Save Selection</button>');
this.view.bind('click', this, function(e) {
var selection = getSelectionCallback();
window.localStorage.setItem("wisegui.nodeselections", JSON.stringify(selection));
$(window).trigger('wisegui-nodeselection-storage-changed');
});
};
10 changes: 9 additions & 1 deletion js/wisegui-reservation-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = $('<div class="modal-footer"/>');
dialogFooter.append(okButton, cancelButton);
dialogFooter.append(nodeSelectionLoadButton.view, nodeSelectionSaveButton.view, okButton, cancelButton);
this.view.append(dialogHeader, dialogBody, dialogFooter);
};
17 changes: 17 additions & 0 deletions js/wisegui-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,23 @@ WiseGuiTable.prototype.getSelectedRows = function () {
return selected;
};

WiseGuiTable.prototype.setSelectedRows = function (selectionCallback) {

var that = this;

if(this.data != null && this.table != null) {
this.table.find("input").each(function() {
var checkbox = $(this);
var name = $(this).attr('name');
// Ignore the checkbox from the header, which doesn't have any name
if(typeof(name) != "undefined") {
var index = parseInt(name);
checkbox.prop('checked', selectionCallback(that.data[index].data));
}
});
}
};

WiseGuiTable.prototype.setFilterFun = function (fn) {

this.preFilterFun = fn;
Expand Down

0 comments on commit 7348510

Please sign in to comment.