|
| 1 | +CLASS z2ui5_cl_cc_sample_messaging DEFINITION |
| 2 | + PUBLIC |
| 3 | + CREATE PUBLIC . |
| 4 | + |
| 5 | + PUBLIC SECTION. |
| 6 | + |
| 7 | + INTERFACES z2ui5_if_app . |
| 8 | + |
| 9 | + "string - constraints |
| 10 | + DATA: mv_maxlength_string TYPE string, |
| 11 | + mv_minlength_string TYPE string, |
| 12 | + mv_startswith_string TYPE string, |
| 13 | + mv_startswithignorecase_string TYPE string, |
| 14 | + mv_endswith_string TYPE string, |
| 15 | + mv_endswithignorecase_string TYPE string, |
| 16 | + mv_contains_string TYPE string, |
| 17 | + mv_equals_string TYPE string, |
| 18 | + mv_search_string TYPE string. |
| 19 | + |
| 20 | + |
| 21 | + "boolean |
| 22 | + DATA: mv_boolean TYPE abap_bool. |
| 23 | + DATA mt_messaging TYPE z2ui5_cl_cc_messaging=>ty_t_items. |
| 24 | + |
| 25 | + DATA: mv_messages_count TYPE i. |
| 26 | + |
| 27 | + |
| 28 | + DATA check_initialized TYPE abap_bool . |
| 29 | + |
| 30 | + METHODS z2ui5_display_view . |
| 31 | + METHODS z2ui5_display_popover |
| 32 | + IMPORTING |
| 33 | + !id TYPE string . |
| 34 | + PROTECTED SECTION. |
| 35 | + |
| 36 | + DATA client TYPE REF TO z2ui5_if_client. |
| 37 | + |
| 38 | + PRIVATE SECTION. |
| 39 | +ENDCLASS. |
| 40 | + |
| 41 | + |
| 42 | + |
| 43 | +CLASS z2ui5_cl_cc_sample_messaging IMPLEMENTATION. |
| 44 | + |
| 45 | + |
| 46 | + METHOD z2ui5_display_popover. |
| 47 | + |
| 48 | + DATA(popup) = z2ui5_cl_xml_view=>factory_popup( ). |
| 49 | + |
| 50 | + popup = popup->message_popover( |
| 51 | + placement = `Top` |
| 52 | + items = client->_bind_edit( mt_messaging ) |
| 53 | + groupitems = abap_true |
| 54 | + afterclose = client->_event( `POPOVER_CLOSE` ) |
| 55 | + )->message_item( |
| 56 | + type = `{TYPE}` |
| 57 | + title = `{MESSAGE}` |
| 58 | + subtitle = `{MESSAGE}` |
| 59 | + description = `{DESCRIPTION}` |
| 60 | + groupname = `{GROUP}` ). |
| 61 | + |
| 62 | + client->popover_display( xml = popup->stringify( ) by_id = id ). |
| 63 | + |
| 64 | + ENDMETHOD. |
| 65 | + |
| 66 | + |
| 67 | + METHOD z2ui5_display_view. |
| 68 | + |
| 69 | + DATA(view) = z2ui5_cl_xml_view=>factory( ). |
| 70 | + |
| 71 | + DATA(page) = view->_z2ui5( )->messaging( client->_bind_edit( mt_messaging ) |
| 72 | + )->shell( |
| 73 | + )->page( class = `sapUiContentPadding ` |
| 74 | + title = 'abap2UI5 - Messaging' |
| 75 | + navbuttonpress = client->_event( val = 'BACK' ) |
| 76 | + shownavbutton = abap_true |
| 77 | + )->header_content( |
| 78 | + )->link( |
| 79 | + text = 'Demo' target = '_blank' |
| 80 | + href = `https://twitter.com/abap2UI5/status/1647246029828268032` |
| 81 | + )->link( |
| 82 | + |
| 83 | + |
| 84 | + )->get_parent( ). |
| 85 | + |
| 86 | + "string |
| 87 | + page->flex_box( justifycontent = `SpaceAround` )->panel( headertext = `sap.ui.model.type.String` |
| 88 | + )->vbox( |
| 89 | + )->title( text = `CONSTRAINTS` level = `H3` |
| 90 | + )->vbox( |
| 91 | + )->hbox( class = `sapUiTinyMarginTopBottom` alignitems = `Center` |
| 92 | + )->label( text = `maxLength (5)` |
| 93 | + )->input( id = `testINPUT` value = `{path:'` && client->_bind_edit( val = mv_maxlength_string path = abap_true ) && `',type: 'sap.ui.model.type.String', constraints:{ maxLength: 5 } }` |
| 94 | + editable = abap_true |
| 95 | + class = `sapUiTinyMarginBeginEnd` )->get_parent( |
| 96 | + |
| 97 | + )->hbox( class = `sapUiTinyMarginTopBottom` alignitems = `Center` |
| 98 | + )->label( text = `minLength (3)` |
| 99 | + )->input( value = `{path:'` && client->_bind_edit( val = mv_minlength_string path = abap_true ) && `',type: 'sap.ui.model.type.String', constraints:{ minLength: 3 } }` |
| 100 | + editable = abap_true |
| 101 | + class = `sapUiTinyMarginBeginEnd` )->get_parent( |
| 102 | + |
| 103 | + )->hbox( class = `sapUiTinyMarginTopBottom` alignitems = `Center` |
| 104 | + )->label( text = `startsWith (a2ui5)` |
| 105 | + )->input( value = `{path:'` && client->_bind_edit( val = mv_startswith_string path = abap_true ) && `',type: 'sap.ui.model.type.String', constraints:{ startsWith: 'a2ui5' } }` |
| 106 | + editable = abap_true |
| 107 | + class = `sapUiTinyMarginBeginEnd` ). |
| 108 | + |
| 109 | + page->footer( )->overflow_toolbar( |
| 110 | + )->button( |
| 111 | + id = 'test' |
| 112 | +* text = 'Messages' |
| 113 | + icon = 'sap-icon://message-popup' |
| 114 | + press = client->_event( 'POPOVER' ) |
| 115 | + type = 'Default' |
| 116 | +* class = `sapUiSizeCozy` |
| 117 | + )->get( )->custom_data( |
| 118 | + )->badge_custom_data( |
| 119 | + value = '{= ${' && client->_bind_edit( val = mt_messaging path = abap_true ) && '}.length}' |
| 120 | +* value = client->_bind_edit( mv_messages_count ) |
| 121 | + visible = abap_true |
| 122 | + key = 'badge' )->get_parent( )->get_parent( |
| 123 | + )->toolbar_spacer( |
| 124 | + )->button( |
| 125 | + text = 'REMOVE_MSG' |
| 126 | + press = client->_event( 'REMOVE_MSG' ) |
| 127 | + type = 'Success' |
| 128 | + )->button( |
| 129 | + text = 'ADD_MSG' |
| 130 | + press = client->_event( 'ADD_MSG' ) |
| 131 | + type = 'Success' |
| 132 | + )->button( |
| 133 | + text = 'Send to Server' |
| 134 | + press = client->_event( 'BUTTON_SEND' ) |
| 135 | + type = 'Success' ). |
| 136 | + |
| 137 | + client->view_display( view->stringify( ) ). |
| 138 | + |
| 139 | + ENDMETHOD. |
| 140 | + |
| 141 | + |
| 142 | + METHOD z2ui5_if_app~main. |
| 143 | + |
| 144 | + me->client = client. |
| 145 | + |
| 146 | + IF check_initialized = abap_false. |
| 147 | + check_initialized = abap_true. |
| 148 | + |
| 149 | + DATA(view) = z2ui5_cl_xml_view=>factory( ). |
| 150 | + client->view_display( |
| 151 | + view->_generic( ns = `html` name = `script` )->_cc_plain_xml( z2ui5_cl_cc_messaging=>get_js( ) |
| 152 | + )->_z2ui5( )->timer( client->_event( `ON_CC_LOADED` ) |
| 153 | + )->stringify( ) ). |
| 154 | + RETURN. |
| 155 | + |
| 156 | + ENDIF. |
| 157 | + |
| 158 | + CASE client->get( )-event. |
| 159 | + |
| 160 | + WHEN `ON_CC_LOADED`. |
| 161 | + z2ui5_display_view( ). |
| 162 | + |
| 163 | + WHEN `REMOVE_MSG`. |
| 164 | + CLEAR mt_messaging. |
| 165 | + z2ui5_display_view( ). |
| 166 | + client->view_model_update( ). |
| 167 | + |
| 168 | + WHEN `ADD_MSG`. |
| 169 | + INSERT VALUE #( |
| 170 | + message = `this is a message` |
| 171 | + type = `Error` |
| 172 | + target = `testINPUT/value` |
| 173 | + ) INTO TABLE mt_messaging. |
| 174 | + client->view_model_update( ). |
| 175 | + |
| 176 | + WHEN 'POPOVER_CLOSE'. |
| 177 | + client->message_toast_display( `POPOVER_CLOSE` ). |
| 178 | + |
| 179 | + WHEN 'BUTTON_SEND'. |
| 180 | + DATA(lv_string) = `mt_messaging is filled with data`. |
| 181 | + |
| 182 | + WHEN 'POPOVER'. |
| 183 | + z2ui5_display_popover( `test` ). |
| 184 | + |
| 185 | + WHEN 'BACK'. |
| 186 | + client->nav_app_leave( client->get_app( client->get( )-s_draft-id_prev_app_stack ) ). |
| 187 | + ENDCASE. |
| 188 | + |
| 189 | + ENDMETHOD. |
| 190 | +ENDCLASS. |
0 commit comments