|
| 1 | +CLASS z2ui5_cl_demo_app_279 DEFINITION |
| 2 | + PUBLIC |
| 3 | + FINAL |
| 4 | + CREATE PUBLIC . |
| 5 | + |
| 6 | + PUBLIC SECTION. |
| 7 | + |
| 8 | + INTERFACES if_serializable_object . |
| 9 | + INTERFACES z2ui5_if_app . |
| 10 | + |
| 11 | + DATA text_input TYPE string . |
| 12 | + DATA dirty TYPE abap_bool. |
| 13 | + |
| 14 | + PRIVATE SECTION. |
| 15 | + DATA client TYPE REF TO z2ui5_if_client. |
| 16 | + DATA initialized TYPE abap_bool. |
| 17 | + |
| 18 | + METHODS display_view. |
| 19 | + METHODS on_event. |
| 20 | + METHODS render_popup. |
| 21 | + |
| 22 | +ENDCLASS. |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | +CLASS z2ui5_cl_demo_app_279 IMPLEMENTATION. |
| 27 | + |
| 28 | + |
| 29 | + METHOD display_view. |
| 30 | + |
| 31 | + DATA(page) = z2ui5_cl_xml_view=>factory( |
| 32 | + )->shell( |
| 33 | + )->page( |
| 34 | + title = 'abap2UI5 - data loss protection' |
| 35 | + navbuttonpress = client->_event( 'BACK' ) |
| 36 | + shownavbutton = xsdbool( client->get( )-s_draft-id_prev_app_stack IS NOT INITIAL ) ). |
| 37 | + |
| 38 | + DATA(box) = page->flex_box( direction = `Row` alignitems = `Start` class = 'sapUiTinyMargin' ). |
| 39 | + |
| 40 | + box->input( |
| 41 | + id = `input` |
| 42 | + value = client->_bind_edit( text_input ) |
| 43 | + submit = client->_event( 'submit' ) |
| 44 | + width = `40rem` |
| 45 | + placeholder = `Enter data, submit and navigate back to trigger data loss protection` ). |
| 46 | + |
| 47 | + box->info_label( |
| 48 | + text = 'dirty' |
| 49 | + colorscheme = '8' |
| 50 | + icon = 'sap-icon://message-success' |
| 51 | + class = `sapUiSmallMarginBegin sapUiTinyMarginTop` |
| 52 | + visible = client->_bind( dirty ) ). |
| 53 | + |
| 54 | + box->button( |
| 55 | + text = 'Reset' |
| 56 | + press = client->_event( 'reset' ) |
| 57 | + class = `sapUiSmallMarginBegin` |
| 58 | + visible = client->_bind( dirty ) ). |
| 59 | + |
| 60 | + page->_z2ui5( )->focus( focusid = `input` ). |
| 61 | + |
| 62 | +* page->_z2ui5( )->dirty( dirty ). |
| 63 | + page->_z2ui5( )->dirty( client->_bind( dirty ) ). |
| 64 | +* page->_z2ui5( )->dirty( '{= $' && client->_bind_Edit( text_input ) && ' !== "" }' ). |
| 65 | + |
| 66 | + client->view_display( page->stringify( ) ). |
| 67 | + |
| 68 | + ENDMETHOD. |
| 69 | + |
| 70 | + |
| 71 | + METHOD on_event. |
| 72 | + |
| 73 | + CASE client->get( )-event. |
| 74 | + WHEN 'BACK'. |
| 75 | + IF text_input IS NOT INITIAL. |
| 76 | + render_popup( ). |
| 77 | + ELSE. |
| 78 | + client->nav_app_leave( ). |
| 79 | + ENDIF. |
| 80 | + WHEN 'submit'. |
| 81 | + dirty = xsdbool( text_input IS NOT INITIAL ). |
| 82 | + WHEN 'reset'. |
| 83 | + CLEAR: |
| 84 | + dirty, |
| 85 | + text_input. |
| 86 | + WHEN 'popup_decide_cancel'. |
| 87 | + CLEAR: dirty. |
| 88 | + client->popup_destroy( ). |
| 89 | + client->nav_app_leave( ). |
| 90 | + WHEN 'popup_decide_continue'. |
| 91 | + client->popup_destroy( ). |
| 92 | + ENDCASE. |
| 93 | + |
| 94 | + ENDMETHOD. |
| 95 | + |
| 96 | + |
| 97 | + METHOD render_popup. |
| 98 | + |
| 99 | + DATA(popup) = z2ui5_cl_xml_view=>factory_popup( ). |
| 100 | + popup->dialog( title = 'Warning' icon = 'sap-icon://status-critical' |
| 101 | + )->vbox( |
| 102 | + )->text( text = 'Your entries will be lost when you leave this page.' |
| 103 | + class ='sapUiSmallMargin' |
| 104 | + )->get_parent( |
| 105 | + )->buttons( |
| 106 | + )->button( |
| 107 | + text = 'Leave Page' |
| 108 | + type = 'Emphasized' |
| 109 | + press = client->_event( 'popup_decide_cancel' ) |
| 110 | + )->button( |
| 111 | + text = 'Cancel' |
| 112 | + press = client->_event( 'popup_decide_continue' ) ). |
| 113 | + |
| 114 | + client->popup_display( popup->stringify( ) ). |
| 115 | + |
| 116 | + ENDMETHOD. |
| 117 | + |
| 118 | + |
| 119 | + METHOD z2ui5_if_app~main. |
| 120 | + |
| 121 | + me->client = client. |
| 122 | + |
| 123 | + on_event( ). |
| 124 | + |
| 125 | + IF initialized = abap_false. |
| 126 | + initialized = abap_true. |
| 127 | + display_view( ). |
| 128 | + ELSE. |
| 129 | + client->view_model_update( ). |
| 130 | + ENDIF. |
| 131 | + |
| 132 | + ENDMETHOD. |
| 133 | +ENDCLASS. |
0 commit comments