mirror of
https://github.com/abapGit/abapGit.git
synced 2025-05-01 04:08:27 +08:00
Dialogs: HTML form enhancements (#4264)
* Dialogs: HTML form tweaks - Minor increase of contrast for background, input- and readonly fields - Add read-only option for columns of table control * Add is_empty * Add init and hidden * Render * Remove init Co-authored-by: Lars Hvam <larshp@hotmail.com>
This commit is contained in:
parent
869c0bccb5
commit
d0983cf386
|
@ -1145,7 +1145,6 @@ settings_tab tr:first-child td { border-top: 0px; }
|
|||
background-color: white;
|
||||
}
|
||||
.dialog table td input {
|
||||
margin: 0px 2px;
|
||||
border: 0px;
|
||||
background: none;
|
||||
}
|
||||
|
|
|
@ -475,14 +475,16 @@ table.settings_tab input:focus {
|
|||
.dialog input::placeholder { color: #ccc }
|
||||
.dialog input:-ms-input-placeholder { color: #ccc }
|
||||
.dialog {
|
||||
border-color: #cbcbcb;
|
||||
background-color: #f4f4f4;
|
||||
border-color: #ccc;
|
||||
background-color: #f0f0f0;
|
||||
}
|
||||
.dialog li.dialog-commands a {
|
||||
border-color: #ccc;
|
||||
background-color: #ddd;
|
||||
}
|
||||
.dialog li.dialog-commands input[type="submit"] {
|
||||
border-color: #ccc;
|
||||
background-color: #ddd;
|
||||
}
|
||||
.dialog li.dialog-commands input[type="submit"].main {
|
||||
background-color: #64a8ff;
|
||||
|
|
|
@ -5,7 +5,14 @@ CLASS zcl_abapgit_html_form DEFINITION
|
|||
|
||||
PUBLIC SECTION.
|
||||
|
||||
CONSTANTS c_rows TYPE string VALUE 'rows' ##NO_TEXT.
|
||||
CONSTANTS c_rows TYPE string VALUE 'rows'.
|
||||
|
||||
CONSTANTS:
|
||||
BEGIN OF c_cmd_type,
|
||||
input TYPE i VALUE 1,
|
||||
link TYPE i VALUE 2,
|
||||
button TYPE i VALUE 3,
|
||||
END OF c_cmd_type.
|
||||
|
||||
CLASS-METHODS create
|
||||
IMPORTING
|
||||
|
@ -25,7 +32,7 @@ CLASS zcl_abapgit_html_form DEFINITION
|
|||
!iv_label TYPE csequence
|
||||
!iv_action TYPE csequence
|
||||
!iv_is_main TYPE abap_bool DEFAULT abap_false
|
||||
!iv_as_a TYPE abap_bool DEFAULT abap_false
|
||||
!iv_cmd_type TYPE i DEFAULT 1
|
||||
RETURNING
|
||||
VALUE(ro_self) TYPE REF TO zcl_abapgit_html_form.
|
||||
METHODS text
|
||||
|
@ -96,6 +103,7 @@ CLASS zcl_abapgit_html_form DEFINITION
|
|||
IMPORTING
|
||||
!iv_label TYPE csequence
|
||||
!iv_width TYPE csequence OPTIONAL
|
||||
!iv_readonly TYPE abap_bool DEFAULT abap_false
|
||||
RETURNING
|
||||
VALUE(ro_self) TYPE REF TO zcl_abapgit_html_form.
|
||||
METHODS start_group
|
||||
|
@ -119,13 +127,27 @@ CLASS zcl_abapgit_html_form DEFINITION
|
|||
VALUE(ro_validation_log) TYPE REF TO zcl_abapgit_string_map
|
||||
RAISING
|
||||
zcx_abapgit_exception.
|
||||
METHODS is_empty
|
||||
IMPORTING
|
||||
!io_form_data TYPE REF TO zcl_abapgit_string_map
|
||||
RETURNING
|
||||
VALUE(rv_empty) TYPE abap_bool
|
||||
RAISING
|
||||
zcx_abapgit_exception.
|
||||
METHODS hidden
|
||||
IMPORTING
|
||||
!iv_name TYPE csequence
|
||||
RETURNING
|
||||
VALUE(ro_self) TYPE REF TO zcl_abapgit_html_form.
|
||||
|
||||
PROTECTED SECTION.
|
||||
PRIVATE SECTION.
|
||||
|
||||
TYPES:
|
||||
BEGIN OF ty_subitem,
|
||||
label TYPE string,
|
||||
value TYPE string,
|
||||
label TYPE string,
|
||||
value TYPE string,
|
||||
readonly TYPE abap_bool,
|
||||
END OF ty_subitem.
|
||||
TYPES:
|
||||
ty_subitems TYPE STANDARD TABLE OF ty_subitem WITH DEFAULT KEY.
|
||||
|
@ -152,10 +174,10 @@ CLASS zcl_abapgit_html_form DEFINITION
|
|||
END OF ty_field.
|
||||
TYPES:
|
||||
BEGIN OF ty_command,
|
||||
label TYPE string,
|
||||
action TYPE string,
|
||||
is_main TYPE abap_bool,
|
||||
as_a TYPE abap_bool,
|
||||
label TYPE string,
|
||||
action TYPE string,
|
||||
is_main TYPE abap_bool,
|
||||
cmd_type TYPE i,
|
||||
* onclick ???
|
||||
END OF ty_command.
|
||||
TYPES:
|
||||
|
@ -177,6 +199,7 @@ CLASS zcl_abapgit_html_form DEFINITION
|
|||
number TYPE i VALUE 5,
|
||||
textarea TYPE i VALUE 6,
|
||||
table TYPE i VALUE 7,
|
||||
hidden TYPE i VALUE 8,
|
||||
END OF c_field_type.
|
||||
DATA:
|
||||
mt_fields TYPE STANDARD TABLE OF ty_field
|
||||
|
@ -222,6 +245,11 @@ CLASS zcl_abapgit_html_form DEFINITION
|
|||
IMPORTING
|
||||
!ii_html TYPE REF TO zif_abapgit_html
|
||||
!is_cmd TYPE ty_command.
|
||||
METHODS render_field_hidden
|
||||
IMPORTING
|
||||
!ii_html TYPE REF TO zif_abapgit_html
|
||||
!is_field TYPE ty_field
|
||||
!is_attr TYPE ty_attr.
|
||||
ENDCLASS.
|
||||
|
||||
|
||||
|
@ -258,8 +286,9 @@ CLASS zcl_abapgit_html_form IMPLEMENTATION.
|
|||
ASSERT sy-subrc = 0.
|
||||
ASSERT <ls_last>-type = c_field_type-table.
|
||||
|
||||
ls_column-label = iv_label.
|
||||
ls_column-value = iv_width.
|
||||
ls_column-label = iv_label.
|
||||
ls_column-value = iv_width.
|
||||
ls_column-readonly = iv_readonly.
|
||||
|
||||
APPEND ls_column TO <ls_last>-subitems.
|
||||
|
||||
|
@ -272,12 +301,12 @@ CLASS zcl_abapgit_html_form IMPLEMENTATION.
|
|||
|
||||
DATA ls_cmd LIKE LINE OF mt_commands.
|
||||
|
||||
ASSERT iv_as_a IS INITIAL OR iv_is_main IS INITIAL.
|
||||
ASSERT iv_cmd_type BETWEEN 1 AND 3.
|
||||
|
||||
ls_cmd-label = iv_label.
|
||||
ls_cmd-action = iv_action.
|
||||
ls_cmd-is_main = iv_is_main.
|
||||
ls_cmd-as_a = iv_as_a.
|
||||
ls_cmd-label = iv_label.
|
||||
ls_cmd-action = iv_action.
|
||||
ls_cmd-is_main = iv_is_main.
|
||||
ls_cmd-cmd_type = iv_cmd_type.
|
||||
|
||||
APPEND ls_cmd TO mt_commands.
|
||||
|
||||
|
@ -302,16 +331,75 @@ CLASS zcl_abapgit_html_form IMPLEMENTATION.
|
|||
ENDMETHOD.
|
||||
|
||||
|
||||
METHOD hidden.
|
||||
|
||||
DATA ls_field LIKE LINE OF mt_fields.
|
||||
|
||||
ls_field-type = c_field_type-hidden.
|
||||
ls_field-name = iv_name.
|
||||
APPEND ls_field TO mt_fields.
|
||||
|
||||
ENDMETHOD.
|
||||
|
||||
|
||||
METHOD is_empty.
|
||||
|
||||
DATA:
|
||||
lv_value TYPE string,
|
||||
lv_rows TYPE i,
|
||||
lv_row TYPE i.
|
||||
|
||||
FIELD-SYMBOLS <ls_field> LIKE LINE OF mt_fields.
|
||||
|
||||
rv_empty = abap_true.
|
||||
LOOP AT mt_fields ASSIGNING <ls_field> WHERE type <> c_field_type-field_group.
|
||||
lv_value = condense(
|
||||
val = io_form_data->get( <ls_field>-name )
|
||||
del = ` ` ).
|
||||
|
||||
IF <ls_field>-type = c_field_type-number.
|
||||
rv_empty = boolc( lv_value IS INITIAL OR lv_value = '0' ).
|
||||
ELSEIF <ls_field>-type = c_field_type-table.
|
||||
lv_rows = io_form_data->get( |{ <ls_field>-name }-{ c_rows }| ).
|
||||
DO lv_rows TIMES.
|
||||
lv_row = sy-index.
|
||||
DO lines( <ls_field>-subitems ) TIMES.
|
||||
lv_value = io_form_data->get( |{ <ls_field>-name }-{ lv_row }-{ sy-index }| ).
|
||||
rv_empty = boolc( lv_value IS INITIAL ).
|
||||
IF rv_empty <> abap_true.
|
||||
RETURN.
|
||||
ENDIF.
|
||||
ENDDO.
|
||||
ENDDO.
|
||||
ELSEIF <ls_field>-type = c_field_type-textarea.
|
||||
REPLACE ALL OCCURRENCES OF zif_abapgit_definitions=>c_crlf IN lv_value WITH ''.
|
||||
REPLACE ALL OCCURRENCES OF zif_abapgit_definitions=>c_newline IN lv_value WITH ''.
|
||||
rv_empty = boolc( lv_value IS INITIAL ).
|
||||
ELSE.
|
||||
rv_empty = boolc( lv_value IS INITIAL ).
|
||||
ENDIF.
|
||||
|
||||
IF rv_empty <> abap_true.
|
||||
RETURN.
|
||||
ENDIF.
|
||||
ENDLOOP.
|
||||
|
||||
ENDMETHOD.
|
||||
|
||||
|
||||
METHOD normalize_form_data.
|
||||
|
||||
DATA lv_value TYPE string.
|
||||
DATA lv_rows TYPE i.
|
||||
DATA lv_row TYPE i.
|
||||
DATA:
|
||||
lv_value TYPE string,
|
||||
lv_rows TYPE i,
|
||||
lv_row TYPE i,
|
||||
lv_len TYPE i.
|
||||
|
||||
FIELD-SYMBOLS <ls_field> LIKE LINE OF mt_fields.
|
||||
|
||||
CREATE OBJECT ro_form_data.
|
||||
|
||||
LOOP AT mt_fields ASSIGNING <ls_field>.
|
||||
LOOP AT mt_fields ASSIGNING <ls_field> WHERE type <> c_field_type-field_group.
|
||||
CLEAR lv_value.
|
||||
lv_value = io_form_data->get( <ls_field>-name ).
|
||||
|
||||
|
@ -339,6 +427,23 @@ CLASS zcl_abapgit_html_form IMPLEMENTATION.
|
|||
iv_val = lv_value ).
|
||||
ENDDO.
|
||||
ENDDO.
|
||||
ro_form_data->set(
|
||||
iv_key = |{ <ls_field>-name }-{ c_rows }|
|
||||
iv_val = |{ lv_rows }| ).
|
||||
ELSEIF <ls_field>-type = c_field_type-textarea.
|
||||
REPLACE ALL OCCURRENCES OF zif_abapgit_definitions=>c_crlf IN lv_value
|
||||
WITH zif_abapgit_definitions=>c_newline.
|
||||
|
||||
" Remove last line if empty (ie 2x newline)
|
||||
lv_len = strlen( lv_value ) - 2.
|
||||
IF lv_len >= 0 AND lv_value+lv_len(1) = zif_abapgit_definitions=>c_newline.
|
||||
lv_len = lv_len + 1.
|
||||
lv_value = lv_value(lv_len).
|
||||
ENDIF.
|
||||
|
||||
ro_form_data->set(
|
||||
iv_key = <ls_field>-name
|
||||
iv_val = lv_value ).
|
||||
ELSE.
|
||||
ro_form_data->set(
|
||||
iv_key = <ls_field>-name
|
||||
|
@ -504,20 +609,33 @@ CLASS zcl_abapgit_html_form IMPLEMENTATION.
|
|||
|
||||
DATA lv_main_submit TYPE string.
|
||||
|
||||
IF is_cmd-as_a = abap_true.
|
||||
ii_html->add_a(
|
||||
iv_txt = is_cmd-label
|
||||
iv_act = is_cmd-action
|
||||
iv_class = 'dialog-commands' ).
|
||||
ELSE.
|
||||
IF is_cmd-is_main = abap_true.
|
||||
lv_main_submit = ' class="main"'.
|
||||
ELSE.
|
||||
CLEAR lv_main_submit.
|
||||
ENDIF.
|
||||
ii_html->add( |<input type="submit" value="{
|
||||
is_cmd-label }"{ lv_main_submit } formaction="sapevent:{ is_cmd-action }">| ).
|
||||
ENDIF.
|
||||
CASE is_cmd-cmd_type.
|
||||
WHEN c_cmd_type-link.
|
||||
|
||||
ii_html->add_a(
|
||||
iv_txt = is_cmd-label
|
||||
iv_act = is_cmd-action
|
||||
iv_class = 'dialog-commands' ).
|
||||
|
||||
WHEN c_cmd_type-button.
|
||||
|
||||
ii_html->add( |<button type="submit" name="action" value="{
|
||||
is_cmd-action }" class="action-commands">{ is_cmd-label }</button>| ).
|
||||
|
||||
WHEN c_cmd_type-input.
|
||||
|
||||
IF is_cmd-is_main = abap_true.
|
||||
lv_main_submit = ' class="main"'.
|
||||
ELSE.
|
||||
CLEAR lv_main_submit.
|
||||
ENDIF.
|
||||
ii_html->add( |<input type="submit" value="{
|
||||
is_cmd-label }"{ lv_main_submit } formaction="sapevent:{ is_cmd-action }">| ).
|
||||
|
||||
WHEN OTHERS.
|
||||
ASSERT 0 = 1.
|
||||
|
||||
ENDCASE.
|
||||
|
||||
ENDMETHOD.
|
||||
|
||||
|
@ -615,6 +733,13 @@ CLASS zcl_abapgit_html_form IMPLEMENTATION.
|
|||
is_attr = ls_attr
|
||||
io_values = io_values ).
|
||||
|
||||
WHEN c_field_type-hidden.
|
||||
|
||||
render_field_hidden(
|
||||
ii_html = ii_html
|
||||
is_field = is_field
|
||||
is_attr = ls_attr ).
|
||||
|
||||
WHEN OTHERS.
|
||||
ASSERT 1 = 0.
|
||||
ENDCASE.
|
||||
|
@ -643,6 +768,14 @@ CLASS zcl_abapgit_html_form IMPLEMENTATION.
|
|||
ENDMETHOD.
|
||||
|
||||
|
||||
METHOD render_field_hidden.
|
||||
|
||||
ii_html->add( |<input type="hidden" name="{ is_field-name }" id="{
|
||||
is_field-name }" value="{ is_attr-value }">| ).
|
||||
|
||||
ENDMETHOD.
|
||||
|
||||
|
||||
METHOD render_field_radio.
|
||||
|
||||
DATA:
|
||||
|
@ -685,6 +818,7 @@ CLASS zcl_abapgit_html_form IMPLEMENTATION.
|
|||
|
||||
DATA:
|
||||
lv_value TYPE string,
|
||||
lv_readonly TYPE string,
|
||||
lv_rows TYPE i,
|
||||
lv_cell_id TYPE string,
|
||||
lv_opt_value TYPE string.
|
||||
|
@ -723,8 +857,12 @@ CLASS zcl_abapgit_html_form IMPLEMENTATION.
|
|||
lv_cell_id = |{ is_field-name }-{ lv_rows }-{ sy-tabix }|.
|
||||
lv_value = escape( val = io_values->get( lv_cell_id )
|
||||
format = cl_abap_format=>e_html_attr ).
|
||||
CLEAR lv_readonly.
|
||||
IF <ls_subitem>-readonly = abap_true.
|
||||
lv_readonly = | readonly|.
|
||||
ENDIF.
|
||||
ii_html->add( |<td><input type="text" name="{ lv_cell_id }" id="{
|
||||
lv_cell_id }" value="{ lv_value }"></td>| ).
|
||||
lv_cell_id }" value="{ lv_value }"{ lv_readonly }></td>| ).
|
||||
ENDLOOP.
|
||||
ii_html->add( |</tr>| ).
|
||||
ENDDO.
|
||||
|
@ -788,7 +926,7 @@ CLASS zcl_abapgit_html_form IMPLEMENTATION.
|
|||
ii_html->add( is_attr-error ).
|
||||
ENDIF.
|
||||
|
||||
lv_rows = lines( zcl_abapgit_convert=>split_string( is_attr-value ) ) + 1. " one new row
|
||||
lv_rows = lines( zcl_abapgit_convert=>split_string( is_attr-value ) ).
|
||||
|
||||
ii_html->add( |<textarea name="{ is_field-name }" id="{
|
||||
is_field-name }" rows="{ lv_rows }"{ is_attr-readonly }>| ).
|
||||
|
|
|
@ -8,6 +8,7 @@ CLASS ltcl_test_form DEFINITION
|
|||
|
||||
METHODS validate FOR TESTING RAISING zcx_abapgit_exception.
|
||||
METHODS normalize FOR TESTING RAISING zcx_abapgit_exception.
|
||||
METHODS is_empty FOR TESTING RAISING zcx_abapgit_exception.
|
||||
|
||||
ENDCLASS.
|
||||
|
||||
|
@ -271,4 +272,92 @@ CLASS ltcl_test_form IMPLEMENTATION.
|
|||
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD is_empty.
|
||||
|
||||
DATA lo_cut TYPE REF TO zcl_abapgit_html_form.
|
||||
DATA lo_form_data TYPE REF TO zcl_abapgit_string_map.
|
||||
|
||||
lo_cut = zcl_abapgit_html_form=>create( ).
|
||||
lo_form_data = zcl_abapgit_string_map=>create( ).
|
||||
|
||||
lo_cut->text(
|
||||
iv_name = 'field1'
|
||||
iv_label = 'Field name 1' ).
|
||||
lo_cut->checkbox(
|
||||
iv_name = 'chk1'
|
||||
iv_label = 'Checkbox1' ).
|
||||
lo_cut->number(
|
||||
iv_name = 'num1'
|
||||
iv_label = 'Number 1' ).
|
||||
lo_cut->table(
|
||||
iv_name = 'tab1'
|
||||
iv_label = 'Table 1' ).
|
||||
lo_cut->column( iv_label = 'Column 1' ).
|
||||
lo_cut->column( iv_label = 'Column 2' ).
|
||||
lo_cut->number(
|
||||
iv_name = |tab1-{ zcl_abapgit_html_form=>c_rows }|
|
||||
iv_label = 'Number of Rows' ). " simulate hidden form field
|
||||
|
||||
cl_abap_unit_assert=>assert_equals(
|
||||
act = lo_cut->is_empty( lo_form_data )
|
||||
exp = abap_true ).
|
||||
|
||||
lo_form_data->set(
|
||||
iv_key = 'field1'
|
||||
iv_val = 'val1' ).
|
||||
|
||||
cl_abap_unit_assert=>assert_equals(
|
||||
act = lo_cut->is_empty( lo_form_data )
|
||||
exp = abap_false ).
|
||||
|
||||
lo_form_data = zcl_abapgit_string_map=>create( ).
|
||||
lo_form_data->set(
|
||||
iv_key = 'chk1'
|
||||
iv_val = 'X' ).
|
||||
|
||||
cl_abap_unit_assert=>assert_equals(
|
||||
act = lo_cut->is_empty( lo_form_data )
|
||||
exp = abap_false ).
|
||||
|
||||
lo_form_data = zcl_abapgit_string_map=>create( ).
|
||||
lo_form_data->set(
|
||||
iv_key = 'num1'
|
||||
iv_val = '123' ).
|
||||
|
||||
cl_abap_unit_assert=>assert_equals(
|
||||
act = lo_cut->is_empty( lo_form_data )
|
||||
exp = abap_false ).
|
||||
|
||||
lo_form_data = zcl_abapgit_string_map=>create( ).
|
||||
lo_form_data->set(
|
||||
iv_key = 'num1'
|
||||
iv_val = '0' ).
|
||||
|
||||
cl_abap_unit_assert=>assert_equals(
|
||||
act = lo_cut->is_empty( lo_form_data )
|
||||
exp = abap_true ).
|
||||
|
||||
lo_form_data = zcl_abapgit_string_map=>create( ).
|
||||
lo_form_data->set(
|
||||
iv_key = |tab1-{ zcl_abapgit_html_form=>c_rows }|
|
||||
iv_val = '2' ).
|
||||
lo_form_data->set(
|
||||
iv_key = |tab1-1-1|
|
||||
iv_val = '' ).
|
||||
lo_form_data->set(
|
||||
iv_key = |tab1-1-2|
|
||||
iv_val = '' ).
|
||||
lo_form_data->set(
|
||||
iv_key = |tab1-2-1|
|
||||
iv_val = '' ).
|
||||
lo_form_data->set(
|
||||
iv_key = |tab1-2-2|
|
||||
iv_val = 'Hello' ).
|
||||
|
||||
cl_abap_unit_assert=>assert_equals(
|
||||
act = lo_cut->is_empty( lo_form_data )
|
||||
exp = abap_false ).
|
||||
|
||||
ENDMETHOD.
|
||||
|
||||
ENDCLASS.
|
||||
|
|
Loading…
Reference in New Issue
Block a user