From 334f7a362b97d1b3b024fe1ab7232e22cdf0b99b Mon Sep 17 00:00:00 2001 From: Jocelyn Fiat Date: Fri, 8 Mar 2013 16:01:05 +0100 Subject: [PATCH] Factorized code for checkbox and radio input. Renamed `text' and similar to `title' and similar --- .../src/kernel/form/cms_form_checkbox_input.e | 100 +--------------- .../src/kernel/form/cms_form_radio_input.e | 44 +------ .../kernel/form/cms_form_selectable_input.e | 112 ++++++++++++++++++ .../modules/user/user_edit_cms_execution.e | 4 +- 4 files changed, 119 insertions(+), 141 deletions(-) create mode 100644 draft/application/cms/src/kernel/form/cms_form_selectable_input.e diff --git a/draft/application/cms/src/kernel/form/cms_form_checkbox_input.e b/draft/application/cms/src/kernel/form/cms_form_checkbox_input.e index 5672b1a8..d0860bf1 100644 --- a/draft/application/cms/src/kernel/form/cms_form_checkbox_input.e +++ b/draft/application/cms/src/kernel/form/cms_form_checkbox_input.e @@ -8,112 +8,16 @@ class CMS_FORM_CHECKBOX_INPUT inherit - CMS_FORM_INPUT - rename - default_value as value - redefine - set_value, - specific_input_attributes_string, - append_child_to_html - end - - CMS_FORM_SELECTABLE_ITEM - rename - is_selected as checked, - set_is_selected as set_checked - end + CMS_FORM_SELECTABLE_INPUT create make, - make_with_text + make_with_value feature -- Access - checked: BOOLEAN - -- Current element should be preselected when the page loads - input_type: STRING = "checkbox" - text: detachable READABLE_STRING_32 - - raw_text: detachable READABLE_STRING_8 - -feature -- Status report - - is_same_value (v: READABLE_STRING_32): BOOLEAN - do - Result := attached value as l_value and then v.same_string (l_value) - end - -feature -- Change - - set_text (t: detachable READABLE_STRING_32) - do - text := t - end - - set_raw_text (t: detachable READABLE_STRING_8) - do - raw_text := t - end - - set_checked (b: like checked) - do - checked := b - end - - set_checked_by_value (v: detachable WSF_VALUE) - do - if attached {WSF_STRING} v as s then - if value /= Void then - set_checked (is_same_value (s.value)) - else - set_checked (s.value.same_string ("on") or s.value.same_string ("true") or s.value.same_string ("yes") or s.value.same_string ("enabled")) - end - else - set_checked (False) - end - end - - set_value (v: detachable WSF_VALUE) - -- Set value `v' if applicable to Current - do - if attached {ITERABLE [WSF_VALUE]} v as lst then - across - lst as c - loop - set_checked_by_value (c.item) - end - else - set_checked_by_value (v) - Precursor (v) - end - end - -feature {NONE} -- Implementation - - append_child_to_html (a_theme: CMS_THEME; a_html: STRING_8) - -- Specific child element if any. - --| To redefine if needed - do - if attached raw_text as t then - a_html.append (t) - elseif attached text as t then - a_html.append (a_theme.html_encoded (t)) --- elseif attached value as v then --- a_html.append (a_theme.html_encoded (v)) - end - end - - specific_input_attributes_string: detachable STRING_8 - -- Specific input attributes if any. - -- To redefine if needed - do - if checked then - Result := "checked=%"checked%"" - end - end - invariant end diff --git a/draft/application/cms/src/kernel/form/cms_form_radio_input.e b/draft/application/cms/src/kernel/form/cms_form_radio_input.e index 3d928d82..78288dca 100644 --- a/draft/application/cms/src/kernel/form/cms_form_radio_input.e +++ b/draft/application/cms/src/kernel/form/cms_form_radio_input.e @@ -8,54 +8,16 @@ class CMS_FORM_RADIO_INPUT inherit - CMS_FORM_INPUT - rename - default_value as value - redefine - specific_input_attributes_string - end - - CMS_FORM_SELECTABLE_ITEM - rename - is_selected as checked, - set_is_selected as set_checked - end + CMS_FORM_SELECTABLE_INPUT create - make + make, + make_with_value feature -- Access - checked: BOOLEAN - -- Current element should be preselected when the page loads - input_type: STRING = "radio" -feature -- Status report - - is_same_value (v: READABLE_STRING_32): BOOLEAN - do - Result := attached value as l_value and then v.same_string (l_value) - end - -feature -- Change - - set_checked (b: like checked) - do - checked := b - end - -feature {NONE} -- Implementation - - specific_input_attributes_string: detachable STRING_8 - -- Specific input attributes if any. - -- To redefine if needed - do - if checked then - Result := "checked=%"checked%"" - end - end - invariant end diff --git a/draft/application/cms/src/kernel/form/cms_form_selectable_input.e b/draft/application/cms/src/kernel/form/cms_form_selectable_input.e new file mode 100644 index 00000000..07a711ca --- /dev/null +++ b/draft/application/cms/src/kernel/form/cms_form_selectable_input.e @@ -0,0 +1,112 @@ +note + description: "Summary description for {CMS_FORM_SELECTABLE_INPUT}." + author: "" + date: "$Date$" + revision: "$Revision$" + +deferred class + CMS_FORM_SELECTABLE_INPUT + +inherit + CMS_FORM_INPUT + rename + default_value as value, + make_with_text as make_with_value + redefine + set_value, + specific_input_attributes_string, + append_child_to_html + end + + CMS_FORM_SELECTABLE_ITEM + rename + is_selected as checked, + set_is_selected as set_checked + end + +feature -- Access + + checked: BOOLEAN + -- Current element should be preselected when the page loads + + title: detachable READABLE_STRING_32 + + raw_title: detachable READABLE_STRING_8 + +feature -- Status report + + is_same_value (v: READABLE_STRING_32): BOOLEAN + do + Result := attached value as l_value and then v.same_string (l_value) + end + +feature -- Change + + set_title (t: detachable READABLE_STRING_32) + do + title := t + end + + set_raw_title (t: detachable READABLE_STRING_8) + do + raw_title := t + end + + set_checked (b: like checked) + do + checked := b + end + + set_checked_by_value (v: detachable WSF_VALUE) + do + if attached {WSF_STRING} v as s then + if value /= Void then + set_checked (is_same_value (s.value)) + else + set_checked (s.value.same_string ("on") or s.value.same_string ("true") or s.value.same_string ("yes") or s.value.same_string ("enabled")) + end + else + set_checked (False) + end + end + + set_value (v: detachable WSF_VALUE) + -- Set value `v' if applicable to Current + do + if attached {ITERABLE [WSF_VALUE]} v as lst then + across + lst as c + loop + set_checked_by_value (c.item) + end + else + set_checked_by_value (v) + Precursor (v) + end + end + +feature {NONE} -- Implementation + + append_child_to_html (a_theme: CMS_THEME; a_html: STRING_8) + -- Specific child element if any. + --| To redefine if needed + do + if attached raw_title as t then + a_html.append (t) + elseif attached title as t then + a_html.append (a_theme.html_encoded (t)) + end + end + + specific_input_attributes_string: detachable STRING_8 + -- Specific input attributes if any. + -- To redefine if needed + do + if checked then + Result := "checked=%"checked%"" + end + end + +invariant + +end diff --git a/draft/application/cms/src/modules/user/user_edit_cms_execution.e b/draft/application/cms/src/modules/user/user_edit_cms_execution.e index 99a20669..37afd19a 100644 --- a/draft/application/cms/src/modules/user/user_edit_cms_execution.e +++ b/draft/application/cms/src/modules/user/user_edit_cms_execution.e @@ -196,8 +196,8 @@ feature -- Execution then -- Skip else - create cb.make_with_text ("roles[]", r.item.id.out) - cb.set_text (r.item.name) + create cb.make_with_value ("roles[]", r.item.id.out) + cb.set_title (r.item.name) cb.set_checked (u /= Void and then u.has_role (r.item)) tset.extend (cb) end