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

View File

@@ -11,24 +11,71 @@ inherit
WSF_CONTROL 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 feature
is_valid (value: G): BOOLEAN is_valid (value: G): BOOLEAN
do do
if attached validate as v then Result := True
Result := v.item ([value]) across
else validators as c
Result := True loop
end end
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 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 end

View File

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

View File

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

View File

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