Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
157 changes: 157 additions & 0 deletions src/01/02/z2ui5_cl_demo_app_471.clas.abap
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
CLASS z2ui5_cl_demo_app_471 DEFINITION PUBLIC.

PUBLIC SECTION.
INTERFACES z2ui5_if_app.

TYPES:
BEGIN OF ty_s_log,
entry TYPE string,
END OF ty_s_log.
DATA t_log TYPE STANDARD TABLE OF ty_s_log WITH EMPTY KEY.
DATA registered TYPE abap_bool.

PROTECTED SECTION.
DATA client TYPE REF TO z2ui5_if_client.

METHODS on_init.
METHODS on_event.
METHODS view_display.
METHODS shortcuts_set
IMPORTING
event_save TYPE string
event_delete TYPE string.

PRIVATE SECTION.
ENDCLASS.


CLASS z2ui5_cl_demo_app_471 IMPLEMENTATION.

METHOD z2ui5_if_app~main.

me->client = client.
IF client->check_on_init( ).
on_init( ).
ELSEIF client->check_on_navigated( ).
view_display( ).
ELSEIF client->check_on_event( ).
on_event( ).
ENDIF.

ENDMETHOD.


METHOD on_init.

registered = abap_true.
shortcuts_set( event_save = `SAVE`
event_delete = `DELETE` ).
view_display( ).

ENDMETHOD.


METHOD on_event.

CASE client->get( )-event.

WHEN `SAVE`.
INSERT VALUE #( entry = `Ctrl+S - save triggered` ) INTO TABLE t_log.
client->message_toast_display( `Ctrl+S: save triggered` ).
client->view_model_update( ).

WHEN `DELETE`.
INSERT VALUE #( entry = `Ctrl+D - delete triggered` ) INTO TABLE t_log.
client->message_toast_display( `Ctrl+D: delete triggered` ).
client->view_model_update( ).

WHEN `TOGGLE_REGISTRATION`.
registered = xsdbool( registered = abap_false ).

IF registered = abap_true.
shortcuts_set( event_save = `SAVE`
event_delete = `DELETE` ).
ELSE.
" an empty event name removes the binding again
shortcuts_set( event_save = ``
event_delete = `` ).
ENDIF.
view_display( ).

WHEN `CLEAR`.
t_log = VALUE #( ).
client->view_model_update( ).

ENDCASE.

ENDMETHOD.


METHOD shortcuts_set.

" one registration per key combination: t_arg is positional - the
" combination (spelled like in UI5: Ctrl+S, Ctrl+Shift+D, F2) and the name
" of the backend event it fires. Registering the same combination again
" rebinds it, an empty event name removes it. The registry lives in the
" frontend, so it survives every roundtrip until the app is left.
client->follow_up_action( val = z2ui5_if_client=>cs_event-keyboard_shortcut

Check failure on line 97 in src/01/02/z2ui5_cl_demo_app_471.clas.abap

View check run for this annotation

abaplint / abaplint

Component "keyboard_shortcut" not found in structure

https://rules.abaplint.org/check_syntax
t_arg = VALUE #( ( `Ctrl+S` )
( event_save ) ) ).

client->follow_up_action( val = z2ui5_if_client=>cs_event-keyboard_shortcut

Check failure on line 101 in src/01/02/z2ui5_cl_demo_app_471.clas.abap

View check run for this annotation

abaplint / abaplint

Component "keyboard_shortcut" not found in structure

https://rules.abaplint.org/check_syntax
t_arg = VALUE #( ( `Ctrl+D` )
( event_delete ) ) ).

ENDMETHOD.


METHOD view_display.

DATA(view) = z2ui5_cl_xml_view=>factory( ).

DATA(page) = view->shell(
)->page(
title = `abap2UI5 - Keyboard Shortcuts`
navbuttonpress = client->_event_nav_app_leave( )
shownavbutton = client->check_app_prev_stack( ) ).

page->message_strip(
text = `Ctrl+S and Ctrl+D fire the backend events SAVE and DELETE - the same events the ` &&
`buttons below send, but from the keyboard and without a control. The binding is ` &&
`pure data (cs_event-keyboard_shortcut with the combination and the event name), ` &&
`the browser default for the combination is suppressed.`
type = `Information`
showicon = abap_true
class = `sapUiSmallMargin` ).

page->hbox( class = `sapUiSmallMargin`
)->button(
text = COND #( WHEN registered = abap_true
THEN `Unregister the shortcuts`
ELSE `Register the shortcuts` )
icon = `sap-icon://keyboard-and-mouse`
press = client->_event( `TOGGLE_REGISTRATION` )
)->button(
text = `Save (Ctrl+S)`
type = `Emphasized`
class = `sapUiTinyMarginBegin`
press = client->_event( `SAVE` )
)->button(
text = `Delete (Ctrl+D)`
class = `sapUiTinyMarginBegin`
press = client->_event( `DELETE` )
)->button(
text = `Clear log`
class = `sapUiTinyMarginBegin`
press = client->_event( `CLEAR` ) ).

page->list(
headertext = `Triggered events`
items = client->_bind_edit( t_log )
)->standard_list_item( title = `{ENTRY}` ).

client->view_display( view->stringify( ) ).

ENDMETHOD.

ENDCLASS.
16 changes: 16 additions & 0 deletions src/01/02/z2ui5_cl_demo_app_471.clas.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<VSEOCLASS>
<CLSNAME>Z2UI5_CL_DEMO_APP_471</CLSNAME>
<LANGU>E</LANGU>
<DESCRIPT>More - Keyboard Shortcuts (A)</DESCRIPT>
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>X</UNICODE>
</VSEOCLASS>
</asx:values>
</asx:abap>
</abapGit>
102 changes: 102 additions & 0 deletions src/01/02/z2ui5_cl_demo_app_472.clas.abap
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
CLASS z2ui5_cl_demo_app_472 DEFINITION PUBLIC.

PUBLIC SECTION.
INTERFACES z2ui5_if_app.

DATA block_navigation TYPE abap_bool.
DATA last_press TYPE string.

PROTECTED SECTION.
DATA client TYPE REF TO z2ui5_if_client.

METHODS on_event.
METHODS view_display.

PRIVATE SECTION.
ENDCLASS.


CLASS z2ui5_cl_demo_app_472 IMPLEMENTATION.

METHOD z2ui5_if_app~main.

me->client = client.
IF client->check_on_init( ).
block_navigation = abap_true.
view_display( ).
ELSEIF client->check_on_navigated( ).
view_display( ).
ELSEIF client->check_on_event( ).
on_event( ).
ENDIF.

ENDMETHOD.


METHOD on_event.

CASE client->get( )-event.

WHEN `LINK_PRESS`.

IF block_navigation = abap_true.
last_press = `Link pressed - the browser did NOT follow the href, the backend decides what happens.`.
ELSE.
last_press = `Link pressed - the href was followed by the browser as usual.`.
ENDIF.
client->view_model_update( ).

WHEN `TOGGLE`.
" the flag is part of the event registration, so the view has to be
" rebuilt for the change to reach the frontend
view_display( ).

ENDCASE.

ENDMETHOD.


METHOD view_display.

DATA(view) = z2ui5_cl_xml_view=>factory( ).

DATA(page) = view->shell(
)->page(
title = `abap2UI5 - Event with preventDefault`
navbuttonpress = client->_event_nav_app_leave( )
shownavbutton = client->check_app_prev_stack( ) ).

page->message_strip(
text = `A sap.m.Link normally follows its href when pressed. Registered with ` &&
`s_ctrl-check_prevent_default the event cancels that built-in default ` &&
`(oEvent.preventDefault()) before the roundtrip - the event still reaches the ` &&
`backend, so the app decides what happens instead. Flip the switch to compare.`
type = `Information`
showicon = abap_true
class = `sapUiSmallMargin` ).

DATA(form) = page->simple_form(
title = `Link with a cancelled default`
editable = abap_true
)->content( `form` ).

form->label( `Cancel the browser navigation`
)->switch(
state = client->_bind_edit( block_navigation )
change = client->_event( `TOGGLE` )
)->label( `Link`
)->link(
text = `Open abap2ui5.org`
href = `https://abap2ui5.org`
target = `_blank`
press = client->_event(
val = `LINK_PRESS`
s_ctrl = VALUE #( check_prevent_default = block_navigation ) )

Check failure on line 94 in src/01/02/z2ui5_cl_demo_app_472.clas.abap

View check run for this annotation

abaplint / abaplint

field check_prevent_default does not exist in structure

https://rules.abaplint.org/check_syntax
)->label( `Result`
)->text( client->_bind_edit( last_press ) ).

client->view_display( view->stringify( ) ).

ENDMETHOD.

ENDCLASS.
16 changes: 16 additions & 0 deletions src/01/02/z2ui5_cl_demo_app_472.clas.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<VSEOCLASS>
<CLSNAME>Z2UI5_CL_DEMO_APP_472</CLSNAME>
<LANGU>E</LANGU>
<DESCRIPT>More - Link with preventDefault (A)</DESCRIPT>
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>X</UNICODE>
</VSEOCLASS>
</asx:values>
</asx:abap>
</abapGit>
80 changes: 80 additions & 0 deletions src/01/02/z2ui5_cl_demo_app_473.clas.abap
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
CLASS z2ui5_cl_demo_app_473 DEFINITION PUBLIC.

PUBLIC SECTION.
INTERFACES z2ui5_if_app.

PROTECTED SECTION.
DATA client TYPE REF TO z2ui5_if_client.

METHODS view_display.

PRIVATE SECTION.
ENDCLASS.


CLASS z2ui5_cl_demo_app_473 IMPLEMENTATION.

METHOD z2ui5_if_app~main.

me->client = client.
IF client->check_on_init( ).
view_display( ).
ENDIF.

ENDMETHOD.


METHOD view_display.

DATA(view) = z2ui5_cl_xml_view=>factory( ).

DATA(page) = view->shell(
)->page(
title = `abap2UI5 - Menu Item Path`
navbuttonpress = client->_event_nav_app_leave( )
shownavbutton = client->check_app_prev_stack( ) ).

page->message_strip(
text = `The toast shows the full path of the selected menu item ` &&
`("Create New Site > Official Store"), not only its own text. ` &&
`$controller.textPath( ) walks the item's parent chain in the control tree ` &&
`and joins the texts - a walk no binding path can express. Everything happens ` &&
`on the client, the menu selection needs no roundtrip at all.`
type = `Information`
showicon = abap_true
class = `sapUiSmallMargin` ).

" the item's breadcrumb is resolved on the client and substituted into the
" toast template ({0}); an argument starting with $ is a client-side
" expression, everything else travels as a plain string
DATA(menu_selected) = client->_event_client(
val = z2ui5_if_client=>cs_event-control_global
t_arg = VALUE #( ( `MESSAGE_TOAST` )
( `show` )
( `Action triggered on item: {0}` )
( `$controller.textPath(${$parameters>/item})` ) ) ).

DATA(menu) = page->hbox( class = `sapUiSmallMargin`
)->menu_button( text = `Actions`
)->menu( itemselected = menu_selected ).

menu->_generic(
name = `MenuItem`
t_prop = VALUE #( ( n = `text` v = `Create New Site` ) )
)->menu_item( text = `Official Store`
)->menu_item( text = `Franchise Store`
)->menu_item( text = `Pop-up Store` ).

menu->_generic(
name = `MenuItem`
t_prop = VALUE #( ( n = `text` v = `Manage Users` ) )
)->menu_item( text = `Add User`
)->menu_item( text = `Remove User` ).

menu->menu_item( text = `Log Out` ).

client->view_display( view->stringify( ) ).

ENDMETHOD.

ENDCLASS.
16 changes: 16 additions & 0 deletions src/01/02/z2ui5_cl_demo_app_473.clas.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<VSEOCLASS>
<CLSNAME>Z2UI5_CL_DEMO_APP_473</CLSNAME>
<LANGU>E</LANGU>
<DESCRIPT>More - Menu Item Path (A)</DESCRIPT>
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>X</UNICODE>
</VSEOCLASS>
</asx:values>
</asx:abap>
</abapGit>
Loading
Loading