From: Scott Baker Date: Tue, 20 Jan 2015 08:20:12 +0000 (-0800) Subject: set dirty if users edited, warning message if change slice while dirty X-Git-Url: http://git.onelab.eu/?p=plstackapi.git;a=commitdiff_plain;h=c2d7c700233884cf21df441192598df8347994ea set dirty if users edited, warning message if change slice while dirty --- diff --git a/planetstack/core/xoslib/static/js/xosTenant.js b/planetstack/core/xoslib/static/js/xosTenant.js index 10e70e6..286537d 100644 --- a/planetstack/core/xoslib/static/js/xosTenant.js +++ b/planetstack/core/xoslib/static/js/xosTenant.js @@ -102,6 +102,7 @@ XOSTenantApp = new XOSApplication({ logTableId: "#logTable", statusMsgId: "#statusMsg", hideTabsByDefault: true, + dirty: false, varName: "XOSTenantApp", }); @@ -115,6 +116,7 @@ XOSTenantApp.addRegions({ }); XOSTenantApp.setDirty = function(dirty) { + XOSTenantApp.dirty = dirty; if (dirty) { $("button.btn-tenant-save").addClass("btn-success"); } else { @@ -253,6 +255,9 @@ XOSTenantApp.editUsers = function(model) { var editDialog = this; user_ids = all_options($("#tenant-edit-users-dialog").find(".select-picker-to")); user_ids = user_ids.map( function(x) { return parseInt(x,10); } ); + if (!array_same_elements(user_ids, model.usersBuffer)) { + XOSTenantApp.setDirty(true); + } model.usersBuffer = user_ids; $(editDialog).dialog("close"); }, @@ -270,6 +275,15 @@ XOSTenantApp.deleteSlice = function(model) { }; XOSTenantApp.viewSlice = function(model) { + if (XOSTenantApp.dirty) { + if (!confirm("The current sliver has unsaved data -- view new sliver anyway ?")) { + $("#tenantSliceSelector select").val(XOSTenantApp.currentSlice.id); + return; + } + } + + XOSTenantApp.setDirty(false); + if (!model && xos.slicesPlus.models.length > 0) { model = xos.slicesPlus.models[0]; } @@ -303,6 +317,8 @@ XOSTenantApp.viewSlice = function(model) { XOSTenantApp.tenantButtons.show( new XOSTenantButtonView( { app: XOSTenantApp, linkedView: tenantSummary } ) ); + + XOSTenantApp.currentSlice = model; } else { XOSTenantApp.tenantSliceSelector.show(new HTMLView({html: ""})); XOSTenantApp.tenantSummary.show(new HTMLView({html: "You have no slices"})); diff --git a/planetstack/core/xoslib/static/js/xoslib/xos-util.js b/planetstack/core/xoslib/static/js/xoslib/xos-util.js index 59fb06e..1c42e26 100644 --- a/planetstack/core/xoslib/static/js/xoslib/xos-util.js +++ b/planetstack/core/xoslib/static/js/xoslib/xos-util.js @@ -105,6 +105,12 @@ function array_subtract(a1, a2) return result; } +function array_same_elements(arr1, arr2) +{ + // return true if arrays have same elements, even if order is different + return ($(arr1).not(arr2).length == 0 && $(arr2).not(arr1).length == 0); +} + function array_pair_lookup(x, names, values) { for (index in values) {