Only send changes back to client

This commit is contained in:
YNH Webdev
2013-08-29 18:31:57 +02:00
parent 275cc7aa21
commit bc6b4f90c3
8 changed files with 96 additions and 50 deletions

View File

@@ -24,10 +24,10 @@ feature
local
panel: WSF_MULTI_CONTROL
do
create textbox1.make ("txtBox1", "1")
create textbox2.make ("txtBox2", "2")
create button1.make ("sample_button1", "SUM")
create textbox_result.make ("txtBox3", "")
create textbox1.make_text ("txtBox1", "1")
create textbox2.make_text ("txtBox2", "2")
create button1.make_button ("sample_button1", "SUM")
create textbox_result.make_text ("txtBox3", "")
button1.set_click_event (agent handle_click)
create panel.make ("panel")
panel.add_control (textbox1)

View File

@@ -7,7 +7,6 @@ trigger_callback = (control_name,event)->
cache: no
.done (new_states)->
#Update all classes
window.states = new_states
for name,state of new_states
controls[name]?.update(state)
return
@@ -35,6 +34,8 @@ class WSF_BUTTON_CONTROL extends WSF_CONTROL
trigger_callback(@control_name, 'click')
update: (state) ->
if state.text?
window.states[@control_name]['text'] = state.text
@$el.text(state.text)
class WSF_TEXT_CONTROL extends WSF_CONTROL
@@ -49,6 +50,8 @@ class WSF_TEXT_CONTROL extends WSF_CONTROL
trigger_callback(@control_name, 'change')
update: (state) ->
if state.text?
window.states[@control_name]['text'] = state.text
@$el.val(state.text)
#map class name to effectiv class

View File

@@ -14,7 +14,6 @@
cache: false
}).done(function(new_states) {
var name, state, _ref;
window.states = new_states;
for (name in new_states) {
state = new_states[name];
if ((_ref = controls[name]) != null) {
@@ -66,7 +65,10 @@
};
WSF_BUTTON_CONTROL.prototype.update = function(state) {
if (state.text != null) {
window.states[this.control_name]['text'] = state.text;
return this.$el.text(state.text);
}
};
return WSF_BUTTON_CONTROL;
@@ -97,7 +99,10 @@
};
WSF_TEXT_CONTROL.prototype.update = function(state) {
if (state.text != null) {
window.states[this.control_name]['text'] = state.text;
return this.$el.val(state.text);
}
};
return WSF_TEXT_CONTROL;

View File

@@ -12,13 +12,13 @@ inherit
WSF_CONTROL
create
make
make_button
feature {NONE}
make (n: STRING; v: STRING)
make_button (n: STRING; v: STRING)
do
control_name := n
make (n)
text := v
end
@@ -64,7 +64,10 @@ feature
set_text (t: STRING)
do
if not t.is_equal (text) then
text := t
state_changes.replace (create {JSON_STRING}.make_json (text), create {JSON_STRING}.make_json ("text"))
end
end
feature

View File

@@ -11,6 +11,16 @@ feature
control_name: STRING
feature {NONE}
make (n: STRING)
do
control_name := n
create state_changes.make
ensure
attached state_changes
end
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
load_state (new_states: JSON_OBJECT)
@@ -32,11 +42,21 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
states.put (state, create {JSON_STRING}.make_json (control_name))
end
read_state_changes (states: JSON_OBJECT)
-- Add a new entry in the `states_changes` JSON object with the `control_name` as key and the `state` as value
do
if state_changes.count > 0 then
states.put (state_changes, create {JSON_STRING}.make_json (control_name))
end
end
state: JSON_OBJECT
-- Returns the current state of the Control as JSON. This state will be transfered to the client.
deferred
end
state_changes: JSON_OBJECT
feature --EVENT HANDLING
handle_callback (cname: STRING; event: STRING)

View File

@@ -11,7 +11,9 @@ inherit
WSF_CONTROL
redefine
make,
read_state,
read_state_changes,
load_state
end
@@ -24,7 +26,7 @@ feature {NONE}
make (n: STRING)
do
control_name := n
Precursor (n)
controls := create {LINKED_LIST [WSF_CONTROL]}.make;
end
@@ -56,6 +58,17 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
end
end
read_state_changes (states: JSON_OBJECT)
-- Read states_changes in subcontrols
do
Precursor (states)
across
controls as c
loop
c.item.read_state_changes (states)
end
end
state: JSON_OBJECT
--Read state
do

View File

@@ -45,7 +45,7 @@ feature
event: detachable STRING
control_name: detachable STRING
states: detachable STRING
new_states: JSON_OBJECT
states_changes: JSON_OBJECT
json_parser: JSON_PARSER
do
control_name := get_parameter ("control_name")
@@ -57,10 +57,10 @@ feature
control.load_state (sp)
end
control.handle_callback (control_name, event)
create new_states.make
control.read_state (new_states)
create states_changes.make
control.read_state_changes (states_changes)
response.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-Type", "application/json"]>>)
response.put_string (new_states.representation)
response.put_string (states_changes.representation)
else
process
render

View File

@@ -12,13 +12,13 @@ inherit
WSF_CONTROL
create
make
make_text
feature {NONE}
make (n: STRING; v: STRING)
make_text (n: STRING; v: STRING)
do
control_name := n
make (n)
text := v
end
@@ -42,7 +42,6 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
feature --EVENT HANDLING
set_change_event (e: attached like change_event)
-- Set text change event handle
do
@@ -67,7 +66,10 @@ feature
set_text (t: STRING)
do
if not t.is_equal (text) then
text := t
state_changes.replace (create {JSON_STRING}.make_json (text), create {JSON_STRING}.make_json ("text"))
end
end
feature