From ad8afa515b0dddeedd6a37e91c6bcda914d1c309 Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Mon, 29 May 2017 10:49:12 +0200 Subject: rework some modals (#2113) --- .../project-admin/deletion/ConfirmationModal.js | 48 ------------ .../deletion/ConfirmationModalTemplate.hbs | 14 ---- .../main/js/apps/project-admin/deletion/Form.js | 91 +++++++++++++++++++--- 3 files changed, 79 insertions(+), 74 deletions(-) delete mode 100644 server/sonar-web/src/main/js/apps/project-admin/deletion/ConfirmationModal.js delete mode 100644 server/sonar-web/src/main/js/apps/project-admin/deletion/ConfirmationModalTemplate.hbs (limited to 'server/sonar-web/src/main/js/apps/project-admin/deletion') diff --git a/server/sonar-web/src/main/js/apps/project-admin/deletion/ConfirmationModal.js b/server/sonar-web/src/main/js/apps/project-admin/deletion/ConfirmationModal.js deleted file mode 100644 index 273850ea38b..00000000000 --- a/server/sonar-web/src/main/js/apps/project-admin/deletion/ConfirmationModal.js +++ /dev/null @@ -1,48 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import ModalForm from '../../../components/common/modal-form'; -import Template from './ConfirmationModalTemplate.hbs'; -import { deleteProject } from '../../../api/components'; - -export default ModalForm.extend({ - template: Template, - - onFormSubmit() { - ModalForm.prototype.onFormSubmit.apply(this, arguments); - this.disableForm(); - this.showSpinner(); - - deleteProject(this.options.project.key) - .then(() => { - this.trigger('done'); - }) - .catch(function(e) { - e.response.json().then(r => { - this.hideSpinner(); - this.showErrors(r.errors, r.warnings); - this.enableForm(); - }); - }); - }, - - serializeData() { - return { project: this.options.project }; - } -}); diff --git a/server/sonar-web/src/main/js/apps/project-admin/deletion/ConfirmationModalTemplate.hbs b/server/sonar-web/src/main/js/apps/project-admin/deletion/ConfirmationModalTemplate.hbs deleted file mode 100644 index 749e408d5bc..00000000000 --- a/server/sonar-web/src/main/js/apps/project-admin/deletion/ConfirmationModalTemplate.hbs +++ /dev/null @@ -1,14 +0,0 @@ -
- - - -
diff --git a/server/sonar-web/src/main/js/apps/project-admin/deletion/Form.js b/server/sonar-web/src/main/js/apps/project-admin/deletion/Form.js index 1a848accaee..ac8ca55598b 100644 --- a/server/sonar-web/src/main/js/apps/project-admin/deletion/Form.js +++ b/server/sonar-web/src/main/js/apps/project-admin/deletion/Form.js @@ -18,30 +18,97 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import React from 'react'; -import ConfirmationModal from './ConfirmationModal'; -import { translate } from '../../../helpers/l10n'; +import Modal from 'react-modal'; +import { deleteProject } from '../../../api/components'; +import { translate, translateWithParameters } from '../../../helpers/l10n'; export default class Form extends React.PureComponent { static propTypes = { component: React.PropTypes.object.isRequired }; - handleDelete(e) { - e.preventDefault(); - new ConfirmationModal({ project: this.props.component }) - .on('done', () => { - window.location = window.baseUrl + '/'; - }) - .render(); + static contextTypes = { + router: React.PropTypes.object + }; + + state = { loading: false, modalOpen: false }; + + componentDidMount() { + this.mounted = true; + } + + componentWillUnmount() { + this.mounted = false; } + handleDeleteClick = event => { + event.preventDefault(); + this.setState({ modalOpen: true }); + }; + + closeModal = () => this.setState({ modalOpen: false }); + + stopLoading = () => { + if (this.mounted) { + this.setState({ loading: false }); + } + }; + + handleSubmit = event => { + event.preventDefault(); + this.setState({ loading: true }); + deleteProject(this.props.component.key) + .then(() => this.context.router.replace('/')) + .catch(this.stopLoading); + }; + + handleCloseClick = (event: Event) => { + event.preventDefault(); + this.closeModal(); + }; + render() { + const { component } = this.props; + return ( -
- -
+ + {this.state.modalOpen && + +
+
+

{translate('qualifiers.delete.TRK')}

+
+
+
+ {translateWithParameters( + 'project_deletion.delete_resource_confirmation', + component.name + )} +
+
+ {this.state.loading && } + + + {translate('cancel')} + +
+ + } +
); } } -- cgit v1.2.3