<div class="modal fade"
     id="confirm-actions"
     tabindex="-1"
     role="dialog"
     aria-hidden="true"
     style="z-index: 9999">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">×</button>
                <h4 class="modal-title">
                    Confirm <span class="confirm-action-name">action</span>
                </h4>
            </div>
            <form id="confirm-form-action" action="" class="form-horizontal">
                <div class="modal-body">
                    <label for="confirm-action-reason">
                        Please enter a reason for <span class="confirm-action-name"></span> this <span id="confirm-action-object"></span><span id="confirm-action-reason-required" style="display:none;color:red">*</span>
                    </label>
                    <input id="confirm-action-reason" name="reason" class="form-control" type="text" maxlength="200" />
                </div>
                <div class="modal-footer" style="border: none">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
                    <button type="button" class="btn btn-danger" id="confirm-action-button">Confirm</button>
                </div>
            </form>
        </div>
    </div>
</div>
<script>
	function confirm_action(url, reason_required, callback, action, object, confirm)
	{
		let form_action = $("#confirm-form-action");
		let confirm_button = $("#confirm-action-button");
		$("#confirm-action-reason").prop("required", reason_required);
		$("#confirm-action-reason").focus();
		$("#confirm-action-reason-required").toggle(reason_required);
		if (action) $(".confirm-action-name").text(action);
		if (object) $("#confirm-action-object").text(object);
		if (confirm) confirm_button.text(confirm);
		confirm_button.unbind().on("click", function ()
		{
			if (form_action[0].reportValidity())
			{
				let failure_dialog = ajax_failure_callback("There was an error " + action + " this " + object);
				let data = form_action.serialize();
				ajax_post(url, data, [callback, function(){$("#confirm-actions").modal('hide');}], failure_dialog);
			}
		});
	}

	$('#confirm-actions').keypress(function(e)
	{
		if (e.which === 13)
		{
			$("#confirm-action-button").trigger("click");
		}
	});
</script>
