From b72e6871e8627885f1cac8aeb585909324d48ece Mon Sep 17 00:00:00 2001 From: YNH Webdev Date: Wed, 28 Aug 2013 11:04:54 +0200 Subject: [PATCH] Fix multi control Use multi control in example --- examples/widgetapp/sample_page.e | 29 +++++++++++++------ examples/widgetapp/widget.coffee | 9 +++--- examples/widgetapp/widget.js | 16 ++++++---- .../wsf_html/webcontrol/wsf_multi_control.e | 24 +++++++++++++-- 4 files changed, 56 insertions(+), 22 deletions(-) diff --git a/examples/widgetapp/sample_page.e b/examples/widgetapp/sample_page.e index 9a289db1..bfa702bc 100644 --- a/examples/widgetapp/sample_page.e +++ b/examples/widgetapp/sample_page.e @@ -21,22 +21,33 @@ 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) - do - if attached {SAMPLE_PAGE} context as sp then - sp.button.set_text("Hello World! (Ueeee)") + handle_click (context: WSF_PAGE_CONTROL) + do + if attached {SAMPLE_PAGE} context as sp then + sp.button1.set_text ("Hello World! (Ueeee)") + sp.button2.set_text ("Hi btn2") + end end - end process do end - button: WSF_BUTTON_CONTROL + button1: WSF_BUTTON_CONTROL + + button2: WSF_BUTTON_CONTROL + end diff --git a/examples/widgetapp/widget.coffee b/examples/widgetapp/widget.coffee index cee6c3cc..49800aa5 100644 --- a/examples/widgetapp/widget.coffee +++ b/examples/widgetapp/widget.coffee @@ -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 - controls[name]=new typemap[type](name,$el) + if type? and typemap[type]? + controls[name]=new typemap[type](name,$el) diff --git a/examples/widgetapp/widget.js b/examples/widgetapp/widget.js index 55f30910..0f025652 100644 --- a/examples/widgetapp/widget.js +++ b/examples/widgetapp/widget.js @@ -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'); - controls[name] = new typemap[type](name, $el); + if ((type != null) && (typemap[type] != null)) { + controls[name] = new typemap[type](name, $el); + } } }).call(this); diff --git a/library/server/wsf_html/webcontrol/wsf_multi_control.e b/library/server/wsf_html/webcontrol/wsf_multi_control.e index 00a14fa9..8ff1889c 100644 --- a/library/server/wsf_html/webcontrol/wsf_multi_control.e +++ b/library/server/wsf_html/webcontrol/wsf_multi_control.e @@ -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