diff --git a/web/pgadmin/browser/__init__.py b/web/pgadmin/browser/__init__.py index 0606b37c6..dbe31bd50 100644 --- a/web/pgadmin/browser/__init__.py +++ b/web/pgadmin/browser/__init__.py @@ -135,6 +135,12 @@ class BrowserModule(PgAdminModule): 'name': name, 'path': url_for('browser.static', filename=end), 'preloaded': True}) + scripts.append({ + 'name': 'pgadmin.browser.node.ui', + 'path': url_for('browser.static', filename='js/node.ui'), + 'when': 'server-group' + }) + for module in self.submodules: scripts.extend(module.get_own_javascripts()) return scripts diff --git a/web/pgadmin/browser/collection.py b/web/pgadmin/browser/collection.py index 44570caa3..4c6753622 100644 --- a/web/pgadmin/browser/collection.py +++ b/web/pgadmin/browser/collection.py @@ -96,8 +96,7 @@ class CollectionNodeModule(PgAdminModule, PGChildModule): snippets = [ render_template( "browser/css/collection.css", - node_type=self.node_type, - _=gettext + node_type=self.node_type ), render_template( "browser/css/node.css", diff --git a/web/pgadmin/browser/server_groups/servers/static/js/privilege.js b/web/pgadmin/browser/server_groups/servers/static/js/privilege.js index 190183e2f..41e9d3dea 100644 --- a/web/pgadmin/browser/server_groups/servers/static/js/privilege.js +++ b/web/pgadmin/browser/server_groups/servers/static/js/privilege.js @@ -103,7 +103,7 @@ var privs = {}; _.each(this.privileges, function(p) { privs[p] = { - 'privilige_type': p, 'privilege': false, 'with_grant': false + 'privilege_type': p, 'privilege': false, 'with_grant': false } }); @@ -376,7 +376,7 @@ }); /* - * This will help us transform the privilieges value in proper format to be + * This will help us transform the privileges value in proper format to be * displayed in the cell. */ var PrivilegeCellFormatter = Backgrid.Extension.PrivilegeCellFormatter = diff --git a/web/pgadmin/browser/static/css/browser.css b/web/pgadmin/browser/static/css/browser.css index 02f96cd18..3ad1dcd51 100644 --- a/web/pgadmin/browser/static/css/browser.css +++ b/web/pgadmin/browser/static/css/browser.css @@ -40,4 +40,8 @@ .browser-tab-content { width: 100%; height: 100%; -} \ No newline at end of file +} + +.pgadmin-node-select option { + padding-left: 20px; +} diff --git a/web/pgadmin/browser/static/js/node.ui.js b/web/pgadmin/browser/static/js/node.ui.js new file mode 100644 index 000000000..a2d6d49bb --- /dev/null +++ b/web/pgadmin/browser/static/js/node.ui.js @@ -0,0 +1,158 @@ +define( + ['jquery', 'underscore', 'pgadmin', 'backbone', 'backform', 'alertify', 'pgadmin.browser.node'], +function($, _, pgAdmin, Backbone, Backform, Alertify, Node) { + + var pgBrowser = pgAdmin.Browser; + + /* + * NodeAjaxOptionsControl + * This control will fetch the options required to render the select + * control, from the url specific to the pgAdmin.Browser node object. + * + * In order to use this properly, schema require to set the 'url' property, + * which exposes the data for this node. + * + * In case the url is not providing the data in proper format, we can + * specify the 'transform' function too, which will convert the fetched + * data to proper 'label', 'value' format. + */ + var NodeAjaxOptionsControl = Backform.NodeAjaxOptionsControl = + Backform.SelectControl.extend({ + defaults: _.extend(Backform.SelectControl.prototype.defaults, { + url: undefined, + transform: undefined + }), + initialize: function() { + /* + * Initialization from the original control. + */ + Backform.SelectControl.prototype.initialize.apply(this, arguments); + + /* + * We're about to fetch the options required for this control. + */ + var self = this, + url = self.field.get('url') || self.defaults.url, + m = self.model.handler || self.model; + + // Hmm - we found the url option. + // That means - we needs to fetch the options from that node. + if (url) { + var node = this.field.get('schema_node'), + full_url = node.generate_url.apply( + node, [ + null, url, this.field.get('node_data'), + false, this.field.get('node_info') + ]), + /* + * We needs to check, if we have already cached data for this url. + * If yes - use that, and do not bother about fetching it again, + * and use it. + */ + data = node.cache(full_url); + if (_.isUndefined(data) || _.isNull(data)) { + m.trigger('pgadmin-view:fetching', m, self.field); + $.ajax({ + async: false, + url: full_url, + success: function(res) { + /* + * We will cache this data for short period of time for avoiding + * same calls. + */ + data = node.cache(full_url, res.data); + }, + error: function() { + m.trigger('pgadmin-view:fetch:error', m, self.field); + } + }); + m.trigger('pgadmin-view:fetched', m, self.field); + } + + /* + * Transform the data + */ + transform = this.field.get('transform') || self.defaults.transform; + if (transform && _.isFunction(transform)) { + try { + data = transform.apply(self, [data]); + } catch(e) { + // Do nothing + data = [] + m.trigger('pgadmin-view:transform:error', m, self.field, e); + } + } + self.field.set('options', data); + } + } + }); + + var NodeListByIdControl = Backform.NodeListByIdControl = NodeAjaxOptionsControl.extend({ + controlClassName: 'pgadmin-node-select form-control', + template: _.template([ + '', + '