${ util.include('header', [title:'Setup: ' + page.title]) }
<form class="form-horizontal" method='POST' action="?step=${ page.nextPage() }">
<div class="panel panel-default">
    <div class="panel-body">
<p>On this panel you can specify basic configuration settings for the Tigase server.</p>
<p>Based on your selection here more configuration options might be presented later on. After the configuration is complete init.properties file will be created.</p>
<p>You can optionally restart the server at the end of the process if you like.</p>
<% def fieldFn = { q, label, valueControl -> %>
<div class="form-group">
    <label class="col-sm-3 control-label" for='${q.getName()}'><%= label %></label>
    <div class="col-sm-9">
        <% valueControl(q); %>
    </div>
</div>
<% } %>
    <% def q = page.getQuestion('configType') %>
    <% fieldFn(q, "Configuration type", { q1 -> %>
    <select class="form-control" name='${q1.getName()}'>
        <% [
        [ value:'default', label:'Default installation' ],
        [ value:'session-manager', label:'Session Manager only' ],
        [ value:'connection-managers', label:'Network connectivity only' ],
        [ value:'component', label:'External component only' ]
        ].each {
        %>
        <option value='${it.value}' ${ q1.isSelected(it.value) ? 'selected' : '' } >${it.label}</option>
        <% } %>
    </select>
    <% }); %>

    <% q = page.getQuestion('virtualDomain') %>
    <% fieldFn(q, "Your XMPP (Jabber) default domain", { q1 -> %>
    <input class="form-control" name='${q.getName()}' type='text' size='30' value='${q.getValue()}' />
    <% }); %>

    <% q = page.getQuestion('admins') %>
    <% fieldFn(q, "Server administrators", { q1 -> %>
    <input class="form-control" name='${q.getName()}' type='text' size='30' value='${q.getValue()}' />
    <% }); %>

    <% q = page.getQuestion('adminPwd') %>
    <% fieldFn(q, "Admin password", { q1 -> %>
    <input class="form-control" name='${q.getName()}' type='password' size='30' value='${q.getValue()}' />
    <% }); %>

    <% q = page.getQuestion('dbType') %>
    <% fieldFn(q, "Select database", { q1 -> %>
    <select class="form-control" name='${q.getName()}' id='dbType' onchange="
	var select = document.getElementById('dbType');
	for (var i=0; i<select.children.length; i++) {
    var it = select.children[i];
    if (it.value == select.value) {
		var warn = document.getElementById('dbTypeWarning');
		warn.innerHTML = it.getAttribute('warning') || '';
	}
}
">
    <% tigase.db.util.SchemaLoader.getAllSupportedTypes().each {
 %>
        <option value='${it.name}' ${ (q.isSelected(it.name) && it.isAvailable()) ? 'selected' : '' } ${it.warning ? 'warning="' + it.warning + '"' : ''} ${it.isAvailable() ? '' : 'disabled'} >${it.label}</option>
    <% } %>
    </select><span id='dbTypeWarning' style='color: red; font-size:0.8em;'></span>
    <% }); %>

    <% q = page.getQuestion('advancedConfig') %>
    <% fieldFn(q, "Advanced configuration options", { q1 -> %>
    <input class="form-control" name='${q.getName()}' type='checkbox' ${ q.isSelected("true") ? "checked" : "" } />
    <% }); %>

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

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