Add comments

Use Precursor
This commit is contained in:
YNH Webdev
2013-08-28 22:59:24 +02:00
parent e186475a81
commit 275cc7aa21
5 changed files with 30 additions and 17 deletions

View File

@@ -25,6 +25,7 @@ feature {NONE}
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
set_state (new_state: JSON_OBJECT)
-- Restore text from json
do
if attached {JSON_STRING} new_state.item (create {JSON_STRING}.make_json ("text")) as new_text then
text := new_text.unescaped_string_32
@@ -32,6 +33,7 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
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_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
set_click_event (e: attached like click_event)
-- Set button click event handle
do
click_event := e
end

View File

@@ -14,37 +14,40 @@ feature
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
load_state (new_states: JSON_OBJECT)
local
new_state: detachable JSON_VALUE
-- Select state stored with `control_name` as key
do
new_state := new_states.item (create {JSON_STRING}.make_json (control_name))
if attached {JSON_OBJECT} new_state as new_state_obj then
if attached {JSON_OBJECT} new_states.item (create {JSON_STRING}.make_json (control_name)) as new_state_obj then
set_state (new_state_obj)
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)
-- Add a new entry in the `states` JSON object with the `control_name` as key and the `state` as value
do
states.put (state, create {JSON_STRING}.make_json (control_name))
end
set_state (new_state: JSON_OBJECT)
deferred
end
state: JSON_OBJECT
-- Returns the current state of the Control as JSON. This state will be transfered to the client.
deferred
end
feature --EVENT HANDLING
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
end
feature
render: STRING
-- Return html representaion of control
deferred
end

View File

@@ -31,7 +31,9 @@ feature {NONE}
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
load_state (new_states: JSON_OBJECT)
-- Pass new_states to subcontrols
do
Precursor(new_states)
across
controls as c
loop
@@ -44,8 +46,9 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
end
read_state (states: JSON_OBJECT)
-- Read states in subcontrols
do
states.put (state, create {JSON_STRING}.make_json (control_name))
Precursor(states)
across
controls as c
loop
@@ -54,20 +57,15 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
end
state: JSON_OBJECT
local
temp: JSON_OBJECT
--Read state
do
create Result.make
across
controls as c
loop
temp := c.item.state
end
end
feature --EVENT HANDLING
handle_callback (event: STRING; cname: STRING)
-- Pass callback to subcontrols
do
if equal (cname, control_name) then
else

View File

@@ -25,18 +25,22 @@ feature -- Access
feature
initialize_controls
-- Initalize all the controls, all the event handles must be set in this function.
deferred
ensure
attached control
end
process
-- Function called on page load (not on callback)
deferred
end
feature
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
event: detachable STRING
control_name: detachable STRING
@@ -64,6 +68,7 @@ feature
end
render
-- Render and send the HTML Page
local
data: STRING
page: WSF_PAGE_RESPONSE
@@ -87,12 +92,13 @@ feature
end
get_parameter (key: STRING): detachable STRING
-- Read query parameter as string
local
value: detachable WSF_VALUE
do
Result := VOID
value := request.query_parameter (key)
if attached value then
if attached value and then value.is_string then
Result := value.as_string.value
end
end

View File

@@ -25,6 +25,7 @@ feature {NONE}
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
set_state (new_state: JSON_OBJECT)
-- Restore text from json
do
if attached {JSON_STRING} new_state.item (create {JSON_STRING}.make_json ("text")) as new_text then
text := new_text.unescaped_string_32
@@ -32,6 +33,7 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
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_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 text change event handle
do
change_event := e
end