Instantly share code, notes, and snippets.

Embed
What would you like to do?
<%@page session="false" %><%--
Copyright 1997-2008 Day Management AG
Barfuesserplatz 6, 4001 Basel, Switzerland
All Rights Reserved.
This software is the confidential and proprietary information of
Day Management AG, ("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 Day.
==============================================================================
Tree Activation
Implements the tree activation component.
--%>
<%@ page contentType="text/html"
pageEncoding="utf-8"
import="com.day.cq.wcm.foundation.Image,
com.day.cq.wcm.api.components.DropTarget,
com.day.cq.wcm.api.components.EditConfig,
com.day.cq.wcm.commons.WCMUtils,
com.day.cq.replication.Replicator,
com.day.cq.replication.Agent,
com.day.cq.replication.AgentConfig,
com.adobe.granite.ui.clientlibs.HtmlLibraryManager,
com.day.cq.wcm.api.WCMMode,
com.day.cq.wcm.api.components.Toolbar,
com.day.cq.replication.ReplicationQueue,
com.day.cq.i18n.I18n,
com.day.cq.replication.AgentManager" %>
<%@ page import="java.util.*" %>
<%
%>
<%@include file="/libs/foundation/global.jsp" %>
<%
AgentManager agentMgr = sling.getService(AgentManager.class);
I18n i18n = new I18n(slingRequest);
List<String> includeList = new ArrayList<String>();
List<String> excludeList = new ArrayList<String>();
if (properties.containsKey("includeList")) {
includeList = Arrays.asList((String[]) properties.get("includeList"));
}
if (properties.containsKey("excludeList")) {
excludeList = Arrays.asList((String[]) properties.get("excludeList"));
}
Map<String, Agent> agents = agentMgr.getAgents();
List<String> agentIdsList = new ArrayList<>();
for(Map.Entry<String, Agent> entry: agents.entrySet()){
Agent agent = entry.getValue();
if(agent.isEnabled()){
agentIdsList.add(entry.getValue().getId());
}
}
%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html>
<head>
<title><%= i18n.get("AEM Replication") %> | <%= i18n.get("Activate Tree") %>
</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script src="/libs/cq/ui/resources/cq-ui.js" type="text/javascript"></script>
<%
HtmlLibraryManager htmlMgr = sling.getService(HtmlLibraryManager.class);
if (htmlMgr != null) {
htmlMgr.writeIncludes(slingRequest, out, "cq.widgets");
}
%>
<style type="text/css">
#treeProgress {
display: block;
background-color: white;
width: 100%;
min-height: 400px;
height: 100%;
border: 1px solid #888888;
overflow: scroll;
overflow-x: auto;
}
</style>
</head>
<body>
<h1><%= i18n.get("Activate Tree") %>
</h1>
<form target="treeProgress" action="<%= xssAPI.encodeForHTMLAttr(resource.getPath()) %>.html" method="POST"
id="treeProgress_form">
<input type="hidden" name="_charset_" value="UTF-8">
<input type="hidden" id="path" name="path" value="/content">
<table class="form">
<tr>
<td><label for="fakePathField"><%= i18n.get("Start Path") %>:</label></td>
<td>
<div id="fakePath">&nbsp;</div>
<br>
<small><%= i18n.get("Select location to activate") %>
</small>
</td>
</tr>
<tr>
<td><label for="agent">Agent:</label></td>
<td>
<select id="agent" name="agent">
<option selected="all">All</option>
</select>
</td>
</tr>
<tr>
<td></td>
<td>
<input id="onlymodified" name="onlymodified" type="checkbox" checked value="true">
<label for="onlymodified"><%= i18n.get("Only Modified") %>
</label>
</td>
</tr>
<tr>
<td></td>
<td>
<input id="reactivate" name="reactivate" type="checkbox" value="true">
<label for="reactivate"><%= i18n.get("Only Activated") %>
</label>
</td>
</tr>
<tr>
<td></td>
<td>
<input id="ignoredeactivated" name="ignoredeactivated" type="checkbox" checked value="true">
<label for="ignoredeactivated"><%= i18n.get("Ignore Deactivated") %>
</label><br>
</td>
</tr>
<tr>
<td></td>
<td>
<input type="hidden" name="cmd" value="dryrun" id="cmd">
<input type="button" value="<%= i18n.get("Dry Run") %>"
onclick="document.getElementById('cmd').value='dryrun'; document.getElementById('treeProgress_form').submit();">
<input type="button" value="<%= i18n.get("Activate") %>"
onclick="document.getElementById('cmd').value='activate'; document.getElementById('treeProgress_form').submit();">
</td>
</tr>
</table>
</form>
<br>
<iframe name="treeProgress" id="treeProgress">
</iframe>
<script>
var includes = new Array();
<% for (int i=0; i<includeList.size(); i++) { %>
includes[<%= i %>] = "<%= xssAPI.encodeForJSString(includeList.get(i)) %>";
<% } %>
var excludes = new Array();
<% for (int i=0; i<excludeList.size(); i++) { %>
excludes[<%= i %>] = "<%= xssAPI.encodeForJSString(excludeList.get(i)) %>";
<% } %>
var select = document.getElementById("agent");
<% for (int i=0; i< agentIdsList.size(); i++) { %>
var option = document.createElement("option");
var id = "<%= xssAPI.encodeForJSString(agentIdsList.get(i)) %>";
option.text = id;
option.value = id;
select.add(option);
<% } %>
//use a SlingTreeLoader to replace the default tree loader (that uses ExtTreeServlet to render and doesn't work)
var slingTreeLoader = new CQ.tree.SlingTreeLoader({
typeIncludes: includes,
typeExcludes: excludes,
baseAttrs: {
singleClickExpand: true
}
});
// provide a path selector field with a repository browse dialog
CQ.Ext.onReady(function () {
var w = new CQ.form.PathField({
// applyTo: "path",
renderTo: "CQ",
// "content": "/content",
rootPath: "/",
predicate: "hierarchy",
hideTrigger: false,
showTitlesInTree: false,
name: "fakePathField",
value: "/content",
width: 400,
treeLoader: slingTreeLoader,
listeners: {
render: function () {
this.wrap.anchorTo("fakePath", "tl");
},
change: function (fld, newValue, oldValue) {
document.getElementById("path").value = newValue;
},
dialogselect: function (fld, newValue) {
document.getElementById("path").value = newValue;
}
}
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment