/*
Copyright (c) 2004-2006, The Dojo Foundation
All Rights Reserved.
Licensed under the Academic Free License version 2.1 or above OR the
modified BSD license. For more information on Dojo licensing, see:
http://dojotoolkit.org/community/licensing.shtml
*/
dojo.require("dojo.widget.Chart");
dojo.require("dojo.widget.SortableTable");
function ChartBindingHack(div, resultSet, attributeMapping) {
this._div = div;
this._resultSet = resultSet;
this._attributeMapping = attributeMapping;
resultSet.addObserver(this);
this.redisplayWidget();
};
ChartBindingHack.prototype.redisplayWidget = function() {
this._div.innerHTML = this.getHtmlString();
var parser = new dojo.xml.Parse();
var frag = parser.parseElement(this._div, null, true);
dojo.widget.getParser().createComponents(frag);
};
ChartBindingHack.prototype.observedObjectHasChanged = function() {
this.redisplayWidget();
};
ChartBindingHack.prototype.getHtmlString = function() {
var arrayOfItems = this._resultSet.toArray();
var map = this._attributeMapping;
var arrayOfStrings = [];
arrayOfStrings.push('
');
arrayOfStrings.push('
');
arrayOfStrings.push(' ');
arrayOfStrings.push(' ');
arrayOfStrings.push(' ' + map.x + ' | ');
for (var i in map.plots) {
var plot = map.plots[i];
var plotType = plot["plotType"];
var y = plot["y"];
var size = plot["size"];
var plotTypeString = '';
if (plotType) {
plotTypeString = ' plotType="' + plotType + '"';
}
arrayOfStrings.push(' ' + y + ' | ');
}
arrayOfStrings.push('
');
arrayOfStrings.push(' ');
arrayOfStrings.push(' ');
for (var i in arrayOfItems) {
var item = arrayOfItems[i];
var rowString = ' ';
rowString += '' + item.get(map.x) + ' | ';
for (var j in map.plots) {
var plot = map.plots[j];
var plotType = plot["plotType"];
var y = plot["y"];
var size = plot["size"];
if (plotType == "bubble") {
rowString += '' + item.get(y) + ' | ';
} else {
rowString += '' + item.get(y) + ' | ';
}
}
rowString += '
';
arrayOfStrings.push(rowString);
}
arrayOfStrings.push(' ');
arrayOfStrings.push('
');
arrayOfStrings.push('
');
var returnString = arrayOfStrings.join('\n');
return returnString;
};
// =======================================================================
function TableBindingHack(div, resultSet, attributeMapping) {
this._div = div;
this._resultSet = resultSet;
this._attributeMapping = attributeMapping;
resultSet.addObserver(this);
this.redisplayWidget();
};
TableBindingHack.prototype.redisplayWidget = function() {
this._div.innerHTML = this.getHtmlString();
var parser = new dojo.xml.Parse();
var frag = parser.parseElement(this._div, null, true);
dojo.widget.getParser().createComponents(frag);
};
TableBindingHack.prototype.observedObjectHasChanged = function() {
this.redisplayWidget();
};
TableBindingHack.prototype.getHtmlString = function() {
var dataProvider = this._resultSet.getDataProvider();
var arrayOfItems = this._resultSet.toArray();
var arrayOfStrings = [];
arrayOfStrings.push('');
arrayOfStrings.push(' ');
arrayOfStrings.push(' ');
var map = this._attributeMapping;
for (var i in map) {
var attributeId = map[i];
var attribute = dataProvider.getAttribute(attributeId);
var dataTypeString = "Number"; // default is "Number" -- SortableTable also supports "String" and "Date"
var type = attribute.get('type');
if (type) {
dataTypeString = type;
}
var nameString = attributeId;
var name = attribute.getName();
if (name) {
nameString = name;
}
arrayOfStrings.push(' ' + nameString + ' | ');
}
// Id | ');
// Name |
// Date Added |
// Date Modified |
// Label |
arrayOfStrings.push('
');
arrayOfStrings.push(' ');
arrayOfStrings.push(' ');
for (var i in arrayOfItems) {
var item = arrayOfItems[i];
var rowString = ' ';
for (var j in map) {
var attributeId = map[j];
rowString += '' + item.get(attributeId) + ' | ';
}
rowString += '
';
arrayOfStrings.push(rowString);
}
arrayOfStrings.push(' ');
arrayOfStrings.push('
');
var returnString = arrayOfStrings.join('\n');
return returnString;
};