From 839f02d82347fd4e9d47576eda669b3c5f4f7f79 Mon Sep 17 00:00:00 2001 From: Carlos Augusto Sanchez Date: Thu, 18 Jul 2013 16:20:29 -0500 Subject: [PATCH] IDEMPIERE-984 Change Role and Logout must check for unsaved records on open windows / use case 1 --- .../oracle/20130717091459_IDEMPIERE-984.sql | 10 ++++ .../20130717091459_IDEMPIERE-984.sql | 11 ++++ .../adwindow/AbstractADWindowContent.java | 5 ++ .../webui/desktop/AbstractDesktop.java | 5 ++ .../webui/desktop/DefaultDesktop.java | 17 ++++++ .../org/adempiere/webui/desktop/IDesktop.java | 2 + .../org/adempiere/webui/panel/UserPanel.java | 52 +++++++++++++++++-- 7 files changed, 98 insertions(+), 4 deletions(-) create mode 100644 migration/i1.0c-release/oracle/20130717091459_IDEMPIERE-984.sql create mode 100644 migration/i1.0c-release/postgresql/20130717091459_IDEMPIERE-984.sql diff --git a/migration/i1.0c-release/oracle/20130717091459_IDEMPIERE-984.sql b/migration/i1.0c-release/oracle/20130717091459_IDEMPIERE-984.sql new file mode 100644 index 0000000000..1c2b601aeb --- /dev/null +++ b/migration/i1.0c-release/oracle/20130717091459_IDEMPIERE-984.sql @@ -0,0 +1,10 @@ +-- Jul 17, 2013 9:14:59 AM COT +-- IDEMPIERE-984 Change Role and Logout must check for unsaved records on open windows +INSERT INTO AD_Message (MsgType,MsgText,MsgTip,AD_Message_ID,EntityType,AD_Message_UU,Value,IsActive,Updated,CreatedBy,UpdatedBy,AD_Org_ID,Created,AD_Client_ID) VALUES ('I','There are records that haven''t been saved yet. ','Do you still want to proceed?',200207,'D','78553b48-d536-4366-90ee-7fc69e80f35a','ProceedWithTask?','Y',TO_DATE('2013-07-17 09:14:58','YYYY-MM-DD HH24:MI:SS'),100,100,0,TO_DATE('2013-07-17 09:14:58','YYYY-MM-DD HH24:MI:SS'),0) +; + +-- Jul 17, 2013 9:14:59 AM COT +-- IDEMPIERE-984 Change Role and Logout must check for unsaved records on open windows +INSERT INTO AD_Message_Trl (AD_Language,AD_Message_ID, MsgText,MsgTip, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy,AD_Message_Trl_UU ) SELECT l.AD_Language,t.AD_Message_ID, t.MsgText,t.MsgTip, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy,Generate_UUID() FROM AD_Language l, AD_Message t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Message_ID=200207 AND NOT EXISTS (SELECT * FROM AD_Message_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Message_ID=t.AD_Message_ID) +; +SELECT register_migration_script('20130717091459_IDEMPIERE-984.sql') FROM dual diff --git a/migration/i1.0c-release/postgresql/20130717091459_IDEMPIERE-984.sql b/migration/i1.0c-release/postgresql/20130717091459_IDEMPIERE-984.sql new file mode 100644 index 0000000000..7c56888df9 --- /dev/null +++ b/migration/i1.0c-release/postgresql/20130717091459_IDEMPIERE-984.sql @@ -0,0 +1,11 @@ +-- Jul 17, 2013 9:14:59 AM COT +-- IDEMPIERE-984 Change Role and Logout must check for unsaved records on open windows +INSERT INTO AD_Message (MsgType,MsgText,MsgTip,AD_Message_ID,EntityType,AD_Message_UU,Value,IsActive,Updated,CreatedBy,UpdatedBy,AD_Org_ID,Created,AD_Client_ID) VALUES ('I','There are records that haven''t been saved yet. ','Do you still want to proceed?',200207,'D','78553b48-d536-4366-90ee-7fc69e80f35a','ProceedWithTask?','Y',TO_TIMESTAMP('2013-07-17 09:14:58','YYYY-MM-DD HH24:MI:SS'),100,100,0,TO_TIMESTAMP('2013-07-17 09:14:58','YYYY-MM-DD HH24:MI:SS'),0) +; + +-- Jul 17, 2013 9:14:59 AM COT +-- IDEMPIERE-984 Change Role and Logout must check for unsaved records on open windows +INSERT INTO AD_Message_Trl (AD_Language,AD_Message_ID, MsgText,MsgTip, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy,AD_Message_Trl_UU ) SELECT l.AD_Language,t.AD_Message_ID, t.MsgText,t.MsgTip, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy,Generate_UUID() FROM AD_Language l, AD_Message t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Message_ID=200207 AND NOT EXISTS (SELECT * FROM AD_Message_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Message_ID=t.AD_Message_ID) +; + +SELECT register_migration_script('20130717091459_IDEMPIERE-984.sql') FROM dual diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/AbstractADWindowContent.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/AbstractADWindowContent.java index 47e3d91660..e1ec1dcaad 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/AbstractADWindowContent.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/AbstractADWindowContent.java @@ -2931,4 +2931,9 @@ public abstract class AbstractADWindowContent extends AbstractUIPart implements LayoutUtils.openEmbeddedWindow(getComponent().getParent(), findWindow, "overlap"); } } + + public boolean isPendingChanges() { + return boolChanges; + } + } diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/desktop/AbstractDesktop.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/desktop/AbstractDesktop.java index 54e7e48380..85e656ffef 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/desktop/AbstractDesktop.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/desktop/AbstractDesktop.java @@ -295,4 +295,9 @@ public abstract class AbstractDesktop extends AbstractUIPart implements IDesktop win.setPage(page); win.doHighlighted(); } + + protected List getWindows(){ + return windows; + } + } diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/desktop/DefaultDesktop.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/desktop/DefaultDesktop.java index 253624c85f..62b739ee64 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/desktop/DefaultDesktop.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/desktop/DefaultDesktop.java @@ -18,6 +18,7 @@ package org.adempiere.webui.desktop; import java.io.Serializable; +import java.util.List; import java.util.Map; import java.util.Properties; @@ -26,6 +27,7 @@ import org.adempiere.base.event.IEventManager; import org.adempiere.base.event.IEventTopics; import org.adempiere.model.MBroadcastMessage; import org.adempiere.util.ServerContext; +import org.adempiere.webui.adwindow.ADWindow; import org.adempiere.webui.apps.AEnv; import org.adempiere.webui.apps.BusyDialog; import org.adempiere.webui.apps.ProcessDialog; @@ -593,4 +595,19 @@ public class DefaultDesktop extends TabbedDesktop implements MenuListener, Seria super.openTask(taskId); updateHelpContext(X_AD_CtxHelp.CTXTYPE_Task, taskId); } + + public boolean isPendingWindow() { + List windows = getWindows(); + if (windows != null) { + for (int idx = 0; idx < windows.size(); idx++) { + Object ad = windows.get(idx); + if (ad != null && ad instanceof ADWindow) { + if ( ((ADWindow)ad).getADWindowContent().isPendingChanges()) { + return true; + } + } + } + } + return false; + } } diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/desktop/IDesktop.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/desktop/IDesktop.java index 7c12de8ca5..4a8b670e75 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/desktop/IDesktop.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/desktop/IDesktop.java @@ -204,4 +204,6 @@ public interface IDesktop extends UIPart { public void updateHelpContext(String ctxType, int recordId); public void updateHelpTooltip(GridField gridField); + + public boolean isPendingWindow(); } diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/UserPanel.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/UserPanel.java index 354ef58b69..d910b0f261 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/UserPanel.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/UserPanel.java @@ -17,13 +17,16 @@ package org.adempiere.webui.panel; + import java.util.Properties; +import org.adempiere.util.Callback; import org.adempiere.webui.component.Label; import org.adempiere.webui.component.Menupopup; import org.adempiere.webui.component.Messagebox; import org.adempiere.webui.session.SessionManager; import org.adempiere.webui.util.FeedbackManager; +import org.adempiere.webui.window.FDialog; import org.adempiere.webui.window.WPreference; import org.compiere.model.MClient; import org.compiere.model.MOrg; @@ -136,14 +139,34 @@ public class UserPanel implements EventListener, Composer return "*"; } } - public void onEvent(Event event) throws Exception { if (event == null) return; if (logout == event.getTarget()) { - SessionManager.logoutSession(); + component.addEventListener("onLogout", new EventListener() { + @Override + public void onEvent(Event event) throws Exception { + SessionManager.logoutSession(); + } + }); + + if (SessionManager.getAppDesktop().isPendingWindow()) { + FDialog.ask(0, component, "ProceedWithTask?", new Callback() { + + @Override + public void onCallback(Boolean result) + { + if (result) + { + Events.echoEvent(new Event("onLogout", component)); + } + } + }); + } else { + SessionManager.logoutSession(); + } } else if (lblUserNameValue == event.getTarget()) { @@ -153,8 +176,29 @@ public class UserPanel implements EventListener, Composer } else if (changeRole == event.getTarget()) { - MUser user = MUser.get(ctx); - SessionManager.changeRole(user); + component.addEventListener("onChangeRole", new EventListener() { + @Override + public void onEvent(Event event) throws Exception { + MUser user = MUser.get(ctx); + SessionManager.changeRole(user); + } + }); + if (SessionManager.getAppDesktop().isPendingWindow()) { + FDialog.ask(0, component, "ProceedWithTask?", new Callback() { + + @Override + public void onCallback(Boolean result) + { + if (result) + { + Events.echoEvent(new Event("onChangeRole", component)); + } + } + }); + } else { + MUser user = MUser.get(ctx); + SessionManager.changeRole(user); + } } else if (preference == event.getTarget()) {