Implement control isolation
This commit is contained in:
@@ -79,6 +79,7 @@ feature
|
|||||||
create source.make
|
create source.make
|
||||||
create progress.make_progress_with_source ("progress1", source)
|
create progress.make_progress_with_source ("progress1", source)
|
||||||
source.set_control (progress)
|
source.set_control (progress)
|
||||||
|
progress.set_isolation(true)
|
||||||
container.add_control (progress)
|
container.add_control (progress)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ class WSF_CONTROL
|
|||||||
constructor: (@parent_control, @$el, @control_name, @fullstate)->
|
constructor: (@parent_control, @$el, @control_name, @fullstate)->
|
||||||
@state = @fullstate.state
|
@state = @fullstate.state
|
||||||
@load_subcontrols()
|
@load_subcontrols()
|
||||||
|
@isolation = (""+@$el.data('isolation')=="1")
|
||||||
return
|
return
|
||||||
|
|
||||||
load_subcontrols: ()->
|
load_subcontrols: ()->
|
||||||
@@ -79,18 +80,6 @@ class WSF_CONTROL
|
|||||||
|
|
||||||
update: (state)->
|
update: (state)->
|
||||||
return
|
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)->
|
process_update: (new_states)->
|
||||||
if new_states[@control_name]?
|
if new_states[@control_name]?
|
||||||
@@ -100,12 +89,18 @@ class WSF_CONTROL
|
|||||||
control.process_update(new_states)
|
control.process_update(new_states)
|
||||||
|
|
||||||
get_context_state : ()->
|
get_context_state : ()->
|
||||||
if @parent_control?
|
if @parent_control? and not @isolation
|
||||||
return @parent_control.get_context_state()
|
return @parent_control.get_context_state()
|
||||||
return @get_full_state()
|
return @wrap(@control_name,@fullstate)
|
||||||
|
wrap : (cname,state)->
|
||||||
trigger_callback: (control_name,event,event_parameter)->
|
ctrs = {}
|
||||||
|
ctrs[cname] = state
|
||||||
|
state = {"controls":ctrs}
|
||||||
if @parent_control?
|
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)
|
return @parent_control.trigger_callback(control_name,event,event_parameter)
|
||||||
self = @
|
self = @
|
||||||
$.ajax
|
$.ajax
|
||||||
@@ -113,8 +108,9 @@ class WSF_CONTROL
|
|||||||
url: '?' + $.param
|
url: '?' + $.param
|
||||||
control_name: control_name
|
control_name: control_name
|
||||||
event: event
|
event: event
|
||||||
|
event_parameter: event_parameter
|
||||||
data:
|
data:
|
||||||
JSON.stringify(@get_full_state())
|
JSON.stringify(@get_context_state())
|
||||||
processData: false,
|
processData: false,
|
||||||
contentType: 'application/json',
|
contentType: 'application/json',
|
||||||
cache: no
|
cache: no
|
||||||
@@ -147,6 +143,8 @@ class WSF_PAGE_CONTROL extends WSF_CONTROL
|
|||||||
@$el = $('[data-name='+@state.id+']')
|
@$el = $('[data-name='+@state.id+']')
|
||||||
@control_name = @state.id
|
@control_name = @state.id
|
||||||
@load_subcontrols()
|
@load_subcontrols()
|
||||||
|
wrap : (cname,state)->
|
||||||
|
state
|
||||||
|
|
||||||
controls = {}
|
controls = {}
|
||||||
|
|
||||||
|
|||||||
@@ -121,6 +121,7 @@ WSF_CONTROL = (function() {
|
|||||||
this.fullstate = fullstate;
|
this.fullstate = fullstate;
|
||||||
this.state = this.fullstate.state;
|
this.state = this.fullstate.state;
|
||||||
this.load_subcontrols();
|
this.load_subcontrols();
|
||||||
|
this.isolation = "" + this.$el.data('isolation') === "1";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,30 +157,6 @@ WSF_CONTROL = (function() {
|
|||||||
|
|
||||||
WSF_CONTROL.prototype.update = function(state) {};
|
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) {
|
WSF_CONTROL.prototype.process_update = function(new_states) {
|
||||||
var control, _i, _len, _ref, _results;
|
var control, _i, _len, _ref, _results;
|
||||||
if (new_states[this.control_name] != null) {
|
if (new_states[this.control_name] != null) {
|
||||||
@@ -199,15 +176,28 @@ WSF_CONTROL = (function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
WSF_CONTROL.prototype.get_context_state = 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.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) {
|
WSF_CONTROL.prototype.trigger_callback = function(control_name, event, event_parameter) {
|
||||||
var self;
|
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);
|
return this.parent_control.trigger_callback(control_name, event, event_parameter);
|
||||||
}
|
}
|
||||||
self = this;
|
self = this;
|
||||||
@@ -215,9 +205,10 @@ WSF_CONTROL = (function() {
|
|||||||
type: 'POST',
|
type: 'POST',
|
||||||
url: '?' + $.param({
|
url: '?' + $.param({
|
||||||
control_name: control_name,
|
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,
|
processData: false,
|
||||||
contentType: 'application/json',
|
contentType: 'application/json',
|
||||||
cache: false
|
cache: false
|
||||||
@@ -270,6 +261,10 @@ WSF_PAGE_CONTROL = (function(_super) {
|
|||||||
this.load_subcontrols();
|
this.load_subcontrols();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WSF_PAGE_CONTROL.prototype.wrap = function(cname, state) {
|
||||||
|
return state;
|
||||||
|
};
|
||||||
|
|
||||||
return WSF_PAGE_CONTROL;
|
return WSF_PAGE_CONTROL;
|
||||||
|
|
||||||
})(WSF_CONTROL);
|
})(WSF_CONTROL);
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ inherit
|
|||||||
render_tag
|
render_tag
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
feature
|
feature
|
||||||
|
|
||||||
control_name: STRING
|
control_name: STRING
|
||||||
@@ -90,6 +91,9 @@ feature -- Rendering
|
|||||||
css_classes_string := css_classes_string + " " + c.item
|
css_classes_string := css_classes_string + " " + c.item
|
||||||
end
|
end
|
||||||
l_attributes := "id=%"" + control_name + "%" data-name=%"" + control_name + "%" data-type=%"" + a_generator + "%" " + attrs
|
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)
|
Result := render_tag_with_tagname (tag_name, body, l_attributes, css_classes_string)
|
||||||
end
|
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
|
-- Method called if any callback received. In this method you can route the callback to the event handler
|
||||||
deferred
|
deferred
|
||||||
end
|
end
|
||||||
|
feature -- Change
|
||||||
|
|
||||||
|
set_isolation (p: BOOLEAN)
|
||||||
|
do
|
||||||
|
isolate := true
|
||||||
|
end
|
||||||
|
|
||||||
|
feature -- Properties
|
||||||
|
|
||||||
|
isolate: BOOLEAN
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user