<?page title="Mail" contentType="text/html;charset=UTF-8"?>
<zk>
<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
<window id="mailWin" border="normal" apply="org.zkoss.bind.BindComposer"
viewModel="@id('vm') @init('info.bukova.isspst.ui.mail.MailForm')" width="800px" closable="true">
	<caption zclass="form-caption" label="${labels.MailForm}" />
	<hbox>
		<vbox hflex="2">
			<hbox>
				<label value="${labels.MailAddressBook}"/> 
				<combobox selectedIndex="@bind(vm.adbType)" readonly="true">
					<comboitem label="${labels.MailUsers}"/>
					<comboitem label="${labels.MailSuppliers}"/>
				</combobox>
			</hbox>
			<textbox
				value="@bind(vm.findAddress)"
				instant="true"
				onChange="@command('find')"
				maxlength="@load(vm.lengthText)"
				width="100%" />
			<listbox model="@load(vm.users)" 
				visible="@load(vm.adbType eq 0)" 
				multiple="true"
				selectedItems="@bind(vm.selectedUsers)"
				height="350px">
				<listhead>
					<listheader label="${labels.MailName}"/>
				</listhead>
				<template name="model">
					<listitem disabled="@load(empty each.email)" draggable="true">
						<listcell label="@load(each.fullName)"/>
					</listitem>
				</template>
			</listbox>
			<listbox model="@load(vm.addressbook)" 
				visible="@load(vm.adbType eq 1)"
				multiple="true"
				selectedItems="@bind(vm.selectedAddresses)"
				height="350px">
				<listhead>
					<listheader label="${labels.MailCompany}"/>
				</listhead>
				<template name="model">
					<listitem disabled="@load(empty each.email)" draggable="true">
						<listcell label="@load(each.company)"/>
					</listitem>
				</template>
			</listbox>
			<button label="${labels.MailToButton}" width="90%" sclass="nicebutton" onClick="@command('addTo')"/>
			<button label="${labels.MailCcButton}" width="90%" sclass="nicebutton" onClick="@command('addCc')"/>
			<button label="${labels.MailBccButton}" width="90%" sclass="nicebutton" onClick="@command('addBcc')"/>
		</vbox>
		<vbox hflex="5">
			<grid>
				<columns>
					<column hflex="min"/>
					<column/>
				</columns>
				<rows>
					<row>
						<label value="${labels.MailFor}"/>
						<textbox
							value="@bind(vm.to)"
							width="100%"
							droppable="true"
							onDrop="@command('addTo')" />
					</row>
					<row>
						<label value="${labels.MailCc}"/> <textbox value="@bind(vm.cc)" width="100%" droppable="true" onDrop="@command('addCc')"/>
					</row>
					<row>
						<label value="${labels.MailBcc}"/> <textbox value="@bind(vm.bcc)" width="100%" droppable="true" onDrop="@command('addBcc')"/>
					</row>
					<row>
						<label value="${labels.MailSubject }"/> <textbox value="@bind(vm.message.subject)" width="100%"/>
					</row>
					<row>
						<label value="${labels.MailAttachement}"/> <textbox value="@load(vm.attachement)" readonly="true" width="100%"/>
					</row>
				</rows>
			</grid>
			<vbox>
				<ckeditor width="540px" height="250px" value="@bind(vm.message.text)" toolbar="Basic"/>
				<hbox>
					<button label="${labels.MailSend}" onClick="@command('send', window=mailWin)" disabled="@load((empty vm.to) or (empty vm.message.subject))" sclass="nicebutton"/> <button label="${labels.ButtonStorno}" onClick="mailWin.detach()" sclass="nicebutton"/>
				</hbox>
			</vbox>
		</vbox>
	</hbox>
</window>
</zk>