Sie sind auf Seite 1von 27

SAPUI5 Developer Center: Develop Hybrid

Mobile Apps With SAP Web IDE Part 2


Posted by Claudia Polster Nov 27, 2015
part 1

Create a new Kapsel App

part 2

Add new Functionality


Test In Browser with Cordova Facade

this part
part 3

Run The App On Your Mobile Device

Add New Functionality To The App on page 1


Test In Browser with Cordova Facade on page 17

Add New Functionality To The App


Now we will add two new features to the app:
1. A scan button next to the search field at the Master View. When you click the button, the camera app
will start and you can scan a bar- or QR-code of a product. It will then search for this product-ID in the
product list.
2. At the detail view we will add a button at the bottom of the view, where you can save the suppliercontactdata to your addressbook of your mobile device.

Because of the Facade plugin we can test this also in the WebPreview of the SAP Web IDE.

In your project, open the view folder and right click on the Master.view.xml - Open With - Layout Editor

Generated by Jive on 2015-12-04+01:00


1

SAPUI5 Developer Center: Develop Hybrid Mobile Apps With SAP Web IDE Part 2

At the left choose the Button

Generated by Jive on 2015-12-04+01:00


2

SAPUI5 Developer Center: Develop Hybrid Mobile Apps With SAP Web IDE Part 2

...and drag and drop it onto the right of the Search Bar.

Generated by Jive on 2015-12-04+01:00


3

SAPUI5 Developer Center: Develop Hybrid Mobile Apps With SAP Web IDE Part 2

Now change the properties of the new Button

Generated by Jive on 2015-12-04+01:00


4

SAPUI5 Developer Center: Develop Hybrid Mobile Apps With SAP Web IDE Part 2

Generated by Jive on 2015-12-04+01:00


5

SAPUI5 Developer Center: Develop Hybrid Mobile Apps With SAP Web IDE Part 2

Click Save.
We must now add the functionality that is invoked when the button is pressed.
Right-click on the button and choose Go to Code

Generated by Jive on 2015-12-04+01:00


6

SAPUI5 Developer Center: Develop Hybrid Mobile Apps With SAP Web IDE Part 2

The XML Code Editor opens.


Here you can find the new button.

Now we have to add more properties to the button description:


tooltip="Bar Code Scanner" press="onBarCodeScan"

Generated by Jive on 2015-12-04+01:00


7

SAPUI5 Developer Center: Develop Hybrid Mobile Apps With SAP Web IDE Part 2

And do not forget to save!


Double click on the Master.controller.js to open it.

Generated by Jive on 2015-12-04+01:00


8

SAPUI5 Developer Center: Develop Hybrid Mobile Apps With SAP Web IDE Part 2

Add the following line at the top of the controller file.


jQuery.sap.require("sap.m.MessageBox");

Generated by Jive on 2015-12-04+01:00


9

SAPUI5 Developer Center: Develop Hybrid Mobile Apps With SAP Web IDE Part 2

Add also the new function onBarCodeScan to the Master.controller.js


onBarCodeScan:function(){ var that = this; var code = ""; try { cordova.plugins.barcodeScanner.scan( function (result) { sap.m
And do not forget to save!

This will use the Cordova barcode scanner plugin to scan a QR-Code or a Bar-Code andstores the result.
It creates a MessageBox which will show the text of the QR- or barcode and what code-format was read.
The result-text is added to the Search-Field and the Search function is then started.
It will also catch the errors if the scanning failed or the Cordova plugin isnt available.
Note: If you want to improve the layout of the source code, right-click in the editor window - Beautify.
This will arrange the code.

Generated by Jive on 2015-12-04+01:00


10

SAPUI5 Developer Center: Develop Hybrid Mobile Apps With SAP Web IDE Part 2

Now we will extend the Detail View.


First close the Layout Editor for Master.view.xml tab
Right click on the Detail.view.xml - Open With - Layout Editor
On the left choose the Button Control

..and drag and drop it to the toolbar at the bottom.

Generated by Jive on 2015-12-04+01:00


11

SAPUI5 Developer Center: Develop Hybrid Mobile Apps With SAP Web IDE Part 2

Now change the properties of the new Button


Click Save.

Generated by Jive on 2015-12-04+01:00


12

SAPUI5 Developer Center: Develop Hybrid Mobile Apps With SAP Web IDE Part 2

We must now add the functionality that is invoked when the button is pressed.
Right-click on the button and choose Go to Code

Generated by Jive on 2015-12-04+01:00


13

SAPUI5 Developer Center: Develop Hybrid Mobile Apps With SAP Web IDE Part 2

The Code Editor opens in which you can find the new button.

Generated by Jive on 2015-12-04+01:00


14

SAPUI5 Developer Center: Develop Hybrid Mobile Apps With SAP Web IDE Part 2

Now we have to add more properties to the button description:


xmlns="sap.m" press="addContact
And do not forget to save!

Open the Detail.controller.js


At the top of the controller add the following line
jQuery.sap.require("sap.m.MessageBox");

Generated by Jive on 2015-12-04+01:00


15

SAPUI5 Developer Center: Develop Hybrid Mobile Apps With SAP Web IDE Part 2

Then add the function addContact


addContact: function(oEvent) {
And do not forget to save!

if (!navigator.contacts) {

sap.m.MessageBox.show("Contacts AP

Generated by Jive on 2015-12-04+01:00


16

SAPUI5 Developer Center: Develop Hybrid Mobile Apps With SAP Web IDE Part 2

This function obtains the ToSupplier-contact data from the selected product and saves it as a new contact.
Note: To improve the layout of the source code, right-click - Beautify. This will arrange the code.

Test In Browser with Cordova Facade


We can test this new functionality using the Cordova Faade.
Remember that by activating the Hybrid Application Toolkit plugin in SAP Web IDE, we are able to test some of
the hardware features of a mobile device directly in the desktop browser.
Click on index.html and then the Run button

Generated by Jive on 2015-12-04+01:00


17

SAPUI5 Developer Center: Develop Hybrid Mobile Apps With SAP Web IDE Part 2

You will see now two new buttons.

Generated by Jive on 2015-12-04+01:00


18

SAPUI5 Developer Center: Develop Hybrid Mobile Apps With SAP Web IDE Part 2

Click the barcode button next to the search field.

Generated by Jive on 2015-12-04+01:00


19

SAPUI5 Developer Center: Develop Hybrid Mobile Apps With SAP Web IDE Part 2

A Chrome pop up will ask you to allow the camera of your laptop.
Click Allow and scan the QR-Code/Barcode with the camera of your laptop.

Generated by Jive on 2015-12-04+01:00


20

SAPUI5 Developer Center: Develop Hybrid Mobile Apps With SAP Web IDE Part 2

Generated by Jive on 2015-12-04+01:00


21

SAPUI5 Developer Center: Develop Hybrid Mobile Apps With SAP Web IDE Part 2

A Message Box will show you the result of your code scan.

Generated by Jive on 2015-12-04+01:00


22

SAPUI5 Developer Center: Develop Hybrid Mobile Apps With SAP Web IDE Part 2

Generated by Jive on 2015-12-04+01:00


23

SAPUI5 Developer Center: Develop Hybrid Mobile Apps With SAP Web IDE Part 2

A search will be performed for the Product having this particular code.

Generated by Jive on 2015-12-04+01:00


24

SAPUI5 Developer Center: Develop Hybrid Mobile Apps With SAP Web IDE Part 2

To test the Add Contact functionality in the browser press F12 to open the Developer Tools.

Choose one product and click the Add to Contact


Important: Please click on a product in the master list. When resizing the screen, it is important to make sure
that you have really selected a product in the master list.

Generated by Jive on 2015-12-04+01:00


25

SAPUI5 Developer Center: Develop Hybrid Mobile Apps With SAP Web IDE Part 2

A Message Box shows a success Message. Your saved contact you can find in the Resources tab in the
Developer Tools - Resources - Local Storage - contacts
If you get an error: be sure that you have marked one product to open the details. If you use the first-loaddetails you will get an error.

Generated by Jive on 2015-12-04+01:00


26

SAPUI5 Developer Center: Develop Hybrid Mobile Apps With SAP Web IDE Part 2

In the next part I will show, how you can test it on your Mobile Device with the companion App.

More Web IDE stuff published by Technology RIG

See you
Claudi
462 Views

Michael Appleby
Nov 30, 2015 5:47 AM
And do not forget to save!!!
So important a step, but so often the source of trouble! Wonderful that you emphasize it when it will save
people so much trouble with their efforts!
Cheers, Mike
SAP Technology RIG

Generated by Jive on 2015-12-04+01:00


27

Das könnte Ihnen auch gefallen