Fix multi control
Use multi control in example
This commit is contained in:
@@ -21,16 +21,24 @@ create
|
||||
feature
|
||||
|
||||
initialize_controls
|
||||
local
|
||||
panel: WSF_MULTI_CONTROL
|
||||
do
|
||||
button := create {WSF_BUTTON_CONTROL}.make ("sample_button", "I'm a button")
|
||||
button.set_click_event(agent handle_click)
|
||||
control := button
|
||||
button1 := create {WSF_BUTTON_CONTROL}.make ("sample_button1", "I'm a button")
|
||||
button1.set_click_event (agent handle_click)
|
||||
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
|
||||
|
||||
handle_click(context: WSF_PAGE_CONTROL)
|
||||
handle_click (context: WSF_PAGE_CONTROL)
|
||||
do
|
||||
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
|
||||
|
||||
@@ -38,5 +46,8 @@ feature
|
||||
do
|
||||
end
|
||||
|
||||
button: WSF_BUTTON_CONTROL
|
||||
button1: WSF_BUTTON_CONTROL
|
||||
|
||||
button2: WSF_BUTTON_CONTROL
|
||||
|
||||
end
|
||||
|
||||
@@ -5,10 +5,10 @@ trigger_callback = (control_name,event)->
|
||||
event: event
|
||||
cache: no
|
||||
.done (new_states)->
|
||||
states = new_states
|
||||
#Update all classes
|
||||
for name,state of states
|
||||
controls[name].update(state)
|
||||
for name,state of new_states
|
||||
controls[name]?.update(state)
|
||||
states = new_states
|
||||
return
|
||||
|
||||
class WSF_CONTROL
|
||||
@@ -46,5 +46,6 @@ for name,state of states
|
||||
#get control type
|
||||
type = $el.data('type')
|
||||
#create class
|
||||
if type? and typemap[type]?
|
||||
controls[name]=new typemap[type](name,$el)
|
||||
|
||||
|
||||
@@ -12,12 +12,14 @@
|
||||
},
|
||||
cache: false
|
||||
}).done(function(new_states) {
|
||||
var name, state, states;
|
||||
states = new_states;
|
||||
for (name in states) {
|
||||
state = states[name];
|
||||
controls[name].update(state);
|
||||
var name, state, states, _ref;
|
||||
for (name in new_states) {
|
||||
state = new_states[name];
|
||||
if ((_ref = controls[name]) != null) {
|
||||
_ref.update(state);
|
||||
}
|
||||
}
|
||||
states = new_states;
|
||||
});
|
||||
};
|
||||
|
||||
@@ -76,7 +78,9 @@
|
||||
state = states[name];
|
||||
$el = $('[data-name=' + name + ']');
|
||||
type = $el.data('type');
|
||||
if ((type != null) && (typemap[type] != null)) {
|
||||
controls[name] = new typemap[type](name, $el);
|
||||
}
|
||||
}
|
||||
|
||||
}).call(this);
|
||||
|
||||
@@ -10,13 +10,16 @@ class
|
||||
inherit
|
||||
|
||||
WSF_CONTROL
|
||||
redefine
|
||||
read_state
|
||||
end
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE}
|
||||
|
||||
controls: LIST [WSF_CONTROL]
|
||||
controls: LINKED_LIST [WSF_CONTROL]
|
||||
|
||||
make (n: STRING)
|
||||
do
|
||||
@@ -24,15 +27,21 @@ feature {NONE}
|
||||
controls := create {LINKED_LIST [WSF_CONTROL]}.make;
|
||||
end
|
||||
|
||||
feature
|
||||
|
||||
add_control (c: WSF_CONTROL)
|
||||
do
|
||||
controls.put_front (c)
|
||||
end
|
||||
|
||||
handle_callback (event: STRING; cname: STRING; page: WSF_PAGE_CONTROL)
|
||||
do
|
||||
if equal (cname, control_name) then
|
||||
|
||||
else
|
||||
across
|
||||
controls as c
|
||||
loop
|
||||
c.item.handle_callback(event, cname, page)
|
||||
c.item.handle_callback (event, cname, page)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -59,4 +68,13 @@ feature {NONE}
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user