diff --git a/examples/widgetapp/sample_page.e b/examples/widgetapp/sample_page.e index b35000c2..15b00173 100644 --- a/examples/widgetapp/sample_page.e +++ b/examples/widgetapp/sample_page.e @@ -79,6 +79,7 @@ feature create source.make create progress.make_progress_with_source ("progress1", source) source.set_control (progress) + progress.set_isolation(true) container.add_control (progress) end diff --git a/examples/widgetapp/widget.coffee b/examples/widgetapp/widget.coffee index db600614..3c0fbc97 100644 --- a/examples/widgetapp/widget.coffee +++ b/examples/widgetapp/widget.coffee @@ -61,6 +61,7 @@ class WSF_CONTROL constructor: (@parent_control, @$el, @control_name, @fullstate)-> @state = @fullstate.state @load_subcontrols() + @isolation = (""+@$el.data('isolation')=="1") return load_subcontrols: ()-> @@ -79,19 +80,7 @@ class WSF_CONTROL update: (state)-> return - get_state: ()-> - @state - - get_control_states:()-> - result = {} - for control in @controls - if control? - result[control.control_name]=control.get_full_state() - result - - get_full_state: ()-> - {"state":@get_state(),"controls":@get_control_states()} - + process_update: (new_states)-> if new_states[@control_name]? @update(new_states[@control_name]) @@ -100,12 +89,18 @@ class WSF_CONTROL control.process_update(new_states) get_context_state : ()-> - if @parent_control? + if @parent_control? and not @isolation return @parent_control.get_context_state() - return @get_full_state() - - trigger_callback: (control_name,event,event_parameter)-> + return @wrap(@control_name,@fullstate) + wrap : (cname,state)-> + ctrs = {} + ctrs[cname] = state + state = {"controls":ctrs} if @parent_control? + return @parent_control.wrap(@parent_control.control_name,state) + return state + trigger_callback: (control_name,event,event_parameter)-> + if @parent_control? and not @isolation return @parent_control.trigger_callback(control_name,event,event_parameter) self = @ $.ajax @@ -113,8 +108,9 @@ class WSF_CONTROL url: '?' + $.param control_name: control_name event: event + event_parameter: event_parameter data: - JSON.stringify(@get_full_state()) + JSON.stringify(@get_context_state()) processData: false, contentType: 'application/json', cache: no @@ -147,6 +143,8 @@ class WSF_PAGE_CONTROL extends WSF_CONTROL @$el = $('[data-name='+@state.id+']') @control_name = @state.id @load_subcontrols() + wrap : (cname,state)-> + state controls = {} diff --git a/examples/widgetapp/widget.js b/examples/widgetapp/widget.js index 6e0b4922..f54c6a1d 100644 --- a/examples/widgetapp/widget.js +++ b/examples/widgetapp/widget.js @@ -121,6 +121,7 @@ WSF_CONTROL = (function() { this.fullstate = fullstate; this.state = this.fullstate.state; this.load_subcontrols(); + this.isolation = "" + this.$el.data('isolation') === "1"; return; } @@ -156,30 +157,6 @@ WSF_CONTROL = (function() { WSF_CONTROL.prototype.update = function(state) {}; - WSF_CONTROL.prototype.get_state = function() { - return this.state; - }; - - WSF_CONTROL.prototype.get_control_states = function() { - var control, result, _i, _len, _ref; - result = {}; - _ref = this.controls; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - control = _ref[_i]; - if (control != null) { - result[control.control_name] = control.get_full_state(); - } - } - return result; - }; - - WSF_CONTROL.prototype.get_full_state = function() { - return { - "state": this.get_state(), - "controls": this.get_control_states() - }; - }; - WSF_CONTROL.prototype.process_update = function(new_states) { var control, _i, _len, _ref, _results; if (new_states[this.control_name] != null) { @@ -199,15 +176,28 @@ WSF_CONTROL = (function() { }; WSF_CONTROL.prototype.get_context_state = function() { - if (this.parent_control != null) { + if ((this.parent_control != null) && !this.isolation) { return this.parent_control.get_context_state(); } - return this.get_full_state(); + return this.wrap(this.control_name, this.fullstate); + }; + + WSF_CONTROL.prototype.wrap = function(cname, state) { + var ctrs; + ctrs = {}; + ctrs[cname] = state; + state = { + "controls": ctrs + }; + if (this.parent_control != null) { + return this.parent_control.wrap(this.parent_control.control_name, state); + } + return state; }; WSF_CONTROL.prototype.trigger_callback = function(control_name, event, event_parameter) { var self; - if (this.parent_control != null) { + if ((this.parent_control != null) && !this.isolation) { return this.parent_control.trigger_callback(control_name, event, event_parameter); } self = this; @@ -215,9 +205,10 @@ WSF_CONTROL = (function() { type: 'POST', url: '?' + $.param({ control_name: control_name, - event: event + event: event, + event_parameter: event_parameter }), - data: JSON.stringify(this.get_full_state()), + data: JSON.stringify(this.get_context_state()), processData: false, contentType: 'application/json', cache: false @@ -270,6 +261,10 @@ WSF_PAGE_CONTROL = (function(_super) { this.load_subcontrols(); } + WSF_PAGE_CONTROL.prototype.wrap = function(cname, state) { + return state; + }; + return WSF_PAGE_CONTROL; })(WSF_CONTROL); diff --git a/library/server/wsf_js_widget/webcontrol/wsf_control.e b/library/server/wsf_js_widget/webcontrol/wsf_control.e index 71184040..f8eb8dbe 100644 --- a/library/server/wsf_js_widget/webcontrol/wsf_control.e +++ b/library/server/wsf_js_widget/webcontrol/wsf_control.e @@ -14,6 +14,7 @@ inherit render_tag end + feature control_name: STRING @@ -90,6 +91,9 @@ feature -- Rendering css_classes_string := css_classes_string + " " + c.item end l_attributes := "id=%"" + control_name + "%" data-name=%"" + control_name + "%" data-type=%"" + a_generator + "%" " + attrs + if isolate then + l_attributes.append (" data-isolation=%"1%"") + end Result := render_tag_with_tagname (tag_name, body, l_attributes, css_classes_string) end @@ -99,5 +103,15 @@ feature -- EVENT HANDLING -- Method called if any callback received. In this method you can route the callback to the event handler deferred end +feature -- Change + + set_isolation (p: BOOLEAN) + do + isolate := true + end + +feature -- Properties + + isolate: BOOLEAN end