<%--
/**
 * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
 *
 * The contents of this file are subject to the terms of the Liferay Enterprise
 * Subscription License ("License"). You may not use this file except in
 * compliance with the License. You can obtain a copy of the License by
 * contacting Liferay, Inc. See the License for the specific language governing
 * permissions and limitations under the License, including but not limited to
 * distribution rights of the Software.
 *
 *
 *
 */
--%>

<%@ include file="/document_library/init.jsp" %>

<%
DLAccessFromDesktopDisplayContext dlAccessFromDesktopDisplayContext = new DLAccessFromDesktopDisplayContext(request);
%>

<liferay-ui:icon
	cssClass='<%= dlAccessFromDesktopDisplayContext.getRandomNamespace() + "-webdav-action" %>'
	message="access-from-desktop"
	url="javascript:;"
/>

<div id="<%= dlAccessFromDesktopDisplayContext.getRandomNamespace() %>webDav" style="display: none;">
	<div class="portlet-document-library">
		<liferay-ui:message key="<%= dlAccessFromDesktopDisplayContext.getWebDAVHelpMessage() %>" />

		<liferay-learn:message
			key="webdav"
			resource="document-library-web"
		/>

		<br /><br />

		<aui:input cssClass="webdav-url-resource" id='<%= dlAccessFromDesktopDisplayContext.getRandomNamespace() + "webDavURL" %>' name="webDavURL" type="resource" value="<%= dlAccessFromDesktopDisplayContext.getWebDAVURL() %>" />
	</div>
</div>

<aui:script>
	(function () {
		var webdavContentContainer = document.getElementById(
			'<%= dlAccessFromDesktopDisplayContext.getRandomNamespace() %>webDav'
		);

		var html = '';

		if (webdavContentContainer) {
			html = webdavContentContainer.innerHTML;

			webdavContentContainer.remove();
		}

		var webdavActionLink = document.querySelector(
			'.<%= dlAccessFromDesktopDisplayContext.getRandomNamespace() %>-webdav-action'
		);

		if (webdavActionLink) {
			webdavActionLink.addEventListener('click', function (event) {
				event.preventDefault();

				if (webdavContentContainer) {
					Liferay.Util.openModal({
						bodyHTML: html,
						onOpen: function (event) {
							var webdavURLInput = document.getElementById(
								'<portlet:namespace /><%= dlAccessFromDesktopDisplayContext.getRandomNamespace() %>webDavURL'
							);

							if (webdavURLInput) {
								webdavURLInput.focus();
							}
						},
						title:
							'<%= UnicodeLanguageUtil.get(request, "access-from-desktop") %>',
					});
				}
			});
		}
	})();
</aui:script>