${ util.include('header', [title:'Setup: ' + page.title]) }
<% def fieldFn = { q, label, valueControl -> %>
<div class="form-group">
	<label class="col-sm-4 control-label" for='${q.getName()}'><%= label %></label>
	<div class="col-sm-8">
		<% valueControl(q); %>
	</div>
</div>
<% } %>
<script>
	var checkACS = function() {
		var acsRequired = false;
		["pubsub","muc"].forEach(function(name) {
			var el = document.getElementById(name);
			if (el != null) {
				acsRequired |= el.checked || false;
			}
		});
		document.getElementById("acsComponent").disabled = !document.getElementById("clusterMode").checked || (document.getElementById("clusterMode").checked && acsRequired);

		if (document.getElementById("acsComponent").checked) {
			document.getElementById("acsComponent").checked = document.getElementById("clusterMode").checked;
		} else {
			document.getElementById("acsComponent").checked = document.getElementById("clusterMode").checked && acsRequired;
		}
		document.getElementById("acs-warn").style.display = (document.getElementById("clusterMode").checked && acsRequired) ? "inline" : "none";
	};
</script>
<div class="panel panel-default">
	<div class="panel-heading panel-xs">
		<h4>Cluster configuration</h4>
	</div>
	<div class="panel-body">
		<% def q1 = page.getQuestion('clusterMode') %>
		<% fieldFn(q1, "Do you want your server to run in the cluster mode?", { q -> %>
		<input class="form-control" name='${q.getName()}' id="clusterMode" type='checkbox' ${ q.isSelected("true") ? 'checked' : '' } onclick='checkACS();'/>
		<% }); %>

		<% def q2 = page.getQuestion('acsComponent') %>
		<% fieldFn(q2, "Tigase Advanced Clustering Strategy (ACS) Component", { q -> %>
		<input class="form-control" name='${q.getName()}' id='acsComponent' type="checkbox" ${ q1.isSelected("true") ? "" : "disabled"} ${ q.isSelected("true") ? 'checked' : '' } /><span id="acs-warn" style="color: red; display: none;"><br/>Warning: Tigase ACS is required for PubSub and MUC components to work and cannot be disabled!</span>
		<% }); %>
	</div>
</div>
<div class="panel panel-default">
	<div class="panel-heading panel-xs">
		<h4>Please select/deselect features which should be enabled:</h4>
	</div>
	<div class="panel-body">
<form class="form-horizontal" method='POST' action="?step=${ page.nextPage() }">
<% page.getFeatureQuestions().each { %>
	<% fieldFn(it, it.getLabel(), { q -> %>
	<input class="form-control" name='${q.getName()}' id='${q.getId()}' type='checkbox' ${ (q.isSelected(q.getId())) ? "checked" : "" } onclick='checkACS();' />
	<% }); %>
<% } %>
	</div>
</div>

<button class="btn btn-default" type="submit" name="next">Next</button>

</form>
<script>
	checkACS();
</script>
${ util.include('footer') } 