Moving the messages used in common utilities in a separate javascript.

This commit is contained in:
Ashesh Vashi 2016-04-11 17:05:49 +05:30
parent d53ab31eb8
commit e07ebdc049
7 changed files with 58 additions and 31 deletions

View File

@ -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():

View File

@ -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: '<p>Statistics pane</p>',
content: '<div><div class="alert alert-info pg-panel-message pg-panel-statistics-message">{{ _('Please select an object in the tree view.') }}</div><div class="pg-panel-statistics-container hidden"></div></div>',
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<br><br>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.") }}"
}
});

View File

@ -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<br><br>' + '{{ _('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;
});

View File

@ -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.

View File

@ -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 = '';

View File

@ -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);
});

View File

@ -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');