set dirty if users edited, warning message if change slice while dirty
authorScott Baker <smbaker@gmail.com>
Tue, 20 Jan 2015 08:20:12 +0000 (00:20 -0800)
committerScott Baker <smbaker@gmail.com>
Tue, 20 Jan 2015 08:20:12 +0000 (00:20 -0800)
planetstack/core/xoslib/static/js/xosTenant.js
planetstack/core/xoslib/static/js/xoslib/xos-util.js

index 10e70e6..286537d 100644 (file)
@@ -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) {
 };\r
 \r
 XOSTenantApp.viewSlice = function(model) {\r
+    if (XOSTenantApp.dirty) {\r
+        if (!confirm("The current sliver has unsaved data -- view new sliver anyway ?")) {\r
+            $("#tenantSliceSelector select").val(XOSTenantApp.currentSlice.id);\r
+            return;\r
+        }\r
+    }\r
+\r
+    XOSTenantApp.setDirty(false);\r
+\r
     if (!model && xos.slicesPlus.models.length > 0) {\r
         model = xos.slicesPlus.models[0];\r
     }\r
@@ -303,6 +317,8 @@ XOSTenantApp.viewSlice = function(model) {
 \r
         XOSTenantApp.tenantButtons.show( new XOSTenantButtonView( { app: XOSTenantApp,\r
                                                                     linkedView: tenantSummary } ) );\r
+\r
+        XOSTenantApp.currentSlice = model;\r
     } else {\r
         XOSTenantApp.tenantSliceSelector.show(new HTMLView({html: ""}));\r
         XOSTenantApp.tenantSummary.show(new HTMLView({html: "You have no slices"}));\r
index 59fb06e..1c42e26 100644 (file)
@@ -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) {