Skip to content

Commit e82e3a1

Browse files
committed
Added everything for Step 9: Adding the Post Page
1 parent f9487f0 commit e82e3a1

5 files changed

Lines changed: 97 additions & 15 deletions

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
);

webapp/controller/Worklist.controller.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ sap.ui.define(
33
"./BaseController",
44
"sap/ui/model/json/JSONModel",
55
"sap/m/library",
6-
'../model/FlaggedType'
6+
"../model/FlaggedType",
77
],
88
function (BaseController, JSONModel, mobileLibrary, FlaggedType) {
99
"use strict";
1010

1111
return BaseController.extend("com.mrb.UI5-Testing.controller.Worklist", {
12-
types : {
13-
flagged: new FlaggedType()
12+
types: {
13+
flagged: new FlaggedType(),
1414
},
1515
/**
1616
* Called when the worklist controller is instantiated.
@@ -112,6 +112,17 @@ sap.ui.define(
112112
oViewModel.getProperty("/shareSendEmailMessage")
113113
);
114114
},
115+
/**
116+
* Event handler when a table item gets pressed
117+
* @param {sap.ui.base.Event} oEvent the table selectionChange event
118+
* @public
119+
*/
120+
onPress: function (oEvent) {
121+
this.getRouter().navTo("post", {
122+
// The source is the list item that got pressed
123+
postId: oEvent.getSource().getBindingContext().getProperty("PostID"),
124+
});
125+
},
115126
});
116127
}
117128
);

webapp/manifest.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,25 @@
9494
"target": [
9595
"TargetHome"
9696
]
97-
}
97+
},
98+
{
99+
"pattern": "Post/{postId}",
100+
"name": "post",
101+
"target": "post"
102+
}
98103
],
99104
"targets": {
100105
"TargetHome": {
101106
"viewType": "XML",
102107
"viewLevel": 1,
103108
"viewId": "home",
104109
"viewName": "Worklist"
105-
}
110+
},
111+
"post": {
112+
"viewName": "Post",
113+
"viewId": "post",
114+
"viewLevel": 2
115+
}
106116
}
107117
}
108118
}

webapp/view/Post.view.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<mvc:View controllerName="com.mrb.UI5-Testing.controller.Post"
2+
xmlns="sap.m"
3+
xmlns:mvc="sap.ui.core.mvc"
4+
xmlns:semantic="sap.m.semantic">
5+
<semantic:FullscreenPage id="page" busy="{postView>/busy}" busyIndicatorDelay="0" navButtonPress=".onNavBack" showNavButton="true" title="{i18n>objectTitle}">
6+
<semantic:content>
7+
<ObjectHeader id="objectHeader" title="{Title}" number="{
8+
path: 'Price',
9+
formatter: '.formatter.numberUnit'
10+
}" numberUnit="{Currency}" backgroundDesign="Translucent">
11+
</ObjectHeader>
12+
</semantic:content>
13+
</semantic:FullscreenPage>
14+
</mvc:View>

webapp/view/Worklist.view.xml

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,15 @@
2929
<Column width="80px" id="flaggedColumn" demandPopin="true" vAlign="Middle"/>
3030
</columns>
3131
<items>
32-
<ColumnListItem vAlign="Middle">
32+
<ColumnListItem vAlign="Middle" type="Navigation" press=".onPress">
3333
<cells>
3434
<ObjectIdentifier title="{Title}"/>
3535
<Text text="{Category}"/>
36-
<ObjectNumber number="{path: 'Price',formatter: '.formatter.numberUnit'}"
37-
state="{path: 'Price',formatter: '.formatter.priceState'}"
38-
unit="{Currency}" />
39-
<ToggleButton id="flaggedButton"
40-
tooltip="{i18n>flaggedTooltip}"
41-
icon="sap-icon://flag"
42-
pressed="{
36+
<ObjectNumber number="{path: 'Price',formatter: '.formatter.numberUnit'}" state="{path: 'Price',formatter: '.formatter.priceState'}" unit="{Currency}" />
37+
<ToggleButton id="flaggedButton" tooltip="{i18n>flaggedTooltip}" icon="sap-icon://flag" pressed="{
4338
path: 'Flagged',
4439
type: '.types.flagged'
45-
}"
46-
class="sapUiMediumMarginBeginEnd"/>
40+
}" class="sapUiMediumMarginBeginEnd"/>
4741
</cells>
4842
</ColumnListItem>
4943
</items>

0 commit comments

Comments
 (0)