Updated comments and added contracts for core controls in webcontrol

This commit is contained in:
severin
2014-03-12 17:21:39 +01:00
parent 3c4e15b386
commit 4f7086a6de
13 changed files with 197 additions and 50 deletions

View File

@@ -25,24 +25,30 @@ create
feature {NONE} -- Initialization feature {NONE} -- Initialization
make (t: STRING_32) make (tag: STRING_32)
-- Initialize -- Initialize
require
tag_not_empty: not tag.is_empty
do do
make_with_body_class (t, "", "", "") make_with_body_class (tag, "", "", "")
end end
make_with_body (t, attr, b: STRING_32) make_with_body (tag, attr, b: STRING_32)
-- Initialize with specific attributes and body -- Initialize with specific attributes and body
require
tag_not_empty: not tag.is_empty
do do
make_stateless_control (t) make_stateless_control (tag)
attributes := attr attributes := attr
body := b body := b
end end
make_with_body_class (t, attr, c, b: STRING_32) make_with_body_class (tag, attr, c, b: STRING_32)
-- Initialize with specific class, attributes and body -- Initialize with specific class, attributes and body
require
tag_not_empty: not tag.is_empty
do do
make_with_body (t, attr, b) make_with_body (tag, attr, b)
if not c.is_empty then if not c.is_empty then
css_classes.extend (c) css_classes.extend (c)
end end
@@ -62,6 +68,8 @@ feature -- Change
-- Set the body of this control -- Set the body of this control
do do
body := b body := b
ensure
body_set: body = b
end end
feature -- Access feature -- Access

View File

@@ -23,12 +23,14 @@ create
feature {NONE} -- Initialization feature {NONE} -- Initialization
make (a_text: STRING_32) make (a_text: STRING_32)
-- Initialize with specified control name and text -- Initialize with specified text
do do
make_control ("button") make_control ("button")
add_class ("btn") add_class ("btn")
add_class ("btn-default") add_class ("btn-default")
text := a_text text := a_text
ensure
text_set: text = a_text
end end
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
@@ -56,9 +58,14 @@ feature --Event handling
-- Set button click event handle -- Set button click event handle
do do
click_event := e click_event := e
ensure
click_event_set: click_event = e
end end
handle_callback (cname: LIST [STRING_32]; event: STRING_32; event_parameter: detachable ANY) handle_callback (cname: LIST [STRING_32]; event: STRING_32; event_parameter: detachable ANY)
-- Called if the button is clicked.
require else
cname_has_element: cname.count > 0
do do
if Current.control_name.same_string (cname [1]) and attached click_event as cevent then if Current.control_name.same_string (cname [1]) and attached click_event as cevent then
cevent.call (Void) cevent.call (Void)
@@ -91,20 +98,26 @@ feature -- Change
text := t text := t
state_changes.replace_with_string (text, "text") state_changes.replace_with_string (text, "text")
end end
ensure
text_set: text.same_string (t)
end end
set_disabled (b: BOOLEAN) set_disabled (b: BOOLEAN)
-- Enables or disables this component, depending on the value of the parameter b.
-- A disabled button cannot be clicked.
do do
if disabled /= b then if disabled /= b then
disabled := b disabled := b
state_changes.replace_with_boolean (disabled, "disabled") state_changes.replace_with_boolean (disabled, "disabled")
end end
ensure
disabled_set: disabled = b
end end
feature -- Properties feature -- Properties
disabled: BOOLEAN disabled: BOOLEAN
-- Defines if the button is editable -- Defines if the button is clickable or not
text: STRING_32 text: STRING_32
-- The text currently displayed on this button -- The text currently displayed on this button

View File

@@ -1,7 +1,7 @@
note note
description: "[ description: "[
This class is the base class for all stateful controls, like This class is the base class for all stateful controls, like
buttons or forms. buttons or forms.
]" ]"
author: "" author: ""
date: "$Date$" date: "$Date$"
@@ -22,22 +22,25 @@ inherit
feature {NONE} -- Initialization feature {NONE} -- Initialization
make (a_tag_name: STRING_32) make (a_tag_name: STRING_32)
-- Initialize with specified and tag -- Initialize with specified tag
require require
not a_tag_name.is_empty a_tag_name_not_empty: not a_tag_name.is_empty
do do
make_stateless_control (a_tag_name) make_stateless_control (a_tag_name)
create control_name_prefix.make_empty create control_name_prefix.make_empty
create state_changes.make create state_changes.make
create actions.make_array create actions.make_array
ensure ensure
attached state_changes state_changes_attached: attached state_changes
end end
feature -- Actions feature -- Actions
start_modal (url: STRING_32; title: STRING_32; big: BOOLEAN) start_modal (url: STRING_32; title: STRING_32; big: BOOLEAN)
--Start a modal window containg an other or the same page --Start a modal window containing an other or the same page
require
url_not_empty: not url.is_empty
title_not_empty: not title.is_empty
local local
modal: WSF_JSON_OBJECT modal: WSF_JSON_OBJECT
do do
@@ -54,6 +57,8 @@ feature -- Actions
show_alert (message: STRING_32) show_alert (message: STRING_32)
--Start a modal window containg an other or the same page --Start a modal window containg an other or the same page
require
message_not_empty: not message.is_empty
local local
alert: WSF_JSON_OBJECT alert: WSF_JSON_OBJECT
do do
@@ -65,6 +70,8 @@ feature -- Actions
redirect (url: STRING_32) redirect (url: STRING_32)
--Redirect to an other page --Redirect to an other page
require
url_not_empty: not url.is_empty
local local
modal: WSF_JSON_OBJECT modal: WSF_JSON_OBJECT
do do
@@ -156,6 +163,10 @@ feature -- Rendering
end end
js_class: STRING_32 js_class: STRING_32
-- The js_class is the name of the corresponding javascript class for this control. If this query is not redefined, it just
-- returns the name of the Eiffel class. In case of customized controls, either the according javascript functionality has to
-- be written in a coffeescript class of the same name or this query has to bee redefined and has to return the name of the
-- control Eiffel class of which the javascript functionality should be inherited.
do do
Result := generator Result := generator
end end
@@ -163,13 +174,14 @@ feature -- Rendering
feature -- Event handling feature -- Event handling
handle_callback (cname: LIST [STRING_32]; event: STRING_32; event_parameter: detachable ANY) handle_callback (cname: LIST [STRING_32]; event: STRING_32; event_parameter: detachable ANY)
-- Method called if any callback received. In this method you can route the callback to the event handler -- Method called if any callback received. In this method the callback can be routed to the event handler
deferred deferred
end end
feature -- Change feature -- Change
set_isolation (p: BOOLEAN) set_isolation (p: BOOLEAN)
-- Set the isolation state of this control
do do
isolate := p isolate := p
end end
@@ -177,24 +189,32 @@ feature -- Change
feature -- Properties feature -- Properties
isolate: BOOLEAN isolate: BOOLEAN
-- The isolation state of this control
actions: JSON_ARRAY actions: JSON_ARRAY
-- An array of actions to be carried out, e.g. display a modal (see tutorial for more information about this)
control_id: INTEGER assign set_control_id control_id: INTEGER assign set_control_id
-- The id of this control
set_control_id (d: INTEGER) set_control_id (d: INTEGER)
-- Set the id of this control
do do
control_id := d control_id := d
end end
control_name: STRING_32 control_name: STRING_32
-- The name of this control which is composed of the control name prefix and the id of the control
do do
Result := control_name_prefix + control_id.out Result := control_name_prefix + control_id.out
end end
control_name_prefix: STRING_32 assign set_control_name_prefix control_name_prefix: STRING_32 assign set_control_name_prefix
-- Used to avoid name conflicts since the children stateful controls of stateless controls are appended to the parent
-- control state and therefore could have the same name
set_control_name_prefix (p: STRING_32) set_control_name_prefix (p: STRING_32)
-- Set the control name prefix
do do
control_name_prefix := p control_name_prefix := p
end end

View File

@@ -23,13 +23,16 @@ inherit
feature {NONE} -- Initialization feature {NONE} -- Initialization
make_with_tag_name (tag: STRING_32) make_with_tag_name (tag: STRING_32)
-- Initialize with specified tag
do do
Precursor (tag) Precursor (tag)
create items.make_array create items.make_array
create pending_removes.make (1) create pending_removes.make (1)
ensure then
tag_set: tag_name.same_string (tag)
end end
feature {WSF_DYNAMIC_MULTI_CONTROL} -- Iternal functions feature {WSF_DYNAMIC_MULTI_CONTROL} -- Internal functions
add_control (c: G; id: INTEGER_32) add_control (c: G; id: INTEGER_32)
-- Add a control to this multi control -- Add a control to this multi control
@@ -40,9 +43,14 @@ feature {WSF_DYNAMIC_MULTI_CONTROL} -- Iternal functions
end end
max_id := id.max (max_id) max_id := id.max (max_id)
items_changed := True items_changed := True
ensure
control_added: controls.has (c)
id_set: attached {WSF_CONTROL} c as d implies d.control_id = id
items_changed: items_changed
end end
execute_pending_removes execute_pending_removes
-- Execute pending removes
local local
found: BOOLEAN found: BOOLEAN
fitem: detachable G fitem: detachable G
@@ -80,12 +88,15 @@ feature {WSF_DYNAMIC_MULTI_CONTROL} -- Iternal functions
end end
items_changed := True items_changed := True
end end
pending_removes.wipe_out
ensure
pending_removes_empty: pending_removes.is_empty
end end
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
set_state (new_state: JSON_OBJECT) set_state (new_state: JSON_OBJECT)
-- Before we process the callback. We restore the subcontrols -- Before we process the callback, we restore the subcontrols
do do
if attached {JSON_ARRAY} new_state.item ("items") as new_items then if attached {JSON_ARRAY} new_state.item ("items") as new_items then
items := new_items items := new_items
@@ -154,6 +165,7 @@ feature
end end
js_class: STRING_32 js_class: STRING_32
-- The default behvaiour of subclasses of the dynamic multi control is that they inherit the javascript functionality of this class
do do
Result := "WSF_DYNAMIC_MULTI_CONTROL" Result := "WSF_DYNAMIC_MULTI_CONTROL"
end end
@@ -161,12 +173,16 @@ feature
feature feature
items: JSON_ARRAY items: JSON_ARRAY
-- Holds the current items in this control
pending_removes: ARRAYED_LIST [INTEGER] pending_removes: ARRAYED_LIST [INTEGER]
-- Stores the removes that have to be executed
items_changed: BOOLEAN items_changed: BOOLEAN
-- Indicates whether a change to the controls has happened since the last state readout
max_id: INTEGER max_id: INTEGER
-- Largest id of the controls in this multi control
invariant invariant
all_items_exist: items.count = controls.count all_items_exist: items.count = controls.count

View File

@@ -14,7 +14,7 @@ inherit
WSF_STATELESS_MULTI_CONTROL [WSF_STATELESS_CONTROL] WSF_STATELESS_MULTI_CONTROL [WSF_STATELESS_CONTROL]
rename rename
make as make_multi_control make as make_stateless_multi_control
redefine redefine
add_control add_control
end end
@@ -27,27 +27,35 @@ create
feature {NONE} -- Initialization feature {NONE} -- Initialization
make make
-- Initialize -- Initialize with default label width 2
do do
make_with_label_width (2) make_with_label_width (2)
end end
make_with_label_width (w: INTEGER) make_with_label_width (w: INTEGER)
-- Initialize with the specified label width measured in Bootstrap columns
require
w_in_range: w >= 0 and w <= 12
do do
make_multi_control make_stateless_multi_control
tag_name := "form" tag_name := "form"
label_width := w label_width := w
add_class ("form-horizontal") add_class ("form-horizontal")
ensure
label_width_set: label_width = w
end end
feature feature
add_control (c: WSF_STATELESS_CONTROL) add_control (c: WSF_STATELESS_CONTROL)
-- Add control to this form
do do
Precursor (c) Precursor (c)
if attached {WSF_FORM_ELEMENT_CONTROL[detachable ANY]} c as fec then if attached {WSF_FORM_ELEMENT_CONTROL [detachable ANY]} c as fec then
fec.set_label_width (label_width) fec.set_label_width (label_width)
end end
ensure then
control_added: controls.has (c)
end end
feature -- Validation feature -- Validation
@@ -74,5 +82,9 @@ feature -- Validation
feature feature
label_width: INTEGER label_width: INTEGER
-- The label width in this form, measured in Bootstrap columns
invariant
label_width_in_range: label_width >= 0 and label_width <= 12
end end

View File

@@ -66,18 +66,26 @@ feature -- Modify
-- Set the label span (a value between 1 and 12 to specify the bootstrap column span or 0 for not displaying the label) -- Set the label span (a value between 1 and 12 to specify the bootstrap column span or 0 for not displaying the label)
do do
label_width := w label_width := w
ensure
label_width_set: label_width = w
end end
feature -- Access feature -- Access
value: G value: G
-- Current value of this form element's value control
do do
Result := value_control.value Result := value_control.value
ensure
result_set: Result = value_control.value
end end
set_value (v: G) set_value (v: G)
-- Set the value of this form element's value control
do do
value_control.set_value (v) value_control.set_value (v)
ensure
value_set: value_control.value = v
end end
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
@@ -98,6 +106,7 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
end end
full_state: WSF_JSON_OBJECT full_state: WSF_JSON_OBJECT
-- The full state of this form
local local
controls_state: WSF_JSON_OBJECT controls_state: WSF_JSON_OBJECT
do do
@@ -147,6 +156,8 @@ feature -- Event handling
handle_callback (cname: LIST [STRING_32]; event: STRING_32; event_parameter: detachable ANY) handle_callback (cname: LIST [STRING_32]; event: STRING_32; event_parameter: detachable ANY)
-- Pass callback to subcontrols -- Pass callback to subcontrols
require else
cname_not_empty: cname.count > 0
do do
if cname [1].same_string (control_name) then if cname [1].same_string (control_name) then
cname.go_i_th (1) cname.go_i_th (1)
@@ -186,6 +197,8 @@ feature -- Validation
-- Add an additional validator that will check the input of the value control of this form element control on validation -- Add an additional validator that will check the input of the value control of this form element control on validation
do do
validators.extend (v) validators.extend (v)
ensure
validator_added: validators.has (v)
end end
set_error (e: STRING_32) set_error (e: STRING_32)
@@ -193,6 +206,8 @@ feature -- Validation
do do
error := e error := e
state_changes.replace (create {JSON_STRING}.make_json (e), "error") state_changes.replace (create {JSON_STRING}.make_json (e), "error")
ensure
error_set: error.same_string (e)
end end
validate validate

View File

@@ -23,17 +23,21 @@ create
feature {NONE} -- Initialization feature {NONE} -- Initialization
make (t, v: STRING_32) make (tag, v: STRING_32)
-- Initialize -- Initialize with specified tag and HTML value
require
tag_not_empty: not tag.is_empty
do do
make_value_control (t) make_value_control (tag)
html := v html := v
ensure
html_set: html.same_string (v)
end end
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
set_state (new_state: JSON_OBJECT) set_state (new_state: JSON_OBJECT)
-- Restore html from json -- Restore HTML from json
do do
if attached {JSON_STRING} new_state.item ("html") as new_html then if attached {JSON_STRING} new_state.item ("html") as new_html then
html := new_html.unescaped_string_32 html := new_html.unescaped_string_32
@@ -50,6 +54,7 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
feature --Event handling feature --Event handling
handle_callback (cname: LIST [STRING_32]; event: STRING_32; event_parameter: detachable ANY) handle_callback (cname: LIST [STRING_32]; event: STRING_32; event_parameter: detachable ANY)
-- By default, this does nothing
do do
end end
@@ -61,26 +66,28 @@ feature -- Implementation
Result := render_tag (html, "") Result := render_tag (html, "")
end end
set_html (t: STRING_32)
do
if not t.same_string (html) then
html := t
state_changes.replace_with_string (html, "html")
end
end
value: STRING_32 value: STRING_32
-- The HTML value of this HTML control
do do
Result := html Result := html
ensure then
result_set: Result.same_string (html)
end end
set_value (v: STRING_32) set_value (v: STRING_32)
-- Set HTML value of this control
do do
html := v if not v.same_string (html) then
html := v
state_changes.replace_with_string (html, "html")
end
ensure then
html_set: html.same_string (v)
end end
feature -- Properties feature -- Properties
html: STRING_32 html: STRING_32
-- The HTML value of this HTML control
end end

View File

@@ -32,6 +32,8 @@ feature
create l_value.make_json_from_string_32 (a_value.as_string_32) create l_value.make_json_from_string_32 (a_value.as_string_32)
end end
put (l_value, key) put (l_value, key)
ensure
has_key: has_key (key)
end end
put_integer (value: detachable INTEGER_64; key: JSON_STRING) put_integer (value: detachable INTEGER_64; key: JSON_STRING)
@@ -46,6 +48,8 @@ feature
create l_value.make_integer (a_value) create l_value.make_integer (a_value)
end end
put (l_value, key) put (l_value, key)
ensure
has_key: has_key (key)
end end
put_natural (value: detachable NATURAL_64; key: JSON_STRING) put_natural (value: detachable NATURAL_64; key: JSON_STRING)
@@ -60,6 +64,8 @@ feature
create l_value.make_natural (a_value) create l_value.make_natural (a_value)
end end
put (l_value, key) put (l_value, key)
ensure
has_key: has_key (key)
end end
put_real (value: detachable DOUBLE; key: JSON_STRING) put_real (value: detachable DOUBLE; key: JSON_STRING)
@@ -74,6 +80,8 @@ feature
create l_value.make_real (a_value) create l_value.make_real (a_value)
end end
put (l_value, key) put (l_value, key)
ensure
has_key: has_key (key)
end end
put_boolean (value: detachable BOOLEAN; key: JSON_STRING) put_boolean (value: detachable BOOLEAN; key: JSON_STRING)
@@ -88,6 +96,8 @@ feature
create l_value.make_boolean (a_value) create l_value.make_boolean (a_value)
end end
put (l_value, key) put (l_value, key)
ensure
has_key: has_key (key)
end end
replace_with_string (value: detachable READABLE_STRING_GENERAL; key: JSON_STRING) replace_with_string (value: detachable READABLE_STRING_GENERAL; key: JSON_STRING)

View File

@@ -1,7 +1,7 @@
note note
description: "[ description: "[
A lightweight layout container to encapsulate the grid layout A lightweight layout container to encapsulate the grid layout
provided by bootstrap. provided by bootstrap.
]" ]"
author: "" author: ""
date: "$Date$" date: "$Date$"
@@ -14,7 +14,7 @@ inherit
WSF_STATELESS_MULTI_CONTROL [WSF_STATELESS_CONTROL] WSF_STATELESS_MULTI_CONTROL [WSF_STATELESS_CONTROL]
rename rename
make as make_multi_control, make as make_stateless_multi_control,
add_control as add_control_raw add_control as add_control_raw
end end
@@ -23,7 +23,8 @@ create
feature {NONE} -- Initialization feature {NONE} -- Initialization
make (n: STRING_32) make
--Initialize
do do
make_with_tag_name ("div") make_with_tag_name ("div")
add_class ("row") add_class ("row")
@@ -32,6 +33,10 @@ feature {NONE} -- Initialization
feature -- Add control feature -- Add control
add_control_with_offset (c: WSF_STATELESS_CONTROL; span, offset: INTEGER) add_control_with_offset (c: WSF_STATELESS_CONTROL; span, offset: INTEGER)
-- Add a control as column with the specified span and offset
require
offset_in_range: offset >= 0 and offset <= 12
span_in_range: span >= 0 and span <= 12 - offset
local local
div: WSF_STATELESS_MULTI_CONTROL [WSF_STATELESS_CONTROL] div: WSF_STATELESS_MULTI_CONTROL [WSF_STATELESS_CONTROL]
do do
@@ -42,6 +47,7 @@ feature -- Add control
end end
add_control (col: INTEGER; c: WSF_STATELESS_CONTROL) add_control (col: INTEGER; c: WSF_STATELESS_CONTROL)
-- Add a control to the specified column
require require
col >= 1 and col <= controls.count col >= 1 and col <= controls.count
attached {WSF_STATELESS_MULTI_CONTROL [WSF_STATELESS_CONTROL]} controls [col] attached {WSF_STATELESS_MULTI_CONTROL [WSF_STATELESS_CONTROL]} controls [col]
@@ -52,6 +58,9 @@ feature -- Add control
end end
add_column (span: INTEGER) add_column (span: INTEGER)
-- Add a multi control as Bootstrap column with the specified span
require
span_in_range: span >= 0 and span <= 12
local local
div: WSF_STATELESS_MULTI_CONTROL [WSF_STATELESS_CONTROL] div: WSF_STATELESS_MULTI_CONTROL [WSF_STATELESS_CONTROL]
do do

View File

@@ -27,16 +27,20 @@ create
feature {NONE} -- Initialization feature {NONE} -- Initialization
make make
-- Initialize with specified control name and default tag "div" -- Initialize with default tag "div"
do do
make_with_tag_name ("div") make_with_tag_name ("div")
end end
make_with_tag_name (t: STRING_32) make_with_tag_name (t: STRING_32)
-- Initialize with specified control name and tag -- Initialize with specified tag
require
t_not_empty: not t.is_empty
do do
make_control (t) make_control (t)
controls := create {ARRAYED_LIST [G]}.make (5); controls := create {ARRAYED_LIST [G]}.make (5);
ensure
tag_name_set:tag_name.same_string (t)
end end
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management

View File

@@ -38,6 +38,8 @@ feature {NONE} -- Initialization
request := req request := req
response := res response := res
initialize_controls initialize_controls
ensure
base_path_set: base_path.same_string (a_base_path)
end end
feature -- Access feature -- Access
@@ -107,7 +109,7 @@ feature -- Implementation
end end
render_page render_page
-- Render and send the HTML Page -- Render and send the HTML page
local local
page: WSF_PAGE_RESPONSE page: WSF_PAGE_RESPONSE
do do
@@ -118,6 +120,7 @@ feature -- Implementation
end end
render: STRING_32 render: STRING_32
-- Render the HTML page
local local
ajax: BOOLEAN ajax: BOOLEAN
do do
@@ -183,6 +186,7 @@ feature -- Event handling
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
state: WSF_JSON_OBJECT state: WSF_JSON_OBJECT
-- State of the page
do do
create Result.make create Result.make
Result.put_string (control_name, "id") Result.put_string (control_name, "id")
@@ -191,6 +195,7 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
end end
set_state (sp: JSON_OBJECT) set_state (sp: JSON_OBJECT)
-- Set state
do do
if attached {JSON_OBJECT} sp.item ("controls") as ct and then attached {JSON_OBJECT} ct.item (control.control_name) as value_state then if attached {JSON_OBJECT} sp.item ("controls") as ct and then attached {JSON_OBJECT} ct.item (control.control_name) as value_state then
control.load_state (value_state) control.load_state (value_state)
@@ -211,8 +216,10 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
feature feature
control_name: STRING_32 control_name: STRING_32
-- Name of this page
base_path: STRING_32 base_path: STRING_32
-- The base path of the assets files
feature {NONE} -- Root control feature {NONE} -- Root control

View File

@@ -17,7 +17,7 @@ feature {NONE} -- Initialization
make (a_tag_name: STRING_32) make (a_tag_name: STRING_32)
-- Initialize with specified tag -- Initialize with specified tag
require require
not a_tag_name.is_empty a_tag_name_not_empty: not a_tag_name.is_empty
do do
tag_name := a_tag_name tag_name := a_tag_name
create css_classes.make (0) create css_classes.make (0)
@@ -38,18 +38,29 @@ feature -- Change
add_class (c: STRING_32) add_class (c: STRING_32)
-- Add a css class to this control -- Add a css class to this control
require
c_not_empty: not c.is_empty
do do
css_classes.force (c) css_classes.force (c)
ensure
class_added: css_classes.has (c)
end end
remove_class (cla: STRING_32) remove_class (c: STRING_32)
-- Add a css class to this control -- Remove a css class from this control
require
c_not_empty: not c.is_empty
do do
css_classes.prune (cla) css_classes.start
css_classes.prune_all (c)
ensure
c_removed: not css_classes.has (c)
end end
append_attribute (a: STRING_32) append_attribute (a: STRING_32)
-- Adds the specified attribute to the attribute string of this control -- Adds the specified attribute to the attribute string of this control
require
a_not_empty: not a.is_empty
do do
if attached attributes as attr then if attached attributes as attr then
attr.append (" ") attr.append (" ")
@@ -110,4 +121,7 @@ feature -- Rendering
deferred deferred
end end
invariant
tag_name_not_empty: not tag_name.is_empty
end end

View File

@@ -1,8 +1,8 @@
note note
description: "[ description: "[
Mutli controls are used as containers for multiple controls, for Mutli controls are used as containers for multiple controls, for
example a form is a multi control. example a form is a multi control.
]" ]"
author: "" author: ""
date: "$Date$" date: "$Date$"
revision: "$Revision$" revision: "$Revision$"
@@ -13,6 +13,8 @@ class
inherit inherit
WSF_MULTI_CONTROL [G] WSF_MULTI_CONTROL [G]
rename
make as make_multi_control
redefine redefine
add_control, add_control,
set_control_name_prefix, set_control_name_prefix,
@@ -22,11 +24,12 @@ inherit
end end
create create
make_with_tag_name, make_tag_less make_with_tag_name, make
feature {NONE} -- Initialization feature {NONE} -- Initialization
make_tag_less make
-- Initialize
do do
make_with_tag_name ("") make_with_tag_name ("")
stateless := True stateless := True
@@ -35,18 +38,25 @@ feature {NONE} -- Initialization
feature feature
set_control_id (d: INTEGER) set_control_id (d: INTEGER)
-- Set id of this control and update subcontrol prefixes
do do
control_id := d control_id := d
set_subcontrol_prefixes set_subcontrol_prefixes
ensure then
control_id_set: control_id.abs = d
end end
set_control_name_prefix (p: STRING_32) set_control_name_prefix (p: STRING_32)
-- Set control name prefix of this control
do do
control_name_prefix := p control_name_prefix := p
set_subcontrol_prefixes set_subcontrol_prefixes
ensure then
control_name_prefix_set: control_name_prefix.same_string (p)
end end
set_subcontrol_prefixes set_subcontrol_prefixes
-- Update subcontrol prefixes
do do
across across
controls as e controls as e
@@ -67,6 +77,8 @@ feature
d.control_id := controls.count d.control_id := controls.count
d.control_name_prefix := control_name_prefix + control_id.out + "_" d.control_name_prefix := control_name_prefix + control_id.out + "_"
end end
ensure then
control_added: controls.has (c)
end end
render_tag (body: STRING_32; attrs: detachable STRING_32): STRING_32 render_tag (body: STRING_32; attrs: detachable STRING_32): STRING_32