From 83b6a04763ec0bd87cec39394cebdae42e238646 Mon Sep 17 00:00:00 2001 From: Murtuza Zabuawala Date: Tue, 10 May 2016 16:04:47 +0530 Subject: [PATCH] Added input validation and title of the prompt for 'Named Restore point' functionality --- .../servers/templates/servers/servers.js | 34 +++++++++++-------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/web/pgadmin/browser/server_groups/servers/templates/servers/servers.js b/web/pgadmin/browser/server_groups/servers/templates/servers/servers.js index 5300055ee..82be70814 100644 --- a/web/pgadmin/browser/server_groups/servers/templates/servers/servers.js +++ b/web/pgadmin/browser/server_groups/servers/templates/servers/servers.js @@ -173,11 +173,11 @@ function($, _, S, pgAdmin, pgBrowser, alertify) { }, /* Reload configuration */ reload_configuration: function(args){ - var input = args || {}; - obj = this, - t = pgBrowser.tree, - i = input.item || t.selected(), - d = i && i.length == 1 ? t.itemData(i) : undefined; + var input = args || {}, + obj = this, + t = pgBrowser.tree, + i = input.item || t.selected(), + d = i && i.length == 1 ? t.itemData(i) : undefined; if (!d) return false; @@ -216,20 +216,21 @@ function($, _, S, pgAdmin, pgBrowser, alertify) { }, /* Add restore point */ restore_point: function(args) { - var input = args || {}; - obj = this, - t = pgBrowser.tree, - i = input.item || t.selected(), - d = i && i.length == 1 ? t.itemData(i) : undefined; + var input = args || {}, + obj = this, + t = pgBrowser.tree, + i = input.item || t.selected(), + d = i && i.length == 1 ? t.itemData(i) : undefined; if (!d) return false; - alertify.prompt('{{ _('Enter the name of the restore point') }}', '', + alertify.prompt('{{ _('Enter the name of the restore point to add') }}', '', // We will execute this function when user clicks on the OK button function(evt, value) { // If user has provided a value, send it to the server - if(!_.isUndefined(value) && !_.isNull(value) && value !== '') { + if(!_.isUndefined(value) && !_.isNull(value) && value !== '' + && String(value).replace(/^\s+|\s+$/g, '') !== '') { $.ajax({ url: obj.generate_url(i, 'restore_point', d, true), method:'POST', @@ -248,11 +249,16 @@ function($, _, S, pgAdmin, pgBrowser, alertify) { } }); } else { + evt.cancel = true; alertify.error('{{ _('Please enter a valid name.') }}', 10); } + }, + // We will execute this function when user clicks on the Cancel button + // Do nothing just close it + function(evt, value) { + evt.cancel = false; } - ); - + ).set({'title':'Restore point name'}); } }, model: pgAdmin.Browser.Node.Model.extend({