IDEMPIERE-3563 Improvement to Process/COG toolbar button popup.

This commit is contained in:
Heng Sin Low 2017-11-20 10:28:31 +08:00
parent 1c0e3c54b6
commit 68f7100ac0
6 changed files with 169 additions and 56 deletions

View File

@ -2974,7 +2974,7 @@ public abstract class AbstractADWindowContent extends AbstractUIPart implements
Clients.response(new AuScript(script.toString()));
}
private void executeButtonProcess(final IProcessButton wButton,
public void executeButtonProcess(final IProcessButton wButton,
final boolean startWOasking, final int table_ID, final int record_ID,
boolean isProcessMandatory) {
/**
@ -3271,8 +3271,10 @@ public abstract class AbstractADWindowContent extends AbstractUIPart implements
popup.setWidgetAttribute(AdempiereWebUI.WIDGET_INSTANCE_NAME, "processButtonPopup");
ADTabpanel adtab = (ADTabpanel) adTabbox.getSelectedTabpanel();
popup.render(adtab.getToolbarButtons());
LayoutUtils.openPopupWindow(toolbar.getButton("Process"), popup, "after_start");
if (popup.getChildren().size() > 0) {
popup.setPage(this.getComponent().getPage());
popup.open(getToolbar().getButton("Process"), "after_start");
}
}
@Override

View File

@ -434,8 +434,10 @@ public class DetailPane extends Panel implements EventListener<Event>, IdSpace {
ProcessButtonPopup popup = new ProcessButtonPopup();
ADTabpanel adtab = (ADTabpanel) getSelectedADTabpanel();
popup.render(adtab.getToolbarButtons());
LayoutUtils.openPopupWindow(button, popup, "after_start");
if (popup.getChildren().size() > 0) {
popup.setPage(button.getPage());
popup.open(button, "after_start");
}
}
/**

View File

@ -5,41 +5,108 @@ package org.adempiere.webui.adwindow;
import java.util.List;
import org.adempiere.webui.component.Window;
import org.adempiere.webui.util.ZKUpdateUtil;
import org.adempiere.util.Callback;
import org.adempiere.webui.component.Menupopup;
import org.adempiere.webui.editor.IProcessButton;
import org.adempiere.webui.editor.WButtonEditor;
import org.adempiere.webui.panel.WDocActionPanel;
import org.compiere.model.GridTab;
import org.compiere.util.Env;
import org.compiere.util.Msg;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zul.Button;
import org.zkoss.zul.Vbox;
import org.zkoss.zul.Listitem;
import org.zkoss.zul.Menu;
import org.zkoss.zul.Menuitem;
import org.zkoss.zul.Menuseparator;
/**
* @author hengsin
*
*/
public class ProcessButtonPopup extends Window {
public class ProcessButtonPopup extends Menupopup implements EventListener<Event> {
private static final String DOCUMENT_ACTION_MENUITEM_ATTRIBUTE = "document-action-menuitem";
private static final String DOC_ACTION_PANEL_ATTRIBUTE = "doc-action-panel";
private static final String BUTTON_ATTRIBUTE = "button";
/**
* generated serial id
*/
private static final long serialVersionUID = 304878472233552113L;
public void render(List<Button> buttons) {
setSclass("toolbar-popup-window process-buttons-popup");
//setWidth("250px");
ZKUpdateUtil.setHflex(this, "min");
setBorder("normal");
Vbox vbox = new Vbox();
ZKUpdateUtil.setHflex(vbox, "true");
appendChild(vbox);
vbox.setSclass("toolbar-popup-window-cnt");
vbox.setAlign("stretch");
this.setSclass("z-menu-noimage");
//process button
Button docActionBtn = null;
for(Button button : buttons) {
if (button.getPage() != null) {
button.detach();
}
ZKUpdateUtil.setHflex(button, "1");
vbox.appendChild(button);
if ("DocAction".equals(button.getId())) {
docActionBtn = button;
continue;
}
Menuitem mi = new Menuitem(button.getLabel());
appendChild(mi);
mi.setAttribute(BUTTON_ATTRIBUTE, button);
mi.addEventListener(Events.ON_CLICK, this);
if (button.isDisabled())
mi.setDisabled(true);
}
//document actions
if (docActionBtn != null) {
IProcessButton processButton = (IProcessButton) docActionBtn.getAttribute(WButtonEditor.EDITOR_ATTRIBUTE);
WDocActionPanel actionPanel = new WDocActionPanel(processButton.getADTabpanel().getGridTab());
List<Listitem> actions = actionPanel.getDocActionItems();
if (actions.size() > 0) {
if (this.getChildren().size() > 0)
appendChild(new Menuseparator());
Menu menu = new Menu(Msg.getElement(Env.getCtx(), "DocAction"));
appendChild(menu);
Menupopup popup = new Menupopup();
popup.setAttribute(BUTTON_ATTRIBUTE, docActionBtn);
popup.setAttribute(DOC_ACTION_PANEL_ATTRIBUTE, actionPanel);
popup.setSclass("z-menu-noimage");
menu.appendChild(popup);
menu.setSclass("z-menu-noimage");
for(Listitem action : actions) {
Menuitem mi = new Menuitem(action.getLabel());
mi.setValue((String)action.getValue());
mi.setSclass(DOCUMENT_ACTION_MENUITEM_ATTRIBUTE);
mi.addEventListener(Events.ON_CLICK, this);
popup.appendChild(mi);
}
}
}
}
}
@Override
public void onEvent(Event event) throws Exception {
Menuitem mi = (Menuitem) event.getTarget();
if (DOCUMENT_ACTION_MENUITEM_ATTRIBUTE.equals(mi.getSclass())) {
final Button button = (Button) mi.getParent().getAttribute(BUTTON_ATTRIBUTE);
WDocActionPanel panel = (WDocActionPanel) mi.getParent().getAttribute(DOC_ACTION_PANEL_ATTRIBUTE);
panel.setSelectedItem(mi.getValue());
panel.onOk(new Callback<Boolean>() {
@Override
public void onCallback(Boolean result) {
if (result) {
IProcessButton pb = (IProcessButton) button.getAttribute(WButtonEditor.EDITOR_ATTRIBUTE);
GridTab gridTab = pb.getADTabpanel().getGridTab();
ADWindow adwindow = ADWindow.get(gridTab.getWindowNo());
ADWindowContent windowContent = adwindow.getADWindowContent();
windowContent.executeButtonProcess(pb, true, gridTab.getAD_Table_ID(), gridTab.getRecord_ID(), true);
}
}
});
} else {
Button button = (Button) mi.getAttribute(BUTTON_ATTRIBUTE);
Events.sendEvent(Events.ON_CLICK, button, null);
}
}
}

View File

@ -55,7 +55,9 @@ import org.zkoss.zk.ui.event.Events;
*/
public class WButtonEditor extends WEditor implements IProcessButton
{
private static final String[] LISTENER_EVENTS = {Events.ON_CLICK};
public static final String EDITOR_ATTRIBUTE = "editor";
private static final String[] LISTENER_EVENTS = {Events.ON_CLICK};
private static final CLogger logger;
@ -91,6 +93,7 @@ public class WButtonEditor extends WEditor implements IProcessButton
m_text = gridField.getHeader();
AD_Process_ID = gridField.getAD_Process_ID();
gridfield = gridField;
getComponent().setAttribute(EDITOR_ATTRIBUTE, this);
init();
}

View File

@ -241,6 +241,10 @@ public class WDocActionPanel extends Window implements EventListener<Event>, Dia
DocAction = DocumentEngine.ACTION_Close;
}
public List<Listitem> getDocActionItems() {
return (List<Listitem>)lstDocAction.getItems();
}
private boolean checkStatus (String TableName, int Record_ID, String DocStatus)
{
String sql = "SELECT 2 FROM " + TableName
@ -331,39 +335,7 @@ public class WDocActionPanel extends Window implements EventListener<Event>, Dia
{
if (confirmPanel.getButton("Ok").equals(event.getTarget()))
{
MClientInfo clientInfo = MClientInfo.get(Env.getCtx());
if(clientInfo.isConfirmOnDocClose() || clientInfo.isConfirmOnDocVoid())
{
String selected = lstDocAction.getSelectedItem().getValue().toString();
if((selected.equals(org.compiere.process.DocAction.ACTION_Close) && clientInfo.isConfirmOnDocClose())
|| (selected.equals(org.compiere.process.DocAction.ACTION_Void) && clientInfo.isConfirmOnDocVoid())
|| (selected.equals(org.compiere.process.DocAction.ACTION_Reverse_Accrual) && clientInfo.isConfirmOnDocVoid())
|| (selected.equals(org.compiere.process.DocAction.ACTION_Reverse_Correct) && clientInfo.isConfirmOnDocVoid()))
{
String docAction = lstDocAction.getSelectedItem().getLabel();
MessageFormat mf = new MessageFormat(Msg.getMsg(Env.getAD_Language(Env.getCtx()), "ConfirmOnDocAction"));
Object[] arguments = new Object[]{docAction};
FDialog.ask(0, this, "", mf.format(arguments), new Callback<Boolean>() {
@Override
public void onCallback(Boolean result) {
if(result)
{
setValueAndClose();
}
else
return;
}
});
}
else
{
setValueAndClose();
}
}
else
{
setValueAndClose();
}
onOk(null);
}
else if (confirmPanel.getButton("Cancel").equals(event.getTarget()))
{
@ -381,6 +353,63 @@ public class WDocActionPanel extends Window implements EventListener<Event>, Dia
}
}
public void setSelectedItem(String value) {
lstDocAction.setSelectedIndex(-1);
List<Listitem> lst = (List<Listitem>)lstDocAction.getItems();
for(Listitem item: lst) {
if (value.equals(item.getValue())) {
item.setSelected(true);
break;
}
}
}
public void onOk(final Callback<Boolean> callback) {
MClientInfo clientInfo = MClientInfo.get(Env.getCtx());
if(clientInfo.isConfirmOnDocClose() || clientInfo.isConfirmOnDocVoid())
{
String selected = lstDocAction.getSelectedItem().getValue().toString();
if((selected.equals(org.compiere.process.DocAction.ACTION_Close) && clientInfo.isConfirmOnDocClose())
|| (selected.equals(org.compiere.process.DocAction.ACTION_Void) && clientInfo.isConfirmOnDocVoid())
|| (selected.equals(org.compiere.process.DocAction.ACTION_Reverse_Accrual) && clientInfo.isConfirmOnDocVoid())
|| (selected.equals(org.compiere.process.DocAction.ACTION_Reverse_Correct) && clientInfo.isConfirmOnDocVoid()))
{
String docAction = lstDocAction.getSelectedItem().getLabel();
MessageFormat mf = new MessageFormat(Msg.getMsg(Env.getAD_Language(Env.getCtx()), "ConfirmOnDocAction"));
Object[] arguments = new Object[]{docAction};
FDialog.ask(0, this, mf.format(arguments), new Callback<Boolean>() {
@Override
public void onCallback(Boolean result) {
if(result)
{
setValueAndClose();
if (callback != null)
callback.onCallback(Boolean.TRUE);
}
else
{
if (callback != null)
callback.onCallback(Boolean.FALSE);
return;
}
}
});
}
else
{
setValueAndClose();
if (callback != null)
callback.onCallback(Boolean.TRUE);
}
}
else
{
setValueAndClose();
if (callback != null)
callback.onCallback(Boolean.TRUE);
}
}
private void setValueAndClose() {
String statusSql = "SELECT DocStatus FROM " + gridTab.getTableName()
+ " WHERE " + gridTab.getKeyColumnName() + " = ? ";

View File

@ -178,3 +178,13 @@
font-size: larger;
}
.z-menu-noimage.z-menupopup .z-menu-content > img.z-menu-image {
display: none;
}
.z-menu-noimage.z-menupopup .z-menuitem-content > img.z-menuitem-image {
display: none;
}
.z-menu-noimage.z-menupopup > .z-menupopup-separator {
display: none;
}