mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-20 11:48:31 -06:00
122 lines
3.4 KiB
JavaScript
122 lines
3.4 KiB
JavaScript
/////////////////////////////////////////////////////////////
|
|
//
|
|
// pgAdmin 4 - PostgreSQL Tools
|
|
//
|
|
// Copyright (C) 2013 - 2022, The pgAdmin Development Team
|
|
// This software is released under the PostgreSQL Licence
|
|
//
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
import gettext from '../gettext';
|
|
import {DialogFactory} from './dialog_factory';
|
|
import Backform from '../backform.pgadmin';
|
|
|
|
/**
|
|
* This class can be extended to create new dialog boxes.
|
|
* Examples of this can be found in:
|
|
* `web/pgadmin/static/js/backup/backup_dialog.js`
|
|
*
|
|
* Do not forget to add the new Dialog type to the `DialogFactory`
|
|
*/
|
|
export class Dialog {
|
|
constructor(errorAlertTitle,
|
|
dialogContainerSelector,
|
|
pgBrowser, $, alertify, DialogModel,
|
|
backform = Backform) {
|
|
this.errorAlertTitle = errorAlertTitle;
|
|
this.alertify = alertify;
|
|
this.pgBrowser = pgBrowser;
|
|
this.jquery = $;
|
|
this.dialogModel = DialogModel;
|
|
this.backform = backform;
|
|
this.dialogContainerSelector = dialogContainerSelector;
|
|
}
|
|
|
|
retrieveAncestorOfTypeServer(item) {
|
|
let serverInformation = null;
|
|
let treeItem = item || this.pgBrowser.tree.selected();
|
|
let treeNode = this.pgBrowser.tree.findNodeByDomElement(treeItem);
|
|
|
|
if (treeNode) {
|
|
let nodeData;
|
|
let databaseNode = treeNode.ancestorNode(
|
|
(node) => {
|
|
nodeData = node.getData();
|
|
return (nodeData._type === 'database');
|
|
}
|
|
);
|
|
let isServerNode = (node) => {
|
|
nodeData = node.getData();
|
|
return nodeData._type === 'server';
|
|
};
|
|
|
|
if (databaseNode !== null) {
|
|
if (nodeData._label.indexOf('=') >= 0) {
|
|
this.alertify.alert(
|
|
gettext(this.errorAlertTitle),
|
|
gettext(
|
|
'Databases with = symbols in the name cannot be backed up or restored using this utility.'
|
|
)
|
|
);
|
|
} else {
|
|
if (databaseNode.anyParent(isServerNode))
|
|
serverInformation = nodeData;
|
|
}
|
|
} else {
|
|
if (treeNode.anyFamilyMember(isServerNode))
|
|
serverInformation = nodeData;
|
|
}
|
|
}
|
|
|
|
if (serverInformation === null) {
|
|
this.alertify.alert(
|
|
gettext(this.errorAlertTitle),
|
|
gettext('Please select server or child node from the browser tree.')
|
|
);
|
|
}
|
|
|
|
return serverInformation;
|
|
}
|
|
|
|
dialogName() {
|
|
return undefined;
|
|
}
|
|
|
|
createOrGetDialog(dialogTitle, typeOfDialog) {
|
|
const dialogName = this.dialogName(typeOfDialog);
|
|
|
|
if (!this.alertify[dialogName]) {
|
|
const self = this;
|
|
this.alertify.dialog(dialogName, function factory() {
|
|
return self.dialogFactory(dialogTitle, typeOfDialog);
|
|
});
|
|
}
|
|
return this.alertify[dialogName];
|
|
}
|
|
|
|
dialogFactory(dialogTitle, typeOfDialog) {
|
|
const factory = new DialogFactory(
|
|
this.pgBrowser,
|
|
this.jquery,
|
|
this.alertify,
|
|
this.dialogModel,
|
|
this.backform,
|
|
this.dialogContainerSelector);
|
|
return factory.create(dialogTitle, typeOfDialog);
|
|
}
|
|
|
|
canExecuteOnCurrentDatabase(treeItem) {
|
|
const treeInfo = this.pgBrowser.tree.getTreeNodeHierarchy(treeItem);
|
|
|
|
if (treeInfo.database && treeInfo.database._label.indexOf('=') >= 0) {
|
|
this.alertify.alert(
|
|
gettext(this.errorAlertTitle),
|
|
gettext('Databases with = symbols in the name cannot be backed up or restored using this utility.')
|
|
);
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|