Code improvement

Cosmetic (comments, names, formatting)
This commit is contained in:
2014-03-26 10:18:02 +01:00
parent acc8cda04f
commit cc7d268610
36 changed files with 684 additions and 291 deletions

View File

@@ -25,32 +25,32 @@ create
feature {NONE} -- Initialization
make (tag: STRING_32)
make (a_tag: STRING_32)
-- Initialize
require
tag_not_empty: not tag.is_empty
tag_not_empty: not a_tag.is_empty
do
make_with_body_class (tag, "", "", "")
make_with_body_class (a_tag, "", "", "")
end
make_with_body (tag, attr, b: STRING_32)
-- Initialize with specific attributes and body
make_with_body (a_tag, a_attribs, a_body: STRING_32)
-- Initialize with tag `a_tag', specific attributes `a_attribs' and body `a_body'.
require
tag_not_empty: not tag.is_empty
tag_not_empty: not a_tag.is_empty
do
make_stateless_control (tag)
attributes := attr
body := b
make_stateless_control (a_tag)
attributes := a_attribs
body := a_body
end
make_with_body_class (tag, attr, c, b: STRING_32)
-- Initialize with specific class, attributes and body
make_with_body_class (a_tag, a_attribs, a_css_class, a_body: STRING_32)
-- Initialize with tag `a_tag' specific class `a_css_class', attributes `a_attribs' and body `a_body'.
require
tag_not_empty: not tag.is_empty
tag_not_empty: not a_tag.is_empty
do
make_with_body (tag, attr, b)
if not c.is_empty then
css_classes.extend (c)
make_with_body (a_tag, a_attribs, a_body)
if not a_css_class.is_empty then
css_classes.extend (a_css_class)
end
end
@@ -80,4 +80,14 @@ feature -- Access
body: STRING_32
-- Body of this control
;note
copyright: "2011-2014, Yassin Hassan, Severin Munger, Jocelyn Fiat, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

View File

@@ -62,12 +62,13 @@ feature --Event handling
click_event_set: click_event = e
end
handle_callback (cname: LIST [STRING_32]; event: STRING_32; event_parameter: detachable ANY)
handle_callback (cname: LIST [READABLE_STRING_GENERAL]; event: READABLE_STRING_GENERAL; event_parameter: detachable ANY)
-- Called if the button is clicked.
require else
cname_has_element: cname.count > 0
do
if Current.control_name.same_string (cname [1]) and attached click_event as cevent then
if
control_name.same_string_general (cname.first) and
attached click_event as cevent
then
cevent.call (Void)
end
end
@@ -84,7 +85,7 @@ feature -- Rendering
attr.append (a)
end
if disabled then
attr.append ("disabled=%"disabled%" ")
attr.append (" disabled=%"disabled%" ")
end
Result := render_tag (text, attr)
end
@@ -109,6 +110,8 @@ feature -- Change
if disabled /= b then
disabled := b
state_changes.replace_with_boolean (disabled, "disabled")
else
check (b = False) implies state_changes.has_key ("disabled") end
end
ensure
disabled_set: disabled = b
@@ -125,4 +128,14 @@ feature -- Properties
click_event: detachable PROCEDURE [ANY, TUPLE]
-- Event that is executed when button is clicked
;note
copyright: "2011-2014, Yassin Hassan, Severin Munger, Jocelyn Fiat, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

View File

@@ -11,7 +11,6 @@ deferred class
WSF_CONTROL
inherit
WSF_STATELESS_CONTROL
rename
make as make_stateless_control
@@ -110,14 +109,14 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
states.put (state_changes, control_name)
end
if actions.count > 0 then
if not attached states.item ("actions") then
if states.item ("actions") = Void then
states.put (create {JSON_ARRAY}.make_array, "actions")
end
if attached {JSON_ARRAY} states.item ("actions") as action_list then
across
actions.array_representation as action
actions.array_representation as ic
loop
action_list.add (action.item)
action_list.add (ic.item)
end
end
end
@@ -127,42 +126,43 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
-- Returns the current state of the Control as JSON. This state will be transfered to the client.
deferred
ensure
controls_not_defined: not (attached Result.item ("controls"))
controls_not_defined: Result.item ("controls") = Void
end
state_changes: WSF_JSON_OBJECT
feature -- Rendering
render_tag (body: STRING_32; attrs: detachable STRING_32): STRING_32
render_tag (body: READABLE_STRING_32; attrs: detachable READABLE_STRING_32): STRING_32
-- Render this control with the specified body and attributes
do
Result := render_tag_with_generator_name (js_class, body, attrs)
end
render_tag_with_generator_name (a_generator, body: STRING_32; attrs: detachable STRING_32): STRING_32
render_tag_with_generator_name (a_generator, body: READABLE_STRING_32; attrs: detachable READABLE_STRING_32): STRING_32
-- Render this control with the specified generator name, body and attributes
local
css_classes_string: STRING_32
l_css_classes_string: STRING_32
l_attributes: STRING_32
do
css_classes_string := ""
create l_css_classes_string.make_empty
across
css_classes as c
css_classes as ic
loop
css_classes_string := css_classes_string + " " + c.item
l_css_classes_string.append_character (' ')
l_css_classes_string.append (ic.item)
end
l_attributes := " data-name=%"" + control_name + "%" data-type=%"" + a_generator + "%" "
if attached attrs as a then
l_attributes := l_attributes + a
if attached attrs as l_attrs then
l_attributes.append (l_attrs)
end
if isolate then
l_attributes.append (" data-isolation=%"1%"")
end
Result := render_tag_with_tagname (tag_name, body, l_attributes, css_classes_string)
Result := render_tag_with_tagname (tag_name, body, l_attributes, l_css_classes_string)
end
js_class: STRING_32
js_class: READABLE_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
@@ -173,8 +173,11 @@ feature -- Rendering
feature -- Event handling
handle_callback (cname: LIST [STRING_32]; event: STRING_32; event_parameter: detachable ANY)
-- Method called if any callback received. In this method the callback can be routed to the event handler
handle_callback (cname: LIST [READABLE_STRING_GENERAL]; event: READABLE_STRING_GENERAL; event_parameter: detachable ANY)
-- Method called if any callback received.
-- In this method the callback can be routed to the event handler.
require
cname_is_not_empty: not cname.is_empty
deferred
end
@@ -219,4 +222,14 @@ feature -- Properties
-- 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 (Stateless multi controls do not add a hierarchy level)
;note
copyright: "2011-2014, Yassin Hassan, Severin Munger, Jocelyn Fiat, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

View File

@@ -148,7 +148,7 @@ feature
end
remove_control_by_id (id: INTEGER)
--Add removes to pending removes list
-- Add removes to pending removes list
do
pending_removes.extend (id)
end
@@ -176,7 +176,7 @@ feature
Result := "WSF_DYNAMIC_MULTI_CONTROL"
end
feature
feature -- Access
items: JSON_ARRAY
-- Holds the current items in this control
@@ -193,4 +193,14 @@ feature
invariant
all_items_exist: items.count = controls.count
note
copyright: "2011-2014, Yassin Hassan, Severin Munger, Jocelyn Fiat, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

View File

@@ -29,33 +29,36 @@ create
feature {NONE} -- Initialization
make_without_border (a_label: detachable STRING_32; c: WSF_VALUE_CONTROL [G])
-- Initialize form element control with a specific label (or 'Void' for no label) and value control
make_without_border (a_label: detachable STRING_32; a_control: WSF_VALUE_CONTROL [G])
-- Initialize Current form element control with a specific label
-- (or 'Void' for no label) and value control `a_control'.
do
make_with_validators (a_label, False, c, create {ARRAYED_LIST [WSF_VALIDATOR [G]]}.make (0))
make_with_validators (a_label, False, a_control, create {ARRAYED_LIST [WSF_VALIDATOR [G]]}.make (0))
end
make (a_label: detachable STRING_32; c: WSF_VALUE_CONTROL [G])
-- Initialize form element control with a specific label (or 'Void' for no label) and value control
make (a_label: detachable STRING_32; a_control: WSF_VALUE_CONTROL [G])
-- Initialize Current form element control with a specific label
-- (or 'Void' for no label) and value control `a_control'.
do
make_with_validators (a_label, True, c, create {ARRAYED_LIST [WSF_VALIDATOR [G]]}.make (0))
make_with_validators (a_label, True, a_control, create {ARRAYED_LIST [WSF_VALIDATOR [G]]}.make (0))
end
make_with_validators (a_label: detachable STRING_32; show_border: BOOLEAN; c: WSF_VALUE_CONTROL [G]; v: LIST [WSF_VALIDATOR [G]])
-- Initialize form element control with a specific label (or 'Void' for no label), value control and list of validators
make_with_validators (a_label: detachable STRING_32; show_border: BOOLEAN; a_control: WSF_VALUE_CONTROL [G]; a_validators: LIST [WSF_VALIDATOR [G]])
-- Initialize Current form element control with a specific label (or 'Void' for no label),
-- value control `a_control' and list of validators `a_validators'
do
make_control ("div")
add_class ("form-group")
if show_border then
if not attached {WSF_VALUE_CONTROL [LIST [ANY]]} c then
c.add_class ("form-control")
if attached {WSF_VALUE_CONTROL [LIST [ANY]]} a_control then
a_control.add_class ("form-control-static")
else
c.add_class ("form-control-static")
a_control.add_class ("form-control")
end
end
label_width := 2
value_control := c
validators := v
value_control := a_control
validators := a_validators
label := a_label
error := ""
end
@@ -94,7 +97,10 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
-- Pass new_states to subcontrols
do
Precursor (new_states)
if attached {JSON_OBJECT} new_states.item ("controls") as ct and then attached {JSON_OBJECT} ct.item (value_control.control_name) as value_state then
if
attached {JSON_OBJECT} new_states.item ("controls") as ct and then
attached {JSON_OBJECT} ct.item (value_control.control_name) as value_state
then
value_control.load_state (value_state)
end
end
@@ -154,13 +160,11 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
feature -- Event handling
handle_callback (cname: LIST [STRING_32]; event: STRING_32; event_parameter: detachable ANY)
handle_callback (cname: LIST [READABLE_STRING_GENERAL]; event: READABLE_STRING_GENERAL; event_parameter: detachable ANY)
-- Pass callback to subcontrols
require else
cname_not_empty: cname.count > 0
do
if cname [1].same_string (control_name) then
cname.go_i_th (1)
if cname.first.same_string (control_name) then
cname.start
cname.remove
if cname.is_empty then
if event.same_string ("validate") then
@@ -179,9 +183,9 @@ feature -- Implementation
local
body: STRING_32
do
body := ""
if attached label as l and then not l.is_empty then
body.append ("<label class=%"col-lg-" + label_width.out + " control-label%" for=%"" + value_control.control_name + "%">" + l + "</label>")
create body.make_empty
if attached label as l_label and then not l_label.is_empty then
body.append ("<label class=%"col-lg-" + label_width.out + " control-label%" for=%"" + value_control.control_name + "%">" + l_label + "</label>")
body.append ("<div class=%"col-lg-" + (12 - label_width).out + "%">")
else
body.append ("<div class=%"col-lg-12%">")
@@ -252,4 +256,14 @@ feature -- Properties
label_width: INTEGER
-- The bootstrap column span of the label of this form element control
;note
copyright: "2011-2014, Yassin Hassan, Severin Munger, Jocelyn Fiat, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

View File

@@ -53,7 +53,7 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
feature --Event handling
handle_callback (cname: LIST [STRING_32]; event: STRING_32; event_parameter: detachable ANY)
handle_callback (cname: LIST [READABLE_STRING_GENERAL]; event: READABLE_STRING_GENERAL; event_parameter: detachable ANY)
-- By default, this does nothing
do
end
@@ -90,4 +90,14 @@ feature -- Properties
html: STRING_32
-- The HTML value of this HTML control
;note
copyright: "2011-2014, Yassin Hassan, Severin Munger, Jocelyn Fiat, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

View File

@@ -18,7 +18,7 @@ inherit
create
make
feature
feature -- Change
put_string (value: detachable READABLE_STRING_GENERAL; key: JSON_STRING)
-- Assuming there is no item of key `key',
@@ -160,4 +160,14 @@ feature
replace (l_value, key)
end
note
copyright: "2011-2014, Yassin Hassan, Severin Munger, Jocelyn Fiat, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

View File

@@ -11,7 +11,6 @@ class
WSF_MULTI_CONTROL [G -> WSF_STATELESS_CONTROL]
inherit
WSF_CONTROL
rename
make as make_control
@@ -32,15 +31,15 @@ feature {NONE} -- Initialization
make_with_tag_name ("div")
end
make_with_tag_name (t: STRING_32)
-- Initialize with specified tag
make_with_tag_name (a_tag: STRING_32)
-- Initialize with specified tag `a_tag'.
require
t_not_empty: not t.is_empty
a_tag_not_empty: not a_tag.is_empty
do
make_control (t)
controls := create {ARRAYED_LIST [G]}.make (5);
ensure
tag_name_set:tag_name.same_string (t)
make_control (a_tag)
create {ARRAYED_LIST [G]} controls.make (5)
ensure
tag_name_set: tag_name.same_string (a_tag)
end
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
@@ -127,11 +126,11 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
-- If the subcontrol is a stateless multicontrol x. We add the state changes of subcontrols of x directly to sub_states. (Stateless multi controls do not add a hierarchy level)
do
across
controls as c
controls as ic
loop
if attached {WSF_STATELESS_MULTI_CONTROL [WSF_STATELESS_CONTROL]} c.item as cont then
if attached {WSF_STATELESS_MULTI_CONTROL [WSF_STATELESS_CONTROL]} ic.item as cont then
cont.read_subcontrol_state_changes (sub_states)
elseif attached {WSF_CONTROL} c.item as cont then
elseif attached {WSF_CONTROL} ic.item as cont then
cont.read_state_changes (sub_states)
end
end
@@ -145,19 +144,19 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
feature -- Event handling
handle_callback (cname: LIST [STRING_32]; event: STRING_32; event_parameter: detachable ANY)
handle_callback (cname: LIST [READABLE_STRING_GENERAL]; event: READABLE_STRING_GENERAL; event_parameter: detachable ANY)
-- Pass callback to subcontrols
do
if equal (cname [1], control_name) then
cname.go_i_th (1)
if cname.first.same_string (control_name) then
cname.start
cname.remove
if not cname.is_empty then
across
controls as c
controls as ic
until
cname.is_empty
loop
if attached {WSF_CONTROL} c.item as cont then
if attached {WSF_CONTROL} ic.item as cont then
cont.handle_callback (cname, event, event_parameter)
end
end
@@ -183,11 +182,11 @@ feature -- Rendering
feature
add_control (c: G)
-- Add a control to this multi control
add_control (a_control: G)
-- Add a control `a_control' to this multi control.
do
controls.extend (c)
if attached {WSF_CONTROL} c as d then
controls.extend (a_control)
if attached {WSF_CONTROL} a_control as d then
d.control_id := controls.count
end
end
@@ -197,4 +196,14 @@ feature -- Properties
controls: ARRAYED_LIST [G]
-- List of current controls in this multi control
;note
copyright: "2011-2014, Yassin Hassan, Severin Munger, Jocelyn Fiat, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

View File

@@ -12,7 +12,6 @@ deferred class
WSF_PAGE_CONTROL
inherit
WSF_CONTROL
rename
make as make_control
@@ -121,12 +120,26 @@ feature -- Implementation
render: STRING_32
-- Render the HTML page
local
ajax: BOOLEAN
do
ajax := attached get_parameter ("ajax")
create Result.make_empty
if not ajax then
if attached get_parameter ("ajax") as p_ajax then
Result.append ("<div data-name=%"" + control_name + "%" data-type=%"WSF_PAGE_CONTROL%">")
Result.append (control.render)
if attached additional_javascripts as l_additional_javascripts then
across
l_additional_javascripts as ic
loop
Result.append ("<script src=%"")
Result.append (base_path)
Result.append (ic.item)
Result.append ("%"></script>")
end
end
Result.append ("<script type=%"text/javascript%">$(function() {var page= new WSF_PAGE_CONTROL(")
Result.append (full_state.representation)
Result.append (");page.initialize();});</script>")
Result.append ("</div>")
else
Result.append ("<html><head>")
Result.append ("<link href=%"")
Result.append (base_path)
@@ -142,13 +155,13 @@ feature -- Implementation
Result.append ("<script src=%"")
Result.append (base_path)
Result.append ("assets/widget.js%"></script>")
if attached additional_javascripts as ajs then
if attached additional_javascripts as l_additional_javascripts then
across
ajs as js
l_additional_javascripts as ic
loop
Result.append ("<script src=%"")
Result.append (base_path)
Result.append (js.item)
Result.append (ic.item)
Result.append ("%"></script>")
end
end
@@ -156,23 +169,6 @@ feature -- Implementation
Result.append (full_state.representation)
Result.append (");page.initialize();});</script>")
Result.append ("</body></html>")
else
Result.append ("<div data-name=%"" + control_name + "%" data-type=%"WSF_PAGE_CONTROL%">")
Result.append (control.render)
if attached additional_javascripts as ajs then
across
ajs as js
loop
Result.append ("<script src=%"")
Result.append (base_path)
Result.append (js.item)
Result.append ("%"></script>")
end
end
Result.append ("<script type=%"text/javascript%">$(function() {var page= new WSF_PAGE_CONTROL(")
Result.append (full_state.representation)
Result.append (");page.initialize();});</script>")
Result.append ("</div>")
end
end
@@ -183,34 +179,31 @@ feature -- Implementation
control.read_state_changes (states)
end
get_parameter (key: STRING_32): detachable STRING_32
get_parameter (key: READABLE_STRING_GENERAL): detachable STRING_32
-- Read query parameter as string
local
value: detachable WSF_VALUE
do
Result := VOID
value := request.query_parameter (key)
if attached value and then value.is_string then
Result := value.as_string.value
if
attached {WSF_STRING} request.query_parameter (key) as l_value
then
Result := l_value.value
end
end
add_javascript (path: STRING_32)
local
ajs: attached like additional_javascripts
l_additional_javascripts: like additional_javascripts
do
if attached additional_javascripts as aajs then
ajs := aajs
else
create ajs.make (1)
l_additional_javascripts := additional_javascripts
if l_additional_javascripts = Void then
create l_additional_javascripts.make (1)
additional_javascripts := l_additional_javascripts
end
ajs.extend (path)
additional_javascripts := ajs
l_additional_javascripts.extend (path)
end
feature -- Event handling
handle_callback (cname: LIST [STRING_32]; event: STRING_32; event_parameter: detachable ANY)
handle_callback (cname: LIST [READABLE_STRING_GENERAL]; event: READABLE_STRING_GENERAL; event_parameter: detachable ANY)
-- Forward callback to control
do
control.handle_callback (cname, event, event_parameter)
@@ -230,7 +223,10 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
set_state (sp: JSON_OBJECT)
-- Set state
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)
end
end
@@ -246,7 +242,7 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
Result.put (state, "state")
end
feature
feature -- Access
control_name: STRING_32
-- Name of this page
@@ -262,4 +258,14 @@ feature {NONE} -- Root control
additional_javascripts: detachable ARRAYED_LIST [STRING_32]
-- List containing the additional javascipt files
;note
copyright: "2011-2014, Yassin Hassan, Severin Munger, Jocelyn Fiat, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

View File

@@ -27,43 +27,43 @@ feature {NONE} -- Initialization
feature -- Change
add_class (c: STRING_32)
add_class (a_css_class: STRING_32)
-- Add a css class to this control
require
c_not_empty: not c.is_empty
a_css_class_not_empty: not a_css_class.is_empty
do
css_classes.force (c)
css_classes.force (a_css_class)
ensure
class_added: css_classes.has (c)
class_added: css_classes.has (a_css_class)
end
remove_class (c: STRING_32)
remove_class (a_css_class: STRING_32)
-- Remove a css class from this control
require
c_not_empty: not c.is_empty
c_not_empty: not a_css_class.is_empty
do
css_classes.start
css_classes.prune_all (c)
css_classes.prune_all (a_css_class)
ensure
c_removed: not css_classes.has (c)
c_removed: not css_classes.has (a_css_class)
end
append_attribute (a: STRING_32)
append_attribute (att: READABLE_STRING_32)
-- Adds the specified attribute to the attribute string of this control
require
a_not_empty: not a.is_empty
att_not_empty: not att.is_empty
do
if attached attributes as attr then
attr.append (" ")
attr.append (a)
attr.append_character (' ')
attr.append (att)
else
attributes := a
create attributes.make_from_string (att)
end
end
feature -- Rendering
render_tag (body: STRING_32; attrs: detachable STRING_32): STRING_32
render_tag (a_body: READABLE_STRING_32; attrs: detachable READABLE_STRING_32): STRING_32
-- Generate HTML of this control with the specified body and attributes
local
css_classes_string: STRING_32
@@ -74,10 +74,10 @@ feature -- Rendering
loop
css_classes_string.append (" " + c.item)
end
Result := render_tag_with_tagname (tag_name, body, attrs, css_classes_string)
Result := render_tag_with_tagname (tag_name, a_body, attrs, css_classes_string)
end
render_tag_with_tagname (tag, body: STRING_32; attrs: detachable STRING_32; css_classes_string: STRING_32): STRING_32
render_tag_with_tagname (tag, a_body: READABLE_STRING_32; attrs: detachable READABLE_STRING_32; css_classes_string: READABLE_STRING_32): STRING_32
-- Generate HTML of the specified tag with specified body, attributes and css classes
local
l_attributes: STRING_32
@@ -92,16 +92,33 @@ feature -- Rendering
l_attributes.append (css_classes_string)
l_attributes.append_character ('%"')
end
Result := "<" + tag + " " + l_attributes
create Result.make_empty
Result.append_character ('<')
Result.append (tag)
Result.append_character (' ')
Result.append (l_attributes)
-- Check if we have to render a body. For some elements, this is not the case (like textareas) or only if the body is not empty.
if body.is_empty and not tag.same_string ("textarea") and not tag.same_string ("span") and not tag.same_string ("button") and not tag.same_string ("ul") and not tag.same_string ("div") then
Result.append (" />")
if
a_body.is_empty and
not tag.same_string ("textarea") and
not tag.same_string ("span") and
not tag.same_string ("button") and
not tag.same_string ("ul") and
not tag.same_string ("div")
then
-- Note: it should be ok to close for textarea, span, ... and so on.
Result.append ("/>")
else
Result.append (" >" + body + "</" + tag + ">")
Result.append (" >")
Result.append (a_body)
Result.append ("</")
Result.append (tag)
Result.append (">")
end
end
render_tag_with_body (body: STRING_32): STRING_32
render_tag_with_body (body: READABLE_STRING_32): STRING_32
-- Generate HTML of this control with the specified body
do
Result := render_tag (body, attributes)
@@ -126,4 +143,14 @@ feature -- Properties
invariant
tag_name_not_empty: not tag_name.is_empty
note
copyright: "2011-2014, Yassin Hassan, Severin Munger, Jocelyn Fiat, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

View File

@@ -3,7 +3,6 @@ note
Mutli controls are used as containers for multiple controls, for
example a form is a multi control.
]"
author: ""
date: "$Date$"
revision: "$Revision$"
@@ -11,7 +10,6 @@ class
WSF_STATELESS_MULTI_CONTROL [G -> WSF_STATELESS_CONTROL]
inherit
WSF_MULTI_CONTROL [G]
rename
make as make_multi_control
@@ -34,7 +32,7 @@ feature {NONE} -- Initialization
make_with_tag_name ("")
end
feature
feature -- Change
set_control_id (d: INTEGER)
-- Set id of this control and update subcontrol prefixes
@@ -56,17 +54,22 @@ feature
set_subcontrol_prefixes
-- Update subcontrol prefixes
local
s: STRING_32
do
across
controls as e
controls as ic
loop
if attached {WSF_CONTROL} e.item as el then
el.control_name_prefix := control_name_prefix + control_id.out + "_"
if attached {WSF_CONTROL} ic.item as l_control then
create s.make_from_string (control_name_prefix)
s.append_integer (control_id)
s.append_character ('_')
l_control.set_control_name_prefix (s)
end
end
end
feature
feature -- Change
add_control (c: G)
-- Add a control to this multi control
@@ -80,7 +83,7 @@ feature
control_added: controls.has (c)
end
render_tag (body: STRING_32; attrs: detachable STRING_32): STRING_32
render_tag (body: READABLE_STRING_32; attrs: detachable READABLE_STRING_32): STRING_32
-- Generate HTML of this control with the specified body and attributes
local
css_classes_string: STRING_32
@@ -96,7 +99,7 @@ feature
feature -- Event handling
handle_callback (cname: LIST [STRING_32]; event: STRING_32; event_parameter: detachable ANY)
handle_callback (cname: LIST [READABLE_STRING_GENERAL]; event: READABLE_STRING_GENERAL; event_parameter: detachable ANY)
-- Pass callback to subcontrols
do
across
@@ -110,4 +113,14 @@ feature -- Event handling
end
end
note
copyright: "2011-2014, Yassin Hassan, Severin Munger, Jocelyn Fiat, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

View File

@@ -11,7 +11,6 @@ deferred class
WSF_VALUE_CONTROL [G]
inherit
WSF_CONTROL
feature -- Access
@@ -22,7 +21,18 @@ feature -- Access
end
set_value (v: G)
-- Set `value' to `v'.
deferred
end
note
copyright: "2011-2014, Yassin Hassan, Severin Munger, Jocelyn Fiat, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end