欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Hybris- how to disable cancle/refund button in cscokpit

程序员文章站 2022-05-16 16:16:23
...

 如何在 CSCokpit 中 disable掉 order cancle,order refund 等button?

 

这里有这样一个类:

 

 

/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package de.hybris.platform.cscockpit.widgets.renderers.impl;

import de.hybris.platform.cockpit.session.UISession;
import de.hybris.platform.cockpit.session.UISessionUtils;
import de.hybris.platform.cockpit.util.UITools;
import de.hybris.platform.cockpit.widgets.Widget;
import de.hybris.platform.cockpit.widgets.models.impl.DefaultItemWidgetModel;
import de.hybris.platform.cscockpit.utils.LabelUtils;
import de.hybris.platform.cscockpit.widgets.controllers.OrderManagementActionsWidgetController;
import de.hybris.platform.cscockpit.widgets.renderers.utils.PopupWidgetHelper;
import org.springframework.beans.factory.annotation.Required;
import org.zkoss.zk.ui.api.HtmlBasedComponent;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zul.Button;
import org.zkoss.zul.Div;
// extends 这个类
public class OrderManagementActionsWidgetRenderer extends AbstractCsWidgetRenderer<Widget<DefaultItemWidgetModel, OrderManagementActionsWidgetController>>
{
  protected static final String CSS_ORDER_MANAGEMENT_ACTIONS_WIDGET = "orderManagementActionsWidget";
  protected static final String CSS_FULL_CANCEL_POPUP = "csFullCancelPopup";
  protected static final String CSS_PARTIAL_CANCEL_POPUP = "csPartialCancelPopup";
  protected static final String CSS_RETURN_REQUEST_CREATE_WIDGET = "csReturnRequestCreateWidget";
  protected static final String COCKPIT_ID_CANCEL_ORDER = "Order_Order_Management_Cancel_Order_button";
  protected static final String COCKPIT_ID_PARTIAL_CANCEL_ORDER = "Order_Order_Management_Partial_Cancel_Order_button";
  protected static final String COCKPIT_ID_REFUND_ORDER = "Order_Order_Management_Refund_Order_button";
  protected static final String COCKPIT_ID_REPLACE_ORDER = "Order_Order_Management_Replace_Order_button";
  private PopupWidgetHelper popupWidgetHelper;

  protected PopupWidgetHelper getPopupWidgetHelper()
  {
    return this.popupWidgetHelper;
  }

  @Required
  public void setPopupWidgetHelper(PopupWidgetHelper popupWidgetHelper)
  {
    this.popupWidgetHelper = popupWidgetHelper;
  }

//override 这个方法,添加你的逻辑
  protected HtmlBasedComponent createContentInternal(Widget<DefaultItemWidgetModel, OrderManagementActionsWidgetController> widget, HtmlBasedComponent rootContainer)
  {
    Div component = new Div();
    component.setSclass("orderManagementActionsWidget");

    createButton(widget, component, "cancelWholeOrder", "csFullOrderCancellationWidgetConfig", "csFullOrderCancel-Popup", 
      "csFullCancelPopup", "popup.fullCancellationRequestCreate", !(((OrderManagementActionsWidgetController)widget.getWidgetController()).isFullCancelPossible()));
    createButton(widget, component, "cancelPartialOrder", "csPartialOrderCancellationWidgetConfig", 
      "csPartialOrderCancellationWidgetConfig-Popup", "csPartialCancelPopup", "popup.partialCancellationRequestCreate", 
      !(((OrderManagementActionsWidgetController)widget.getWidgetController()).isPartialCancelPossible()));
    createButton(widget, component, "refundOrder", "csRefundRequestCreateWidgetConfig", "csRefundRequestCreateWidget-Popup", 
      "csReturnRequestCreateWidget", "popup.refundRequestCreate", !(((OrderManagementActionsWidgetController)widget.getWidgetController()).isRefundPossible()));
    createButton(widget, component, "replaceOrder", "csReplacementRequestCreateWidgetConfig", 
      "csReplacementRequestCreateWidget-Popup", "csReturnRequestCreateWidget", "popup.replacementRequestCreate", 
      !(((OrderManagementActionsWidgetController)widget
      .getWidgetController()).isReplacePossible()));

    return component;
  }

  protected void createButton(Widget<DefaultItemWidgetModel, OrderManagementActionsWidgetController> widget, Div container, String buttonLabelName, String springWidgetName, String popupCode, String cssClass, String popupTitleLabelName, boolean disabled)
  {
    EventListener eventListener = new EventListener(widget, container, springWidgetName, popupCode, cssClass, popupTitleLabelName)
    {
      public void onEvent(Event event)
        throws Exception
      {
        OrderManagementActionsWidgetRenderer.this.handleButtonClickEvent(this.val$widget, event, this.val$container, this.val$springWidgetName, this.val$popupCode, this.val$cssClass, this.val$popupTitleLabelName);
      }
    };
    createButton(widget, container, buttonLabelName, eventListener, disabled);
  }

  protected void handleButtonClickEvent(Widget<DefaultItemWidgetModel, OrderManagementActionsWidgetController> widget, Event event, Div container, String springWidgetName, String popupCode, String cssClass, String popupTitleLabelName)
  {
    getPopupWidgetHelper().createPopupWidget(container, springWidgetName, popupCode, cssClass, 
      LabelUtils.getLabel(widget, popupTitleLabelName, new Object[0]), 1000);
  }

  protected void createButton(Widget widget, Div container, String buttonLabelName, EventListener eventListener, boolean disabled)
  {
    Button button = new Button();

    if (UISessionUtils.getCurrentSession().isUsingTestIDs())
    {
      if ("cancelWholeOrder".equals(buttonLabelName))
      {
        UITools.applyTestID(button, "Order_Order_Management_Cancel_Order_button");
      }
      else if ("cancelPartialOrder".equals(buttonLabelName))
      {
        UITools.applyTestID(button, "Order_Order_Management_Partial_Cancel_Order_button");
      }
      else if ("refundOrder".equals(buttonLabelName))
      {
        UITools.applyTestID(button, "Order_Order_Management_Refund_Order_button");
      }
      else if ("replaceOrder".equals(buttonLabelName))
      {
        UITools.applyTestID(button, "Order_Order_Management_Replace_Order_button");
      }
    }

    button.setLabel(LabelUtils.getLabel(widget, buttonLabelName, new Object[0]));
    button.setParent(container);
    button.setDisabled(disabled);
    button.addEventListener("onClick", eventListener);
  }
}

 

所以这里很简单 ,只要extends这个类 再override上面的方法,添加你的逻辑就OK了,如下

public class MyOrderManagementActionsWidgetRenderer extends OrderManagementActionsWidgetRenderer
{
	private static final Logger LOG = Logger.getLogger(VirginOrderManagementActionsWidgetRenderer.class);
	private UserService userService;
	private static String CREDITCARD = "creditcard";
	@Override
	protected HtmlBasedComponent createContentInternal(
			final Widget<DefaultItemWidgetModel, OrderManagementActionsWidgetController> widget,
			final HtmlBasedComponent rootContainer)
	{

		String paymentMode = getPaymentModeCode(widget);	
		final Div component = new Div();
		component.setSclass("orderManagementActionsWidget");
		Boolean canCancel=false;
		for(ConsignmentStatus status:getConsignmentStatus(widget)){
			if(ConsignmentStatus.PACKED.equals(status)||ConsignmentStatus.SHIPPED.equals(status)){// PACKED/SHIPPED/READY FOR COLLECTION/ COLLECTED.
				canCancel=false;
				break;
			}else if(ConsignmentStatus.READY.equals(status)||ConsignmentStatus.PICKPACK.equals(status)||ConsignmentStatus.NOT_COLLECTED.equals(status)){//READY/PICKPACK/PICKPACK/PICKPACK/PICKPACK
				canCancel=true;
			}
		}
		createButton(widget, component, "cancelWholeOrder",
				"csFullOrderCancellationWidgetConfig",
				"csFullOrderCancel-Popup", "csFullCancelPopup",
				"popup.fullCancellationRequestCreate",
				!canCancel);