Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
0 Kudos

SAP Web IDE Hybrid Application Toolkit Introduction and Demo


Video Link


Here is the code needed to add the button for adding barcode reader to the searchfield (time 14:10)


Master.view.xml:

<contentRight>

     <Button id="barcodeButton" icon="sap-icon://bar-code" tooltip="Bar Code Scanner" press="onBarCodeScan"></Button>

</contentRight>



Master.controller.js

onBarCodeScan: function() {

     var that = this;

     var code = "";



if (!cordova.plugins.barcodeScanner) {

     sap.m.MessageBox.show("barCode scanning not supported", sap.m.MessageBox.Icon.INFORMATION, "Bsrcode scanning");

     return;

}



cordova.plugins.barcodeScanner.scan(

          function (result) {

                code = result.text;

                that.getView().byId("searchField").setValue(code);

                that.onSearch();

          },

          function (error) {

           alert("Scanning failed: " + error);

          }

     );

},

Here is the code needed to add the button for adding the contact to mobile device (time 5:00)

Detail.view.xml:

<Button xmlns="sap.m" text="add to contact" press="addContact"></Button>

Detail.controller.js:

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

      addContact: function(oEvent) {

           if (!navigator.contacts) {

                sap.m.MessageBox.show("Contacts API only supported on Devices/Simulators", sap.m.MessageBox.Icon.INFORMATION, "Add Contact");

                return;

           }

           var oView = this.getView();

           var sEntityPath = "/" + oEvent.getSource().getBindingContext().getPath().slice(1) + "/SupplierDetails";

           var bpData = oView.getModel().getData(sEntityPath);

           //Get Contacts data

           var name = bpData.SupplierName;

           var phone = bpData.PhoneNumber;

           var email = bpData.EmailAddress;

           var contact = navigator.contacts.create();

           contact.name = { givenName: name };

           var phoneNumbers = [];

           var emails = [];

   

           phoneNumbers[0] = new ContactField("work", phone, true);

           emails[0] = new ContactField("email", email, false);

           contact.phoneNumbers = phoneNumbers;

           contact.emails = emails;

           contact.save();

           sap.m.MessageBox.show("Successfully saved into Device Contacts ", sap.m.MessageBox.Icon.SUCCESS, "Add Contact");

     },

2 Comments