generator-openui5
Version:
OpenUI5 generator for yeoman
110 lines (84 loc) • 3.29 kB
JavaScript
jQuery.sap.require("<%= fioriComponentNamespace %>.util.Formatter");
jQuery.sap.require("<%= fioriComponentNamespace %>.util.Controller");
<%= fioriComponentNamespace %>.util.Controller.extend("<%= fioriComponentNamespace %>.view.Detail", {
onInit : function() {
this.oInitialLoadFinishedDeferred = jQuery.Deferred();
if(sap.ui.Device.system.phone) {
//don't wait for the master on a phone
this.oInitialLoadFinishedDeferred.resolve();
} else {
this.getView().setBusy(true);
this.getEventBus().subscribe("Master", "InitialLoadFinished", this.onMasterLoaded, this);
}
this.getRouter().attachRouteMatched(this.onRouteMatched, this);
},
onMasterLoaded : function (sChannel, sEvent, oData) {
this.bindView(oData.oListItem.getBindingContext().getPath());
this.getView().setBusy(false);
this.oInitialLoadFinishedDeferred.resolve();
},
onRouteMatched : function(oEvent) {
var oParameters = oEvent.getParameters();
jQuery.when(this.oInitialLoadFinishedDeferred).then(jQuery.proxy(function () {
var oView = this.getView();
// when detail navigation occurs, update the binding context
if (oParameters.name !== "product") {
return;
}
var sProductPath = "/" + oParameters.arguments.product;
this.bindView(sProductPath);
var oIconTabBar = oView.byId("idIconTabBar");
oIconTabBar.getItems().forEach(function(oItem) {
oItem.bindElement(<%= fioriComponentNamespace %>.util.Formatter.uppercaseFirstChar(oItem.getKey()));
});
// Which tab?
var sTabKey = oParameters.arguments.tab || "supplier";
this.getEventBus().publish("Detail", "TabChanged", { sTabKey : sTabKey });
if (oIconTabBar.getSelectedKey() !== sTabKey) {
oIconTabBar.setSelectedKey(sTabKey);
}
}, this));
},
bindView : function (sProductPath) {
var oView = this.getView();
oView.bindElement(sProductPath);
//Check if the data is already on the client
if(!oView.getModel().getData(sProductPath)) {
// Check that the product specified actually was found.
oView.getElementBinding().attachEventOnce("dataReceived", jQuery.proxy(function() {
var oData = oView.getModel().getData(sProductPath);
if (!oData) {
this.showEmptyView();
this.fireDetailNotFound();
} else {
this.fireDetailChanged(sProductPath);
}
}, this));
} else {
this.fireDetailChanged(sProductPath);
}
},
showEmptyView : function () {
this.getRouter().myNavToWithoutHash({
currentView : this.getView(),
targetViewName : "<%= fioriComponentNamespace %>.view.NotFound",
targetViewType : "XML"
});
},
fireDetailChanged : function (sProductPath) {
this.getEventBus().publish("Detail", "Changed", { sProductPath : sProductPath });
},
fireDetailNotFound : function () {
this.getEventBus().publish("Detail", "NotFound");
},
onNavBack : function() {
// This is only relevant when running on phone devices
this.getRouter().myNavBack("main");
},
onDetailSelect : function(oEvent) {
sap.ui.core.UIComponent.getRouterFor(this).navTo("product",{
product : oEvent.getSource().getBindingContext().getPath().slice(1),
tab: oEvent.getParameter("selectedKey")
}, true);
}
});