This blog post is a 3rd one in the series of “Mobilizing your SAP Data with Telerik Platform”. If you have not read my first 2 parts I suggest you take a look at those first. Here is the link to first 2 parts of this series:
Mobilizing your SAP Data with Kendo UI Mobile – Get the Environment Ready – Part 1
Mobilizing your SAP Data with Kendo UI Mobile – Building the Mobile App – Part 2
In Part 1 I wrote about how to get started with SAP. In Part 2 I talked about building a mobile app using Kendo UI Mobile. We connected with the SAP data through the OData service that SAP Netweaver Gateway system provides. We were also able to build the first screen of the app namely the Partners listing screen. In this blog post we will look at how to build a screen that shows the details of the selected Partner. Let’s get started
Recap – Partner Item Template:
In the part 1 when we built the Partners listing screen, we used Kendo UI Mobile ListView to list the partners from the system. Each item in the ListView will be rendered by making use of an item template we provided. Just to recap that code, here is the code snippet of the item template:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/x-kendo-template" id="partnerTemplate"> | |
<div data-role="touch" data-bind="events: { tap: partnerSelected }"> | |
<div style="font-size:20px;font-weight:bold"> | |
<span>${Company}</span> | |
</div> | |
<div>${City} ${PostalCode}, ${Country}</div> | |
</div> | |
</script> |
Notice the usage of data-role=touch on the div and the data bind syntax where we trap the tap event and provide an event handler named “partnerSelected”. Here is the code snippet of the partnersViewModel where we have defined the partnerSelected event handler:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var partnersViewModel = (function(){ | |
// Navigate to partner view When some partner is selected | |
var partnerSelected = function (e) { | |
app.application.navigate(appSettings.viewSettings.partnerView + '?uid=' + e.data.uid); | |
}; | |
return { | |
partners: partnersModel.partners, | |
partnerSelected: partnerSelected, | |
}; | |
}()); |
Handling Navigation to Partner View:
We saw that we have an event handler which handles the tap event of the partners listing listview. The code just navigates to a new view called partnerView. But the view name is not hard coded. It is coming from appsettings object which contains viewsettings and the value for partnerView. Also notice that we are passing the currently selected partner UID in the querystring. UID is the unique identifier that the Kendo UI Data Source maintains for each item in its data collection. We will use this information to get a single partner object from the collection using datasource method getbyid().
First let’s update the appsettings.js with viewsettings data. Here is the code snippet:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var appSettings = { | |
dataSettings: | |
{ | |
partnersReadUrl : "http://<your server>/sap/opu/odata/sap/ZGWSAMPLE_SRV/BusinessPartnerCollection", | |
}, | |
viewSettings: | |
{ | |
partnerView: "views/partnerView.html", | |
} | |
}; |
Notice that we have the URI of the new view set to “views/partnerView.html”. Let’s create a new folder under the root of the project by name “views” and create a new html file called “partnerView.html”.
When you add a new HTML file, the file content will have bare bone HTML code. Remove that basic HTML code as we don’t need that. Next we will create the partnerView UI.
Partner View UI:
As part of the partner view screen, we will just list out all the details of a partner like name, email, phone, address, etc. Here is the code snippet of the partner view:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div data-role="view" id="partner-view" data-show="app.Partner.show"> | |
<header data-role="header"> | |
<div data-role="navbar"> | |
Partner Details | |
<a data-align="left" data-icon="bck" data-role="backbutton"></a> | |
</div> | |
</header> | |
<ul id="partner-view-container" data-role="listview" data-style="inset"> | |
<li> | |
<div align=center> | |
<span style="font-weight:bold;font-size:20px" data-bind="text: Company"> | |
</span> | |
</div> | |
</li> | |
<li> | |
<div> | |
<span><b>Legal Form</b>:</span><br><span style="margin-left:5px;" data-bind="text:LegalForm"></span> | |
</div> | |
<div> | |
| |
</div> | |
<div> | |
<span><b>Email</b>:</span><span style="margin-left:5px;" data-bind="text:Email"></span> | |
</div> | |
<div> | |
| |
</div> | |
<div> | |
<span><b>Phone</b>:</span><span style="margin-left:5px;" data-bind="text:Phone"></span> | |
</div> | |
<div> | |
| |
</div> | |
<div> | |
<span><b>Fax</b>:</span><span style="margin-left:5px;" data-bind="text:Fax"></span> | |
</div> | |
<div> | |
| |
</div> | |
<div> | |
<span><b>Web</b>:</span><span style="margin-left:5px;" data-bind="text:Web"></span> | |
</div> | |
<div> | |
| |
</div> | |
<div> | |
<span><b>Address</b>:</span> | |
<br /> | |
<span data-bind="text:Building"></span>, <span data-bind="text:Street"></span>, <span data-bind="text:City"></span> – <span data-bind="text:PostalCode"></span>, <span data-bind="text:Country"></span> | |
</div> | |
</li> | |
</ul> | |
<div data-role="footer"> | |
<div data-role="tabstrip"> | |
<a href="views/ordersView.html" data-icon="orders">Orders</a> | |
</div> | |
</div> | |
</div> | |
<style> | |
.km-orders:after, | |
.km-orders:before | |
{ | |
content: "\e07a"; | |
} | |
</style> |
Let’s go over the code once. It’s a simple div with its data role set to view. This is how Kendo UI knows that this is a page or screen in the app. We are trapping the show method of the view through data-show attribute and is bound to Partner object’s show() method. We will see the partner object in next section. Then we have spans to output different property of the partner and we have data bound different properties to the text property of the span. Next let’s take a look at the Partner JavaScript file.
Partner JavaScript Object:
In previous section we saw that the partner view screen is data bound to partner JavaScript object. Create a new JavaScript file named “partner.js” in scripts folder. And paste the following code in the script file:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var app = app || {}; | |
app.Partner = (function() | |
{ | |
'use strict' | |
var partnerViewModel = (function() | |
{ | |
var partnerUid; | |
var show = function(e){ | |
partnerUid = e.view.params.uid; | |
var partner = app.Partners.partners.getByUid(partnerUid); | |
appSettings.sessionSettings.selectedPartner = partner; | |
kendo.bind(e.view.element, partner, kendo.mobile.ui) | |
} | |
return { | |
show:show, | |
}; | |
}()); | |
return partnerViewModel; | |
}()) |
Pay close attention to show() method. Remember that when we navigate from the partners listing screen, we had passed a querystring value which was the UID of the partner object. Here in partner view show method, we retrieve the UID and piggyback on app.Partners.partners data source and use the data source method getByUid() to retrieve the partner object. Once we get the object we use kendo.bind() method to data bind it to the view. With this the view at runtime get data bound with the partner object and the spans will show the appropriate data as they have the data-bind syntax.
Running the App:
One last thing to do is adding a reference to partner.js. Add a script reference to partner.js in the script block of index.html. After adding the reference, select Run > In Simulator from the toolbar. Here is the screen shot of the partner view:
Don’t question me on the UI – I am a design handicap when it comes to UX. But we now have 2 screens as part of the application itself. We now have the Partners Listing screen and Partner Details screen. And we are making progress.
Summary:
In this blog post we looked at how to create Partner details screen. We created a HTML page and a corresponding JavaScript file. With the concept of DataBinding we were able to bind different properties of a Partner object to different span on the view. In the next part of this blog series, we will take a look at how to create a new partner right from the mobile app itself. So stay tuned.
Pingback: Mobilizing your SAP Data with Kendo UI Mobile – New Partner Screen – Part 4 | telerik helper
Pingback: Mobilizing your SAP Data with Kendo UI Mobile – Wrap Up – Part 5 | telerik helper