From 000c76871f46d3bcd69edddd0634322d8775c785 Mon Sep 17 00:00:00 2001 From: Neel Patel Date: Mon, 29 Feb 2016 19:34:06 +0530 Subject: [PATCH] Updated the misc module javascripts to work with latest wcDocker. --- web/pgadmin/misc/depends/static/js/depends.js | 77 ++++++++++++++----- web/pgadmin/misc/sql/static/js/sql.js | 23 +++++- 2 files changed, 79 insertions(+), 21 deletions(-) diff --git a/web/pgadmin/misc/depends/static/js/depends.js b/web/pgadmin/misc/depends/static/js/depends.js index 0a48db151..b6c193ea0 100644 --- a/web/pgadmin/misc/depends/static/js/depends.js +++ b/web/pgadmin/misc/depends/static/js/depends.js @@ -25,26 +25,12 @@ define( 'showDependencies', 'dependenciesPanelVisibilityChanged', '__updateCollection' ); - // Find the panels to render the grid. - var dependenciesPanels = this.dependenciesPanels = pgBrowser.docker.findPanels('dependencies'); - var dependentsPanels = this.dependentsPanels = pgBrowser.docker.findPanels('dependents'); - // We will listened to the visibility change of the Dependencies and Dependents panel pgBrowser.Events.on('pgadmin-browser:panel-dependencies:' + wcDocker.EVENT.VISIBILITY_CHANGED, this.dependenciesPanelVisibilityChanged); pgBrowser.Events.on('pgadmin-browser:panel-dependents:' + wcDocker.EVENT.VISIBILITY_CHANGED, this.dependentsPanelVisibilityChanged); - // If Dependencies panel exists and is focused then we need to listen the browser tree selection events. - if ((dependenciesPanels.length == 1 && dependenciesPanels[0].isVisible()) || dependenciesPanels.length != 1) { - pgBrowser.Events.on('pgadmin-browser:tree:selected', this.showDependencies); - } - - // If Dependents panel exists and is focused then we need to listen the browser tree selection events. - if ((dependentsPanels.length == 1 && dependentsPanels[0].isVisible()) || dependentsPanels.length != 1) { - pgBrowser.Events.on('pgadmin-browser:tree:selected', this.showDependents); - } - // Defining Backbone Model for Dependencies and Dependents. var Model = Backbone.Model.extend({ defaults: { @@ -85,7 +71,7 @@ define( * panel only once. */ var appendGridToPanel = function(collection, panel, is_dependent) { - var $container = panel[0].layout().$table.find('.pg-panel-content'), + var $container = panel[0].layout().scene().find('.pg-panel-content'), $gridContainer = $container.find('.pg-panel-depends-container'), grid = new Backgrid.Grid({ columns: [ @@ -127,16 +113,71 @@ define( self.dependenciesGrid = grid; $gridContainer.append(grid.render().el); + + return true; }; - appendGridToPanel(this.dependentCollection, this.dependentsPanels, true); - appendGridToPanel(this.dependenciesCollection, this.dependenciesPanels, false); + // We will listened to the visibility change of the Dependencies and Dependents panel + pgBrowser.Events.on('pgadmin-browser:panel-dependencies:' + wcDocker.EVENT.VISIBILITY_CHANGED, + this.dependenciesPanelVisibilityChanged); + pgBrowser.Events.on('pgadmin-browser:panel-dependents:' + wcDocker.EVENT.VISIBILITY_CHANGED, + this.dependentsPanelVisibilityChanged); + + // We will render the grid objects in the panel after some time, because - + // it is possible, it is not yet available. + // Find the panels to render the grid. + var dependenciesPanels = this.dependenciesPanels = pgBrowser.docker.findPanels('dependencies'); + var dependentsPanels = this.dependentsPanels = pgBrowser.docker.findPanels('dependents'); + + if (dependenciesPanels.length == 0) { + pgBrowser.Events.on( + 'pgadmin-browser:panel-dependencies:' + wcDocker.EVENT.INIT, + function() { + this.dependenciesPanels = pgBrowser.docker.findPanels('dependencies'); + appendGridToPanel(this.dependenciesCollection, this.dependenciesPanels, false); + + // If Dependencies panel exists and is focused then we need to listen the browser tree selection events. + if ((dependenciesPanels[0].isVisible()) || dependenciesPanels.length != 1) { + pgBrowser.Events.on('pgadmin-browser:tree:selected', this.showDependencies); + } + }.bind(this) + ); + } else { + appendGridToPanel(this.dependenciesCollection, this.dependenciesPanels, false); + + // If Dependencies panel exists and is focused then we need to listen the browser tree selection events. + if ((dependenciesPanels[0].isVisible()) || dependenciesPanels.length != 1) { + pgBrowser.Events.on('pgadmin-browser:tree:selected', this.showDependencies); + } + } + + if (dependentsPanels.length == 0) { + pgBrowser.Events.on( + 'pgadmin-browser:panel-dependents:' + wcDocker.EVENT.INIT, + function() { + this.dependentsPanels = pgBrowser.docker.findPanels('dependents'); + appendGridToPanel(this.dependentCollection, this.dependentsPanels, true); + + // If Dependents panel exists and is focused then we need to listen the browser tree selection events. + if ((dependentsPanels[0].isVisible()) || dependentsPanels.length != 1) { + pgBrowser.Events.on('pgadmin-browser:tree:selected', this.showDependents); + } + }.bind(this) + ); + } else { + appendGridToPanel(this.dependentCollection, this.dependentsPanels, true); + + // If Dependents panel exists and is focused then we need to listen the browser tree selection events. + if ((dependentsPanels[0].isVisible()) || dependentsPanels.length != 1) { + pgBrowser.Events.on('pgadmin-browser:tree:selected', this.showDependents); + } + } }, // Fetch the actual data and update the collection __updateCollection: function(collection, panel, url, messages, node) { var msg = messages[0], - $container = panel[0].layout().$table.find('.pg-panel-content'), + $container = panel[0].layout().scene().find('.pg-panel-content'), $msgContainer = $container.find('.pg-panel-depends-message'), $gridContainer = $container.find('.pg-panel-depends-container'); diff --git a/web/pgadmin/misc/sql/static/js/sql.js b/web/pgadmin/misc/sql/static/js/sql.js index 43abeef60..95d16a2b5 100644 --- a/web/pgadmin/misc/sql/static/js/sql.js +++ b/web/pgadmin/misc/sql/static/js/sql.js @@ -19,13 +19,30 @@ function(_, $, pgBrowser) { var sqlPanels = pgBrowser.docker.findPanels('sql'); // We will listend to the visibility change of the SQL panel - pgBrowser.Events.on('pgadmin-browser:panel-sql:' + wcDocker.EVENT.VISIBILITY_CHANGED, this.sqlPanelVisibilityChanged); + pgBrowser.Events.on( + 'pgadmin-browser:panel-sql:' + wcDocker.EVENT.VISIBILITY_CHANGED, + this.sqlPanelVisibilityChanged + ); // Hmm.. Did we find the SQL panel, and is it visible (openned)? // If that is the case - we need to listen the browser tree selection // events. - if ((sqlPanels.length == 1 && sqlPanels[0].isVisible()) || sqlPanels.length != 1) { - pgBrowser.Events.on('pgadmin-browser:tree:selected', this.showSQL); + if (sqlPanels.length == 0) { + pgBrowser.Events.on( + 'pgadmin-browser:panel-sql:' + wcDocker.EVENT.INIT, + function() { + if ((sqlPanels[0].isVisible()) || sqlPanels.length != 1) { + pgBrowser.Events.on( + 'pgadmin-browser:tree:selected', this.showSQL + ); + } + }.bind(this) + ); + } + else { + if ((sqlPanels[0].isVisible()) || sqlPanels.length != 1) { + pgBrowser.Events.on('pgadmin-browser:tree:selected', this.showSQL); + } } }, showSQL: function(item, data, node) {