Redesign states and implement generated control_name
This commit is contained in:
@@ -19,13 +19,13 @@ create
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (n: STRING; t: STRING)
|
||||
make (a_text: STRING)
|
||||
-- Initialize with specified control name and text
|
||||
do
|
||||
make_control (n, "button")
|
||||
make_control ("button")
|
||||
add_class ("btn")
|
||||
add_class ("btn-default")
|
||||
text := t
|
||||
text := a_text
|
||||
end
|
||||
|
||||
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
|
||||
@@ -54,9 +54,9 @@ feature --Event handling
|
||||
click_event := e
|
||||
end
|
||||
|
||||
handle_callback (cname: STRING; event: STRING; event_parameter: detachable STRING)
|
||||
handle_callback (cname: LIST[STRING]; event: STRING; event_parameter: detachable STRING)
|
||||
do
|
||||
if Current.control_name.same_string (cname) and attached click_event as cevent then
|
||||
if Current.control_name.same_string (cname[1]) and attached click_event as cevent then
|
||||
cevent.call (Void)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -18,14 +18,13 @@ inherit
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (n, a_tag_name: STRING)
|
||||
make (a_tag_name: STRING)
|
||||
-- Initialize with specified control name and tag
|
||||
require
|
||||
not n.is_empty
|
||||
not a_tag_name.is_empty
|
||||
do
|
||||
make_stateless_control (a_tag_name)
|
||||
control_name := n
|
||||
create control_name_prefix.make_empty
|
||||
create state_changes.make
|
||||
create actions.make_array
|
||||
ensure
|
||||
@@ -140,7 +139,7 @@ feature -- Rendering
|
||||
loop
|
||||
css_classes_string := css_classes_string + " " + c.item
|
||||
end
|
||||
l_attributes := "id=%"" + control_name + "%" data-name=%"" + control_name + "%" data-type=%"" + a_generator + "%" "
|
||||
l_attributes := " data-name=%"" + control_name + "%" data-type=%"" + a_generator + "%" "
|
||||
if attached attrs as a then
|
||||
l_attributes := l_attributes + a
|
||||
end
|
||||
@@ -152,7 +151,7 @@ feature -- Rendering
|
||||
|
||||
feature -- Event handling
|
||||
|
||||
handle_callback (cname: STRING; event: STRING; event_parameter: detachable STRING)
|
||||
handle_callback (cname: LIST [STRING]; event: STRING; event_parameter: detachable STRING)
|
||||
-- Method called if any callback received. In this method you can route the callback to the event handler
|
||||
deferred
|
||||
end
|
||||
@@ -170,6 +169,24 @@ feature -- Properties
|
||||
|
||||
actions: JSON_ARRAY
|
||||
|
||||
control_id: INTEGER assign set_control_id
|
||||
|
||||
set_control_id (d: INTEGER)
|
||||
do
|
||||
control_id := d
|
||||
end
|
||||
|
||||
control_name: STRING
|
||||
do
|
||||
Result := control_name_prefix + control_id.out
|
||||
end
|
||||
|
||||
control_name_prefix: STRING assign set_control_name_prefix
|
||||
|
||||
|
||||
set_control_name_prefix (p: STRING)
|
||||
do
|
||||
control_name_prefix := p
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -21,10 +21,10 @@ create
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (n: STRING)
|
||||
make
|
||||
-- Initialize
|
||||
do
|
||||
make_multi_control (n)
|
||||
make_multi_control
|
||||
tag_name := "form"
|
||||
end
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ feature {NONE} -- Initialization
|
||||
make_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")
|
||||
make_control ("div")
|
||||
add_class ("form-group")
|
||||
if attached {WSF_INPUT_CONTROL} c or attached {WSF_TEXTAREA_CONTROL} c then
|
||||
c.add_class ("form-control")
|
||||
@@ -100,14 +100,15 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
|
||||
|
||||
feature -- Event handling
|
||||
|
||||
handle_callback (cname: STRING; event: STRING; event_parameter: detachable STRING)
|
||||
handle_callback (cname: LIST[STRING]; event: STRING; event_parameter: detachable STRING)
|
||||
-- Pass callback to subcontrols
|
||||
do
|
||||
if cname.same_string (control_name) then
|
||||
if cname[1].same_string (control_name) then
|
||||
cname.go_i_th (1)
|
||||
cname.remove
|
||||
if event.same_string ("validate") then
|
||||
validate
|
||||
end
|
||||
else
|
||||
value_control.handle_callback (cname, event, event_parameter)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -17,10 +17,10 @@ create
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (n, t, v: STRING)
|
||||
make (t, v: STRING)
|
||||
-- Initialize
|
||||
do
|
||||
make_value_control (n, t)
|
||||
make_value_control ( t)
|
||||
html := v
|
||||
end
|
||||
|
||||
@@ -43,7 +43,7 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
|
||||
|
||||
feature --Event handling
|
||||
|
||||
handle_callback (cname: STRING; event: STRING; event_parameter: detachable STRING)
|
||||
handle_callback (cname: LIST[STRING]; event: STRING; event_parameter: detachable STRING)
|
||||
do
|
||||
end
|
||||
|
||||
|
||||
@@ -30,9 +30,9 @@ feature -- Add control
|
||||
|
||||
add_control_with_offset (c: WSF_STATELESS_CONTROL; span, offset: INTEGER)
|
||||
local
|
||||
div: WSF_MULTI_CONTROL [WSF_STATELESS_CONTROL]
|
||||
div: WSF_STATELESS_MULTI_CONTROL [WSF_STATELESS_CONTROL]
|
||||
do
|
||||
create div.make (control_name + "_item_" + controls.count.out)
|
||||
create div.make_with_tag_name ("div")
|
||||
div.add_class ("col-md-" + span.out + " col-md-offset-" + offset.out)
|
||||
div.add_control (c)
|
||||
add_control_raw (div)
|
||||
@@ -40,9 +40,9 @@ feature -- Add control
|
||||
|
||||
add_control (c: WSF_STATELESS_CONTROL; span: INTEGER)
|
||||
local
|
||||
div: WSF_MULTI_CONTROL [WSF_STATELESS_CONTROL]
|
||||
div: WSF_STATELESS_MULTI_CONTROL [WSF_STATELESS_CONTROL]
|
||||
do
|
||||
create div.make (control_name + "_item_" + controls.count.out)
|
||||
create div.make_with_tag_name ("div")
|
||||
div.add_class ("col-md-" + span.out)
|
||||
div.add_control (c)
|
||||
add_control_raw (div)
|
||||
|
||||
@@ -23,16 +23,16 @@ create
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (n: STRING)
|
||||
make
|
||||
-- Initialize with specified control name and default tag "div"
|
||||
do
|
||||
make_with_tag_name (n, "div")
|
||||
make_with_tag_name ("div")
|
||||
end
|
||||
|
||||
make_with_tag_name (n, t: STRING)
|
||||
make_with_tag_name (t: STRING)
|
||||
-- Initialize with specified control name and tag
|
||||
do
|
||||
make_control (n, t)
|
||||
make_control (t)
|
||||
controls := create {ARRAYED_LIST [G]}.make (5);
|
||||
end
|
||||
|
||||
@@ -52,7 +52,7 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
|
||||
across
|
||||
controls as c
|
||||
loop
|
||||
if attached {WSF_STATELESS_MULTI_CONTROL[WSF_STATELESS_CONTROL]} c.item as cont then
|
||||
if attached {WSF_STATELESS_MULTI_CONTROL [WSF_STATELESS_CONTROL]} c.item as cont then
|
||||
cont.load_subcontrol_state (newstate)
|
||||
elseif attached {WSF_CONTROL} c.item as cont then
|
||||
if attached {JSON_OBJECT} newstate.item (cont.control_name) as value_state then
|
||||
@@ -83,7 +83,7 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
|
||||
across
|
||||
controls as c
|
||||
loop
|
||||
if attached {WSF_STATELESS_MULTI_CONTROL[WSF_STATELESS_CONTROL]} c.item as mcont then
|
||||
if attached {WSF_STATELESS_MULTI_CONTROL [WSF_STATELESS_CONTROL]} c.item as mcont then
|
||||
mcont.read_subcontrol_state (controls_state)
|
||||
elseif attached {WSF_CONTROL} c.item as cont then
|
||||
controls_state.put (cont.full_state, cont.control_name)
|
||||
@@ -93,12 +93,32 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
|
||||
|
||||
read_state_changes (states: WSF_JSON_OBJECT)
|
||||
-- Read states_changes in subcontrols
|
||||
local
|
||||
sub_states: WSF_JSON_OBJECT
|
||||
control_state: WSF_JSON_OBJECT
|
||||
do
|
||||
Precursor (states)
|
||||
create sub_states.make
|
||||
read_subcontrol_state_changes (sub_states)
|
||||
if sub_states.count>0 then
|
||||
if attached {JSON_OBJECT}states.item (control_name) as changes then
|
||||
changes.put (sub_states, "controls")
|
||||
else
|
||||
create control_state.make
|
||||
control_state.put (sub_states, "controls")
|
||||
states.put (control_state, control_name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
read_subcontrol_state_changes (states: WSF_JSON_OBJECT)
|
||||
do
|
||||
across
|
||||
controls as c
|
||||
loop
|
||||
if attached {WSF_CONTROL} c.item as cont then
|
||||
if attached {WSF_STATELESS_MULTI_CONTROL [WSF_STATELESS_CONTROL]} c.item as cont then
|
||||
cont.read_subcontrol_state_changes (states)
|
||||
elseif attached {WSF_CONTROL} c.item as cont then
|
||||
cont.read_state_changes (states)
|
||||
end
|
||||
end
|
||||
@@ -112,11 +132,12 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
|
||||
|
||||
feature -- Event handling
|
||||
|
||||
handle_callback (cname: STRING; event: STRING; event_parameter: detachable STRING)
|
||||
handle_callback (cname: LIST [STRING]; event: STRING; event_parameter: detachable STRING)
|
||||
-- Pass callback to subcontrols
|
||||
do
|
||||
if equal (cname, control_name) then
|
||||
else
|
||||
if equal (cname [1], control_name) then
|
||||
cname.go_i_th (1)
|
||||
cname.remove
|
||||
across
|
||||
controls as c
|
||||
loop
|
||||
@@ -143,12 +164,15 @@ feature -- Rendering
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Change
|
||||
feature
|
||||
|
||||
add_control (c: G)
|
||||
-- Add a control to this multi control
|
||||
do
|
||||
controls.extend (c)
|
||||
if attached {WSF_CONTROL} c as d then
|
||||
d.control_id := controls.count
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Properties
|
||||
|
||||
@@ -13,6 +13,7 @@ inherit
|
||||
rename
|
||||
make as make_control
|
||||
redefine
|
||||
control_name,
|
||||
full_state,
|
||||
read_state_changes
|
||||
end
|
||||
@@ -22,7 +23,8 @@ feature {NONE} -- Initialization
|
||||
make (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
-- Initialize
|
||||
do
|
||||
make_control (req.request_time_stamp.out, "body")
|
||||
control_name:=req.request_time_stamp.out
|
||||
make_control ( "body")
|
||||
request := req
|
||||
response := res
|
||||
initialize_controls
|
||||
@@ -73,7 +75,7 @@ feature -- Implementation
|
||||
if attached {JSON_OBJECT} json_parser.parse_json as sp then
|
||||
set_state (sp)
|
||||
end
|
||||
handle_callback (event_control_name, event, event_parameter)
|
||||
handle_callback (event_control_name.split ('-'), event, event_parameter)
|
||||
create states_changes.make
|
||||
read_state_changes (states_changes)
|
||||
response.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-Type", "application/json; charset=ISO-8859-1"]>>)
|
||||
@@ -145,7 +147,7 @@ feature -- Implementation
|
||||
|
||||
feature -- Event handling
|
||||
|
||||
handle_callback (cname: STRING; event: STRING; event_parameter: detachable STRING)
|
||||
handle_callback (cname: LIST[STRING]; event: STRING; event_parameter: detachable STRING)
|
||||
-- Forward callback to control
|
||||
do
|
||||
control.handle_callback (cname, event, event_parameter)
|
||||
@@ -178,6 +180,8 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
|
||||
Result.put (controls_state, "controls")
|
||||
Result.put (state, "state")
|
||||
end
|
||||
feature
|
||||
control_name:STRING
|
||||
|
||||
feature {NONE} -- Root control
|
||||
|
||||
|
||||
@@ -37,6 +37,12 @@ feature -- Change
|
||||
css_classes.force (c)
|
||||
end
|
||||
|
||||
remove_class (cla: STRING)
|
||||
-- Add a css class to this control
|
||||
do
|
||||
css_classes.prune (cla)
|
||||
end
|
||||
|
||||
feature -- Rendering
|
||||
|
||||
render_tag (body: STRING; attrs: detachable STRING): STRING
|
||||
|
||||
@@ -6,10 +6,17 @@ note
|
||||
|
||||
class
|
||||
WSF_STATELESS_MULTI_CONTROL [G -> WSF_STATELESS_CONTROL]
|
||||
|
||||
inherit
|
||||
|
||||
WSF_MULTI_CONTROL [G]
|
||||
rename
|
||||
make_with_tag_name as make_with_tag_name_and_name
|
||||
redefine
|
||||
add_control,
|
||||
set_control_name_prefix,
|
||||
handle_callback,
|
||||
set_control_id
|
||||
end
|
||||
|
||||
create
|
||||
@@ -17,15 +24,67 @@ create
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make_with_tag_name(t:STRING)
|
||||
do
|
||||
make_with_tag_name_and_name("",t)
|
||||
end
|
||||
make_with_tag_name (t: STRING)
|
||||
do
|
||||
make_with_tag_name_and_name (t)
|
||||
end
|
||||
|
||||
make_tag_less
|
||||
do
|
||||
make_with_tag_name_and_name ("", "")
|
||||
make_with_tag_name_and_name ("")
|
||||
stateless := True
|
||||
end
|
||||
|
||||
feature
|
||||
|
||||
|
||||
|
||||
set_control_id (d: INTEGER)
|
||||
do
|
||||
control_id := d
|
||||
set_subcontrol_prefixes
|
||||
end
|
||||
|
||||
set_control_name_prefix (p: STRING)
|
||||
do
|
||||
control_name_prefix := p
|
||||
set_subcontrol_prefixes
|
||||
end
|
||||
|
||||
set_subcontrol_prefixes
|
||||
do
|
||||
across
|
||||
controls as e
|
||||
loop
|
||||
if attached {WSF_CONTROL} e.item as el then
|
||||
el.control_name_prefix := control_name_prefix + control_id.out + "_"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
feature
|
||||
|
||||
add_control (c: G)
|
||||
-- Add a control to this multi control
|
||||
do
|
||||
controls.extend (c)
|
||||
if attached {WSF_CONTROL} c as d then
|
||||
d.control_id := controls.count
|
||||
d.control_name_prefix := control_name_prefix + control_id.out + "_"
|
||||
end
|
||||
end
|
||||
feature -- Event handling
|
||||
|
||||
handle_callback (cname: LIST [STRING]; event: STRING; event_parameter: detachable STRING)
|
||||
-- Pass callback to subcontrols
|
||||
do
|
||||
across
|
||||
controls as c
|
||||
loop
|
||||
if attached {WSF_CONTROL} c.item as cont then
|
||||
cont.handle_callback (cname, event, event_parameter)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user