Added comments to autocompletion, input, navbar, progressbar, validator, webcontrol. Some more little changes.

This commit is contained in:
Severin Münger
2013-09-21 23:01:36 +02:00
parent 252b5ff758
commit 57dd4ce259
33 changed files with 232 additions and 138 deletions

View File

@@ -16,16 +16,17 @@ create
feature {NONE} -- Initialization
make ()
make
-- Initialize
do
template := "<div class=%"clearfix%" style=%"min-width:250px%"><img src=%"http://api.randomuser.me/0.2/portraits/{{=img}}.jpg%" style=%"max-width:50px;margin-right:10px%" class=%"img-circle pull-left%"> <b>{{=value}}</b><br /><small>{{=company}}</small></div>";
list := <<["Zelma Hays","Applideck","women/13"],["Little Dixon","Centregy","men/20"],["Marta Fuentes","Papricut","women/11"],["Aileen Dillon","Neteria","women/9"],["Noel Melendez","Corporana","men/19"],["Gutierrez Francis","Capscreen","men/3"],["Valerie Weiss","Zizzle","women/9"],["Mabel Hammond","Pyramax","women/19"],["Mckay Logan","Providco","men/17"],["Hazel Colon","Translink","women/14"],["Margery Whitney","Tropoli","women/21"],["Saundra Neal","Geekmosis","women/20"],["Meghan Pittman","Micronaut","women/16"],["Adrienne Woodward","Mixers","women/8"],["Harriett Macdonald","Anarco","women/4"],["Velasquez Curtis","Zensus","men/4"],["Victoria Greene","Zorromop","women/10"],["Hood Barron","Kangle","men/2"],["Mccullough Cross","Kindaloo","men/15"],["Porter Hart","Kongle","men/15"],["Fox Bryant","Columella","men/17"],["Singleton Knapp","Marketoid","men/10"],["Gracie Lane","Solgan","women/15"],["Randall Cobb","Barkarama","men/7"],["Miranda Brooks","Earwax","men/1"],["Teresa Taylor","Stockpost","women/6"]>>
list := <<["Zelma Hays", "Applideck", "women/13"], ["Little Dixon", "Centregy", "men/20"], ["Marta Fuentes", "Papricut", "women/11"], ["Aileen Dillon", "Neteria", "women/9"], ["Noel Melendez", "Corporana", "men/19"], ["Gutierrez Francis", "Capscreen", "men/3"], ["Valerie Weiss", "Zizzle", "women/9"], ["Mabel Hammond", "Pyramax", "women/19"], ["Mckay Logan", "Providco", "men/17"], ["Hazel Colon", "Translink", "women/14"], ["Margery Whitney", "Tropoli", "women/21"], ["Saundra Neal", "Geekmosis", "women/20"], ["Meghan Pittman", "Micronaut", "women/16"], ["Adrienne Woodward", "Mixers", "women/8"], ["Harriett Macdonald", "Anarco", "women/4"], ["Velasquez Curtis", "Zensus", "men/4"], ["Victoria Greene", "Zorromop", "women/10"], ["Hood Barron", "Kangle", "men/2"], ["Mccullough Cross", "Kindaloo", "men/15"], ["Porter Hart", "Kongle", "men/15"], ["Fox Bryant", "Columella", "men/17"], ["Singleton Knapp", "Marketoid", "men/10"], ["Gracie Lane", "Solgan", "women/15"], ["Randall Cobb", "Barkarama", "men/7"], ["Miranda Brooks", "Earwax", "men/1"], ["Teresa Taylor", "Stockpost", "women/6"]>>
end
feature -- Implementation
autocompletion (input: STRING): JSON_ARRAY
-- Implementation
local
o: JSON_OBJECT
do
@@ -46,5 +47,6 @@ feature -- Implementation
end
list: ITERABLE [TUPLE [STRING, STRING]]
-- List of contacts
end

View File

@@ -16,7 +16,8 @@ create
feature {NONE} -- Initialization
make ()
make
-- Initialize
do
template := "<img src=%"http://www.famfamfam.com/lab/icons/flags/icons/gif/{{=flag}}.gif%"> {{=value}}";
end
@@ -24,6 +25,7 @@ feature {NONE} -- Initialization
feature -- Implementation
autocompletion (input: STRING): JSON_ARRAY
-- Implementation
local
list: ITERABLE [TUPLE [STRING, STRING]]
o: JSON_OBJECT

View File

@@ -17,6 +17,7 @@ create
feature {NONE} -- Initialization
make
-- Initialize
do
template := "{{=value}}";
end
@@ -24,11 +25,11 @@ feature {NONE} -- Initialization
feature -- Implementation
autocompletion (input: STRING): JSON_ARRAY
-- Implementation
local
cl: LIBCURL_HTTP_CLIENT
sess: HTTP_CLIENT_SESSION
l_json: detachable READABLE_STRING_8
o: JSON_OBJECT
json_parser: JSON_PARSER
query_str: STRING

View File

@@ -7,12 +7,14 @@ note
deferred class
WSF_AUTOCOMPLETION
feature
feature -- Access
autocompletion (input: STRING): JSON_ARRAY
-- JSON array of suggestions that fit the specific input
deferred
end
template: detachable STRING
-- Customizable template
end

View File

@@ -14,9 +14,10 @@ inherit
create
make
feature {NONE}
feature {NONE} -- Initialization
make (l: ITERABLE [STRING])
-- Initialize
do
list := l
end
@@ -24,6 +25,7 @@ feature {NONE}
feature -- Implementation
autocompletion (input: STRING): JSON_ARRAY
-- Implementation
local
o: JSON_OBJECT
do
@@ -33,14 +35,13 @@ feature -- Implementation
loop
if c.item.as_lower.has_substring (input.as_lower) then
create o.make
o.put (create {JSON_STRING}.make_json(c.item), "value")
o.put (create {JSON_STRING}.make_json (c.item), "value")
Result.add (o)
end
end
end
feature
list: ITERABLE [STRING]
-- List containing suggestions
end

View File

@@ -18,9 +18,10 @@ inherit
create
make_autocomplete, make_autocomplete_with_agent
feature {NONE} -- Creation
feature {NONE} -- Initialization
make_autocomplete (n: STRING; c: WSF_AUTOCOMPLETION)
-- Initialize with specified name and autocompletion
do
make_autocomplete_with_agent (n, agent c.autocompletion)
if attached c.template as t then
@@ -29,6 +30,7 @@ feature {NONE} -- Creation
end
make_autocomplete_with_agent (n: STRING; c: FUNCTION [ANY, TUPLE [STRING], JSON_ARRAY])
-- Initialize with specified name and autocompletion function
do
make_input (n, "")
create_json_list := c
@@ -53,7 +55,7 @@ feature -- Callback
end
end
feature -- Autocomplete
feature -- Properties
create_json_list: FUNCTION [ANY, TUPLE [STRING], JSON_ARRAY]

View File

@@ -14,16 +14,17 @@ inherit
create
make_checkbox
feature {NONE}
feature {NONE} -- Initialization
make_checkbox (n: STRING; l: STRING; c: STRING)
make_checkbox (n, l, c: STRING)
-- Initialize with specified control name,
do
make_control (n, "input")
label := l
checked_value := c
end
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
set_state (new_state: JSON_OBJECT)
-- Restore text from json
@@ -42,7 +43,7 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
Result.put (create {JSON_BOOLEAN}.make_boolean (attached change_event), "callback_change")
end
feature --EVENT HANDLING
feature --Event handling
set_change_event (e: attached like change_event)
-- Set text change event handle
@@ -77,14 +78,18 @@ feature -- Implementation
Result := checked
end
feature
feature -- Properties
label: STRING
-- The label of the checkbox control
checked: BOOLEAN
-- The checked value of the checkbox control
checked_value: STRING
-- String checked value
change_event: detachable PROCEDURE [ANY, TUPLE]
-- Function to be executed on change
end

View File

@@ -21,14 +21,15 @@ inherit
create
make_checkbox_list_control
feature {NONE}
feature {NONE} -- Initializaton
make_checkbox_list_control (n: STRING)
-- Initialize with specified control name
do
make_multi_control (n)
end
feature
feature -- Implementation
value: LIST [STRING]
do

View File

@@ -14,16 +14,17 @@ inherit
create
make_input
feature {NONE}
feature {NONE} -- Initialization
make_input (n: STRING; v: STRING)
make_input (n, v: STRING)
-- Initialize with specified name and value
do
make_control (n, "input")
type := "text"
text := v
end
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
set_state (new_state: JSON_OBJECT)
-- Restore text from json
@@ -41,7 +42,7 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
Result.put (create {JSON_BOOLEAN}.make_boolean (attached change_event), "callback_change")
end
feature --EVENT HANDLING
feature --Event handling
set_change_event (e: attached like change_event)
-- Set text change event handle
@@ -58,14 +59,17 @@ feature --EVENT HANDLING
end
end
feature -- Implementation
feature -- Rendering
render: STRING
do
Result := render_tag ("", "type=%"" + type + "%" value=%"" + text + "%"")
end
feature -- Change
set_text (t: STRING)
-- Set text to be displayed
do
if not t.same_string (text) then
text := t
@@ -73,17 +77,22 @@ feature -- Implementation
end
end
feature -- Implementation
value: STRING
do
Result := text
end
feature
feature -- Properties
text: STRING
-- Text to be displayed
type: STRING
-- Type of this input control
change_event: detachable PROCEDURE [ANY, TUPLE]
-- Procedure to be execued on change
end

View File

@@ -14,9 +14,10 @@ inherit
create
make_password
feature {NONE}
feature {NONE} -- Initialization
make_password (n: STRING; v: STRING)
make_password (n, v: STRING)
-- Initialize with specified control name and text
do
make_input (n, v)
type := "password"

View File

@@ -17,15 +17,16 @@ inherit
create
make_textarea
feature {NONE}
feature {NONE} -- Initialization
make_textarea (n, t: STRING)
-- Initialize with specified control name and text to be displayed in this textarea
do
make_input (n, t)
tag_name := "textarea"
end
feature
feature -- Rendering
render: STRING
do

View File

@@ -9,47 +9,19 @@ class
inherit
WSF_STATELESS_MULTI_CONTROL [WSF_STATELESS_CONTROL]
WSF_STATELESS_MULTI_CONTROL
create
make_navbar
feature
collapse: WSF_STATELESS_MULTI_CONTROL [WSF_STATELESS_CONTROL]
nav: WSF_STATELESS_MULTI_CONTROL [WSF_STATELESS_CONTROL]
nav_right: WSF_STATELESS_MULTI_CONTROL [WSF_STATELESS_CONTROL]
feature
add_element (c: WSF_STATELESS_CONTROL)
do
add_element_to_nav (c, nav)
end
add_element_right (c: WSF_STATELESS_CONTROL)
do
add_element_to_nav (c, nav_right)
end
add_element_to_nav (e: WSF_STATELESS_CONTROL; n: WSF_STATELESS_MULTI_CONTROL [WSF_STATELESS_CONTROL])
local
li: WSF_STATELESS_MULTI_CONTROL [WSF_STATELESS_CONTROL]
do
create li.make_with_tag_name ("li")
li.add_control (e)
n.add_control (li)
end
feature {NONE} -- Initialization
make_navbar (b: STRING)
-- Initialize with specified brand string
local
container: WSF_STATELESS_MULTI_CONTROL [WSF_STATELESS_CONTROL]
header: WSF_STATELESS_MULTI_CONTROL [WSF_STATELESS_CONTROL]
collapse_button: WSF_STATELESS_MULTI_CONTROL [WSF_STATELESS_CONTROL]
container: WSF_STATELESS_MULTI_CONTROL
header: WSF_STATELESS_MULTI_CONTROL
collapse_button: WSF_STATELESS_MULTI_CONTROL
brand: WSF_BASIC_CONTROL
icon_bar: WSF_BASIC_CONTROL
do
@@ -70,10 +42,9 @@ feature {NONE} -- Initialization
collapse_button.add_control (icon_bar)
collapse_button.add_control (icon_bar)
collapse_button.add_control (icon_bar)
-- collapse_button.set_attributes ("data-target=%".navbar-collapse%" data-toggle=%"collapse%" type=%"button%"")
brand.add_class ("navbar-brand")
brand.set_attributes ("href=%"#%"")
brand.set_content (b)
brand.set_body (b)
header.add_control (collapse_button)
header.add_control (brand)
nav.add_class ("nav navbar-nav")
@@ -86,4 +57,15 @@ feature {NONE} -- Initialization
add_control (container)
end
feature -- Properties
collapse: WSF_STATELESS_MULTI_CONTROL
-- Content of collapsable navbar
nav: WSF_STATELESS_MULTI_CONTROL
-- Middle nav
nav_right: WSF_STATELESS_MULTI_CONTROL
-- Right nav
end

View File

@@ -17,6 +17,7 @@ create
feature {NONE} -- Initialization
make_progress (n: STRING)
-- Initialize with specified control name
do
make_control (n, "div")
add_class ("progress")
@@ -24,6 +25,7 @@ feature {NONE} -- Initialization
end
make_progress_with_source (n: STRING; p: WSF_PROGRESSSOURCE)
-- Initialize with specified control name and progresssource
do
make_progress (n)
progress_source := p
@@ -64,21 +66,18 @@ feature -- Rendering
Result := render_tag (Result, "")
end
feature --Change progress
feature -- Change
set_progress (p: INTEGER)
-- Set current progress value to specified value. Must be between 0 and 100. Must only be called when no progresssource has been set to this progress control
require
no_progress_source: not (attached progress_source)
no_progress_source: not (attached progress_source) and p >= 0 and p <= 100
do
progress := p
state_changes.put (create {JSON_NUMBER}.make_integer (progress), "progress")
end
feature
progress_source: detachable WSF_PROGRESSSOURCE
progress: INTEGER
feature -- Implementation
progress_value: INTEGER
do
@@ -88,4 +87,10 @@ feature
end
end
feature -- Properties
progress_source: detachable WSF_PROGRESSSOURCE
progress: INTEGER
end

View File

@@ -7,9 +7,10 @@ note
deferred class
WSF_PROGRESSSOURCE
feature
feature -- Specification
progress: INTEGER
-- Current value of progress between 0 and 100 of this progresssource
deferred
end

View File

@@ -14,9 +14,10 @@ inherit
create
make_decimal_validator
feature {NONE}
feature {NONE} -- Initialization
make_decimal_validator (e: STRING)
-- Initialize with specified error message which will be displayed on validation failure
do
make_regexp_validator ("^[0-9]+(\.[0-9]*)?$|^\.[0-9]+$", e)
end

View File

@@ -14,9 +14,10 @@ inherit
create
make_email_validator
feature {NONE}
feature {NONE} -- Initialization
make_email_validator (e: STRING)
-- Initialize with specified error message which will be displayed on validation failure
do
make_regexp_validator ("^[a-zA-Z0-9._%%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,6}$", e)
end

View File

@@ -17,9 +17,10 @@ inherit
create
make_max_validator
feature {NONE}
feature {NONE} -- Initialization
make_max_validator (m: INTEGER; e: STRING)
-- Initialize with specified maximum and error message which will be displayed on validation failure
do
make (e)
max := m
@@ -32,7 +33,7 @@ feature -- Implementation
Result := input.count < max or input.count = max
end
feature
feature -- State
state: JSON_OBJECT
do
@@ -40,6 +41,9 @@ feature
Result.put (create {JSON_NUMBER}.make_integer (max), "max")
end
feature -- Properties
max: INTEGER
-- The maximal allowed value
end

View File

@@ -5,10 +5,11 @@ note
revision: "$Revision$"
class
WSF_MIN_VALIDATOR[G]
WSF_MIN_VALIDATOR [G]
inherit
WSF_VALIDATOR [LIST[G]]
WSF_VALIDATOR [LIST [G]]
redefine
state
end
@@ -16,9 +17,10 @@ inherit
create
make_min_validator
feature {NONE}
feature {NONE} -- Initialization
make_min_validator (m:INTEGER; e: STRING)
make_min_validator (m: INTEGER; e: STRING)
-- Initialize with specified minimum and error message which will be displayed on validation failure
do
make (e)
min := m
@@ -26,13 +28,12 @@ feature {NONE}
feature -- Implementation
is_valid (input:LIST[G]): BOOLEAN
is_valid (input: LIST [G]): BOOLEAN
do
Result:= input.count > min or input.count = min
Result := input.count > min or input.count = min
end
feature
feature -- State
state: JSON_OBJECT
do
@@ -40,6 +41,9 @@ feature
Result.put (create {JSON_NUMBER}.make_integer (min), "min")
end
feature -- Propertiess
min: INTEGER
-- The minimal allowed value
end

View File

@@ -14,9 +14,10 @@ inherit
create
make_with_message
feature {NONE}
feature {NONE} -- Initialization
make_with_message (e: STRING)
-- Initialize with specified error message which will be displayed on validation failure
do
make_regexp_validator ("", e)
end

View File

@@ -17,9 +17,10 @@ inherit
create
make_regexp_validator
feature {NONE}
feature {NONE} -- Initialization
make_regexp_validator (r, e: STRING)
-- Initialize with specified regular expression and error message which will be displayed on validation failure
do
make (e)
regexp_string := r
@@ -37,7 +38,7 @@ feature -- Implementation
Result := regexp.matches (input)
end
feature
feature -- State
state: JSON_OBJECT
do
@@ -47,6 +48,8 @@ feature
Result.put (create {JSON_STRING}.make_json (error), "error")
end
feature -- Properties
regexp_string: STRING
regexp: REGULAR_EXPRESSION

View File

@@ -7,13 +7,15 @@ note
deferred class
WSF_VALIDATABLE
feature
feature -- Specification
validate
-- Perform validation
deferred
end
is_valid: BOOLEAN
-- Result of last validation
deferred
end

View File

@@ -7,16 +7,18 @@ note
deferred class
WSF_VALIDATOR [G]
feature {NONE}
feature {NONE} -- Initialization
make (e: STRING)
-- Initialize with specified error message to be displayed on validation failure
do
error := e
end
feature
feature -- Access
state: JSON_OBJECT
-- JSON state of this validator
do
create Result.make
Result.put (create {JSON_STRING}.make_json (generator), "name")
@@ -24,9 +26,12 @@ feature
end
is_valid (input: G): BOOLEAN
-- Perform validation on given input and tell whether validation was successful or not
deferred
end
feature -- Properties
error: STRING
end

View File

@@ -12,46 +12,52 @@ inherit
WSF_STATELESS_CONTROL
create
make_control,
make_with_body
make_control, make_with_body
feature {NONE} -- Initialization
make_control (t: STRING)
-- Initialize
do
make_with_body (t, "", "")
end
make_with_body (t,attr,a_content: STRING)
make_with_body (t, attr, b: STRING)
-- Initialize with specific attributes and body
do
make (t)
attributes := attr
content := a_content
body := b
end
feature -- Access
feature -- Access
attributes: STRING
-- Attributes string of this control
content: STRING
body: STRING
-- Body of this control
feature -- Rendering
render: STRING
-- HTML representation of this control
do
Result := render_tag (content, attributes)
Result := render_tag (body, attributes)
end
feature
set_attributes (a: STRING)
-- Set the attributes string of this control
do
attributes := a
end
set_content (c: STRING)
set_body (b: STRING)
-- Set the body of this control
do
content := c
body := b
end
end

View File

@@ -14,9 +14,10 @@ inherit
create
make_button
feature {NONE}
feature {NONE} -- Initialization
make_button (n: STRING; t: STRING)
-- Initialize with specified control name and text
do
make_control (n, "button")
add_class ("btn")
@@ -24,7 +25,7 @@ feature {NONE}
text := t
end
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
set_state (new_state: JSON_OBJECT)
-- Restore text from json
@@ -42,7 +43,7 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
Result.put (create {JSON_BOOLEAN}.make_boolean (attached click_event), "callback_click")
end
feature --EVENT HANDLING
feature --Event handling
set_click_event (e: attached like click_event)
-- Set button click event handle
@@ -57,14 +58,18 @@ feature --EVENT HANDLING
end
end
feature
feature -- Rendering
render: STRING
-- HTML representation of this control
do
Result := render_tag (text, "")
end
feature -- Change
set_text (t: STRING)
-- Set text of that button
do
if not t.same_string (text) then
text := t
@@ -72,10 +77,12 @@ feature
end
end
feature
feature -- Properties
text: STRING
-- The text currently displayed on this button
click_event: detachable PROCEDURE [ANY, TUPLE]
-- Event that is executed when button is clicked
end

View File

@@ -18,9 +18,10 @@ feature
control_name: STRING
feature {NONE}
feature {NONE} -- Initialization
make_control (n, a_tag_name: STRING)
-- Initialize with specified control name and tag
do
make (a_tag_name)
control_name := n
@@ -68,11 +69,13 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
feature -- Rendering
render_tag (body, attrs: STRING): STRING
-- Render this control with the specified body and attributes
do
Result := render_tag_with_generator_name (generator, body, attrs)
end
render_tag_with_generator_name (a_generator, body, attrs: STRING): STRING
-- Render this control with the specified generator name, body and attributes
local
css_classes_string: STRING
l_attributes: STRING

View File

@@ -16,9 +16,10 @@ inherit
create
make_form_control
feature {NONE}
feature {NONE} -- Initialization
make_form_control (n: STRING)
-- Initialize
do
make_multi_control (n)
tag_name := "form"
@@ -27,6 +28,7 @@ feature {NONE}
feature -- Validation
validate
-- Perform form validation
do
is_valid := True
across
@@ -44,5 +46,6 @@ feature -- Validation
end
is_valid: BOOLEAN
-- Tells whether the last validation was valid
end

View File

@@ -21,14 +21,16 @@ inherit
create
make_form_element, make_form_element_with_validators
feature {NONE}
feature {NONE} -- Initialization
make_form_element (a_label: STRING; c: WSF_VALUE_CONTROL [G])
-- Initialize form element control with a specific label and value control
do
make_form_element_with_validators (a_label, c, create {ARRAYED_LIST [WSF_VALIDATOR [G]]}.make (0))
end
make_form_element_with_validators (a_label: STRING; c: WSF_VALUE_CONTROL [G]; v: LIST [WSF_VALIDATOR [G]])
-- Initialize form element control with a specific label, value control and list of validators
do
make_control (c.control_name + "_container", "div")
add_class ("form-group")
@@ -44,7 +46,7 @@ feature {NONE}
error := ""
end
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
load_state (new_states: JSON_OBJECT)
-- Pass new_states to subcontrols
@@ -54,6 +56,7 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
end
set_state (new_state: JSON_OBJECT)
-- Set new state
do
value_control.set_state (new_state)
end
@@ -73,7 +76,7 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
end
state: JSON_OBJECT
--Read state
-- Read state
local
validator_description: JSON_ARRAY
do
@@ -88,7 +91,7 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
Result.put (validator_description, "validators")
end
feature --EVENT HANDLING
feature -- Event handling
handle_callback (cname: STRING; event: STRING; event_parameter: detachable STRING)
-- Pass callback to subcontrols
@@ -102,9 +105,10 @@ feature --EVENT HANDLING
end
end
feature --Implementation
feature -- Implementation
render: STRING
-- HTML Respresentation of this form element control
local
body: STRING
do
@@ -121,17 +125,20 @@ feature --Implementation
feature -- Validation
add_validator (v: WSF_VALIDATOR [G])
-- Add an additional validator that will check the input of the value control of this form element control on validation
do
validators.extend (v)
end
set_error (e: STRING)
-- Set the error message that will be displayed upon failure of client side validation
do
error := e
state_changes.replace (create {JSON_STRING}.make_json (e), "error")
end
validate
-- Perform validation
local
current_value: G
do
@@ -153,15 +160,20 @@ feature -- Validation
end
is_valid: BOOLEAN
-- Tells whether the last validation was successful or not
feature
feature -- Properties
value_control: WSF_VALUE_CONTROL [G]
-- The value control associated with this form element control
validators: LIST [WSF_VALIDATOR [G]]
-- The validators which check the input when validaton is performed
label: STRING
-- The label of this form element control
error: STRING
-- The error message that is displayed when client side validation fails
end

View File

@@ -14,15 +14,16 @@ inherit
create
make_html
feature {NONE}
feature {NONE} -- Initialization
make_html (n, t, v: STRING)
-- Initialize
do
make_control (n, t)
html := v
end
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
set_state (new_state: JSON_OBJECT)
-- Restore html from json
@@ -39,7 +40,7 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
Result.put (create {JSON_STRING}.make_json (html), "html")
end
feature --EVENT HANDLING
feature --Event handling
handle_callback (cname: STRING; event: STRING; event_parameter: detachable STRING)
do
@@ -48,6 +49,7 @@ feature --EVENT HANDLING
feature -- Implementation
render: STRING
-- HTML representation of this html control
do
Result := render_tag (html, "")
end
@@ -65,7 +67,7 @@ feature -- Implementation
Result := html
end
feature
feature -- Properties
html: STRING

View File

@@ -22,17 +22,19 @@ create
feature {NONE} -- Initialization
make_multi_control (n: STRING)
-- Initialize with specified control name and default tag "div"
do
make_with_tag_name (n, "div")
end
make_with_tag_name (n, t: STRING)
-- Initialize with specified control name and tag
do
make_control (n, t)
controls := create {LINKED_LIST [G]}.make;
end
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
load_state (new_states: JSON_OBJECT)
-- Pass new_states to subcontrols
@@ -84,7 +86,7 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
create Result.make
end
feature -- EVENT HANDLING
feature -- Event handling
handle_callback (cname: STRING; event: STRING; event_parameter: detachable STRING)
-- Pass callback to subcontrols
@@ -101,9 +103,10 @@ feature -- EVENT HANDLING
end
end
feature
feature -- Rendering
render: STRING
-- HTML representation of this multi control
do
Result := ""
across
@@ -114,13 +117,19 @@ feature
Result := render_tag (Result, "")
end
add_control (c: detachable G)
feature -- Change
add_control (c: detachable G)
-- Add a control to this multi control
do
if attached c as d then
controls.put_front (d)
end
end
feature -- Properties
controls: LINKED_LIST [G]
-- List of current controls in this multi control
end

View File

@@ -10,6 +10,7 @@ deferred class
feature {NONE} -- Initialization
make (req: WSF_REQUEST; res: WSF_RESPONSE)
-- Initialize
do
request := req
response := res
@@ -19,10 +20,12 @@ feature {NONE} -- Initialization
feature -- Access
request: WSF_REQUEST
-- The request
response: WSF_RESPONSE
-- The response
feature
feature -- Specific implementation
initialize_controls
-- Initalize all the controls, all the event handles must be set in this function.
@@ -36,7 +39,7 @@ feature
deferred
end
feature
feature -- Implementation
execute
-- Entry Point: If request is a callback, restore control states and execute handle then return new state json.
@@ -108,8 +111,9 @@ feature
end
end
feature {NONE}
feature {NONE} -- Root control
control: WSF_CONTROL
-- The root control of this page
end

View File

@@ -7,9 +7,10 @@ note
deferred class
WSF_STATELESS_CONTROL
feature {NONE}
feature {NONE} -- Initialization
make (a_tag_name: STRING)
-- Initialize with specified tag
do
tag_name := a_tag_name
create css_classes.make (0)
@@ -20,19 +21,25 @@ feature {NONE}
feature -- Access
tag_name: STRING
-- The tag name
css_classes: ARRAYED_LIST [STRING]
-- List of classes (appear in the "class" attribute)
--TODO: Maybe improve
-- TODO: Maybe improve
feature -- Change
add_class (c: STRING)
-- Add a css class to this control
do
css_classes.force (c)
end
feature -- Rendering
render_tag (body, attrs: STRING): STRING
-- Generate HTML of this control with the specified body and attributes
local
css_classes_string: STRING
do
@@ -46,6 +53,7 @@ feature -- Change
end
render_tag_with_tagname (tag, body, attrs, css_classes_string: STRING): STRING
-- Generate HTML of the specified tag with specified body, attributes and css classes
local
l_attributes: STRING
do
@@ -56,13 +64,7 @@ feature -- Change
l_attributes.append_character ('%"')
end
Result := "<" + tag + " " + l_attributes
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")
then
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") then
Result.append (" />")
else
Result.append (" >" + body + "</" + tag + ">")

View File

@@ -5,7 +5,7 @@ note
revision: "$Revision$"
class
WSF_STATELESS_MULTI_CONTROL [G -> WSF_STATELESS_CONTROL]
WSF_STATELESS_MULTI_CONTROL
inherit
@@ -17,19 +17,22 @@ create
feature {NONE} -- Initialization
make_multi_control
-- Initialize with default tag "div"
do
make_with_tag_name ("div")
end
make_with_tag_name (t: STRING)
-- Initialize with specified tag
do
make (t)
controls := create {LINKED_LIST [G]}.make;
controls := create {LINKED_LIST [WSF_STATELESS_CONTROL]}.make;
end
feature
feature -- Rendering
render: STRING
-- HTML representation of this stateless multi control
do
Result := ""
across
@@ -40,11 +43,17 @@ feature
Result := render_tag (Result, "")
end
add_control (c: G)
feature -- Change
add_control (c: WSF_STATELESS_CONTROL)
-- Add control to this stateless multi control
do
controls.put_front (c)
end
controls: LINKED_LIST [G]
feature -- Properties
controls: LINKED_LIST [WSF_STATELESS_CONTROL]
-- List of controls
end

View File

@@ -11,9 +11,10 @@ inherit
WSF_CONTROL
feature
feature -- Access
value: G
-- The current value of this control
deferred
end