Set url within page class
This commit is contained in:
@@ -1,5 +1,18 @@
|
|||||||
#IMPORTANT PLEASE COMPILE WITH:: coffee -cbw widget.coffee
|
#IMPORTANT PLEASE COMPILE WITH:: coffee -cbw widget.coffee
|
||||||
cache = {}
|
cache = {}
|
||||||
|
jQuery.unparam = (value) ->
|
||||||
|
params = {}
|
||||||
|
pieces = value.split("&")
|
||||||
|
pair = undefined
|
||||||
|
i = undefined
|
||||||
|
l = undefined
|
||||||
|
i = 0
|
||||||
|
l = pieces.length
|
||||||
|
while i < l
|
||||||
|
pair = pieces[i].split("=", 2)
|
||||||
|
params[decodeURIComponent(pair[0])] = ((if pair.length is 2 then decodeURIComponent(pair[1].replace(/\+/g, " ")) else true))
|
||||||
|
i++
|
||||||
|
params
|
||||||
template = tmpl = (str, data) ->
|
template = tmpl = (str, data) ->
|
||||||
# Simple JavaScript Templating
|
# Simple JavaScript Templating
|
||||||
# John Resig - http://ejohn.org/ - MIT Licensed
|
# John Resig - http://ejohn.org/ - MIT Licensed
|
||||||
@@ -99,13 +112,20 @@ class WSF_CONTROL
|
|||||||
if @parent_control?
|
if @parent_control?
|
||||||
return @parent_control.wrap(@parent_control.control_name,state)
|
return @parent_control.wrap(@parent_control.control_name,state)
|
||||||
return state
|
return state
|
||||||
|
|
||||||
|
callback_url: (params)->
|
||||||
|
if @parent_control?
|
||||||
|
return @parent_control.callback_url(params)
|
||||||
|
$.extend params, @url_params
|
||||||
|
@url + '?' + $.param(params)
|
||||||
|
|
||||||
trigger_callback: (control_name,event,event_parameter)->
|
trigger_callback: (control_name,event,event_parameter)->
|
||||||
if @parent_control? and not @isolation
|
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
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
url: '?' + $.param
|
url: @callback_url
|
||||||
control_name: control_name
|
control_name: control_name
|
||||||
event: event
|
event: event
|
||||||
event_parameter: event_parameter
|
event_parameter: event_parameter
|
||||||
@@ -142,7 +162,10 @@ class WSF_PAGE_CONTROL extends WSF_CONTROL
|
|||||||
@parent_control=null
|
@parent_control=null
|
||||||
@$el = $('[data-name='+@state.id+']')
|
@$el = $('[data-name='+@state.id+']')
|
||||||
@control_name = @state.id
|
@control_name = @state.id
|
||||||
|
@url = @state['url']
|
||||||
|
@url_params = jQuery.unparam(@state['url_params'])
|
||||||
@load_subcontrols()
|
@load_subcontrols()
|
||||||
|
|
||||||
wrap : (cname,state)->
|
wrap : (cname,state)->
|
||||||
state
|
state
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,23 @@ var Mini, WSF_AUTOCOMPLETE_CONTROL, WSF_BUTTON_CONTROL, WSF_CHECKBOX_CONTROL, WS
|
|||||||
|
|
||||||
cache = {};
|
cache = {};
|
||||||
|
|
||||||
|
jQuery.unparam = function(value) {
|
||||||
|
var i, l, pair, params, pieces;
|
||||||
|
params = {};
|
||||||
|
pieces = value.split("&");
|
||||||
|
pair = void 0;
|
||||||
|
i = void 0;
|
||||||
|
l = void 0;
|
||||||
|
i = 0;
|
||||||
|
l = pieces.length;
|
||||||
|
while (i < l) {
|
||||||
|
pair = pieces[i].split("=", 2);
|
||||||
|
params[decodeURIComponent(pair[0])] = (pair.length === 2 ? decodeURIComponent(pair[1].replace(/\+/g, " ")) : true);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return params;
|
||||||
|
};
|
||||||
|
|
||||||
template = tmpl = function(str, data) {
|
template = tmpl = function(str, data) {
|
||||||
var fn;
|
var fn;
|
||||||
fn = (!/\W/.test(str) ? cache[str] = cache[str] || tmpl(str) : new Function("obj", "var p=[],print=function(){p.push.apply(p,arguments);};" + "with(obj){p.push('" + str.replace(/[\r\t\n]/g, " ").split("{{").join("\t").replace(/((^|}})[^\t]*)'/g, "$1\r").replace(/\t=(.*?)}}/g, "',$1,'").split("\t").join("');").split("}}").join("p.push('").split("\r").join("\\'") + "');}return p.join('');"));
|
fn = (!/\W/.test(str) ? cache[str] = cache[str] || tmpl(str) : new Function("obj", "var p=[],print=function(){p.push.apply(p,arguments);};" + "with(obj){p.push('" + str.replace(/[\r\t\n]/g, " ").split("{{").join("\t").replace(/((^|}})[^\t]*)'/g, "$1\r").replace(/\t=(.*?)}}/g, "',$1,'").split("\t").join("');").split("}}").join("p.push('").split("\r").join("\\'") + "');}return p.join('');"));
|
||||||
@@ -195,6 +212,14 @@ WSF_CONTROL = (function() {
|
|||||||
return state;
|
return state;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
WSF_CONTROL.prototype.callback_url = function(params) {
|
||||||
|
if (this.parent_control != null) {
|
||||||
|
return this.parent_control.callback_url(params);
|
||||||
|
}
|
||||||
|
$.extend(params, this.url_params);
|
||||||
|
return this.url + '?' + $.param(params);
|
||||||
|
};
|
||||||
|
|
||||||
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) && !this.isolation) {
|
if ((this.parent_control != null) && !this.isolation) {
|
||||||
@@ -203,7 +228,7 @@ WSF_CONTROL = (function() {
|
|||||||
self = this;
|
self = this;
|
||||||
return $.ajax({
|
return $.ajax({
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
url: '?' + $.param({
|
url: this.callback_url({
|
||||||
control_name: control_name,
|
control_name: control_name,
|
||||||
event: event,
|
event: event,
|
||||||
event_parameter: event_parameter
|
event_parameter: event_parameter
|
||||||
@@ -258,6 +283,8 @@ WSF_PAGE_CONTROL = (function(_super) {
|
|||||||
this.parent_control = null;
|
this.parent_control = null;
|
||||||
this.$el = $('[data-name=' + this.state.id + ']');
|
this.$el = $('[data-name=' + this.state.id + ']');
|
||||||
this.control_name = this.state.id;
|
this.control_name = this.state.id;
|
||||||
|
this.url = this.state['url'];
|
||||||
|
this.url_params = jQuery.unparam(this.state['url_params']);
|
||||||
this.load_subcontrols();
|
this.load_subcontrols();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -109,6 +109,8 @@ feature -- Implementation
|
|||||||
do
|
do
|
||||||
create Result.make
|
create Result.make
|
||||||
Result.put (create {JSON_STRING}.make_json (control_name), "id")
|
Result.put (create {JSON_STRING}.make_json (control_name), "id")
|
||||||
|
Result.put (create {JSON_STRING}.make_json (request.path_info), "url")
|
||||||
|
Result.put (create {JSON_STRING}.make_json (request.query_string), "url_params")
|
||||||
end
|
end
|
||||||
|
|
||||||
full_state: JSON_OBJECT
|
full_state: JSON_OBJECT
|
||||||
|
|||||||
Reference in New Issue
Block a user