IDEMPIERE-724 Zk: Make iDempiere theme more easily customizable. Refactoring to allowing theme to change the appearance of the login dialog by extending LoginWindow, LoginPanel and RolePanel.
This commit is contained in:
parent
e18d9ed666
commit
329d7afaef
|
@ -39,7 +39,6 @@ import org.adempiere.webui.component.Combobox;
|
||||||
import org.adempiere.webui.component.ConfirmPanel;
|
import org.adempiere.webui.component.ConfirmPanel;
|
||||||
import org.adempiere.webui.component.Label;
|
import org.adempiere.webui.component.Label;
|
||||||
import org.adempiere.webui.component.Textbox;
|
import org.adempiere.webui.component.Textbox;
|
||||||
import org.adempiere.webui.component.ToolBarButton;
|
|
||||||
import org.adempiere.webui.component.Window;
|
import org.adempiere.webui.component.Window;
|
||||||
import org.adempiere.webui.event.TokenEvent;
|
import org.adempiere.webui.event.TokenEvent;
|
||||||
import org.adempiere.webui.exception.ApplicationException;
|
import org.adempiere.webui.exception.ApplicationException;
|
||||||
|
@ -82,6 +81,7 @@ import org.zkoss.zk.ui.event.Event;
|
||||||
import org.zkoss.zk.ui.event.EventListener;
|
import org.zkoss.zk.ui.event.EventListener;
|
||||||
import org.zkoss.zk.ui.event.Events;
|
import org.zkoss.zk.ui.event.Events;
|
||||||
import org.zkoss.zk.ui.util.Clients;
|
import org.zkoss.zk.ui.util.Clients;
|
||||||
|
import org.zkoss.zul.A;
|
||||||
import org.zkoss.zul.Checkbox;
|
import org.zkoss.zul.Checkbox;
|
||||||
import org.zkoss.zul.Comboitem;
|
import org.zkoss.zul.Comboitem;
|
||||||
import org.zkoss.zul.Image;
|
import org.zkoss.zul.Image;
|
||||||
|
@ -106,19 +106,19 @@ public class LoginPanel extends Window implements EventListener<Event>
|
||||||
private static final String ON_LOAD_TOKEN = "onLoadToken";
|
private static final String ON_LOAD_TOKEN = "onLoadToken";
|
||||||
private static CLogger logger = CLogger.getCLogger(LoginPanel.class);
|
private static CLogger logger = CLogger.getCLogger(LoginPanel.class);
|
||||||
|
|
||||||
private Properties ctx;
|
protected Properties ctx;
|
||||||
private Label lblUserId;
|
protected Label lblUserId;
|
||||||
private Label lblPassword;
|
protected Label lblPassword;
|
||||||
private Label lblLanguage;
|
protected Label lblLanguage;
|
||||||
private Textbox txtUserId;
|
protected Textbox txtUserId;
|
||||||
private Textbox txtPassword;
|
protected Textbox txtPassword;
|
||||||
private Combobox lstLanguage;
|
protected Combobox lstLanguage;
|
||||||
private LoginWindow wndLogin;
|
protected LoginWindow wndLogin;
|
||||||
private Checkbox chkRememberMe;
|
protected Checkbox chkRememberMe;
|
||||||
private Checkbox chkSelectRole;
|
protected Checkbox chkSelectRole;
|
||||||
private ToolBarButton btnResetPassword;
|
protected A btnResetPassword;
|
||||||
private ConfirmPanel pnlButtons;
|
protected ConfirmPanel pnlButtons;
|
||||||
boolean email_login = MSysConfig.getBooleanValue(MSysConfig.USE_EMAIL_FOR_LOGIN, false);
|
protected boolean email_login = MSysConfig.getBooleanValue(MSysConfig.USE_EMAIL_FOR_LOGIN, false);
|
||||||
|
|
||||||
public LoginPanel(Properties ctx, LoginWindow loginWindow)
|
public LoginPanel(Properties ctx, LoginWindow loginWindow)
|
||||||
{
|
{
|
||||||
|
@ -138,7 +138,71 @@ public class LoginPanel extends Window implements EventListener<Event>
|
||||||
|
|
||||||
private void init()
|
private void init()
|
||||||
{
|
{
|
||||||
Div div = new Div();
|
createUI();
|
||||||
|
|
||||||
|
txtUserId.addEventListener(TokenEvent.ON_USER_TOKEN, new EventListener<Event>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEvent(Event event) throws Exception {
|
||||||
|
String[] data = (String[]) event.getData();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
int AD_Session_ID = Integer.parseInt(data[0]);
|
||||||
|
MSession session = new MSession(Env.getCtx(), AD_Session_ID, null);
|
||||||
|
if (session.get_ID() == AD_Session_ID)
|
||||||
|
{
|
||||||
|
int AD_User_ID = session.getCreatedBy();
|
||||||
|
MUser user = MUser.get(Env.getCtx(), AD_User_ID);
|
||||||
|
if (user != null && user.get_ID() == AD_User_ID)
|
||||||
|
{
|
||||||
|
String token = data[1];
|
||||||
|
if (BrowserToken.validateToken(session, user, token))
|
||||||
|
{
|
||||||
|
if (MSystem.isZKRememberUserAllowed()) {
|
||||||
|
if (email_login) {
|
||||||
|
txtUserId.setValue(user.getEMail());
|
||||||
|
} else {
|
||||||
|
if (user.getLDAPUser() != null && user.getLDAPUser().length() > 0) {
|
||||||
|
txtUserId.setValue(user.getLDAPUser());
|
||||||
|
} else {
|
||||||
|
txtUserId.setValue(user.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
onUserIdChange(AD_User_ID);
|
||||||
|
chkRememberMe.setChecked(true);
|
||||||
|
}
|
||||||
|
if (MSystem.isZKRememberPasswordAllowed()) {
|
||||||
|
txtPassword.setValue(token);
|
||||||
|
txtPassword.setAttribute("user.token.hash", token);
|
||||||
|
txtPassword.setAttribute("user.token.sid", AD_Session_ID);
|
||||||
|
}
|
||||||
|
chkSelectRole.setChecked(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
//safe to ignore
|
||||||
|
if (logger.isLoggable(Level.INFO))logger.log(Level.INFO, e.getLocalizedMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Make the default language the language of client System
|
||||||
|
String defaultLanguage = MClient.get(ctx, 0).getAD_Language();
|
||||||
|
for(int i = 0; i < lstLanguage.getItemCount(); i++)
|
||||||
|
{
|
||||||
|
Comboitem li = lstLanguage.getItemAtIndex(i);
|
||||||
|
if (li.getValue().equals(defaultLanguage))
|
||||||
|
{
|
||||||
|
lstLanguage.setSelectedIndex(i);
|
||||||
|
languageChanged(li.getLabel());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void createUI() {
|
||||||
|
Div div = new Div();
|
||||||
div.setSclass(ITheme.LOGIN_BOX_HEADER_CLASS);
|
div.setSclass(ITheme.LOGIN_BOX_HEADER_CLASS);
|
||||||
Label label = new Label("Login");
|
Label label = new Label("Login");
|
||||||
label.setSclass(ITheme.LOGIN_BOX_HEADER_TXT_CLASS);
|
label.setSclass(ITheme.LOGIN_BOX_HEADER_TXT_CLASS);
|
||||||
|
@ -257,67 +321,7 @@ public class LoginPanel extends Window implements EventListener<Event>
|
||||||
pnlButtons.getButton(ConfirmPanel.A_OK).setSclass(ITheme.LOGIN_BUTTON_CLASS);
|
pnlButtons.getButton(ConfirmPanel.A_OK).setSclass(ITheme.LOGIN_BUTTON_CLASS);
|
||||||
div.appendChild(pnlButtons);
|
div.appendChild(pnlButtons);
|
||||||
this.appendChild(div);
|
this.appendChild(div);
|
||||||
|
}
|
||||||
txtUserId.addEventListener(TokenEvent.ON_USER_TOKEN, new EventListener<Event>() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onEvent(Event event) throws Exception {
|
|
||||||
String[] data = (String[]) event.getData();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
int AD_Session_ID = Integer.parseInt(data[0]);
|
|
||||||
MSession session = new MSession(Env.getCtx(), AD_Session_ID, null);
|
|
||||||
if (session.get_ID() == AD_Session_ID)
|
|
||||||
{
|
|
||||||
int AD_User_ID = session.getCreatedBy();
|
|
||||||
MUser user = MUser.get(Env.getCtx(), AD_User_ID);
|
|
||||||
if (user != null && user.get_ID() == AD_User_ID)
|
|
||||||
{
|
|
||||||
String token = data[1];
|
|
||||||
if (BrowserToken.validateToken(session, user, token))
|
|
||||||
{
|
|
||||||
if (MSystem.isZKRememberUserAllowed()) {
|
|
||||||
if (email_login) {
|
|
||||||
txtUserId.setValue(user.getEMail());
|
|
||||||
} else {
|
|
||||||
if (user.getLDAPUser() != null && user.getLDAPUser().length() > 0) {
|
|
||||||
txtUserId.setValue(user.getLDAPUser());
|
|
||||||
} else {
|
|
||||||
txtUserId.setValue(user.getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
onUserIdChange(AD_User_ID);
|
|
||||||
chkRememberMe.setChecked(true);
|
|
||||||
}
|
|
||||||
if (MSystem.isZKRememberPasswordAllowed()) {
|
|
||||||
txtPassword.setValue(token);
|
|
||||||
txtPassword.setAttribute("user.token.hash", token);
|
|
||||||
txtPassword.setAttribute("user.token.sid", AD_Session_ID);
|
|
||||||
}
|
|
||||||
chkSelectRole.setChecked(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
//safe to ignore
|
|
||||||
if (logger.isLoggable(Level.INFO))logger.log(Level.INFO, e.getLocalizedMessage(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Make the default language the language of client System
|
|
||||||
String defaultLanguage = MClient.get(ctx, 0).getAD_Language();
|
|
||||||
for(int i = 0; i < lstLanguage.getItemCount(); i++)
|
|
||||||
{
|
|
||||||
Comboitem li = lstLanguage.getItemAtIndex(i);
|
|
||||||
if (li.getValue().equals(defaultLanguage))
|
|
||||||
{
|
|
||||||
lstLanguage.setSelectedIndex(i);
|
|
||||||
languageChanged(li.getLabel());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initComponents()
|
private void initComponents()
|
||||||
{
|
{
|
||||||
|
@ -372,7 +376,7 @@ public class LoginPanel extends Window implements EventListener<Event>
|
||||||
chkSelectRole = new Checkbox(Msg.getMsg(Language.getBaseAD_Language(), "SelectRole"));
|
chkSelectRole = new Checkbox(Msg.getMsg(Language.getBaseAD_Language(), "SelectRole"));
|
||||||
chkSelectRole.setId("chkSelectRole");
|
chkSelectRole.setId("chkSelectRole");
|
||||||
|
|
||||||
btnResetPassword = new ToolBarButton(Msg.getMsg(Language.getBaseAD_Language(), "ForgotMyPassword"));
|
btnResetPassword = new A(Msg.getMsg(Language.getBaseAD_Language(), "ForgotMyPassword"));
|
||||||
btnResetPassword.setId("btnResetPassword");
|
btnResetPassword.setId("btnResetPassword");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -78,24 +78,24 @@ public class RolePanel extends Window implements EventListener<Event>, Deferrabl
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = 1071903027424763936L;
|
private static final long serialVersionUID = 1071903027424763936L;
|
||||||
|
|
||||||
private LoginWindow wndLogin;
|
protected LoginWindow wndLogin;
|
||||||
private Login login;
|
protected Login login;
|
||||||
|
|
||||||
private Combobox lstRole, lstClient, lstOrganisation, lstWarehouse;
|
protected Combobox lstRole, lstClient, lstOrganisation, lstWarehouse;
|
||||||
private Label lblRole, lblClient, lblOrganisation, lblWarehouse, lblDate;
|
protected Label lblRole, lblClient, lblOrganisation, lblWarehouse, lblDate;
|
||||||
private WDateEditor lstDate;
|
protected WDateEditor lstDate;
|
||||||
private Button btnOk, btnCancel;
|
protected Button btnOk, btnCancel;
|
||||||
|
|
||||||
/** Context */
|
/** Context */
|
||||||
private Properties m_ctx;
|
protected Properties m_ctx;
|
||||||
/** Username */
|
/** Username */
|
||||||
private String m_userName;
|
protected String m_userName;
|
||||||
/** Password */
|
/** Password */
|
||||||
private KeyNamePair[] m_clientKNPairs;
|
protected KeyNamePair[] m_clientKNPairs;
|
||||||
|
|
||||||
private UserPreference m_userpreference=null;
|
protected UserPreference m_userpreference=null;
|
||||||
|
|
||||||
private boolean m_show = true;
|
protected boolean m_show = true;
|
||||||
|
|
||||||
public RolePanel(Properties ctx, LoginWindow loginWindow, String userName, boolean show, KeyNamePair[] clientsKNPairs) {
|
public RolePanel(Properties ctx, LoginWindow loginWindow, String userName, boolean show, KeyNamePair[] clientsKNPairs) {
|
||||||
this.wndLogin = loginWindow;
|
this.wndLogin = loginWindow;
|
||||||
|
@ -138,7 +138,11 @@ public class RolePanel extends Window implements EventListener<Event>, Deferrabl
|
||||||
private void init()
|
private void init()
|
||||||
{
|
{
|
||||||
Clients.response(new AuScript("zAu.cmd0.clearBusy()"));
|
Clients.response(new AuScript("zAu.cmd0.clearBusy()"));
|
||||||
Div div = new Div();
|
createUI();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void createUI() {
|
||||||
|
Div div = new Div();
|
||||||
div.setSclass(ITheme.LOGIN_BOX_HEADER_CLASS);
|
div.setSclass(ITheme.LOGIN_BOX_HEADER_CLASS);
|
||||||
Label label = new Label("Login");
|
Label label = new Label("Login");
|
||||||
label.setSclass(ITheme.LOGIN_BOX_HEADER_TXT_CLASS);
|
label.setSclass(ITheme.LOGIN_BOX_HEADER_TXT_CLASS);
|
||||||
|
@ -236,7 +240,7 @@ public class RolePanel extends Window implements EventListener<Event>, Deferrabl
|
||||||
pnlButtons.getButton(ConfirmPanel.A_CANCEL).setSclass(ITheme.LOGIN_BUTTON_CLASS);
|
pnlButtons.getButton(ConfirmPanel.A_CANCEL).setSclass(ITheme.LOGIN_BUTTON_CLASS);
|
||||||
div.appendChild(pnlButtons);
|
div.appendChild(pnlButtons);
|
||||||
this.appendChild(div);
|
this.appendChild(div);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initComponents()
|
private void initComponents()
|
||||||
{
|
{
|
||||||
|
|
|
@ -59,12 +59,12 @@ public class LoginWindow extends FWindow implements EventListener<Event>
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = -5169830531440825871L;
|
private static final long serialVersionUID = -5169830531440825871L;
|
||||||
|
|
||||||
private IWebClient app;
|
protected IWebClient app;
|
||||||
private Properties ctx;
|
protected Properties ctx;
|
||||||
private LoginPanel pnlLogin;
|
protected LoginPanel pnlLogin;
|
||||||
private ResetPasswordPanel pnlResetPassword;
|
protected ResetPasswordPanel pnlResetPassword;
|
||||||
private ChangePasswordPanel pnlChangePassword;
|
protected ChangePasswordPanel pnlChangePassword;
|
||||||
private RolePanel pnlRole;
|
protected RolePanel pnlRole;
|
||||||
|
|
||||||
public LoginWindow() {}
|
public LoginWindow() {}
|
||||||
|
|
||||||
|
@ -82,31 +82,50 @@ public class LoginWindow extends FWindow implements EventListener<Event>
|
||||||
|
|
||||||
private void initComponents()
|
private void initComponents()
|
||||||
{
|
{
|
||||||
pnlLogin = new LoginPanel(ctx, this);
|
createLoginPanel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void createLoginPanel() {
|
||||||
|
pnlLogin = new LoginPanel(ctx, this);
|
||||||
|
}
|
||||||
|
|
||||||
public void loginOk(String userName, boolean show, KeyNamePair[] clientsKNPairs)
|
public void loginOk(String userName, boolean show, KeyNamePair[] clientsKNPairs)
|
||||||
{
|
{
|
||||||
pnlRole = new RolePanel(ctx, this, userName, show, clientsKNPairs);
|
createRolePanel(userName, show, clientsKNPairs);
|
||||||
this.getChildren().clear();
|
this.getChildren().clear();
|
||||||
this.appendChild(pnlRole);
|
this.appendChild(pnlRole);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void createRolePanel(String userName, boolean show,
|
||||||
|
KeyNamePair[] clientsKNPairs) {
|
||||||
|
pnlRole = new RolePanel(ctx, this, userName, show, clientsKNPairs);
|
||||||
|
}
|
||||||
|
|
||||||
public void changePassword(String userName, String userPassword, boolean show, KeyNamePair[] clientsKNPairs)
|
public void changePassword(String userName, String userPassword, boolean show, KeyNamePair[] clientsKNPairs)
|
||||||
{
|
{
|
||||||
Clients.clearBusy();
|
Clients.clearBusy();
|
||||||
pnlChangePassword = new ChangePasswordPanel(ctx, this, userName, userPassword, show, clientsKNPairs);
|
createChangePasswordPanel(userName, userPassword, show, clientsKNPairs);
|
||||||
this.getChildren().clear();
|
this.getChildren().clear();
|
||||||
this.appendChild(pnlChangePassword);
|
this.appendChild(pnlChangePassword);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void createChangePasswordPanel(String userName,
|
||||||
|
String userPassword, boolean show, KeyNamePair[] clientsKNPairs) {
|
||||||
|
pnlChangePassword = new ChangePasswordPanel(ctx, this, userName, userPassword, show, clientsKNPairs);
|
||||||
|
}
|
||||||
|
|
||||||
public void resetPassword(String userName, boolean noSecurityQuestion)
|
public void resetPassword(String userName, boolean noSecurityQuestion)
|
||||||
{
|
{
|
||||||
pnlResetPassword = new ResetPasswordPanel(ctx, this, userName, noSecurityQuestion);
|
createResetPasswordPanel(userName, noSecurityQuestion);
|
||||||
this.getChildren().clear();
|
this.getChildren().clear();
|
||||||
this.appendChild(pnlResetPassword);
|
this.appendChild(pnlResetPassword);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void createResetPasswordPanel(String userName,
|
||||||
|
boolean noSecurityQuestion) {
|
||||||
|
pnlResetPassword = new ResetPasswordPanel(ctx, this, userName, noSecurityQuestion);
|
||||||
|
}
|
||||||
|
|
||||||
public void loginCompleted()
|
public void loginCompleted()
|
||||||
{
|
{
|
||||||
app.loginCompleted();
|
app.loginCompleted();
|
||||||
|
@ -114,7 +133,7 @@ public class LoginWindow extends FWindow implements EventListener<Event>
|
||||||
|
|
||||||
public void loginCancelled()
|
public void loginCancelled()
|
||||||
{
|
{
|
||||||
pnlLogin = new LoginPanel(ctx, this);
|
createLoginPanel();
|
||||||
this.getChildren().clear();
|
this.getChildren().clear();
|
||||||
this.appendChild(pnlLogin);
|
this.appendChild(pnlLogin);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue