UI Improvement: Modal confirmation dialog for deletion actions
This commit is contained in:
parent
f7e396d04c
commit
6c0aed7f28
|
@ -73,7 +73,7 @@ switch($build->getStatus())
|
|||
<span class="caret"></span>
|
||||
</button>
|
||||
<ul class="dropdown-menu">
|
||||
<li><a href="javascript:confirmDeleteBuild('<?= PHPCI_URL ?>build/delete/<?php print $build->getId(); ?>');">Delete Build</a></li>
|
||||
<li><a href="javascript:confirmDelete('<?= PHPCI_URL ?>build/delete/<?php print $build->getId(); ?>', 'Build').onClose = function(){refreshBuildsTable();};">Delete Build</a></li>
|
||||
</ul>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
|
|
@ -92,7 +92,9 @@
|
|||
$(function() {
|
||||
$('#delete-project').on('click', function (e) {
|
||||
e.preventDefault();
|
||||
confirmDelete("<?= PHPCI_URL ?>project/delete/<?php print $project->getId(); ?>");
|
||||
confirmDelete(
|
||||
"<?= PHPCI_URL ?>project/delete/<?php print $project->getId(); ?>", "Project"
|
||||
).onClose = function () {window.location = '/'};
|
||||
});
|
||||
})
|
||||
</script>
|
||||
|
|
|
@ -50,7 +50,7 @@
|
|||
<span class="caret"></span>
|
||||
</button>
|
||||
<ul class="dropdown-menu">
|
||||
<li><a href="javascript:confirmDelete('<?= PHPCI_URL ?>user/delete/<?php print $user->getId(); ?>');">Delete User</a></li>
|
||||
<li><a href="javascript:confirmDelete('<?= PHPCI_URL ?>user/delete/<?php print $user->getId(); ?>', 'User', true);">Delete User</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
|
|
@ -30,25 +30,10 @@ if (!Function.prototype.bind) {
|
|||
/**
|
||||
* Used for delete buttons in the system, just to prevent accidental clicks.
|
||||
*/
|
||||
function confirmDelete(url)
|
||||
{
|
||||
if(confirm('Are you sure you want to delete this?'))
|
||||
{
|
||||
window.location.href = url;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Used for delete build buttons in the system, just to prevent accidental clicks.
|
||||
*/
|
||||
function confirmDeleteBuild(url) {
|
||||
function confirmDelete(url, subject, reloadAfter) {
|
||||
|
||||
var dialog = new PHPCIConfirmDialog({
|
||||
message: 'This build will be permanently deleted. Are you sure?',
|
||||
message: subject + ' will be permanently deleted. Are you sure?',
|
||||
confirmBtnCaption: 'Delete',
|
||||
/*
|
||||
confirm-btn click handler
|
||||
|
@ -62,11 +47,11 @@ function confirmDeleteBuild(url) {
|
|||
*/
|
||||
$.ajax({
|
||||
url: url,
|
||||
'success': function () {
|
||||
if (refreshBuildsTable) {
|
||||
dialog.$dialog.on('hidden.bs.modal', function () {
|
||||
refreshBuildsTable();
|
||||
});
|
||||
'success': function (data) {
|
||||
if (reloadAfter) {
|
||||
dialog.onClose = function () {
|
||||
window.location.reload();
|
||||
};
|
||||
}
|
||||
|
||||
dialog.showStatusMessage('Successfully deleted!', 1000);
|
||||
|
@ -79,6 +64,7 @@ function confirmDeleteBuild(url) {
|
|||
});
|
||||
|
||||
dialog.show();
|
||||
return dialog;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -156,11 +142,14 @@ var PHPCIConfirmDialog = Class.extend({
|
|||
this.confirmBtnClick = options.confirmed;
|
||||
|
||||
/*
|
||||
Re-bind on click handler
|
||||
Re-bind handlers
|
||||
*/
|
||||
this.$confirmBtn.unbind('click');
|
||||
this.$confirmBtn.click(this.onConfirm.bind(this));
|
||||
|
||||
this.$confirmBtn.unbind('hidden.bs.modal');
|
||||
this.$dialog.on('hidden.bs.modal', function () {this.onClose()}.bind(this));
|
||||
|
||||
/*
|
||||
Restore state if was changed previously
|
||||
*/
|
||||
|
@ -187,6 +176,8 @@ var PHPCIConfirmDialog = Class.extend({
|
|||
this.confirmBtnClick(e);
|
||||
},
|
||||
|
||||
onClose: function () {},
|
||||
|
||||
showStatusMessage: function (message, closeTimeout) {
|
||||
this.$confirmBtn.hide();
|
||||
this.$cancelBtn.html('Close');
|
||||
|
|
Loading…
Reference in a new issue