diff --git a/web/pgadmin/browser/templates/browser/js/browser.js b/web/pgadmin/browser/templates/browser/js/browser.js index 3679fb319..93d30c0db 100644 --- a/web/pgadmin/browser/templates/browser/js/browser.js +++ b/web/pgadmin/browser/templates/browser/js/browser.js @@ -434,19 +434,8 @@ OWNER TO helpdesk;\n'; // Treeview event handler $('#tree').on('acitree', function(event, api, item, eventName, options) { - var d = null; - if (item) { - d = obj.tree.itemData(item); - if (d && obj.Nodes[d._type] && - _.isObject(obj.Nodes[d._type].callbacks) && - eventName in obj.Nodes[d._type].callbacks && - typeof obj.Nodes[d._type].callbacks[eventName] == - 'function') { - return obj.Nodes[d._type].callbacks[eventName].apply( - obj.Nodes[d._type], [item, d, obj, options, eventName] - ); - } - } + var d = item ? obj.tree.itemData(item) : null; + switch (eventName) { // When a node is added in the browser tree, we need to // load the registered scripts @@ -477,6 +466,29 @@ OWNER TO helpdesk;\n'; } break; } + + if (d && obj.Nodes[d._type]) { + var node = obj.Nodes[d._type]; + + /* If the node specific callback returns false, we will also return + * false for further processing. + */ + if (_.isObject(node.callbacks) && + eventName in node.callbacks && + typeof node.callbacks[eventName] == 'function' && + !node.callbacks[eventName].apply( + node, [item, d, obj, options, eventName])) { + return false; + } + /* Raise tree events for the nodes */ + try { + node.trigger( + 'browser-node.' + eventName, node, item, d + ); + } catch (e) { + console.log(e); + } + } return true; }); diff --git a/web/pgadmin/test/static/js/test.js b/web/pgadmin/test/static/js/test.js index 2cdc55e51..c3527fd09 100644 --- a/web/pgadmin/test/static/js/test.js +++ b/web/pgadmin/test/static/js/test.js @@ -1,6 +1,6 @@ define( - ['jquery', 'alertify', 'pgadmin', 'pgadmin.node.server'], - function($, alertify, pgAdmin, pgServer) { + ['jquery', 'alertify', 'pgadmin', 'pgadmin.node.server', 'pgadmin.node.server-group'], + function($, alertify, pgAdmin, pgServer, ServerGroup) { pgAdmin = pgAdmin || window.pgAdmin || {}; pgAdmin.Test = { @@ -76,5 +76,9 @@ define( }, {'a': 'test'}); + ServerGroup.on('browser-node.loaded', function() { + console.log('I know that the server-group has been expanded!'); + }, pgAdmin.Test); + return pgAdmin.Test; });