Fix multi control

Use multi control in example
This commit is contained in:
YNH Webdev
2013-08-28 11:04:54 +02:00
parent f14ea29636
commit b72e6871e8
4 changed files with 56 additions and 22 deletions

View File

@@ -21,16 +21,24 @@ create
feature feature
initialize_controls initialize_controls
local
panel: WSF_MULTI_CONTROL
do do
button := create {WSF_BUTTON_CONTROL}.make ("sample_button", "I'm a button") button1 := create {WSF_BUTTON_CONTROL}.make ("sample_button1", "I'm a button")
button.set_click_event(agent handle_click) button1.set_click_event (agent handle_click)
control := button button2 := create {WSF_BUTTON_CONTROL}.make ("sample_button2", "I'm a button2")
button2.set_click_event (agent handle_click)
create panel.make ("panel")
panel.add_control (button1)
panel.add_control (button2)
control := panel
end end
handle_click (context: WSF_PAGE_CONTROL) handle_click (context: WSF_PAGE_CONTROL)
do do
if attached {SAMPLE_PAGE} context as sp then if attached {SAMPLE_PAGE} context as sp then
sp.button.set_text("Hello World! (Ueeee)") sp.button1.set_text ("Hello World! (Ueeee)")
sp.button2.set_text ("Hi btn2")
end end
end end
@@ -38,5 +46,8 @@ feature
do do
end end
button: WSF_BUTTON_CONTROL button1: WSF_BUTTON_CONTROL
button2: WSF_BUTTON_CONTROL
end end

View File

@@ -5,10 +5,10 @@ trigger_callback = (control_name,event)->
event: event event: event
cache: no cache: no
.done (new_states)-> .done (new_states)->
states = new_states
#Update all classes #Update all classes
for name,state of states for name,state of new_states
controls[name].update(state) controls[name]?.update(state)
states = new_states
return return
class WSF_CONTROL class WSF_CONTROL
@@ -46,5 +46,6 @@ for name,state of states
#get control type #get control type
type = $el.data('type') type = $el.data('type')
#create class #create class
if type? and typemap[type]?
controls[name]=new typemap[type](name,$el) controls[name]=new typemap[type](name,$el)

View File

@@ -12,12 +12,14 @@
}, },
cache: false cache: false
}).done(function(new_states) { }).done(function(new_states) {
var name, state, states; var name, state, states, _ref;
states = new_states; for (name in new_states) {
for (name in states) { state = new_states[name];
state = states[name]; if ((_ref = controls[name]) != null) {
controls[name].update(state); _ref.update(state);
} }
}
states = new_states;
}); });
}; };
@@ -76,7 +78,9 @@
state = states[name]; state = states[name];
$el = $('[data-name=' + name + ']'); $el = $('[data-name=' + name + ']');
type = $el.data('type'); type = $el.data('type');
if ((type != null) && (typemap[type] != null)) {
controls[name] = new typemap[type](name, $el); controls[name] = new typemap[type](name, $el);
} }
}
}).call(this); }).call(this);

View File

@@ -10,13 +10,16 @@ class
inherit inherit
WSF_CONTROL WSF_CONTROL
redefine
read_state
end
create create
make make
feature {NONE} feature {NONE}
controls: LIST [WSF_CONTROL] controls: LINKED_LIST [WSF_CONTROL]
make (n: STRING) make (n: STRING)
do do
@@ -24,10 +27,16 @@ feature {NONE}
controls := create {LINKED_LIST [WSF_CONTROL]}.make; controls := create {LINKED_LIST [WSF_CONTROL]}.make;
end end
feature
add_control (c: WSF_CONTROL)
do
controls.put_front (c)
end
handle_callback (event: STRING; cname: STRING; page: WSF_PAGE_CONTROL) handle_callback (event: STRING; cname: STRING; page: WSF_PAGE_CONTROL)
do do
if equal (cname, control_name) then if equal (cname, control_name) then
else else
across across
controls as c controls as c
@@ -59,4 +68,13 @@ feature {NONE}
end end
end end
read_state (states: JSON_OBJECT)
do
states.put (state, create {JSON_STRING}.make_json (control_name))
across
controls as c
loop
c.item.read_state(states)
end
end
end end