Commit a9e59723 authored by Romain Courteaud's avatar Romain Courteaud

Add first version of aq_dynamic.

parent c335849c
This diff is collapsed.
This diff is collapsed.
...@@ -740,6 +740,24 @@ ...@@ -740,6 +740,24 @@
throw new Error("No element defined"); throw new Error("No element defined");
} }
return this.element; return this.element;
})
.declareMethod('acquire', function () {
var gadget = this,
argument_list = arguments;
return new RSVP.Queue()
.push(function () {
var aq_dynamic = gadget.aq_dynamic;
if (aq_dynamic !== undefined) {
return aq_dynamic.apply(gadget, argument_list);
}
throw new renderJS.AcquisitionError("aq_dynamic is not defined");
})
.push(undefined, function (error) {
if (error instanceof renderJS.AcquisitionError) {
return gadget.aq_parent.apply(gadget, argument_list);
}
throw error;
});
}); });
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
...@@ -909,6 +927,16 @@ ...@@ -909,6 +927,16 @@
gadget_instance.chan.bind("trigger", function (trans, params) { gadget_instance.chan.bind("trigger", function (trans, params) {
return gadget_instance.trigger(params.event_name, params.options); return gadget_instance.trigger(params.event_name, params.options);
}); });
gadget_instance.chan.bind("acquire", function (trans, params) {
gadget_instance.acquire.apply(gadget_instance, params)
.then(function (g) {
trans.complete(g);
}).fail(function (e) {
trans.error(e.toString());
});
trans.delayReturn(true);
});
return RSVP.any([ return RSVP.any([
iframe_loading_deferred.promise, iframe_loading_deferred.promise,
// Timeout to prevent non renderJS embeddable gadget // Timeout to prevent non renderJS embeddable gadget
...@@ -922,6 +950,7 @@ ...@@ -922,6 +950,7 @@
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
RenderJSGadget.prototype.declareGadget = function (url, options) { RenderJSGadget.prototype.declareGadget = function (url, options) {
var queue, var queue,
parent_gadget = this,
previous_loading_gadget_promise = loading_gadget_promise; previous_loading_gadget_promise = loading_gadget_promise;
if (options === undefined) { if (options === undefined) {
...@@ -956,6 +985,10 @@ ...@@ -956,6 +985,10 @@
// Set the HTML context // Set the HTML context
.push(function (gadget_instance) { .push(function (gadget_instance) {
var i; var i;
// Define aq_parent to reach parent gadget
gadget_instance.aq_parent = function (method_name, argument_list) {
return parent_gadget.acquire(method_name, argument_list);
};
// Drop the current loading klass info used by selector // Drop the current loading klass info used by selector
gadget_loading_klass = undefined; gadget_loading_klass = undefined;
// Trigger calling of all ready callback // Trigger calling of all ready callback
...@@ -997,6 +1030,20 @@ ...@@ -997,6 +1030,20 @@
return result; return result;
}; };
/////////////////////////////////////////////////////////////////
// renderJS.AcquisitionError
/////////////////////////////////////////////////////////////////
renderJS.AcquisitionError = function (message) {
this.name = "AcquisitionError";
if ((message !== undefined) && (typeof message !== "string")) {
throw new TypeError('You must pass a string.');
}
this.message = message || "Acquisition failed";
};
renderJS.AcquisitionError.prototype = new Error();
renderJS.AcquisitionError.prototype.constructor =
renderJS.AcquisitionError;
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// renderJS.declareJS // renderJS.declareJS
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
...@@ -1238,6 +1285,14 @@ ...@@ -1238,6 +1285,14 @@
// Create the root gadget instance and put it in the loading stack // Create the root gadget instance and put it in the loading stack
root_gadget = new gadget_model_dict[url](); root_gadget = new gadget_model_dict[url]();
// Stop acquisition on the original root gadget
// Do not put this on the klass, as their could be multiple instances
root_gadget.aq_parent = function (method_name) {
throw new renderJS.AcquisitionError(
"No gadget provides " + method_name
);
};
} else { } else {
// Create the communication channel // Create the communication channel
embedded_channel = Channel.build({ embedded_channel = Channel.build({
...@@ -1317,6 +1372,26 @@ ...@@ -1317,6 +1372,26 @@
notifyTrigger(eventName, options); notifyTrigger(eventName, options);
return result; return result;
}; };
// Define aq_parent to inform parent window
tmp_constructor.prototype.aq_parent = function (method_name,
argument_list) {
return new RSVP.Promise(function (resolve, reject) {
embedded_channel.call({
method: "acquire",
params: [
method_name,
argument_list
],
success: function (s) {
resolve(s);
},
error: function (e) {
reject(e);
}
});
});
};
} }
gadget_loading_klass = tmp_constructor; gadget_loading_klass = tmp_constructor;
......
This diff is collapsed.
{ {
"name": "renderjs", "name": "renderjs",
"version": "0.6.0", "version": "0.6.1",
"description": "RenderJs provides HTML5 gadgets", "description": "RenderJs provides HTML5 gadgets",
"main": "dist/renderjs-latest.js", "main": "dist/renderjs-latest.js",
"dependencies": { "dependencies": {
......
...@@ -81,6 +81,24 @@ ...@@ -81,6 +81,24 @@
throw new Error("No element defined"); throw new Error("No element defined");
} }
return this.element; return this.element;
})
.declareMethod('acquire', function () {
var gadget = this,
argument_list = arguments;
return new RSVP.Queue()
.push(function () {
var aq_dynamic = gadget.aq_dynamic;
if (aq_dynamic !== undefined) {
return aq_dynamic.apply(gadget, argument_list);
}
throw new renderJS.AcquisitionError("aq_dynamic is not defined");
})
.push(undefined, function (error) {
if (error instanceof renderJS.AcquisitionError) {
return gadget.aq_parent.apply(gadget, argument_list);
}
throw error;
});
}); });
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
...@@ -250,6 +268,16 @@ ...@@ -250,6 +268,16 @@
gadget_instance.chan.bind("trigger", function (trans, params) { gadget_instance.chan.bind("trigger", function (trans, params) {
return gadget_instance.trigger(params.event_name, params.options); return gadget_instance.trigger(params.event_name, params.options);
}); });
gadget_instance.chan.bind("acquire", function (trans, params) {
gadget_instance.acquire.apply(gadget_instance, params)
.then(function (g) {
trans.complete(g);
}).fail(function (e) {
trans.error(e.toString());
});
trans.delayReturn(true);
});
return RSVP.any([ return RSVP.any([
iframe_loading_deferred.promise, iframe_loading_deferred.promise,
// Timeout to prevent non renderJS embeddable gadget // Timeout to prevent non renderJS embeddable gadget
...@@ -263,6 +291,7 @@ ...@@ -263,6 +291,7 @@
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
RenderJSGadget.prototype.declareGadget = function (url, options) { RenderJSGadget.prototype.declareGadget = function (url, options) {
var queue, var queue,
parent_gadget = this,
previous_loading_gadget_promise = loading_gadget_promise; previous_loading_gadget_promise = loading_gadget_promise;
if (options === undefined) { if (options === undefined) {
...@@ -297,6 +326,10 @@ ...@@ -297,6 +326,10 @@
// Set the HTML context // Set the HTML context
.push(function (gadget_instance) { .push(function (gadget_instance) {
var i; var i;
// Define aq_parent to reach parent gadget
gadget_instance.aq_parent = function (method_name, argument_list) {
return parent_gadget.acquire(method_name, argument_list);
};
// Drop the current loading klass info used by selector // Drop the current loading klass info used by selector
gadget_loading_klass = undefined; gadget_loading_klass = undefined;
// Trigger calling of all ready callback // Trigger calling of all ready callback
...@@ -338,6 +371,20 @@ ...@@ -338,6 +371,20 @@
return result; return result;
}; };
/////////////////////////////////////////////////////////////////
// renderJS.AcquisitionError
/////////////////////////////////////////////////////////////////
renderJS.AcquisitionError = function (message) {
this.name = "AcquisitionError";
if ((message !== undefined) && (typeof message !== "string")) {
throw new TypeError('You must pass a string.');
}
this.message = message || "Acquisition failed";
};
renderJS.AcquisitionError.prototype = new Error();
renderJS.AcquisitionError.prototype.constructor =
renderJS.AcquisitionError;
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// renderJS.declareJS // renderJS.declareJS
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
...@@ -579,6 +626,14 @@ ...@@ -579,6 +626,14 @@
// Create the root gadget instance and put it in the loading stack // Create the root gadget instance and put it in the loading stack
root_gadget = new gadget_model_dict[url](); root_gadget = new gadget_model_dict[url]();
// Stop acquisition on the original root gadget
// Do not put this on the klass, as their could be multiple instances
root_gadget.aq_parent = function (method_name) {
throw new renderJS.AcquisitionError(
"No gadget provides " + method_name
);
};
} else { } else {
// Create the communication channel // Create the communication channel
embedded_channel = Channel.build({ embedded_channel = Channel.build({
...@@ -658,6 +713,26 @@ ...@@ -658,6 +713,26 @@
notifyTrigger(eventName, options); notifyTrigger(eventName, options);
return result; return result;
}; };
// Define aq_parent to inform parent window
tmp_constructor.prototype.aq_parent = function (method_name,
argument_list) {
return new RSVP.Promise(function (resolve, reject) {
embedded_channel.call({
method: "acquire",
params: [
method_name,
argument_list
],
success: function (s) {
resolve(s);
},
error: function (e) {
reject(e);
}
});
});
};
} }
gadget_loading_klass = tmp_constructor; gadget_loading_klass = tmp_constructor;
......
...@@ -21,6 +21,9 @@ ...@@ -21,6 +21,9 @@
}) })
.declareMethod('getContent', function () { .declareMethod('getContent', function () {
return this.embedded_property; return this.embedded_property;
})
.declareMethod('callAcquire', function (method_name, param_list) {
return this.acquire(method_name, param_list);
}); });
}(window, rJS)); }(window, rJS));
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment