diff options
Diffstat (limited to 'server/sonar-web/src/main/js/apps/project-admin/deletion/Form.js')
-rw-r--r-- | server/sonar-web/src/main/js/apps/project-admin/deletion/Form.js | 69 |
1 files changed, 61 insertions, 8 deletions
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 81d52fb3ba2..354935418fa 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,24 +18,39 @@ * 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 { translate, translateWithParameters } from '../../../helpers/l10n'; +import { deleteProject } from '../../../api/components'; export default class Form extends React.Component { static propTypes = { component: React.PropTypes.object.isRequired }; + state = { + confirmation: false, + loading: false + }; + handleDelete (e) { e.preventDefault(); - new ConfirmationModal({ project: this.props.component }) - .on('done', () => { - window.location = window.baseUrl + '/'; - }) - .render(); + this.setState({ confirmation: true }); } - render () { + confirmDeleteClick (e) { + e.preventDefault(); + this.setState({ loading: true }); + deleteProject(this.props.component.key).then(() => { + window.location = window.baseUrl + '/'; + }); + } + + cancelDeleteClick (e) { + e.preventDefault(); + e.target.blur(); + this.setState({ confirmation: false }); + } + + renderInitial () { return ( <form onSubmit={this.handleDelete.bind(this)}> <button id="delete-project" className="button-red"> @@ -44,4 +59,42 @@ export default class Form extends React.Component { </form> ); } + + renderConfirmation () { + return ( + <form className="panel panel-warning" + onSubmit={this.confirmDeleteClick.bind(this)}> + <div className="big-spacer-bottom"> + {translateWithParameters( + 'project_deletion.delete_resource_confirmation', + this.props.component.name)} + </div> + + <div> + <button + id="confirm-project-deletion" + className="button-red" + disabled={this.state.loading}> + {translate('delete')} + </button> + + {this.state.loading ? ( + <i className="spinner big-spacer-left"/> + ) : ( + <a href="#" + className="big-spacer-left" + onClick={this.cancelDeleteClick.bind(this)}> + {translate('cancel')} + </a> + )} + </div> + </form> + ); + } + + render () { + return this.state.confirmation ? + this.renderConfirmation() : + this.renderInitial(); + } } |