qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From oru...@apache.org
Subject svn commit: r1677590 [3/6] - in /qpid/java/trunk: bdbstore/src/main/java/resources/js/qpid/management/virtualhost/bdb_ha/ bdbstore/src/main/java/resources/js/qpid/management/virtualhostnode/bdb_ha/ broker-plugins/jdbc-store/src/main/java/resources/js/q...
Date Mon, 04 May 2015 12:17:25 GMT
Modified: qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/GroupProvider.js
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/GroupProvider.js?rev=1677590&r1=1677589&r2=1677590&view=diff
==============================================================================
--- qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/GroupProvider.js (original)
+++ qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/GroupProvider.js Mon May  4 12:17:23 2015
@@ -18,8 +18,7 @@
  * under the License.
  *
  */
-define(["dojo/_base/xhr",
-        "dojo/parser",
+define(["dojo/parser",
         "dojo/query",
         "dojo/_base/connect",
         "dojo/_base/array",
@@ -27,7 +26,6 @@ define(["dojo/_base/xhr",
         "qpid/common/properties",
         "qpid/common/updater",
         "qpid/common/util",
-        "qpid/common/metadata",
         "qpid/common/UpdatableStore",
         "dojox/grid/EnhancedGrid",
         "dijit/registry",
@@ -37,13 +35,14 @@ define(["dojo/_base/xhr",
         "dojox/grid/enhanced/plugins/Pagination",
         "dojox/grid/enhanced/plugins/IndirectSelection",
         "dojo/domReady!"],
-       function (xhr, parser, query, connect, array, event, properties, updater, util, metadata, UpdatableStore,
+       function (parser, query, connect, array, event, properties, updater, util, UpdatableStore,
                  EnhancedGrid, registry, entities, template, addGroupProvider)
        {
 
            function GroupProvider(name, parent, controller) {
                this.name = name;
                this.controller = controller;
+               this.management = controller.management;
                this.modelObj = { type: "groupprovider", name: name, parent: parent};
            }
 
@@ -64,10 +63,13 @@ define(["dojo/_base/xhr",
                var that = this;
                var contentPane = this.contentPane;
                this.groupProviderUpdater = new GroupProviderUpdater(contentPane.containerNode, this.modelObj, this.controller);
+               this.groupProviderUpdater.update(function(){that._onOpenAfterUpdate();});
+           };
 
-               // load data
-               this.groupProviderUpdater.update();
-
+           GroupProvider.prototype._onOpenAfterUpdate = function()
+           {
+               var that = this;
+               var contentPane = this.contentPane;
                this.deleteButton = registry.byNode(query(".deleteGroupProviderButton", contentPane.containerNode)[0]);
                this.deleteButton.on("click", function(evt){ event.stop(evt); that.deleteGroupProvider(); });
 
@@ -84,7 +86,7 @@ define(["dojo/_base/xhr",
                             that.groupProviderUpdater.details.update(that.groupProviderUpdater.groupProviderData);
                         });
 
-               var managedInterfaces = metadata.getMetaData("GroupProvider", type).managedInterfaces;
+               var managedInterfaces = this.management.metadata.getMetaData("GroupProvider", type).managedInterfaces;
                if (managedInterfaces)
                {
 
@@ -117,46 +119,38 @@ define(["dojo/_base/xhr",
                warnMessage = "NOTE: provider deletion will also remove the group file on disk.\n\n";
              }
              if(confirm(warnMessage + "Are you sure you want to delete group provider '" + this.name + "'?")) {
-                 var query = "api/latest/groupprovider/" +encodeURIComponent(this.name);
-                 this.success = true
                  var that = this;
-                 xhr.del({url: query, sync: true, handleAs: "json"}).then(
+                 this.controller.management.remove(this.modelObj).then(
                      function(data) {
                          that.close();
                          that.contentPane.onClose()
                          that.controller.tabContainer.removeChild(that.contentPane);
                          that.contentPane.destroyRecursive();
                      },
-                     function(error) {that.success = false; that.failureReason = error;});
-                 if(!this.success ) {
-                     util.xhrErrorHandler(this.failureReason);
-                 }
+                     util.xhrErrorHandler);
              }
            };
 
            GroupProvider.prototype.editGroupProvider = function()
            {
-                xhr.get(
-                        {
-                          url: this.groupProviderUpdater.query,
-                          sync: true,
-                          content: { actuals: true },
-                          handleAs: "json",
-                          load: function(actualData)
+                var management = this.controller.management;
+                management.load(this.modelObj,{ actuals: true }).then(
+                          function(actualData)
                           {
-                            addGroupProvider.show(actualData[0]);
-                          }
-                        }
-                );
+                            addGroupProvider.show(management, that.modelObj, actualData[0]);
+                          },
+                          util.xhrErrorHandler
+                        );
            }
 
            function GroupProviderUpdater(node, groupProviderObj, controller)
            {
                this.controller = controller;
+               this.management = controller.management;
+               this.modelObj = groupProviderObj;
                this.name = query(".name", node)[0];
                this.type = query(".type", node)[0];
                this.state = query(".state", node)[0];
-               this.query = "api/latest/groupprovider/"+encodeURIComponent(groupProviderObj.name);
                this.managedInterfaces = {};
                this.details = null;
            }
@@ -168,10 +162,19 @@ define(["dojo/_base/xhr",
                this.state.innerHTML = entities.encode(String(this.groupProviderData[ "state" ]));
            };
 
-           GroupProviderUpdater.prototype.update = function()
+           GroupProviderUpdater.prototype.update = function(callback)
            {
                var that = this;
-               xhr.get({url: this.query, sync: true, handleAs: "json"}).then(function(data) {that._update(data[0]);});
+               var management = this.controller.management;
+               management.load(this.modelObj).then(
+                               function(data)
+                               {
+                                that._update(data[0]);
+                                if (callback)
+                                {
+                                    callback();
+                                }
+                               });
            };
 
            GroupProviderUpdater.prototype._update = function(data)

Modified: qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/KeyStore.js
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/KeyStore.js?rev=1677590&r1=1677589&r2=1677590&view=diff
==============================================================================
--- qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/KeyStore.js (original)
+++ qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/KeyStore.js Mon May  4 12:17:23 2015
@@ -19,7 +19,6 @@
  *
  */
 define(["dojo/dom",
-        "dojo/_base/xhr",
         "dojo/parser",
         "dojo/query",
         "dojo/_base/connect",
@@ -30,14 +29,15 @@ define(["dojo/dom",
         "qpid/common/util",
         "qpid/common/formatter",
         "qpid/management/addStore",
+        "dojo/text!showStore.html",
         "dojo/domReady!"],
-       function (dom, xhr, parser, query, connect, registry, entities, properties, updater, util, formatter, addStore) {
+       function (dom, parser, query, connect, registry, entities, properties, updater, util, formatter, addStore, template) {
 
            function KeyStore(name, parent, controller) {
                this.keyStoreName = name;
                this.controller = controller;
+               this.management = controller.management;
                this.modelObj = { type: "keystore", name: name, parent: parent};
-               this.url = "api/latest/keystore/" + encodeURIComponent(name);
            }
 
            KeyStore.prototype.getTitle = function() {
@@ -47,16 +47,12 @@ define(["dojo/dom",
            KeyStore.prototype.open = function(contentPane) {
                var that = this;
                this.contentPane = contentPane;
-               xhr.get({url: "showStore.html",
-                        sync: true,
-                        load:  function(data) {
-                            contentPane.containerNode.innerHTML = data;
-                            parser.parse(contentPane.containerNode).then(function(instances)
-                            {
-
-                            that.keyStoreUpdater = new KeyStoreUpdater(contentPane.containerNode, that.modelObj, that.controller, that.url);
-                            that.keyStoreUpdater.update();
-                            updater.add( that.keyStoreUpdater );
+                contentPane.containerNode.innerHTML = template;
+                parser.parse(contentPane.containerNode).then(function(instances)
+                {
+                            that.keyStoreUpdater = new KeyStoreUpdater(contentPane.containerNode, that.modelObj, that.controller);
+                            that.keyStoreUpdater.update(function(){updater.add( that.keyStoreUpdater );});
+
 
                             var deleteKeyStoreButton = query(".deleteStoreButton", contentPane.containerNode)[0];
                             var node = registry.byNode(deleteKeyStoreButton);
@@ -69,26 +65,27 @@ define(["dojo/dom",
                             var node = registry.byNode(editKeyStoreButton);
                             connect.connect(node, "onClick",
                                 function(evt){
-                                  xhr.get({url: that.url, sync: properties.useSyncGet, handleAs: "json", content: { actuals: true }})
+                                  management.load(that.modelObj, { actuals: true })
                                     .then(function(data)
                                     {
-                                      addStore.setupTypeStore("KeyStore");
-                                      addStore.show(data[0], that.url);
-                                    });
+                                      addStore.setupTypeStore(that.management, "KeyStore", that.modelObj);
+                                      addStore.show(data[0]);
+                                    }, util.xhrErrorHandler);
                                 });
-                            });
-                        }});
+                });
+
            };
 
            KeyStore.prototype.close = function() {
                updater.remove( this.keyStoreUpdater );
            };
 
-           function KeyStoreUpdater(containerNode, keyStoreObj, controller, url)
+           function KeyStoreUpdater(containerNode, keyStoreObj, controller)
            {
                var that = this;
                this.keyStoreDetailsContainer = query(".typeFieldsContainer", containerNode)[0];
-
+               this.management = controller.management;
+               this.modelObj = keyStoreObj;
                function findNode(name) {
                    return query("." + name, containerNode)[0];
                }
@@ -104,15 +101,6 @@ define(["dojo/dom",
                            "type",
                            "state"
                            ]);
-
-               this.query = url;
-
-               xhr.get({url: this.query, sync: properties.useSyncGet, handleAs: "json"}).then(function(data)
-                               {
-                                  that.keyStoreData = data[0];
-                                  that.updateHeader();
-                               });
-
            }
 
            KeyStoreUpdater.prototype.updateHeader = function()
@@ -122,16 +110,21 @@ define(["dojo/dom",
               this.state.innerHTML = entities.encode(String(this.keyStoreData[ "state" ]));
            };
 
-           KeyStoreUpdater.prototype.update = function()
+           KeyStoreUpdater.prototype.update = function(callback)
            {
 
               var that = this;
 
-              xhr.get({url: this.query, sync: properties.useSyncGet, handleAs: "json"}).then(function(data)
+              this.management.load(that.modelObj).then(function(data)
                    {
                       that.keyStoreData = data[0];
                       that.updateHeader();
 
+                      if (callback)
+                      {
+                        callback();
+                      }
+
                       if (that.details)
                       {
                         that.details.update(that.keyStoreData);
@@ -151,20 +144,15 @@ define(["dojo/dom",
 
            KeyStore.prototype.deleteKeyStore = function() {
                if(confirm("Are you sure you want to delete key store '" +this.keyStoreName+"'?")) {
-                   var query = this.url;
-                   this.success = true
                    var that = this;
-                   xhr.del({url: query, sync: true, handleAs: "json"}).then(
+                   this.management.remove(this.modelObj).then(
                        function(data) {
                            that.contentPane.onClose()
                            that.controller.tabContainer.removeChild(that.contentPane);
                            that.contentPane.destroyRecursive();
                            that.close();
                        },
-                       function(error) {that.success = false; that.failureReason = error;});
-                   if(!this.success ) {
-                       util.xhrErrorHandler(this.failureReason);
-                   }
+                       util.xhrErrorHandler);
                }
            }
 

Added: qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/Management.js
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/Management.js?rev=1677590&view=auto
==============================================================================
--- qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/Management.js (added)
+++ qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/Management.js Mon May  4 12:17:23 2015
@@ -0,0 +1,418 @@
+/*
+ *
+ * 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.
+ *
+ */
+define(["dojo/_base/lang",
+        "dojo/_base/array",
+        "dojo/request/xhr",
+        "dojo/io-query",
+        "dojo/json",
+        "qpid/common/metadata",
+        "qpid/common/timezone",
+        "qpid/management/UserPreferences"],
+  function (lang, array, xhr, ioQuery, json, Metadata, Timezone, UserPreferences)
+  {
+
+    function shallowCopy(source, target, excludes)
+    {
+        if (source)
+        {
+            for(var fieldName in source)
+            {
+                if(source.hasOwnProperty(fieldName))
+                {
+                    if (excludes && excludes.indexOf(fieldName) != -1)
+                    {
+                        continue;
+                    }
+
+                    target[fieldName] = source[fieldName];
+                }
+            }
+        }
+        return target;
+    }
+
+    function merge(data1, data2)
+    {
+        var result = {};
+        shallowCopy(data1, result);
+        shallowCopy(data2, result);
+        return result;
+    }
+
+    // summary:
+    // This is a proxy for sending management requests to broker at given host and port specified in brokerURL argument.
+    // Optional errorHandler method can be set and invoked on error responses when methods are invoked as non promise.
+
+    function Management(brokerURL, errorHandler)
+    {
+        this.brokerURL = brokerURL;
+        this.errorHandler = errorHandler || function(error){console.error(error);};
+    }
+
+    // summary:
+    // Submits HTTP request to broker using dojo.request.xhr
+    // request: Object?
+    //        request object can have the same fields as dojo.request.xhr options and  additional 'url' field:
+    //          data: String|Object|FormData?
+    //		        Data to transfer. This is ignored for GET and DELETE requests.
+    //          headers: Object?
+    //              Headers to use for the request.
+    //          user: String?
+    //		        Username to use during the request.
+    //          password: String?
+    //		        Password to use during the request.
+    //          withCredentials: Boolean?
+    //		        For cross-site requests, whether to send credentials or not.
+    //          query: Object?
+    //              the object send defining request query parameters
+    //          handleAs: String
+    //		        Indicates how the response will be handled.
+    //          url: String?
+    //              relative URL to broker REST API
+    // successAction: function
+    //		Optional callback function to execute on successful response.
+    //      It can be specified if function does not need to return promise
+    // failureAction: function
+    //		Optional callback function to execute on erroneous response.
+    //      It can be specified if function does not need to return promise
+    //
+    // returns: promise
+    //      Promise returned by dojo.request.xhr.
+    Management.prototype.submit = function(request, successAction, failureAction)
+    {
+        var requestOptions = {
+            sync: false,
+            handleAs: "json",
+            withCredentials: true,
+            headers: { "Content-Type": "application/json"}
+        };
+
+        if (request)
+        {
+            shallowCopy(request, requestOptions, ["url"]);
+            if (requestOptions.data && requestOptions.headers && requestOptions.headers["Content-Type"]
+                && requestOptions.headers["Content-Type"] == "application/json"
+                && typeof requestOptions.data != "string")
+            {
+                requestOptions.data = json.stringify(request.data );
+            }
+        }
+
+        if (!requestOptions.method)
+        {
+            requestOptions.method = "GET";
+        }
+
+        var url = this.getFullUrl(request.url);
+        var promise = xhr(url, requestOptions);
+        if (successAction || failureAction)
+        {
+            var that = this;
+            promise.then(
+                function(data)
+                {
+                    if (successAction)
+                    {
+                        successAction(data);
+                    }
+                },
+                function(error)
+                {
+                    if (failureAction)
+                    {
+                        failureAction(error);
+                    }
+                    else
+                    {
+                        that.errorHandler(error);
+                    }
+                }
+            );
+        }
+        return promise;
+    };
+
+    Management.prototype.get = function(request, successAction, failureAction)
+    {
+        var requestOptions = merge(request, {method: "GET"});
+        return this.submit(requestOptions, successAction, failureAction);
+    };
+
+    Management.prototype.post = function(request, data, successAction, failureAction)
+    {
+        var requestOptions = merge(request, {method: "POST", data: data});
+        return this.submit(requestOptions, successAction, failureAction);
+    };
+
+    Management.prototype.del = function(request, successAction, failureAction)
+    {
+        var requestOptions = merge(request, {method: "DELETE"});
+        return this.submit(requestOptions, successAction, failureAction);
+    };
+
+    // summary:
+    //  Loads object data specified as modelObj argument
+    //   modelObj: Object?
+    //             is a JSON object specifying the hierarchy
+    //            It has the following fields:
+    //               name: String?
+    //                     name of the object
+    //               type: String?
+    //                     category of the object
+    //               parent: Object?
+    //                     parent of the object in the same format, having fields name, type, parent
+    //
+    //   parameters: Object?
+    //               is optional JSON to pass additional request parameters
+    //   successAction: function
+    //		Optional callback function to execute on successful response.
+    //      It can be specified if function does not need to return promise
+    //   failureAction: function
+    //		Optional callback function to execute on erroneous response.
+    //      It can be specified if function does not need to return promise
+    //
+    //   returns: promise
+    //      Promise returned by dojo.request.xhr.
+    Management.prototype.load = function(modelObj, parameters, successAction, failureAction)
+    {
+        var url = this.objectToURL(modelObj);
+        var request = {url: url};
+        if (parameters)
+        {
+            request.query = parameters;
+        }
+        return this.get(request, successAction, failureAction);
+    };
+
+    // summary:
+    //  Creates object as specified in data parameter with given category and with given parent parentModelObject
+    //   category: String?
+    //             Object category
+    //
+    //   parentModelObject: Object?
+    //              Parent object hierarchy
+    //   data; Object?
+    //              Object structure
+    //   successAction: function
+    //		Optional callback function to execute on successful response.
+    //      It can be specified if function does not need to return promise
+    //   failureAction: function
+    //		Optional callback function to execute on erroneous response.
+    //      It can be specified if function does not need to return promise
+    //
+    //   returns: promise
+    //      Promise returned by dojo.request.xhr.
+    Management.prototype.create = function(category, parentModelObject, data, successAction, failureAction)
+    {
+        var newObjectModel ={type: category.toLowerCase(), parent: parentModelObject};
+        var url = this.objectToURL(newObjectModel);
+        var request = {url: url};
+        this.post(request, data, successAction, failureAction);
+    };
+
+    // summary:
+    //  Updates object (which can be located using modelObj parameter) attributes to the values set in data parameter
+    //
+    //   modelObj: Object?
+    //              Object specifying hierarchy
+    //   data; Object?
+    //              New attributes
+    //   successAction: function
+    //		Optional callback function to execute on successful response.
+    //      It can be specified if function does not need to return promise
+    //   failureAction: function
+    //		Optional callback function to execute on erroneous response.
+    //      It can be specified if function does not need to return promise
+    //
+    //   returns: promise
+    //      Promise returned by dojo.request.xhr.
+    Management.prototype.update = function(modelObj, data, successAction, failureAction)
+    {
+        var url = this.objectToURL(modelObj);
+        var request = {url: url};
+        return this.post(request, data, successAction, failureAction);
+    };
+
+    // summary:
+    //  Removes object specified as modelObj argument
+    //   modelObj: Object?
+    //             hierarchy object
+    //   parameters: Object?
+    //               is optional JSON object to pass additional request parameters
+    //   successAction: function
+    //		Optional callback function to execute on successful response.
+    //      It can be specified if function does not need to return promise
+    //   failureAction: function
+    //		Optional callback function to execute on erroneous response.
+    //      It can be specified if function does not need to return promise
+    //
+    //   returns: promise
+    //      Promise returned by dojo.request.xhr.
+    Management.prototype.remove = function(modelObj, parameters, successAction, failureAction)
+    {
+        var url = this.objectToURL(modelObj);
+        var request = {url: url};
+        if (parameters)
+        {
+            request.query = parameters;
+        }
+        return this.del(request, successAction, failureAction);
+    };
+
+    // summary:
+    //  Downloads current JSON for object specified as modelObj argument
+    //   modelObj: Object?
+    //             hierarchy object
+    //   parameters: Object?
+    //               is optional JSON object to pass additional request parameters
+    Management.prototype.download = function(modelObj, parameters)
+    {
+        var url = this.buildObjectURL(modelObj, parameters);
+        setTimeout(function() {window.location  = url;}, 100);
+    }
+
+    Management.prototype.downloadIntoFrame = function(modelObj, parameters)
+    {
+        var url = this.buildObjectURL(modelObj, parameters);
+        var iframe = document.createElement('iframe');
+        iframe.id = "downloader_" + modelObj.name;
+        document.body.appendChild(iframe);
+        iframe.src = url;
+        // It seems there is no way to remove this iframe in a manner that is cross browser compatible.
+    }
+
+    Management.prototype.objectToURL = function(modelObj)
+    {
+        var url = null;
+        if (modelObj.type == "broker")
+        {
+            url = "broker"
+        }
+        else
+        {
+            url = encodeURIComponent(modelObj.type);
+            var parentPath = this.objectToPath(modelObj);
+            if (parentPath)
+            {
+                 url = url + "/" + parentPath;
+            }
+
+            if (modelObj.name)
+            {
+               if (url.substring(url.length - 1) != "/")
+               {
+                    url = url + "/";
+               }
+               url = url + encodeURIComponent(modelObj.name)
+            }
+        }
+        return "api/latest/" + url;
+    };
+
+    Management.prototype.objectToPath = function(modelObj)
+    {
+        var path = "";
+        var parent = modelObj.parent;
+        while (parent && parent.type != "broker")
+        {
+            if (path)
+            {
+                path = encodeURIComponent(parent.name) + "/" + path;
+            }
+            else
+            {
+                path = encodeURIComponent(parent.name);
+            }
+            parent = parent.parent;
+        }
+        return path;
+    };
+
+    Management.prototype.buildObjectURL = function(modelObj, parameters)
+    {
+        var url = this.objectToURL(modelObj);
+        if (parameters)
+        {
+            url = url + "?" + ioQuery.objectToQuery(parameters);
+        }
+        return this.getFullUrl(url);
+    }
+
+    Management.prototype.getFullUrl = function(url)
+    {
+        var baseUrl = this.brokerURL || "";
+        if (baseUrl != "")
+        {
+            baseUrl = baseUrl + "/";
+        }
+        return baseUrl + url;
+    }
+
+    Management.prototype.init = function(callback)
+    {
+        var that = this;
+        this.loadMetadata(function()
+                          {
+                            that.loadTimezones(function()
+                                                {
+                                                    that.loadUserPreferences(callback)
+                                                });
+                          });
+    };
+
+    Management.prototype.loadMetadata = function(callback)
+    {
+        var that = this;
+        this.get({url: "service/metadata"},
+                 function(data)
+                 {
+                    that.metadata = new Metadata(data);
+                    if (callback)
+                    {
+                        callback();
+                    }
+                 },
+                 this.errorHandler);
+    };
+
+    Management.prototype.loadTimezones = function(callback)
+    {
+        var that = this;
+        that.get({url: "service/timezones"},
+                 function(timezones)
+                 {
+                    that.timezone = new Timezone(timezones);
+                    if (callback)
+                    {
+                        callback();
+                    }
+                 },
+                 this.errorHandler);
+    };
+
+    Management.prototype.loadUserPreferences = function(callback)
+    {
+        this.userPreferences = new UserPreferences(this);
+        this.userPreferences.load(callback);
+    };
+
+    return Management;
+  });

Modified: qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/Plugin.js
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/Plugin.js?rev=1677590&r1=1677589&r2=1677590&view=diff
==============================================================================
--- qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/Plugin.js (original)
+++ qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/Plugin.js Mon May  4 12:17:23 2015
@@ -18,8 +18,7 @@
  * under the License.
  *
  */
-define(["dojo/_base/xhr",
-        "dojo/parser",
+define(["dojo/parser",
         "dojo/query",
         "dojo/_base/connect",
         "qpid/common/properties",
@@ -28,12 +27,14 @@ define(["dojo/_base/xhr",
         "dijit/registry",
         "dojo/_base/event",
         "dojox/html/entities",
+        "dojo/text!showPlugin.html",
         "dojo/domReady!"],
-       function (xhr, parser, query, connect, properties, updater, util, registry, event, entities) {
+       function (parser, query, connect, properties, updater, util, registry, event, entities, template) {
 
            function Plugin(name, parent, controller) {
                this.name = name;
                this.controller = controller;
+               this.management = controller.management;
                this.modelObj = { type: "plugin", name: name, parent: parent };
            }
 
@@ -44,15 +45,11 @@ define(["dojo/_base/xhr",
            Plugin.prototype.open = function(contentPane) {
                var that = this;
                this.contentPane = contentPane;
-               xhr.get({url: "showPlugin.html",
-                        sync: true,
-                        load:  function(data) {
-                            contentPane.containerNode.innerHTML = data;
-                            parser.parse(contentPane.containerNode).then(function(instances)
-                            {
-                                that.pluginUpdater = new PluginUpdater(contentPane.containerNode, that.modelObj, that.controller);
-                            });
-                        }});
+                contentPane.containerNode.innerHTML = template;
+                parser.parse(contentPane.containerNode).then(function(instances)
+                {
+                    that.pluginUpdater = new PluginUpdater(contentPane.containerNode, that.modelObj, that.controller);
+                });
            };
 
            Plugin.prototype.close = function() {
@@ -62,13 +59,14 @@ define(["dojo/_base/xhr",
            function PluginUpdater(node, pluginObject, controller)
            {
                this.controller = controller;
+               this.modelObj = pluginObject;
+               this.management = controller.management;
                this.name = query(".name", node)[0];
                this.type = query(".type", node)[0];
-               this.query = "api/latest/plugin/"+encodeURIComponent(pluginObject.name);
 
                var that = this;
 
-               xhr.get({url: this.query, sync: properties.useSyncGet, handleAs: "json"})
+               this.management.load(that.modelObj)
                    .then(function(data)
                          {
                              that.pluginData = data[0];
@@ -80,7 +78,7 @@ define(["dojo/_base/xhr",
                                  that.details = new SpecificPlugin(query(".pluginDetails", node)[0], pluginObject, controller);
                              });
 
-                         });
+                         }, util.xhrErrorHandler);
 
            }
 

Modified: qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/Port.js
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/Port.js?rev=1677590&r1=1677589&r2=1677590&view=diff
==============================================================================
--- qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/Port.js (original)
+++ qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/Port.js Mon May  4 12:17:23 2015
@@ -19,7 +19,6 @@
  *
  */
 define(["dojo/dom",
-        "dojo/_base/xhr",
         "dojo/parser",
         "dojo/query",
         "dojo/_base/connect",
@@ -30,13 +29,14 @@ define(["dojo/dom",
         "qpid/common/util",
         "qpid/common/formatter",
         "qpid/management/addPort",
-        "qpid/common/metadata",
+        "dojo/text!showPort.html",
         "dojo/domReady!"],
-       function (dom, xhr, parser, query, connect, registry, entities, properties, updater, util, formatter, addPort, metadata) {
+       function (dom, parser, query, connect, registry, entities, properties, updater, util, formatter, addPort, template) {
 
            function Port(name, parent, controller) {
                this.name = name;
                this.controller = controller;
+               this.management = controller.management;
                this.modelObj = { type: "port", name: name, parent: parent};
            }
 
@@ -47,17 +47,11 @@ define(["dojo/dom",
            Port.prototype.open = function(contentPane) {
                var that = this;
                this.contentPane = contentPane;
-               xhr.get({url: "showPort.html",
-                        sync: true,
-                        load:  function(data) {
-                            contentPane.containerNode.innerHTML = data;
-                            parser.parse(contentPane.containerNode).then(function(instances)
-                            {
-                            that.portUpdater = new PortUpdater(contentPane.containerNode, that.modelObj, that.controller, "api/latest/port/" + encodeURIComponent(that.name));
 
-                            updater.add( that.portUpdater );
-
-                            that.portUpdater.update();
+                contentPane.containerNode.innerHTML = template;
+                parser.parse(contentPane.containerNode).then(function(instances)
+                {
+                            that.portUpdater = new PortUpdater(contentPane.containerNode, that.modelObj, that.controller);
 
                             var deletePortButton = query(".deletePortButton", contentPane.containerNode)[0];
                             var node = registry.byNode(deletePortButton);
@@ -72,8 +66,9 @@ define(["dojo/dom",
                                 function(evt){
                                   that.showEditDialog();
                                 });
-                            });
-                        }});
+
+                            that.portUpdater.update(function(){updater.add( that.portUpdater );});
+                });
            };
 
            Port.prototype.close = function() {
@@ -82,38 +77,36 @@ define(["dojo/dom",
 
 
            Port.prototype.deletePort = function() {
-               if(confirm("Are you sure you want to delete port '" +this.name+"'?")) {
-                   var query = "api/latest/port/" + encodeURIComponent(this.name);
-                   this.success = true
+               if(confirm("Are you sure you want to delete port '" + entities.encode(this.name) + "'?")) {
                    var that = this;
-                   xhr.del({url: query, sync: true, handleAs: "json"}).then(
+                   this.management.remove(this.modelObj).then(
                        function(data) {
                            that.contentPane.onClose()
                            that.controller.tabContainer.removeChild(that.contentPane);
                            that.contentPane.destroyRecursive();
                            that.close();
                        },
-                       function(error) {that.success = false; that.failureReason = error;});
-                   if(!this.success ) {
-                       util.xhrErrorHandler(this.failureReason);
-                   }
+                       util.xhrErrorHandler);
                }
            }
 
            Port.prototype.showEditDialog = function() {
                var that = this;
-               xhr.get({url: "api/latest/broker", sync: properties.useSyncGet, handleAs: "json"})
+               this.management.load(that.modelObj.parent)
                .then(function(data)
                      {
                          var brokerData= data[0];
-                         addPort.show(that.name, that.portUpdater.portData.type, brokerData.authenticationproviders, brokerData.keystores, brokerData.truststores);
-                     }
+                         addPort.show(that.management, that.modelObj, that.portUpdater.portData.type, brokerData.authenticationproviders, brokerData.keystores, brokerData.truststores);
+                     },
+                     util.xhrErrorHandler
                );
            }
 
-           function PortUpdater(containerNode, portObj, controller, url)
+           function PortUpdater(containerNode, portObj, controller)
            {
                var that = this;
+               this.management = controller.management;
+               this.modelObj = portObj;
 
                function findNode(name) {
                    return query("." + name, containerNode)[0];
@@ -148,16 +141,6 @@ define(["dojo/dom",
                            "trustStores",
                            "maxOpenConnections"
                            ]);
-
-               this.query = url;
-
-               xhr.get({url: this.query, sync: properties.useSyncGet, handleAs: "json"}).then(function(data)
-                               {
-                                  that.portData = data[0];
-                                  util.flattenStatistics( that.portData );
-                                  that.updateHeader();
-                               });
-
            }
 
            PortUpdater.prototype.updateHeader = function()
@@ -190,7 +173,7 @@ define(["dojo/dom",
               this.wantClientAuthValue.innerHTML = "<input type='checkbox' disabled='disabled' "+(this.portData[ "wantClientAuth" ] ? "checked='checked'": "")+" />" ;
               this.trustStoresValue.innerHTML = printArray( "trustStores", this.portData);
 
-              var typeMetaData = metadata.getMetaData("Port", this.portData["type"]);
+              var typeMetaData = this.management.metadata.getMetaData("Port", this.portData["type"]);
 
               this.authenticationProvider.style.display = "authenticationProvider" in typeMetaData.attributes ? "block" : "none";
               this.bindingAddress.style.display = "bindingAddress" in typeMetaData.attributes ? "block" : "none";
@@ -203,15 +186,19 @@ define(["dojo/dom",
 
            };
 
-           PortUpdater.prototype.update = function()
+           PortUpdater.prototype.update = function(callback)
            {
 
               var thisObj = this;
 
-              xhr.get({url: this.query, sync: properties.useSyncGet, handleAs: "json"}).then(function(data)
+              this.management.load(this.modelObj).then(function(data)
                    {
                       thisObj.portData = data[0];
                       util.flattenStatistics( thisObj.portData );
+                      if (callback)
+                      {
+                        callback();
+                      }
                       thisObj.updateHeader();
                    });
            };

Modified: qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/Preferences.js
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/Preferences.js?rev=1677590&r1=1677589&r2=1677590&view=diff
==============================================================================
--- qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/Preferences.js (original)
+++ qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/Preferences.js Mon May  4 12:17:23 2015
@@ -20,7 +20,6 @@
  */
 define([
         "dojo/_base/declare",
-        "dojo/_base/xhr",
         "dojo/_base/event",
         "dojo/_base/connect",
         "dojo/dom",
@@ -34,7 +33,6 @@ define([
         "qpid/common/TimeZoneSelector",
         "dojo/text!../../showPreferences.html",
         "qpid/common/util",
-        "qpid/management/UserPreferences",
         "dijit/Dialog",
         "dijit/form/NumberSpinner",
         "dijit/form/CheckBox",
@@ -51,7 +49,7 @@ define([
         "dojox/validate/us",
         "dojox/validate/web",
         "dojo/domReady!"],
-function (declare, xhr, event, connect, dom, domConstruct, parser, json, Memory, ObjectStore, entities, registry, TimeZoneSelector, markup, util, UserPreferences) {
+function (declare, event, connect, dom, domConstruct, parser, json, Memory, ObjectStore, entities, registry, TimeZoneSelector, markup, util) {
 
   var preferenceNames = ["timeZone", "updatePeriod"];
 
@@ -59,10 +57,10 @@ function (declare, xhr, event, connect,
 
     preferencesDialog: null,
 
-    constructor: function()
+    constructor: function(management)
     {
       var that = this;
-
+      this.management = management;
       this.userPreferences = {};
       this.domNode = domConstruct.create("div", {innerHTML: markup});
       parser.parse(this.domNode).then(function(instances)
@@ -81,6 +79,8 @@ function (declare, xhr, event, connect,
         this[name].on("change", function(val){that._toggleSetButtons();});
       }
 
+      this.timeZoneSelector = registry.byId("preferences.timeZone");
+      this.timeZoneSelector.set("timezones", this.management.timezone.getAllTimeZones());
       this.setButton = registry.byId("preferences.setButton");
       this.setAndCloseButton = registry.byId("preferences.setAndCloseButton");
       this.setButton.on("click", function(e){that._savePreferences(e, false);});
@@ -111,8 +111,8 @@ function (declare, xhr, event, connect,
 
     showDialog: function(){
       this._setValues();
-      this._loadUserPreferences();
-      this.preferencesDialog.show();
+      var that = this;
+      this._loadUserPreferences(function(){that.preferencesDialog.show();});
     },
 
     destroy: function()
@@ -140,7 +140,7 @@ function (declare, xhr, event, connect,
           }
         }
 
-        UserPreferences.setPreferences(
+        this.management.userPreferences.save(
             preferences,
             function(preferences)
             {
@@ -170,37 +170,38 @@ function (declare, xhr, event, connect,
                 }
               }
               that._toggleSetButtons();
-            },
-            UserPreferences.defaultErrorHandler
-        );
+            });
       }
     },
 
     _deletePreferences: function(hideDialog){
-      var data = this.usersGrid.selection.getSelected();
-      if (util.deleteGridSelections(
-         null,
-         this.usersGrid,
-         "service/userpreferences",
-         "Are you sure you want to delete preferences for user",
-         "user"))
+    var that = this;
+    var postDelete = function(data)
        {
-        this._loadUserPreferences();
+        that._loadUserPreferences();
         var authenticatedUser = dom.byId("authenticatedUser").innerHTML;
         for(i = 0; i<data.length; i++)
         {
           if (data[i].name == authenticatedUser)
           {
-            UserPreferences.resetPreferences();
-            this._setValues();
+            that.management.userPreferences.resetPreferences();
+            that._setValues();
             break;
           }
         }
         if (hideDialog)
         {
-          this.preferencesDialog.hide();
+          that.preferencesDialog.hide();
         }
-       }
+       };
+
+      util.deleteSelectedRows(this.usersGrid,
+                              "Are you sure you want to delete preferences for user",
+                              this.management,
+                              "service/userpreferences",
+                              null,
+                              "user",
+                              postDelete );
     },
 
     _setValues: function()
@@ -211,7 +212,7 @@ function (declare, xhr, event, connect,
         var preferenceWidget = this[name];
         if (preferenceWidget)
         {
-          var value = UserPreferences[name]
+          var value = this.management.userPreferences[name]
           if (typeof value == "string")
           {
             value = entities.encode(String(value))
@@ -224,36 +225,37 @@ function (declare, xhr, event, connect,
           preferenceWidget.set("value", value);
           if (preferenceWidget.hasOwnProperty("checked"))
           {
-            preferenceWidget.set("checked", UserPreferences[name] ? true : false);
+            preferenceWidget.set("checked", this.management.userPreferences[name] ? true : false);
           }
         }
       }
       this._toggleSetButtons();
     },
 
-    _loadUserPreferences : function()
+    _loadUserPreferences : function(callback)
     {
       var that = this;
-      xhr.get({
-        url: "service/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;
-             }
-             that.users = users;
-             var usersStore = new Memory({data: users, idProperty: "id"});
-             var usersDataStore = new ObjectStore({objectStore: usersStore});
-             if (that.usersGrid.store)
-             {
-               that.usersGrid.store.close();
-             }
-             that.usersGrid.set("store", usersDataStore);
-             that.usersGrid._refresh();
-      });
+      this.management.get({url: "service/userpreferences"},
+                          function(users)
+                          {
+                                 for(var i=0; i<users.length; i++)
+                                 {
+                                   users[i].id = users[i].authenticationProvider + "/" + users[i].name;
+                                 }
+                                 that.users = users;
+                                 var usersStore = new Memory({data: users, idProperty: "id"});
+                                 var usersDataStore = new ObjectStore({objectStore: usersStore});
+                                 if (that.usersGrid.store)
+                                 {
+                                   that.usersGrid.store.close();
+                                 }
+                                 that.usersGrid.set("store", usersDataStore);
+                                 if (callback)
+                                 {
+                                    callback();
+                                 }
+                                 that.usersGrid._refresh();
+                          });
     },
 
     _toggleSetButtons: function()
@@ -266,7 +268,7 @@ function (declare, xhr, event, connect,
         if (preferenceWidget)
         {
           var value = preferenceWidget.hasOwnProperty("checked") ? preferenceWidget.checked : preferenceWidget.get("value");
-          if (value != UserPreferences[name])
+          if (value != this.management.userPreferences[name])
           {
             changed = true;
             break;

Modified: qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/PreferencesProvider.js
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/PreferencesProvider.js?rev=1677590&r1=1677589&r2=1677590&view=diff
==============================================================================
--- qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/PreferencesProvider.js (original)
+++ qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/PreferencesProvider.js Mon May  4 12:17:23 2015
@@ -18,8 +18,7 @@
  * under the License.
  *
  */
-define(["dojo/_base/xhr",
-        "dojo/parser",
+define(["dojo/parser",
         "dojo/query",
         "dojo/dom-construct",
         "dojo/_base/array",
@@ -31,12 +30,14 @@ define(["dojo/_base/xhr",
         "dojo/dom-style",
         "dojox/html/entities",
         "qpid/management/addPreferencesProvider",
+        "dojo/text!showPreferencesProvider.html",
         "dojo/domReady!"],
-       function (xhr, parser, query, construct, array, properties, updater, util, event, registry, domStyle, entities, addPreferencesProvider) {
+       function (parser, query, construct, array, properties, updater, util, event, registry, domStyle, entities, addPreferencesProvider, template) {
 
            function PreferencesProvider(name, parent, controller) {
                this.name = name;
                this.controller = controller;
+               this.management = management;
                this.modelObj = { type: "preferencesprovider", name: name, parent: parent};
                this.authenticationProviderName = parent.name;
            }
@@ -47,12 +48,9 @@ define(["dojo/_base/xhr",
 
            PreferencesProvider.prototype.init = function(node, parentObject) {
              var that = this;
-             xhr.get({url: "showPreferencesProvider.html",
-               sync: true,
-               load:  function(data) {
-                   node.innerHTML = data;
-                   parser.parse(node).then(function(instances)
-                   {
+               node.innerHTML = template;
+               parser.parse(node).then(function(instances)
+               {
                    that.containerNode = node;
                    that.parentObject = parentObject;
                    that.preferencesProviderType=query(".preferencesProviderType", node)[0];
@@ -65,8 +63,7 @@ define(["dojo/_base/xhr",
                    editPreferencesProviderWidget.on("click", function(evt){ event.stop(evt); that.editPreferencesProvider();});
                    var deletePreferencesProviderWidget = registry.byNode(that.deletePreferencesProviderButton);
                    deletePreferencesProviderWidget.on("click", function(evt){ event.stop(evt); that.deletePreferencesProvider();});
-                   });
-               }});
+               });
            };
 
            PreferencesProvider.prototype.open = function(contentPane) {
@@ -88,10 +85,8 @@ define(["dojo/_base/xhr",
              if (this.preferencesProviderData){
                var preferencesProviderData = this.preferencesProviderData;
                if(confirm("Are you sure you want to delete preferences provider '" + preferencesProviderData.name + "'?")) {
-                 var query = "api/latest/preferencesprovider/" + encodeURIComponent(this.authenticationProviderName) + "/" + encodeURIComponent(preferencesProviderData.name);
-                 this.success = true
                  var that = this;
-                 xhr.del({url: query, sync: true, handleAs: "json"}).then(
+                 this.management.remove(this.modelObj).then(
                      function(data) {
                        that.update(null);
 
@@ -114,17 +109,14 @@ define(["dojo/_base/xhr",
                          }
                        }
                      },
-                     function(error) {that.success = false; that.failureReason = error;});
-                 if(!this.success ) {
-                     util.xhrErrorHandler(this.failureReason);
-                 }
+                     util.xhrErrorHandler);
                }
              }
            };
 
            PreferencesProvider.prototype.editPreferencesProvider = function() {
              if (this.preferencesProviderData){
-               addPreferencesProvider.show(this.authenticationProviderName, this.name);
+               addPreferencesProvider.show(this.management, this.modelObj);
              }
            };
 
@@ -163,9 +155,8 @@ define(["dojo/_base/xhr",
 
            PreferencesProvider.prototype.reload = function()
            {
-             var query = "api/latest/preferencesprovider/" + encodeURIComponent(this.authenticationProviderName) + "/" + encodeURIComponent(this.name);
              var that = this;
-             xhr.get({url: query, sync: properties.useSyncGet, handleAs: "json"})
+             that.management.load(that.modelObj)
                  .then(function(data) {
                      var preferencesProviderData = data[0];
                      util.flattenStatistics( preferencesProviderData );

Modified: qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/Queue.js
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/Queue.js?rev=1677590&r1=1677589&r2=1677590&view=diff
==============================================================================
--- qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/Queue.js (original)
+++ qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/Queue.js Mon May  4 12:17:23 2015
@@ -18,8 +18,7 @@
  * under the License.
  *
  */
-define(["dojo/_base/xhr",
-        "dojo/parser",
+define(["dojo/parser",
         "dojo/query",
         "dijit/registry",
         "dojo/_base/connect",
@@ -33,21 +32,24 @@ define(["dojo/_base/xhr",
         "qpid/management/addBinding",
         "qpid/management/moveCopyMessages",
         "qpid/management/showMessage",
-        "qpid/management/UserPreferences",
         "qpid/management/editQueue",
         "dojo/store/JsonRest",
         "dojox/grid/EnhancedGrid",
         "dojo/data/ObjectStore",
         "dojox/html/entities",
+        "dojo/text!showQueue.html",
+        "dojox/data/JsonRestStore",
         "dojox/grid/enhanced/plugins/Pagination",
         "dojox/grid/enhanced/plugins/IndirectSelection",
         "dojo/domReady!"],
-       function (xhr, parser, query, registry, connect, event, json, properties, updater, util, formatter,
-                 UpdatableStore, addBinding, moveMessages, showMessage, UserPreferences, editQueue, JsonRest, EnhancedGrid, ObjectStore, entities) {
+       function (parser, query, registry, connect, event, json, properties, updater, util, formatter,
+                 UpdatableStore, addBinding, moveMessages, showMessage, editQueue, JsonRest,
+                 EnhancedGrid, ObjectStore, entities, template, JsonRestStore) {
 
            function Queue(name, parent, controller) {
                this.name = name;
                this.controller = controller;
+               this.management = controller.management;
                this.modelObj = { type: "queue", name: name, parent: parent };
            }
 
@@ -75,23 +77,18 @@ define(["dojo/_base/xhr",
            Queue.prototype.open = function(contentPane) {
                var that = this;
                this.contentPane = contentPane;
-               xhr.get({url: "showQueue.html",
-                        sync: true,
-                        load:  function(data) {
-                            contentPane.containerNode.innerHTML = data;
-                            parser.parse(contentPane.containerNode).then(function(instances)
-                            {
 
-                            that.queueUpdater = new QueueUpdater(contentPane.containerNode, that, that.controller);
+                contentPane.containerNode.innerHTML = template;
+                parser.parse(contentPane.containerNode).then(function(instances)
+                {
 
-                            updater.add( that.queueUpdater );
+                            that.queueUpdater = new QueueUpdater(contentPane.containerNode, that.modelObj, that.controller);
 
-                            that.queueUpdater.update();
-
-                            var myStore = new JsonRest({target:"service/message/"+ encodeURIComponent(that.getVirtualHostName()) +
-                                                                               "/" + encodeURIComponent(that.getQueueName())});
+                            var myStore = new JsonRest({target: that.management.getFullUrl("service/message/"+ encodeURIComponent(that.getVirtualHostName()) +
+                                                                               "/" + encodeURIComponent(that.getQueueName()))});
                             var messageGridDiv = query(".messages",contentPane.containerNode)[0];
-                            that.dataStore = new ObjectStore({objectStore: myStore});
+                            that.dataStore =  new ObjectStore({objectStore: myStore});
+                            var userPreferences = this.management.userPreferences;
                             that.grid = new EnhancedGrid({
                                 store: that.dataStore,
                                 autoHeight: 10,
@@ -102,7 +99,7 @@ define(["dojo/_base/xhr",
 
                                     {name:"Arrival", field:"arrivalTime", width: "30%",
                                         formatter: function(val) {
-                                            return UserPreferences.formatDateTime(val, {addOffset: true, appendTimeZone: true});
+                                            return userPreferences.formatDateTime(val, {addOffset: true, appendTimeZone: true});
                                         } }
                                 ],
                                 plugins: {
@@ -124,7 +121,7 @@ define(["dojo/_base/xhr",
                                                  var idx = evt.rowIndex,
                                                      theItem = this.getItem(idx);
                                                  var id = that.dataStore.getValue(theItem,"id");
-                                                 showMessage.show({ messageNumber: id,
+                                                 showMessage.show(that.management, { messageNumber: id,
                                                                     queue: that.getQueueName(),
                                                                     virtualhost: that.getVirtualHostName(),
                                                                     virtualhostnode: that.getVirtualHostNodeName()});
@@ -163,9 +160,7 @@ define(["dojo/_base/xhr",
                             connect.connect(registry.byNode(addBindingButton), "onClick",
                                             function(evt){
                                                 event.stop(evt);
-                                                addBinding.show({ virtualhost: that.getVirtualHostName(),
-                                                                  queue: that.getQueueName(),
-                                                                  virtualhostnode: that.getVirtualHostNodeName()});
+                                                addBinding.show(that.management, that.modelObj);
                                             });
 
                             var deleteQueueButton = query(".deleteQueueButton", contentPane.containerNode)[0];
@@ -178,15 +173,11 @@ define(["dojo/_base/xhr",
                             connect.connect(registry.byNode(editQueueButton), "onClick",
                                     function(evt){
                                         event.stop(evt);
-                                        editQueue.show({nodeName:that.modelObj.parent.parent.name, hostName:that.modelObj.parent.name,queueName:that.name});
+                                        editQueue.show(that.management, that.modelObj);
                                     });
-                            UserPreferences.addListener(that);
-
-                            });
-                        }});
-
-
-
+                            userPreferences.addListener(that);
+                            that.queueUpdater.update(function(){ updater.add( that.queueUpdater );});
+                });
            };
 
            Queue.prototype.deleteMessages = function() {
@@ -194,29 +185,15 @@ define(["dojo/_base/xhr",
                if(data.length) {
                    var that = this;
                    if(confirm("Delete " + data.length + " messages?")) {
-                       var i, queryParam;
-                       for(i = 0; i<data.length; i++) {
-                           if(queryParam) {
-                               queryParam += "&";
-                           } else {
-                               queryParam = "?";
-                           }
-
-                           queryParam += "id=" + data[i].id;
-                       }
-                       var query = "service/message/"+ encodeURIComponent(that.getVirtualHostName())
-                           + "/" + encodeURIComponent(that.getQueueName()) + queryParam;
-                       that.success = true
-                       xhr.del({url: query, sync: true, handleAs: "json"}).then(
-                           function(data) {
+                       var query = util.buildDeleteQuery(data, "service/message/" + encodeURIComponent(this.getVirtualHostName()) + "/" + encodeURIComponent(this.getQueueName()));
+                       management.del({url: query}).then(
+                           function(result)
+                           {
                                that.grid.setQuery({id: "*"});
                                that.grid.selection.deselectAll();
                                that.queueUpdater.update();
                            },
-                           function(error) {that.success = false; that.failureReason = error;});
-                        if(!that.success ) {
-                            alert("Error:" + this.failureReason);
-                        }
+                           util.xhrErrorHandler);
                    }
                }
            };
@@ -226,16 +203,13 @@ define(["dojo/_base/xhr",
                    var query = "service/message/"+ encodeURIComponent(that.getVirtualHostName())
                        + "/" + encodeURIComponent(that.getQueueName()) + "?clear=true";
                    that.success = true
-                   xhr.del({url: query, sync: true, handleAs: "json"}).then(
+                   this.management.del({url: query}).then(
                        function(data) {
                            that.grid.setQuery({id: "*"});
                            that.grid.selection.deselectAll();
                            that.queueUpdater.update();
                        },
-                       function(error) {that.success = false; that.failureReason = error;});
-                   if(!that.success ) {
-                       alert("Error:" + this.failureReason);
-                   }
+                       util.xhrErrorHandler);
                }
            };
            Queue.prototype.moveOrCopyMessages = function(obj) {
@@ -251,9 +225,8 @@ define(["dojo/_base/xhr",
                    for(i = 0; i<data.length; i++) {
                        putData.messages.push(data[i].id);
                    }
-                   moveMessages.show({ virtualhost: this.getVirtualHostName(),
-                                       queue: this.getQueueName(),
-                                       data: putData}, function() {
+                   moveMessages.show(that.management, that.modelObj,
+                                       putData, function() {
                                          if(move)
                                          {
                                             that.grid.setQuery({id: "*"});
@@ -273,12 +246,12 @@ define(["dojo/_base/xhr",
 
            Queue.prototype.close = function() {
                updater.remove( this.queueUpdater );
-               UserPreferences.removeListener(this);
+               this.management.userPreferences.removeListener(this);
            };
 
            Queue.prototype.onPreferencesChange = function(data)
            {
-             this.grid._refresh();
+             //this.grid._refresh();
            };
 
            var queueTypeKeys = {
@@ -296,6 +269,8 @@ define(["dojo/_base/xhr",
            function QueueUpdater(containerNode, queueObj, controller)
            {
                var that = this;
+               this.management = controller.management;
+               this.modelObj = queueObj;
 
                function findNode(name) {
                    return query("." + name, containerNode)[0];
@@ -349,24 +324,14 @@ define(["dojo/_base/xhr",
                            "maximumDeliveryAttempts",
                            "oldestMessageAge"]);
 
-
-
-               this.query = "api/latest/queue/" + encodeURIComponent(queueObj.getVirtualHostNodeName()) + "/"  + encodeURIComponent(queueObj.getVirtualHostName()) + "/" + encodeURIComponent(queueObj.getQueueName());
-
-               xhr.get({url: this.query, sync: properties.useSyncGet, handleAs: "json"}).then(function(data)
-                               {
-                                   that.queueData = data[0];
-
-                                   util.flattenStatistics( that.queueData );
-
-                                   that.updateHeader();
-                                   that.bindingsGrid = new UpdatableStore(that.queueData.bindings, findNode("bindings"),
+                                   that.queueData = {}
+                                   that.bindingsGrid = new UpdatableStore([], findNode("bindings"),
                                                             [ { name: "Exchange",    field: "exchange",      width: "40%"},
                                                               { name: "Binding Key", field: "name",          width: "30%"},
                                                               { name: "Arguments",   field: "argumentString",     width: "30%"}
                                                             ]);
 
-                                   that.consumersGrid = new UpdatableStore(that.queueData.consumers, findNode("consumers"),
+                                   that.consumersGrid = new UpdatableStore([], findNode("consumers"),
                                                             [ { name: "Name",    field: "name",      width: "40%"},
                                                               { name: "Mode", field: "distributionMode", width: "20%"},
                                                               { name: "Msgs Rate", field: "msgRate",
@@ -378,7 +343,6 @@ define(["dojo/_base/xhr",
 
 
 
-                               });
 
            }
 
@@ -436,16 +400,19 @@ define(["dojo/_base/xhr",
                this.maximumDeliveryAttempts.innerHTML = entities.encode(String( maximumDeliveryAttempts == 0 ? "" : maximumDeliveryAttempts));
            };
 
-           QueueUpdater.prototype.update = function()
+           QueueUpdater.prototype.update = function(callback)
            {
 
                var thisObj = this;
 
-               xhr.get({url: this.query, sync: properties.useSyncGet, handleAs: "json"}).then(function(data) {
+               this.management.load(this.modelObj).then(function(data) {
                        var i,j;
                        thisObj.queueData = data[0];
                        util.flattenStatistics( thisObj.queueData );
-
+                       if (callback)
+                       {
+                          callback();
+                       }
                        var bindings = thisObj.queueData[ "bindings" ];
                        var consumers = thisObj.queueData[ "consumers" ];
 
@@ -545,20 +512,14 @@ define(["dojo/_base/xhr",
 
            Queue.prototype.deleteQueue = function() {
                if(confirm("Are you sure you want to delete queue '" +this.name+"'?")) {
-                   var query = "api/latest/queue/" + encodeURIComponent(this.getVirtualHostNodeName())
-                                   + "/" + encodeURIComponent(this.getVirtualHostName()) + "/" + encodeURIComponent(this.name);
-                   this.success = true
                    var that = this;
-                   xhr.del({url: query, sync: true, handleAs: "json"}).then(
+                   this.management.remove(this.modelObj).then(
                        function(data) {
                            that.contentPane.onClose()
                            that.controller.tabContainer.removeChild(that.contentPane);
                            that.contentPane.destroyRecursive();
                        },
-                       function(error) {that.success = false; that.failureReason = error;});
-                   if(!this.success ) {
-                       util.xhrErrorHandler(this.failureReason);
-                   }
+                       util.xhrErrorHandler);
                }
            }
 

Modified: qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/TrustStore.js
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/TrustStore.js?rev=1677590&r1=1677589&r2=1677590&view=diff
==============================================================================
--- qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/TrustStore.js (original)
+++ qpid/java/trunk/broker-plugins/management-http/src/main/java/resources/js/qpid/management/TrustStore.js Mon May  4 12:17:23 2015
@@ -19,7 +19,6 @@
  *
  */
 define(["dojo/dom",
-        "dojo/_base/xhr",
         "dojo/parser",
         "dojo/query",
         "dojo/_base/connect",
@@ -30,14 +29,15 @@ define(["dojo/dom",
         "qpid/common/util",
         "qpid/common/formatter",
         "qpid/management/addStore",
+        "dojo/text!showStore.html",
         "dojo/domReady!"],
-       function (dom, xhr, parser, query, connect, registry, entities, properties, updater, util, formatter, addStore) {
+       function (dom, parser, query, connect, registry, entities, properties, updater, util, formatter, addStore, template) {
 
            function TrustStore(name, parent, controller) {
                this.keyStoreName = name;
                this.controller = controller;
                this.modelObj = { type: "truststore", name: name, parent: parent};
-               this.url = "api/latest/truststore/" + encodeURIComponent(name);
+               this.management = controller.management;
            }
 
            TrustStore.prototype.getTitle = function() {
@@ -47,16 +47,13 @@ define(["dojo/dom",
            TrustStore.prototype.open = function(contentPane) {
                var that = this;
                this.contentPane = contentPane;
-               xhr.get({url: "showStore.html",
-                        sync: true,
-                        load:  function(data) {
-                            contentPane.containerNode.innerHTML = data;
-                            parser.parse(contentPane.containerNode).then(function(instances)
-                            {
-
-                            that.keyStoreUpdater = new KeyStoreUpdater(contentPane.containerNode, that.modelObj, that.controller, that.url);
-                            that.keyStoreUpdater.update();
-                            updater.add( that.keyStoreUpdater );
+
+                contentPane.containerNode.innerHTML = template;
+                parser.parse(contentPane.containerNode).then(function(instances)
+                {
+
+                            that.keyStoreUpdater = new KeyStoreUpdater(contentPane.containerNode, that.modelObj, that.controller);
+                            that.keyStoreUpdater.update(function(){updater.add( that.keyStoreUpdater );});
 
                             var deleteTrustStoreButton = query(".deleteStoreButton", contentPane.containerNode)[0];
                             var node = registry.byNode(deleteTrustStoreButton);
@@ -69,15 +66,14 @@ define(["dojo/dom",
                             var node = registry.byNode(editTrustStoreButton);
                             connect.connect(node, "onClick",
                                 function(evt){
-                                    xhr.get({url: that.url, sync: properties.useSyncGet, handleAs: "json", content: { actuals: true }})
+                                    that.management.load(that.modelObj, { actuals: true })
                                     .then(function(data)
                                     {
-                                      addStore.setupTypeStore("TrustStore");
+                                      addStore.setupTypeStore(that.management, "TrustStore", that.modelObj);
                                       addStore.show(data[0], that.url);
-                                    });
+                                    }, util.xhrErrorHandler);
                                 });
-                            });
-                        }});
+                });
            };
 
            TrustStore.prototype.close = function() {
@@ -88,6 +84,8 @@ define(["dojo/dom",
            {
                var that = this;
                this.keyStoreDetailsContainer = query(".typeFieldsContainer", containerNode)[0];
+               this.management = controller.management;
+               this.modelObj = keyStoreObj;
 
                function findNode(name) {
                    return query("." + name , containerNode)[0];
@@ -107,28 +105,28 @@ define(["dojo/dom",
 
                this.query = url;
 
-               xhr.get({url: this.query, sync: properties.useSyncGet, handleAs: "json"}).then(function(data)
-                               {
-                                  that.keyStoreData = data[0];
-                                  that.updateHeader();
-                               });
-
            }
 
            KeyStoreUpdater.prototype.updateHeader = function()
            {
-              this.name.innerHTML = entities.encode(String(this.keyStoreData[ "name" ]));
-              this.type.innerHTML = entities.encode(String(this.keyStoreData[ "type" ]));
-              this.state.innerHTML = entities.encode(String(this.keyStoreData[ "state" ]));
+              this.name.innerHTML = entities.encode(String(this.trustStoreData[ "name" ]));
+              this.type.innerHTML = entities.encode(String(this.trustStoreData[ "type" ]));
+              this.state.innerHTML = entities.encode(String(this.trustStoreData[ "state" ]));
            };
 
-           KeyStoreUpdater.prototype.update = function()
+           KeyStoreUpdater.prototype.update = function(callback)
            {
               var that = this;
-              xhr.get({url: this.query, sync: properties.useSyncGet, handleAs: "json"}).then(function(data)
+              this.management.load(this.modelObj).then(function(data)
                {
                   that.trustStoreData = data[0];
                   that.updateHeader();
+
+                  if (callback)
+                  {
+                    callback();
+                  }
+
                   if (that.details)
                   {
                     that.details.update(that.trustStoreData);
@@ -148,20 +146,15 @@ define(["dojo/dom",
 
            TrustStore.prototype.deleteKeyStore = function() {
                if(confirm("Are you sure you want to delete trust store '" +this.keyStoreName+"'?")) {
-                   var query = this.url;
-                   this.success = true
                    var that = this;
-                   xhr.del({url: query, sync: true, handleAs: "json"}).then(
+                   this.management.remove(this.modelObj).then(
                        function(data) {
                            that.contentPane.onClose()
                            that.controller.tabContainer.removeChild(that.contentPane);
                            that.contentPane.destroyRecursive();
                            that.close();
                        },
-                       function(error) {that.success = false; that.failureReason = error;});
-                   if(!this.success ) {
-                       util.xhrErrorHandler(this.failureReason);
-                   }
+                       util.xhrErrorHandler);
                }
            }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message