diff --git a/js/app/views/SendToSampButtonUI.js b/js/app/views/SendToSampButtonUI.js index 4756788..90e98f3 100644 --- a/js/app/views/SendToSampButtonUI.js +++ b/js/app/views/SendToSampButtonUI.js @@ -41,27 +41,27 @@ Ext.define('amdaUI.SendToSampButtonUI', { clientId : id, handler : function () { - if (!me.testSAMPConnection()) - return; - if (me.onSendToSamp) - me.onSendToSamp.call(this,id,me.sendOpt); + me.testSAMPConnection(function () { + if (me.onSendToSamp) + me.onSendToSamp.call(this,id,me.sendOpt); + }); }, icon : icon }; }, - testSAMPConnection : function() + testSAMPConnection : function(onConnected) { - var interopModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.interop.id); - if (!interopModule) - return false; - if (!interopModule.sampConnected()) - { - interopModule.switchSampConnect(); - return false; + var me = this; + myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.interop.id, true, function (module) { + if (!module.sampConnected()) { + module.switchSampConnect(); } - - return true; + else { + if (onConnected) + onConnected.call(); + } + }); }, updateMenu : function() @@ -70,34 +70,33 @@ Ext.define('amdaUI.SendToSampButtonUI', { this.menu.removeAll(); - if (!this.testSAMPConnection()) - return false; - - var clients = []; + this.testSAMPConnection(function () { + var clients = []; - var interopModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.interop.id); - if (!interopModule) - return false; + var interopModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.interop.id); + if (!interopModule) + return false; - switch (this.type) - { - case 'fits' : - clients = interopModule.getFITSClients(); - break; - default : - clients = interopModule.getVOTableClients(); - } + switch (me.type) + { + case 'fits' : + clients = interopModule.getFITSClients(); + break; + default : + clients = interopModule.getVOTableClients(); + } - Ext.each(clients,function(client) + Ext.each(clients,function(client) { if (client['id'] != 'hub') me.menu.add(me.getMenuItem(client['name'],client['id'],client['icon'])); }); - if (clients.length > 0) - { - me.menu.add('-'); - me.menu.add(me.getMenuItem('all clients','hub')); - } + if (clients.length > 0) + { + me.menu.add('-'); + me.menu.add(me.getMenuItem('all clients','hub')); + } + }); return true; }, @@ -127,4 +126,4 @@ Ext.define('amdaUI.SendToSampButtonUI', { Ext.apply(this, newConfig); } -}); \ No newline at end of file +}); -- libgit2 0.21.2