Implemented WSF_CHECKBOX_CONTROL, added id attribute to rendering of WSF_CONTROL

This commit is contained in:
Severin Münger
2013-09-05 17:16:56 +02:00
parent edce18fb1f
commit f506d9e925
6 changed files with 93 additions and 12 deletions

View File

@@ -59,7 +59,7 @@ feature
render: STRING render: STRING
do do
Result := render_tag ( text, "") Result := render_tag (text, "")
end end
set_text (t: STRING) set_text (t: STRING)

View File

@@ -0,0 +1,83 @@
note
description: "Summary description for {WSF_CHECKBOX_CONTROL}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_CHECKBOX_CONTROL
inherit
WSF_VALUE_CONTROL[BOOLEAN]
create
make_checkbox
feature {NONE}
make_checkbox (n: STRING; l: STRING)
do
make (n, "input")
label := l
end
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
set_state (new_state: JSON_OBJECT)
-- Restore text from json
do
if attached {JSON_BOOLEAN} new_state.item (create {JSON_STRING}.make_json ("checked")) as new_checked then
checked := new_checked.item
end
end
state: JSON_OBJECT
-- Return state which contains the current text and if there is an event handle attached
do
create Result.make
Result.put (create {JSON_BOOLEAN}.make_boolean (checked), create {JSON_STRING}.make_json ("checked"))
Result.put (create {JSON_BOOLEAN}.make_boolean (attached change_event), create {JSON_STRING}.make_json ("callback_change"))
end
feature --EVENT HANDLING
set_change_event (e: attached like change_event)
-- Set text change event handle
do
change_event := e
end
handle_callback (cname: STRING; event: STRING)
do
if Current.control_name.is_equal (cname) and attached change_event as cevent then
if event.is_equal ("change") then
cevent.call ([])
end
end
end
feature -- Implementation
render: STRING
local
attributes: STRING
do
attributes := "type=%"checkbox%""
if checked then
attributes := attributes + " checked"
end
Result := render_tag ("", attributes)
end
value: BOOLEAN
do
Result := checked
end
feature
label: STRING
checked: BOOLEAN
change_event: detachable PROCEDURE [ANY, TUPLE []]
end

View File

@@ -91,7 +91,7 @@ feature
if not css_classes_string.is_empty then if not css_classes_string.is_empty then
css_classes_string := " class=%"" + css_classes_string + "%"" css_classes_string := " class=%"" + css_classes_string + "%""
end end
Result := "<" + tag_name + " data-name=%"" + control_name + "%" data-type=%"" + generator + "%" " + attributes + css_classes_string Result := "<" + tag_name + " id=%"" + control_name + "%" data-name=%"" + control_name + "%" data-type=%"" + generator + "%" " + attributes + css_classes_string
if body.is_empty then if body.is_empty then
Result := Result + " />" Result := Result + " />"
else else

View File

@@ -12,22 +12,21 @@ inherit
WSF_CONTROL WSF_CONTROL
create create
make_form_element, make_form_element, make_form_element_with_validators
make_form_element_with_validators
feature {NONE} feature {NONE}
make_form_element (a_label:STRING; c: WSF_VALUE_CONTROL [G]) make_form_element (a_label: STRING; c: WSF_VALUE_CONTROL [G])
local local
a_validators: LINKED_LIST [WSF_VALIDATOR [G]] a_validators: LINKED_LIST [WSF_VALIDATOR [G]]
do do
create a_validators.make create a_validators.make
make_form_element_with_validators(a_label,c,a_validators) make_form_element_with_validators (a_label, c, a_validators)
end end
make_form_element_with_validators (a_label: STRING; c: WSF_VALUE_CONTROL [G]; v: LINKED_LIST [WSF_VALIDATOR [G]]) make_form_element_with_validators (a_label: STRING; c: WSF_VALUE_CONTROL [G]; v: LINKED_LIST [WSF_VALIDATOR [G]])
do do
make (c.control_name+"_container", "div") make (c.control_name + "_container", "div")
add_class ("form-group") add_class ("form-group")
c.add_class ("form-control") c.add_class ("form-control")
value_control := c value_control := c

View File

@@ -9,8 +9,6 @@ class
inherit inherit
WSF_CONTROL
WSF_VALUE_CONTROL [STRING] WSF_VALUE_CONTROL [STRING]
create create
@@ -63,7 +61,7 @@ feature -- Implementation
render: STRING render: STRING
do do
Result := render_tag ("", "value=%"" + text + "%"") Result := render_tag ("", "type=%"text%" value=%"" + text + "%"")
end end
set_text (t: STRING) set_text (t: STRING)

View File

@@ -24,11 +24,12 @@ feature {NONE}
make_text (n, t) make_text (n, t)
tag_name := "textarea" tag_name := "textarea"
end end
feature feature
render: STRING render: STRING
do do
Result :=render_tag(text,"") Result := render_tag (text, "")
end end
end end