|
| 1 | +sap.ui.define( |
| 2 | + ["./BaseController", "sap/ui/model/json/JSONModel", "../model/formatter"], |
| 3 | + function (BaseController, JSONModel, formatter) { |
| 4 | + "use strict"; |
| 5 | + return BaseController.extend("com.mrb.UI5-Testing.controller.Post", { |
| 6 | + formatter: formatter, |
| 7 | + /** |
| 8 | + * Called when the worklist controller is instantiated. |
| 9 | + * @public |
| 10 | + */ |
| 11 | + onInit: function () { |
| 12 | + // Model used to manipulate control states. The chosen values make sure, |
| 13 | + // detail page is busy indication immediately so there is no break in |
| 14 | + // between the busy indication for loading the view's meta data |
| 15 | + var oViewModel = new JSONModel({ |
| 16 | + busy: false, |
| 17 | + }); |
| 18 | + this.getRouter() |
| 19 | + .getRoute("post") |
| 20 | + .attachPatternMatched(this._onPostMatched, this); |
| 21 | + this.setModel(oViewModel, "postView"); |
| 22 | + }, |
| 23 | + /** |
| 24 | + * Binds the view to the post path. |
| 25 | + * |
| 26 | + * @function |
| 27 | + * @param {sap.ui.base.Event} oEvent pattern match event in route 'object' |
| 28 | + * @private |
| 29 | + */ |
| 30 | + _onPostMatched: function (oEvent) { |
| 31 | + var oViewModel = this.getModel("postView"), |
| 32 | + oDataModel = this.getModel(); |
| 33 | + this.getView().bindElement({ |
| 34 | + path: "/Posts('" + oEvent.getParameter("arguments").postId + "')", |
| 35 | + events: { |
| 36 | + dataRequested: function () { |
| 37 | + oDataModel.metadataLoaded().then(function () { |
| 38 | + // Busy indicator on view should only be set if metadata is loaded, |
| 39 | + // otherwise there may be two busy indications next to each other on the |
| 40 | + // screen. This happens because route matched handler already calls '_bindView' |
| 41 | + // while metadata is loaded. |
| 42 | + oViewModel.setProperty("/busy", true); |
| 43 | + }); |
| 44 | + }, |
| 45 | + dataReceived: function () { |
| 46 | + oViewModel.setProperty("/busy", false); |
| 47 | + }, |
| 48 | + }, |
| 49 | + }); |
| 50 | + }, |
| 51 | + }); |
| 52 | + } |
| 53 | +); |
0 commit comments