Implement control isolation

This commit is contained in:
YNH Webdev
2013-09-22 19:11:07 +02:00
parent 3a9ede6e8c
commit b33de9985f
4 changed files with 55 additions and 47 deletions

View File

@@ -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

View File

@@ -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 = {}

View File

@@ -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);