IDEMPIERE-3518 Improvement For Mobile Compatibility. Fix calendar errors on mobile devices.

This commit is contained in:
Heng Sin Low 2017-10-20 12:25:52 +08:00
parent 75a36ec2ac
commit b98154670d
5 changed files with 126 additions and 10 deletions

View File

@ -28,10 +28,11 @@ import java.util.Map;
import java.util.Properties;
import java.util.TimeZone;
import org.adempiere.webui.ClientInfo;
import org.adempiere.webui.component.Tabpanel;
import org.adempiere.webui.component.Window;
import org.adempiere.webui.panel.ITabOnCloseHandler;
import org.adempiere.webui.part.WindowContainer;
import org.adempiere.webui.session.SessionManager;
import org.adempiere.webui.theme.ThemeManager;
import org.adempiere.webui.util.ZKUpdateUtil;
@ -80,6 +81,7 @@ public class CalendarWindow extends Window implements EventListener<Event>, ITab
*
*/
private static final long serialVersionUID = 1576992746053720647L;
private static final String ON_MOBILE_SET_SELECTED_TAB_ECHO = "onMobileSetSelectedTabEcho";
private Calendars calendars;
private SimpleCalendarModel scm;
@ -187,15 +189,35 @@ public class CalendarWindow extends Window implements EventListener<Event>, ITab
calendars.addEventListener("onEventUpdate", this);
calendars.addEventListener("onMouseOver", this);
if (ClientInfo.isMobile()) {
addCallback(AFTER_PAGE_ATTACHED, t -> afterPageAttached());
addEventListener(ON_MOBILE_SET_SELECTED_TAB_ECHO, evt -> calendars.invalidate());
}
SessionManager.getAppDesktop().showWindow(this);
// IDEMPIERE-1457: when show this window on tab, handle event close to remove calendars away scm
Component parentTab = this.getParent();
if (parentTab != null && parentTab.getClass().equals(Tabpanel.class)) {
((Tabpanel)parentTab).setOnCloseHandler(this);
}
}
private void afterPageAttached() {
Component p = getParent();
while (p != null) {
if (p instanceof Tabpanel) {
p.addEventListener(WindowContainer.ON_MOBILE_SET_SELECTED_TAB, evt -> onMobileSelected());
break;
}
p = p.getParent();
}
}
private void onMobileSelected() {
Events.echoEvent(ON_MOBILE_SET_SELECTED_TAB_ECHO, this, null);
}
public void onClose(Tabpanel tabPanel){
//IDEMPIERE-1457: On close, remove calendars away scm
calendars.setModel(null);

View File

@ -30,6 +30,9 @@ import org.adempiere.base.Service;
import org.adempiere.base.event.AbstractEventHandler;
import org.adempiere.base.event.EventManager;
import org.adempiere.base.event.IEventTopics;
import org.adempiere.webui.ClientInfo;
import org.adempiere.webui.component.Tabpanel;
import org.adempiere.webui.part.WindowContainer;
import org.adempiere.webui.session.SessionManager;
import org.adempiere.webui.theme.ThemeManager;
import org.adempiere.webui.util.ServerPushTemplate;
@ -70,11 +73,12 @@ import org.zkoss.zul.impl.LabelImageElement;
*/
public class DPCalendar extends DashboardPanel implements EventListener<Event>, EventHandler {
/**
*
*/
private static final long serialVersionUID = -224914882522997787L;
private static final String ON_MOBILE_SET_SELECTED_TAB_ECHO = "onMobileSetSelectedTabEcho";
private Calendars calendars;
private SimpleCalendarModel scm;
private LabelImageElement btnCal, btnRefresh;
@ -137,6 +141,26 @@ public class DPCalendar extends DashboardPanel implements EventListener<Event>,
DPCalendar.this.cleanup();
}
};
if (ClientInfo.isMobile()) {
addCallback(AFTER_PAGE_ATTACHED, t -> afterPageAttached());
addEventListener(ON_MOBILE_SET_SELECTED_TAB_ECHO, evt -> calendars.invalidate());
}
}
private void afterPageAttached() {
Component p = getParent();
while (p != null) {
if (p instanceof Tabpanel) {
p.addEventListener(WindowContainer.ON_MOBILE_SET_SELECTED_TAB, evt -> onMobileSelected());
break;
}
p = p.getParent();
}
}
private void onMobileSelected() {
Events.echoEvent(ON_MOBILE_SET_SELECTED_TAB_ECHO, this, null);
}
private synchronized void createStaticListeners() {

View File

@ -24,9 +24,12 @@ import java.util.GregorianCalendar;
import java.util.TimeZone;
import java.util.logging.Level;
import org.adempiere.webui.ClientInfo;
import org.adempiere.webui.component.Tabpanel;
import org.adempiere.webui.component.ToolBarButton;
import org.adempiere.webui.component.Window;
import org.adempiere.webui.component.ZkCssHelper;
import org.adempiere.webui.part.WindowContainer;
import org.adempiere.webui.session.SessionManager;
import org.adempiere.webui.theme.ThemeManager;
import org.adempiere.webui.util.ZKUpdateUtil;
@ -69,6 +72,7 @@ public class WSchedule extends Window implements EventListener<Event>
*
*/
private static final long serialVersionUID = -4819513326165148245L;
private static final String ON_MOBILE_SET_SELECTED_TAB_ECHO = "onMobileSetSelectedTabEcho";
@SuppressWarnings("unused")
private InfoSchedule infoSchedule;
@ -204,7 +208,27 @@ public class WSchedule extends Window implements EventListener<Event>
divTabClicked(7);
addEventListener("onAfterReCreate", this);
} // jbInit
if (ClientInfo.isMobile()) {
addCallback(AFTER_PAGE_ATTACHED, t -> afterPageAttached());
addEventListener(ON_MOBILE_SET_SELECTED_TAB_ECHO, evt -> calendars.invalidate());
}
}
private void afterPageAttached() {
Component p = getParent();
while (p != null) {
if (p instanceof Tabpanel) {
p.addEventListener(WindowContainer.ON_MOBILE_SET_SELECTED_TAB, evt -> onMobileSelected());
break;
}
p = p.getParent();
}
}
private void onMobileSelected() {
Events.echoEvent(ON_MOBILE_SET_SELECTED_TAB_ECHO, this, null);
}
/**
* Recreate View

View File

@ -49,6 +49,8 @@ import org.zkoss.zul.Menuitem;
*/
public class WindowContainer extends AbstractUIPart implements EventListener<Event>
{
public static final String ON_MOBILE_SET_SELECTED_TAB = "onMobileSetSelectedTab";
private static final String ON_AFTER_TAB_CLOSE = "onAfterTabClose";
private static final String ON_DEFER_SET_SELECTED_TAB = "onDeferSetSelectedTab";
@ -100,8 +102,11 @@ public class WindowContainer extends AbstractUIPart implements EventListener<Eve
}
});
tabbox.addEventListener(ON_AFTER_TAB_CLOSE, evt -> {
updateMobileTabState(tabbox.getSelectedTab());
updateTabListButton();
if (isMobile()) {
updateMobileTabState(tabbox.getSelectedTab());
updateTabListButton();
tabbox.getTabs().invalidate();
}
});
Tabpanels tabpanels = new Tabpanels();
@ -474,8 +479,11 @@ public class WindowContainer extends AbstractUIPart implements EventListener<Eve
*/
public void setSelectedTab(org.zkoss.zul.Tab tab)
{
tabbox.setSelectedTab(tab);
updateMobileTabState(tab);
if (isMobile())
updateMobileTabState(tab);
tabbox.setSelectedTab(tab);
if (isMobile())
tabbox.getTabs().invalidate();
}
private void updateMobileTabState(org.zkoss.zul.Tab tab) {
@ -486,10 +494,12 @@ public class WindowContainer extends AbstractUIPart implements EventListener<Eve
if (c instanceof Tab) {
Tab t = (Tab) c;
t.setVisible(t == tab);
t.getLinkedPanel().setVisible(t == tab);
t.getLinkedPanel().setVisible(t == tab);
if (t.isVisible()) {
Events.postEvent(ON_MOBILE_SET_SELECTED_TAB, t.getLinkedPanel(), null);
}
}
}
tabbox.getTabs().invalidate();
}
}
}

View File

@ -215,6 +215,42 @@ Copyright (C) 2007 Ashley G Ramdass.
return '[ ' + (acp * psz + 1) + dash + ' / ' + tsz + ' ]';
});
});
zk.afterLoad('calendar', function () {
zk.override(calendar.Event.prototype, "calculate_", function () {
if (typeof this.event === "undefined" || this.event == null) {
return;
}
this.$calculate_.apply(this, arguments);
});
zk.override(calendar.Event.prototype, "unbind_", function() {
var node = this.$n();
if (typeof node === "undefined") {
return;
}
if (typeof this.$unbind_ === "undefined") {
return;
}
this.$unbind_.apply(this, arguments);
});
zk.override(calendar.CalendarsMonth.prototype, "onSize", function () {
var cmp = this.$n();
if (typeof cmp === "undefined" || cmp == null) {
return;
}
this.$onSize.apply(this, arguments);
});
zk.override(calendar.CalendarsDefault.prototype, "onSize", function () {
var cmp = this.$n();
if (typeof cmp === "undefined" || cmp == null) {
return;
}
this.$onSize.apply(this, arguments);
});
});
]]>
</script>