Implemented WSF_FORM_ELEMENT_CONTROL

This commit is contained in:
Severin Münger
2013-09-05 16:25:44 +02:00
parent f9cc0afb9e
commit deaeaa434d
5 changed files with 85 additions and 27 deletions

View File

@@ -13,7 +13,7 @@ feature
tag_name: STRING
css_class: LINKED_LIST [STRING]
css_classes: LINKED_LIST [STRING]
feature {NONE}
@@ -21,11 +21,11 @@ feature {NONE}
do
control_name := n
tag_name := a_tag_name
create css_class.make
create css_classes.make
create state_changes.make
ensure
attached state_changes
attached css_class
attached css_classes
end
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
@@ -73,20 +73,25 @@ feature --EVENT HANDLING
feature
render_tag(body,attributes:STRING):STRING
local
css_class_string: STRING
add_class (c: STRING)
do
css_class_string := ""
css_classes.extend (c)
end
render_tag (body, attributes: STRING): STRING
local
css_classes_string: STRING
do
css_classes_string := ""
across
css_class as c
css_classes as c
loop
css_class_string := css_class_string + " " + c.item
css_classes_string := css_classes_string + " " + c.item
end
if not css_class_string.is_empty then
css_class_string := " class=%"" + css_class_string + "%""
if not css_classes_string.is_empty then
css_classes_string := " class=%"" + css_classes_string + "%""
end
Result:="<"+tag_name+" data-name=%"" + control_name + "%" data-type=%""+generator+"%" "+attributes+css_class_string
Result := "<" + tag_name + " data-name=%"" + control_name + "%" data-type=%"" + generator + "%" " + attributes + css_classes_string
if not body.is_empty then
Result := Result + " />"
else

View File

@@ -11,24 +11,71 @@ inherit
WSF_CONTROL
create
make_form_element
feature {NONE}
make_form_element (n: STRING; c: WSF_VALUE_CONTROL [G]; v: LINKED_LIST [WSF_VALIDATOR [G]])
do
make (n, "div")
add_class ("form-group")
value_control := c
validators := v
label := ""
error := ""
end
feature
is_valid (value: G): BOOLEAN
do
if attached validate as v then
Result := v.item ([value])
else
Result := True
Result := True
across
validators as c
loop
end
end
feature --Implementation
set_state (new_state: JSON_OBJECT)
do
value_control.set_state (new_state)
end
state: JSON_OBJECT
do
Result := value_control.state
end
handle_callback (cname, event: STRING_8)
do
value_control.handle_callback (cname, event)
end
render: STRING
local
body:STRING
do
body := ""
if not label.is_empty then
body := "<label class=%"col-lg-10 control-label%" for=%"" + value_control.control_name + "%">" + label + "</label>"
end
body := body + "<div class=%"col-lg-10%">"
body := body + value_control.render
body := body + "</div>"
Result := render_tag (body, "")
end
feature
value_control: WSF_VALUE_CONTROL[G]
value_control: WSF_VALUE_CONTROL [G]
validate: detachable FUNCTION [ANY, TUPLE [G], BOOLEAN]
validators: LINKED_LIST [WSF_VALIDATOR [G]]
label: STRING
error: STRING
end

View File

@@ -80,7 +80,7 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
feature --EVENT HANDLING
handle_callback (event: STRING; cname: STRING)
handle_callback (cname: STRING; event: STRING)
-- Pass callback to subcontrols
do
if equal (cname, control_name) then
@@ -88,7 +88,7 @@ feature --EVENT HANDLING
across
controls as c
loop
c.item.handle_callback (event, cname)
c.item.handle_callback (cname, event)
end
end
end

View File

@@ -4,13 +4,15 @@ note
date: "$Date$"
revision: "$Revision$"
class
WSF_VALIDATOR
deferred class
WSF_VALIDATOR [G]
create
make
feature
feature {NONE}
validate (input: G): BOOLEAN
deferred
end
error: STRING
end

View File

@@ -7,6 +7,10 @@ note
deferred class
WSF_VALUE_CONTROL [G]
inherit
WSF_CONTROL
feature
value: G