fix users list not subtracted properly when displaying picker
authorScott Baker <smbaker@gmail.com>
Sat, 17 Jan 2015 03:26:54 +0000 (19:26 -0800)
committerScott Baker <smbaker@gmail.com>
Sat, 17 Jan 2015 03:26:54 +0000 (19:26 -0800)
planetstack/core/xoslib/dashboards/xosTenant.html
planetstack/core/xoslib/objects/sliceplus.py
planetstack/core/xoslib/static/js/xosTenant.js
planetstack/core/xoslib/static/js/xoslib/xos-util.js

index ca74d5c..1287e15 100644 (file)
 
 <script type="text/template" id="tenant-edit-users">
     <%= xosPickerTemplate({pickedItems: model.usersBuffer,
-                          unpickedItems: array_diff(xos.tenant().current_user_site_users, model.usersBuffer),
+                          unpickedItems: array_subtract(xos.tenant().current_user_site_users, model.usersBuffer),
                           id: "users",
                           fieldName: "users",
                           detailView: detailView,
-                          lookupFunc: function(x) { return array_pair_lookup(x, xos.tenant().current_user_site_user_names, xos.tenant().current_user_site_users); },
+                          lookupFunc: function(x) { return array_pair_lookup(x,
+                                                     $.merge($.merge([], xos.tenant().current_user_site_user_names), model.user_namesOrig),
+                                                     $.merge($.merge([], xos.tenant().current_user_site_users), model.usersOrig)); },
                           } ) %>
 </script>
 
index 4fdc824..9a70e25 100644 (file)
@@ -57,6 +57,10 @@ class SlicePlus(Slice, PlusObjectMixin):
     def user_names(self):
         return [user["name"] for user in self.getSliceInfo()["users"].values()]
 
+    @user_names.setter
+    def user_names(self, value):
+        pass # it's read-only
+
     @property
     def users(self):
         return [user["id"] for user in self.getSliceInfo()["users"].values()]
index 929552c..96465d3 100644 (file)
@@ -264,6 +264,8 @@ XOSTenantApp.viewSlice = function(model) {
         tenantSites = new XOSTenantSiteCollection();\r
         tenantSites.getFromSlice(model);\r
         model.usersBuffer = model.attributes.users; /* save a copy of 'users' that we can edit. This prevents another view (developer) from overwriting our copy with a fetch from the server */\r
+        model.usersOrig = model.attributes.users;   /* save an immutable copy that we'll use for username lookups */\r
+        model.user_namesOrig = model.attributes.user_names;\r
         model.tenantSiteCollection = tenantSites;\r
         XOSTenantApp.tenantSites = tenantSites;\r
 \r
index 7a57d8a..59fb06e 100644 (file)
@@ -93,6 +93,18 @@ function array_diff(a1, a2)
   return diff;\r
 }
 
+function array_subtract(a1, a2)
+{
+    result=[]
+    for (index in a1) {
+        value = a1[index];
+        if (!$.inArray(value, a2) >= 0) {
+            result.push(value);
+        }
+    }
+    return result;
+}
+
 function array_pair_lookup(x, names, values)
 {
     for (index in values) {