datasource-scriptnode-debug.js revision bab7b684072c4810ad2fab84014166f8fca4893d
1N/AYUI.add('datasource-scriptnode', function(Y) {
1N/A
1N/A/**
1N/A * The DataSource utility provides a common configurable interface for widgets to
1N/A * access a variety of data, from JavaScript arrays to online database servers.
1N/A *
1N/A * @module datasource
1N/A */
1N/A
1N/A/**
1N/A * Dynamic script node subclass for the YUI DataSource utility.
1N/A * @class DataSource.ScriptNode
1N/A * @extends DataSource.Local
1N/A * @constructor
1N/A */
1N/Avar DSSN = function() {
1N/A DSSN.superclass.constructor.apply(this, arguments);
1N/A};
1N/A
1N/A
1N/A /////////////////////////////////////////////////////////////////////////////
1N/A //
1N/A // DataSource.ScriptNode static properties
1N/A //
1N/A /////////////////////////////////////////////////////////////////////////////
1N/AY.mix(DSSN, {
1N/A /**
1N/A * Class name.
1N/A *
1N/A * @property NAME
1N/A * @type String
1N/A * @static
1N/A * @final
1N/A * @value "dataSourceScriptNode"
1N/A */
1N/A NAME: "dataSourceScriptNode",
1N/A
1N/A
1N/A /////////////////////////////////////////////////////////////////////////////
1N/A //
1N/A // DataSource.ScriptNode Attributes
1N/A //
1N/A /////////////////////////////////////////////////////////////////////////////
1N/A
1N/A ATTRS: {
1N/A /**
1N/A * Pointer to Get Utility.
1N/A *
1N/A * @attribute get
1N/A * @type Y.Get
1N/A * @default Y.Get
1N/A */
1N/A get: {
1N/A value: Y.Get,
1N/A cloneDefaultValue: false
1N/A },
1N/A
1N/A/**
1N/A * Defines request/response management in the following manner:
1N/A * <dl>
1N/A * <!--<dt>queueRequests</dt>
1N/A * <dd>If a request is already in progress, wait until response is returned before sending the next request.</dd>
1N/A * <dt>cancelStaleRequests</dt>
1N/A * <dd>If a request is already in progress, cancel it before sending the next request.</dd>-->
1N/A * <dt>ignoreStaleResponses</dt>
1N/A * <dd>Send all requests, but handle only the response for the most recently sent request.</dd>
1N/A * <dt>allowAll</dt>
1N/A * <dd>Send all requests and handle all responses.</dd>
1N/A * </dl>
1N/A *
1N/A * @attribute asyncMode
1N/A * @type String
1N/A * @default "allowAll"
1N/A */
1N/AasyncMode: {
1N/A value: "allowAll"
1N/A},
1N/A
1N/A/**
1N/A * Callback string parameter name sent to the remote script. By default,
1N/A * requests are sent to
1N/A * &#60;URI&#62;?&#60;scriptCallbackParam&#62;=callbackFunction
1N/A *
1N/A * @attribute scriptCallbackParam
1N/A * @type String
1N/A * @default "callback"
1N/A */
1N/AscriptCallbackParam : {
1N/A value: "callback"
1N/A},
1N/A
1N/A/**
1N/A * Accepts the DataSource instance and a callback ID, and returns a callback
1N/A * param/value string that gets appended to the script URI. Implementers
1N/A * can customize this string to match their server's query syntax.
1N/A *
1N/A * @attribute generateRequestCallback
1N/A * @type Function
1N/A */
1N/AgenerateRequestCallback : {
1N/A value: function(self, id) {
1N/A return "&" + self.get("scriptCallbackParam") + "=YUI.Env.DataSource.callbacks["+id+"]" ;
1N/A }
1N/A}
1N/A
1N/A
1N/A
1N/A
1N/A
1N/A },
1N/A
1N/A /**
1N/A * Global array of callback functions, one for each request sent.
1N/A *
1N/A * @property callbacks
1N/A * @type Function[]
1N/A * @static
1N/A */
1N/A callbacks : [],
1N/A
1N/A /**
1N/A * Unique ID to track requests.
1N/A *
1N/A * @property _tId
1N/A * @type Number
1N/A * @private
1N/A * @static
1N/A */
1N/A _tId : 0
1N/A});
1N/A
1N/AY.extend(DSSN, Y.DataSource.Local, {
1N/A /**
1N/A * Passes query string to Get Utility. Fires <code>response</code> event when
1N/A * response is received asynchronously.
1N/A *
1N/A * @method _defRequestFn
1N/A * @param e {Event.Facade} Event Facade with the following properties:
1N/A * <dl>
1N/A * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
1N/A * <dt>request (Object)</dt> <dd>The request.</dd>
1N/A * <dt>callback (Object)</dt> <dd>The callback object with the following properties:
1N/A * <dl>
1N/A * <dt>success (Function)</dt> <dd>Success handler.</dd>
1N/A * <dt>failure (Function)</dt> <dd>Failure handler.</dd>
1N/A * </dl>
1N/A * </dd>
1N/A * <dt>cfg (Object)</dt> <dd>Configuration object.</dd>
1N/A * </dl>
1N/A * @protected
1N/A */
1N/A _defRequestFn: function(e) {
1N/A var uri = this.get("source"),
1N/A get = this.get("get"),
1N/A id = DSSN._tId++,
1N/A self = this;
1N/A
1N/A
1N/A
1N/A
1N/A
1N/A
1N/A
1N/A
1N/A
1N/A
1N/A
1N/A
1N/A
1N/A // Dynamically add handler function with a closure to the callback stack
1N/A YUI.Env.DataSource.callbacks[id] = Y.rbind(function(response) {
1N/A if((self.get("asyncMode") !== "ignoreStaleResponses")||
1N/A (id === DSSN.callbacks.length-1)) { // Must ignore stale responses
1N/A
1N/A self.fire("data", Y.mix({data:response}, e));
1N/A }
1N/A else {
1N/A Y.log("DataSource ignored stale response for id " + e.tId + "(" + e.request + ")", "info", "datasource-scriptnode");
1N/A }
1N/A
1N/A delete DSSN.callbacks[id];
1N/A }, this, id);
1N/A
1N/A // We are now creating a request
1N/A uri += e.request + this.get("generateRequestCallback")(this, id);
1N/A //uri = this.doBeforeGetScriptNode(sUri);
1N/A Y.log("DataSource is querying URL " + uri, "info", "datasource-scriptnode");
1N/A get.script(uri, {
1N/A autopurge: true,
1N/A // Works in Firefox only....
1N/A onFailure: Y.bind(function(e) {
1N/A e.error = new Error("Script node data failure");
1N/A this.fire("error", e);
1N/A }, this, e)
1N/A });
1N/A
1N/A
1N/A
1N/A
1N/A
1N/A
1N/A
1N/A
1N/A
1N/A
1N/A
1N/A
1N/A
1N/A
1N/A
1N/A return e.tId;
1N/A }
1N/A});
1N/A
1N/AY.DataSource.ScriptNode = DSSN;
1N/AYUI.namespace("Env.DataSource.callbacks");
1N/A
1N/A
1N/A
1N/A
1N/A}, '@VERSION@' ,{requires:['datasource-local', 'get']});
1N/A