Add comments
Use Precursor
This commit is contained in:
@@ -25,6 +25,7 @@ feature {NONE}
|
|||||||
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
|
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
|
||||||
|
|
||||||
set_state (new_state: JSON_OBJECT)
|
set_state (new_state: JSON_OBJECT)
|
||||||
|
-- Restore text from json
|
||||||
do
|
do
|
||||||
if attached {JSON_STRING} new_state.item (create {JSON_STRING}.make_json ("text")) as new_text then
|
if attached {JSON_STRING} new_state.item (create {JSON_STRING}.make_json ("text")) as new_text then
|
||||||
text := new_text.unescaped_string_32
|
text := new_text.unescaped_string_32
|
||||||
@@ -32,6 +33,7 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
|
|||||||
end
|
end
|
||||||
|
|
||||||
state: JSON_OBJECT
|
state: JSON_OBJECT
|
||||||
|
-- Return state which contains the current text and if there is an event handle attached
|
||||||
do
|
do
|
||||||
create Result.make
|
create Result.make
|
||||||
Result.put (create {JSON_STRING}.make_json (text), create {JSON_STRING}.make_json ("text"))
|
Result.put (create {JSON_STRING}.make_json (text), create {JSON_STRING}.make_json ("text"))
|
||||||
@@ -41,6 +43,7 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
|
|||||||
feature --EVENT HANDLING
|
feature --EVENT HANDLING
|
||||||
|
|
||||||
set_click_event (e: attached like click_event)
|
set_click_event (e: attached like click_event)
|
||||||
|
-- Set button click event handle
|
||||||
do
|
do
|
||||||
click_event := e
|
click_event := e
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -14,37 +14,40 @@ feature
|
|||||||
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
|
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
|
||||||
|
|
||||||
load_state (new_states: JSON_OBJECT)
|
load_state (new_states: JSON_OBJECT)
|
||||||
local
|
-- Select state stored with `control_name` as key
|
||||||
new_state: detachable JSON_VALUE
|
|
||||||
do
|
do
|
||||||
new_state := new_states.item (create {JSON_STRING}.make_json (control_name))
|
if attached {JSON_OBJECT} new_states.item (create {JSON_STRING}.make_json (control_name)) as new_state_obj then
|
||||||
if attached {JSON_OBJECT} new_state as new_state_obj then
|
|
||||||
set_state (new_state_obj)
|
set_state (new_state_obj)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
set_state (new_state: JSON_OBJECT)
|
||||||
|
-- Before we process the callback. We restore the state of control.
|
||||||
|
deferred
|
||||||
|
end
|
||||||
|
|
||||||
read_state (states: JSON_OBJECT)
|
read_state (states: JSON_OBJECT)
|
||||||
|
-- Add a new entry in the `states` JSON object with the `control_name` as key and the `state` as value
|
||||||
do
|
do
|
||||||
states.put (state, create {JSON_STRING}.make_json (control_name))
|
states.put (state, create {JSON_STRING}.make_json (control_name))
|
||||||
end
|
end
|
||||||
|
|
||||||
set_state (new_state: JSON_OBJECT)
|
|
||||||
deferred
|
|
||||||
end
|
|
||||||
|
|
||||||
state: JSON_OBJECT
|
state: JSON_OBJECT
|
||||||
|
-- Returns the current state of the Control as JSON. This state will be transfered to the client.
|
||||||
deferred
|
deferred
|
||||||
end
|
end
|
||||||
|
|
||||||
feature --EVENT HANDLING
|
feature --EVENT HANDLING
|
||||||
|
|
||||||
handle_callback (cname: STRING; event: STRING)
|
handle_callback (cname: STRING; event: STRING)
|
||||||
|
-- Method called if any callback recived. In this method you can route the callback to the event handler
|
||||||
deferred
|
deferred
|
||||||
end
|
end
|
||||||
|
|
||||||
feature
|
feature
|
||||||
|
|
||||||
render: STRING
|
render: STRING
|
||||||
|
-- Return html representaion of control
|
||||||
deferred
|
deferred
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,9 @@ feature {NONE}
|
|||||||
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
|
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
|
||||||
|
|
||||||
load_state (new_states: JSON_OBJECT)
|
load_state (new_states: JSON_OBJECT)
|
||||||
|
-- Pass new_states to subcontrols
|
||||||
do
|
do
|
||||||
|
Precursor(new_states)
|
||||||
across
|
across
|
||||||
controls as c
|
controls as c
|
||||||
loop
|
loop
|
||||||
@@ -44,8 +46,9 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
|
|||||||
end
|
end
|
||||||
|
|
||||||
read_state (states: JSON_OBJECT)
|
read_state (states: JSON_OBJECT)
|
||||||
|
-- Read states in subcontrols
|
||||||
do
|
do
|
||||||
states.put (state, create {JSON_STRING}.make_json (control_name))
|
Precursor(states)
|
||||||
across
|
across
|
||||||
controls as c
|
controls as c
|
||||||
loop
|
loop
|
||||||
@@ -54,20 +57,15 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
|
|||||||
end
|
end
|
||||||
|
|
||||||
state: JSON_OBJECT
|
state: JSON_OBJECT
|
||||||
local
|
--Read state
|
||||||
temp: JSON_OBJECT
|
|
||||||
do
|
do
|
||||||
create Result.make
|
create Result.make
|
||||||
across
|
|
||||||
controls as c
|
|
||||||
loop
|
|
||||||
temp := c.item.state
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
feature --EVENT HANDLING
|
feature --EVENT HANDLING
|
||||||
|
|
||||||
handle_callback (event: STRING; cname: STRING)
|
handle_callback (event: STRING; cname: STRING)
|
||||||
|
-- Pass callback to subcontrols
|
||||||
do
|
do
|
||||||
if equal (cname, control_name) then
|
if equal (cname, control_name) then
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -25,18 +25,22 @@ feature -- Access
|
|||||||
feature
|
feature
|
||||||
|
|
||||||
initialize_controls
|
initialize_controls
|
||||||
|
-- Initalize all the controls, all the event handles must be set in this function.
|
||||||
deferred
|
deferred
|
||||||
ensure
|
ensure
|
||||||
attached control
|
attached control
|
||||||
end
|
end
|
||||||
|
|
||||||
process
|
process
|
||||||
|
-- Function called on page load (not on callback)
|
||||||
deferred
|
deferred
|
||||||
end
|
end
|
||||||
|
|
||||||
feature
|
feature
|
||||||
|
|
||||||
execute
|
execute
|
||||||
|
-- Entry Point: If request is a callback, restore control states and execute handle then return new state json.
|
||||||
|
-- If request is not a callback. Run process and render the html page
|
||||||
local
|
local
|
||||||
event: detachable STRING
|
event: detachable STRING
|
||||||
control_name: detachable STRING
|
control_name: detachable STRING
|
||||||
@@ -64,6 +68,7 @@ feature
|
|||||||
end
|
end
|
||||||
|
|
||||||
render
|
render
|
||||||
|
-- Render and send the HTML Page
|
||||||
local
|
local
|
||||||
data: STRING
|
data: STRING
|
||||||
page: WSF_PAGE_RESPONSE
|
page: WSF_PAGE_RESPONSE
|
||||||
@@ -87,12 +92,13 @@ feature
|
|||||||
end
|
end
|
||||||
|
|
||||||
get_parameter (key: STRING): detachable STRING
|
get_parameter (key: STRING): detachable STRING
|
||||||
|
-- Read query parameter as string
|
||||||
local
|
local
|
||||||
value: detachable WSF_VALUE
|
value: detachable WSF_VALUE
|
||||||
do
|
do
|
||||||
Result := VOID
|
Result := VOID
|
||||||
value := request.query_parameter (key)
|
value := request.query_parameter (key)
|
||||||
if attached value then
|
if attached value and then value.is_string then
|
||||||
Result := value.as_string.value
|
Result := value.as_string.value
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ feature {NONE}
|
|||||||
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
|
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
|
||||||
|
|
||||||
set_state (new_state: JSON_OBJECT)
|
set_state (new_state: JSON_OBJECT)
|
||||||
|
-- Restore text from json
|
||||||
do
|
do
|
||||||
if attached {JSON_STRING} new_state.item (create {JSON_STRING}.make_json ("text")) as new_text then
|
if attached {JSON_STRING} new_state.item (create {JSON_STRING}.make_json ("text")) as new_text then
|
||||||
text := new_text.unescaped_string_32
|
text := new_text.unescaped_string_32
|
||||||
@@ -32,6 +33,7 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
|
|||||||
end
|
end
|
||||||
|
|
||||||
state: JSON_OBJECT
|
state: JSON_OBJECT
|
||||||
|
-- Return state which contains the current text and if there is an event handle attached
|
||||||
do
|
do
|
||||||
create Result.make
|
create Result.make
|
||||||
Result.put (create {JSON_STRING}.make_json (text), create {JSON_STRING}.make_json ("text"))
|
Result.put (create {JSON_STRING}.make_json (text), create {JSON_STRING}.make_json ("text"))
|
||||||
@@ -42,6 +44,7 @@ feature --EVENT HANDLING
|
|||||||
|
|
||||||
|
|
||||||
set_change_event (e: attached like change_event)
|
set_change_event (e: attached like change_event)
|
||||||
|
-- Set text change event handle
|
||||||
do
|
do
|
||||||
change_event := e
|
change_event := e
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user