mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-09 23:15:58 -06:00
Fixed following SonarQube issues:
- Refactor functions to not always return the same value. - Rename "cls" to "self" or add the missing "self" parameter. - Remove useless assignment to variables.
This commit is contained in:
parent
dd7eb54e90
commit
56cf64ad22
@ -27,13 +27,13 @@ class AuthSourceRegistry(ABCMeta):
|
||||
registry = None
|
||||
auth_sources = dict()
|
||||
|
||||
def __init__(cls, name, bases, d):
|
||||
def __init__(self, name, bases, d):
|
||||
|
||||
# Register this type of auth_sources, based on the module name
|
||||
# Avoid registering the BaseAuthentication itself
|
||||
|
||||
AuthSourceRegistry.registry[_decorate_cls_name(d['__module__'])] = cls
|
||||
ABCMeta.__init__(cls, name, bases, d)
|
||||
AuthSourceRegistry.registry[_decorate_cls_name(d['__module__'])] = self
|
||||
ABCMeta.__init__(self, name, bases, d)
|
||||
|
||||
@classmethod
|
||||
def create(cls, name, **kwargs):
|
||||
|
@ -333,42 +333,39 @@ define('pgadmin.node.fts_configuration', [
|
||||
var self = this,
|
||||
token = self.headerData.get('token');
|
||||
|
||||
if (!token || token == '') {
|
||||
return false;
|
||||
}
|
||||
if (token && token != '') {
|
||||
var coll = self.model.get(self.field.get('name')),
|
||||
m = new (self.field.get('model'))(
|
||||
self.headerData.toJSON(), {
|
||||
silent: true, top: self.model.top,
|
||||
collection: coll, handler: coll,
|
||||
}),
|
||||
checkVars = ['token'],
|
||||
idx = -1;
|
||||
|
||||
var coll = self.model.get(self.field.get('name')),
|
||||
m = new (self.field.get('model'))(
|
||||
self.headerData.toJSON(), {
|
||||
silent: true, top: self.model.top,
|
||||
collection: coll, handler: coll,
|
||||
}),
|
||||
checkVars = ['token'],
|
||||
idx = -1;
|
||||
|
||||
// Find if token exists in grid
|
||||
self.collection.each(function(local_model) {
|
||||
_.each(checkVars, function(v) {
|
||||
var val = local_model.get(v);
|
||||
if(val == token) {
|
||||
idx = coll.indexOf(local_model);
|
||||
}
|
||||
// Find if token exists in grid
|
||||
self.collection.each(function(local_model) {
|
||||
_.each(checkVars, function(v) {
|
||||
var val = local_model.get(v);
|
||||
if(val == token) {
|
||||
idx = coll.indexOf(local_model);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
// remove 'm' if duplicate value found.
|
||||
if (idx == -1) {
|
||||
coll.add(m);
|
||||
idx = coll.indexOf(m);
|
||||
// remove 'm' if duplicate value found.
|
||||
if (idx == -1) {
|
||||
coll.add(m);
|
||||
idx = coll.indexOf(m);
|
||||
}
|
||||
self.$grid.find('.new').removeClass('new');
|
||||
var newRow = self.grid.body.rows[idx].$el;
|
||||
newRow.addClass('new');
|
||||
//$(newRow).pgMakeVisible('table-bordered');
|
||||
$(newRow).pgMakeVisible('backform-tab');
|
||||
}
|
||||
self.$grid.find('.new').removeClass('new');
|
||||
var newRow = self.grid.body.rows[idx].$el;
|
||||
newRow.addClass('new');
|
||||
//$(newRow).pgMakeVisible('table-bordered');
|
||||
$(newRow).pgMakeVisible('backform-tab');
|
||||
|
||||
|
||||
return false;
|
||||
},
|
||||
|
@ -64,30 +64,28 @@ define('pgadmin.node.check_constraint', [
|
||||
i = input.item || t.selected(),
|
||||
d = i && i.length == 1 ? t.itemData(i) : undefined;
|
||||
|
||||
if (!d) {
|
||||
return false;
|
||||
}
|
||||
var data = d;
|
||||
$.ajax({
|
||||
url: obj.generate_url(i, 'validate', d, true),
|
||||
type:'GET',
|
||||
})
|
||||
.done(function(res) {
|
||||
if (res.success == 1) {
|
||||
alertify.success(res.info);
|
||||
t.removeIcon(i);
|
||||
data.valid = true;
|
||||
data.icon = 'icon-check_constraint';
|
||||
t.addIcon(i, {icon: data.icon});
|
||||
setTimeout(function() {t.deselect(i);}, 10);
|
||||
setTimeout(function() {t.select(i);}, 100);
|
||||
}
|
||||
if (d) {
|
||||
var data = d;
|
||||
$.ajax({
|
||||
url: obj.generate_url(i, 'validate', d, true),
|
||||
type:'GET',
|
||||
})
|
||||
.fail(function(xhr, status, error) {
|
||||
alertify.pgRespErrorNotify(xhr, error);
|
||||
t.unload(i);
|
||||
});
|
||||
|
||||
.done(function(res) {
|
||||
if (res.success == 1) {
|
||||
alertify.success(res.info);
|
||||
t.removeIcon(i);
|
||||
data.valid = true;
|
||||
data.icon = 'icon-check_constraint';
|
||||
t.addIcon(i, {icon: data.icon});
|
||||
setTimeout(function() {t.deselect(i);}, 10);
|
||||
setTimeout(function() {t.select(i);}, 100);
|
||||
}
|
||||
})
|
||||
.fail(function(xhr, status, error) {
|
||||
alertify.pgRespErrorNotify(xhr, error);
|
||||
t.unload(i);
|
||||
});
|
||||
}
|
||||
return false;
|
||||
},
|
||||
},
|
||||
|
@ -541,41 +541,39 @@ define('pgadmin.node.exclusion_constraint', [
|
||||
var self = this,
|
||||
column = self.headerData.get('column');
|
||||
|
||||
if (!column || column == '') {
|
||||
return false;
|
||||
}
|
||||
if (column && column != '') {
|
||||
var coll = self.model.get(self.field.get('name')),
|
||||
m = new (self.field.get('model'))(
|
||||
self.headerData.toJSON(), {
|
||||
silent: true, top: self.model.top,
|
||||
collection: coll, handler: coll,
|
||||
}),
|
||||
col_types =self.field.get('col_types') || [];
|
||||
|
||||
var coll = self.model.get(self.field.get('name')),
|
||||
m = new (self.field.get('model'))(
|
||||
self.headerData.toJSON(), {
|
||||
silent: true, top: self.model.top,
|
||||
collection: coll, handler: coll,
|
||||
}),
|
||||
col_types =self.field.get('col_types') || [];
|
||||
|
||||
for(var i=0; i < col_types.length; i++) {
|
||||
var col_type = col_types[i];
|
||||
if (col_type['name'] == m.get('column')) {
|
||||
m.set({'col_type':col_type['type']});
|
||||
break;
|
||||
for(var i=0; i < col_types.length; i++) {
|
||||
var col_type = col_types[i];
|
||||
if (col_type['name'] == m.get('column')) {
|
||||
m.set({'col_type':col_type['type']});
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
coll.add(m);
|
||||
coll.add(m);
|
||||
|
||||
var idx = coll.indexOf(m);
|
||||
var idx = coll.indexOf(m);
|
||||
|
||||
// idx may not be always > -1 because our UniqueColCollection may
|
||||
// remove 'm' if duplicate value found.
|
||||
if (idx > -1) {
|
||||
self.$grid.find('.new').removeClass('new');
|
||||
// idx may not be always > -1 because our UniqueColCollection may
|
||||
// remove 'm' if duplicate value found.
|
||||
if (idx > -1) {
|
||||
self.$grid.find('.new').removeClass('new');
|
||||
|
||||
var newRow = self.grid.body.rows[idx].$el;
|
||||
var newRow = self.grid.body.rows[idx].$el;
|
||||
|
||||
newRow.addClass('new');
|
||||
$(newRow).pgMakeVisible('backform-tab');
|
||||
} else {
|
||||
//delete m;
|
||||
newRow.addClass('new');
|
||||
$(newRow).pgMakeVisible('backform-tab');
|
||||
} else {
|
||||
//delete m;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -27,7 +27,7 @@ define('pgadmin.node.foreign_key', [
|
||||
return opt.text;
|
||||
} else {
|
||||
return $(
|
||||
'<span><span class="wcTabIcon ' + optimage + '"/>' + opt.text + '</span>'
|
||||
'<span><span class="wcTabIcon ' + optimage + '"/></span><span>' + opt.text + '</span></span>'
|
||||
);
|
||||
}
|
||||
},
|
||||
@ -487,32 +487,28 @@ define('pgadmin.node.foreign_key', [
|
||||
local_column = self.headerData.get('local_column'),
|
||||
referenced = self.headerData.get('referenced');
|
||||
|
||||
if (!local_column || local_column == '' ||
|
||||
!referenced || referenced =='') {
|
||||
return false;
|
||||
if (local_column && local_column != '' && referenced && referenced != '') {
|
||||
var m = new (self.field.get('model'))(
|
||||
self.headerData.toJSON()),
|
||||
coll = self.model.get(self.field.get('name'));
|
||||
|
||||
coll.add(m);
|
||||
|
||||
var idx = coll.indexOf(m);
|
||||
|
||||
// idx may not be always > -1 because our UniqueColCollection may
|
||||
// remove 'm' if duplicate value found.
|
||||
if (idx > -1) {
|
||||
self.$grid.find('.new').removeClass('new');
|
||||
|
||||
var newRow = self.grid.body.rows[idx].$el;
|
||||
|
||||
newRow.addClass('new');
|
||||
$(newRow).pgMakeVisible('backform-tab');
|
||||
} else {
|
||||
//delete m;
|
||||
}
|
||||
}
|
||||
|
||||
var m = new (self.field.get('model'))(
|
||||
self.headerData.toJSON()),
|
||||
coll = self.model.get(self.field.get('name'));
|
||||
|
||||
coll.add(m);
|
||||
|
||||
var idx = coll.indexOf(m);
|
||||
|
||||
// idx may not be always > -1 because our UniqueColCollection may
|
||||
// remove 'm' if duplicate value found.
|
||||
if (idx > -1) {
|
||||
self.$grid.find('.new').removeClass('new');
|
||||
|
||||
var newRow = self.grid.body.rows[idx].$el;
|
||||
|
||||
newRow.addClass('new');
|
||||
$(newRow).pgMakeVisible('backform-tab');
|
||||
} else {
|
||||
//delete m;
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
@ -663,30 +659,28 @@ define('pgadmin.node.foreign_key', [
|
||||
i = input.item || t.selected(),
|
||||
d = i && i.length == 1 ? t.itemData(i) : undefined;
|
||||
|
||||
if (!d) {
|
||||
return false;
|
||||
}
|
||||
var data = d;
|
||||
$.ajax({
|
||||
url: obj.generate_url(i, 'validate', d, true),
|
||||
type:'GET',
|
||||
})
|
||||
.done(function(res) {
|
||||
if (res.success == 1) {
|
||||
Alertify.success(res.info);
|
||||
t.removeIcon(i);
|
||||
data.valid = true;
|
||||
data.icon = 'icon-foreign_key';
|
||||
t.addIcon(i, {icon: data.icon});
|
||||
setTimeout(function() {t.deselect(i);}, 10);
|
||||
setTimeout(function() {t.select(i);}, 100);
|
||||
}
|
||||
if (d) {
|
||||
var data = d;
|
||||
$.ajax({
|
||||
url: obj.generate_url(i, 'validate', d, true),
|
||||
type:'GET',
|
||||
})
|
||||
.fail(function(xhr, status, error) {
|
||||
Alertify.pgRespErrorNotify(xhr, error);
|
||||
t.unload(i);
|
||||
});
|
||||
|
||||
.done(function(res) {
|
||||
if (res.success == 1) {
|
||||
Alertify.success(res.info);
|
||||
t.removeIcon(i);
|
||||
data.valid = true;
|
||||
data.icon = 'icon-foreign_key';
|
||||
t.addIcon(i, {icon: data.icon});
|
||||
setTimeout(function() {t.deselect(i);}, 10);
|
||||
setTimeout(function() {t.select(i);}, 100);
|
||||
}
|
||||
})
|
||||
.fail(function(xhr, status, error) {
|
||||
Alertify.pgRespErrorNotify(xhr, error);
|
||||
t.unload(i);
|
||||
});
|
||||
}
|
||||
return false;
|
||||
},
|
||||
},
|
||||
|
@ -172,10 +172,9 @@ define('pgadmin.node.database', [
|
||||
i = input.item || t.selected(),
|
||||
d = i && i.length == 1 ? t.itemData(i) : undefined;
|
||||
|
||||
if (!d || d.label == 'template0')
|
||||
return false;
|
||||
|
||||
connect_to_database(obj, d, t, i, true);
|
||||
if (d && d.label != 'template0') {
|
||||
connect_to_database(obj, d, t, i, true);
|
||||
}
|
||||
return false;
|
||||
},
|
||||
/* Disconnect the database */
|
||||
@ -186,54 +185,53 @@ define('pgadmin.node.database', [
|
||||
i = input.item || t.selected(),
|
||||
d = i && i.length == 1 ? t.itemData(i) : undefined;
|
||||
|
||||
if (!d)
|
||||
return false;
|
||||
|
||||
Alertify.confirm(
|
||||
gettext('Disconnect the database'),
|
||||
gettext('Are you sure you want to disconnect the database - %s?', d.label),
|
||||
function() {
|
||||
var data = d;
|
||||
$.ajax({
|
||||
url: obj.generate_url(i, 'connect', d, true),
|
||||
type:'DELETE',
|
||||
})
|
||||
.done(function(res) {
|
||||
if (res.success == 1) {
|
||||
var prv_i = t.parent(i);
|
||||
if(res.data.info_prefix) {
|
||||
res.info = `${_.escape(res.data.info_prefix)} - ${res.info}`;
|
||||
}
|
||||
Alertify.success(res.info);
|
||||
t.removeIcon(i);
|
||||
data.connected = false;
|
||||
data.icon = 'icon-database-not-connected';
|
||||
t.addIcon(i, {icon: data.icon});
|
||||
t.unload(i);
|
||||
t.setInode(i);
|
||||
setTimeout(function() {
|
||||
t.select(prv_i);
|
||||
}, 10);
|
||||
|
||||
} else {
|
||||
try {
|
||||
Alertify.error(res.errormsg);
|
||||
} catch (e) {
|
||||
console.warn(e.stack || e);
|
||||
}
|
||||
t.unload(i);
|
||||
}
|
||||
if (d) {
|
||||
Alertify.confirm(
|
||||
gettext('Disconnect the database'),
|
||||
gettext('Are you sure you want to disconnect the database - %s?', d.label),
|
||||
function() {
|
||||
var data = d;
|
||||
$.ajax({
|
||||
url: obj.generate_url(i, 'connect', d, true),
|
||||
type:'DELETE',
|
||||
})
|
||||
.fail(function(xhr, status, error) {
|
||||
Alertify.pgRespErrorNotify(xhr, error);
|
||||
t.unload(i);
|
||||
});
|
||||
},
|
||||
function() { return true; }
|
||||
).set('labels', {
|
||||
ok: gettext('Yes'),
|
||||
cancel: gettext('No'),
|
||||
});
|
||||
.done(function(res) {
|
||||
if (res.success == 1) {
|
||||
var prv_i = t.parent(i);
|
||||
if(res.data.info_prefix) {
|
||||
res.info = `${_.escape(res.data.info_prefix)} - ${res.info}`;
|
||||
}
|
||||
Alertify.success(res.info);
|
||||
t.removeIcon(i);
|
||||
data.connected = false;
|
||||
data.icon = 'icon-database-not-connected';
|
||||
t.addIcon(i, {icon: data.icon});
|
||||
t.unload(i);
|
||||
t.setInode(i);
|
||||
setTimeout(function() {
|
||||
t.select(prv_i);
|
||||
}, 10);
|
||||
|
||||
} else {
|
||||
try {
|
||||
Alertify.error(res.errormsg);
|
||||
} catch (e) {
|
||||
console.warn(e.stack || e);
|
||||
}
|
||||
t.unload(i);
|
||||
}
|
||||
})
|
||||
.fail(function(xhr, status, error) {
|
||||
Alertify.pgRespErrorNotify(xhr, error);
|
||||
t.unload(i);
|
||||
});
|
||||
},
|
||||
function() { return true; }
|
||||
).set('labels', {
|
||||
ok: gettext('Yes'),
|
||||
cancel: gettext('No'),
|
||||
});
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
|
@ -177,20 +177,19 @@ define('pgadmin.node.pga_job', [
|
||||
i = input.item || t.selected(),
|
||||
d = i && i.length == 1 ? t.itemData(i) : undefined;
|
||||
|
||||
if (!d)
|
||||
return false;
|
||||
|
||||
$.ajax({
|
||||
url: obj.generate_url(i, 'run_now', d, true),
|
||||
method:'PUT',
|
||||
})
|
||||
// 'pgagent.pga_job' table updated with current time to run the job
|
||||
// now.
|
||||
.done(function() { t.unload(i); })
|
||||
.fail(function(xhr, status, error) {
|
||||
alertify.pgRespErrorNotify(xhr, error);
|
||||
t.unload(i);
|
||||
});
|
||||
if (d) {
|
||||
$.ajax({
|
||||
url: obj.generate_url(i, 'run_now', d, true),
|
||||
method:'PUT',
|
||||
})
|
||||
// 'pgagent.pga_job' table updated with current time to run the job
|
||||
// now.
|
||||
.done(function() { t.unload(i); })
|
||||
.fail(function(xhr, status, error) {
|
||||
alertify.pgRespErrorNotify(xhr, error);
|
||||
t.unload(i);
|
||||
});
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
|
@ -199,10 +199,9 @@ define('pgadmin.node.server', [
|
||||
i = input.item || t.selected(),
|
||||
d = i && i.length == 1 ? t.itemData(i) : undefined;
|
||||
|
||||
if (!d)
|
||||
return false;
|
||||
|
||||
connect_to_server(obj, d, t, i, false);
|
||||
if (d) {
|
||||
connect_to_server(obj, d, t, i, false);
|
||||
}
|
||||
return false;
|
||||
},
|
||||
/* Disconnect the server */
|
||||
@ -213,59 +212,58 @@ define('pgadmin.node.server', [
|
||||
i = 'item' in input ? input.item : t.selected(),
|
||||
d = i && i.length == 1 ? t.itemData(i) : undefined;
|
||||
|
||||
if (!d)
|
||||
return false;
|
||||
if (d) {
|
||||
notify = notify || _.isUndefined(notify) || _.isNull(notify);
|
||||
|
||||
notify = notify || _.isUndefined(notify) || _.isNull(notify);
|
||||
|
||||
var disconnect = function() {
|
||||
$.ajax({
|
||||
url: obj.generate_url(i, 'connect', d, true),
|
||||
type:'DELETE',
|
||||
})
|
||||
.done(function(res) {
|
||||
if (res.success == 1) {
|
||||
Alertify.success(res.info);
|
||||
d = t.itemData(i);
|
||||
t.removeIcon(i);
|
||||
d.connected = false;
|
||||
d.icon = 'icon-server-not-connected';
|
||||
t.addIcon(i, {icon: d.icon});
|
||||
obj.callbacks.refresh.apply(obj, [null, i]);
|
||||
if (pgBrowser.serverInfo && d._id in pgBrowser.serverInfo) {
|
||||
delete pgBrowser.serverInfo[d._id];
|
||||
}
|
||||
pgBrowser.enable_disable_menus(i);
|
||||
// Trigger server disconnect event
|
||||
pgBrowser.Events.trigger(
|
||||
'pgadmin:server:disconnect',
|
||||
{item: i, data: d}, false
|
||||
);
|
||||
}
|
||||
else {
|
||||
try {
|
||||
Alertify.error(res.errormsg);
|
||||
} catch (e) {
|
||||
console.warn(e.stack || e);
|
||||
}
|
||||
t.unload(i);
|
||||
}
|
||||
var disconnect = function() {
|
||||
$.ajax({
|
||||
url: obj.generate_url(i, 'connect', d, true),
|
||||
type:'DELETE',
|
||||
})
|
||||
.fail(function(xhr, status, error) {
|
||||
Alertify.pgRespErrorNotify(xhr, error);
|
||||
t.unload(i);
|
||||
});
|
||||
};
|
||||
.done(function(res) {
|
||||
if (res.success == 1) {
|
||||
Alertify.success(res.info);
|
||||
d = t.itemData(i);
|
||||
t.removeIcon(i);
|
||||
d.connected = false;
|
||||
d.icon = 'icon-server-not-connected';
|
||||
t.addIcon(i, {icon: d.icon});
|
||||
obj.callbacks.refresh.apply(obj, [null, i]);
|
||||
if (pgBrowser.serverInfo && d._id in pgBrowser.serverInfo) {
|
||||
delete pgBrowser.serverInfo[d._id];
|
||||
}
|
||||
pgBrowser.enable_disable_menus(i);
|
||||
// Trigger server disconnect event
|
||||
pgBrowser.Events.trigger(
|
||||
'pgadmin:server:disconnect',
|
||||
{item: i, data: d}, false
|
||||
);
|
||||
}
|
||||
else {
|
||||
try {
|
||||
Alertify.error(res.errormsg);
|
||||
} catch (e) {
|
||||
console.warn(e.stack || e);
|
||||
}
|
||||
t.unload(i);
|
||||
}
|
||||
})
|
||||
.fail(function(xhr, status, error) {
|
||||
Alertify.pgRespErrorNotify(xhr, error);
|
||||
t.unload(i);
|
||||
});
|
||||
};
|
||||
|
||||
if (notify) {
|
||||
Alertify.confirm(
|
||||
gettext('Disconnect server'),
|
||||
gettext('Are you sure you want to disconnect the server %s?', d.label),
|
||||
function() { disconnect(); },
|
||||
function() { return true;}
|
||||
);
|
||||
} else {
|
||||
disconnect();
|
||||
if (notify) {
|
||||
Alertify.confirm(
|
||||
gettext('Disconnect server'),
|
||||
gettext('Are you sure you want to disconnect the server %s?', d.label),
|
||||
function() { disconnect(); },
|
||||
function() { return true;}
|
||||
);
|
||||
} else {
|
||||
disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -306,32 +304,31 @@ define('pgadmin.node.server', [
|
||||
i = input.item || t.selected(),
|
||||
d = i && i.length == 1 ? t.itemData(i) : undefined;
|
||||
|
||||
if (!d)
|
||||
return false;
|
||||
|
||||
Alertify.confirm(
|
||||
gettext('Reload server configuration'),
|
||||
gettext('Are you sure you want to reload the server configuration on %s?', d.label),
|
||||
function() {
|
||||
$.ajax({
|
||||
url: obj.generate_url(i, 'reload', d, true),
|
||||
method:'GET',
|
||||
})
|
||||
.done(function(res) {
|
||||
if (res.data.status) {
|
||||
Alertify.success(res.data.result);
|
||||
}
|
||||
else {
|
||||
Alertify.error(res.data.result);
|
||||
}
|
||||
if (d) {
|
||||
Alertify.confirm(
|
||||
gettext('Reload server configuration'),
|
||||
gettext('Are you sure you want to reload the server configuration on %s?', d.label),
|
||||
function() {
|
||||
$.ajax({
|
||||
url: obj.generate_url(i, 'reload', d, true),
|
||||
method:'GET',
|
||||
})
|
||||
.fail(function(xhr, status, error) {
|
||||
Alertify.pgRespErrorNotify(xhr, error);
|
||||
t.unload(i);
|
||||
});
|
||||
},
|
||||
function() { return true; }
|
||||
);
|
||||
.done(function(res) {
|
||||
if (res.data.status) {
|
||||
Alertify.success(res.data.result);
|
||||
}
|
||||
else {
|
||||
Alertify.error(res.data.result);
|
||||
}
|
||||
})
|
||||
.fail(function(xhr, status, error) {
|
||||
Alertify.pgRespErrorNotify(xhr, error);
|
||||
t.unload(i);
|
||||
});
|
||||
},
|
||||
function() { return true; }
|
||||
);
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
@ -387,174 +384,173 @@ define('pgadmin.node.server', [
|
||||
is_pgpass_file_used = false,
|
||||
check_pgpass_url = obj.generate_url(i, 'check_pgpass', d, true);
|
||||
|
||||
if (!d)
|
||||
return false;
|
||||
|
||||
if(!Alertify.changeServerPassword) {
|
||||
var newPasswordModel = Backbone.Model.extend({
|
||||
defaults: {
|
||||
user_name: undefined,
|
||||
password: undefined,
|
||||
newPassword: undefined,
|
||||
confirmPassword: undefined,
|
||||
},
|
||||
validate: function() {
|
||||
return null;
|
||||
},
|
||||
}),
|
||||
passwordChangeFields = [{
|
||||
name: 'user_name', label: gettext('User'),
|
||||
type: 'text', readonly: true, control: 'input',
|
||||
},{
|
||||
name: 'password', label: gettext('Current Password'),
|
||||
type: 'password', disabled: function() { return is_pgpass_file_used; },
|
||||
control: 'input', required: true,
|
||||
},{
|
||||
name: 'newPassword', label: gettext('New Password'),
|
||||
type: 'password', disabled: false, control: 'input',
|
||||
required: true,
|
||||
},{
|
||||
name: 'confirmPassword', label: gettext('Confirm Password'),
|
||||
type: 'password', disabled: false, control: 'input',
|
||||
required: true,
|
||||
}];
|
||||
if (d) {
|
||||
if(!Alertify.changeServerPassword) {
|
||||
var newPasswordModel = Backbone.Model.extend({
|
||||
defaults: {
|
||||
user_name: undefined,
|
||||
password: undefined,
|
||||
newPassword: undefined,
|
||||
confirmPassword: undefined,
|
||||
},
|
||||
validate: function() {
|
||||
return null;
|
||||
},
|
||||
}),
|
||||
passwordChangeFields = [{
|
||||
name: 'user_name', label: gettext('User'),
|
||||
type: 'text', readonly: true, control: 'input',
|
||||
},{
|
||||
name: 'password', label: gettext('Current Password'),
|
||||
type: 'password', disabled: function() { return is_pgpass_file_used; },
|
||||
control: 'input', required: true,
|
||||
},{
|
||||
name: 'newPassword', label: gettext('New Password'),
|
||||
type: 'password', disabled: false, control: 'input',
|
||||
required: true,
|
||||
},{
|
||||
name: 'confirmPassword', label: gettext('Confirm Password'),
|
||||
type: 'password', disabled: false, control: 'input',
|
||||
required: true,
|
||||
}];
|
||||
|
||||
|
||||
Alertify.dialog('changeServerPassword' ,function factory() {
|
||||
return {
|
||||
main: function(params) {
|
||||
var title = gettext('Change Password');
|
||||
this.set('title', title);
|
||||
this.user_name = params.user.name;
|
||||
},
|
||||
setup:function() {
|
||||
return {
|
||||
buttons: [{
|
||||
text: gettext('Cancel'), key: 27,
|
||||
className: 'btn btn-secondary fa fa-times pg-alertify-button', attrs: {name: 'cancel'},
|
||||
},{
|
||||
text: gettext('OK'), key: 13, className: 'btn btn-primary fa fa-check pg-alertify-button',
|
||||
attrs: {name:'submit'},
|
||||
}],
|
||||
// Set options for dialog
|
||||
options: {
|
||||
padding : !1,
|
||||
overflow: !1,
|
||||
modal:false,
|
||||
resizable: true,
|
||||
maximizable: true,
|
||||
pinnable: false,
|
||||
closableByDimmer: false,
|
||||
Alertify.dialog('changeServerPassword' ,function factory() {
|
||||
return {
|
||||
main: function(params) {
|
||||
var title = gettext('Change Password');
|
||||
this.set('title', title);
|
||||
this.user_name = params.user.name;
|
||||
},
|
||||
setup:function() {
|
||||
return {
|
||||
buttons: [{
|
||||
text: gettext('Cancel'), key: 27,
|
||||
className: 'btn btn-secondary fa fa-times pg-alertify-button', attrs: {name: 'cancel'},
|
||||
},{
|
||||
text: gettext('OK'), key: 13, className: 'btn btn-primary fa fa-check pg-alertify-button',
|
||||
attrs: {name:'submit'},
|
||||
}],
|
||||
// Set options for dialog
|
||||
options: {
|
||||
padding : !1,
|
||||
overflow: !1,
|
||||
modal:false,
|
||||
resizable: true,
|
||||
maximizable: true,
|
||||
pinnable: false,
|
||||
closableByDimmer: false,
|
||||
},
|
||||
};
|
||||
},
|
||||
hooks: {
|
||||
// triggered when the dialog is closed
|
||||
onclose: function() {
|
||||
if (this.view) {
|
||||
this.view.remove({data: true, internal: true, silent: true});
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
hooks: {
|
||||
// triggered when the dialog is closed
|
||||
onclose: function() {
|
||||
if (this.view) {
|
||||
this.view.remove({data: true, internal: true, silent: true});
|
||||
},
|
||||
prepare: function() {
|
||||
var self = this;
|
||||
// Disable Ok button until user provides input
|
||||
this.__internal.buttons[1].element.disabled = true;
|
||||
|
||||
var $container = $('<div class=\'change_password\'></div>'),
|
||||
newpasswordmodel = new newPasswordModel(
|
||||
{'user_name': self.user_name}
|
||||
),
|
||||
view = this.view = new Backform.Form({
|
||||
el: $container,
|
||||
model: newpasswordmodel,
|
||||
fields: passwordChangeFields,
|
||||
});
|
||||
|
||||
view.render();
|
||||
|
||||
this.elements.content.appendChild($container.get(0));
|
||||
|
||||
// Listen to model & if filename is provided then enable Backup button
|
||||
this.view.model.on('change', function() {
|
||||
var that = this,
|
||||
password = this.get('password'),
|
||||
newPassword = this.get('newPassword'),
|
||||
confirmPassword = this.get('confirmPassword');
|
||||
|
||||
// Only check password field if pgpass file is not available
|
||||
if ((!is_pgpass_file_used &&
|
||||
(_.isUndefined(password) || _.isNull(password) || password == '')) ||
|
||||
_.isUndefined(newPassword) || _.isNull(newPassword) || newPassword == '' ||
|
||||
_.isUndefined(confirmPassword) || _.isNull(confirmPassword) || confirmPassword == '') {
|
||||
self.__internal.buttons[1].element.disabled = true;
|
||||
} else if (newPassword != confirmPassword) {
|
||||
self.__internal.buttons[1].element.disabled = true;
|
||||
|
||||
this.errorTimeout && clearTimeout(this.errorTimeout);
|
||||
this.errorTimeout = setTimeout(function() {
|
||||
that.errorModel.set('confirmPassword', gettext('Passwords do not match.'));
|
||||
} ,400);
|
||||
}else {
|
||||
that.errorModel.clear();
|
||||
self.__internal.buttons[1].element.disabled = false;
|
||||
}
|
||||
});
|
||||
},
|
||||
// Callback functions when click on the buttons of the Alertify dialogs
|
||||
callback: function(e) {
|
||||
if (e.button.element.name == 'submit') {
|
||||
var self = this,
|
||||
alertArgs = this.view.model.toJSON();
|
||||
|
||||
e.cancel = true;
|
||||
|
||||
$.ajax({
|
||||
url: url,
|
||||
method:'POST',
|
||||
data:{'data': JSON.stringify(alertArgs) },
|
||||
})
|
||||
.done(function(res) {
|
||||
if (res.success) {
|
||||
// Notify user to update pgpass file
|
||||
if(is_pgpass_file_used) {
|
||||
Alertify.alert(
|
||||
gettext('Change Password'),
|
||||
gettext('Please make sure to disconnect the server'
|
||||
+ ' and update the new password in the pgpass file'
|
||||
+ ' before performing any other operation')
|
||||
);
|
||||
}
|
||||
|
||||
Alertify.success(res.info);
|
||||
self.close();
|
||||
} else {
|
||||
Alertify.error(res.errormsg);
|
||||
}
|
||||
})
|
||||
.fail(function(xhr, status, error) {
|
||||
Alertify.pgRespErrorNotify(xhr, error);
|
||||
});
|
||||
}
|
||||
},
|
||||
},
|
||||
prepare: function() {
|
||||
var self = this;
|
||||
// Disable Ok button until user provides input
|
||||
this.__internal.buttons[1].element.disabled = true;
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
var $container = $('<div class=\'change_password\'></div>'),
|
||||
newpasswordmodel = new newPasswordModel(
|
||||
{'user_name': self.user_name}
|
||||
),
|
||||
view = this.view = new Backform.Form({
|
||||
el: $container,
|
||||
model: newpasswordmodel,
|
||||
fields: passwordChangeFields,
|
||||
});
|
||||
|
||||
view.render();
|
||||
|
||||
this.elements.content.appendChild($container.get(0));
|
||||
|
||||
// Listen to model & if filename is provided then enable Backup button
|
||||
this.view.model.on('change', function() {
|
||||
var that = this,
|
||||
password = this.get('password'),
|
||||
newPassword = this.get('newPassword'),
|
||||
confirmPassword = this.get('confirmPassword');
|
||||
|
||||
// Only check password field if pgpass file is not available
|
||||
if ((!is_pgpass_file_used &&
|
||||
(_.isUndefined(password) || _.isNull(password) || password == '')) ||
|
||||
_.isUndefined(newPassword) || _.isNull(newPassword) || newPassword == '' ||
|
||||
_.isUndefined(confirmPassword) || _.isNull(confirmPassword) || confirmPassword == '') {
|
||||
self.__internal.buttons[1].element.disabled = true;
|
||||
} else if (newPassword != confirmPassword) {
|
||||
self.__internal.buttons[1].element.disabled = true;
|
||||
|
||||
this.errorTimeout && clearTimeout(this.errorTimeout);
|
||||
this.errorTimeout = setTimeout(function() {
|
||||
that.errorModel.set('confirmPassword', gettext('Passwords do not match.'));
|
||||
} ,400);
|
||||
}else {
|
||||
that.errorModel.clear();
|
||||
self.__internal.buttons[1].element.disabled = false;
|
||||
}
|
||||
});
|
||||
},
|
||||
// Callback functions when click on the buttons of the Alertify dialogs
|
||||
callback: function(e) {
|
||||
if (e.button.element.name == 'submit') {
|
||||
var self = this,
|
||||
alertArgs = this.view.model.toJSON();
|
||||
|
||||
e.cancel = true;
|
||||
|
||||
$.ajax({
|
||||
url: url,
|
||||
method:'POST',
|
||||
data:{'data': JSON.stringify(alertArgs) },
|
||||
})
|
||||
.done(function(res) {
|
||||
if (res.success) {
|
||||
// Notify user to update pgpass file
|
||||
if(is_pgpass_file_used) {
|
||||
Alertify.alert(
|
||||
gettext('Change Password'),
|
||||
gettext('Please make sure to disconnect the server'
|
||||
+ ' and update the new password in the pgpass file'
|
||||
+ ' before performing any other operation')
|
||||
);
|
||||
}
|
||||
|
||||
Alertify.success(res.info);
|
||||
self.close();
|
||||
} else {
|
||||
Alertify.error(res.errormsg);
|
||||
}
|
||||
})
|
||||
.fail(function(xhr, status, error) {
|
||||
Alertify.pgRespErrorNotify(xhr, error);
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
// Call to check if server is using pgpass file or not
|
||||
$.ajax({
|
||||
url: check_pgpass_url,
|
||||
method:'GET',
|
||||
})
|
||||
.done(function(res) {
|
||||
if (res.success && res.data.is_pgpass) {
|
||||
is_pgpass_file_used = true;
|
||||
}
|
||||
Alertify.changeServerPassword(d).resizeTo('40%','52%');
|
||||
// Call to check if server is using pgpass file or not
|
||||
$.ajax({
|
||||
url: check_pgpass_url,
|
||||
method:'GET',
|
||||
})
|
||||
.fail(function(xhr, status, error) {
|
||||
Alertify.pgRespErrorNotify(xhr, error);
|
||||
});
|
||||
.done(function(res) {
|
||||
if (res.success && res.data.is_pgpass) {
|
||||
is_pgpass_file_used = true;
|
||||
}
|
||||
Alertify.changeServerPassword(d).resizeTo('40%','52%');
|
||||
})
|
||||
.fail(function(xhr, status, error) {
|
||||
Alertify.pgRespErrorNotify(xhr, error);
|
||||
});
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
@ -637,32 +633,31 @@ define('pgadmin.node.server', [
|
||||
i = input.item || t.selected(),
|
||||
d = i && i.length == 1 ? t.itemData(i) : undefined;
|
||||
|
||||
if (!d)
|
||||
return false;
|
||||
|
||||
Alertify.confirm(
|
||||
gettext('Clear saved password'),
|
||||
gettext('Are you sure you want to clear the saved password for server %s?', d.label),
|
||||
function() {
|
||||
$.ajax({
|
||||
url: obj.generate_url(i, 'clear_saved_password', d, true),
|
||||
method:'PUT',
|
||||
})
|
||||
.done(function(res) {
|
||||
if (res.success == 1) {
|
||||
Alertify.success(res.info);
|
||||
t.itemData(i).is_password_saved=res.data.is_password_saved;
|
||||
}
|
||||
else {
|
||||
Alertify.error(res.info);
|
||||
}
|
||||
if (d) {
|
||||
Alertify.confirm(
|
||||
gettext('Clear saved password'),
|
||||
gettext('Are you sure you want to clear the saved password for server %s?', d.label),
|
||||
function() {
|
||||
$.ajax({
|
||||
url: obj.generate_url(i, 'clear_saved_password', d, true),
|
||||
method:'PUT',
|
||||
})
|
||||
.fail(function(xhr, status, error) {
|
||||
Alertify.pgRespErrorNotify(xhr, error);
|
||||
});
|
||||
},
|
||||
function() { return true; }
|
||||
);
|
||||
.done(function(res) {
|
||||
if (res.success == 1) {
|
||||
Alertify.success(res.info);
|
||||
t.itemData(i).is_password_saved=res.data.is_password_saved;
|
||||
}
|
||||
else {
|
||||
Alertify.error(res.info);
|
||||
}
|
||||
})
|
||||
.fail(function(xhr, status, error) {
|
||||
Alertify.pgRespErrorNotify(xhr, error);
|
||||
});
|
||||
},
|
||||
function() { return true; }
|
||||
);
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
@ -675,32 +670,31 @@ define('pgadmin.node.server', [
|
||||
i = input.item || t.selected(),
|
||||
d = i && i.length == 1 ? t.itemData(i) : undefined;
|
||||
|
||||
if (!d)
|
||||
return false;
|
||||
|
||||
Alertify.confirm(
|
||||
gettext('Clear SSH Tunnel password'),
|
||||
gettext('Are you sure you want to clear the saved password of SSH Tunnel for server %s?', d.label),
|
||||
function() {
|
||||
$.ajax({
|
||||
url: obj.generate_url(i, 'clear_sshtunnel_password', d, true),
|
||||
method:'PUT',
|
||||
})
|
||||
.done(function(res) {
|
||||
if (res.success == 1) {
|
||||
Alertify.success(res.info);
|
||||
t.itemData(i).is_tunnel_password_saved=res.data.is_tunnel_password_saved;
|
||||
}
|
||||
else {
|
||||
Alertify.error(res.info);
|
||||
}
|
||||
if (d) {
|
||||
Alertify.confirm(
|
||||
gettext('Clear SSH Tunnel password'),
|
||||
gettext('Are you sure you want to clear the saved password of SSH Tunnel for server %s?', d.label),
|
||||
function() {
|
||||
$.ajax({
|
||||
url: obj.generate_url(i, 'clear_sshtunnel_password', d, true),
|
||||
method:'PUT',
|
||||
})
|
||||
.fail(function(xhr, status, error) {
|
||||
Alertify.pgRespErrorNotify(xhr, error);
|
||||
});
|
||||
},
|
||||
function() { return true; }
|
||||
);
|
||||
.done(function(res) {
|
||||
if (res.success == 1) {
|
||||
Alertify.success(res.info);
|
||||
t.itemData(i).is_tunnel_password_saved=res.data.is_tunnel_password_saved;
|
||||
}
|
||||
else {
|
||||
Alertify.error(res.info);
|
||||
}
|
||||
})
|
||||
.fail(function(xhr, status, error) {
|
||||
Alertify.pgRespErrorNotify(xhr, error);
|
||||
});
|
||||
},
|
||||
function() { return true; }
|
||||
);
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
|
@ -31,7 +31,6 @@ define('pgadmin.browser', [
|
||||
// Generally the one, which do no have AMD support.
|
||||
var wcDocker = window.wcDocker;
|
||||
$ = $ || window.jQuery || window.$;
|
||||
Bootstrap = Bootstrap || window.Bootstrap;
|
||||
var CodeMirror = codemirror.default;
|
||||
|
||||
var pgBrowser = pgAdmin.Browser = pgAdmin.Browser || {};
|
||||
|
@ -154,7 +154,6 @@ define([
|
||||
|
||||
if (_.isUndefined(options) || _.isNull(options)) {
|
||||
options = attributes || {};
|
||||
attributes = null;
|
||||
}
|
||||
|
||||
self.sessAttrs = {};
|
||||
@ -1029,129 +1028,125 @@ define([
|
||||
return (_.findIndex(this.sessAttrs[type], comparator));
|
||||
},
|
||||
onModelAdd: function(obj) {
|
||||
if (!this.trackChanges)
|
||||
return true;
|
||||
if (this.trackChanges) {
|
||||
var self = this,
|
||||
msg,
|
||||
idx = self.objFindInSession(obj, 'deleted');
|
||||
|
||||
var self = this,
|
||||
msg,
|
||||
idx = self.objFindInSession(obj, 'deleted');
|
||||
// Hmm.. - it was originally deleted from this collection, we should
|
||||
// remove it from the 'deleted' list.
|
||||
if (idx >= 0) {
|
||||
var origObj = self.sessAttrs['deleted'][idx];
|
||||
|
||||
// Hmm.. - it was originally deleted from this collection, we should
|
||||
// remove it from the 'deleted' list.
|
||||
if (idx >= 0) {
|
||||
var origObj = self.sessAttrs['deleted'][idx];
|
||||
obj.origSessAttrs = _.clone(origObj.origSessAttrs);
|
||||
obj.attributes = _.extend(obj.attributes, origObj.attributes);
|
||||
obj.sessAttrs = _.clone(origObj.sessAttrs);
|
||||
|
||||
obj.origSessAttrs = _.clone(origObj.origSessAttrs);
|
||||
obj.attributes = _.extend(obj.attributes, origObj.attributes);
|
||||
obj.sessAttrs = _.clone(origObj.sessAttrs);
|
||||
self.sessAttrs['deleted'].splice(idx, 1);
|
||||
|
||||
self.sessAttrs['deleted'].splice(idx, 1);
|
||||
|
||||
// It has been changed originally!
|
||||
if ((!('sessChanged' in obj)) || obj.sessChanged()) {
|
||||
self.sessAttrs['changed'].push(obj);
|
||||
}
|
||||
|
||||
(self.handler || self).trigger('pgadmin-session:added', self, obj);
|
||||
|
||||
|
||||
if ('default_validate' in obj && typeof(obj.default_validate) == 'function') {
|
||||
msg = obj.default_validate();
|
||||
}
|
||||
|
||||
if (_.isString(msg)) {
|
||||
(self.sessAttrs['invalid'])[obj.cid] = msg;
|
||||
} else if ('validate' in obj && typeof(obj.validate) === 'function') {
|
||||
msg = obj.validate();
|
||||
|
||||
if (msg) {
|
||||
(self.sessAttrs['invalid'])[obj.cid] = msg;
|
||||
// It has been changed originally!
|
||||
if ((!('sessChanged' in obj)) || obj.sessChanged()) {
|
||||
self.sessAttrs['changed'].push(obj);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
if ('default_validate' in obj && typeof(obj.default_validate) == 'function') {
|
||||
msg = obj.default_validate();
|
||||
}
|
||||
(self.handler || self).trigger('pgadmin-session:added', self, obj);
|
||||
|
||||
if (_.isString(msg)) {
|
||||
(self.sessAttrs['invalid'])[obj.cid] = msg;
|
||||
} else if ('validate' in obj && typeof(obj.validate) === 'function') {
|
||||
msg = obj.validate();
|
||||
|
||||
if (msg) {
|
||||
(self.sessAttrs['invalid'])[obj.cid] = msg;
|
||||
if ('default_validate' in obj && typeof(obj.default_validate) == 'function') {
|
||||
msg = obj.default_validate();
|
||||
}
|
||||
}
|
||||
self.sessAttrs['added'].push(obj);
|
||||
|
||||
/*
|
||||
* Session has been changed
|
||||
*/
|
||||
(self.handler || self).trigger('pgadmin-session:added', self, obj);
|
||||
if (_.isString(msg)) {
|
||||
(self.sessAttrs['invalid'])[obj.cid] = msg;
|
||||
} else if ('validate' in obj && typeof(obj.validate) === 'function') {
|
||||
msg = obj.validate();
|
||||
|
||||
if (msg) {
|
||||
(self.sessAttrs['invalid'])[obj.cid] = msg;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
if ('default_validate' in obj && typeof(obj.default_validate) == 'function') {
|
||||
msg = obj.default_validate();
|
||||
}
|
||||
|
||||
if (_.isString(msg)) {
|
||||
(self.sessAttrs['invalid'])[obj.cid] = msg;
|
||||
} else if ('validate' in obj && typeof(obj.validate) === 'function') {
|
||||
msg = obj.validate();
|
||||
|
||||
if (msg) {
|
||||
(self.sessAttrs['invalid'])[obj.cid] = msg;
|
||||
}
|
||||
}
|
||||
self.sessAttrs['added'].push(obj);
|
||||
|
||||
/*
|
||||
* Session has been changed
|
||||
*/
|
||||
(self.handler || self).trigger('pgadmin-session:added', self, obj);
|
||||
}
|
||||
|
||||
// Let the parent/listener know about my status (valid/invalid).
|
||||
this.triggerValidationEvent.apply(this);
|
||||
}
|
||||
|
||||
// Let the parent/listener know about my status (valid/invalid).
|
||||
this.triggerValidationEvent.apply(this);
|
||||
|
||||
return true;
|
||||
},
|
||||
onModelRemove: function(obj) {
|
||||
if (!this.trackChanges)
|
||||
return true;
|
||||
if (this.trackChanges) {
|
||||
/* Once model is removed from collection clear its errorModel as it's no longer relevant
|
||||
* for us. Otherwise it creates problem in 'clearInvalidSessionIfModelValid' function.
|
||||
*/
|
||||
obj.errorModel.clear();
|
||||
|
||||
/* Once model is removed from collection clear its errorModel as it's no longer relevant
|
||||
* for us. Otherwise it creates problem in 'clearInvalidSessionIfModelValid' function.
|
||||
*/
|
||||
obj.errorModel.clear();
|
||||
var self = this,
|
||||
invalidModels = self.sessAttrs['invalid'],
|
||||
copy = _.clone(obj),
|
||||
idx = self.objFindInSession(obj, 'added');
|
||||
|
||||
var self = this,
|
||||
invalidModels = self.sessAttrs['invalid'],
|
||||
copy = _.clone(obj),
|
||||
idx = self.objFindInSession(obj, 'added');
|
||||
// We need to remove it from the invalid object list first.
|
||||
if (obj.cid in invalidModels) {
|
||||
delete invalidModels[obj.cid];
|
||||
}
|
||||
|
||||
// We need to remove it from the invalid object list first.
|
||||
if (obj.cid in invalidModels) {
|
||||
delete invalidModels[obj.cid];
|
||||
// Hmm - it was newly added, we can safely remove it.
|
||||
if (idx >= 0) {
|
||||
self.sessAttrs['added'].splice(idx, 1);
|
||||
|
||||
(self.handler || self).trigger('pgadmin-session:removed', self, copy);
|
||||
|
||||
self.checkDuplicateWithModel(copy);
|
||||
|
||||
// Let the parent/listener know about my status (valid/invalid).
|
||||
this.triggerValidationEvent.apply(this);
|
||||
} else {
|
||||
// Hmm - it was changed in this session, we should remove it from the
|
||||
// changed models.
|
||||
idx = self.objFindInSession(obj, 'changed');
|
||||
|
||||
if (idx >= 0) {
|
||||
self.sessAttrs['changed'].splice(idx, 1);
|
||||
(self.handler || self).trigger('pgadmin-session:removed', self, copy);
|
||||
} else {
|
||||
(self.handler || self).trigger('pgadmin-session:removed', self, copy);
|
||||
}
|
||||
|
||||
self.sessAttrs['deleted'].push(obj);
|
||||
|
||||
self.checkDuplicateWithModel(obj);
|
||||
|
||||
// Let the parent/listener know about my status (valid/invalid).
|
||||
this.triggerValidationEvent.apply(this);
|
||||
}
|
||||
|
||||
/*
|
||||
* This object has been remove, we need to check (if we still have any
|
||||
* other invalid message pending).
|
||||
*/
|
||||
}
|
||||
|
||||
// Hmm - it was newly added, we can safely remove it.
|
||||
if (idx >= 0) {
|
||||
self.sessAttrs['added'].splice(idx, 1);
|
||||
|
||||
(self.handler || self).trigger('pgadmin-session:removed', self, copy);
|
||||
|
||||
self.checkDuplicateWithModel(copy);
|
||||
|
||||
// Let the parent/listener know about my status (valid/invalid).
|
||||
this.triggerValidationEvent.apply(this);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Hmm - it was changed in this session, we should remove it from the
|
||||
// changed models.
|
||||
idx = self.objFindInSession(obj, 'changed');
|
||||
|
||||
if (idx >= 0) {
|
||||
self.sessAttrs['changed'].splice(idx, 1);
|
||||
(self.handler || self).trigger('pgadmin-session:removed', self, copy);
|
||||
} else {
|
||||
(self.handler || self).trigger('pgadmin-session:removed', self, copy);
|
||||
}
|
||||
|
||||
self.sessAttrs['deleted'].push(obj);
|
||||
|
||||
self.checkDuplicateWithModel(obj);
|
||||
|
||||
// Let the parent/listener know about my status (valid/invalid).
|
||||
this.triggerValidationEvent.apply(this);
|
||||
|
||||
/*
|
||||
* This object has been remove, we need to check (if we still have any
|
||||
* other invalid message pending).
|
||||
*/
|
||||
|
||||
return true;
|
||||
},
|
||||
triggerValidationEvent: function() {
|
||||
@ -1194,52 +1189,39 @@ define([
|
||||
onModelChange: function(obj) {
|
||||
var self = this;
|
||||
|
||||
if (!this.trackChanges || !(obj instanceof pgBrowser.Node.Model))
|
||||
return true;
|
||||
|
||||
var idx = self.objFindInSession(obj, 'added');
|
||||
|
||||
// It was newly added model, we don't need to add into the changed
|
||||
// list.
|
||||
if (idx >= 0) {
|
||||
(self.handler || self).trigger('pgadmin-session:changed', self, obj);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
idx = self.objFindInSession(obj, 'changed');
|
||||
|
||||
if (!('sessChanged' in obj)) {
|
||||
(self.handler || self).trigger('pgadmin-session:changed', self, obj);
|
||||
if (this.trackChanges && obj instanceof pgBrowser.Node.Model) {
|
||||
var idx = self.objFindInSession(obj, 'added');
|
||||
|
||||
// It was newly added model, we don't need to add into the changed
|
||||
// list.
|
||||
if (idx >= 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
self.sessAttrs['changed'].push(obj);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (idx >= 0) {
|
||||
|
||||
if (!obj.sessChanged()) {
|
||||
// This object is no more updated, removing it from the changed
|
||||
// models list.
|
||||
self.sessAttrs['changed'].splice(idx, 1);
|
||||
|
||||
(self.handler || self).trigger('pgadmin-session:changed', self, obj);
|
||||
return true;
|
||||
} else {
|
||||
idx = self.objFindInSession(obj, 'changed');
|
||||
|
||||
if (!('sessChanged' in obj)) {
|
||||
(self.handler || self).trigger('pgadmin-session:changed', self, obj);
|
||||
|
||||
if (idx < 0) {
|
||||
self.sessAttrs['changed'].push(obj);
|
||||
}
|
||||
} else {
|
||||
if (idx >= 0) {
|
||||
if (!obj.sessChanged()) {
|
||||
// This object is no more updated, removing it from the changed
|
||||
// models list.
|
||||
self.sessAttrs['changed'].splice(idx, 1);
|
||||
|
||||
(self.handler || self).trigger('pgadmin-session:changed', self, obj);
|
||||
} else {
|
||||
(self.handler || self).trigger('pgadmin-session:changed', self, obj);
|
||||
}
|
||||
} else if (obj.sessChanged()) {
|
||||
self.sessAttrs['changed'].push(obj);
|
||||
(self.handler || self).trigger('pgadmin-session:changed', self, obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
(self.handler || self).trigger('pgadmin-session:changed', self, obj);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (obj.sessChanged()) {
|
||||
self.sessAttrs['changed'].push(obj);
|
||||
(self.handler || self).trigger('pgadmin-session:changed', self, obj);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -320,7 +320,7 @@ define('pgadmin.preferences', [
|
||||
switch (eventName) {
|
||||
case 'selected':
|
||||
if (!d)
|
||||
return true;
|
||||
break;
|
||||
|
||||
if (d.preferences) {
|
||||
/*
|
||||
@ -330,14 +330,14 @@ define('pgadmin.preferences', [
|
||||
|
||||
renderPreferencePanel(d.preferences);
|
||||
|
||||
return true;
|
||||
break;
|
||||
} else {
|
||||
selectFirstCategory(api, item);
|
||||
}
|
||||
break;
|
||||
case 'added':
|
||||
if (!d)
|
||||
return true;
|
||||
break;
|
||||
|
||||
// We will add the preferences in to the preferences data
|
||||
// collection.
|
||||
|
@ -136,7 +136,6 @@ define([
|
||||
}
|
||||
} catch (e) {
|
||||
// Do nothing
|
||||
options = [];
|
||||
console.warn(e.stack || e);
|
||||
}
|
||||
} else {
|
||||
|
@ -45,15 +45,15 @@ class ObjectRegistry(ABCMeta):
|
||||
|
||||
registry = dict()
|
||||
|
||||
def __init__(cls, name, bases, d):
|
||||
def __init__(self, name, bases, d):
|
||||
"""
|
||||
This method is used to register the objects based on object type.
|
||||
"""
|
||||
|
||||
if d and 'object_type' in d:
|
||||
ObjectRegistry.registry[d['object_type']] = cls
|
||||
ObjectRegistry.registry[d['object_type']] = self
|
||||
|
||||
ABCMeta.__init__(cls, name, bases, d)
|
||||
ABCMeta.__init__(self, name, bases, d)
|
||||
|
||||
@classmethod
|
||||
def get_object(cls, name, **kwargs):
|
||||
|
@ -953,28 +953,31 @@ define([
|
||||
this.$content.find('button.add').first().on('click',(e) => {
|
||||
e.preventDefault();
|
||||
// There should be only one empty row.
|
||||
let anyNew = false;
|
||||
for(const [idx, model] of userCollection.models.entries()) {
|
||||
if(model.isNew()) {
|
||||
let row = view.body.rows[idx].$el;
|
||||
row.addClass('new');
|
||||
$(row).pgMakeVisible('backgrid');
|
||||
$(row).find('.email').trigger('click');
|
||||
return false;
|
||||
anyNew = true;
|
||||
}
|
||||
}
|
||||
|
||||
$(view.body.$el.find($('tr.new'))).removeClass('new');
|
||||
var m = new(UserModel)(null, {
|
||||
handler: userCollection,
|
||||
top: userCollection,
|
||||
collection: userCollection,
|
||||
});
|
||||
userCollection.add(m);
|
||||
if(!anyNew) {
|
||||
$(view.body.$el.find($('tr.new'))).removeClass('new');
|
||||
var m = new(UserModel)(null, {
|
||||
handler: userCollection,
|
||||
top: userCollection,
|
||||
collection: userCollection,
|
||||
});
|
||||
userCollection.add(m);
|
||||
|
||||
var newRow = view.body.rows[userCollection.indexOf(m)].$el;
|
||||
newRow.addClass('new');
|
||||
$(newRow).pgMakeVisible('backgrid');
|
||||
$(newRow).find('.email').trigger('click');
|
||||
var newRow = view.body.rows[userCollection.indexOf(m)].$el;
|
||||
newRow.addClass('new');
|
||||
$(newRow).pgMakeVisible('backgrid');
|
||||
$(newRow).find('.email').trigger('click');
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
|
@ -120,7 +120,7 @@ class Driver(BaseDriver):
|
||||
|
||||
return managers[str(sid)]
|
||||
|
||||
def version(cls):
|
||||
def version(self):
|
||||
"""
|
||||
version(...)
|
||||
|
||||
@ -135,7 +135,7 @@ class Driver(BaseDriver):
|
||||
"Driver Version information for psycopg2 is not available!"
|
||||
)
|
||||
|
||||
def libpq_version(cls):
|
||||
def libpq_version(self):
|
||||
"""
|
||||
Returns the loaded libpq version
|
||||
"""
|
||||
|
@ -50,15 +50,15 @@ class DriverRegistry(ABCMeta):
|
||||
registry = None
|
||||
drivers = dict()
|
||||
|
||||
def __init__(cls, name, bases, d):
|
||||
def __init__(self, name, bases, d):
|
||||
|
||||
# Register this type of driver, based on the module name
|
||||
# Avoid registering the BaseDriver itself
|
||||
|
||||
if name != 'BaseDriver':
|
||||
DriverRegistry.registry[_decorate_cls_name(d['__module__'])] = cls
|
||||
DriverRegistry.registry[_decorate_cls_name(d['__module__'])] = self
|
||||
|
||||
ABCMeta.__init__(cls, name, bases, d)
|
||||
ABCMeta.__init__(self, name, bases, d)
|
||||
|
||||
@classmethod
|
||||
def create(cls, name, **kwargs):
|
||||
|
@ -42,7 +42,7 @@ class TestsGeneratorRegistry(ABCMeta):
|
||||
|
||||
registry = dict()
|
||||
|
||||
def __init__(cls, name, bases, d):
|
||||
def __init__(self, name, bases, d):
|
||||
|
||||
# Register this type of module, based on the module name
|
||||
# Avoid registering the BaseDriver itself
|
||||
@ -51,11 +51,11 @@ class TestsGeneratorRegistry(ABCMeta):
|
||||
# Store/append test classes in 'registry' if test modules has
|
||||
# multiple classes
|
||||
if d['__module__'] in TestsGeneratorRegistry.registry:
|
||||
TestsGeneratorRegistry.registry[d['__module__']].append(cls)
|
||||
TestsGeneratorRegistry.registry[d['__module__']].append(self)
|
||||
else:
|
||||
TestsGeneratorRegistry.registry[d['__module__']] = [cls]
|
||||
TestsGeneratorRegistry.registry[d['__module__']] = [self]
|
||||
|
||||
ABCMeta.__init__(cls, name, bases, d)
|
||||
ABCMeta.__init__(self, name, bases, d)
|
||||
|
||||
@classmethod
|
||||
def load_generators(cls, pkg_root, exclude_pkgs, for_modules=[],
|
||||
|
Loading…
Reference in New Issue
Block a user