From e07ebdc049b65e6d00f123c063c57da02e0044c2 Mon Sep 17 00:00:00 2001 From: Ashesh Vashi Date: Mon, 11 Apr 2016 17:05:49 +0530 Subject: [PATCH] Moving the messages used in common utilities in a separate javascript. --- web/pgadmin/browser/__init__.py | 26 +++++++++------- .../browser/templates/browser/js/browser.js | 21 ++++--------- .../browser/templates/browser/js/messages.js | 30 +++++++++++++++++++ web/pgadmin/misc/depends/static/js/depends.js | 2 +- web/pgadmin/misc/sql/static/js/sql.js | 4 +-- .../static/js/alertifyjs/pgadmin.defaults.js | 4 +-- web/pgadmin/static/js/backform.pgadmin.js | 2 +- 7 files changed, 58 insertions(+), 31 deletions(-) create mode 100644 web/pgadmin/browser/templates/browser/js/messages.js diff --git a/web/pgadmin/browser/__init__.py b/web/pgadmin/browser/__init__.py index c145f76a7..63e239fec 100644 --- a/web/pgadmin/browser/__init__.py +++ b/web/pgadmin/browser/__init__.py @@ -12,8 +12,7 @@ from pgadmin import current_blueprint from pgadmin.utils import PgAdminModule from pgadmin.utils.ajax import make_json_response from pgadmin.settings import get_setting -from flask import current_app, render_template, url_for, make_response, \ - Response, flash +from flask import current_app, render_template, url_for, make_response, flash from flask.ext.security import login_required from flask.ext.login import current_user from flask.ext.babel import gettext @@ -160,6 +159,7 @@ class BrowserModule(PgAdminModule): for name, script in [ ['pgadmin.browser.node', 'js/node'], + ['pgadmin.browser.messages', 'js/messages'], ['pgadmin.browser.collection', 'js/collection']]: scripts.append({ 'name': name, @@ -428,13 +428,13 @@ class BrowserPluginModule(PgAdminModule): def index(): """Render and process the main browser window.""" # Get the Gravatar - gravatar = Gravatar(current_app, - size=100, - rating='g', - default='retro', - force_default=False, - use_ssl=False, - base_url=None) + Gravatar(current_app, + size=100, + rating='g', + default='retro', + force_default=False, + use_ssl=False, + base_url=None) # Get the current version info from the website, and flash a message if # the user is out of date, and the check is enabled. @@ -499,12 +499,18 @@ def error_js(): @blueprint.route("/js/node.js") -@login_required def node_js(): return make_response( render_template('browser/js/node.js', _=gettext), 200, {'Content-Type': 'application/x-javascript'}) +@blueprint.route("/js/messages.js") +def messages_js(): + return make_response( + render_template('browser/js/messages.js', _=gettext), + 200, {'Content-Type': 'application/x-javascript'}) + + @blueprint.route("/js/collection.js") @login_required def collection_js(): diff --git a/web/pgadmin/browser/templates/browser/js/browser.js b/web/pgadmin/browser/templates/browser/js/browser.js index 97a7c74f2..533ecc698 100644 --- a/web/pgadmin/browser/templates/browser/js/browser.js +++ b/web/pgadmin/browser/templates/browser/js/browser.js @@ -1,10 +1,12 @@ -define( +define('pgadmin.browser', ['require', 'jquery', 'underscore', 'underscore.string', 'bootstrap', 'pgadmin', 'alertify', 'codemirror', 'codemirror.sql', 'wcdocker', - 'jquery.contextmenu', 'jquery.acitree', 'pgadmin.alertifyjs', - 'pgadmin.browser.menu', 'pgadmin.browser.panel', 'jquery.aciplugin', + 'jquery.contextmenu', 'jquery.aciplugin', 'jquery.acitree', + 'pgadmin.alertifyjs', 'pgadmin.browser.messages', + 'pgadmin.browser.menu', 'pgadmin.browser.panel', 'pgadmin.browser.error', 'pgadmin.browser.frame', 'pgadmin.browser.node', 'pgadmin.browser.collection' + ], function(require, $, _, S, Bootstrap, pgAdmin, alertify, CodeMirror) { @@ -75,7 +77,7 @@ function(require, $, _, S, Bootstrap, pgAdmin, alertify, CodeMirror) { width: 500, isCloseable: false, isPrivate: true, - content: '

Statistics pane

', + content: '
{{ _('Please select an object in the tree view.') }}
', events: panelEvents }), // Reversed engineered SQL for the object @@ -627,17 +629,6 @@ function(require, $, _, S, Bootstrap, pgAdmin, alertify, CodeMirror) { navbar.children('#mnu_obj').removeClass('hide'); obj.enable_disable_menus(); - }, - messages: { - 'server_lost': '{{ _('Connection to the server has been lost!') }}', - 'click_for_detailed_msg': '{{ _('%%s

Click here for details.') }}', - 'general_cateogty': '{{ _('General') }}', - 'SQL_TAB': '{{ _('SQL') }}', - 'SQL_NO_CHANGE': '-- ' + '{{ _('Nothing changed') }}', - 'MUST_BE_INT' : " {{ _("'%%s' must be an integer.") }}", - 'MUST_BE_NUM' : " {{ _("'%%s' must be a numeric.") }}", - 'MUST_GR_EQ' : " {{ _("'%%s' must be greater than or equal to %%d.") }}", - 'MUST_LESS_EQ' : " {{ _("'%%s' must be less than or equal to %%d.") }}" } }); diff --git a/web/pgadmin/browser/templates/browser/js/messages.js b/web/pgadmin/browser/templates/browser/js/messages.js new file mode 100644 index 000000000..17e8c6dab --- /dev/null +++ b/web/pgadmin/browser/templates/browser/js/messages.js @@ -0,0 +1,30 @@ +define('pgadmin.browser.messages', + ['underscore', 'underscore.string', 'pgadmin'], +function(_, S, pgAdmin) { + + var pgBrowser = pgAdmin.Browser = pgAdmin.Browser || {}; + + if (pgBrowser.messages) + return pgBrowser.messages; + + pgBrowser.messages = { + 'SERVER_LOST': '{{ _('Connection to the server has been lost!') }}', + 'CLICK_FOR_DETAILED_MSG': '%s

' + '{{ _('Click here for details!')|safe }}', + 'GENERAL_CATEOGTY': '{{ _('General')|safe }}', + 'SQL_TAB': '{{ _('SQL') }}', + 'SQL_NO_CHANGE': '-- ' + '{{ _('Nothing changed')|safe }}', + 'MUST_BE_INT' : "{{ _("'%%s' must be an integer.")|safe }}", + 'MUST_BE_NUM' : "{{ _("'%%s' must be a numeric.")|safe }}", + 'MUST_GR_EQ' : "{{ _("'%%s' must be greater than or equals to %%d.")|safe }}", + 'MUST_LESS_EQ' : "{{ _("'%%s' must be less than or equals to %%d.")|safe }}", + 'STATISTICS_LABEL': "{{ _("Statistics") }}", + 'STATISTICS_VALUE_LABEL': "{{ _("Value") }}", + 'NODE_HAS_NO_SQL': "{{ _("No SQL could be generated for the selected object.") }}", + 'NODE_HAS_NO_STATISTICS': "{{ _("No statistics are available for the selected object!") }}", + 'TRUE': "{{ _("True") }}", + 'FALSE': "{{ _("False") }}" + }; + + return pgBrowser.messages; + +}); diff --git a/web/pgadmin/misc/depends/static/js/depends.js b/web/pgadmin/misc/depends/static/js/depends.js index e9aa91fb5..c92085eec 100644 --- a/web/pgadmin/misc/depends/static/js/depends.js +++ b/web/pgadmin/misc/depends/static/js/depends.js @@ -103,7 +103,7 @@ define( ], collection: collection, - className: "backgrid table-bordered" + className: "backgrid presentation table backgrid-striped table-bordered table-hover", }); // Condition is used to save grid object to change the label of the header. diff --git a/web/pgadmin/misc/sql/static/js/sql.js b/web/pgadmin/misc/sql/static/js/sql.js index 8d0f87958..8b13399a0 100644 --- a/web/pgadmin/misc/sql/static/js/sql.js +++ b/web/pgadmin/misc/sql/static/js/sql.js @@ -57,9 +57,9 @@ function(_, $, pgBrowser) { } this.timeout = setTimeout( function() { - var sql = '-- Please select an object in the tree view.'; + var sql = ''; if (node) { - sql = '-- No SQL could be generated for the selected object.'; + sql = pgBrowser.messages.NODE_HAS_NO_SQL; if (node.hasSQL) { sql = ''; diff --git a/web/pgadmin/static/js/alertifyjs/pgadmin.defaults.js b/web/pgadmin/static/js/alertifyjs/pgadmin.defaults.js index a6aca1153..30a34d806 100644 --- a/web/pgadmin/static/js/alertifyjs/pgadmin.defaults.js +++ b/web/pgadmin/static/js/alertifyjs/pgadmin.defaults.js @@ -90,7 +90,7 @@ function(alertify, S) { contentType = xhr.getResponseHeader('Content-Type'); if (xhr.status == 0) { - msg = window.pgAdmin.Browser.messages.server_lost; + msg = window.pgAdmin.Browser.messages.SERVER_LOST; } if (contentType) { @@ -110,7 +110,7 @@ function(alertify, S) { if (contentType.indexOf('text/html') == 0) { alertify.notify( S( - window.pgAdmin.Browser.messages.click_for_detailed_msg + window.pgAdmin.Browser.messages.CLICK_FOR_DETAILED_MSG ).sprintf(promptmsg).value(), type, 0, function() { alertify.pgIframeDialog().show().set({ frameless: false }).set('pg_msg', msg); }); diff --git a/web/pgadmin/static/js/backform.pgadmin.js b/web/pgadmin/static/js/backform.pgadmin.js index 8eaed6dda..2b3a4bb4d 100644 --- a/web/pgadmin/static/js/backform.pgadmin.js +++ b/web/pgadmin/static/js/backform.pgadmin.js @@ -1631,7 +1631,7 @@ _.indexOf(s.mode, mode) != -1)) { // Each field is kept in specified group, or in // 'General' category. - var group = s.group || pgBrowser.messages.general_cateogty, + var group = s.group || pgBrowser.messages.GENERAL_CATEOGTY, control = s.control || Backform.getMappedControl(s.type, mode), cell = s.cell || Backform.getMappedControl(s.type, 'cell');