Factorized code for checkbox and radio input.
Renamed `text' and similar to `title' and similar
This commit is contained in:
@@ -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 <input> 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
|
||||
|
||||
@@ -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 <input> 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
|
||||
|
||||
@@ -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 <input> 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
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user