UserCreateEditForm.lzx
<library>
<class name="UserCreateEditForm" extends="BorderedBox" width="$once{this.content.width+26}" height="${this.content.height+26}" borderColor="#777777" bgcolor="#f8f3aa" inset="10">
<attribute name="user" type="expression" value="null
"/>
<node name="i18n" datapath="i18nDS:/app/user/create">
<attribute name="missingParameters" type="string" value="$path{'missingParameters/text()'}"/>
<attribute name="passwordMissmatch" type="string" value="$path{'passwordMissmatch/text()'}"/>
</node>
<ServiceConnector name="createUserConn" form="$once{parent}">
<method name="handleResult" args="message">
form.searchSubnodes("name", "messageBox").setAttribute('text', message);
</method>
</ServiceConnector>
<ServiceConnector name="updateUserConn" form="$once{parent}">
<method name="handleResult" args="message">
form.searchSubnodes("name", "messageBox").setAttribute('text', message);
</method>
</ServiceConnector>
<method name="clear">
searchSubnodes("name", "login").setAttribute('text', '');
searchSubnodes("name", "realName").setAttribute('text', '');
searchSubnodes("name", "email").setAttribute('text', '');
searchSubnodes("name", "password1").setAttribute('text', '');
searchSubnodes("name", "password2").setAttribute('text', '');
parent.user = null;
content.createState.setAttribute('applied', true);
content.updateState.setAttribute('applied', false);
</method>
<method name="collectValues">
var values = new Array();
values['login'] = parent.searchSubnodes("name", "login").text;
values['password'] = parent.searchSubnodes("name", "password1").text;
values['email'] = parent.searchSubnodes("name", "email").text;
values['realname'] = parent.searchSubnodes("name", "realName").text;
if (this.user != null) {
values['id'] = user.userId;
}
return values;
</method>
<method name="createUser">
createUserConn.callService();
</method>
<method name="loadUser" args="user">
this.user = user;
parent.searchSubnodes("name", "login").setAttribute('text', user.login);
parent.searchSubnodes("name", "realName").setAttribute('text', user.realName);
parent.searchSubnodes("name", "email").setAttribute('text', user.email);
content.createState.setAttribute('applied', false);
content.updateState.setAttribute('applied', true);
</method>
<method name="updateUser">
updateUserConn.callService();
</method>
<method name="validate" args="conn">
var errorMessage = null;
var name = searchSubnodes("name", "login").text;
var pass1 = searchSubnodes("name", "password1").text;
var pass2 = searchSubnodes("name", "password2").text;
var email = searchSubnodes("name", "email").text;
var realName = searchSubnodes("name", "realName").text;
if (name.length == 0 || email.length == 0 || realName.length == 0 || pass1.length == 0) {
errorMessage = this.i18n.missingParameters;
} else if (pass1 != pass2) {
errorMessage = this.i18n.passwordMissmatch;
}
if (errorMessage != null) {
conn.showValidatonError(errorMessage);
return false;
} else {
return true;
}
</method>
<view name="content" width="$once{classroot.innerWidth}">
<simplelayout axis="y" spacing="5"/>
<BorderedBox name="messageBox" align="center" y="60" height="0" width="${parent.width-40}" borderColor="#777777" bgcolor="#cccccc" borderSize="2" visible="true" clip="true">
<method name="setText" args="t">
if (t.length > 0) {
this.textField.setAttribute('text', t);
this.setAttribute("visible", true);
this.animate('height', 30, 400);
} else {
this.animate('height', 0, 400);
}
</method>
<text name="textField" align="center" fgcolor="#2c4c62" fontsize="12"/>
</BorderedBox>
<view height="10"/>
<view name="buttonYRef" height="40">
<text y="3" fontsize="10" fontstyle="bold" datapath="i18nDS:/app/login/user/text()"/>
<edittext name="login" x="100" width="180"/>
</view>
<view height="40">
<text y="3" fontsize="10" fontstyle="bold" datapath="i18nDS:/app/main/peopleTab/realName/text()"/>
<edittext name="realName" x="100" width="180"/>
</view>
<view height="40">
<text y="3" fontsize="10" fontstyle="bold" datapath="i18nDS:/app/main/peopleTab/email/text()"/>
<edittext name="email" x="100" width="180"/>
</view>
<view height="40">
<text y="3" fontsize="10" fontstyle="bold" datapath="i18nDS:/app/login/password/text()"/>
<edittext name="password1" x="100" width="180" password="true"/>
</view>
<view height="40">
<text y="3" fontsize="10" fontstyle="bold" datapath="i18nDS:/app/login/password/text()"/>
<edittext name="password2" x="100" width="180" password="true"/>
</view>
<state name="createState" pooling="true" applied="true">
<button name="createButton" y="${parent.buttonYRef.y}" datapath="i18nDS:/app/main/peopleTab/newUser/text()" align="right" options="ignorelayout" onclick="classroot.createUser()"/>
</state>
<state name="updateState" pooling="true">
<button name="editButton" y="${parent.buttonYRef.y}" datapath="i18nDS:/app/main/peopleTab/editUser/text()" align="right" options="ignorelayout" onclick="classroot.updateUser()"/>
</state>
<button name="cancelButton" y="${parent.buttonYRef.y+40}" datapath="i18nDS:/app/main/peopleTab/cancel/text()" align="right" options="ignorelayout" onclick="classroot.clear()"/>
</view>
</class>
</library>