14.01.2020 Views

ABAP_to_the_Future

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

13

SAPUI5

First, create a new XML file called ActionSheet.fragment.xml, as shown in Listing

13.24.

<?xml version="1.0" encoding="UTF-8"?>

<core:FragmentDefinition

xmlns="sap.m"

xmlns:core="sap.ui.core">

<ActionSheet

title="Choose Monster Action"

showCancelButton="true"

placement="Bottom">

<buttons>

<Button text="Create" icon="sap-icon://lab" />

<Button text="Give Award" icon="sap-icon://competitor" />

<Button text="Remove Head" icon="sap-icon://wrench" />

<Button text="Award Degree" icon="sap-icon://study-leave" />

<Button text="Inject" icon="sap-icon://syringe" />

<Button text="Other" />

</buttons>

</ActionSheet>

</core:FragmentDefinition>

Listing 13.24 ActionSheet.fragment.xml

This code defines a list of push buttons wi th icons that will appear in a context

menu when the user clicks the Action button. Now, change the code near the top

of your view. You had a button that did nothing; change it to one that invokes an

action from the controller (Listing 13.25).

<headerContent>

<Button

text="Open Action Sheet"

press="handleOpen" />

</headerContent>

<subHeader>

Listing 13.25 Coding a Button that Triggers an Action when You Press It

Finally, add a function to your controller to respond to the user pressing the button

and to call up your fragment of possible monster actions (Listing 13.26).

handleOpen : function (oEvent) {

var oButton = oEvent.getSource();

// create action sheet only once

if (!this._actionSheet) {

this._actionSheet = sap.ui.xmlfragment(

618

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!