Dialog with Confirm Options
Creating a dialog with confirm and reject options that replaces the confirmDialog functionality.
Z2UI5_CL_SMPC_APP_019
Controls
sap.m
UI5 1.71
The facts
- Repository
- abap2UI5/samples-controls
- Class
Z2UI5_CL_SMPC_APP_019- Source file
z2ui5_cl_smpc_app_019.clas.abap↗- Library
- sap.m
- UI5 entity
sap.m.Dialog- Demo kit sample
sap.m.sample.DialogConfirm- SAP's own sample
- running at sdk.openui5.org ↗
- Minimum UI5
- 1.71 — the floor abap2UI5 holds its samples to
- In the playground
- runs in the browser, with no system and nothing installed
Keywords: dialog, sap.m, confirm, reject, submit, order, dialogs, verticallayout, button, text, label, textarea
Controls it builds
- sap.m.Button
- sap.m.Dialog
- sap.m.Label
- sap.m.Text
- sap.m.TextArea
- sap.ui.core.FragmentDefinition
- sap.ui.core.mvc.View
- sap.ui.layout.HorizontalLayout
- sap.ui.layout.VerticalLayout
Read out of the builder chain by the abap2UI5 linter, not from the category this sample is filed under — which is what makes “which samples build one of these” a question the catalogue can answer at all.
Libraries
Run it here
The sample running, in this page — the app on its own, with no editor over it.
Switch to Playground with this code
Nothing is installed and nothing is sent anywhere: the ABAP is compiled to JavaScript in this browser and runs against abap2UI5 itself.
The ABAP
z2ui5_cl_smpc_app_019.clas.abap — 297 lines
Click a number to link to a line — shift-click for a range.
Read it on GitHub ↗
" @keywords dialog sap.m confirm reject submit order dialogs verticallayout button text label textarea
" @summary Creating a dialog with confirm and reject options that replaces the confirmDialog functionality.
CLASS z2ui5_cl_smpc_app_019 DEFINITION PUBLIC.
PUBLIC SECTION.
INTERFACES z2ui5_if_app.
DATA reject_note TYPE string.
DATA submit_note TYPE string.
DATA confirm_note TYPE string.
PROTECTED SECTION.
DATA client TYPE REF TO z2ui5_if_client.
METHODS view_display.
METHODS on_event.
METHODS popup_approve_display.
METHODS popup_reject_display.
METHODS popup_submit_display.
METHODS popup_confirm_display.
PRIVATE SECTION.
ENDCLASS.
CLASS z2ui5_cl_smpc_app_019 IMPLEMENTATION.
METHOD z2ui5_if_app~main.
me->client = client.
IF client->check_on_navigated( ).
view_display( ).
ELSEIF client->check_on_event( ).
on_event( ).
ENDIF.
ENDMETHOD.
METHOD view_display.
DATA(view) = z2ui5_cl_ui5_view_builder=>factory( ).
view->ele( n = `View` ns = `mvc`
)->a( n = `xmlns:l` v = `sap.ui.layout`
)->a( n = `xmlns:mvc` v = `sap.ui.core.mvc`
)->a( n = `xmlns` v = `sap.m`
)->ele( n = `VerticalLayout` ns = `l`
)->a( n = `class` v = `sapUiContentPadding`
)->a( n = `width` v = `100%`
)->tag( `Button`
)->a( n = `text` v = `Approve`
)->a( n = `width` v = `230px`
)->a( n = `press` v = client->_event( `APPROVE_DIALOG` )
)->a( n = `class` v = `sapUiSmallMarginBottom`
)->tag( `Button`
)->a( n = `text` v = `Reject`
)->a( n = `width` v = `230px`
)->a( n = `press` v = client->_event( `REJECT_DIALOG` )
)->a( n = `class` v = `sapUiSmallMarginBottom`
)->tag( `Button`
)->a( n = `text` v = `Submit (mandatory note)`
)->a( n = `width` v = `230px`
)->a( n = `press` v = client->_event( `SUBMIT_DIALOG` )
)->a( n = `class` v = `sapUiSmallMarginBottom`
)->tag( `Button`
)->a( n = `text` v = `Confirm (optional note)`
)->a( n = `width` v = `230px`
)->a( n = `press` v = client->_event( `CONFIRM_DIALOG` )
)->a( n = `class` v = `sapUiSmallMarginBottom` ).
client->view_display( view->stringify( ) ).
ENDMETHOD.
METHOD on_event.
CASE client->get_event( ).
WHEN `APPROVE_DIALOG`.
popup_approve_display( ).
WHEN `APPROVE_SUBMIT`.
client->message_toast_display( `Submit pressed!` ).
client->popup_destroy( ).
WHEN `REJECT_DIALOG`.
popup_reject_display( ).
WHEN `REJECT_SUBMIT`.
client->message_toast_display( |Note is: { reject_note }| ).
client->popup_destroy( ).
WHEN `SUBMIT_DIALOG`.
popup_submit_display( ).
WHEN `SUBMIT_SUBMIT`.
client->message_toast_display( |Note is: { submit_note }| ).
client->popup_destroy( ).
WHEN `CONFIRM_DIALOG`.
popup_confirm_display( ).
WHEN `CONFIRM_SUBMIT`.
client->message_toast_display( |Note is: { confirm_note }| ).
client->popup_destroy( ).
WHEN `DIALOG_CANCEL`.
client->popup_destroy( ).
ENDCASE.
ENDMETHOD.
METHOD popup_approve_display.
DATA(popup) = z2ui5_cl_ui5_view_builder=>factory( ).
popup->ele( n = `FragmentDefinition` ns = `core`
)->a( n = `xmlns:core` v = `sap.ui.core`
)->a( n = `xmlns` v = `sap.m`
)->ele( `Dialog`
)->a( n = `type` v = `Message`
)->a( n = `title` v = `Confirm`
)->ele( `content`
)->tag( `Text`
)->a( n = `text` v = `Do you want to submit this order?`
)->end(
)->ele( `beginButton`
)->tag( `Button`
)->a( n = `type` v = `Emphasized`
)->a( n = `text` v = `Submit`
)->a( n = `press` v = client->_event( `APPROVE_SUBMIT` )
)->end(
)->ele( `endButton`
)->tag( `Button`
)->a( n = `text` v = `Cancel`
)->a( n = `press` v = client->follow_up_action( client->cs_event-popup_close ) ).
client->popup_display( popup->stringify( ) ).
ENDMETHOD.
METHOD popup_reject_display.
DATA(popup) = z2ui5_cl_ui5_view_builder=>factory( ).
popup->ele( n = `FragmentDefinition` ns = `core`
)->a( n = `xmlns:core` v = `sap.ui.core`
)->a( n = `xmlns` v = `sap.m`
)->ele( `Dialog`
)->a( n = `title` v = `Reject`
)->a( n = `type` v = `Message`
)->ele( `content`
)->tag( `Label`
)->a( n = `text` v = `Do you want to reject this order?`
)->a( n = `labelFor` v = `rejectionNote`
" original reads the note imperatively via getValue - here the value is two-way bound
)->tag( `TextArea`
)->a( n = `id` v = `rejectionNote`
)->a( n = `value` v = client->_bind( reject_note )
)->a( n = `width` v = `100%`
)->a( n = `placeholder` v = `Add note (optional)`
)->end(
)->ele( `beginButton`
)->tag( `Button`
)->a( n = `type` v = `Emphasized`
)->a( n = `text` v = `Reject`
)->a( n = `press` v = client->_event( `REJECT_SUBMIT` )
)->end(
)->ele( `endButton`
)->tag( `Button`
)->a( n = `text` v = `Cancel`
)->a( n = `press` v = client->_event( `DIALOG_CANCEL` ) ).
client->popup_display( popup->stringify( ) ).
ENDMETHOD.
METHOD popup_submit_display.
DATA(popup) = z2ui5_cl_ui5_view_builder=>factory( ).
popup->ele( n = `FragmentDefinition` ns = `core`
)->a( n = `xmlns:core` v = `sap.ui.core`
)->a( n = `xmlns` v = `sap.m`
)->ele( `Dialog`
)->a( n = `type` v = `Message`
)->a( n = `title` v = `Confirm`
)->ele( `content`
)->tag( `Label`
)->a( n = `text` v = `Do you want to submit this order?`
)->a( n = `labelFor` v = `submissionNote`
" valueLiveUpdate replaces the original liveChange handler feeding the button's enabled state
)->tag( `TextArea`
)->a( n = `id` v = `submissionNote`
)->a( n = `value` v = client->_bind( submit_note )
)->a( n = `valueLiveUpdate` v = `true`
)->a( n = `width` v = `100%`
)->a( n = `placeholder` v = `Add note (required)`
)->end(
)->ele( `beginButton`
" enabled while the note is non-empty - expression binding instead of the liveChange round-trip
)->tag( `Button`
)->a( n = `type` v = `Emphasized`
)->a( n = `text` v = `Submit`
)->a( n = `enabled` v = |\{= ${ client->_bind( submit_note ) }.length > 0 \}|
)->a( n = `press` v = client->_event( `SUBMIT_SUBMIT` )
)->end(
)->ele( `endButton`
)->tag( `Button`
)->a( n = `text` v = `Cancel`
)->a( n = `press` v = client->_event( `DIALOG_CANCEL` ) ).
client->popup_display( popup->stringify( ) ).
ENDMETHOD.
METHOD popup_confirm_display.
DATA(popup) = z2ui5_cl_ui5_view_builder=>factory( ).
popup->ele( n = `FragmentDefinition` ns = `core`
)->a( n = `xmlns:core` v = `sap.ui.core`
)->a( n = `xmlns:l` v = `sap.ui.layout`
)->a( n = `xmlns` v = `sap.m`
)->ele( `Dialog`
)->a( n = `type` v = `Message`
)->a( n = `title` v = `Confirm`
)->ele( `content`
)->ele( n = `HorizontalLayout` ns = `l`
)->ele( n = `VerticalLayout` ns = `l`
)->a( n = `width` v = `120px`
)->tag( `Text`
)->a( n = `text` v = `Type: `
)->tag( `Text`
)->a( n = `text` v = `Delivery: `
)->tag( `Text`
)->a( n = `text` v = `Items count: `
)->end(
)->ele( n = `VerticalLayout` ns = `l`
)->tag( `Text`
)->a( n = `text` v = `Shopping Cart`
)->tag( `Text`
)->a( n = `text` v = `Jun 26, 2013`
)->tag( `Text`
)->a( n = `text` v = `2`
)->end(
)->end(
)->tag( `TextArea`
)->a( n = `id` v = `confirmationNote`
)->a( n = `value` v = client->_bind( confirm_note )
)->a( n = `width` v = `100%`
)->a( n = `placeholder` v = `Add note (optional)`
)->end(
)->ele( `beginButton`
)->tag( `Button`
)->a( n = `type` v = `Emphasized`
)->a( n = `text` v = `Submit`
)->a( n = `press` v = client->_event( `CONFIRM_SUBMIT` )
)->end(
)->ele( `endButton`
)->tag( `Button`
)->a( n = `text` v = `Cancel`
)->a( n = `press` v = client->_event( `DIALOG_CANCEL` ) ).
client->popup_display( popup->stringify( ) ).
ENDMETHOD.
ENDCLASS.
More in sap.m
- Cookie Settings Dialog Pattern — The Cookie Settings Dialog allows you to easily manage the cookie settings according to t…
- Custom List Item — With the Custom List Item you can add any kind of content to lists.
- Custom Tree Item — With the Custom Tree Item you can add any kind of content to Tree.
- Date Picker - Open by Another Control — This example shows Date Picker which is opened by another control.
- Date Range Selection — The Date Range Selection is an extension of the Date Picker Control and enables the user…
- Date Time Picker — With the DateTimePicker a Date can be entered or selected including the time part.
- Display List Item — Use the Display List Item for showing name/value pairs.
- Draft Indicator — The Draft Indicator shows that eighter currently a draft is saving or that it is already…
- Facet Filter - Light — This is a 'Light' version of the Facet Filter. It is for small displays where only a sele…
- Feed Content — Shows the tile containing the text of the feed, a subheader, and a numeric value.
- Feed — This sample shows you how to build a complete feed user interface by combining a FeedInpu…
- Feed List Item — The Feed List Item provides a standard UI for 'feeds' where multiple users publish inform…
On this page