Allow to generate events from the nodes, whenever some any events.

i.e.
'server-connect' and 'server-disconnected' events will be generated
while server gets connected and disconnected respectively.

For demo purpose - listening to the server connection from the test
script.
pull/3/head
Ashesh Vashi 2015-11-19 23:41:58 +05:30
parent 77834ccdda
commit 5ff09223a2
3 changed files with 18 additions and 4 deletions

View File

@ -95,6 +95,7 @@ function($, _, S, pgAdmin, pgBrowser, alertify) {
if (pgBrowser.serverInfo && d._id in pgBrowser.serverInfo) {
delete pgBrowser.serverInfo[d._id]
}
obj.trigger('server-disconnected', obj, i, d);
}
},
error: function(xhr, status, error) {
@ -235,7 +236,13 @@ function($, _, S, pgAdmin, pgBrowser, alertify) {
_.extend(data, res.data);
alertify.success(res.info);
setTimeout(function() { tree.select(item); tree.open(item); }, 10);
obj.trigger('server-connected', obj, item, data);
setTimeout(function() {
tree.select(item);
tree.open(item);
}, 10);
}
};

View File

@ -46,7 +46,7 @@ function($, _, S, pgAdmin, Menu, Backbone, Alertify, Backform) {
return child;
};
_.extend(pgAdmin.Browser.Node, {
_.extend(pgAdmin.Browser.Node, Backbone.Events, {
// Node type
type: undefined,
// Label

View File

@ -1,6 +1,6 @@
define(
['jquery', 'alertify', 'pgadmin'],
function($, alertify, pgAdmin) {
['jquery', 'alertify', 'pgadmin', 'pgadmin.node.server'],
function($, alertify, pgAdmin, pgServer) {
pgAdmin = pgAdmin || window.pgAdmin || {};
pgAdmin.Test = {
@ -69,5 +69,12 @@ define(
}
};
pgServer.on(
'server-connected', function() {
console.log(arguments);
console.log('Yay - we connected the server!');
},
{'a': 'test'});
return pgAdmin.Test;
});