2014-10-01 103 views
0

我期望根据某些过滤条件隐藏Fiori应用程序的详细信息页面中的批准/拒绝按钮。过滤器通过视图/控制器扩展添加到主列表视图(左侧视图)中。 现在,如果用户选择了某种类型的过滤器(比如过去的订单) - 那么批准/拒绝按钮不应该显示在订单明细页中。 这是我怎样在报头中定义的按钮/详细视图隐藏Fiori主页中的批准/拒绝按钮详细信息页面

this.oHeaderFooterOptions = { 
         oPositiveAction: {      
         sI18nBtnTxt: that.resourceBundle.getText("XBUT_APPROVE"), 
         id :"btn_approve", 
         onBtnPressed: jQuery.proxy(that.handleApprove, that) 
         }, 

        oNegativeAction: {     
        sI18nBtnTxt: that.resourceBundle.getText("XBUT_REJECT"), 
        id :"btn_reject", 
        onBtnPressed: jQuery.proxy(that.handleReject, that) 
        }, 

但是在运行时,这些按钮没有被分配我所提到的标识,而不是它们与__button0和__button1的ID的创建。

有没有办法从主列表视图中隐藏这些按钮?

谢谢。

回答

1

你可以打电话给你的控制器上setHeaderFooterOptions多次例如:

//Code inside of the controller 
_myHeaderFooterOptions = { 
    oPositiveAction: {      
     sI18nBtnTxt: that.resourceBundle.getText("XBUT_APPROVE"), 
     id :"btn_approve", 
      onBtnPressed: jQuery.proxy(that.handleApprove, that) 
     }, 
    oNegativeAction: {     
     sI18nBtnTxt: that.resourceBundle.getText("XBUT_REJECT"), 
     id :"btn_reject", 
     onBtnPressed: jQuery.proxy(that.handleReject, that) 
    } 
}, 

//set the initial options 
onInit: function() { 
    this.setHeaderFooterOptions(this._myHeaderFooterOptions); 
}, 

//modify the options in an event 
onFilter : function() { 
    //remove the negative action to hide it 
    this._myHeaderFooterOptions.oNegativeAction = undefined; 
    this.setHeaderFooterOptions(this._myHeaderFooterOptions); 
}, 

//further code 

所以通过操纵_myHeaderFooterOptions可以影响显示的按钮。

+0

嗨托比亚斯 - 感谢您的回复。那么问题是过滤器事件处理程序是在不同的控制器(S2列表)中定义的,并且按钮位于S3标题视图中。在这种情况下,我如何控制按钮的可见性? – user3161840 2014-10-06 15:53:29

+0

嗨,你可以在组件的事件总线上触发事件,请参阅https://openui5.hana.ondemand.com/#docs/api/symbols/sap.ui.core.Component.html。您在S3控制器中发布事件,并在S2控制器中订阅。订阅处理程序你修改headerFooterOptions – TobiasOetzel 2014-10-07 06:35:30

+0

HI Tobias - 这是一个好主意。感谢您的回复。对于迟到回来抱歉。取代全局事件总线,是否有办法获得组件的事件总线?我认为这是适当的。 – user3161840 2014-10-14 18:53:43

-1

首先,你应该使用sId代替id定义HeaderFooterOptions时,您可以通过sId得到页脚按钮,例如,批准按钮。

this._oControlStore.oButtonListHelper.mButtons["btn_approve"] 

请检查下面的代码片段:

S2.view.controller:你有一个过滤器的事件处理程序中定义以下和使用EventBus发布事件OrderTypeChangedS3.view.controller

onFilterChanged: function(oEvent) { 
    // Set the filter value, here i use hard code 
    var sFilter = "Past Orders"; 
    sap.ui.getCore().getEventBus().publish("app", "OrderTypeChanged", { 
     filter: sFilter 
    }); 
} 

S3.view.controller:从S2.view.controller订阅事件OrderTypeChanged

onInit: function() { 
    /// 
    var bus = sap.ui.getCore().getEventBus(); 
    bus.subscribe("app", "OrderTypeChanged", this.handleOrderTypeChanged, this); 

}, 

getHeaderFooterOptions: function() { 

    var oOptions = { 

     oPositiveAction: { 
      sI18nBtnTxt: that.resourceBundle.getText("XBUT_APPROVE"), 
      sId: "btn_approve", 
      onBtnPressed: jQuery.proxy(that.handleApprove, that) 
     }, 

     oNegativeAction: { 
      sI18nBtnTxt: that.resourceBundle.getText("XBUT_REJECT"), 
      sId: "btn_reject", 
      onBtnPressed: jQuery.proxy(that.handleReject, that) 
     } 
    }; 
    return oOptions; 

}, 
handleOrderTypeChanged: function(channelId, eventId, data) { 
    if (data && data.filter) { 
     var sFilter = data.filter; 
     if (sFilter == "Past Orders") { 
      this._oControlStore.oButtonListHelper.mButtons["btn_approve"].setVisible(false); 
     } 
     //set Approve/Reject button visible/invisible based on other values 
     //else if(sFilter == "Other Filter") 
    } 
} 
+0

嗨艾伦,谢谢你的回复。对于迟到回来抱歉。取代全局事件总线,是否有办法获得组件的事件总线? – user3161840 2014-10-14 18:53:19

+0

好吧,所以我得到了组件的事件总线.. var c = sap.ui.core.Component.getOwnerIdFor(this.getView()); \t \t var localEventBus = sap.ui.component(c).getEventBus(); localEventBus.publish( “zPrApp”, “showHideApprovalButtons”,{ID:sButtonId});然后在另一个视图controllerlocalEventBus.subscribe(“zPrApp”,“showHideApprovalButtons”,this.handleApprovalButtonsVisibility,this);这在桌面上运行良好,但在iPhone中失败。奇怪。手机上的错误是拒绝按钮是undefined.this._oControlStore.oButtonListHelper.mButtons只返回批准按钮..任何建议.. – user3161840 2014-10-14 21:05:11

+0

嗨,我尝试在Chrome iPhone模拟器,它是拒绝按钮的工作。奇怪。 – Allen 2014-10-15 05:50:12

2

推荐: SAP菲奥里设计原则只谈禁用页脚按钮,而不是改变Button知名度Read More here about Guidelines

基于过滤条件,您可以禁用像这样:

this.setBtnEnabled("btn_approve", false); 

再次启用:this.setBtnEnabled("btn_approve", true);

同样可以使用更改按钮文字this.setBtnText("btn_approve", "buttonText");

另一种方式:由于@TobiasOetzel表示使用

this.setHeaderFooterOptions(yourModifiedHeaderFooterOptions);