|
| 1 | +CLASS z2ui5_cl_demo_app_327 DEFINITION |
| 2 | + PUBLIC FINAL |
| 3 | + CREATE PUBLIC. |
| 4 | + |
| 5 | + PUBLIC SECTION. |
| 6 | + INTERFACES z2ui5_if_app. |
| 7 | + |
| 8 | + TYPES: BEGIN OF ty_value, |
| 9 | + field1 TYPE i, |
| 10 | + field2 TYPE string, |
| 11 | + END OF ty_value. |
| 12 | + |
| 13 | + TYPES: BEGIN OF ty_storage, |
| 14 | + type TYPE string, |
| 15 | + prefix TYPE string, |
| 16 | + key TYPE string, |
| 17 | + value TYPE string, |
| 18 | +* value TYPE ty_value, |
| 19 | + END OF ty_storage. |
| 20 | + |
| 21 | + TYPES: BEGIN OF ty_storage_type, |
| 22 | + type TYPE string, |
| 23 | + END OF ty_storage_type. |
| 24 | + |
| 25 | + DATA storage TYPE ty_storage. |
| 26 | + DATA stored_value TYPE string. |
| 27 | + DATA storage_types TYPE STANDARD TABLE OF ty_storage_type. |
| 28 | + |
| 29 | +ENDCLASS. |
| 30 | + |
| 31 | + |
| 32 | +CLASS z2ui5_cl_demo_app_327 IMPLEMENTATION. |
| 33 | + METHOD z2ui5_if_app~main. |
| 34 | + IF client->check_on_init( ). |
| 35 | + |
| 36 | + storage_types = VALUE #( ( type = `local` ) |
| 37 | + ( type = `session` ) ). |
| 38 | + storage = VALUE #( type = `local` |
| 39 | + prefix = `prefix1` |
| 40 | + key = 'key1' |
| 41 | +* value = VALUE #( field1 = 1 |
| 42 | +* field2 = 'textfld1' ) |
| 43 | + ). |
| 44 | + |
| 45 | + DATA(view) = z2ui5_cl_xml_view=>factory( ). |
| 46 | + |
| 47 | + view->shell( |
| 48 | + )->page( title = 'abap2UI5 - Storage' |
| 49 | + navbuttonpress = client->_event( val = 'BACK' ) |
| 50 | + shownavbutton = xsdbool( client->get( )-s_draft-id_prev_app_stack IS NOT INITIAL ) |
| 51 | + |
| 52 | + )->simple_form( title = 'Local/Session Storage' |
| 53 | + editable = abap_true |
| 54 | + )->content( 'form' |
| 55 | + )->label( 'Type' |
| 56 | + )->select( forceselection = abap_true |
| 57 | + selectedkey = client->_bind_edit( storage-type ) |
| 58 | + items = client->_bind( storage_types ) |
| 59 | + )->item( key = '{TYPE}' |
| 60 | + text = '{TYPE}' |
| 61 | + )->get_parent( |
| 62 | + )->label( 'Prefix' |
| 63 | + )->input( client->_bind_edit( storage-prefix ) |
| 64 | + )->label( 'Key' |
| 65 | + )->input( client->_bind_edit( storage-key ) |
| 66 | + )->label( 'Value' |
| 67 | + )->input( client->_bind_edit( storage-value ) |
| 68 | + )->button( text = 'store' |
| 69 | + press = client->_event_client( val = z2ui5_if_client=>cs_event-store_data |
| 70 | + t_arg = VALUE #( ( |${ client->_bind_edit( storage ) }| ) ) ) |
| 71 | + |
| 72 | + )->button( text = 'get' |
| 73 | + press = client->_event( 'GET_STORED_VALUE' ) |
| 74 | + )->get_parent( |
| 75 | + )->get_parent( |
| 76 | + |
| 77 | + )->_z2ui5( )->storage( |
| 78 | + finished = client->_event( |
| 79 | + val = `LOCAL_STORAGE_LOADED` |
| 80 | + t_arg = VALUE #( ( `${$parameters>/type}` ) ( `${$parameters>/prefix}` ) ( `${$parameters>/key}` ) ( `${$parameters>/value}` ) ) ) |
| 81 | + type = client->_bind_edit( storage-type ) |
| 82 | + prefix = client->_bind_edit( storage-prefix ) |
| 83 | + key = client->_bind_edit( storage-key ) |
| 84 | + value = client->_bind_edit( stored_value ) ). |
| 85 | + client->view_display( view->stringify( ) ). |
| 86 | + |
| 87 | + ENDIF. |
| 88 | + |
| 89 | + CASE client->get( )-event. |
| 90 | + WHEN 'LOCAL_STORAGE_LOADED'. |
| 91 | +* z2ui5_cl_ajson=>parse( client->get_event_arg( 4 ) )->to_abap( IMPORTING ev_container = storage-value ). |
| 92 | + storage-value = client->get_event_arg( 4 ). |
| 93 | + client->view_model_update( ). |
| 94 | + WHEN 'GET_STORED_VALUE'. |
| 95 | +* z2ui5_cl_ajson=>parse( stored_value )->to_abap( IMPORTING ev_container = storage-value ). |
| 96 | + storage-value = stored_value. |
| 97 | + client->view_model_update( ). |
| 98 | + WHEN 'BACK'. |
| 99 | + client->nav_app_leave( client->get_app( client->get( )-s_draft-id_prev_app_stack ) ). |
| 100 | + ENDCASE. |
| 101 | + ENDMETHOD. |
| 102 | +ENDCLASS. |
0 commit comments