EdgeExpressDB
view release on metacpan or search on metacpan
www/edgeexpress/jscript/SpryAssets/SpryData.js view on Meta::CPAN
// Spry.Data.HTTPSourceDataSet
// base class for any DataSet that uses external
//
//////////////////////////////////////////////////////////////////////
Spry.Data.HTTPSourceDataSet = function(dataSetURL, dataSetOptions)
{
// Call the constructor for our DataSet base class so that
// our base class properties get defined. We'll call setOptions
// manually after we set up our HTTPSourceDataSet properties.
Spry.Data.DataSet.call(this);
// HTTPSourceDataSet Properties:
this.url = dataSetURL;
this.dataSetsForDataRefStrings = new Array;
this.hasDataRefStrings = false;
this.useCache = true;
this.setRequestInfo(dataSetOptions, true);
Spry.Utils.setOptions(this, dataSetOptions, true);
this.recalculateDataSetDependencies();
if (this.loadInterval > 0)
this.startLoadInterval(this.loadInterval);
}; // End of Spry.Data.HTTPSourceDataSet() constructor.
Spry.Data.HTTPSourceDataSet.prototype = new Spry.Data.DataSet();
Spry.Data.HTTPSourceDataSet.prototype.constructor = Spry.Data.HTTPSourceDataSet;
Spry.Data.HTTPSourceDataSet.prototype.setRequestInfo = function(requestInfo, undefineRequestProps)
{
// Create a loadURL request object to store any load options
// the caller specified. We'll fill in the URL at the last minute
// before we make the actual load request because our URL needs
// to be processed at the last possible minute in case it contains
// data references.
this.requestInfo = new Spry.Utils.loadURL.Request();
this.requestInfo.extractRequestOptions(requestInfo, undefineRequestProps);
// If the caller wants to use "POST" to fetch the data, but didn't
// provide the content type, default to x-www-form-urlencoded.
if (this.requestInfo.method == "POST")
{
if (!this.requestInfo.headers)
this.requestInfo.headers = {};
if (!this.requestInfo.headers['Content-Type'])
this.requestInfo.headers['Content-Type'] = "application/x-www-form-urlencoded; charset=UTF-8";
}
};
Spry.Data.HTTPSourceDataSet.prototype.recalculateDataSetDependencies = function()
{
this.hasDataRefStrings = false;
// Clear all old callbacks that may have been registered.
var i = 0;
for (i = 0; i < this.dataSetsForDataRefStrings.length; i++)
{
var ds = this.dataSetsForDataRefStrings[i];
if (ds)
ds.removeObserver(this);
}
// Now run through the strings that may contain data references and figure
// out what data sets they require. Note that the data references in these
// strings must be fully qualified with a data set name. (ex: {dsDataSetName::columnName})
this.dataSetsForDataRefStrings = new Array();
var regionStrs = this.getDataRefStrings();
var dsCount = 0;
for (var n = 0; n < regionStrs.length; n++)
{
var tokens = Spry.Data.Region.getTokensFromStr(regionStrs[n]);
for (i = 0; tokens && i < tokens.length; i++)
{
if (tokens[i].search(/{[^}:]+::[^}]+}/) != -1)
{
var dsName = tokens[i].replace(/^\{|::.*\}/g, "");
var ds = null;
if (!this.dataSetsForDataRefStrings[dsName])
{
try { ds = eval(dsName); } catch (e) { ds = null; }
if (dsName && ds)
{
// The dataSetsForDataRefStrings array serves as both an
// array of data sets and a hash lookup by name.
this.dataSetsForDataRefStrings[dsName] = ds;
this.dataSetsForDataRefStrings[dsCount++] = ds;
this.hasDataRefStrings = true;
}
}
}
}
}
// Set up observers on any data sets our URL depends on.
for (i = 0; i < this.dataSetsForDataRefStrings.length; i++)
{
var ds = this.dataSetsForDataRefStrings[i];
ds.addObserver(this);
}
};
Spry.Data.HTTPSourceDataSet.prototype.getDataRefStrings = function()
{
var strArr = [];
if (this.url) strArr.push(this.url);
( run in 0.633 second using v1.01-cache-2.11-cpan-39bf76dae61 )