parent
							
								
									4a55467e1e
								
							
						
					
					
						commit
						a834b91091
					
				@ -0,0 +1,67 @@
 | 
			
		||||
package info.bukova.isspst.validators;
 | 
			
		||||
 | 
			
		||||
import info.bukova.isspst.StringUtils;
 | 
			
		||||
 | 
			
		||||
import org.slf4j.Logger;
 | 
			
		||||
import org.zkoss.bind.ValidationContext;
 | 
			
		||||
import org.zkoss.bind.validator.AbstractValidator;
 | 
			
		||||
import org.zkoss.zk.ui.Component;
 | 
			
		||||
import org.zkoss.zk.ui.HtmlBasedComponent;
 | 
			
		||||
import org.zkoss.zk.ui.event.Event;
 | 
			
		||||
import org.zkoss.zk.ui.event.EventListener;
 | 
			
		||||
import org.zkoss.zul.Messagebox;
 | 
			
		||||
 | 
			
		||||
public abstract class BaseValidator extends AbstractValidator
 | 
			
		||||
{
 | 
			
		||||
	HtmlBasedComponent htmlComponent;
 | 
			
		||||
	
 | 
			
		||||
	protected Logger getLogger()
 | 
			
		||||
	{
 | 
			
		||||
		return null;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void errorMsg(ValidationContext ctx, String msg, String componentIdFocused)
 | 
			
		||||
	{
 | 
			
		||||
		this.addInvalidMessage(ctx, msg);
 | 
			
		||||
 | 
			
		||||
		Logger logger = this.getLogger();
 | 
			
		||||
 | 
			
		||||
		if (logger != null)
 | 
			
		||||
		{
 | 
			
		||||
			logger.error(msg);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		htmlComponent = null;
 | 
			
		||||
		
 | 
			
		||||
		if ((componentIdFocused != null) && (!componentIdFocused.isEmpty()))
 | 
			
		||||
		{
 | 
			
		||||
			Component component = ctx.getBindContext().getComponent().getFellowIfAny(componentIdFocused, true);
 | 
			
		||||
 | 
			
		||||
			if ((component != null) && (component instanceof HtmlBasedComponent))
 | 
			
		||||
			{
 | 
			
		||||
				htmlComponent = (HtmlBasedComponent) component;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		Messagebox.show(msg, StringUtils.localize("Error"), Messagebox.OK, Messagebox.ERROR, new EventListener<Event>()
 | 
			
		||||
		{
 | 
			
		||||
			public void onEvent(Event evt) throws InterruptedException
 | 
			
		||||
			{
 | 
			
		||||
				if (htmlComponent != null)
 | 
			
		||||
				{
 | 
			
		||||
					htmlComponent.setFocus(true);
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		});
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void addErrorMsg(ValidationContext ctx, String msg)
 | 
			
		||||
	{
 | 
			
		||||
		this.errorMsg(ctx, msg, null);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public void validate(ValidationContext ctx)
 | 
			
		||||
	{
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,61 @@
 | 
			
		||||
package info.bukova.isspst.validators;
 | 
			
		||||
 | 
			
		||||
import info.bukova.isspst.StringUtils;
 | 
			
		||||
 | 
			
		||||
import org.slf4j.Logger;
 | 
			
		||||
import org.slf4j.LoggerFactory;
 | 
			
		||||
import org.zkoss.bind.Property;
 | 
			
		||||
import org.zkoss.bind.ValidationContext;
 | 
			
		||||
 | 
			
		||||
public class UserFormValidator extends BaseValidator
 | 
			
		||||
{
 | 
			
		||||
	private final static Logger log = LoggerFactory.getLogger(UserFormValidator.class.getName());
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	protected Logger getLogger()
 | 
			
		||||
	{
 | 
			
		||||
		return log;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private boolean recordIsNew;
 | 
			
		||||
 | 
			
		||||
	public UserFormValidator(boolean recordIsNew)
 | 
			
		||||
	{
 | 
			
		||||
		this.recordIsNew = recordIsNew;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public void validate(ValidationContext ctx)
 | 
			
		||||
	{
 | 
			
		||||
		Property propertyOrig = ctx.getProperties("password")[0];
 | 
			
		||||
		String passwordOrig = (String) propertyOrig.getValue();
 | 
			
		||||
		
 | 
			
		||||
		if (passwordOrig == null)
 | 
			
		||||
		{
 | 
			
		||||
			passwordOrig = "";
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if (passwordOrig.isEmpty())
 | 
			
		||||
		{
 | 
			
		||||
			if (this.recordIsNew)
 | 
			
		||||
			{
 | 
			
		||||
				this.errorMsg(ctx, StringUtils.localize("UserPasswordIsEmpty"), "idUserPasswordOriginal");
 | 
			
		||||
				return;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		Property propertyDupl = ctx.getProperties("retPasswd")[0];
 | 
			
		||||
		String passwordDupl = (String) propertyDupl.getValue();
 | 
			
		||||
 | 
			
		||||
		if (passwordDupl == null)
 | 
			
		||||
		{
 | 
			
		||||
			passwordDupl = "";
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if (!passwordOrig.equals(passwordDupl))
 | 
			
		||||
		{
 | 
			
		||||
			this.errorMsg(ctx, StringUtils.localize("UserPasswordsAreNotSame"), "idUserPasswordDuplicate");
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,65 @@
 | 
			
		||||
package info.bukova.isspst.validators;
 | 
			
		||||
 | 
			
		||||
import info.bukova.isspst.StringUtils;
 | 
			
		||||
 | 
			
		||||
import org.slf4j.Logger;
 | 
			
		||||
import org.slf4j.LoggerFactory;
 | 
			
		||||
import org.zkoss.bind.Property;
 | 
			
		||||
import org.zkoss.bind.ValidationContext;
 | 
			
		||||
 | 
			
		||||
public class UserPasswordDuplValidator extends BaseValidator
 | 
			
		||||
{
 | 
			
		||||
	private final static Logger log = LoggerFactory.getLogger(UserPasswordDuplValidator.class.getName());
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	protected Logger getLogger()
 | 
			
		||||
	{
 | 
			
		||||
		return log;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public void validate(ValidationContext ctx)
 | 
			
		||||
	{
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public void aaa(ValidationContext ctx)
 | 
			
		||||
	{
 | 
			
		||||
		Object argOrig = ctx.getBindContext().getValidatorArg("orig");
 | 
			
		||||
 | 
			
		||||
		if (argOrig == null)
 | 
			
		||||
		{
 | 
			
		||||
			this.addErrorMsg(ctx, StringUtils.localize("NullPointerErr"));
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if (!(argOrig instanceof String))
 | 
			
		||||
		{
 | 
			
		||||
			this.addErrorMsg(ctx, StringUtils.localize("DataTypeErr"));
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		String propertyNameOrig = (String) argOrig;
 | 
			
		||||
 | 
			
		||||
		Property propertyOrig = ctx.getProperties(propertyNameOrig)[0];
 | 
			
		||||
		String passwordOrig = (String) propertyOrig.getValue();
 | 
			
		||||
 | 
			
		||||
		if (passwordOrig == null)
 | 
			
		||||
		{
 | 
			
		||||
			passwordOrig = "";
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		Property propertyDupl = ctx.getProperty();
 | 
			
		||||
		String passwordDupl = (String) propertyDupl.getValue();
 | 
			
		||||
 | 
			
		||||
		if (passwordDupl == null)
 | 
			
		||||
		{
 | 
			
		||||
			passwordDupl = "";
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if (!passwordOrig.equals(passwordDupl))
 | 
			
		||||
		{
 | 
			
		||||
			this.addErrorMsg(ctx, StringUtils.localize("UserPasswordsAreNotSame"));
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,51 @@
 | 
			
		||||
package info.bukova.isspst.validators;
 | 
			
		||||
 | 
			
		||||
import info.bukova.isspst.StringUtils;
 | 
			
		||||
 | 
			
		||||
import org.slf4j.Logger;
 | 
			
		||||
import org.slf4j.LoggerFactory;
 | 
			
		||||
import org.zkoss.bind.Property;
 | 
			
		||||
import org.zkoss.bind.ValidationContext;
 | 
			
		||||
 | 
			
		||||
public class UserPasswordOrigValidator extends BaseValidator
 | 
			
		||||
{
 | 
			
		||||
	private final static Logger log = LoggerFactory.getLogger(UserPasswordOrigValidator.class.getName());
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	protected Logger getLogger()
 | 
			
		||||
	{
 | 
			
		||||
		return log;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private boolean recordIsNew;
 | 
			
		||||
 | 
			
		||||
	public UserPasswordOrigValidator(boolean recordIsNew)
 | 
			
		||||
	{
 | 
			
		||||
		this.recordIsNew = recordIsNew;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public void validate(ValidationContext ctx)
 | 
			
		||||
	{
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public void aaa(ValidationContext ctx)
 | 
			
		||||
	{
 | 
			
		||||
		Property propertyOrig = ctx.getProperty();
 | 
			
		||||
		String passwordOrig = (String) propertyOrig.getValue();
 | 
			
		||||
 | 
			
		||||
		if (passwordOrig == null)
 | 
			
		||||
		{
 | 
			
		||||
			passwordOrig = "";
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if (passwordOrig.isEmpty())
 | 
			
		||||
		{
 | 
			
		||||
			if (this.recordIsNew)
 | 
			
		||||
			{
 | 
			
		||||
				this.addErrorMsg(ctx, StringUtils.localize("UserPasswordIsEmpty"));
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@ -1,3 +1,11 @@
 | 
			
		||||
BuildingsFormCodeConstr = Zadejte k\u00F3d budovy...
 | 
			
		||||
MaterialFormCodeConstr = Zadejte k\u00F3d materi\u00E1lu...
 | 
			
		||||
BuildingsFormCodeConstr=Zadejte k\u00F3d budovy...
 | 
			
		||||
MaterialFormCodeConstr=Zadejte k\u00F3d materi\u00E1lu...
 | 
			
		||||
MUnitsFormCodeConstr=Zadejte k\u00f3d m\u011brn\u00e9 jednotky...
 | 
			
		||||
 | 
			
		||||
Lad = \u00E1
 | 
			
		||||
Led = \u00E9
 | 
			
		||||
Leh = \u011B
 | 
			
		||||
Lid = \u00ED
 | 
			
		||||
Lod = \u00F3
 | 
			
		||||
Lyd = \u00FD
 | 
			
		||||
Lzh = \u017E
 | 
			
		||||
 | 
			
		||||
@ -0,0 +1,5 @@
 | 
			
		||||
NullPointerErr=Chyba ukazatele...
 | 
			
		||||
DataTypeErr=Chybný datový typ...
 | 
			
		||||
 | 
			
		||||
UserPasswordIsEmpty=Uživatelské heslo musí být zadané...
 | 
			
		||||
UserPasswordsAreNotSame=Znovu zadané heslo není stejné...
 | 
			
		||||
@ -1,35 +1,97 @@
 | 
			
		||||
<?page title="${labels.UsersFormTitle}" contentType="text/html;charset=UTF-8"?>
 | 
			
		||||
<zk>
 | 
			
		||||
<window id="editWin" border="normal" closable="true" width="450px" apply="org.zkoss.bind.BindComposer"
 | 
			
		||||
	viewModel="@id('vm') @init('info.bukova.isspst.ui.users.UserForm')">
 | 
			
		||||
 | 
			
		||||
	<caption zclass="form-caption" label="${labels.UsersFormTitle}" />
 | 
			
		||||
	<grid width="440px">
 | 
			
		||||
		<columns>
 | 
			
		||||
			<column hflex="min"></column>
 | 
			
		||||
			<column></column>
 | 
			
		||||
			<column></column>
 | 
			
		||||
		</columns>
 | 
			
		||||
		<rows>
 | 
			
		||||
			<row><label value="${labels.UsersFormLogin}"/><textbox value="@bind(vm.dataBean.username)" instant="true" disabled="@load(vm.edit)" onChange="@command('checkLogin')"/><label value="Login je obsazený" sclass="error" visible="@load(not vm.loginFree)"/></row>
 | 
			
		||||
			<row><label value="${labels.UsersFormFirstName}"/><textbox value="@bind(vm.dataBean.firstName)"/></row>
 | 
			
		||||
			<row><label value="${labels.UsersFormSureName}"/><textbox value="@bind(vm.dataBean.lastName)"/></row>
 | 
			
		||||
			<row><label value="${labels.UsersFormPersonalID}"/><textbox value="@bind(vm.dataBean.personalNumber)" width="90px"/></row>
 | 
			
		||||
			<row><label value="${labels.UsersFormEmail}"/><textbox value="@bind(vm.dataBean.email)"/></row>
 | 
			
		||||
			<row><label value=""/><checkbox label="${labels.UsersFormSendNotify}" checked="@bind(vm.dataBean.notify)"/></row>
 | 
			
		||||
			<row><label value="${labels.UsersFormPassword}"/><textbox value="@bind(vm.password)" type="password" instant="true"/></row>
 | 
			
		||||
			<row><label value="${labels.UsersFormRepeatPassword}"/><textbox value="@bind(vm.retPasswd)" type="password" instant="true"/><label value="Hesla nesouhlasí" sclass="error" visible="@load(not vm.pwMatches)"/></row>
 | 
			
		||||
			<row><label value=""/><checkbox label="${labels.UsersFormActive}" checked="@bind(vm.dataBean.enabled)" disabled="@load(vm.dataBean.username eq 'admin')" /></row>
 | 
			
		||||
		</rows>
 | 
			
		||||
	</grid>
 | 
			
		||||
	<groupbox mold="3d">
 | 
			
		||||
	<caption label="Role"/>
 | 
			
		||||
	<vbox children="@load(vm.userRoles.roleChecks)">
 | 
			
		||||
		<template name="children">
 | 
			
		||||
			<checkbox label="@load(each.role.description)" checked="@bind(each.checked)"  disabled="@load(vm.dataBean.username eq 'admin')" />
 | 
			
		||||
		</template>
 | 
			
		||||
	</vbox>
 | 
			
		||||
	</groupbox>
 | 
			
		||||
	<include src="/app/formButtons.zul" />
 | 
			
		||||
</window>
 | 
			
		||||
	<window
 | 
			
		||||
		id="editWin"
 | 
			
		||||
		border="normal"
 | 
			
		||||
		closable="true"
 | 
			
		||||
		width="450px"
 | 
			
		||||
		apply="org.zkoss.bind.BindComposer"
 | 
			
		||||
		viewModel="@id('vm') @init('info.bukova.isspst.ui.users.UserForm')"
 | 
			
		||||
		validationMessages="@id('vmsg')">
 | 
			
		||||
		<caption
 | 
			
		||||
			zclass="form-caption"
 | 
			
		||||
			label="${labels.UsersFormTitle}" />
 | 
			
		||||
		<grid
 | 
			
		||||
			width="440px"
 | 
			
		||||
			form="@id('fx') @load(vm.dataBean) @save(vm.dataBean, before='save') @validator(vm.userFormValidator)">
 | 
			
		||||
			<columns>
 | 
			
		||||
				<column hflex="min"></column>
 | 
			
		||||
				<column></column>
 | 
			
		||||
				<column></column>
 | 
			
		||||
			</columns>
 | 
			
		||||
			<rows>
 | 
			
		||||
				<row>
 | 
			
		||||
					<label value="${labels.UsersFormLogin}" />
 | 
			
		||||
					<textbox
 | 
			
		||||
						value="@bind(vm.dataBean.username)"
 | 
			
		||||
						instant="true"
 | 
			
		||||
						disabled="@load(vm.edit)"
 | 
			
		||||
						onChange="@command('checkLogin')" />
 | 
			
		||||
					<label
 | 
			
		||||
						value="Login je obsazený"
 | 
			
		||||
						sclass="error"
 | 
			
		||||
						visible="@load(not vm.loginFree)" />
 | 
			
		||||
				</row>
 | 
			
		||||
				<row>
 | 
			
		||||
					<label value="${labels.UsersFormFirstName}" />
 | 
			
		||||
					<textbox value="@bind(vm.dataBean.firstName)" />
 | 
			
		||||
				</row>
 | 
			
		||||
				<row>
 | 
			
		||||
					<label value="${labels.UsersFormSureName}" />
 | 
			
		||||
					<textbox value="@bind(vm.dataBean.lastName)" />
 | 
			
		||||
				</row>
 | 
			
		||||
				<row>
 | 
			
		||||
					<label value="${labels.UsersFormPersonalID}" />
 | 
			
		||||
					<textbox
 | 
			
		||||
						value="@bind(vm.dataBean.personalNumber)"
 | 
			
		||||
						width="90px" />
 | 
			
		||||
				</row>
 | 
			
		||||
				<row>
 | 
			
		||||
					<label value="${labels.UsersFormEmail}" />
 | 
			
		||||
					<textbox value="@bind(vm.dataBean.email)" />
 | 
			
		||||
				</row>
 | 
			
		||||
				<row>
 | 
			
		||||
					<label value="" />
 | 
			
		||||
					<checkbox
 | 
			
		||||
						label="${labels.UsersFormSendNotify}"
 | 
			
		||||
						checked="@bind(vm.dataBean.notify)" />
 | 
			
		||||
				</row>
 | 
			
		||||
				<row>
 | 
			
		||||
					<label value="${labels.UsersFormPassword}" />
 | 
			
		||||
					<textbox
 | 
			
		||||
						id="idUserPasswordOriginal"
 | 
			
		||||
						value="@save(vm.password, before='save')"
 | 
			
		||||
						type="password"
 | 
			
		||||
						instant="true" />
 | 
			
		||||
				</row>
 | 
			
		||||
				<row>
 | 
			
		||||
					<label value="${labels.UsersFormRepeatPassword}" />
 | 
			
		||||
					<textbox
 | 
			
		||||
						id="idUserPasswordDuplicate"
 | 
			
		||||
						value="@save(vm.retPasswd, before='save')"
 | 
			
		||||
						type="password"
 | 
			
		||||
						instant="true" />
 | 
			
		||||
				</row>
 | 
			
		||||
				<row>
 | 
			
		||||
					<label value="" />
 | 
			
		||||
					<checkbox
 | 
			
		||||
						label="${labels.UsersFormActive}"
 | 
			
		||||
						checked="@bind(vm.dataBean.enabled)"
 | 
			
		||||
						disabled="@load(vm.dataBean.username eq 'admin')" />
 | 
			
		||||
				</row>
 | 
			
		||||
			</rows>
 | 
			
		||||
		</grid>
 | 
			
		||||
		<groupbox mold="3d">
 | 
			
		||||
			<caption label="Role" />
 | 
			
		||||
			<vbox children="@load(vm.userRoles.roleChecks)">
 | 
			
		||||
				<template name="children">
 | 
			
		||||
					<checkbox
 | 
			
		||||
						label="@load(each.role.description)"
 | 
			
		||||
						checked="@bind(each.checked)"
 | 
			
		||||
						disabled="@load(vm.dataBean.username eq 'admin')" />
 | 
			
		||||
				</template>
 | 
			
		||||
			</vbox>
 | 
			
		||||
		</groupbox>
 | 
			
		||||
		<include src="/app/formButtons.zul" />
 | 
			
		||||
	</window>
 | 
			
		||||
</zk>
 | 
			
		||||
					Loading…
					
					
				
		Reference in New Issue