abap2UI5

Side Navigation - Actions

SideNavigation with a quick create action button.

Z2UI5_CL_SMPC_APP_299

Controls sap.tnt UI5 1.133

The facts

Repository
abap2UI5/samples-controls
Class
Z2UI5_CL_SMPC_APP_299
Source file
z2ui5_cl_smpc_app_299.clas.abap
Library
sap.tnt
UI5 entity
sap.tnt.SideNavigation
Demo kit sample
sap.tnt.sample.SideNavigationActions
SAP's own sample
running at sdk.openui5.org ↗
Minimum UI5
1.133
In the playground
runs in the browser, with no system and nothing installed

Keywords: sidenavigation, side, navigation, sap.tnt, sidenavigationactions, vbox, button, navigationlist, navigationlistitem, dialog, label, input

Controls it builds

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_299.clas.abap — 201 lines Read it on GitHub ↗
" @keywords sidenavigation side navigation sap.tnt sidenavigationactions vbox button navigationlist navigationlistitem dialog label input
" @summary SideNavigation with a quick create action button.
CLASS z2ui5_cl_smpc_app_299 DEFINITION PUBLIC.

  PUBLIC SECTION.
    INTERFACES z2ui5_if_app.

    DATA expanded    TYPE abap_bool.
    DATA create_name TYPE string.
    DATA create_icon TYPE string.

    TYPES: BEGIN OF ty_s_nav_item,
             text     TYPE string,
             icon     TYPE string,
             expanded TYPE abap_bool,
           END OF ty_s_nav_item.
    DATA t_nav_items TYPE STANDARD TABLE OF ty_s_nav_item WITH EMPTY KEY.

  PROTECTED SECTION.
    DATA client TYPE REF TO z2ui5_if_client.

    METHODS view_display.
    METHODS on_event.
    METHODS popup_quickcreate_display.
    METHODS model_init.

  PRIVATE SECTION.
ENDCLASS.


CLASS z2ui5_cl_smpc_app_299 IMPLEMENTATION.

  METHOD z2ui5_if_app~main.

    me->client = client.
    IF client->check_on_init( ).
      model_init( ).
      view_display( ).
    ELSEIF 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`     v = `sap.m`
        )->a( n = `xmlns:mvc` v = `sap.ui.core.mvc`
        )->a( n = `xmlns:tnt` v = `sap.tnt`
        )->a( n = `height`    v = `100%`

        )->ele( `VBox`
            )->a( n = `renderType` v = `Bare`
            )->a( n = `alignItems` v = `Start`
            )->a( n = `height`     v = `100%`

            )->tag( `Button`
                )->a( n = `text`  v = `Toggle Collapse/Expand`
                )->a( n = `icon`  v = `sap-icon://menu2`
                )->a( n = `press` v = client->_event( `TOGGLE_EXPAND` )

            )->ele( n = `SideNavigation` ns = `tnt`
                )->a( n = `id`          v = `sideNavigation`
                )->a( n = `selectedKey` v = `walked`
                )->a( n = `expanded`    v = client->_bind( expanded )

                " the Create button of the quick-create dialog does
                " sideNavigation.getItem().addItem( new NavigationListItem( ... ) ), so
                " the list is a bound aggregation (the app-241 pattern) instead of four
                " static entries: creating appends a row. EXPANDED is omitted while
                " initial so an item that does not set it keeps the control default
                )->ele( n = `NavigationList` ns = `tnt`
                    )->a( n = `items` v = client->_bind(
                                              val                = t_nav_items
                                              omit_initial_paths = VALUE #( ( `EXPANDED` ) ) )

                    )->tag( n = `NavigationListItem` ns = `tnt`
                        )->a( n = `text`     v = `{TEXT}`
                        )->a( n = `icon`     v = `{ICON}`
                        )->a( n = `expanded` v = `{EXPANDED}`

                )->end(

                )->ele( n = `fixedItem` ns = `tnt`
                    )->ele( n = `NavigationList` ns = `tnt`
                        )->tag( n = `NavigationListItem` ns = `tnt`
                            )->a( n = `ariaHasPopup` v = `Dialog`
                            )->a( n = `id`           v = `quickCreate`
                            )->a( n = `press`        v = client->_event( `QUICK_CREATE` )
                            )->a( n = `text`         v = `Quick Create`
                            )->a( n = `icon`         v = `sap-icon://write-new`
                            )->a( n = `design`       v = `Action`
                            )->a( n = `selectable`   v = `false`
                        )->tag( n = `NavigationListItem` ns = `tnt`
                            )->a( n = `selectable` v = `false`
                            )->a( n = `href`       v = `https://sap.com`
                            )->a( n = `target`     v = `_blank`
                            )->a( n = `text`       v = `External Link`
                            )->a( n = `icon`       v = `sap-icon://attachment` ).

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

  ENDMETHOD.


  METHOD on_event.

    CASE client->get_event( ).

      WHEN `TOGGLE_EXPAND`.
        " original onCollapseExpandPress: toggles SideNavigation.expanded
        expanded = xsdbool( expanded = abap_false ).

      WHEN `QUICK_CREATE`.
        popup_quickcreate_display( ).

      WHEN `CREATE_ITEM`.
        " the Create button: addItem( new NavigationListItem({ text: sName ||
        " 'New Navigation Item', expanded: true, icon: sIcon || 'sap-icon://building' }) )
        " - reproduced 1:1 by appending the row the bound list renders
        INSERT VALUE #( text     = COND #( WHEN create_name IS NOT INITIAL
                                           THEN create_name
                                           ELSE `New Navigation Item` )
                        icon     = COND #( WHEN create_icon IS NOT INITIAL
                                           THEN create_icon
                                           ELSE `sap-icon://building` )
                        expanded = abap_true ) INTO TABLE t_nav_items.
        client->popup_destroy( ).

    ENDCASE.

  ENDMETHOD.


  METHOD popup_quickcreate_display.

    " original quickActionPress builds this Dialog imperatively (new Dialog({...}).open());
    " expressed as a core:FragmentDefinition shown via popup_display (declared deviation)
    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 = `Create Navigation List Item`

            )->ele( `content`
                )->tag( `Label`
                    )->a( n = `text`     v = `Name:`
                    )->a( n = `labelFor` v = `navigationItemName`
                )->tag( `Input`
                    )->a( n = `id`          v = `navigationItemName`
                    )->a( n = `width`       v = `100%`
                    )->a( n = `placeholder` v = `Name`
                    )->a( n = `value`       v = client->_bind( create_name )
                )->tag( `Label`
                    )->a( n = `text`     v = `Icon:`
                    )->a( n = `labelFor` v = `navigationItemIcon`
                )->tag( `Input`
                    )->a( n = `id`          v = `navigationItemIcon`
                    )->a( n = `width`       v = `100%`
                    )->a( n = `placeholder` v = `sap-icon://home`
                    )->a( n = `value`       v = client->_bind( create_icon )

            )->end(
            )->ele( `beginButton`
                )->tag( `Button`
                    )->a( n = `type`  v = `Emphasized`
                    )->a( n = `text`  v = `Create`
                    )->a( n = `press` v = client->_event( `CREATE_ITEM` )

            )->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 model_init.

    " the four items the sample declares on the main NavigationList
    t_nav_items = VALUE #( ( text = `Home`      icon = `sap-icon://home` )
                           ( text = `Building`  icon = `sap-icon://building` )
                           ( text = `Mileage`   icon = `sap-icon://mileage` )
                           ( text = `Transport` icon = `sap-icon://map-2` ) ).

  ENDMETHOD.

ENDCLASS.

More in sap.tnt

Search every abap2UI5 sample · the full list on one page

On this page