Added input validation and title of the prompt for 'Named Restore point' functionality

This commit is contained in:
Murtuza Zabuawala
2016-05-10 16:04:47 +05:30
committed by Akshay Joshi
parent 585daddce2
commit 83b6a04763

View File

@@ -173,7 +173,7 @@ function($, _, S, pgAdmin, pgBrowser, alertify) {
}, },
/* Reload configuration */ /* Reload configuration */
reload_configuration: function(args){ reload_configuration: function(args){
var input = args || {}; var input = args || {},
obj = this, obj = this,
t = pgBrowser.tree, t = pgBrowser.tree,
i = input.item || t.selected(), i = input.item || t.selected(),
@@ -216,7 +216,7 @@ function($, _, S, pgAdmin, pgBrowser, alertify) {
}, },
/* Add restore point */ /* Add restore point */
restore_point: function(args) { restore_point: function(args) {
var input = args || {}; var input = args || {},
obj = this, obj = this,
t = pgBrowser.tree, t = pgBrowser.tree,
i = input.item || t.selected(), i = input.item || t.selected(),
@@ -225,11 +225,12 @@ function($, _, S, pgAdmin, pgBrowser, alertify) {
if (!d) if (!d)
return false; 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 // We will execute this function when user clicks on the OK button
function(evt, value) { function(evt, value) {
// If user has provided a value, send it to the server // 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({ $.ajax({
url: obj.generate_url(i, 'restore_point', d, true), url: obj.generate_url(i, 'restore_point', d, true),
method:'POST', method:'POST',
@@ -248,11 +249,16 @@ function($, _, S, pgAdmin, pgBrowser, alertify) {
} }
}); });
} else { } else {
evt.cancel = true;
alertify.error('{{ _('Please enter a valid name.') }}', 10); 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({ model: pgAdmin.Browser.Node.Model.extend({