Skip to content

Commit a993d79

Browse files
306: use reusable image editor popup (#555)
1 parent 83241d4 commit a993d79

File tree

1 file changed

+36
-69
lines changed

1 file changed

+36
-69
lines changed

src/z2ui5_cl_demo_app_306.clas.abap

Lines changed: 36 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
CLASS z2ui5_cl_demo_app_306 DEFINITION
22
PUBLIC
3-
FINAL
43
CREATE PUBLIC .
54

65
PUBLIC SECTION.
@@ -36,17 +35,12 @@ CLASS z2ui5_cl_demo_app_306 DEFINITION
3635

3736
PROTECTED SECTION.
3837

39-
METHODS view_display
40-
IMPORTING
41-
client TYPE REF TO z2ui5_if_client.
42-
43-
METHODS edit
44-
IMPORTING
45-
client TYPE REF TO z2ui5_if_client.
38+
METHODS view_display.
39+
METHODS edit_image.
40+
METHODS ui5_callback.
4641

4742
DATA selected_picture TYPE ty_picture.
48-
49-
PRIVATE SECTION.
43+
DATA client TYPE REF TO z2ui5_if_client.
5044

5145
ENDCLASS.
5246

@@ -108,36 +102,29 @@ CLASS z2ui5_cl_demo_app_306 IMPLEMENTATION.
108102
page->button( text = 'Edit' icon = 'sap-icon://edit' press = client->_event( 'EDIT' ) ).
109103
ENDIF.
110104

111-
112-
view->_generic( name = `script`
113-
ns = `html`
114-
)->_cc_plain_xml(
115-
'z2ui5.sendImage = () => { ' &&
116-
' const image = sap.ui.core.Fragment.byId("popupId", "imageEditor").getImagePngDataURL();' &&
117-
' z2ui5.oController.PopupDestroy();' && |\n| &&
118-
' z2ui5.oController.eB([`SAVE`],image);' &&
119-
'}'
120-
).
121-
122105
client->view_display( view->stringify( ) ).
123106

124107
ENDMETHOD.
125108

126109

127110
METHOD z2ui5_if_app~main.
128111

129-
IF mv_check_init = abap_false.
130-
131-
mv_check_init = abap_true.
112+
me->client = client.
132113

114+
IF me->z2ui5_if_app~check_initialized = abap_false.
133115
facing_modes = VALUE tt_combo( ( key = `` text = `` )
134116
( key = `environment` text = `environment` )
135117
( key = `user` text = `user` )
136118
( key = `left` text = `left` )
137119
( key = `right` text = `right` ) ).
138120

139-
view_display( client ).
121+
view_display( ).
122+
ENDIF.
140123

124+
IF client->get( )-check_on_navigated = abap_true.
125+
ui5_callback( ).
126+
view_display( ).
127+
RETURN.
141128
ENDIF.
142129

143130

@@ -152,22 +139,11 @@ CLASS z2ui5_cl_demo_app_306 IMPLEMENTATION.
152139

153140
selected_picture = mt_picture_out[ selected = abap_true ].
154141
mv_pic_display = mt_picture[ selected_picture-id ]-data.
155-
view_display( client ).
142+
view_display( ).
156143

157144
WHEN 'EDIT'.
158145

159-
edit( client ).
160-
161-
WHEN 'SAVE'.
162-
163-
DATA(args) = client->get( )-t_event_arg.
164-
165-
ASSIGN mt_picture[ selected_picture-id ] TO FIELD-SYMBOL(<picture>).
166-
IF sy-subrc = 0.
167-
mv_pic_display = <picture>-data = args[ 1 ].
168-
ENDIF.
169-
170-
view_display( client ).
146+
edit_image( ).
171147

172148
WHEN 'BACK'.
173149

@@ -182,38 +158,29 @@ CLASS z2ui5_cl_demo_app_306 IMPLEMENTATION.
182158

183159
ENDMETHOD.
184160

185-
METHOD edit.
186-
187-
DATA(popup) = z2ui5_cl_xml_view=>factory_popup(
188-
)->dialog(
189-
title = 'Edit Picture'
190-
icon = 'sap-icon://edit'
191-
contentheight = `80%`
192-
contentwidth = `80%` ).
193-
194-
popup->_generic(
195-
name = 'ImageEditorContainer'
196-
ns = 'ie'
197-
)->_generic(
198-
name = 'ImageEditor'
199-
ns = 'ie'
200-
t_prop = VALUE #(
201-
( n = `id` v = `imageEditor` )
202-
( n = `src` v = mv_pic_display ) ) ).
203-
204-
popup->footer( )->overflow_toolbar(
205-
)->button(
206-
text = 'Cancel'
207-
type = 'Reject'
208-
press = client->_event_client( client->cs_event-popup_close )
209-
)->toolbar_spacer(
210-
)->button(
211-
text = 'Save'
212-
type = 'Emphasized'
213-
press = client->_event_client( val = `Z2UI5` t_arg = VALUE #( ( `sendImage` ) ) ) ).
214-
215-
client->popup_display( popup->stringify( ) ).
161+
METHOD edit_image.
162+
163+
client->nav_app_call( z2ui5_cl_pop_image_editor=>factory( mv_pic_display ) ).
164+
165+
ENDMETHOD.
166+
167+
168+
METHOD ui5_callback.
169+
170+
TRY.
171+
DATA(lo_prev) = client->get_app( client->get( )-s_draft-id_prev_app ).
172+
DATA(result) = CAST z2ui5_cl_pop_image_editor( lo_prev )->result( ).
173+
174+
IF result-check_confirmed = abap_true.
175+
mv_pic_display = result-image.
176+
ASSIGN mt_picture[ selected_picture-id ] TO FIELD-SYMBOL(<picture>).
177+
IF sy-subrc = 0.
178+
<picture>-data = mv_pic_display.
179+
ENDIF.
180+
ENDIF.
216181

182+
CATCH cx_root.
183+
ENDTRY.
217184
ENDMETHOD.
218185

219186
ENDCLASS.

0 commit comments

Comments
 (0)