IDEMPIERE-984 Change Role and Logout must check for unsaved records on open windows / use case 1

This commit is contained in:
Carlos Augusto Sanchez 2013-07-18 16:20:29 -05:00
parent 45db44b024
commit 839f02d823
7 changed files with 98 additions and 4 deletions

View File

@ -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

View File

@ -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

View File

@ -2931,4 +2931,9 @@ public abstract class AbstractADWindowContent extends AbstractUIPart implements
LayoutUtils.openEmbeddedWindow(getComponent().getParent(), findWindow, "overlap");
}
}
public boolean isPendingChanges() {
return boolChanges;
}
}

View File

@ -295,4 +295,9 @@ public abstract class AbstractDesktop extends AbstractUIPart implements IDesktop
win.setPage(page);
win.doHighlighted();
}
protected List<Object> getWindows(){
return windows;
}
}

View File

@ -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<Object> 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;
}
}

View File

@ -204,4 +204,6 @@ public interface IDesktop extends UIPart {
public void updateHelpContext(String ctxType, int recordId);
public void updateHelpTooltip(GridField gridField);
public boolean isPendingWindow();
}

View File

@ -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,15 +139,35 @@ public class UserPanel implements EventListener<Event>, Composer<Component>
return "*";
}
}
public void onEvent(Event event) throws Exception {
if (event == null)
return;
if (logout == event.getTarget())
{
component.addEventListener("onLogout", new EventListener<Event>() {
@Override
public void onEvent(Event event) throws Exception {
SessionManager.logoutSession();
}
});
if (SessionManager.getAppDesktop().isPendingWindow()) {
FDialog.ask(0, component, "ProceedWithTask?", new Callback<Boolean>() {
@Override
public void onCallback(Boolean result)
{
if (result)
{
Events.echoEvent(new Event("onLogout", component));
}
}
});
} else {
SessionManager.logoutSession();
}
}
else if (lblUserNameValue == event.getTarget())
{
String roleInfo = MRole.getDefault().toStringX(Env.getCtx());
@ -153,9 +176,30 @@ public class UserPanel implements EventListener<Event>, Composer<Component>
}
else if (changeRole == event.getTarget())
{
component.addEventListener("onChangeRole", new EventListener<Event>() {
@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<Boolean>() {
@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())
{
if (preferencePopup != null)