<?page title="${labels.RequirementsFormTitle}" contentType="text/html;charset=UTF-8"?>
<zk xmlns="http://www.zkoss.org/2005/zul"
	xmlns:h="http://www.w3.org/1999/xhtml"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.zkoss.org/2005/zul http://www.zkoss.org/2005/zul/zul.xsd">
	<window
		id="editWin"
		closable="true"
		border="normal"
		position="center"
		apply="org.zkoss.bind.BindComposer"
		viewModel="@id('vm') @init('info.bukova.isspst.ui.requirement.TripRequirementForm')">
		<caption
			src="/img/reqact.png"
			zclass="form-caption"
			label="${labels.RequirementsFormTitle}" />
		<vlayout form="@id('fx') @load(vm.dataBean) @save(vm.dataBean, before='save') @validator(vm.validator)">
			<hbox>
				<grid hflex="min">
					<columns>
						<column
							align="right"
							hflex="min" />
						<column />
					</columns>
					<rows>
						<row>
							<cell sclass="row-title">${labels.RequirementsFormNumberSerie} :</cell>
							<cell>
								<textbox
									id="numser"
									width="200px"
									value="@bind(fx.numser)"
									maxlength="@load(vm.lengthText)"
									readonly="true" />
							</cell>
						</row>
						<row>
							<cell sclass="row-title">${labels.RequirementsFormReqDate} :</cell>
							<cell>
								<datebox
									id="reqDate"
									width="200px"
									value="@bind(fx.reqDate)"
									format="${labels.DateFormat}" />
							</cell>
						</row>
						<row>
							<cell sclass="row-title">${labels.RequirementsFormCenter} :</cell>
							<cell>
								<combobox
									model="@load(vm.centres)"
									readonly="true"
									selectedItem="@bind(fx.centre)">
									<template name="model">
										<comboitem label="@load(each.fullName)" />
									</template>
								</combobox>
							</cell>
						</row>
						<row>
							<cell sclass="row-title">${labels.RequirementsFormFrom} :</cell>
							<cell>
								<textbox
									id="from"
									width="300px"
									maxlength="@load(vm.lengthText)"
									value="@bind(fx.from)" />
							</cell>
						</row>
						<row>
							<cell sclass="row-title">${labels.RequirementsFormStartDateTime} :</cell>
							<cell>
								<hbox>
								<datebox
									id="tripDate"
									width="200px"
									format="medium"
									value="@bind(fx.tripDate)" />
								<timebox
									id="tripTime"
									width="90px"
									format="short"
									value="@bind(fx.tripDate)" />

								</hbox>
							</cell>
						</row>
						<row>
							<cell sclass="row-title">${labels.RequirementsFormTo} :</cell>
							<cell>
								<textbox
									id="to"
									width="300px"
									maxlength="@load(vm.lengthText)"
									value="@bind(fx.to)" />
							</cell>
						</row>
						<row>
							<cell sclass="row-title">${labels.RequirementsFormPurpose} :</cell>
							<cell>
								<textbox
									id="description"
									width="300px"
									maxlength="@load(vm.lengthText)"
									value="@bind(fx.description)" />
							</cell>
						</row>
						<row>
							<cell sclass="row-title">${labels.RequirementsFormEndTravel} :</cell>
							<cell>
								<textbox
									id="end"
									width="200px"
									maxlength="@load(vm.lengthText)"
									value="@bind(fx.end)" />
							</cell>
						</row>
						<row>
							<cell sclass="row-title">${labels.RequirementsFormEndDate} :</cell>
							<cell>
								<datebox
									id="endDate"
									width="300px"
									format="medium"
									value="@bind(fx.endDate)" />
							</cell>
						</row>
					</rows>
				</grid>
				<vbox>
					<button label="Připojit"
							upload="true"
							onUpload="@command('uploadAttachment')"
							sclass="nicebutton" />
					<grid model="@load(vm.attachments)">
						<columns>
							<column/>
						</columns>
						<rows>
							<template name="model">
								<row>
									<a href="@load('/api/dl/'.concat(each.pathInFilesystem).concat('/').concat(each.fileName))"
									   label="@load(each.fileName)"
									   target="blank"/>
									<hbox>
										<button label="Odebrat" onClick="@command('deleteAttachment', attachment=each)"/>
										<button label="Stáhnout" onClick="@command('downloadAttachment', attachment=each)"/>
									</hbox>
								</row>
							</template>
						</rows>
					</grid>
				</vbox>
			</hbox>
			<vbox>
				<label value="${labels.RequirementsFormPassengers}"/>
				<hbox>
					<combobox model="@load(vm.users)"
						autocomplete="true" 
						selectedItem="@bind(vm.selUser)">
						<template name="model">
							<comboitem label="@load(each)"/>
						</template>
					</combobox>
					<button label="${labels.Confirm}"
						onClick="@command('addPassanger')"
						sclass="nicebutton"
						disabled="@load(vm.selUser eq null)"/>
				</hbox>
				<grid model="@load(vm.passengers)" width="700px">
					<columns>
						<column/>
						<column/>
					</columns>
					<rows>
						<template name="model">
							<row>
								<label value="@load(each)" />
								<button label="${labels.RemoveItem}" 
									onClick="@command('removePassanger', user=each)"
									sclass="nicebutton"/>
							</row>
						</template>
					</rows>
				</grid>
				
				<grid hflex="min">
					<columns>
						<column hflex="min"/>
						<column hflex="min"/>
					</columns>
					<rows>
						<row>
							<label value="${labels.RequirementsFormVehicle}"/>
							<combobox model="@load(vm.settings.vehicles)" 
								selectedItem="@bind(fx.vehicle)"
								readonly="true">
								<template name="model">
									<comboitem label="@load(each)"/>
								</template>
							</combobox>	
						</row>
						<row>
							<checkbox label="Požaduji zálohu" checked="@bind(vm.dataBean.requireDownPayment)"/>
							<textbox
								value="@bind(vm.dataBean.downPayment)"
								maxlength="@load(vm.lengthText)"
								disabled="@bind(not vm.dataBean.requireDownPayment)" />
						</row>
					</rows>
				</grid>
			</vbox>
			<include src="/app/formButtons.zul" />
		</vlayout>
	</window>
</zk>