<%--
 * Copyright by Intland Software
 *
 * All rights reserved.
 *
 * This software is the confidential and proprietary information
 * of Intland Software. ("Confidential Information"). You
 * shall not disclose such Confidential Information and shall use
 * it only in accordance with the terms of the license agreement
 * you entered into with Intland.
 *
 * $Revision$ $Date$
--%>

<%@ taglib uri="jstl-c" prefix="c" %>
<%@ taglib uri="jstl-fmt" prefix="fmt" %>

<%--
	jsp fragment used on document-list and report pages to be able to delete one or multiple artifacts (doc/report)
	this mainly contains the javascripts for that, plus a hidden input field contains the artifact ids to select
	Assumes that there is an combo box with id of "actionCombo", which is disabled before form submit.

	parameters:
	param.confirmMessageKey			- the key for multi-delete confirm message
	param.confirmOneMessageKey		- the key for one-delete confirm message
	param.confirmOneDirMessageKey	- optional key when deleting one directory
--%>

<c:set var="confirmMessageKey" value="${param.confirmMessageKey}" />
<c:set var="confirmOneMessageKey" value="${param.confirmOneMessageKey}" />
<c:set var="confirmOneDirMessageKey" value="${param.confirmOneDirMessageKey}" />

<SCRIPT LANGUAGE="JavaScript" type="text/javascript">
<!--
// Hide script from old browsers

// confirm the delete and submit the form if confirmed
// @param form The form to submit
function confirmDelete(form) { // FIXME There is similar function in report/mail.js. Join together?
	var answer = submitIfSelected(form, 'selectedArtifactIds');
	if (answer) {
		var msg = <fmt:message key="${confirmMessageKey}" />;
		showFancyConfirmDialogWithCallbacks(msg, function() {
				disableButtonsAndSubmit(form, "delete");
			});
	}
	return false;
}

function disableButtonsAndSubmit(form, act) {
	// disable action combo
	var actionCombo = document.getElementById("actionCombo");
	actionCombo.disabled = true;
	// pass back the action value
	form.action.value = act;
	form.submit();
	return false;
}
// script for deleting one selected document
// @param artifactId the artifact to delete
// @param artifactName the name of the artifact to delete
// @param isDirectory If the artifact to be deleted is a directory
function deleteOneArtifact(artifactId, artifactName, isDirectory) {
	var msg = <fmt:message key="${confirmOneMessageKey}" />;
	<c:if test="${!empty confirmOneDirMessageKey}">
		if (isDirectory) {
			msg = <fmt:message key="${confirmOneDirMessageKey}" />;
		}
	</c:if>
	msg = msg.replace("{name}", artifactName);
	showFancyConfirmDialogWithCallbacks(msg, function() {
			var url = contextPath + "/proj/doc/documentProperties.do?action=delete&selectedArtifactIds=" + artifactId;
			document.location.href = url;
		});
}
//-->
</script>

