Author: orudyy
Date: Thu Sep 19 15:36:14 2013
New Revision: 1524771

URL: http://svn.apache.org/r1524771
Log:
QPID-5138: Add functionality to delete user preferences from web management 
console

Modified:
    
qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/resources/common/TimeZoneSelector.html
    
qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/util.js
    
qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/Preferences.js
    
qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/resources/showPreferences.html

Modified: 
qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/resources/common/TimeZoneSelector.html
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/resources/common/TimeZoneSelector.html?rev=1524771&r1=1524770&r2=1524771&view=diff
==============================================================================
--- 
qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/resources/common/TimeZoneSelector.html
 (original)
+++ 
qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/resources/common/TimeZoneSelector.html
 Thu Sep 19 15:36:14 2013
@@ -1,3 +1,23 @@
+<!--
+ -
+ - Licensed to the Apache Software Foundation (ASF) under one
+ - or more contributor license agreements.  See the NOTICE file
+ - distributed with this work for additional information
+ - regarding copyright ownership.  The ASF licenses this file
+ - to you under the Apache License, Version 2.0 (the
+ - "License"); you may not use this file except in compliance
+ - with the License.  You may obtain a copy of the License at
+ -
+ -   http://www.apache.org/licenses/LICENSE-2.0
+ -
+ - Unless required by applicable law or agreed to in writing,
+ - software distributed under the License is distributed on an
+ - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ - KIND, either express or implied.  See the License for the
+ - specific language governing permissions and limitations
+ - under the License.
+ -
+ -->
 <table cellpadding="0" cellspacing="2">
     <tr>
         <td>Region</td>

Modified: 
qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/util.js
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/util.js?rev=1524771&r1=1524770&r2=1524771&view=diff
==============================================================================
--- 
qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/util.js
 (original)
+++ 
qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/util.js
 Thu Sep 19 15:36:14 2013
@@ -77,10 +77,10 @@ define(["dojo/_base/xhr",
                return exchangeName == null || exchangeName == "" || 
"<<default>>" == exchangeName || exchangeName.indexOf("amq.") == 0 || 
exchangeName.indexOf("qpid.") == 0;
            };
 
-           util.deleteGridSelections = function(updater, grid, url, 
confirmationMessageStart)
+           util.deleteGridSelections = function(updater, grid, url, 
confirmationMessageStart, idParam)
            {
                var data = grid.selection.getSelected();
-
+               var success = false;
                if(data.length)
                {
                    var confirmationMessage = null;
@@ -114,18 +114,19 @@ define(["dojo/_base/xhr",
                            {
                                queryParam = "?";
                            }
-                           queryParam += "id=" + data[i].id;
+                           queryParam += ( idParam || "id" ) + "=" + 
encodeURIComponent(data[i].id);
                        }
                        var query = url + queryParam;
-                       var success = true
                        var failureReason = "";
                        xhr.del({url: query, sync: true, handleAs: 
"json"}).then(
                            function(data)
                            {
-                               // TODO why query *??
-                               //grid.setQuery({id: "*"});
+                               success = true;
                                grid.selection.deselectAll();
-                               updater.update();
+                               if (updater)
+                               {
+                                 updater.update();
+                               }
                            },
                            function(error) {success = false; failureReason = 
error;});
                        if(!success )
@@ -134,6 +135,7 @@ define(["dojo/_base/xhr",
                        }
                    }
                }
+               return success;
            }
 
            util.isProviderManagingUsers = function(type)

Modified: 
qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/Preferences.js
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/Preferences.js?rev=1524771&r1=1524770&r2=1524771&view=diff
==============================================================================
--- 
qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/Preferences.js
 (original)
+++ 
qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/Preferences.js
 Thu Sep 19 15:36:14 2013
@@ -22,15 +22,18 @@ define([
         "dojo/_base/declare",
         "dojo/_base/xhr",
         "dojo/_base/event",
+        "dojo/_base/connect",
         "dojo/dom",
         "dojo/dom-construct",
         "dojo/parser",
-        "dojo/query",
         "dojo/json",
+        "dojo/store/Memory",
+        "dojo/data/ObjectStore",
         "dojox/html/entities",
         "dijit/registry",
         "qpid/common/TimeZoneSelector",
         "dojo/text!../../showPreferences.html",
+        "qpid/common/util",
         "dijit/Dialog",
         "dijit/form/NumberSpinner",
         "dijit/form/CheckBox",
@@ -40,10 +43,13 @@ define([
         "dijit/form/DropDownButton",
         "dijit/form/Button",
         "dijit/form/Form",
+        "dijit/layout/TabContainer",
+        "dijit/layout/ContentPane",
+        "dojox/grid/EnhancedGrid",
         "dojox/validate/us",
         "dojox/validate/web",
         "dojo/domReady!"],
-function (declare, xhr, event, dom, domConstruct, parser, query, json, 
entities, registry, TimeZoneSelector, markup) {
+function (declare, xhr, event, connect, dom, domConstruct, parser, json, 
Memory, ObjectStore, entities, registry, TimeZoneSelector, markup, util) {
 
   var preferenceNames = ["timeZone", "updatePeriod", "saveTabs"];
 
@@ -58,25 +64,39 @@ function (declare, xhr, event, dom, domC
       var that = this;
 
       this.domNode = domConstruct.create("div", {innerHTML: markup});
-      parser.parse(this.domNode);
+      this.preferencesDialog = parser.parse(this.domNode)[0];
 
       for(var i=0; i<preferenceNames.length; i++)
       {
         var name = preferenceNames[i];
-        this[name] = registry.byNode(query("." + name, this.domNode)[0]);
+        this[name] = registry.byId("preferences." + name);
       }
 
-      this.saveButton = registry.byNode(query(".saveButton", this.domNode)[0]);
-      this.cancelButton = registry.byNode(query(".cancelButton", 
this.domNode)[0]);
-      this.theForm = registry.byId("preferencesForm");
-
-      this.preferencesDialog = new dijit.Dialog({
-        title:"Preferences",
-        style: "width: 600px",
-        content: this.domNode
-      });
-
+      this.saveButton = registry.byId("preferences.saveButton");
+      this.cancelButton = registry.byId("preferences.cancelButton");
+      this.theForm = registry.byId("preferences.preferencesForm");
+      this.users = registry.byId("preferences.users");
+      this.users.set("structure", [ { name: "User", field: "name", width: 
"50%"},
+                                 { name: "Authentication Provider", field: 
"authenticationProvider", width: "50%"}]);
       this.cancelButton.on("click", 
function(){that.preferencesDialog.hide();});
+      this.deletePreferencesButton = 
registry.byId("preferences.deletePreeferencesButton");
+      this.deletePreferencesButton.on("click", function(){
+         if (util.deleteGridSelections(
+            null,
+            that.users,
+            "rest/userpreferences",
+            "Are you sure you want to delete preferences for user",
+            "user"))
+          {
+             that._updateUsersWithPreferences();
+          }
+      });
+      var deletePreferencesButtonToggler = function(rowIndex){
+        var data = that.users.selection.getSelected();
+        that.deletePreferencesButton.set("disabled",!data.length );
+      };
+      connect.connect(this.users.selection, 'onSelected',  
deletePreferencesButtonToggler);
+      connect.connect(this.users.selection, 'onDeselected',  
deletePreferencesButtonToggler);
       this.theForm.on("submit", function(e){
         event.stop(e);
         if(that.theForm.validate()){
@@ -120,18 +140,8 @@ function (declare, xhr, event, dom, domC
         sync: true,
         handleAs: "json",
         load: function(data) {
-          for(var preference in data)
-          {
-            if (that.hasOwnProperty(preference))
-            {
-              var value = data[preference];
-              if (typeof data[preference] == "string")
-              {
-                value = entities.encode(String(value))
-              }
-              that[preference].set("value", value);
-            }
-          }
+          that._updatePreferencesWidgets(data);
+          that._updateUsersWithPreferences();
           that.preferencesDialog.show();
        },
        error: function(error){
@@ -147,6 +157,48 @@ function (declare, xhr, event, dom, domC
         this.preferencesDialog.destroyRecursevly();
         this.preferencesDialog = null;
       }
+    },
+
+    _updatePreferencesWidgets: function(data)
+    {
+      for(var i=0; i<preferenceNames.length; i++)
+      {
+        var preference = preferenceNames[i];
+        if (this.hasOwnProperty(preference))
+        {
+          var value = data ? data[preference] : null;
+          if (typeof value == "string")
+          {
+            value = entities.encode(String(value))
+          }
+          this[preference].set("value", value);
+        }
+      }
+    },
+
+    _updateUsersWithPreferences: function()
+    {
+      var that = this;
+      xhr.get({
+        url: "rest/userpreferences",
+        sync: false,
+        handleAs: "json"
+      }).then(
+         function(users) {
+             for(var i=0; i<users.length; i++)
+             {
+               users[i].id = users[i].authenticationProvider + "/" + 
users[i].name;
+             }
+             var usersStore = new Memory({data: users, idProperty: "id"});
+             var usersDataStore = new ObjectStore({objectStore: usersStore});
+             if (that.users.store)
+             {
+               that.users.store.close();
+             }
+             that.users.set("store", usersDataStore);
+             that.users._refresh();
+      });
     }
+
   });
 });
\ No newline at end of file

Modified: 
qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/resources/showPreferences.html
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/resources/showPreferences.html?rev=1524771&r1=1524770&r2=1524771&view=diff
==============================================================================
--- 
qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/resources/showPreferences.html
 (original)
+++ 
qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/resources/showPreferences.html
 Thu Sep 19 15:36:14 2013
@@ -18,18 +18,20 @@
  - under the License.
  -
  -->
-<div>
-    <form method="post" data-dojo-type="dijit/form/Form" id="preferencesForm">
-        <table cellpadding="0" cellspacing="2">
+<div data-dojo-type="dijit/Dialog" data-dojo-props="title:'Preferences'" 
id="preferences.preferencesDialog">
+  <div data-dojo-type="dijit/layout/TabContainer" style="width: 600px; height: 
400px">
+    <div data-dojo-type="dijit/layout/ContentPane" title="Own Preferences" 
data-dojo-props="selected:true" id="preferences.preferencesTab">
+      <form method="post" data-dojo-type="dijit/form/Form" 
id="preferences.preferencesForm">
+        <table cellpadding="0" cellspacing="2" style="overflow: auto; height: 
300px;">
             <tr>
                 <td><strong>Time zone: </strong></td>
                 <td>
-                    <span class="timeZone" 
data-dojo-type="qpid/common/TimeZoneSelector" data-dojo-props="name: 
'timeZone'"></span>
+                    <span id="preferences.timeZone" 
data-dojo-type="qpid/common/TimeZoneSelector" data-dojo-props="name: 
'timeZone'"></span>
                 </td>
             </tr>
             <tr>
                 <td><strong>Update period:</strong></td>
-                <td><input class="updatePeriod" name="updatePeriod" 
data-dojo-type="dijit/form/NumberSpinner" data-dojo-props="
+                <td><input id="preferences.updatePeriod" name="updatePeriod" 
data-dojo-type="dijit/form/NumberSpinner" data-dojo-props="
                                   invalidMessage: 'Invalid value',
                                   required: false,
                                   smallDelta: 1,
@@ -40,12 +42,42 @@
             </tr>
             <tr>
                 <td><strong>Save tabs:</strong></td>
-                <td><input class="saveTabs" type="checkbox" 
data-dojo-type="dijit/form/CheckBox" name="saveTabs"/></td>
+                <td><input id="preferences.saveTabs" type="checkbox" 
data-dojo-type="dijit/form/CheckBox" name="saveTabs"/></td>
             </tr>
         </table>
         <div class="dijitDialogPaneActionBar">
-          <input type="submit" value="Save Preferences" 
data-dojo-type="dijit/form/Button" data-dojo-props="label: 'Save Preferences'" 
class="saveButton"/>
-          <button value="Cancel" data-dojo-type="dijit/form/Button" 
data-dojo-props="label: 'Cancel'" class="cancelButton"></button>
+          <input type="submit" value="Save Preferences" 
data-dojo-type="dijit/form/Button" data-dojo-props="label: 'Save Preferences'" 
id="preferences.saveButton"/>
+          <button value="Cancel" data-dojo-type="dijit/form/Button" 
data-dojo-props="label: 'Cancel'" id="preferences.cancelButton"></button>
         </div>
-    </form>
+      </form>
+    </div>
+    <div data-dojo-type="dijit/layout/ContentPane" title="Users with 
Preferences" id="preferences.usersTab">
+      <table id="preferences.users" data-dojo-type="dojox/grid/EnhancedGrid" 
data-dojo-props="
+            label:'Trust Stores:',
+            plugins:{
+                      indirectSelection: true,
+                      pagination: {
+                        pageSizes: [10, 25, 50, 100],
+                        description: true,
+                        sizeSwitch: true,
+                        pageStepper: true,
+                        gotoButton: true,
+                        maxPageStep: 4,
+                        position: 'bottom'
+                      }
+                    },
+            rowSelector:'0px'
+            " style="height: 300px;">
+        <thead>
+          <tr>
+            <th field="name" style="width:50%">User</th>
+            <th field="authenticationProvider" 
style="width:50%">Authentication Provider</th>
+          </tr>
+        </thead>
+      </table>
+      <div class="dijitDialogPaneActionBar">
+        <button id="preferences.deletePreeferencesButton" 
data-dojo-type="dijit/form/Button" data-dojo-props="label:'Delete Preferences', 
title:'Delete preferences for selected users'">Delete Preferences</button>
+      </div>
+    </div>
+  </div>
 </div>



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to