Subversion Repositories Applications.papyrus

Compare Revisions

Ignore whitespace Rev 2149 → Rev 2150

/trunk/api/js/dojo1.0/dojox/data/demos/demo_FlickrRestStore.html
New file
0,0 → 1,275
<!--
This file is a demo of the FlickrStore, a simple wrapper to the public feed service
of Flickr. This just does very basic queries against Flickr and loads the results
into a list viewing widget.
-->
<html>
<head>
<title>Demo of FlickrRestStore</title>
<style type="text/css">
 
@import "../../../dijit/themes/tundra/tundra.css";
@import "../../../dojo/resources/dojo.css";
@import "../../../dijit/tests/css/dijitTests.css";
@import "./flickrDemo.css";
</style>
 
<script type="text/javascript" src="../../../dojo/dojo.js" djConfig="isDebug: true, parseOnLoad: true"></script>
<script type="text/javascript">
dojo.require("dojo.parser");
dojo.require("dijit.form.TextBox");
dojo.require("dijit.form.Button");
dojo.require("dijit.form.ComboBox");
dojo.require("dijit.form.NumberSpinner");
dojo.require("dijit.Tree");
dojo.require("dojox.data.FlickrStore");
dojo.require("dojox.data.FlickrRestStore");
dojo.require("dojox.data.demos.widgets.FlickrViewList");
dojo.require("dojox.data.demos.widgets.FlickrView");
 
function init(){
var fViewWidgets = [];
 
//Set up an onComplete handler for flickrData
function onComplete(items, request){
flickrViewsWidget.clearList();
if(items.length > 0){
for(var i = 0; i < items.length; i++){
var flickrData = {
title: flickrStore.getValue(items[i],"title"),
author: flickrStore.getValue(items[i],"author"),
iconUrl: flickrStore.getValue(items[i],"imageUrlSmall"),
imageUrl: flickrStore.getValue(items[i],"imageUrl")
}
flickrViewsWidget.addView(flickrData);
}
}
statusWidget.setValue("PROCESSING COMPLETE.");
 
}
//What to do if a search fails...
function onError(error, request){
flickrViewsWidget.clearList();
statusWidget.setValue("PROCESSING ERROR.");
}
 
//Function to invoke the search of the FlickrStore
function invokeSearch(){
var request = {
query: {
apikey: "8c6803164dbc395fb7131c9d54843627"
},
onComplete: onComplete,
onError: onError
};
 
if(idWidget){
var userid = idWidget.getValue();
if(userid && userid !== ""){
request.query.userid = userid;
}
}
if(tagsWidget){
var tags = tagsWidget.getValue();
if(tags && tags !== ""){
var tagsArray = tags.split(" ");
tags = "";
for(var i = 0; i < tagsArray.length; i++){
tags = tags + tagsArray[i];
if(i < (tagsArray.length - 1)){
tags += ","
}
}
request.query.tags = tags;
}
}
if(tagmodeWidget){
var tagmode = tagmodeWidget.getValue();
if(tagmode !== ""){
request.query.tagmode = tagmode;
}
}
if(setIdWidget){
var setId = setIdWidget.getValue();
if(setId != ""){
request.query.setId = setId;
}
}
if(fullTextWidget){
var fullText = fullTextWidget.getValue();
if(fullText != ""){
request.query.text = fullText;
}
}
if(sortTypeWidget && sortDirWidget){
var sortType = sortTypeWidget.getValue();
var sortDirection = sortDirWidget.getValue();
if(sortType != "" && sortDirection != ""){
request.query.sort = [
{
attribute: sortType,
descending: (sortDirection.toLowerCase() == "descending")
}
];
}
}
if(countWidget){
request.count = countWidget.getValue();
}
if(pageWidget){
request.start = request.count * (pageWidget.getValue() -1);
}
 
if(statusWidget){
statusWidget.setValue("PROCESSING REQUEST");
}
 
flickrStore.fetch(request);
}
 
//Lastly, link up the search event.
var button = dijit.byId("searchButton");
dojo.connect(button, "onClick", invokeSearch);
}
dojo.addOnLoad(init);
</script>
</head>
 
<body class="tundra">
<h1>
DEMO: FlickrRestStore Search
</h1>
<hr>
<h3>
Description:
</h3>
<p>
This simple demo shows how services, such as Flickr, can be wrapped by the datastore API.
In this demo, you can search public Flickr images through a FlickrRestStore by specifying
a series of tags (separated by spaces) to search on. The results will be displayed below the search box.
</p>
<p>
For fun, search on the 3dny tag!
</p>
 
<blockquote>
 
<!--
The store instance used by this demo.
-->
<table>
<tbody>
<tr>
<td>
<b>Status:</b>
</td>
<td>
<div dojoType="dijit.form.TextBox" size="50" id="status" jsId="statusWidget" disabled="true"></div>
</td>
<td></td>
<td></td>
</tr>
<tr>
<td>
<b>User ID:</b>
</td>
<td>
<div dojoType="dijit.form.TextBox" size="50" id="userid" jsId="idWidget" value="44153025@N00"></div>
</td>
<td>
<b>Set ID</b>
</td>
<td>
<div dojoType="dijit.form.TextBox" size="50" id="setid" jsId="setIdWidget"></div>
</td>
</tr>
<tr>
<td>
<b>Tags:</b>
</td>
<td>
<div dojoType="dijit.form.TextBox" size="50" id="tags" jsId="tagsWidget" value="rollingstones,kinsale"></div>
</td>
<td>
<b>Full Text</b>
</td>
<td>
<div dojoType="dijit.form.TextBox" size="50" id="fulltext" jsId="fullTextWidget"></div>
</td>
</tr>
<tr>
<td>
<b>Tagmode:</b>
</td>
<td>
<select id="tagmode"
jsId="tagmodeWidget"
dojoType="dijit.form.ComboBox"
autocomplete="false"
value="any"
>
<option>any</option>
<option>all</option>
</select>
</td>
<td>
<b>Sort</b>
</td>
<td>
<select dojoType="dijit.form.ComboBox" size="15" id="sorttype" jsId="sortTypeWidget">
<option>date-posted</option>
<option>date-taken</option>
<option>interestingness</option>
</select>
<select dojoType="dijit.form.ComboBox" size="15" id="sortdirection" jsId="sortDirWidget">
<option>ascending</option>
<option>descending</option>
</select>
</td>
</tr>
<tr>
<td>
<b>Number of Pictures:</b>
</td>
<td>
<div
id="count"
jsId="countWidget"
dojoType="dijit.form.NumberSpinner"
value="20"
constraints="{min:1,max:20,places:0}"
></div>
</td>
<td>
<b>Page:</b>
</td>
<td>
<div
id="page"
jsId="pageWidget"
dojoType="dijit.form.NumberSpinner"
value="1"
constraints="{min:1,max:5,places:0}"
></div>
</td>
</tr>
<tr>
<td>
</td>
<td>
<div dojoType="dijit.form.Button" label="Search" id="searchButton" jsId="searchButtonWidget"></div>
</td>
</tr>
</tbody>
</table>
<hr/>
<div dojoType="dojox.data.FlickrRestStore" jsId="flickrStore" label="title"></div>
<div dojoType="dojox.data.demos.widgets.FlickrViewList" id="flickrViews" jsId="flickrViewsWidget"></div>
 
</body>
</html>
/trunk/api/js/dojo1.0/dojox/data/demos/picasaDemo.css
New file
0,0 → 1,44
.picasaView {
padding: 3 3 3 3;
border-width: 1px;
border-style: solid;
border-color: #000000;
border-collapse: separate;
width: 100%;
}
 
.picasaView th {
text-align: left;
}
 
.picasaView tr {
padding: 3 3 3 3;
border-width: 1px;
border-style: solid;
border-color: #000000;
}
 
.picasaView tr td {
padding: 3 3 3 3;
border-width: 1px;
border-style: solid;
border-color: #000000;
}
 
.picasaView {
background-color: #EFEFEF;
float: left;
width: 250px;
height: 250px;
}
 
.picasaSummary {
width: 250px;
height: 30px;
overflow: hidden;
}
 
.picasaTitle {
background-color: #CCCCCC;
}
 
/trunk/api/js/dojo1.0/dojox/data/demos/demo_DataDemoTable.html
New file
0,0 → 1,130
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Dojo Visual Loader Test</title>
<style type="text/css">
@import "../../../dojo/resources/dojo.css";
@import "../../../dijit/themes/tundra/tundra.css";
@import "../../../dijit/themes/dijit.css";
@import "../../../dijit/tests/css/dijitTests.css";
 
.oddRow { background-color: #f2f5f9; }
.population { text-align: right; }
</style>
 
<script type="text/javascript" src="../../../dojo/dojo.js"
djConfig="isDebug: false, parseOnLoad: true"></script>
<script type="text/javascript">
dojo.require("dijit.dijit");
dojo.require("dojo.parser");
dojo.require("dijit.Declaration");
dojo.require("dojo.data.ItemFileReadStore");
dojo.require("dojox.data.FlickrStore");
</script>
</head>
<body class="tundra">
<span dojoType="dojo.data.ItemFileReadStore"
jsId="continentStore"
url="../../../dijit/tests/_data/countries.json"></span>
<span dojoType="dojox.data.FlickrStore" jsId="flickrStore"></span>
 
 
<h1 class="testTitle">Dojox Data Demo Table</h1>
 
<table dojoType="dijit.Declaration"
widgetClass="demo.Table" class="dojoTabular"
defaults="{ store: null, query: { query: { name: '*' } }, columns: [ { name: 'Name', attribute: 'name' } ] }">
<thead dojoAttachPoint="head">
<tr dojoAttachPoint="headRow"></tr>
</thead>
<tbody dojoAttachPoint="body">
<tr dojoAttachPoint="row">
</tr>
</tbody>
 
<script type="dojo/method">
dojo.forEach(this.columns, function(item, idx){
var icn = item.className||"";
// add a header for each column
var tth = document.createElement("th");
tth.innerHTML = item.name;
tth.className = icn;
dojo.connect(tth, "onclick", dojo.hitch(this, "onSort", idx));
this.headRow.appendChild(tth);
 
// and fill in the column cell in the template row
this.row.appendChild(document.createElement("td"));
this.row.lastChild.className = icn;
}, this);
this.runQuery();
</script>
<script type="dojo/method" event="onSort" args="index">
var ca = this.columns[index].attribute;
var qs = this.query.sort;
// clobber an existing sort arrow
dojo.query("> th", this.headRow).styles("background", "").styles("paddingRight", "");
if(qs && qs[0].attribute == ca){
qs[0].descending = !qs[0].descending;
}else{
this.query.sort = [{
attribute: ca,
descending: false
}];
}
var th = dojo.query("> th", this.headRow)[index];
th.style.paddingRight = "16px"; // space for the sort arrow
th.style.background = "url(\""+dojo.moduleUrl("dijit", "themes/tundra/images/arrow"+(this.query.sort[0].descending ? "Up" : "Down")+((dojo.isIE == 6) ? ".gif" : ".png")) + "\") no-repeat 98% 4px";
this.runQuery();
</script>
<script type="dojo/method" event="runQuery">
this.query.onBegin = dojo.hitch(this, function(){ dojo.query("tr", this.body).orphan(); });
this.query.onItem = dojo.hitch(this, "onItem");
this.query.onComplete = dojo.hitch(this, function(){
dojo.query("tr:nth-child(odd)", this.body).addClass("oddRow");
dojo.query("tr:nth-child(even)", this.body).removeClass("oddRow");
});
this.store.fetch(this.query);
</script>
<script type="dojo/method" event="onItem" args="item">
var tr = this.row.cloneNode(true);
dojo.query("td", tr).forEach(function(n, i, a){
var tc = this.columns[i];
var tv = this.store.getValue(item, tc.attribute)||"";
if(tc.format){ tv = tc.format(tv, item, this.store); }
n.innerHTML = tv;
}, this);
this.body.appendChild(tr);
</script>
</table>
 
<span dojoType="demo.Table" store="continentStore"
query="{ query: { type: 'country' }, sort: [ { attribute: 'name', descending: true } ] }"
id="foo">
<script type="dojo/method" event="preamble">
this.columns = [
{ name: "Name", attribute: "name" },
{ name: "Population",
attribute: "population",
className: "population"
}
];
</script>
</span>
<span dojoType="demo.Table" store="continentStore"
query="{ query: { name: 'A*' } }"></span>
<span dojoType="demo.Table" store="flickrStore"
query="{ query: { tags: '3dny' } }">
<script type="dojo/method" event="preamble">
this.columns = [
{ name: "", attribute: "imageUrlSmall",
format: function(value, item, store){
return (value.length) ? "<img src='"+value+"'>" : "";
}
},
{ name: "Title", attribute: "title" }
];
</script>
</span>
</body>
</html>
/trunk/api/js/dojo1.0/dojox/data/demos/geography.json
New file
0,0 → 1,45
{ identifier: 'name',
label: 'name',
items: [
{ name:'Africa', type:'continent', children:[
{ name:'Egypt', type:'country' },
{ name:'Kenya', type:'country', children:[
{ name:'Nairobi', type:'city' },
{ name:'Mombasa', type:'city' } ]
},
{ name:'Sudan', type:'country', children:
{ name:'Khartoum', type:'city' }
} ]
},
{ name:'Asia', type:'continent', children:[
{ name:'China', type:'country' },
{ name:'India', type:'country' },
{ name:'Russia', type:'country' },
{ name:'Mongolia', type:'country' } ]
},
{ name:'Australia', type:'continent', population:'21 million', children:
{ name:'Commonwealth of Australia', type:'country', population:'21 million'}
},
{ name:'Europe', type:'continent', children:[
{ name:'Germany', type:'country' },
{ name:'France', type:'country' },
{ name:'Spain', type:'country' },
{ name:'Italy', type:'country' } ]
},
{ name:'North America', type:'continent', children:[
{ name:'Mexico', type:'country', population:'108 million', area:'1,972,550 sq km', children:[
{ name:'Mexico City', type:'city', population:'19 million', timezone:'-6 UTC'},
{ name:'Guadalajara', type:'city', population:'4 million', timezone:'-6 UTC' } ]
},
{ name:'Canada', type:'country', population:'33 million', area:'9,984,670 sq km', children:[
{ name:'Ottawa', type:'city', population:'0.9 million', timezone:'-5 UTC'},
{ name:'Toronto', type:'city', population:'2.5 million', timezone:'-5 UTC' }]
},
{ name:'United States of America', type:'country' } ]
},
{ name:'South America', type:'continent', children:[
{ name:'Brazil', type:'country', population:'186 million' },
{ name:'Argentina', type:'country', population:'40 million' } ]
} ]
}
 
/trunk/api/js/dojo1.0/dojox/data/demos/demo_FlickrStore.html
New file
0,0 → 1,199
<!--
This file is a demo of the FlickrStore, a simple wrapper to the public feed service
of Flickr. This just does very basic queries against Flickr and loads the results
into a list viewing widget.
-->
<html>
<head>
<title>Demo of FlickrStore</title>
<style type="text/css">
 
@import "../../../dijit/themes/tundra/tundra.css";
@import "../../../dojo/resources/dojo.css";
@import "../../../dijit/tests/css/dijitTests.css";
@import "./flickrDemo.css";
</style>
 
<script type="text/javascript" src="../../../dojo/dojo.js" djConfig="isDebug: true, parseOnLoad: true"></script>
<script type="text/javascript">
dojo.require("dojo.parser");
dojo.require("dijit.form.TextBox");
dojo.require("dijit.form.Button");
dojo.require("dijit.form.ComboBox");
dojo.require("dijit.form.NumberSpinner");
dojo.require("dijit.Tree");
dojo.require("dojox.data.FlickrStore");
dojo.require("dojox.data.demos.widgets.FlickrViewList");
dojo.require("dojox.data.demos.widgets.FlickrView");
 
function init(){
var fViewWidgets = [];
 
//Set up an onComplete handler for flickrData
function onComplete(items, request){
flickrViewsWidget.clearList();
if(items.length > 0){
for(var i = 0; i < items.length; i++){
var flickrData = {
title: flickrStore.getValue(items[i],"title"),
author: flickrStore.getValue(items[i],"author"),
iconUrl: flickrStore.getValue(items[i],"imageUrlSmall"),
imageUrl: flickrStore.getValue(items[i],"imageUrl")
}
flickrViewsWidget.addView(flickrData);
}
}
statusWidget.setValue("PROCESSING COMPLETE.");
 
}
//What to do if a search fails...
function onError(error, request){
flickrViewsWidget.clearList();
statusWidget.setValue("PROCESSING ERROR.");
}
 
//Function to invoke the search of the FlickrStore
function invokeSearch(){
var request = {
query: {},
onComplete: onComplete,
onError: onError
};
 
if(idWidget){
var userid = idWidget.getValue();
if(userid && userid !== ""){
request.query.userid = userid;
}
}
if(tagsWidget){
var tags = tagsWidget.getValue();
if(tags && tags !== ""){
var tagsArray = tags.split(" ");
tags = "";
for(var i = 0; i < tagsArray.length; i++){
tags = tags + tagsArray[i];
if(i < (tagsArray.length - 1)){
tags += ","
}
}
request.query.tags = tags;
}
}
if(tagmodeWidget){
var tagmode = tagmodeWidget.getValue();
if(tagmode !== ""){
request.query.tagmode = tagmode;
}
}
 
if(countWidget){
request.count = countWidget.getValue();
}
 
if(statusWidget){
statusWidget.setValue("PROCESSING REQUEST");
}
 
flickrStore.fetch(request);
}
 
//Lastly, link up the search event.
var button = dijit.byId("searchButton");
dojo.connect(button, "onClick", invokeSearch);
}
dojo.addOnLoad(init);
</script>
</head>
 
<body class="tundra">
<h1>
DEMO: FlickrStore Search
</h1>
<hr>
<h3>
Description:
</h3>
<p>
This simple demo shows how services, such as Flickr, can be wrapped by the datastore API. In this demo, you can search public Flickr images through a simple FlickrStore by specifying a series of tags (separated by spaces) to search on. The results will be displayed below the search box.
</p>
<p>
For fun, search on the 3dny tag!
</p>
 
<blockquote>
 
<!--
The store instance used by this demo.
-->
<table>
<tbody>
<tr>
<td>
<b>Status:</b>
</td>
<td>
<div dojoType="dijit.form.TextBox" size="50" id="status" jsId="statusWidget" disabled="true"></div>
</td>
</tr>
<tr>
<td>
<b>ID:</b>
</td>
<td>
<div dojoType="dijit.form.TextBox" size="50" id="userid" jsId="idWidget"></div>
</td>
</tr>
<tr>
<td>
<b>Tags:</b>
</td>
<td>
<div dojoType="dijit.form.TextBox" size="50" id="tags" jsId="tagsWidget" value="3dny"></div>
</td>
</tr>
<tr>
<td>
<b>Tagmode:</b>
</td>
<td>
<select id="tagmode"
jsId="tagmodeWidget"
dojoType="dijit.form.ComboBox"
autocomplete="false"
value="any"
>
<option>any</option>
<option>all</option>
</select>
</td>
</tr>
<tr>
<td>
<b>Number of Pictures:</b>
</td>
<td>
<div
id="count"
jsId="countWidget"
dojoType="dijit.form.NumberSpinner"
value="20"
constraints="{min:1,max:20,places:0}"
></div>
</td>
</tr>
<tr>
<td>
</td>
<td>
<div dojoType="dijit.form.Button" label="Search" id="searchButton" jsId="searchButtonWidget"></div>
</td>
</tr>
</tbody>
</table>
<hr/>
<div dojoType="dojox.data.FlickrStore" jsId="flickrStore" label="title"></div>
<div dojoType="dojox.data.demos.widgets.FlickrViewList" id="flickrViews" jsId="flickrViewsWidget"></div>
 
</body>
</html>
/trunk/api/js/dojo1.0/dojox/data/demos/stores/LazyLoadJSIStore.js
New file
0,0 → 1,142
if(!dojo._hasResource["dojox.data.demos.stores.LazyLoadJSIStore"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.data.demos.stores.LazyLoadJSIStore"] = true;
dojo.provide("dojox.data.demos.stores.LazyLoadJSIStore");
dojo.require("dojo.data.ItemFileReadStore");
 
dojo.declare("dojox.data.demos.stores.LazyLoadJSIStore", dojo.data.ItemFileReadStore, {
constructor: function(/* object */ keywordParameters){
// LazyLoadJSIStore extends ItemFileReadStore to implement an
// example of lazy-loading/faulting in items on-demand.
// Note this is certianly not a perfect implementation, it is
// an example.
},
isItemLoaded: function(/*object*/ item) {
// summary:
// Overload of the isItemLoaded function to look for items of type 'stub', which indicate
// the data hasn't been loaded in yet.
//
// item:
// The item to examine.
//For this store, if it has the value of stub for its type attribute,
//then the item basn't been fully loaded yet. It's just a placeholder.
if(this.getValue(item, "type") === "stub"){
return false;
}
return true;
},
loadItem: function(keywordArgs){
// summary:
// Overload of the loadItem function to fault in items. This assumes the data for an item is laid out
// in a RESTful sort of pattern name0/name1/data.json and so on and uses that to load the data.
// It will also detect stub items in the newly loaded item and insert the stubs into the ItemFileReadStore
// list so they can also be loaded in on-demand.
//
// item:
// The item to examine.
 
var item = keywordArgs.item;
this._assertIsItem(item);
 
//Build the path to the data.json for this item
//The path consists of where its parent was loaded from
//plus the item name.
var itemName = this.getValue(item, "name");
var parent = this.getValue(item, "parent");
var dataUrl = "";
if (parent){
dataUrl += (parent + "/");
}
 
//For this store, all child input data is loaded from a url that ends with data.json
dataUrl += itemName + "/data.json";
 
//Need a reference to the store to call back to its structures.
var self = this;
 
// Callback for handling a successful load.
var gotData = function(data){
//Now we need to modify the existing item a bit to take it out of stub state
//Since we extend the store and have knowledge of the internal
//structure, this can be done here. Now, is we extended
//a write store, we could call the write APIs to do this too
//But for a simple demo the diretc modification in the store function
//is sufficient.
 
//Clear off the stub indicators.
delete item.type;
delete item.parent;
 
//Set up the loaded values in the format ItemFileReadStore uses for attributes.
for (i in data) {
if (dojo.isArray(data[i])) {
item[i] = data[i];
}else{
item[i] = [data[i]];
}
}
 
//Reset the item in the reference.
self._arrayOfAllItems[item[self._itemNumPropName]] = item;
 
//Scan the new values in the item for extra stub items we need to
//add to the items array of the store so they can be lazy-loaded later...
var attributes = self.getAttributes(item);
for(i in attributes){
var values = self.getValues(item, attributes[i]);
for (var j = 0; j < values.length; j++) {
var value = values[j];
if(typeof value === "object"){
if(value["stub"] ){
//We have a stub reference here, we need to create the stub item
var stub = {
type: ["stub"],
name: [value["stub"]], //
parent: [itemName] //The child stub item is parented by this item name...
};
if (parent) {
//Add in any parents to your parent so URL construstruction is accurate.
stub.parent[0] = parent + "/" + stub.parent[0];
}
//Finalize the addition of the new stub item into the ItemFileReadStore list.
self._arrayOfAllItems.push(stub);
stub[self._storeRefPropName] = self;
stub[self._itemNumPropName] = (self._arrayOfAllItems.length - 1); //Last one pushed in should be the item
values[j] = stub; //Set the stub item back in its place and replace the stub notation.
}
}
}
}
 
//Done processing! Call the onItem, if any.
if(keywordArgs.onItem){
var scope = keywordArgs.scope ? keywordArgs.scope : dojo.global;
keywordArgs.onItem.call(scope, item);
}
};
 
//Callback for any errors that occur during load.
var gotError = function(error){
//Call the onComplete, if any
if(keywordArgs.onError){
var scope = keywordArgs.scope ? keywordArgs.scope : dojo.global;
keywordArgs.onError.call(scope, error);
}
};
 
//Fire the get and pass the proper callbacks to the deferred.
var xhrArgs = {
url: dataUrl,
handleAs: "json-comment-optional"
};
var d = dojo.xhrGet(xhrArgs);
d.addCallback(gotData);
d.addErrback(gotError);
}
});
 
 
}
/trunk/api/js/dojo1.0/dojox/data/demos/demo_MultiStores.html
New file
0,0 → 1,72
<!--
This file is a demo of multiple dojo.data aware widgets using different datastore implementations for displaying data.
-->
<html>
<head>
<title>Demo of Multiple Widgets using different Datastores</title>
<style type="text/css">
@import "../../../dijit/themes/tundra/tundra.css";
@import "../../../dojo/resources/dojo.css";
@import "../../../dijit/tests/css/dijitTests.css";
</style>
 
<script type="text/javascript" src="../../../dojo/dojo.js" djConfig="isDebug: true, parseOnLoad: true"></script>
<script type="text/javascript">
dojo.require("dojo.parser");
dojo.require("dijit.form.ComboBox");
dojo.require("dijit.Tree");
 
dojo.require("dojox.data.OpmlStore");
dojo.require("dojo.data.ItemFileReadStore");
 
</script>
</head>
 
<body class="tundra">
<h1>
DEMO: Multiple DataStore implementations with dojo.data aware Widgets
</h1>
<hr>
<h3>
Description:
</h3>
<p>
This simple demo shows how widgets which know only the dojo.data interfaces can work with data sources of varying formats. In this case an OpmlStore
and a ItemFileReadStore are used to house the same data in different formats.
</p>
 
<blockquote>
 
<!--
The store instances used by this demo.
-->
<div dojoType="dojo.data.ItemFileReadStore" url="geography.json" jsId="ifrGeoStore"></div>
<div dojoType="dojox.data.OpmlStore" url="geography.xml" label="text" jsId="opmlGeoStore"></div>
 
<h3>
Widgets using OpmlStore:
</h3>
<blockquote>
<b>ComboBox:</b><br>
<input dojoType="dijit.form.ComboBox" id="combo1" name="combo1" class="medium" store="opmlGeoStore" searchAttr="text" query="{}"></input>
<br>
<br>
 
<b>Tree:</b><br>
<div dojoType="dijit.Tree" id="tree1" label="Continents" store="opmlGeoStore"></div>
</blockquote>
 
<h3>
Widgets using ItemFileReadStore:
</h3>
<blockquote>
<b>ComboBox:</b><br>
<input dojoType="dijit.form.ComboBox" id="combo2" name="combo2" class="medium" store="ifrGeoStore" searchAttr="name" query="{}"></input>
<br>
<br>
 
<b>Tree:</b><br>
<div dojoType="dijit.Tree" id="tree2" label="Continents" store="ifrGeoStore"></div>
</blockquote>
</body>
</html>
/trunk/api/js/dojo1.0/dojox/data/demos/demo_PicasaStore.html
New file
0,0 → 1,188
<!--
This file is a demo of the PicasaStore, a simple wrapper to the public feed service
of Picasa. This just does very basic queries against Picasa and loads the results
into a list viewing widget.
-->
<html>
<head>
<title>Demo of PicasaStore</title>
<style type="text/css">
 
@import "../../../dijit/themes/tundra/tundra.css";
@import "../../../dojo/resources/dojo.css";
@import "../../../dijit/tests/css/dijitTests.css";
@import "./picasaDemo.css";
</style>
 
<script type="text/javascript" src="../../../dojo/dojo.js" djConfig="isDebug: true, parseOnLoad: true"></script>
<script type="text/javascript">
dojo.require("dojo.parser");
dojo.require("dijit.form.TextBox");
dojo.require("dijit.form.Button");
dojo.require("dijit.form.ComboBox");
dojo.require("dijit.form.NumberSpinner");
dojo.require("dijit.Tree");
dojo.require("dojox.data.PicasaStore");
dojo.require("dojox.data.demos.widgets.PicasaViewList");
dojo.require("dojox.data.demos.widgets.PicasaView");
function init(){
var fViewWidgets = [];
 
//Set up an onComplete handler for flickrData
function onComplete(items, request){
flickrViewsWidget.clearList();
if(items.length > 0){
for(var i = 0; i < items.length; i++){
var flickrData = {
title: flickrStore.getValue(items[i],"title"),
author: flickrStore.getValue(items[i],"author"),
description: flickrStore.getValue(items[i],"description"),
iconUrl: flickrStore.getValue(items[i],"imageUrlSmall"),
imageUrl: flickrStore.getValue(items[i],"imageUrl")
}
flickrViewsWidget.addView(flickrData);
}
}
statusWidget.setValue("PROCESSING COMPLETE.");
 
}
//What to do if a search fails...
function onError(error, request){
flickrViewsWidget.clearList();
statusWidget.setValue("PROCESSING ERROR.");
}
 
//Function to invoke the search of the FlickrStore
function invokeSearch(){
var request = {
query: {},
onComplete: onComplete,
onError: onError
};
 
if(idWidget){
var userid = idWidget.getValue();
if(userid && userid !== ""){
request.query.userid = userid;
}
}
if(tagsWidget){
var tags = tagsWidget.getValue();
if(tags && tags !== ""){
var tagsArray = tags.split(" ");
tags = "";
for(var i = 0; i < tagsArray.length; i++){
tags = tags + tagsArray[i];
if(i < (tagsArray.length - 1)){
tags += ","
}
}
request.query.tags = tags;
}
}
if(countWidget){
request.count = countWidget.getValue();
}
 
if(startWidget){
request.query.start = startWidget.getValue();
}
 
if(statusWidget){
statusWidget.setValue("PROCESSING REQUEST");
}
 
flickrStore.fetch(request);
}
 
//Lastly, link up the search event.
var button = dijit.byId("searchButton");
dojo.connect(button, "onClick", invokeSearch);
}
dojo.addOnLoad(init);
</script>
</head>
 
<body class="tundra">
<h1>
DEMO: PicasaStore Search
</h1>
<hr>
<h3>
Description:
</h3>
<p>
This simple demo shows how services, such as Flickr, can be wrapped by the datastore API. In this demo, you can search public Flickr images through a simple FlickrStore by specifying a series of tags (separated by spaces) to search on. The results will be displayed below the search box.
</p>
<p>
For fun, search on the 3dny tag!
</p>
 
<blockquote>
 
<!--
The store instance used by this demo.
-->
<table>
<tbody>
<tr>
<td>
<b>Status:</b>
</td>
<td>
<div dojoType="dijit.form.TextBox" size="50" id="status" jsId="statusWidget" disabled="true"></div>
</td>
</tr>
<tr>
<td>
<b>ID:</b>
</td>
<td>
<div dojoType="dijit.form.TextBox" size="50" id="userid" jsId="idWidget"></div>
</td>
</tr>
<tr>
<td>
<b>Query:</b>
</td>
<td>
<div dojoType="dijit.form.TextBox" size="50" id="tags" jsId="tagsWidget" value="flower"></div>
</td>
</tr>
<tr>
<td>
<b>Number of Pictures:</b>
</td>
<td>
<div
id="start"
jsId="startWidget"
dojoType="dijit.form.NumberSpinner"
value="1"
constraints="{min:1,places:0}"
></div>
<div
id="count"
jsId="countWidget"
dojoType="dijit.form.NumberSpinner"
value="20"
constraints="{min:1,max:100,places:0}"
></div>
</td>
</tr>
<tr>
<td>
</td>
<td>
<div dojoType="dijit.form.Button" label="Search" id="searchButton" jsId="searchButtonWidget"></div>
</td>
</tr>
</tbody>
</table>
<hr/>
<div dojoType="dojox.data.PicasaStore" jsId="flickrStore" label="title"></div>
<div dojoType="dojox.data.demos.widgets.PicasaViewList" id="flickrViews" jsId="flickrViewsWidget"></div>
 
</body>
</html>
/trunk/api/js/dojo1.0/dojox/data/demos/geography.xml
New file
0,0 → 1,51
<?xml version="1.0" encoding="ISO-8859-1"?>
<opml version="1.0">
<head>
<title>geography.opml</title>
<dateCreated>2006-11-10</dateCreated>
<dateModified>2006-11-13</dateModified>
<ownerName>Magellan, Ferdinand</ownerName>
</head>
<body>
<outline text="Africa" type="continent">
<outline text="Egypt" type="country"/>
<outline text="Kenya" type="country">
<outline text="Nairobi" type="city"/>
<outline text="Mombasa" type="city"/>
</outline>
<outline text="Sudan" type="country">
<outline text="Khartoum" type="city"/>
</outline>
</outline>
<outline text="Asia" type="continent">
<outline text="China" type="country"/>
<outline text="India" type="country"/>
<outline text="Russia" type="country"/>
<outline text="Mongolia" type="country"/>
</outline>
<outline text="Australia" type="continent" population="21 million">
<outline text="Australia" type="country" population="21 million"/>
</outline>
<outline text="Europe" type="continent">
<outline text="Germany" type="country"/>
<outline text="France" type="country"/>
<outline text="Spain" type="country"/>
<outline text="Italy" type="country"/>
</outline>
<outline text="North America" type="continent">
<outline text="Mexico" type="country" population="108 million" area="1,972,550 sq km">
<outline text="Mexico City" type="city" population="19 million" timezone="-6 UTC"/>
<outline text="Guadalajara" type="city" population="4 million" timezone="-6 UTC"/>
</outline>
<outline text="Canada" type="country" population="33 million" area="9,984,670 sq km">
<outline text="Ottawa" type="city" population="0.9 million" timezone="-5 UTC"/>
<outline text="Toronto" type="city" population="2.5 million" timezone="-5 UTC"/>
</outline>
<outline text="United States of America" type="country"/>
</outline>
<outline text="South America" type="continent">
<outline text="Brazil" type="country" population="186 million"/>
<outline text="Argentina" type="country" population="40 million"/>
</outline>
</body>
</opml>
/trunk/api/js/dojo1.0/dojox/data/demos/geography/Argentina/data.json
New file
0,0 → 1,5
{
name:'Argentina',
type:'country',
population:'40 million'
}
/trunk/api/js/dojo1.0/dojox/data/demos/geography/Sudan/data.json
New file
0,0 → 1,6
{
name:'Sudan',
type:'country',
children:{stub:'Khartoum'}
}
 
/trunk/api/js/dojo1.0/dojox/data/demos/geography/Sudan/Khartoum/data.json
New file
0,0 → 1,5
{
name:'Khartoum',
type:'city'
}
 
/trunk/api/js/dojo1.0/dojox/data/demos/geography/Spain/data.json
New file
0,0 → 1,4
{
name:'Spain',
type:'country'
}
/trunk/api/js/dojo1.0/dojox/data/demos/geography/China/data.json
New file
0,0 → 1,4
{
name:'China',
type:'country'
}
/trunk/api/js/dojo1.0/dojox/data/demos/geography/Italy/data.json
New file
0,0 → 1,4
{
name:'Italy',
type:'country'
}
/trunk/api/js/dojo1.0/dojox/data/demos/geography/United States of America/data.json
New file
0,0 → 1,4
{
name:'United States of America',
type:'country'
}
/trunk/api/js/dojo1.0/dojox/data/demos/geography/Brazil/data.json
New file
0,0 → 1,5
{
name:'Brazil',
type:'country',
population:'186 million'
}
/trunk/api/js/dojo1.0/dojox/data/demos/geography/India/data.json
New file
0,0 → 1,4
{
name:'India',
type:'country'
}
/trunk/api/js/dojo1.0/dojox/data/demos/geography/Mexico/Guadalajara/data.json
New file
0,0 → 1,7
{
name:'Guadalajara',
type:'city',
population:'4 million',
timezone:'-6 UTC'
}
 
/trunk/api/js/dojo1.0/dojox/data/demos/geography/Mexico/Mexico City/data.json
New file
0,0 → 1,6
{
name:'Mexico City',
type:'city',
population:'19 million',
timezone:'-6 UTC'
}
/trunk/api/js/dojo1.0/dojox/data/demos/geography/Mexico/data.json
New file
0,0 → 1,10
{
name:'Mexico',
type:'country',
population:'108 million',
area:'1,972,550 sq km',
children:[
{stub:'Mexico City'},
{stub:'Guadalajara'}
]
}
/trunk/api/js/dojo1.0/dojox/data/demos/geography/Commonwealth of Australia/data.json
New file
0,0 → 1,5
{
name:'Commonwealth of Australia',
type:'country',
population:'21 million'
}
/trunk/api/js/dojo1.0/dojox/data/demos/geography/Egypt/data.json
New file
0,0 → 1,5
{
name:'Egypt',
type:'country'
}
 
/trunk/api/js/dojo1.0/dojox/data/demos/geography/root.json
New file
0,0 → 1,39
{
identifier: 'name',
label: 'name',
items: [
{ name:'Africa', type:'continent',
children:[{_reference:'Egypt'}, {_reference:'Kenya'}, {_reference:'Sudan'}] },
{ name:'Egypt', type:'stub', parent: 'geography'},
{ name:'Kenya', type:'stub', parent: 'geography'},
{ name:'Sudan', type:'stub', parent: 'geography'},
 
{ name:'Asia', type:'continent',
children:[{_reference:'China'}, {_reference:'India'}, {_reference:'Russia'}, {_reference:'Mongolia'}] },
{ name:'China', type:'stub', parent: 'geography'},
{ name:'India', type:'stub', parent: 'geography'},
{ name:'Russia', type:'stub', parent: 'geography'},
{ name:'Mongolia', type:'stub', parent: 'geography'},
 
{ name:'Australia', type:'continent', population:'21 million',
children:{_reference:'Commonwealth of Australia'}},
{ name:'Commonwealth of Australia', type:'stub', parent:'geography'},
 
{ name:'Europe', type:'continent',
children:[{_reference:'Germany'}, {_reference:'France'}, {_reference:'Spain'}, {_reference:'Italy'}] },
{ name:'Germany', type:'stub', parent: 'geography'},
{ name:'France', type:'stub', parent: 'geography'},
{ name:'Spain', type:'stub', parent: 'geography'},
{ name:'Italy', type:'stub', parent: 'geography'},
 
{ name:'North America', type:'continent',
children:[{_reference:'Mexico'}, {_reference:'Canada'}, {_reference:'United States of America'}] },
{ name:'Mexico', type:'stub', parent: 'geography'},
{ name:'Canada', type:'stub', parent: 'geography'},
{ name:'United States of America', type:'stub', parent: 'geography'},
 
{ name:'South America', type:'continent',
children:[{_reference:'Brazil'}, {_reference:'Argentina'}] },
{ name:'Brazil', type:'stub', parent: 'geography'},
{ name:'Argentina', type:'stub', parent: 'geography'}
]}
/trunk/api/js/dojo1.0/dojox/data/demos/geography/France/data.json
New file
0,0 → 1,4
{
name:'France',
type:'country'
}
/trunk/api/js/dojo1.0/dojox/data/demos/geography/Germany/data.json
New file
0,0 → 1,4
{
name:'Germany',
type:'country'
}
/trunk/api/js/dojo1.0/dojox/data/demos/geography/Mongolia/data.json
New file
0,0 → 1,4
{
name:'Mongolia',
type:'country'
}
/trunk/api/js/dojo1.0/dojox/data/demos/geography/Russia/data.json
New file
0,0 → 1,4
{
name:'Russia',
type:'country'
}
/trunk/api/js/dojo1.0/dojox/data/demos/geography/Canada/Ottawa/data.json
New file
0,0 → 1,6
{
name:'Ottawa',
type:'city',
population:'0.9 million',
timezone:'-5 UTC'
}
/trunk/api/js/dojo1.0/dojox/data/demos/geography/Canada/data.json
New file
0,0 → 1,10
{
name:'Canada',
type:'country',
population:'33 million', area:'9,984,670 sq km',
children:[
{stub:'Ottawa'},
{stub:'Toronto'}
]
}
 
/trunk/api/js/dojo1.0/dojox/data/demos/geography/Canada/Toronto/data.json
New file
0,0 → 1,6
{
name:'Toronto',
type:'city',
population:'2.5 million',
timezone:'-5 UTC'
}
/trunk/api/js/dojo1.0/dojox/data/demos/geography/Kenya/Mombasa/data.json
New file
0,0 → 1,5
{
name:'Mombasa',
type:'city',
population: "Unknown"
}
/trunk/api/js/dojo1.0/dojox/data/demos/geography/Kenya/data.json
New file
0,0 → 1,9
{
name:'Kenya',
type:'country',
children:[
{stub:'Nairobi'},
{stub:'Mombasa'}
]
}
 
/trunk/api/js/dojo1.0/dojox/data/demos/geography/Kenya/Nairobi/data.json
New file
0,0 → 1,5
{
name:'Nairobi',
type:'city',
population: "Unknown"
}
/trunk/api/js/dojo1.0/dojox/data/demos/demo_LazyLoad.html
New file
0,0 → 1,66
<!--
This file is a simple loader for the Lazy Load demo of a Datastore. In this
Example, a simple extension of ItemFileReadStore that can do rudimentary lazy-loading
of items into the store is used to showcase how Datastores can hide how data
is loaded from the widget. As long as the widget implements to the Dojo.data API
spec, then it should be able to use most datastores as input sources for its
values.
-->
<html>
<head>
<title>Demo of Lazy Loading Datastore</title>
<style type="text/css">
 
@import "../../../dijit/themes/tundra/tundra.css";
@import "../../../dojo/resources/dojo.css";
@import "../../../dijit/tests/css/dijitTests.css";
</style>
 
<script type="text/javascript" src="../../../dojo/dojo.js" djConfig="isDebug: true, parseOnLoad: true, usePlainJson: true"></script>
<script type="text/javascript">
dojo.require("dojo.parser");
dojo.require("dojox.data.demos.stores.LazyLoadJSIStore");
dojo.require("dijit.Tree");
</script>
</head>
 
<body class="tundra">
<h1>
DEMO: Lazy Loading Datastore used by dijit.Tree
</h1>
<hr>
<h3>
Description:
</h3>
<p>
This simple demo shows how the dijit.Tree widget can work with a Datastore that does lazy-loading of values into the tree.
In this demo, the Datastore is an extension of ItemFileReadStore that overrides the <i>isItemLoaded()</i> and <i>loadItem()</i> functions of
with ones that can detect 'stub' items and use the data in the stub item to load the real data for that item when it
is required. In this demo, the real data is required when one of the tree nodes is expanded.
</p>
<p>
The key thing to note is that all the lazy-loading logic (how to locate the data from the backend and so forth) is encapsulated
into the store functions. The dijit.Tree widget only knows about and uses the dojo.data.Read API interfaces to call to the store to
get items, test if child items are fully loaded or not, and to invoke the <i>loadItem()</i> function on items that are not yet fully
loaded but have been requested to be expanded into view. It has no knowledge of how the store actually goes and gets the data.
</p>
 
<blockquote>
 
<!--
The store instance used by this demo.
-->
<div dojoType="dojox.data.demos.stores.LazyLoadJSIStore" jsId="continentStore"
url="geography/root.json"></div>
 
<!--
Display the toplevel tree with items that have an attribute of 'type',
with value of 'contintent'
-->
<b>Continents</b>
<div dojoType="dijit.Tree" id=tree label="Continents" store="continentStore" query="{type:'continent'}"
labelAttr="name" typeAttr="type"></div>
</blockquote>
 
</body>
</html>
/trunk/api/js/dojo1.0/dojox/data/demos/flickrDemo.css
New file
0,0 → 1,35
.flickrView {
padding: 3 3 3 3;
border-width: 1px;
border-style: solid;
border-color: #000000;
border-collapse: separate;
width: 100%;
}
 
.flickrView th {
text-align: left;
}
 
.flickrView tr {
padding: 3 3 3 3;
border-width: 1px;
border-style: solid;
border-color: #000000;
}
 
.flickrView tr td {
padding: 3 3 3 3;
border-width: 1px;
border-style: solid;
border-color: #000000;
}
 
.flickrView {
background-color: #EFEFEF;
}
 
.flickrTitle {
background-color: #CCCCCC;
}
 
/trunk/api/js/dojo1.0/dojox/data/demos/widgets/FlickrViewList.js
New file
0,0 → 1,37
if(!dojo._hasResource["dojox.data.demos.widgets.FlickrViewList"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.data.demos.widgets.FlickrViewList"] = true;
dojo.provide("dojox.data.demos.widgets.FlickrViewList");
dojo.require("dijit._Templated");
dojo.require("dijit._Widget");
dojo.require("dojox.data.demos.widgets.FlickrView");
 
dojo.declare("dojox.data.demos.widgets.FlickrViewList", [dijit._Widget, dijit._Templated], {
//Simple demo widget that is just a list of FlickrView Widgets.
 
templateString:"<div dojoAttachPoint=\"list\"></div>\n\n",
 
//Attach points for reference.
listNode: null,
 
postCreate: function(){
this.fViewWidgets = [];
},
 
clearList: function(){
while(this.list.firstChild){
this.list.removeChild(this.list.firstChild);
}
for(var i = 0; i < this.fViewWidgets.length; i++){
this.fViewWidgets[i].destroy();
}
this.fViewWidgets = [];
},
 
addView: function(viewData){
var newView = new dojox.data.demos.widgets.FlickrView(viewData);
this.fViewWidgets.push(newView);
this.list.appendChild(newView.domNode);
}
});
 
}
/trunk/api/js/dojo1.0/dojox/data/demos/widgets/templates/PicasaViewList.html
New file
0,0 → 1,2
<div dojoAttachPoint="list"></div>
 
/trunk/api/js/dojo1.0/dojox/data/demos/widgets/templates/PicasaView.html
New file
0,0 → 1,35
<table class="picasaView">
<tbody>
<tr class="picasaTitle">
<td>
<b>
Title:
</b>
</td>
<td dojoAttachPoint="titleNode">
</td>
</tr>
<tr>
<td>
<b>
Author:
</b>
</td>
<td dojoAttachPoint="authorNode">
</td>
</tr>
<tr>
<td colspan="2">
<b>
Summary:
</b>
<span class="picasaSummary" dojoAttachPoint="descriptionNode"></span>
</td>
</tr>
<tr>
<td dojoAttachPoint="imageNode" colspan="2">
</td>
</tr>
</tbody>
</table>
 
/trunk/api/js/dojo1.0/dojox/data/demos/widgets/templates/FlickrViewList.html
New file
0,0 → 1,2
<div dojoAttachPoint="list"></div>
 
/trunk/api/js/dojo1.0/dojox/data/demos/widgets/templates/FlickrView.html
New file
0,0 → 1,34
<table class="flickrView">
<tbody>
<tr class="flickrTitle">
<td>
<b>
Title:
</b>
</td>
<td dojoAttachPoint="titleNode">
</td>
</tr>
<tr>
<td>
<b>
Author:
</b>
</td>
<td dojoAttachPoint="authorNode">
</td>
</tr>
<tr>
<td colspan="2">
<b>
Image:
</b>
</td>
</tr>
<tr>
<td dojoAttachPoint="imageNode" colspan="2">
</td>
</tr>
</tbody>
</table>
 
/trunk/api/js/dojo1.0/dojox/data/demos/widgets/FlickrView.js
New file
0,0 → 1,36
if(!dojo._hasResource["dojox.data.demos.widgets.FlickrView"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.data.demos.widgets.FlickrView"] = true;
dojo.provide("dojox.data.demos.widgets.FlickrView");
dojo.require("dijit._Templated");
dojo.require("dijit._Widget");
 
dojo.declare("dojox.data.demos.widgets.FlickrView", [dijit._Widget, dijit._Templated], {
//Simple demo widget for representing a view of a Flickr Item.
 
templateString:"<table class=\"flickrView\">\n\t<tbody>\n\t\t<tr class=\"flickrTitle\">\n\t\t\t<td>\n\t\t\t\t<b>\n\t\t\t\t\tTitle:\n\t\t\t\t</b>\n\t\t\t</td>\n\t\t\t<td dojoAttachPoint=\"titleNode\">\n\t\t\t</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td>\n\t\t\t\t<b>\n\t\t\t\t\tAuthor:\n\t\t\t\t</b>\n\t\t\t</td>\n\t\t\t<td dojoAttachPoint=\"authorNode\">\n\t\t\t</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td colspan=\"2\">\n\t\t\t\t<b>\n\t\t\t\t\tImage:\n\t\t\t\t</b>\n\t\t\t</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td dojoAttachPoint=\"imageNode\" colspan=\"2\">\n\t\t\t</td>\n\t\t</tr>\n\t</tbody>\n</table>\n\n",
 
//Attach points for reference.
titleNode: null,
descriptionNode: null,
imageNode: null,
authorNode: null,
 
title: "",
author: "",
imageUrl: "",
iconUrl: "",
 
postCreate: function(){
this.titleNode.appendChild(document.createTextNode(this.title));
this.authorNode.appendChild(document.createTextNode(this.author));
var href = document.createElement("a");
href.setAttribute("href", this.imageUrl);
href.setAttribute("target", "_blank");
var imageTag = document.createElement("img");
imageTag.setAttribute("src", this.iconUrl);
href.appendChild(imageTag);
this.imageNode.appendChild(href);
}
});
 
}
/trunk/api/js/dojo1.0/dojox/data/demos/widgets/PicasaViewList.js
New file
0,0 → 1,37
if(!dojo._hasResource["dojox.data.demos.widgets.PicasaViewList"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.data.demos.widgets.PicasaViewList"] = true;
dojo.provide("dojox.data.demos.widgets.PicasaViewList");
dojo.require("dijit._Templated");
dojo.require("dijit._Widget");
dojo.require("dojox.data.demos.widgets.PicasaView");
 
dojo.declare("dojox.data.demos.widgets.PicasaViewList", [dijit._Widget, dijit._Templated], {
//Simple demo widget that is just a list of PicasaView Widgets.
 
templateString:"<div dojoAttachPoint=\"list\"></div>\n\n",
 
//Attach points for reference.
listNode: null,
 
postCreate: function(){
this.fViewWidgets = [];
},
 
clearList: function(){
while(this.list.firstChild){
this.list.removeChild(this.list.firstChild);
}
for(var i = 0; i < this.fViewWidgets.length; i++){
this.fViewWidgets[i].destroy();
}
this.fViewWidgets = [];
},
 
addView: function(viewData){
var newView = new dojox.data.demos.widgets.PicasaView(viewData);
this.fViewWidgets.push(newView);
this.list.appendChild(newView.domNode);
}
});
 
}
/trunk/api/js/dojo1.0/dojox/data/demos/widgets/PicasaView.js
New file
0,0 → 1,37
if(!dojo._hasResource["dojox.data.demos.widgets.PicasaView"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.data.demos.widgets.PicasaView"] = true;
dojo.provide("dojox.data.demos.widgets.PicasaView");
dojo.require("dijit._Templated");
dojo.require("dijit._Widget");
 
dojo.declare("dojox.data.demos.widgets.PicasaView", [dijit._Widget, dijit._Templated], {
//Simple demo widget for representing a view of a Picasa Item.
 
templateString:"<table class=\"picasaView\">\n\t<tbody>\n\t\t<tr class=\"picasaTitle\">\n\t\t\t<td>\n\t\t\t\t<b>\n\t\t\t\t\tTitle:\n\t\t\t\t</b>\n\t\t\t</td>\n\t\t\t<td dojoAttachPoint=\"titleNode\">\n\t\t\t</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td>\n\t\t\t\t<b>\n\t\t\t\t\tAuthor:\n\t\t\t\t</b>\n\t\t\t</td>\n\t\t\t<td dojoAttachPoint=\"authorNode\">\n\t\t\t</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td colspan=\"2\">\n\t\t\t\t<b>\n\t\t\t\t\tSummary:\n\t\t\t\t</b>\n\t\t\t\t<span class=\"picasaSummary\" dojoAttachPoint=\"descriptionNode\"></span>\n\t\t\t</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td dojoAttachPoint=\"imageNode\" colspan=\"2\">\n\t\t\t</td>\n\t\t</tr>\n\t</tbody>\n</table>\n\n",
 
//Attach points for reference.
titleNode: null,
descriptionNode: null,
imageNode: null,
authorNode: null,
 
title: "",
author: "",
imageUrl: "",
iconUrl: "",
 
postCreate: function(){
this.titleNode.appendChild(document.createTextNode(this.title));
this.authorNode.appendChild(document.createTextNode(this.author));
this.descriptionNode.appendChild(document.createTextNode(this.description));
var href = document.createElement("a");
href.setAttribute("href", this.imageUrl);
href.setAttribute("target", "_blank");
var imageTag = document.createElement("img");
imageTag.setAttribute("src", this.iconUrl);
href.appendChild(imageTag);
this.imageNode.appendChild(href);
}
});
 
}
/trunk/api/js/dojo1.0/dojox/data/PicasaStore.js
New file
0,0 → 1,254
if(!dojo._hasResource["dojox.data.PicasaStore"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.data.PicasaStore"] = true;
dojo.provide("dojox.data.PicasaStore");
 
dojo.require("dojo.data.util.simpleFetch");
dojo.require("dojo.io.script");
dojo.require("dojo.date.stamp");
 
dojo.declare("dojox.data.PicasaStore", null, {
constructor: function(/*Object*/args){
// summary:
// Initializer for the PicasaStore store.
// description:
// The PicasaStore is a Datastore interface to one of the basic services
// of the Picasa service, the public photo feed. This does not provide
// access to all the services of Picasa.
// This store cannot do * and ? filtering as the picasa service
// provides no interface for wildcards.
if(args && args.label){
this.label = args.label;
}
},
 
_picasaUrl: "http://picasaweb.google.com/data/feed/api/all",
 
_storeRef: "_S",
 
label: "title",
 
_assertIsItem: function(/* item */ item){
// summary:
// This function tests whether the item passed in is indeed an item in the store.
// item:
// The item to test for being contained by the store.
if(!this.isItem(item)){
throw new Error("dojox.data.PicasaStore: a function was passed an item argument that was not an item");
}
},
 
_assertIsAttribute: function(/* attribute-name-string */ attribute){
// summary:
// This function tests whether the item passed in is indeed a valid 'attribute' like type for the store.
// attribute:
// The attribute to test for being contained by the store.
if(typeof attribute !== "string"){
throw new Error("dojox.data.PicasaStore: a function was passed an attribute argument that was not an attribute name string");
}
},
 
getFeatures: function(){
// summary:
// See dojo.data.api.Read.getFeatures()
return {
'dojo.data.api.Read': true
};
},
 
getValue: function(item, attribute){
// summary:
// See dojo.data.api.Read.getValue()
var values = this.getValues(item, attribute);
if(values){
return values[0];
}
return undefined;
},
 
getAttributes: function(item){
// summary:
// See dojo.data.api.Read.getAttributes()
return ["id", "published", "updated", "category", "title$type", "title", "summary$type", "summary", "rights$type", "rights", "link", "author", "gphoto$id", "gphoto$name", "location"];
},
 
hasAttribute: function(item, attribute){
// summary:
// See dojo.data.api.Read.hasAttributes()
if(this.getValue(item,attribute)){
return true;
}
return false;
},
 
isItemLoaded: function(item){
// summary:
// See dojo.data.api.Read.isItemLoaded()
return this.isItem(item);
},
 
loadItem: function(keywordArgs){
// summary:
// See dojo.data.api.Read.loadItem()
},
 
getLabel: function(item){
// summary:
// See dojo.data.api.Read.getLabel()
return this.getValue(item,this.label);
},
getLabelAttributes: function(item){
// summary:
// See dojo.data.api.Read.getLabelAttributes()
return [this.label];
},
 
containsValue: function(item, attribute, value){
// summary:
// See dojo.data.api.Read.containsValue()
var values = this.getValues(item,attribute);
for(var i = 0; i < values.length; i++){
if(values[i] === value){
return true;
}
}
return false;
},
 
getValues: function(item, attribute){
// summary:
// See dojo.data.api.Read.getValue()
 
this._assertIsItem(item);
this._assertIsAttribute(attribute);
if(attribute === "title"){
return [this._unescapeHtml(item.title)];
}else if(attribute === "author"){
return [this._unescapeHtml(item.author[0].name)];
}else if(attribute === "datePublished"){
return [dojo.date.stamp.fromISOString(item.published)];
}else if(attribute === "dateTaken"){
return [dojo.date.stamp.fromISOString(item.date_taken)];
}else if(attribute === "imageUrlSmall"){
return [item.media.thumbnail[1].url];
}else if(attribute === "imageUrl"){
return [item.content$src];
}else if(attribute === "imageUrlMedium"){
return [item.media.thumbnail[2].url];
}else if(attribute === "link"){
return [item.link[1]];
}else if(attribute === "tags"){
return item.tags.split(" ");
}else if(attribute === "description"){
return [this._unescapeHtml(item.summary)];
}
return undefined;
},
 
isItem: function(item){
// summary:
// See dojo.data.api.Read.isItem()
if(item && item[this._storeRef] === this){
return true;
}
return false;
},
close: function(request){
// summary:
// See dojo.data.api.Read.close()
},
 
_fetchItems: function(request, fetchHandler, errorHandler){
// summary:
// Fetch picasa items that match to a query
// request:
// A request object
// fetchHandler:
// A function to call for fetched items
// errorHandler:
// A function to call on error
 
if(!request.query){
request.query={};
}
 
//Build up the content to send the request for.
var content = {alt: "jsonm", pp: "1", psc: "G"};
content['start-index'] = "1";
if(request.query.start){
content['start-index'] = request.query.start;
}
if(request.query.tags){
content.q = request.query.tags;
}
if(request.query.userid){
content.uname = request.query.userid;
}
if(request.query.userids){
content.ids = request.query.userids;
}
if(request.query.lang){
content.hl = request.query.lang;
}
if(request.count){
content['max-results'] = request.count;
}else{
content['max-results'] = "20";
}
 
//Linking this up to Picasa is a JOY!
var self = this;
var handle = null;
var myHandler = function(data){
if(handle !== null){
dojo.disconnect(handle);
}
 
//Process the items...
fetchHandler(self._processPicasaData(data), request);
};
var getArgs = {
url: this._picasaUrl,
// preventCache: true,
content: content,
callbackParamName: 'callback',
handle: myHandler
};
var deferred = dojo.io.script.get(getArgs);
deferred.addErrback(function(error){
dojo.disconnect(handle);
errorHandler(error, request);
});
},
 
_processPicasaData: function(data){
var items = [];
if(data.feed){
items = data.feed.entry;
//Add on the store ref so that isItem can work.
for(var i = 0; i < items.length; i++){
var item = items[i];
item[this._storeRef] = this;
}
}
return items;
},
 
_unescapeHtml: function(str){
// summary: Utility function to un-escape XML special characters in an HTML string.
// description: Utility function to un-escape XML special characters in an HTML string.
// str: String.
// The string to un-escape
// returns: HTML String converted back to the normal text (unescaped) characters (<,>,&, ", etc,).
//
//TODO: Check to see if theres already compatible escape() in dojo.string or dojo.html
str = str.replace(/&amp;/gm, "&").replace(/&lt;/gm, "<").replace(/&gt;/gm, ">").replace(/&quot;/gm, "\"");
str = str.replace(/&#39;/gm, "'");
return str;
}
});
dojo.extend(dojox.data.PicasaStore,dojo.data.util.simpleFetch);
 
}
/trunk/api/js/dojo1.0/dojox/data/XmlStore.js
New file
0,0 → 1,1126
if(!dojo._hasResource["dojox.data.XmlStore"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.data.XmlStore"] = true;
dojo.provide("dojox.data.XmlStore");
dojo.provide("dojox.data.XmlItem");
 
dojo.require("dojo.data.util.simpleFetch");
dojo.require("dojo.data.util.filter");
dojo.require("dojox.data.dom");
 
dojo.declare("dojox.data.XmlStore", null, {
// summary:
// A data store for XML based services or documents
// description:
// A data store for XML based services or documents
constructor: function(/* object */ args) {
// summary:
// Constructor for the XML store.
// args:
// An anonymous object to initialize properties. It expects the following values:
// url: The url to a service or an XML document that represents the store
// rootItem: A tag name for root items
// keyAttribute: An attribute name for a key or an indentify
// attributeMap: An anonymous object contains properties for attribute mapping,
// {"tag_name.item_attribute_name": "@xml_attribute_name", ...}
// sendQuery: A boolean indicate to add a query string to the service URL
console.log("XmlStore()");
if(args){
this._url = args.url;
this._rootItem = (args.rootItem || args.rootitem);
this._keyAttribute = (args.keyAttribute || args.keyattribute);
this._attributeMap = (args.attributeMap || args.attributemap);
this._labelAttr = args.label;
this._sendQuery = (args.sendQuery || args.sendquery);
}
this._newItems = [];
this._deletedItems = [];
this._modifiedItems = [];
},
 
/* dojo.data.api.Read */
 
getValue: function(/* item */ item, /* attribute || attribute-name-string */ attribute, /* value? */ defaultValue){
// summary:
// Return an attribute value
// description:
// 'item' must be an instance of a dojox.data.XmlItem from the store instance.
// If 'attribute' specifies "tagName", the tag name of the element is
// returned.
// If 'attribute' specifies "childNodes", the first element child is
// returned.
// If 'attribute' specifies "text()", the value of the first text
// child is returned.
// For generic attributes, if '_attributeMap' is specified,
// an actual attribute name is looked up with the tag name of
// the element and 'attribute' (concatenated with '.').
// Then, if 'attribute' starts with "@", the value of the XML
// attribute is returned.
// Otherwise, the first child element of the tag name specified with
// 'attribute' is returned.
// item:
// An XML element that holds the attribute
// attribute:
// A tag name of a child element, An XML attribute name or one of
// special names
// defaultValue:
// A default value
// returns:
// An attribute value found, otherwise 'defaultValue'
var element = item.element;
if(attribute === "tagName"){
return element.nodeName;
}else if (attribute === "childNodes"){
for (var i = 0; i < element.childNodes.length; i++) {
var node = element.childNodes[i];
if (node.nodeType === 1 /*ELEMENT_NODE*/) {
return this._getItem(node); //object
}
}
return defaultValue;
}else if(attribute === "text()"){
for(var i = 0; i < element.childNodes.length; i++){
var node = element.childNodes[i];
if(node.nodeType === 3 /*TEXT_NODE*/ ||
node.nodeType === 4 /*CDATA_SECTION_NODE*/){
return node.nodeValue; //string
}
}
return defaultValue;
}else{
attribute = this._getAttribute(element.nodeName, attribute);
if(attribute.charAt(0) === '@'){
var name = attribute.substring(1);
var value = element.getAttribute(name);
return (value !== undefined) ? value : defaultValue; //object
}else{
for(var i = 0; i < element.childNodes.length; i++){
var node = element.childNodes[i];
if( node.nodeType === 1 /*ELEMENT_NODE*/ &&
node.nodeName === attribute){
return this._getItem(node); //object
}
}
return defaultValue; //object
}
}
},
 
getValues: function(/* item */ item, /* attribute || attribute-name-string */ attribute){
// summary:
// Return an array of attribute values
// description:
// 'item' must be an instance of a dojox.data.XmlItem from the store instance.
// If 'attribute' specifies "tagName", the tag name of the element is
// returned.
// If 'attribute' specifies "childNodes", child elements are returned.
// If 'attribute' specifies "text()", the values of child text nodes
// are returned.
// For generic attributes, if '_attributeMap' is specified,
// an actual attribute name is looked up with the tag name of
// the element and 'attribute' (concatenated with '.').
// Then, if 'attribute' starts with "@", the value of the XML
// attribute is returned.
// Otherwise, child elements of the tag name specified with
// 'attribute' are returned.
// item:
// An XML element that holds the attribute
// attribute:
// A tag name of child elements, An XML attribute name or one of
// special names
// returns:
// An array of attribute values found, otherwise an empty array
var element = item.element;
if(attribute === "tagName"){
return [element.nodeName];
}else if(attribute === "childNodes"){
var values = [];
for(var i = 0; i < element.childNodes.length; i++){
var node = element.childNodes[i];
if(node.nodeType === 1 /*ELEMENT_NODE*/){
values.push(this._getItem(node));
}
}
return values; //array
}else if(attribute === "text()"){
var values = [];
for(var i = 0; i < element.childNodes.length; i++){
var node = childNodes[i];
if(node.nodeType === 3){
values.push(node.nodeValue);
}
}
return values; //array
}else{
attribute = this._getAttribute(element.nodeName, attribute);
if(attribute.charAt(0) === '@'){
var name = attribute.substring(1);
var value = element.getAttribute(name);
return (value !== undefined) ? [value] : []; //array
}else{
var values = [];
for(var i = 0; i < element.childNodes.length; i++){
var node = element.childNodes[i];
if( node.nodeType === 1 /*ELEMENT_NODE*/ &&
node.nodeName === attribute){
values.push(this._getItem(node));
}
}
return values; //array
}
}
},
 
getAttributes: function(/* item */ item) {
// summary:
// Return an array of attribute names
// description:
// 'item' must be an instance of a dojox.data.XmlItem from the store instance.
// tag names of child elements and XML attribute names of attributes
// specified to the element are returned along with special attribute
// names applicable to the element including "tagName", "childNodes"
// if the element has child elements, "text()" if the element has
// child text nodes, and attribute names in '_attributeMap' that match
// the tag name of the element.
// item:
// An XML element
// returns:
// An array of attributes found
var element = item.element;
var attributes = [];
attributes.push("tagName");
if(element.childNodes.length > 0){
var names = {};
var childNodes = true;
var text = false;
for(var i = 0; i < element.childNodes.length; i++){
var node = element.childNodes[i];
if (node.nodeType === 1 /*ELEMENT_NODE*/) {
var name = node.nodeName;
if(!names[name]){
attributes.push(name);
names[name] = name;
}
childNodes = true;
}else if(node.nodeType === 3){
text = true;
}
}
if(childNodes){
attributes.push("childNodes");
}
if(text){
attributes.push("text()");
}
}
for(var i = 0; i < element.attributes.length; i++){
attributes.push("@" + element.attributes[i].nodeName);
}
if(this._attributeMap){
for (var key in this._attributeMap){
var i = key.indexOf('.');
if(i > 0){
var tagName = key.substring(0, i);
if (tagName === element.nodeName){
attributes.push(key.substring(i + 1));
}
}else{ // global attribute
attributes.push(key);
}
}
}
return attributes; //array
},
 
hasAttribute: function(/* item */ item, /* attribute || attribute-name-string */ attribute){
// summary:
// Check whether an element has the attribute
// item:
// 'item' must be an instance of a dojox.data.XmlItem from the store instance.
// attribute:
// A tag name of a child element, An XML attribute name or one of
// special names
// returns:
// True if the element has the attribute, otherwise false
return (this.getValue(item, attribute) !== undefined); //boolean
},
 
containsValue: function(/* item */ item, /* attribute || attribute-name-string */ attribute, /* anything */ value){
// summary:
// Check whether the attribute values contain the value
// item:
// 'item' must be an instance of a dojox.data.XmlItem from the store instance.
// attribute:
// A tag name of a child element, An XML attribute name or one of
// special names
// returns:
// True if the attribute values contain the value, otherwise false
var values = this.getValues(item, attribute);
for(var i = 0; i < values.length; i++){
if((typeof value === "string")){
if(values[i].toString && values[i].toString() === value){
return true;
}
}else if (values[i] === value){
return true; //boolean
}
}
return false;//boolean
},
 
isItem: function(/* anything */ something){
// summary:
// Check whether the object is an item (XML element)
// item:
// An object to check
// returns:
// True if the object is an XML element, otherwise false
if(something && something.element && something.store && something.store === this){
return true; //boolean
}
return false; //boolran
},
 
isItemLoaded: function(/* anything */ something){
// summary:
// Check whether the object is an item (XML element) and loaded
// item:
// An object to check
// returns:
// True if the object is an XML element, otherwise false
return this.isItem(something); //boolean
},
 
loadItem: function(/* object */ keywordArgs){
// summary:
// Load an item (XML element)
// keywordArgs:
// object containing the args for loadItem. See dojo.data.api.Read.loadItem()
},
 
getFeatures: function() {
// summary:
// Return supported data APIs
// returns:
// "dojo.data.api.Read" and "dojo.data.api.Write"
var features = {
"dojo.data.api.Read": true,
"dojo.data.api.Write": true
};
return features; //array
},
 
getLabel: function(/* item */ item){
// summary:
// See dojo.data.api.Read.getLabel()
if(this._labelAttr && this.isItem(item)){
var label = this.getValue(item,this._labelAttr);
if(label){
return label.toString();
}
}
return undefined; //undefined
},
 
getLabelAttributes: function(/* item */ item){
// summary:
// See dojo.data.api.Read.getLabelAttributes()
if(this._labelAttr){
return [this._labelAttr]; //array
}
return null; //null
},
 
_fetchItems: function(request, fetchHandler, errorHandler) {
// summary:
// Fetch items (XML elements) that match to a query
// description:
// If '_sendQuery' is true, an XML document is loaded from
// '_url' with a query string.
// Otherwise, an XML document is loaded and list XML elements that
// match to a query (set of element names and their text attribute
// values that the items to contain).
// A wildcard, "*" can be used to query values to match all
// occurrences.
// If '_rootItem' is specified, it is used to fetch items.
// request:
// A request object
// fetchHandler:
// A function to call for fetched items
// errorHandler:
// A function to call on error
var url = this._getFetchUrl(request);
console.log("XmlStore._fetchItems(): url=" + url);
if(!url){
errorHandler(new Error("No URL specified."));
return;
}
var localRequest = (!this._sendQuery ? request : null); // use request for _getItems()
 
var self = this;
var getArgs = {
url: url,
handleAs: "xml",
preventCache: true
};
var getHandler = dojo.xhrGet(getArgs);
getHandler.addCallback(function(data){
var items = self._getItems(data, localRequest);
console.log("XmlStore._fetchItems(): length=" + (items ? items.length : 0));
if (items && items.length > 0) {
fetchHandler(items, request);
}
else {
fetchHandler([], request);
}
});
getHandler.addErrback(function(data){
errorHandler(data, request);
});
},
 
_getFetchUrl: function(request){
// summary:
// Generate a URL for fetch
// description:
// This default implementation generates a query string in the form of
// "?name1=value1&name2=value2..." off properties of 'query' object
// specified in 'request' and appends it to '_url', if '_sendQuery'
// is set to false.
// Otherwise, '_url' is returned as is.
// Sub-classes may override this method for the custom URL generation.
// request:
// A request object
// returns:
// A fetch URL
if(!this._sendQuery){
return this._url;
}
var query = request.query;
if(!query){
return this._url;
}
if(dojo.isString(query)){
return this._url + query;
}
var queryString = "";
for(var name in query){
var value = query[name];
if(value){
if(queryString){
queryString += "&";
}
queryString += (name + "=" + value);
}
}
if(!queryString){
return this._url;
}
//Check to see if the URL already has query params or not.
var fullUrl = this._url;
if(fullUrl.indexOf("?") < 0){
fullUrl += "?";
}else{
fullUrl += "&";
}
return fullUrl + queryString;
},
 
_getItems: function(document, request) {
// summary:
// Fetch items (XML elements) in an XML document based on a request
// description:
// This default implementation walks through child elements of
// the document element to see if all properties of 'query' object
// match corresponding attributes of the element (item).
// If 'request' is not specified, all child elements are returned.
// Sub-classes may override this method for the custom search in
// an XML document.
// document:
// An XML document
// request:
// A request object
// returns:
// An array of items
var query = null;
if(request){
query = request.query;
}
var items = [];
var nodes = null;
if(this._rootItem){
nodes = document.getElementsByTagName(this._rootItem);
}
else{
nodes = document.documentElement.childNodes;
}
for(var i = 0; i < nodes.length; i++){
var node = nodes[i];
if(node.nodeType != 1 /*ELEMENT_NODE*/){
continue;
}
var item = this._getItem(node);
if(query){
var found = true;
var ignoreCase = request.queryOptions ? request.queryOptions.ignoreCase : false;
 
//See if there are any string values that can be regexp parsed first to avoid multiple regexp gens on the
//same value for each item examined. Much more efficient.
var regexpList = {};
for(var key in query){
var value = query[key];
if(typeof value === "string"){
regexpList[key] = dojo.data.util.filter.patternToRegExp(value, ignoreCase);
}
}
 
for(var attribute in query){
var value = this.getValue(item, attribute);
if(value){
var queryValue = query[attribute];
if ((typeof value) === "string" &&
(regexpList[attribute])){
if((value.match(regexpList[attribute])) !== null){
continue;
}
}else if((typeof value) === "object"){
if( value.toString &&
(regexpList[attribute])){
var stringValue = value.toString();
if((stringValue.match(regexpList[attribute])) !== null){
continue;
}
}else{
if(queryValue === "*" || queryValue === value){
continue;
}
}
}
}
found = false;
break;
}
if(!found){
continue;
}
}
items.push(item);
}
dojo.forEach(items,function(item){
item.element.parentNode.removeChild(item.element); // make it root
},this);
return items;
},
 
close: function(/*dojo.data.api.Request || keywordArgs || null */ request){
// summary:
// See dojo.data.api.Read.close()
},
 
/* dojo.data.api.Write */
 
newItem: function(/* object? */ keywordArgs){
// summary:
// Return a new dojox.data.XmlItem
// description:
// At least, 'keywordArgs' must contain "tagName" to be used for
// the new element.
// Other attributes in 'keywordArgs' are set to the new element,
// including "text()", but excluding "childNodes".
// keywordArgs:
// An object containing initial attributes
// returns:
// An XML element
console.log("XmlStore.newItem()");
keywordArgs = (keywordArgs || {});
var tagName = keywordArgs.tagName;
if(!tagName){
tagName = this._rootItem;
if(!tagName){
return null;
}
}
 
var document = this._getDocument();
var element = document.createElement(tagName);
for(var attribute in keywordArgs){
if(attribute === "tagName"){
continue;
}else if(attribute === "text()"){
var text = document.createTextNode(keywordArgs[attribute]);
element.appendChild(text);
}else{
attribute = this._getAttribute(tagName, attribute);
if(attribute.charAt(0) === '@'){
var name = attribute.substring(1);
element.setAttribute(name, keywordArgs[attribute]);
}else{
var child = document.createElement(attribute);
var text = document.createTextNode(keywordArgs[attribute]);
child.appendChild(text);
element.appendChild(child);
}
}
}
 
var item = this._getItem(element);
this._newItems.push(item);
return item; //object
},
deleteItem: function(/* item */ item){
// summary:
// Delete an dojox.data.XmlItem (wrapper to a XML element).
// item:
// An XML element to delete
// returns:
// True
console.log("XmlStore.deleteItem()");
var element = item.element;
if(element.parentNode){
this._backupItem(item);
element.parentNode.removeChild(element);
return true;
}
this._forgetItem(item);
this._deletedItems.push(item);
return true; //boolean
},
setValue: function(/* item */ item, /* attribute || string */ attribute, /* almost anything */ value){
// summary:
// Set an attribute value
// description:
// 'item' must be an instance of a dojox.data.XmlItem from the store instance.
// If 'attribute' specifies "tagName", nothing is set and false is
// returned.
// If 'attribute' specifies "childNodes", the value (XML element) is
// added to the element.
// If 'attribute' specifies "text()", a text node is created with
// the value and set it to the element as a child.
// For generic attributes, if '_attributeMap' is specified,
// an actual attribute name is looked up with the tag name of
// the element and 'attribute' (concatenated with '.').
// Then, if 'attribute' starts with "@", the value is set to the XML
// attribute.
// Otherwise, a text node is created with the value and set it to
// the first child element of the tag name specified with 'attribute'.
// If the child element does not exist, it is created.
// item:
// An XML element that holds the attribute
// attribute:
// A tag name of a child element, An XML attribute name or one of
// special names
// value:
// A attribute value to set
// returns:
// False for "tagName", otherwise true
if(attribute === "tagName"){
return false; //boolean
}
 
this._backupItem(item);
 
var element = item.element;
if(attribute === "childNodes"){
var child = value.element;
element.appendChild(child);
}else if(attribute === "text()"){
while (element.firstChild){
element.removeChild(element.firstChild);
}
var text = this._getDocument(element).createTextNode(value);
element.appendChild(text);
}else{
attribute = this._getAttribute(element.nodeName, attribute);
if(attribute.charAt(0) === '@'){
var name = attribute.substring(1);
element.setAttribute(name, value);
}else{
var child = null;
for(var i = 0; i < element.childNodes.length; i++){
var node = element.childNodes[i];
if( node.nodeType === 1 /*ELEMENT_NODE*/&&
node.nodeName === attribute){
child = node;
break;
}
}
var document = this._getDocument(element);
if(child){
while(child.firstChild){
child.removeChild(child.firstChild);
}
}else{
child = document.createElement(attribute);
element.appendChild(child);
}
var text = document.createTextNode(value);
child.appendChild(text);
}
}
return true; //boolean
},
setValues: function(/* item */ item, /* attribute || string */ attribute, /* array */ values){
// summary:
// Set attribute values
// description:
// 'item' must be an instance of a dojox.data.XmlItem from the store instance.
// If 'attribute' specifies "tagName", nothing is set and false is
// returned.
// If 'attribute' specifies "childNodes", the value (array of XML
// elements) is set to the element's childNodes.
// If 'attribute' specifies "text()", a text node is created with
// the values and set it to the element as a child.
// For generic attributes, if '_attributeMap' is specified,
// an actual attribute name is looked up with the tag name of
// the element and 'attribute' (concatenated with '.').
// Then, if 'attribute' starts with "@", the first value is set to
// the XML attribute.
// Otherwise, child elements of the tag name specified with
// 'attribute' are replaced with new child elements and their
// child text nodes of values.
// item:
// An XML element that holds the attribute
// attribute:
// A tag name of child elements, an XML attribute name or one of
// special names
// value:
// A attribute value to set
// returns:
// False for "tagName", otherwise true
if(attribute === "tagName"){
return false; //boolean
}
 
this._backupItem(item);
 
var element = item.element;
if(attribute === "childNodes"){
while(element.firstChild){
element.removeChild(element.firstChild);
}
for(var i = 0; i < values.length; i++){
var child = values[i].element;
element.appendChild(child);
}
}else if(attribute === "text()"){
while (element.firstChild){
element.removeChild(element.firstChild);
}
var value = "";
for(var i = 0; i < values.length; i++){
value += values[i];
}
var text = this._getDocument(element).createTextNode(value);
element.appendChild(text);
}else{
attribute = this._getAttribute(element.nodeName, attribute);
if(attribute.charAt(0) === '@'){
var name = attribute.substring(1);
element.setAttribute(name, values[0]);
}else{
for(var i = element.childNodes.length - 1; i >= 0; i--){
var node = element.childNodes[i];
if( node.nodeType === 1 /*ELEMENT_NODE*/ &&
node.nodeName === attribute){
element.removeChild(node);
}
}
var document = this._getDocument(element);
for(var i = 0; i < values.length; i++){
var child = document.createElement(attribute);
var text = document.createTextNode(values[i]);
child.appendChild(text);
element.appendChild(child);
}
}
}
return true; //boolean
},
unsetAttribute: function(/* item */ item, /* attribute || string */ attribute){
// summary:
// Remove an attribute
// description:
// 'item' must be an instance of a dojox.data.XmlItem from the store instance.
// 'attribute' can be an XML attribute name of the element or one of
// special names described below.
// If 'attribute' specifies "tagName", nothing is removed and false is
// returned.
// If 'attribute' specifies "childNodes" or "text()", all child nodes
// are removed.
// For generic attributes, if '_attributeMap' is specified,
// an actual attribute name is looked up with the tag name of
// the element and 'attribute' (concatenated with '.').
// Then, if 'attribute' starts with "@", the XML attribute is removed.
// Otherwise, child elements of the tag name specified with
// 'attribute' are removed.
// item:
// An XML element that holds the attribute
// attribute:
// A tag name of child elements, an XML attribute name or one of
// special names
// returns:
// False for "tagName", otherwise true
if(attribute === "tagName"){
return false; //boolean
}
 
this._backupItem(item);
 
var element = item.element;
if(attribute === "childNodes" || attribute === "text()"){
while(element.firstChild){
element.removeChild(element.firstChild);
}
}else{
attribute = this._getAttribute(element.nodeName, attribute);
if(attribute.charAt(0) === '@'){
var name = attribute.substring(1);
element.removeAttribute(name);
}else{
for(var i = element.childNodes.length - 1; i >= 0; i--){
var node = element.childNodes[i];
if( node.nodeType === 1 /*ELEMENT_NODE*/ &&
node.nodeName === attribute){
element.removeChild(node);
}
}
}
}
return true; //boolean
},
save: function(/* object */ keywordArgs){
// summary:
// Save new and/or modified items (XML elements)
// description:
// '_url' is used to save XML documents for new, modified and/or
// deleted XML elements.
// keywordArgs:
// An object for callbacks
if(!keywordArgs){
keywordArgs = {};
}
for(var i = 0; i < this._modifiedItems.length; i++){
this._saveItem(this._modifiedItems[i], keywordArgs, "PUT");
}
for(var i = 0; i < this._newItems.length; i++){
var item = this._newItems[i];
if(item.element.parentNode){ // reparented
this._newItems.splice(i, 1);
i--;
continue;
}
this._saveItem(this._newItems[i], keywordArgs, "POST");
}
for(var i = 0; i < this._deletedItems.length; i++){
this._saveItem(this._deletedItems[i], keywordArgs, "DELETE");
}
},
 
revert: function(){
// summary:
// Invalidate changes (new and/or modified elements)
// returns:
// True
console.log("XmlStore.revert() _newItems=" + this._newItems.length);
console.log("XmlStore.revert() _deletedItems=" + this._deletedItems.length);
console.log("XmlStore.revert() _modifiedItems=" + this._modifiedItems.length);
this._newItems = [];
this._restoreItems(this._deletedItems);
this._deletedItems = [];
this._restoreItems(this._modifiedItems);
this._modifiedItems = [];
return true; //boolean
},
isDirty: function(/* item? */ item){
// summary:
// Check whether an item is new, modified or deleted
// description:
// If 'item' is specified, true is returned if the item is new,
// modified or deleted.
// Otherwise, true is returned if there are any new, modified
// or deleted items.
// item:
// An item (XML element) to check
// returns:
// True if an item or items are new, modified or deleted, otherwise
// false
if (item) {
var element = this._getRootElement(item.element);
return (this._getItemIndex(this._newItems, element) >= 0 ||
this._getItemIndex(this._deletedItems, element) >= 0 ||
this._getItemIndex(this._modifiedItems, element) >= 0); //boolean
}
else {
return (this._newItems.length > 0 ||
this._deletedItems.length > 0 ||
this._modifiedItems.length > 0); //boolean
}
},
 
_saveItem: function(item, keywordArgs, method){
if(method === "PUT"){
url = this._getPutUrl(item);
}else if(method === "DELETE"){
url = this._getDeleteUrl(item);
}else{ // POST
url = this._getPostUrl(item);
}
if(!url){
if(keywordArgs.onError){
keywordArgs.onError.call(scope, new Error("No URL for saving content: " + postContent));
}
return;
}
 
var saveArgs = {
url: url,
method: (method || "POST"),
contentType: "text/xml",
handleAs: "xml"
};
var saveHander;
if(method === "PUT"){
saveArgs.putData = this._getPutContent(item);
saveHandler = dojo.rawXhrPut(saveArgs);
}else if(method === "DELETE"){
saveHandler = dojo.xhrDelete(saveArgs);
}else{ // POST
saveArgs.postData = this._getPostContent(item);
saveHandler = dojo.rawXhrPost(saveArgs);
}
var scope = (keywordArgs.scope || dojo.global);
var self = this;
saveHandler.addCallback(function(data){
self._forgetItem(item);
if(keywordArgs.onComplete){
keywordArgs.onComplete.call(scope);
}
});
saveHandler.addErrback(function(error){
if(keywordArgs.onError){
keywordArgs.onError.call(scope, error);
}
});
},
 
_getPostUrl: function(item){
// summary:
// Generate a URL for post
// description:
// This default implementation just returns '_url'.
// Sub-classes may override this method for the custom URL.
// item:
// An item to save
// returns:
// A post URL
return this._url; //string
},
 
_getPutUrl: function(item){
// summary:
// Generate a URL for put
// description:
// This default implementation just returns '_url'.
// Sub-classes may override this method for the custom URL.
// item:
// An item to save
// returns:
// A put URL
return this._url; //string
},
 
_getDeleteUrl: function(item){
// summary:
// Generate a URL for delete
// description:
// This default implementation returns '_url' with '_keyAttribute'
// as a query string.
// Sub-classes may override this method for the custom URL based on
// changes (new, deleted, or modified).
// item:
// An item to delete
// returns:
// A delete URL
if (!this._url) {
return this._url; //string
}
var url = this._url;
if (item && this._keyAttribute) {
var value = this.getValue(item, this._keyAttribute);
if (value) {
url = url + '?' + this._keyAttribute + '=' + value;
}
}
return url; //string
},
 
_getPostContent: function(item){
// summary:
// Generate a content to post
// description:
// This default implementation generates an XML document for one
// (the first only) new or modified element.
// Sub-classes may override this method for the custom post content
// generation.
// item:
// An item to save
// returns:
// A post content
var element = item.element;
var declaration = "<?xml version=\"1.0\"?>"; // FIXME: encoding?
return declaration + dojox.data.dom.innerXML(element); //XML string
},
 
_getPutContent: function(item){
// summary:
// Generate a content to put
// description:
// This default implementation generates an XML document for one
// (the first only) new or modified element.
// Sub-classes may override this method for the custom put content
// generation.
// item:
// An item to save
// returns:
// A post content
var element = item.element;
var declaration = "<?xml version=\"1.0\"?>"; // FIXME: encoding?
return declaration + dojox.data.dom.innerXML(element); //XML string
},
 
/* internal API */
 
_getAttribute: function(tagName, attribute){
if(this._attributeMap){
var key = tagName + "." + attribute;
var value = this._attributeMap[key];
if(value){
attribute = value;
}else{ // look for global attribute
value = this._attributeMap[attribute];
if(value){
attribute = value;
}
}
}
return attribute; //object
},
 
_getItem: function(element){
return new dojox.data.XmlItem(element, this); //object
},
 
_getItemIndex: function(items, element){
for(var i = 0; i < items.length; i++){
if(items[i].element === element){
return i; //int
}
}
return -1; //int
},
 
_backupItem: function(item){
var element = this._getRootElement(item.element);
if( this._getItemIndex(this._newItems, element) >= 0 ||
this._getItemIndex(this._modifiedItems, element) >= 0){
return; // new or already modified
}
if(element != item.element){
item = this._getItem(element);
}
item._backup = element.cloneNode(true);
this._modifiedItems.push(item);
},
 
_restoreItems: function(items){
 
dojo.forEach(items,function(item){
if(item._backup){
item.element = item._backup;
item._backup = null;
}
},this);
},
 
_forgetItem: function(item){
var element = item.element;
var index = this._getItemIndex(this._newItems, element);
if(index >= 0){
this._newItems.splice(index, 1);
}
index = this._getItemIndex(this._deletedItems, element);
if(index >= 0){
this._deletedItems.splice(index, 1);
}
index = this._getItemIndex(this._modifiedItems, element);
if(index >= 0){
this._modifiedItems.splice(index, 1);
}
},
 
_getDocument: function(element){
if(element){
return element.ownerDocument; //DOMDocument
}else if(!this._document){
return dojox.data.dom.createDocument(); // DOMDocument
}
},
 
_getRootElement: function(element){
while(element.parentNode){
element = element.parentNode;
}
return element; //DOMElement
}
 
});
 
//FIXME: Is a full class here really needed for containment of the item or would
//an anon object work fine?
dojo.declare("dojox.data.XmlItem", null, {
constructor: function(element, store) {
// summary:
// Initialize with an XML element
// element:
// An XML element
// store:
// The containing store, if any.
this.element = element;
this.store = store;
},
// summary:
// A data item of 'XmlStore'
// description:
// This class represents an item of 'XmlStore' holding an XML element.
// 'element'
// element:
// An XML element
 
toString: function() {
// summary:
// Return a value of the first text child of the element
// returns:
// a value of the first text child of the element
var str = "";
if (this.element) {
for (var i = 0; i < this.element.childNodes.length; i++) {
var node = this.element.childNodes[i];
if (node.nodeType === 3) {
str = node.nodeValue;
break;
}
}
}
return str; //String
}
 
});
dojo.extend(dojox.data.XmlStore,dojo.data.util.simpleFetch);
 
}
/trunk/api/js/dojo1.0/dojox/data/QueryReadStore.js
New file
0,0 → 1,474
if(!dojo._hasResource["dojox.data.QueryReadStore"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.data.QueryReadStore"] = true;
dojo.provide("dojox.data.QueryReadStore");
dojo.provide("dojox.data.QueryReadStore.InvalidItemError");
dojo.provide("dojox.data.QueryReadStore.InvalidAttributeError");
 
dojo.require("dojo.string");
dojo.require("dojo.data.util.simpleFetch");
 
dojo.declare("dojox.data.QueryReadStore", null, {
/*
// summary:
// This class provides a store that is mainly intended to be used
// for loading data dynamically from the server, used i.e. for
// retreiving chunks of data from huge data stores on the server (by server-side filtering!).
// Upon calling the fetch() method of this store the data are requested from
// the server if they are not yet loaded for paging (or cached).
//
// For example used for a combobox which works on lots of data. It
// can be used to retreive the data partially upon entering the
// letters "ac" it returns only items like "action", "acting", etc.
//
// note:
// The field name "id" in a query is reserved for looking up data
// by id. This is necessary as before the first fetch, the store
// has no way of knowing which field the server will declare as
// identifier.
//
// examples:
// // The parameter "query" contains the data that are sent to the server.
// var store = new dojox.data.QueryReadStore({url:'/search.php'});
// store.fetch({query:{name:'a'}, queryOptions:{ignoreCase:false}});
//
// // Since "serverQuery" is given, it overrules and those data are
// // sent to the server.
// var store = new dojox.data.QueryReadStore({url:'/search.php'});
// store.fetch({serverQuery:{name:'a'}, queryOptions:{ignoreCase:false}});
//
// todo:
// - there is a bug in the paging, when i set start:2, count:5 after an initial fetch() and doClientPaging:true
// it returns 6 elemetns, though count=5, try it in QueryReadStore.html
// - allow configuring if the paging shall takes place on the client or the server
// - add optional caching
// - when the first query searched for "a" and the next for a subset of
// the first, i.e. "ab" then we actually dont need a server request, if
// we have client paging, we just need to filter the items we already have
// that might also be tooo much logic
*/
url:"",
requestMethod:"get",
//useCache:false,
// We use the name in the errors, once the name is fixed hardcode it, may be.
_className:"dojox.data.QueryReadStore",
// This will contain the items we have loaded from the server.
// The contents of this array is optimized to satisfy all read-api requirements
// and for using lesser storage, so the keys and their content need some explaination:
// this._items[0].i - the item itself
// this._items[0].r - a reference to the store, so we can identify the item
// securly. We set this reference right after receiving the item from the
// server.
_items:[],
// Store the last query that triggered xhr request to the server.
// So we can compare if the request changed and if we shall reload
// (this also depends on other factors, such as is caching used, etc).
_lastServerQuery:null,
// Store a hash of the last server request. Actually I introduced this
// for testing, so I can check if no unnecessary requests were issued for
// client-side-paging.
lastRequestHash:null,
// If this is false, every request is sent to the server.
// If it's true a second request with the same query will not issue another
// request, but use the already returned data. This assumes that the server
// does not do the paging.
doClientPaging:true,
 
// Items by identify for Identify API
_itemsByIdentity:null,
// Identifier used
_identifier:null,
 
_features: {'dojo.data.api.Read':true, 'dojo.data.api.Identity':true},
constructor: function(/* Object */ params){
dojo.mixin(this,params);
},
getValue: function(/* item */ item, /* attribute-name-string */ attribute, /* value? */ defaultValue){
// According to the Read API comments in getValue() and exception is
// thrown when an item is not an item or the attribute not a string!
this._assertIsItem(item);
if (!dojo.isString(attribute)) {
throw new Error(this._className+".getValue(): Invalid attribute, string expected!");
}
if(!this.hasAttribute(item, attribute)){
// read api says: return defaultValue "only if *item* does not have a value for *attribute*."
// Is this the case here? The attribute doesn't exist, but a defaultValue, sounds reasonable.
if(defaultValue){
return defaultValue;
}
console.log(this._className+".getValue(): Item does not have the attribute '"+attribute+"'.");
}
return item.i[attribute];
},
getValues: function(/* item */ item, /* attribute-name-string */ attribute){
var ret = [];
if(this.hasAttribute(item, attribute)){
ret.push(item.i[attribute]);
}
return ret;
},
getAttributes: function(/* item */ item){
this._assertIsItem(item);
var ret = [];
for(var i in item.i){
ret.push(i);
}
return ret;
},
 
hasAttribute: function(/* item */ item, /* attribute-name-string */ attribute) {
// summary:
// See dojo.data.api.Read.hasAttribute()
return this.isItem(item) && typeof item.i[attribute]!="undefined";
},
containsValue: function(/* item */ item, /* attribute-name-string */ attribute, /* anything */ value){
var values = this.getValues(item, attribute);
var len = values.length;
for(var i=0; i<len; i++){
if(values[i]==value){
return true;
}
}
return false;
},
isItem: function(/* anything */ something){
// Some basic tests, that are quick and easy to do here.
// >>> var store = new dojox.data.QueryReadStore({});
// >>> store.isItem("");
// false
//
// >>> var store = new dojox.data.QueryReadStore({});
// >>> store.isItem({});
// false
//
// >>> var store = new dojox.data.QueryReadStore({});
// >>> store.isItem(0);
// false
//
// >>> var store = new dojox.data.QueryReadStore({});
// >>> store.isItem({name:"me", label:"me too"});
// false
//
if(something){
return typeof something.r!="undefined" && something.r==this;
}
return false;
},
isItemLoaded: function(/* anything */ something) {
// Currently we dont have any state that tells if an item is loaded or not
// if the item exists its also loaded.
// This might change when we start working with refs inside items ...
return this.isItem(something);
},
 
loadItem: function(/* object */ args){
if(this.isItemLoaded(args.item)){
return;
}
// Actually we have nothing to do here, or at least I dont know what to do here ...
},
 
fetch:function(/* Object? */ request){
// summary:
// See dojo.data.util.simpleFetch.fetch() this is just a copy and I adjusted
// only the paging, since it happens on the server if doClientPaging is
// false, thx to http://trac.dojotoolkit.org/ticket/4761 reporting this.
// Would be nice to be able to use simpleFetch() to reduce copied code,
// but i dont know how yet. Ideas please!
request = request || {};
if(!request.store){
request.store = this;
}
var self = this;
var _errorHandler = function(errorData, requestObject){
if(requestObject.onError){
var scope = requestObject.scope || dojo.global;
requestObject.onError.call(scope, errorData, requestObject);
}
};
var _fetchHandler = function(items, requestObject){
var oldAbortFunction = requestObject.abort || null;
var aborted = false;
var startIndex = requestObject.start?requestObject.start:0;
if (self.doClientPaging==false) {
// For client paging we dont need no slicing of the result.
startIndex = 0;
}
var endIndex = requestObject.count?(startIndex + requestObject.count):items.length;
requestObject.abort = function(){
aborted = true;
if(oldAbortFunction){
oldAbortFunction.call(requestObject);
}
};
var scope = requestObject.scope || dojo.global;
if(!requestObject.store){
requestObject.store = self;
}
if(requestObject.onBegin){
requestObject.onBegin.call(scope, items.length, requestObject);
}
if(requestObject.sort){
items.sort(dojo.data.util.sorter.createSortFunction(requestObject.sort, self));
}
if(requestObject.onItem){
for(var i = startIndex; (i < items.length) && (i < endIndex); ++i){
var item = items[i];
if(!aborted){
requestObject.onItem.call(scope, item, requestObject);
}
}
}
if(requestObject.onComplete && !aborted){
var subset = null;
if (!requestObject.onItem) {
subset = items.slice(startIndex, endIndex);
}
requestObject.onComplete.call(scope, subset, requestObject);
}
};
this._fetchItems(request, _fetchHandler, _errorHandler);
return request; // Object
},
 
getFeatures: function(){
return this._features;
},
 
close: function(/*dojo.data.api.Request || keywordArgs || null */ request){
// I have no idea if this is really needed ...
},
 
getLabel: function(/* item */ item){
// Override it to return whatever the label shall be, see Read-API.
return undefined;
},
 
getLabelAttributes: function(/* item */ item){
return null;
},
_fetchItems: function(request, fetchHandler, errorHandler){
// summary:
// The request contains the data as defined in the Read-API.
// Additionally there is following keyword "serverQuery".
//
// The *serverQuery* parameter, optional.
// This parameter contains the data that will be sent to the server.
// If this parameter is not given the parameter "query"'s
// data are sent to the server. This is done for some reasons:
// - to specify explicitly which data are sent to the server, they
// might also be a mix of what is contained in "query", "queryOptions"
// and the paging parameters "start" and "count" or may be even
// completely different things.
// - don't modify the request.query data, so the interface using this
// store can rely on unmodified data, as the combobox dijit currently
// does it, it compares if the query has changed
// - request.query is required by the Read-API
//
// I.e. the following examples might be sent via GET:
// fetch({query:{name:"abc"}, queryOptions:{ignoreCase:true}})
// the URL will become: /url.php?name=abc
//
// fetch({serverQuery:{q:"abc", c:true}, query:{name:"abc"}, queryOptions:{ignoreCase:true}})
// the URL will become: /url.php?q=abc&c=true
// // The serverQuery-parameter has overruled the query-parameter
// // but the query parameter stays untouched, but is not sent to the server!
// // The serverQuery contains more data than the query, so they might differ!
//
 
var serverQuery = request.serverQuery || request.query || {};
//Need to add start and count
if(!this.doClientPaging){
serverQuery.start = request.start || 0;
// Count might not be sent if not given.
if (request.count) {
serverQuery.count = request.count;
}
}
// Compare the last query and the current query by simply json-encoding them,
// so we dont have to do any deep object compare ... is there some dojo.areObjectsEqual()???
if(this.doClientPaging && this._lastServerQuery!==null &&
dojo.toJson(serverQuery)==dojo.toJson(this._lastServerQuery)
){
fetchHandler(this._items, request);
}else{
var xhrFunc = this.requestMethod.toLowerCase()=="post" ? dojo.xhrPost : dojo.xhrGet;
var xhrHandler = xhrFunc({url:this.url, handleAs:"json-comment-optional", content:serverQuery});
xhrHandler.addCallback(dojo.hitch(this, function(data){
data=this._filterResponse(data);
this._items = [];
// Store a ref to "this" in each item, so we can simply check if an item
// really origins form here (idea is from ItemFileReadStore, I just don't know
// how efficient the real storage use, garbage collection effort, etc. is).
dojo.forEach(data.items,function(e){
this._items.push({i:e, r:this});
},this);
var identifier = data.identifier;
this._itemsByIdentity = {};
if(identifier){
this._identifier = identifier;
for(i = 0; i < this._items.length; ++i){
var item = this._items[i].i;
var identity = item[identifier];
if(!this._itemsByIdentity[identity]){
this._itemsByIdentity[identity] = item;
}else{
throw new Error("dojo.data.QueryReadStore: The json data as specified by: [" + this.url + "] is malformed. Items within the list have identifier: [" + identifier + "]. Value collided: [" + identity + "]");
}
}
}else{
this._identifier = Number;
for(i = 0; i < this._items.length; ++i){
this._items[i].n = i;
}
}
// TODO actually we should do the same as dojo.data.ItemFileReadStore._getItemsFromLoadedData() to sanitize
// (does it really sanititze them) and store the data optimal. should we? for security reasons???
fetchHandler(this._items, request);
}));
xhrHandler.addErrback(function(error){
errorHandler(error, request);
});
// Generate the hash using the time in milliseconds and a randon number.
// Since Math.randon() returns something like: 0.23453463, we just remove the "0."
// probably just for esthetic reasons :-).
this.lastRequestHash = new Date().getTime()+"-"+String(Math.random()).substring(2);
this._lastServerQuery = dojo.mixin({}, serverQuery);
}
},
_filterResponse: function(data){
// summary:
// If the data from servers needs to be processed before it can be processed by this
// store, then this function should be re-implemented in subclass. This default
// implementation just return the data unchanged.
// data:
// The data received from server
return data;
},
 
_assertIsItem: function(/* item */ item){
// summary:
// It throws an error if item is not valid, so you can call it in every method that needs to
// throw an error when item is invalid.
// item:
// The item to test for being contained by the store.
if(!this.isItem(item)){
throw new dojox.data.QueryReadStore.InvalidItemError(this._className+": a function was passed an item argument that was not an item");
}
},
 
_assertIsAttribute: function(/* attribute-name-string */ attribute){
// summary:
// This function tests whether the item passed in is indeed a valid 'attribute' like type for the store.
// attribute:
// The attribute to test for being contained by the store.
if(typeof attribute !== "string"){
throw new dojox.data.QueryReadStore.InvalidAttributeError(this._className+": '"+attribute+"' is not a valid attribute identifier.");
}
},
 
fetchItemByIdentity: function(/* Object */ keywordArgs){
// summary:
// See dojo.data.api.Identity.fetchItemByIdentity()
 
// See if we have already loaded the item with that id
// In case there hasn't been a fetch yet, _itemsByIdentity is null
// and thus a fetch will be triggered below.
if(this._itemsByIdentity){
var item = this._itemsByIdentity[keywordArgs.identity];
if(!(item === undefined)){
if(keywordArgs.onItem){
var scope = keywordArgs.scope?keywordArgs.scope:dojo.global;
keywordArgs.onItem.call(scope, {i:item, r:this});
}
return;
}
}
 
// Otherwise we need to go remote
// Set up error handler
var _errorHandler = function(errorData, requestObject){
var scope = keywordArgs.scope?keywordArgs.scope:dojo.global;
if(keywordArgs.onError){
keywordArgs.onError.call(scope, error);
}
};
// Set up fetch handler
var _fetchHandler = function(items, requestObject){
var scope = keywordArgs.scope?keywordArgs.scope:dojo.global;
try{
// There is supposed to be only one result
var item = null;
if(items && items.length == 1){
item = items[0];
}
// If no item was found, item is still null and we'll
// fire the onItem event with the null here
if(keywordArgs.onItem){
keywordArgs.onItem.call(scope, item);
}
}catch(error){
if(keywordArgs.onError){
keywordArgs.onError.call(scope, error);
}
}
};
// Construct query
var request = {serverQuery:{id:keywordArgs.identity}};
// Dispatch query
this._fetchItems(request, _fetchHandler, _errorHandler);
},
getIdentity: function(/* item */ item){
// summary:
// See dojo.data.api.Identity.getIdentity()
var identifier = null;
if(this._identifier === Number){
identifier = item.n; // Number
}else{
identifier = item.i[this._identifier];
}
return identifier;
},
getIdentityAttributes: function(/* item */ item){
// summary:
// See dojo.data.api.Identity.getIdentityAttributes()
return [this._identifier];
}
});
 
dojo.declare("dojox.data.QueryReadStore.InvalidItemError", Error, {});
dojo.declare("dojox.data.QueryReadStore.InvalidAttributeError", Error, {});
 
 
 
 
}
/trunk/api/js/dojo1.0/dojox/data/dom.js
New file
0,0 → 1,187
if(!dojo._hasResource["dojox.data.dom"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.data.dom"] = true;
dojo.provide("dojox.data.dom");
 
//DOM type to int value for reference.
//Ints make for more compact code than full constant names.
//ELEMENT_NODE = 1;
//ATTRIBUTE_NODE = 2;
//TEXT_NODE = 3;
//CDATA_SECTION_NODE = 4;
//ENTITY_REFERENCE_NODE = 5;
//ENTITY_NODE = 6;
//PROCESSING_INSTRUCTION_NODE = 7;
//COMMENT_NODE = 8;
//DOCUMENT_NODE = 9;
//DOCUMENT_TYPE_NODE = 10;
//DOCUMENT_FRAGMENT_NODE = 11;
//NOTATION_NODE = 12;
 
//FIXME: Remove this file when possible.
//This file contains internal/helper APIs as holders until the true DOM apis of Dojo 0.9 are finalized.
//Therefore, these should not be generally used, they are present only for the use by XmlStore and the
//wires project until proper dojo replacements are available. When such exist, XmlStore and the like
//will be ported off these and this file will be deleted.
dojo.experimental("dojox.data.dom");
 
dojox.data.dom.createDocument = function(/*string?*/ str, /*string?*/ mimetype){
// summary:
// cross-browser implementation of creating an XML document object.
//
// str:
// Optional text to create the document from. If not provided, an empty XML document will be created.
// mimetype:
// Optional mimetype of the text. Typically, this is text/xml. Will be defaulted to text/xml if not provided.
var _document = dojo.doc;
 
if(!mimetype){ mimetype = "text/xml"; }
if(str && (typeof dojo.global["DOMParser"]) !== "undefined"){
var parser = new DOMParser();
return parser.parseFromString(str, mimetype); // DOMDocument
}else if((typeof dojo.global["ActiveXObject"]) !== "undefined"){
var prefixes = [ "MSXML2", "Microsoft", "MSXML", "MSXML3" ];
for(var i = 0; i<prefixes.length; i++){
try{
var doc = new ActiveXObject(prefixes[i]+".XMLDOM");
if(str){
if(doc){
doc.async = false;
doc.loadXML(str);
return doc; // DOMDocument
}else{
console.log("loadXML didn't work?");
}
}else{
if(doc){
return doc; //DOMDocument
}
}
}catch(e){ /* squelch */ };
}
}else if((_document.implementation)&&
(_document.implementation.createDocument)){
if(str){
if(_document.createElement){
// FIXME: this may change all tags to uppercase!
var tmp = _document.createElement("xml");
tmp.innerHTML = str;
var xmlDoc = _document.implementation.createDocument("foo", "", null);
for(var i = 0; i < tmp.childNodes.length; i++) {
xmlDoc.importNode(tmp.childNodes.item(i), true);
}
return xmlDoc; // DOMDocument
}
}else{
return _document.implementation.createDocument("", "", null); // DOMDocument
}
}
return null; // DOMDocument
}
 
dojox.data.dom.textContent = function(/*Node*/node, /*string?*/text){
// summary:
// Implementation of the DOM Level 3 attribute; scan node for text
// description:
// Implementation of the DOM Level 3 attribute; scan node for text
// This function can also update the text of a node by replacing all child
// content of the node.
// node:
// The node to get the text off of or set the text on.
// text:
// Optional argument of the text to apply to the node.
if(arguments.length>1){
var _document = node.ownerDocument || dojo.doc; //Preference is to get the node owning doc first or it may fail
dojox.data.dom.replaceChildren(node, _document.createTextNode(text));
return text; // string
} else {
if(node.textContent !== undefined){ //FF 1.5
return node.textContent; // string
}
var _result = "";
if(node == null){
return _result; //empty string.
}
for(var i = 0; i < node.childNodes.length; i++){
switch(node.childNodes[i].nodeType){
case 1: // ELEMENT_NODE
case 5: // ENTITY_REFERENCE_NODE
_result += dojox.data.dom.textContent(node.childNodes[i]);
break;
case 3: // TEXT_NODE
case 2: // ATTRIBUTE_NODE
case 4: // CDATA_SECTION_NODE
_result += node.childNodes[i].nodeValue;
break;
default:
break;
}
}
return _result; // string
}
}
 
dojox.data.dom.replaceChildren = function(/*Element*/node, /*Node || array*/ newChildren){
// summary:
// Removes all children of node and appends newChild. All the existing
// children will be destroyed.
// description:
// Removes all children of node and appends newChild. All the existing
// children will be destroyed.
// node:
// The node to modify the children on
// newChildren:
// The children to add to the node. It can either be a single Node or an
// array of Nodes.
var nodes = [];
if(dojo.isIE){
for(var i=0;i<node.childNodes.length;i++){
nodes.push(node.childNodes[i]);
}
}
 
dojox.data.dom.removeChildren(node);
for(var i=0;i<nodes.length;i++){
dojo._destroyElement(nodes[i]);
}
 
if(!dojo.isArray(newChildren)){
node.appendChild(newChildren);
}else{
for(var i=0;i<newChildren.length;i++){
node.appendChild(newChildren[i]);
}
}
}
 
dojox.data.dom.removeChildren = function(/*Element*/node){
// summary:
// removes all children from node and returns the count of children removed.
// The children nodes are not destroyed. Be sure to call dojo._destroyElement on them
// after they are not used anymore.
// node:
// The node to remove all the children from.
var count = node.childNodes.length;
while(node.hasChildNodes()){
node.removeChild(node.firstChild);
}
return count; // int
}
 
 
dojox.data.dom.innerXML = function(/*Node*/node){
// summary:
// Implementation of MS's innerXML function.
// node:
// The node from which to generate the XML text representation.
if(node.innerXML){
return node.innerXML; // string
}else if (node.xml){
return node.xml; // string
}else if(typeof XMLSerializer != "undefined"){
return (new XMLSerializer()).serializeToString(node); // string
}
}
 
 
}
/trunk/api/js/dojo1.0/dojox/data/README
New file
0,0 → 1,62
-------------------------------------------------------------------------------
DojoX Data
-------------------------------------------------------------------------------
Version 1.0
Release date: 05/29/2007
-------------------------------------------------------------------------------
Project state: stable
-------------------------------------------------------------------------------
Project authors
Jared Jurkiewicz (jared.jurkiewicz@gmail.com)
Shane O'Sullivan (shaneosullivan1@gmail.com) (FlickrRestStore)
Wolfram Kriesing (wolfram@kriesing.de) (QueryReadStore)
-------------------------------------------------------------------------------
Project description
 
The DojoX Data project is a container for extensions and extra example stores
that implement the dojo.data APIs. It may also contain utility functions for
working with specific types of data.
 
-------------------------------------------------------------------------------
Dependencies:
 
DojoX Data has dependencies on core dojo (dojo.data) and the D.O.H. unit test
framework.
-------------------------------------------------------------------------------
Documentation:
 
See the Dojo API tool (http://dojotoolkit.org/api)
-------------------------------------------------------------------------------
Installation instructions
 
Grab the following from the Dojo SVN Repository:
http://svn.dojotoolkit.org/var/src/dojo/dojox/trunk/data/*
 
Install into the following directory structure:
/dojox/data/
 
...which should be at the same level as your Dojo checkout.
 
/dojox/data/*
 
Require in the dojox.data stores you wish to use.
-------------------------------------------------------------------------------
Additional Notes:
dojox.data.CvsStore - comma-separated (spreadsheet output)
datastore implementation
dojox.data.FlickrRestStore - advanced version of: dojox.data.FlickrStore
(Caching + user key support)
dojox.data.FlickrStore - data store driven by Flickr.com public API.
dojox.data.HtmlTableStore - Implementation of an HTML Table reading
datastore
dojox.data.OpmlStore - Store for reading OMPL formatted data
dojox.data.XmlStore - datastore for XML based services or
documents.
 
dojox.data.QueryReadStore - datastore to provide serverside URL query
matching. Similar to the 0.4.X ComboBox dataUrl parameter.
/trunk/api/js/dojo1.0/dojox/data/OpmlStore.js
New file
0,0 → 1,515
if(!dojo._hasResource["dojox.data.OpmlStore"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.data.OpmlStore"] = true;
dojo.provide("dojox.data.OpmlStore");
 
dojo.require("dojo.data.util.filter");
dojo.require("dojo.data.util.simpleFetch");
 
dojo.declare("dojox.data.OpmlStore", null, {
/* summary:
* The OpmlStore implements the dojo.data.api.Read API.
*/
/* examples:
* var opmlStore = new dojo.data.OpmlStore({url:"geography.xml"});
* var opmlStore = new dojo.data.OpmlStore({url:"http://example.com/geography.xml"});
*/
constructor: function(/* Object */ keywordParameters){
// summary: constructor
// keywordParameters: {url: String, label: String} Where label is optional and configures what should be used as the return from getLabel()
this._xmlData = null;
this._arrayOfTopLevelItems = [];
this._arrayOfAllItems = [];
this._metadataNodes = null;
this._loadFinished = false;
this.url = keywordParameters.url;
this._opmlData = keywordParameters.data; // XML DOM Document
if(keywordParameters.label){
this.label = keywordParameters.label;
}
this._loadInProgress = false; //Got to track the initial load to prevent duelling loads of the dataset.
this._queuedFetches = [];
this._identityMap = {};
this._identCount = 0;
this._idProp = "_I";
},
 
label: "text",
 
url: "",
 
_assertIsItem: function(/* item */ item){
if(!this.isItem(item)){
throw new Error("dojo.data.OpmlStore: a function was passed an item argument that was not an item");
}
},
_assertIsAttribute: function(/* item || String */ attribute){
// summary:
// This function tests whether the item passed in is indeed a valid 'attribute' like type for the store.
// attribute:
// The attribute to test for being contained by the store.
if(!dojo.isString(attribute)){
throw new Error("dojox.data.OpmlStore: a function was passed an attribute argument that was not an attribute object nor an attribute name string");
}
},
_removeChildNodesThatAreNotElementNodes: function(/* node */ node, /* boolean */ recursive){
var childNodes = node.childNodes;
if(childNodes.length === 0){
return;
}
var nodesToRemove = [];
var i, childNode;
for(i = 0; i < childNodes.length; ++i){
childNode = childNodes[i];
if(childNode.nodeType != 1){
nodesToRemove.push(childNode);
}
}
for(i = 0; i < nodesToRemove.length; ++i){
childNode = nodesToRemove[i];
node.removeChild(childNode);
}
if(recursive){
for(i = 0; i < childNodes.length; ++i){
childNode = childNodes[i];
this._removeChildNodesThatAreNotElementNodes(childNode, recursive);
}
}
},
_processRawXmlTree: function(/* xmlDoc */ rawXmlTree){
this._loadFinished = true;
this._xmlData = rawXmlTree;
var headNodes = rawXmlTree.getElementsByTagName('head');
var headNode = headNodes[0];
if(headNode){
this._removeChildNodesThatAreNotElementNodes(headNode);
this._metadataNodes = headNode.childNodes;
}
var bodyNodes = rawXmlTree.getElementsByTagName('body');
var bodyNode = bodyNodes[0];
if(bodyNode){
this._removeChildNodesThatAreNotElementNodes(bodyNode, true);
var bodyChildNodes = bodyNodes[0].childNodes;
for(var i = 0; i < bodyChildNodes.length; ++i){
var node = bodyChildNodes[i];
if(node.tagName == 'outline'){
this._identityMap[this._identCount] = node;
this._identCount++;
this._arrayOfTopLevelItems.push(node);
this._arrayOfAllItems.push(node);
this._checkChildNodes(node);
}
}
}
},
 
_checkChildNodes: function(node /*Node*/){
// summary:
// Internal function to recurse over all child nodes from the store and add them
// As non-toplevel items
// description:
// Internal function to recurse over all child nodes from the store and add them
// As non-toplevel items
//
// node:
// The child node to walk.
if(node.firstChild){
for(var i = 0; i < node.childNodes.length; i++){
var child = node.childNodes[i];
if(child.tagName == 'outline'){
this._identityMap[this._identCount] = child;
this._identCount++;
this._arrayOfAllItems.push(child);
this._checkChildNodes(child);
}
}
}
},
 
_getItemsArray: function(/*object?*/queryOptions){
// summary:
// Internal function to determine which list of items to search over.
// queryOptions: The query options parameter, if any.
if(queryOptions && queryOptions.deep) {
return this._arrayOfAllItems;
}
return this._arrayOfTopLevelItems;
},
 
/***************************************
dojo.data.api.Read API
***************************************/
getValue: function( /* item */ item,
/* attribute || attribute-name-string */ attribute,
/* value? */ defaultValue){
// summary:
// See dojo.data.api.Read.getValue()
this._assertIsItem(item);
this._assertIsAttribute(attribute);
if(attribute == 'children'){
return (item.firstChild || defaultValue); //Object
} else {
var value = item.getAttribute(attribute);
return (value !== undefined) ? value : defaultValue; //Object
}
},
getValues: function(/* item */ item,
/* attribute || attribute-name-string */ attribute){
// summary:
// See dojo.data.api.Read.getValues()
this._assertIsItem(item);
this._assertIsAttribute(attribute);
var array = [];
if(attribute == 'children'){
for(var i = 0; i < item.childNodes.length; ++i){
array.push(item.childNodes[i]);
}
} else if(item.getAttribute(attribute) !== null){
array.push(item.getAttribute(attribute));
}
return array; // Array
},
getAttributes: function(/* item */ item){
// summary:
// See dojo.data.api.Read.getAttributes()
this._assertIsItem(item);
var attributes = [];
var xmlNode = item;
var xmlAttributes = xmlNode.attributes;
for(var i = 0; i < xmlAttributes.length; ++i){
var xmlAttribute = xmlAttributes.item(i);
attributes.push(xmlAttribute.nodeName);
}
if(xmlNode.childNodes.length > 0){
attributes.push('children');
}
return attributes; //Array
},
hasAttribute: function( /* item */ item,
/* attribute || attribute-name-string */ attribute){
// summary:
// See dojo.data.api.Read.hasAttribute()
return (this.getValues(item, attribute).length > 0); //Boolean
},
containsValue: function(/* item */ item,
/* attribute || attribute-name-string */ attribute,
/* anything */ value){
// summary:
// See dojo.data.api.Read.containsValue()
var regexp = undefined;
if(typeof value === "string"){
regexp = dojo.data.util.filter.patternToRegExp(value, false);
}
return this._containsValue(item, attribute, value, regexp); //boolean.
},
 
_containsValue: function( /* item */ item,
/* attribute || attribute-name-string */ attribute,
/* anything */ value,
/* RegExp?*/ regexp){
// summary:
// Internal function for looking at the values contained by the item.
// description:
// Internal function for looking at the values contained by the item. This
// function allows for denoting if the comparison should be case sensitive for
// strings or not (for handling filtering cases where string case should not matter)
//
// item:
// The data item to examine for attribute values.
// attribute:
// The attribute to inspect.
// value:
// The value to match.
// regexp:
// Optional regular expression generated off value if value was of string type to handle wildcarding.
// If present and attribute values are string, then it can be used for comparison instead of 'value'
var values = this.getValues(item, attribute);
for(var i = 0; i < values.length; ++i){
var possibleValue = values[i];
if(typeof possibleValue === "string" && regexp){
return (possibleValue.match(regexp) !== null);
}else{
//Non-string matching.
if(value === possibleValue){
return true; // Boolean
}
}
}
return false; // Boolean
},
isItem: function(/* anything */ something){
// summary:
// See dojo.data.api.Read.isItem()
// description:
// Four things are verified to ensure that "something" is an item:
// something can not be null, the nodeType must be an XML Element,
// the tagName must be "outline", and the node must be a member of
// XML document for this datastore.
return (something &&
something.nodeType == 1 &&
something.tagName == 'outline' &&
something.ownerDocument === this._xmlData); //Boolean
},
isItemLoaded: function(/* anything */ something){
// summary:
// See dojo.data.api.Read.isItemLoaded()
// OpmlStore loads every item, so if it's an item, then it's loaded.
return this.isItem(something); //Boolean
},
loadItem: function(/* item */ item){
// summary:
// See dojo.data.api.Read.loadItem()
// description:
// The OpmlStore always loads all items, so if it's an item, then it's loaded.
// From the dojo.data.api.Read.loadItem docs:
// If a call to isItemLoaded() returns true before loadItem() is even called,
// then loadItem() need not do any work at all and will not even invoke the callback handlers.
},
 
getLabel: function(/* item */ item){
// summary:
// See dojo.data.api.Read.getLabel()
if(this.isItem(item)){
return this.getValue(item,this.label); //String
}
return undefined; //undefined
},
 
getLabelAttributes: function(/* item */ item){
// summary:
// See dojo.data.api.Read.getLabelAttributes()
return [this.label]; //array
},
 
// The dojo.data.api.Read.fetch() function is implemented as
// a mixin from dojo.data.util.simpleFetch.
// That mixin requires us to define _fetchItems().
_fetchItems: function( /* Object */ keywordArgs,
/* Function */ findCallback,
/* Function */ errorCallback){
// summary:
// See dojo.data.util.simpleFetch.fetch()
var self = this;
var filter = function(requestArgs, arrayOfItems){
var items = null;
if(requestArgs.query){
items = [];
var ignoreCase = requestArgs.queryOptions ? requestArgs.queryOptions.ignoreCase : false;
 
//See if there are any string values that can be regexp parsed first to avoid multiple regexp gens on the
//same value for each item examined. Much more efficient.
var regexpList = {};
for(var key in requestArgs.query){
var value = requestArgs.query[key];
if(typeof value === "string"){
regexpList[key] = dojo.data.util.filter.patternToRegExp(value, ignoreCase);
}
}
 
for(var i = 0; i < arrayOfItems.length; ++i){
var match = true;
var candidateItem = arrayOfItems[i];
for(var key in requestArgs.query){
var value = requestArgs.query[key];
if(!self._containsValue(candidateItem, key, value, regexpList[key])){
match = false;
}
}
if(match){
items.push(candidateItem);
}
}
}else{
// We want a copy to pass back in case the parent wishes to sort the array. We shouldn't allow resort
// of the internal list so that multiple callers can get lists and sort without affecting each other.
if(arrayOfItems.length> 0){
items = arrayOfItems.slice(0,arrayOfItems.length);
}
}
findCallback(items, requestArgs);
};
 
if(this._loadFinished){
filter(keywordArgs, this._getItemsArray(keywordArgs.queryOptions));
}else{
 
//If fetches come in before the loading has finished, but while
//a load is in progress, we have to defer the fetching to be
//invoked in the callback.
if(this._loadInProgress){
this._queuedFetches.push({args: keywordArgs, filter: filter});
}else{
if(this.url !== ""){
this._loadInProgress = true;
var getArgs = {
url: self.url,
handleAs: "xml"
};
var getHandler = dojo.xhrGet(getArgs);
getHandler.addCallback(function(data){
self._processRawXmlTree(data);
filter(keywordArgs, self._getItemsArray(keywordArgs.queryOptions));
self._handleQueuedFetches();
});
getHandler.addErrback(function(error){
throw error;
});
}else if(this._opmlData){
this._processRawXmlTree(this._opmlData);
this._opmlData = null;
filter(keywordArgs, this._getItemsArray(keywordArgs.queryOptions));
}else{
throw new Error("dojox.data.OpmlStore: No OPML source data was provided as either URL or XML data input.");
}
}
}
},
getFeatures: function(){
// summary: See dojo.data.api.Read.getFeatures()
var features = {
'dojo.data.api.Read': true,
'dojo.data.api.Identity': true
};
return features; //Object
},
 
/***************************************
dojo.data.api.Identity API
***************************************/
getIdentity: function(/* item */ item){
// summary:
// See dojo.data.api.Identity.getIdentity()
if(this.isItem(item)){
//No ther way to do this other than O(n) without
//complete rework of how the tree stores nodes.
for(var i in this._identityMap){
if(this._identityMap[i] === item){
return i;
}
}
}
return null; //null
},
 
fetchItemByIdentity: function(/* Object */ keywordArgs){
// summary:
// See dojo.data.api.Identity.fetchItemByIdentity()
 
//Hasn't loaded yet, we have to trigger the load.
if(!this._loadFinished){
var self = this;
if(this.url !== ""){
//If fetches come in before the loading has finished, but while
//a load is in progress, we have to defer the fetching to be
//invoked in the callback.
if(this._loadInProgress){
this._queuedFetches.push({args: keywordArgs});
}else{
this._loadInProgress = true;
var getArgs = {
url: self.url,
handleAs: "xml"
};
var getHandler = dojo.xhrGet(getArgs);
getHandler.addCallback(function(data){
var scope = keywordArgs.scope?keywordArgs.scope:dojo.global;
try{
self._processRawXmlTree(data);
var item = self._identityMap[keywordArgs.identity];
if(!self.isItem(item)){
item = null;
}
if(keywordArgs.onItem){
keywordArgs.onItem.call(scope, item);
}
self._handleQueuedFetches();
}catch(error){
if(keywordArgs.onError){
keywordArgs.onError.call(scope, error);
}
}
});
getHandler.addErrback(function(error){
this._loadInProgress = false;
if(keywordArgs.onError){
var scope = keywordArgs.scope?keywordArgs.scope:dojo.global;
keywordArgs.onError.call(scope, error);
}
});
}
}else if(this._opmlData){
this._processRawXmlTree(this._opmlData);
this._opmlData = null;
var item = this._identityMap[keywordArgs.identity];
if(!self.isItem(item)){
item = null;
}
if(keywordArgs.onItem){
var scope = keywordArgs.scope?keywordArgs.scope:dojo.global;
keywordArgs.onItem.call(scope, item);
}
}
}else{
//Already loaded. We can just look it up and call back.
var item = this._identityMap[keywordArgs.identity];
if(!this.isItem(item)){
item = null;
}
if(keywordArgs.onItem){
var scope = keywordArgs.scope?keywordArgs.scope:dojo.global;
keywordArgs.onItem.call(scope, item);
}
}
},
 
getIdentityAttributes: function(/* item */ item){
// summary:
// See dojo.data.api.Identity.getIdentifierAttributes()
//Identity isn't a public attribute in the item, it's the node count.
//So, return null.
return null;
},
 
_handleQueuedFetches: function(){
// summary:
// Internal function to execute delayed request in the store.
//Execute any deferred fetches now.
if (this._queuedFetches.length > 0) {
for(var i = 0; i < this._queuedFetches.length; i++){
var fData = this._queuedFetches[i];
var delayedQuery = fData.args;
var delayedFilter = fData.filter;
if(delayedFilter){
delayedFilter(delayedQuery, this._getItemsArray(delayedQuery.queryOptions));
}else{
this.fetchItemByIdentity(delayedQuery);
}
}
this._queuedFetches = [];
}
},
 
close: function(/*dojo.data.api.Request || keywordArgs || null */ request){
// summary:
// See dojo.data.api.Read.close()
}
});
//Mix in the simple fetch implementation to this class.
dojo.extend(dojox.data.OpmlStore,dojo.data.util.simpleFetch);
 
}
/trunk/api/js/dojo1.0/dojox/data/FlickrRestStore.js
New file
0,0 → 1,471
if(!dojo._hasResource["dojox.data.FlickrRestStore"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.data.FlickrRestStore"] = true;
dojo.provide("dojox.data.FlickrRestStore");
 
dojo.require("dojox.data.FlickrStore");
 
dojo.declare("dojox.data.FlickrRestStore",
dojox.data.FlickrStore, {
constructor: function(/*Object*/args){
// summary:
// Initializer for the FlickrRestStore store.
// description:
// The FlickrRestStore is a Datastore interface to one of the basic services
// of the Flickr service, the public photo feed. This does not provide
// access to all the services of Flickr.
// This store cannot do * and ? filtering as the flickr service
// provides no interface for wildcards.
if(args && args.label){
if(args.label) {
this.label = args.label;
}
if(args.apikey) {
this._apikey = args.apikey;
}
}
this._cache = [];
this._prevRequests = {};
this._handlers = {};
this._prevRequestRanges = [];
this._maxPhotosPerUser = {};
this._id = dojox.data.FlickrRestStore.prototype._id++;
},
// _id: Integer
// A unique identifier for this store.
_id: 0,
// _requestCount: Integer
// A counter for the number of requests made. This is used to define
// the callback function that Flickr will use.
_requestCount: 0,
// _flickrRestUrl: String
// The URL to the Flickr REST services.
_flickrRestUrl: "http://www.flickr.com/services/rest/",
// _apikey: String
// The users API key to be used when accessing Flickr REST services.
_apikey: null,
// _storeRef: String
// A key used to mark an data store item as belonging to this store.
_storeRef: "_S",
// _cache: Array
// An Array of all previously downloaded picture info.
_cache: null,
// _prevRequests: Object
// A HashMap used to record the signature of a request to prevent duplicate
// request being made.
_prevRequests: null,
// _handlers: Object
// A HashMap used to record the handlers registered for a single remote request. Multiple
// requests may be made for the same information before the first request has finished.
// Each element of this Object is an array of handlers to call back when the request finishes.
// This prevents multiple requests being made for the same information.
_handlers: null,
// _sortAttributes: Object
// A quick lookup of valid attribute names in a sort query.
_sortAttributes: {
"date-posted": true,
"date-taken": true,
"interestingness": true
},
_fetchItems: function(request, fetchHandler, errorHandler){
// summary: Fetch flickr items that match to a query
// request:
// A request object
// fetchHandler:
// A function to call for fetched items
// errorHandler:
// A function to call on error
var query = {};
if(!request.query){
request.query = query = {};
} else {
dojo.mixin(query, request.query);
}
var primaryKey = [];
var secondaryKey = [];
//Generate a unique function to be called back
var callbackFn = "FlickrRestStoreCallback_" + this._id + "_" + (++this._requestCount);
//Build up the content to send the request for.
var content = {
format: "json",
method: "flickr.photos.search",
api_key: this._apikey,
extras: "owner_name,date_upload,date_taken",
jsoncallback: callbackFn
};
var isRest = false;
if(query.userid){
isRest = true;
content.user_id = request.query.userid;
primaryKey.push("userid"+request.query.userid);
}
if(query.apikey){
isRest = true;
content.api_key = request.query.apikey;
secondaryKey.push("api"+request.query.apikey);
} else{
throw Error("dojox.data.FlickrRestStore: An API key must be specified.");
}
request._curCount = request.count;
if(query.page){
content.page = request.query.page;
secondaryKey.push("page" + content.page);
}else if(typeof(request.start) != "undefined" && request.start != null) {
if(!request.count){
request.count = 20;
}
var diff = request.start % request.count;
var start = request.start, count = request.count;
//If the count does not divide cleanly into the start number,
//more work has to be done to figure out the best page to request
if(diff != 0) {
if(start < count / 2) {
//If the first record requested is less than half the amount requested,
//then request from 0 to the count record
count = start + count;
start = 0;
} else {
var divLimit = 20, div = 2;
for(var i = divLimit; i > 0; i--) {
if(start % i == 0 && (start/i) >= count){
div = i;
break;
}
}
count = start/div;
}
request._realStart = request.start;
request._realCount = request.count;
request._curStart = start;
request._curCount = count;
} else {
request._realStart = request._realCount = null;
request._curStart = request.start;
request._curCount = request.count;
}
content.page = (start / count) + 1;
secondaryKey.push("page" + content.page);
}
if(request._curCount){
content.per_page = request._curCount;
secondaryKey.push("count" + request._curCount);
}
if(query.lang){
content.lang = request.query.lang;
primaryKey.push("lang" + request.lang);
}
var url = this._flickrRestUrl;
if(query.setid){
content.method = "flickr.photosets.getPhotos";
content.photoset_id = request.query.set;
primaryKey.push("set" + request.query.set);
}
if(query.tags){
if(query.tags instanceof Array){
content.tags = query.tags.join(",");
} else {
content.tags=query.tags;
}
primaryKey.push("tags" + content.tags);
if(query["tag_mode"] && (query.tag_mode.toLowerCase() == "any"
|| query.tag_mode.toLowerCase() == "all")){
content.tag_mode = query.tag_mode;
}
}
if(query.text){
content.text=query.text;
primaryKey.push("text:"+query.text);
}
//The store only supports a single sort attribute, even though the
//Read API technically allows multiple sort attributes
if(query.sort && query.sort.length > 0){
//The default sort attribute is 'date-posted'
if(!query.sort[0].attribute){
query.sort[0].attribute = "date-posted";
}
//If the sort attribute is valid, check if it is ascending or
//descending.
if(this._sortAttributes[query.sort[0].attribute]) {
if(query.sort[0].descending){
content.sort = query.sort[0].attribute + "-desc";
} else {
content.sort = query.sort[0].attribute + "-asc";
}
}
} else {
//The default sort in the Dojo Data API is ascending.
content.sort = "date-posted-asc";
}
primaryKey.push("sort:"+content.sort);
//Generate a unique key for this request, so the store can
//detect duplicate requests.
primaryKey = primaryKey.join(".");
secondaryKey = secondaryKey.length > 0 ? "." + secondaryKey.join(".") : "";
var requestKey = primaryKey + secondaryKey;
//Make a copy of the request, in case the source object is modified
//before the request completes
request = {
query: query,
count: request._curCount,
start: request._curStart,
_realCount: request._realCount,
_realStart: request._realStart,
onBegin: request.onBegin,
onComplete: request.onComplete,
onItem: request.onItem
};
 
var thisHandler = {
request: request,
fetchHandler: fetchHandler,
errorHandler: errorHandler
};
 
//If the request has already been made, but not yet completed,
//then add the callback handler to the list of handlers
//for this request, and finish.
if(this._handlers[requestKey]){
this._handlers[requestKey].push(thisHandler);
return;
}
 
this._handlers[requestKey] = [thisHandler];
 
//Linking this up to Flickr is a PAIN!
var self = this;
var handle = null;
var getArgs = {
url: this._flickrRestUrl,
preventCache: true,
content: content
};
var doHandle = function(processedData, data, handler){
var onBegin = handler.request.onBegin;
handler.request.onBegin = null;
var maxPhotos;
var req = handler.request;
if(typeof(req._realStart) != undefined && req._realStart != null) {
req.start = req._realStart;
req.count = req._realCount;
req._realStart = req._realCount = null;
}
 
//If the request contains an onBegin method, the total number
//of photos must be calculated.
if(onBegin){
if(data && typeof(data.photos.perpage) != "undefined" && typeof(data.photos.pages) != "undefined"){
if(data.photos.perpage * data.photos.pages <= handler.request.start + handler.request.count){
//If the final page of results has been received, it is possible to
//know exactly how many photos there are
maxPhotos = handler.request.start + data.photos.photo.length;
}else{
//If the final page of results has not yet been received,
//it is not possible to tell exactly how many photos exist, so
//return the number of pages multiplied by the number of photos per page.
maxPhotos = data.photos.perpage * data.photos.pages;
}
self._maxPhotosPerUser[primaryKey] = maxPhotos;
onBegin(maxPhotos, handler.request);
} else if(self._maxPhotosPerUser[primaryKey]) {
onBegin(self._maxPhotosPerUser[primaryKey], handler.request);
}
}
//Call whatever functions the caller has defined on the request object, except for onBegin
handler.fetchHandler(processedData, handler.request);
if(onBegin){
//Replace the onBegin function, if it existed.
handler.request.onBegin = onBegin;
}
};
//Define a callback for the script that iterates through a list of
//handlers for this piece of data. Multiple requests can come into
//the store for the same data.
var myHandler = function(data){
//The handler should not be called more than once, so disconnect it.
//if(handle !== null){ dojo.disconnect(handle); }
if(data.stat != "ok"){
errorHandler(null, request);
}else{ //Process the items...
var handlers = self._handlers[requestKey];
if(!handlers){
console.log("FlickrRestStore: no handlers for data", data);
return;
}
 
self._handlers[requestKey] = null;
self._prevRequests[requestKey] = data;
 
//Process the data once.
var processedData = self._processFlickrData(data, request, primaryKey);
if(!self._prevRequestRanges[primaryKey]) {
self._prevRequestRanges[primaryKey] = [];
}
self._prevRequestRanges[primaryKey].push({
start: request.start,
end: request.start + data.photos.photo.length
});
 
//Iterate through the array of handlers, calling each one.
for(var i = 0; i < handlers.length; i++ ){
doHandle(processedData, data, handlers[i]);
}
}
};
 
var data = this._prevRequests[requestKey];
//If the data was previously retrieved, there is no need to fetch it again.
if(data){
this._handlers[requestKey] = null;
doHandle(this._cache[primaryKey], data, thisHandler);
return;
} else if(this._checkPrevRanges(primaryKey, request.start, request.count)) {
//If this range of data has already been retrieved, reuse it.
this._handlers[requestKey] = null;
doHandle(this._cache[primaryKey], null, thisHandler);
return;
}
dojo.global[callbackFn] = function(data){
myHandler(data);
//Clean up the function, it should never be called again
dojo.global[callbackFn] = null;
};
var deferred = dojo.io.script.get(getArgs);
//We only set up the errback, because the callback isn't ever really used because we have
//to link to the jsonFlickrFeed function....
deferred.addErrback(function(error){
dojo.disconnect(handle);
errorHandler(error, request);
});
},
getAttributes: function(item){
// summary:
// See dojo.data.api.Read.getAttributes()
return ["title", "author", "imageUrl", "imageUrlSmall",
"imageUrlMedium", "imageUrlThumb", "link",
"dateTaken", "datePublished"];
},
getValues: function(item, attribute){
// summary:
// See dojo.data.api.Read.getValue()
this._assertIsItem(item);
this._assertIsAttribute(attribute);
if(attribute === "title"){
return [this._unescapeHtml(item.title)]; // String
}else if(attribute === "author"){
return [item.ownername]; // String
}else if(attribute === "imageUrlSmall"){
return [item.media.s]; // String
}else if(attribute === "imageUrl"){
return [item.media.l]; // String
}else if(attribute === "imageUrlMedium"){
return [item.media.m]; // String
}else if(attribute === "imageUrlThumb"){
return [item.media.t]; // String
}else if(attribute === "link"){
return ["http://www.flickr.com/photos/" + item.owner + "/" + item.id]; // String
}else if(attribute === "dateTaken"){
return item.datetaken;
}else if(attribute === "datePublished"){
return item.datepublished;
}
return undefined;
},
 
_processFlickrData: function(/* Object */data, /* Object */request, /* String */ cacheKey){
// summary: Processes the raw data from Flickr and updates the internal cache.
// data:
// Data returned from Flickr
// request:
// The original dojo.data.Request object passed in by the user.
//If the data contains an 'item' object, it has not come from the REST services,
//so process it using the FlickrStore.
if(data.items){
return dojox.data.FlickrStore.prototype._processFlickrData.apply(this,arguments);
}
 
var template = ["http://farm", null, ".static.flickr.com/", null, "/", null, "_", null];
var items = [];
if(data.stat == "ok" && data.photos && data.photos.photo){
items = data.photos.photo;
//Add on the store ref so that isItem can work.
for(var i = 0; i < items.length; i++){
var item = items[i];
item[this._storeRef] = this;
template[1] = item.farm;
template[3] = item.server;
template[5] = item.id;
template[7] = item.secret;
var base = template.join("");
item.media = {
s: base + "_s.jpg",
m: base + "_m.jpg",
l: base + ".jpg",
t: base + "_t.jpg"
};
}
}
var start = request.start ? request.start : 0;
var arr = this._cache[cacheKey];
if(!arr) {
this._cache[cacheKey] = arr = [];
}
for(var count = 0; count < items.length; count++){
arr[count + start] = items[count];
}
 
return arr; // Array
},
_checkPrevRanges: function(primaryKey, start, count) {
var end = start + count;
var arr = this._prevRequestRanges[primaryKey];
if(!arr) {
return false;
}
for(var i = 0; i< arr.length; i++) {
if(start >= arr[i].start &&
end <= arr[i].end) {
return true;
}
}
return false;
}
});
 
 
}
/trunk/api/js/dojo1.0/dojox/data/FlickrStore.js
New file
0,0 → 1,257
if(!dojo._hasResource["dojox.data.FlickrStore"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.data.FlickrStore"] = true;
dojo.provide("dojox.data.FlickrStore");
 
dojo.require("dojo.data.util.simpleFetch");
dojo.require("dojo.io.script");
dojo.require("dojo.date.stamp");
 
dojo.declare("dojox.data.FlickrStore", null, {
constructor: function(/*Object*/args){
// summary:
// Initializer for the FlickrStore store.
// description:
// The FlickrStore is a Datastore interface to one of the basic services
// of the Flickr service, the public photo feed. This does not provide
// access to all the services of Flickr.
// This store cannot do * and ? filtering as the flickr service
// provides no interface for wildcards.
if(args && args.label){
this.label = args.label;
}
},
 
_flickrUrl: "http://api.flickr.com/services/feeds/photos_public.gne",
 
_storeRef: "_S",
 
label: "title",
 
_assertIsItem: function(/* item */ item){
// summary:
// This function tests whether the item passed in is indeed an item in the store.
// item:
// The item to test for being contained by the store.
if(!this.isItem(item)){
throw new Error("dojox.data.FlickrStore: a function was passed an item argument that was not an item");
}
},
 
_assertIsAttribute: function(/* attribute-name-string */ attribute){
// summary:
// This function tests whether the item passed in is indeed a valid 'attribute' like type for the store.
// attribute:
// The attribute to test for being contained by the store.
if(typeof attribute !== "string"){
throw new Error("dojox.data.FlickrStore: a function was passed an attribute argument that was not an attribute name string");
}
},
 
getFeatures: function(){
// summary:
// See dojo.data.api.Read.getFeatures()
return {
'dojo.data.api.Read': true
};
},
 
getValue: function(item, attribute){
// summary:
// See dojo.data.api.Read.getValue()
var values = this.getValues(item, attribute);
if(values){
return values[0];
}
return undefined;
},
 
getAttributes: function(item){
// summary:
// See dojo.data.api.Read.getAttributes()
return ["title", "description", "author", "datePublished", "dateTaken", "imageUrl", "imageUrlSmall", "imageUrlMedium", "tags", "link"];
},
 
hasAttribute: function(item, attribute){
// summary:
// See dojo.data.api.Read.hasAttributes()
if(this.getValue(item,attribute)){
return true;
}
return false;
},
 
isItemLoaded: function(item){
// summary:
// See dojo.data.api.Read.isItemLoaded()
return this.isItem(item);
},
 
loadItem: function(keywordArgs){
// summary:
// See dojo.data.api.Read.loadItem()
},
 
getLabel: function(item){
// summary:
// See dojo.data.api.Read.getLabel()
return this.getValue(item,this.label);
},
getLabelAttributes: function(item){
// summary:
// See dojo.data.api.Read.getLabelAttributes()
return [this.label];
},
 
containsValue: function(item, attribute, value){
// summary:
// See dojo.data.api.Read.containsValue()
var values = this.getValues(item,attribute);
for(var i = 0; i < values.length; i++){
if(values[i] === value){
return true;
}
}
return false;
},
 
getValues: function(item, attribute){
// summary:
// See dojo.data.api.Read.getValue()
 
this._assertIsItem(item);
this._assertIsAttribute(attribute);
if(attribute === "title"){
return [this._unescapeHtml(item.title)];
}else if(attribute === "author"){
return [this._unescapeHtml(item.author)];
}else if(attribute === "datePublished"){
return [dojo.date.stamp.fromISOString(item.published)];
}else if(attribute === "dateTaken"){
return [dojo.date.stamp.fromISOString(item.date_taken)];
}else if(attribute === "imageUrlSmall"){
return [item.media.m.replace(/_m\./, "_s.")];
}else if(attribute === "imageUrl"){
return [item.media.m.replace(/_m\./, ".")];
}else if(attribute === "imageUrlMedium"){
return [item.media.m];
}else if(attribute === "link"){
return [item.link];
}else if(attribute === "tags"){
return item.tags.split(" ");
}else if(attribute === "description"){
return [this._unescapeHtml(item.description)];
}
return undefined;
},
 
isItem: function(item){
// summary:
// See dojo.data.api.Read.isItem()
if(item && item[this._storeRef] === this){
return true;
}
return false;
},
close: function(request){
// summary:
// See dojo.data.api.Read.close()
},
 
_fetchItems: function(request, fetchHandler, errorHandler){
// summary:
// Fetch flickr items that match to a query
// request:
// A request object
// fetchHandler:
// A function to call for fetched items
// errorHandler:
// A function to call on error
 
if(!request.query){
request.query={};
}
 
//Build up the content to send the request for.
var content = {format: "json", tagmode:"any"};
if (request.query.tags) {
content.tags = request.query.tags;
}
if (request.query.tagmode) {
content.tagmode = request.query.tagmode;
}
if (request.query.userid) {
content.id = request.query.userid;
}
if (request.query.userids) {
content.ids = request.query.userids;
}
if (request.query.lang) {
content.lang = request.query.lang;
}
 
//Linking this up to Flickr is a PAIN!
var self = this;
var handle = null;
var getArgs = {
url: this._flickrUrl,
preventCache: true,
content: content
};
var myHandler = function(data){
if(handle !== null){
dojo.disconnect(handle);
}
 
//Process the items...
fetchHandler(self._processFlickrData(data), request);
};
handle = dojo.connect("jsonFlickrFeed", myHandler);
var deferred = dojo.io.script.get(getArgs);
//We only set up the errback, because the callback isn't ever really used because we have
//to link to the jsonFlickrFeed function....
deferred.addErrback(function(error){
dojo.disconnect(handle);
errorHandler(error, request);
});
},
 
_processFlickrData: function(data){
var items = [];
if(data.items){
items = data.items;
//Add on the store ref so that isItem can work.
for(var i = 0; i < data.items.length; i++){
var item = data.items[i];
item[this._storeRef] = this;
}
}
return items;
},
 
_unescapeHtml: function(str){
// summary: Utility function to un-escape XML special characters in an HTML string.
// description: Utility function to un-escape XML special characters in an HTML string.
//
// str: String.
// The string to un-escape
// returns: HTML String converted back to the normal text (unescaped) characters (<,>,&, ", etc,).
//
//TODO: Check to see if theres already compatible escape() in dojo.string or dojo.html
str = str.replace(/&amp;/gm, "&").replace(/&lt;/gm, "<").replace(/&gt;/gm, ">").replace(/&quot;/gm, "\"");
str = str.replace(/&#39;/gm, "'");
return str;
}
});
dojo.extend(dojox.data.FlickrStore,dojo.data.util.simpleFetch);
//We have to define this because of how the Flickr API works.
//This somewhat stinks, but what can you do?
if (!jsonFlickrFeed) {
var jsonFlickrFeed = function(data){};
}
 
 
}
/trunk/api/js/dojo1.0/dojox/data/tests/ml/test_HtmlTableStore_declaratively.html
New file
0,0 → 1,120
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Dojox HtmlDataStore Widget</title>
<style>
@import "../../../../dijit/themes/tundra/tundra.css";
@import "../../../../dojo/resources/dojo.css";
@import "../../../../dijit/tests/css/dijitTests.css";
</style>
<script type="text/javascript">
djConfig = {
isDebug: true,
parseOnLoad: true
};
</script>
<script type="text/javascript" src="../../../../dojo/dojo.js"></script>
<!--
<script language="JavaScript" type="text/javascript">
dojo.require("doh.runner");
function registerTests() {
doh.register("t",
[
function testTableLoaded(t){
t.assertTrue(tableStore !== null);
t.assertTrue(tableStore !== undefined);
}
]
);
doh.run();
};
dojo.addOnLoad(registerTests);
</script>
-->
 
<script language="JavaScript" type="text/javascript">
dojo.require("dojo.parser");
dojo.require("dojox.data.HtmlTableStore");
dojo.require("dijit.Tree");
function init() {
var table = tableStore;
function testComplete(items, request){
console.debug("Completed!");
 
var attributes = null;
for(var i = 0; i < items.length; i++){
attributes = table.getAttributes(items[i]);
for(var j=0; j < attributes.length; j++){
console.debug("attribute: [" + attributes[j] + "] have value: " + table.getValue(items[i], attributes[j]));
}
}
}
table.fetch({query:{X:1}, onComplete: testComplete});
table.fetch({query:{X:2}, onComplete: testComplete});
table.fetch({query:{X:3}, onComplete: testComplete});
table.fetch({query:{X:4}, onComplete: testComplete});
table.fetch({query:{X:5}, onComplete: testComplete}); // Should be empty
}
dojo.addOnLoad(init);
</script>
 
</head>
<body class="tundra">
<h1>Dojox HtmlDataStore Widget</h1>
<hr/>
<br/>
<br/>
 
<!-- Instantiate the HtmlTableStore and bind it to global name tableStore -->
<div dojoType="dojox.data.HtmlTableStore" tableId="tableExample" jsId="tableStore"></div>
 
<!-- The table to link into with the HtmlTableStore-->
<table id="tableExample">
<thead>
<tr>
<th>X</th>
<th>Y</th>
<th>A</th>
<th>B</th>
</tr>
</thead>
<tbody>
<tr id="test">
<td>2</td>
<td>3</td>
<td></td>
<td>8</td>
</tr>
<tr>
<td>1</td>
<td>3</td>
<td>5</td>
<td>7</td>
</tr>
<tr>
<td>4</td>
<td>9</td>
<td>22</td>
<td>777</td>
</tr>
<tr>
<td>3231</td>
<td>3</td>
<td>535</td>
<td>747</td>
</tr>
 
</tbody>
</table>
 
<br/>
<br/>
<blockquote>
<b>Table Rows: <br/><i>(Just to show that the tree can determine that the tableStore works like a store).<br/>Should have three branches, where the row had attr Y value of 3.</i></b>
<div dojoType="dijit.Tree" id="tree" store="tableStore" query="{Y:3}" label="Test tree"></div>
</blockquote>
</body>
</html>
/trunk/api/js/dojo1.0/dojox/data/tests/dom.js
New file
0,0 → 1,133
if(!dojo._hasResource["dojox.data.tests.dom"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.data.tests.dom"] = true;
dojo.provide("dojox.data.tests.dom");
dojo.require("dojox.data.dom");
 
tests.register("dojox.data.tests.dom",
[
function testCreateDocument(t){
var document = dojox.data.dom.createDocument();
t.assertTrue(document !== null);
},
function testCreateDocumentFromText(t){
var simpleXml = "<parentNode><childNode><grandchildNode/></childNode><childNode/></parentNode>";
var document = dojox.data.dom.createDocument(simpleXml, "text/xml");
var parent = document.firstChild;
t.assertTrue(parent !== null);
t.assertTrue(parent.tagName === "parentNode");
t.assertTrue(parent.childNodes.length == 2);
var firstChild = parent.firstChild;
t.assertTrue(firstChild !== null);
t.assertTrue(firstChild.tagName === "childNode");
t.assertTrue(firstChild.childNodes.length == 1);
var secondChild = firstChild.nextSibling;
t.assertTrue(secondChild !== null);
t.assertTrue(secondChild.tagName === "childNode");
 
var grandChild = firstChild.firstChild;
t.assertTrue(grandChild !== null);
t.assertTrue(grandChild.tagName === "grandchildNode");
 
},
function testReadTextContent(t){
var text = "This is a bunch of child text on the node";
var simpleXml = "<parentNode>" + text + "</parentNode>";
var document = dojox.data.dom.createDocument(simpleXml, "text/xml");
var topNode = document.firstChild;
t.assertTrue(topNode !== null);
t.assertTrue(topNode.tagName === "parentNode");
t.assertTrue(text === dojox.data.dom.textContent(topNode));
dojo._destroyElement(topNode);
t.assertTrue(document.firstChild === null);
},
function testSetTextContent(t){
var text = "This is a bunch of child text on the node";
var text2 = "This is the new text";
var simpleXml = "<parentNode>" + text + "</parentNode>";
var document = dojox.data.dom.createDocument(simpleXml, "text/xml");
var topNode = document.firstChild;
t.assertTrue(topNode !== null);
t.assertTrue(topNode.tagName === "parentNode");
t.assertTrue(text === dojox.data.dom.textContent(topNode));
dojox.data.dom.textContent(topNode, text2);
t.assertTrue(text2 === dojox.data.dom.textContent(topNode));
dojo._destroyElement(topNode);
t.assertTrue(document.firstChild === null);
 
},
function testReplaceChildrenArray(t){
var simpleXml1 = "<parentNode><child1/><child2/><child3/></parentNode>";
var simpleXml2 = "<parentNode><child4/><child5/><child6/><child7/></parentNode>";
var doc1 = dojox.data.dom.createDocument(simpleXml1, "text/xml");
var doc2 = dojox.data.dom.createDocument(simpleXml2, "text/xml");
var topNode1 = doc1.firstChild;
var topNode2 = doc2.firstChild;
t.assertTrue(topNode1 !== null);
t.assertTrue(topNode1.tagName === "parentNode");
t.assertTrue(topNode2 !== null);
t.assertTrue(topNode2.tagName === "parentNode");
dojox.data.dom.removeChildren(topNode1);
var newChildren=[];
for(var i=0;i<topNode2.childNodes.length;i++){
newChildren.push(topNode2.childNodes[i]);
}
dojox.data.dom.removeChildren(topNode2);
dojox.data.dom.replaceChildren(topNode1,newChildren);
t.assertTrue(topNode1.childNodes.length === 4);
t.assertTrue(topNode1.firstChild.tagName === "child4");
t.assertTrue(topNode1.lastChild.tagName === "child7");
 
},
function testReplaceChildrenSingle(t){
var simpleXml1 = "<parentNode><child1/><child2/><child3/></parentNode>";
var simpleXml2 = "<parentNode><child4/></parentNode>";
var doc1 = dojox.data.dom.createDocument(simpleXml1, "text/xml");
var doc2 = dojox.data.dom.createDocument(simpleXml2, "text/xml");
var topNode1 = doc1.firstChild;
var topNode2 = doc2.firstChild;
t.assertTrue(topNode1 !== null);
t.assertTrue(topNode1.tagName === "parentNode");
t.assertTrue(topNode2 !== null);
t.assertTrue(topNode2.tagName === "parentNode");
dojox.data.dom.removeChildren(topNode1);
var newChildren = topNode2.firstChild;
dojox.data.dom.removeChildren(topNode2);
dojox.data.dom.replaceChildren(topNode1,newChildren);
t.assertTrue(topNode1.childNodes.length === 1);
t.assertTrue(topNode1.firstChild.tagName === "child4");
t.assertTrue(topNode1.lastChild.tagName === "child4");
},
function testRemoveChildren(t){
var simpleXml1 = "<parentNode><child1/><child2/><child3/></parentNode>";
var doc1 = dojox.data.dom.createDocument(simpleXml1, "text/xml");
var topNode1 = doc1.firstChild;
t.assertTrue(topNode1 !== null);
t.assertTrue(topNode1.tagName === "parentNode");
dojox.data.dom.removeChildren(topNode1);
t.assertTrue(topNode1.childNodes.length === 0);
t.assertTrue(topNode1.firstChild === null);
},
function testInnerXML(t){
var simpleXml1 = "<parentNode><child1/><child2/><child3/></parentNode>";
var doc1 = dojox.data.dom.createDocument(simpleXml1, "text/xml");
var topNode1 = doc1.firstChild;
t.assertTrue(topNode1 !== null);
t.assertTrue(topNode1.tagName === "parentNode");
 
var innerXml = dojox.data.dom.innerXML(topNode1);
t.assertTrue(simpleXml1 === innerXml);
}
]
);
 
}
/trunk/api/js/dojo1.0/dojox/data/tests/runTests.html
New file
0,0 → 1,9
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Dojox Unit Test Runner</title>
<meta http-equiv="REFRESH" content="0;url=../../../util/doh/runner.html?testModule=dojox.data.tests.module"></HEAD>
<BODY>
Redirecting to D.O.H runner.
</BODY>
</HTML>
/trunk/api/js/dojo1.0/dojox/data/tests/stores/movies2.csv
New file
0,0 → 1,9
Title, Year, Producer
City of God, 2002, Katia Lund
Rain,"", Christine Jeffs
2001: A Space Odyssey, , Stanley Kubrick
"This is a ""fake"" movie title", 1957, Sidney Lumet
Alien, 1979 , Ridley Scott
"The Sequel to ""Dances With Wolves.""", 1982, Ridley Scott
"Caine Mutiny, The", 1954, "Dymtryk ""the King"", Edward"
 
/trunk/api/js/dojo1.0/dojox/data/tests/stores/geography_withspeciallabel.xml
New file
0,0 → 1,51
<?xml version="1.0" encoding="ISO-8859-1"?>
<opml version="1.0">
<head>
<title>geography.opml</title>
<dateCreated>2006-11-10</dateCreated>
<dateModified>2006-11-13</dateModified>
<ownerName>Magellan, Ferdinand</ownerName>
</head>
<body>
<outline text="Africa" type="continent" label="Continent/Africa">
<outline text="Egypt" type="country" label="Country/Egypt"/>
<outline text="Kenya" type="country" label="Country/Kenya">
<outline text="Nairobi" type="city" label="City/Nairobi"/>
<outline text="Mombasa" type="city" label="City/Mombasa"/>
</outline>
<outline text="Sudan" type="country" label="Country/Sudan">
<outline text="Khartoum" type="city" label="City/Khartoum"/>
</outline>
</outline>
<outline text="Asia" type="continent" label="Continent/Asia">
<outline text="China" type="country" label="Country/China"/>
<outline text="India" type="country" label="Country/India"/>
<outline text="Russia" type="country" label="Country/Russia"/>
<outline text="Mongolia" type="country" label="Country/Mongolia"/>
</outline>
<outline text="Australia" type="continent" population="21 million" label="Continent/Australia">
<outline text="Australia" type="country" population="21 million" label="Country/Australia"/>
</outline>
<outline text="Europe" type="continent" label="Contintent/Europe">
<outline text="Germany" type="country" label="Country/Germany"/>
<outline text="France" type="country" label="Country/France"/>
<outline text="Spain" type="country" label="Country/Spain"/>
<outline text="Italy" type="country" label="Country/Italy"/>
</outline>
<outline text="North America" type="continent" label="Continent/North America">
<outline text="Mexico" type="country" population="108 million" area="1,972,550 sq km" label="Country/Mexico">
<outline text="Mexico City" type="city" population="19 million" timezone="-6 UTC" label="City/Mexico City"/>
<outline text="Guadalajara" type="city" population="4 million" timezone="-6 UTC" label="City/Guadalajara"/>
</outline>
<outline text="Canada" type="country" population="33 million" area="9,984,670 sq km" label="Country/Canada">
<outline text="Ottawa" type="city" population="0.9 million" timezone="-5 UTC" label="City/Ottawa"/>
<outline text="Toronto" type="city" population="2.5 million" timezone="-5 UTC" label="City/Toronto"/>
</outline>
<outline text="United States of America" type="country" label="Country/United States of America"/>
</outline>
<outline text="South America" type="continent" label="Continent/South America">
<outline text="Brazil" type="country" population="186 million" label="Country/Brazil"/>
<outline text="Argentina" type="country" population="40 million" label="Country/Argentina"/>
</outline>
</body>
</opml>
/trunk/api/js/dojo1.0/dojox/data/tests/stores/books.html
New file
0,0 → 1,118
<html>
<head>
<title>Books2.html</title>
</head>
<body>
<table id="books">
<thead>
<tr>
<th>isbn</th>
<th>title</th>
<th>author</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Title of 1</td>
<td>Author of 1</td>
</tr>
<tr>
<td>2</td>
<td>Title of 2</td>
<td>Author of 2</td>
</tr>
<tr>
<td>3</td>
<td>Title of 3</td>
<td>Author of 3</td>
</tr>
<tr>
<td>4</td>
<td>Title of 4</td>
<td>Author of 4</td>
</tr>
<tr>
<td>5</td>
<td>Title of 5</td>
<td>Author of 5</td>
</tr>
<tr>
<td>6</td>
<td>Title of 6</td>
<td>Author of 6</td>
</tr>
<tr>
<td>7</td>
<td>Title of 7</td>
<td>Author of 7</td>
</tr>
<tr>
<td>8</td>
<td>Title of 8</td>
<td>Author of 8</td>
</tr>
<tr>
<td>9</td>
<td>Title of 9</td>
<td>Author of 9</td>
</tr>
<tr>
<td>10</td>
<td>Title of 10</td>
<td>Author of 10</td>
</tr>
<tr>
<td>11</td>
<td>Title of 11</td>
<td>Author of 11</td>
</tr>
<tr>
<td>12</td>
<td>Title of 12</td>
<td>Author of 12</td>
</tr>
<tr>
<td>13</td>
<td>Title of 13</td>
<td>Author of 13</td>
</tr>
<tr>
<td>14</td>
<td>Title of 14</td>
<td>Author of 14</td>
</tr>
<tr>
<td>15</td>
<td>Title of 15</td>
<td>Author of 15</td>
</tr>
<tr>
<td>16</td>
<td>Title of 16</td>
<td>Author of 16</td>
</tr>
<tr>
<td>17</td>
<td>Title of 17</td>
<td>Author of 17</td>
</tr>
<tr>
<td>18</td>
<td>Title of 18</td>
<td>Author of 18</td>
</tr>
<tr>
<td>19</td>
<td>Title of 19</td>
<td>Author of 19</td>
</tr>
<tr>
<td>20</td>
<td>Title of 20</td>
<td>Author of 20</td>
</tr>
</tbody>
</table>
</body>
</html>
/trunk/api/js/dojo1.0/dojox/data/tests/stores/books_isbnAttr.xml
New file
0,0 → 1,23
<?xml version="1.0" encoding="ISO-8859-1"?>
<books>
<book isbn="1">
<title>Title of 1</title>
<author>Author of 1</author>
</book>
<book isbn="2">
<title>Title of 2</title>
<author>Author of 2</author>
</book>
<book isbn="3">
<title>Title of 3</title>
<author>Author of 3</author>
</book>
<book isbn="4">
<title>Title of 4</title>
<author>Author of 4</author>
</book>
<book isbn="5">
<title>Title of 5</title>
<author>Author of 5</author>
</book>
</books>
/trunk/api/js/dojo1.0/dojox/data/tests/stores/CsvStore.js
New file
0,0 → 1,1127
if(!dojo._hasResource["dojox.data.tests.stores.CsvStore"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.data.tests.stores.CsvStore"] = true;
dojo.provide("dojox.data.tests.stores.CsvStore");
dojo.require("dojox.data.CsvStore");
dojo.require("dojo.data.api.Read");
dojo.require("dojo.data.api.Identity");
 
dojox.data.tests.stores.CsvStore.getDatasource = function(filepath){
// summary:
// A simple helper function for getting the sample data used in each of the tests.
// description:
// A simple helper function for getting the sample data used in each of the tests.
 
var dataSource = {};
if(dojo.isBrowser){
dataSource.url = dojo.moduleUrl("dojox.data.tests", filepath).toString();
}else{
// When running tests in Rhino, xhrGet is not available,
// so we have the file data in the code below.
switch(filepath){
case "stores/movies.csv":
var csvData = "";
csvData += "Title, Year, Producer\n";
csvData += "City of God, 2002, Katia Lund\n";
csvData += "Rain,, Christine Jeffs\n";
csvData += "2001: A Space Odyssey, 1968, Stanley Kubrick\n";
csvData += '"This is a ""fake"" movie title", 1957, Sidney Lumet\n';
csvData += "Alien, 1979 , Ridley Scott\n";
csvData += '"The Sequel to ""Dances With Wolves.""", 1982, Ridley Scott\n';
csvData += '"Caine Mutiny, The", 1954, "Dymtryk ""the King"", Edward"\n';
break;
case "stores/movies2.csv":
var csvData = "";
csvData += "Title, Year, Producer\n";
csvData += "City of God, 2002, Katia Lund\n";
csvData += "Rain,\"\", Christine Jeffs\n";
csvData += "2001: A Space Odyssey, 1968, Stanley Kubrick\n";
csvData += '"This is a ""fake"" movie title", 1957, Sidney Lumet\n';
csvData += "Alien, 1979 , Ridley Scott\n";
csvData += '"The Sequel to ""Dances With Wolves.""", 1982, Ridley Scott\n';
csvData += '"Caine Mutiny, The", 1954, "Dymtryk ""the King"", Edward"\n';
break;
case "stores/books.csv":
var csvData = "";
csvData += "Title, Author\n";
csvData += "The Transparent Society, David Brin\n";
csvData += "The First Measured Century, Theodore Caplow\n";
csvData += "Maps in a Mirror, Orson Scott Card\n";
csvData += "Princess Smartypants, Babette Cole\n";
csvData += "Carfree Cities, Crawford J.H.\n";
csvData += "Down and Out in the Magic Kingdom, Cory Doctorow\n";
csvData += "Tax Shift, Alan Thein Durning\n";
csvData += "The Sneetches and other stories, Dr. Seuss\n";
csvData += "News from Tartary, Peter Fleming\n";
break;
case "stores/patterns.csv":
var csvData = "";
csvData += "uniqueId, value\n";
csvData += "9, jfq4@#!$!@Rf14r14i5u\n";
csvData += "6, BaBaMaSaRa***Foo\n";
csvData += "2, bar*foo\n";
csvData += "8, 123abc\n";
csvData += "4, bit$Bite\n";
csvData += "3, 123abc\n";
csvData += "10, 123abcdefg\n";
csvData += "1, foo*bar\n";
csvData += "7, \n";
csvData += "5, 123abc\n"
break;
}
dataSource.data = csvData;
}
return dataSource; //Object
}
 
dojox.data.tests.stores.CsvStore.verifyItems = function(csvStore, items, attribute, compareArray){
// summary:
// A helper function for validating that the items array is ordered
// the same as the compareArray
if(items.length != compareArray.length){ return false; }
for(var i = 0; i < items.length; i++){
if(!(csvStore.getValue(items[i], attribute) === compareArray[i])){
return false; //Boolean
}
}
return true; //Boolean
}
 
dojox.data.tests.stores.CsvStore.error = function(t, d, errData){
// summary:
// The error callback function to be used for all of the tests.
for (i in errData) {
console.log(errData[i]);
}
d.errback(errData);
}
 
doh.register("dojox.data.tests.stores.CsvStore",
[
function testReadAPI_fetch_all(t){
// summary:
// Simple test of a basic fetch on CsvStore.
// description:
// Simple test of a basic fetch on CsvStore.
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
var csvStore = new dojox.data.CsvStore(args);
var d = new doh.Deferred();
function completedAll(items){
t.assertTrue((items.length === 7));
d.callback(true);
}
 
//Get everything...
csvStore.fetch({ onComplete: completedAll, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d; //Object
},
function testReadAPI_fetch_all_withEmptyStringField(t){
// summary:
// Simple test of a basic fetch on CsvStore.
// description:
// Simple test of a basic fetch on CsvStore.
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies2.csv");
var csvStore = new dojox.data.CsvStore(args);
var d = new doh.Deferred();
function completedAll(items){
t.assertTrue((items.length === 7));
d.callback(true);
}
 
//Get everything...
csvStore.fetch({ onComplete: completedAll, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d; //Object
},
function testReadAPI_fetch_one(t){
// summary:
// Simple test of a basic fetch on CsvStore of a single item.
// description:
// Simple test of a basic fetch on CsvStore of a single item.
 
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
var csvStore = new dojox.data.CsvStore(args);
var d = new doh.Deferred();
function onComplete(items, request){
t.is(1, items.length);
d.callback(true);
}
csvStore.fetch({ query: {Title: "*Sequel*"},
onComplete: onComplete,
onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)
});
return d; //Object
},
function testReadAPI_fetch_Multiple(t){
// summary:
// Simple test of a basic fetch on CsvStore of a single item.
// description:
// Simple test of a basic fetch on CsvStore of a single item.
 
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
var csvStore = new dojox.data.CsvStore(args);
var d = new doh.Deferred();
 
var done = [false, false];
 
function onCompleteOne(items, request){
done[0] = true;
t.is(1, items.length);
if(done[0] && done[1]){
d.callback(true);
}
}
function onCompleteTwo(items, request){
done[1] = true;
t.is(1, items.length);
if(done[0] && done[1]){
d.callback(true);
}
}
try
{
csvStore.fetch({ query: {Title: "*Sequel*"},
onComplete: onCompleteOne,
onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)
});
csvStore.fetch({ query: {Title: "2001:*"},
onComplete: onCompleteTwo,
onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)
});
}
catch(e)
{
for (i in e) {
console.log(e[i]);
}
}
 
return d; //Object
},
function testReadAPI_fetch_MultipleMixed(t){
// summary:
// Simple test of a basic fetch on CsvStore of a single item.
// description:
// Simple test of a basic fetch on CsvStore of a single item.
 
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
var csvStore = new dojox.data.CsvStore(args);
var d = new doh.Deferred();
 
var done = [false, false];
function onComplete(items, request){
done[0] = true;
t.is(1, items.length);
if(done[0] && done[1]){
d.callback(true);
}
}
function onItem(item){
done[1] = true;
t.assertTrue(item !== null);
t.is('Dymtryk "the King", Edward', csvStore.getValue(item,"Producer"));
t.is('Caine Mutiny, The', csvStore.getValue(item,"Title"));
if(done[0] && done[1]){
d.callback(true);
}
}
 
csvStore.fetch({ query: {Title: "*Sequel*"},
onComplete: onComplete,
onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)
});
csvStore.fetchItemByIdentity({identity: "6", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d; //Object
},
function testReadAPI_fetch_all_streaming(t){
// summary:
// Simple test of a basic fetch on CsvStore.
// description:
// Simple test of a basic fetch on CsvStore.
 
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
var csvStore = new dojox.data.CsvStore(args);
 
var d = new doh.Deferred();
count = 0;
 
function onBegin(size, requestObj){
t.assertTrue(size === 7);
}
function onItem(item, requestObj){
t.assertTrue(csvStore.isItem(item));
count++;
}
function onComplete(items, request){
t.is(7, count);
t.is(null, items);
d.callback(true);
}
 
//Get everything...
csvStore.fetch({ onBegin: onBegin,
onItem: onItem,
onComplete: onComplete,
onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)
});
return d; //Object
},
function testReadAPI_fetch_paging(t){
// summary:
// Test of multiple fetches on a single result. Paging, if you will.
// description:
// Test of multiple fetches on a single result. Paging, if you will.
 
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
var csvStore = new dojox.data.CsvStore(args);
var d = new doh.Deferred();
function dumpFirstFetch(items, request){
t.is(5, items.length);
request.start = 3;
request.count = 1;
request.onComplete = dumpSecondFetch;
csvStore.fetch(request);
}
 
function dumpSecondFetch(items, request){
t.is(1, items.length);
request.start = 0;
request.count = 5;
request.onComplete = dumpThirdFetch;
csvStore.fetch(request);
}
 
function dumpThirdFetch(items, request){
t.is(5, items.length);
request.start = 2;
request.count = 20;
request.onComplete = dumpFourthFetch;
csvStore.fetch(request);
}
 
function dumpFourthFetch(items, request){
t.is(5, items.length);
request.start = 9;
request.count = 100;
request.onComplete = dumpFifthFetch;
csvStore.fetch(request);
}
 
function dumpFifthFetch(items, request){
t.is(0, items.length);
request.start = 2;
request.count = 20;
request.onComplete = dumpSixthFetch;
csvStore.fetch(request);
}
 
function dumpSixthFetch(items, request){
t.is(5, items.length);
d.callback(true);
}
 
function completed(items, request){
t.is(7, items.length);
request.start = 1;
request.count = 5;
request.onComplete = dumpFirstFetch;
csvStore.fetch(request);
}
 
csvStore.fetch({onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d; //Object
 
},
function testReadAPI_getLabel(t){
// summary:
// Simple test of the getLabel function against a store set that has a label defined.
// description:
// Simple test of the getLabel function against a store set that has a label defined.
 
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
args.label = "Title";
var csvStore = new dojox.data.CsvStore(args);
var d = new doh.Deferred();
function onComplete(items, request){
t.assertEqual(items.length, 1);
var label = csvStore.getLabel(items[0]);
t.assertTrue(label !== null);
t.assertEqual("The Sequel to \"Dances With Wolves.\"", label);
d.callback(true);
}
csvStore.fetch({ query: {Title: "*Sequel*"},
onComplete: onComplete,
onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)
});
return d;
},
function testReadAPI_getLabelAttributes(t){
// summary:
// Simple test of the getLabelAttributes function against a store set that has a label defined.
// description:
// Simple test of the getLabelAttributes function against a store set that has a label defined.
 
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
args.label = "Title";
var csvStore = new dojox.data.CsvStore(args);
var d = new doh.Deferred();
function onComplete(items, request){
t.assertEqual(items.length, 1);
var labelList = csvStore.getLabelAttributes(items[0]);
t.assertTrue(dojo.isArray(labelList));
t.assertEqual("Title", labelList[0]);
d.callback(true);
}
csvStore.fetch({ query: {Title: "*Sequel*"},
onComplete: onComplete,
onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)
});
return d;
},
function testReadAPI_getValue(t){
// summary:
// Simple test of the getValue function of the store.
// description:
// Simple test of the getValue function of the store.
 
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
var csvStore = new dojox.data.CsvStore(args);
 
var d = new doh.Deferred();
function onItem(item){
t.assertTrue(item !== null);
t.is('Dymtryk "the King", Edward', csvStore.getValue(item,"Producer"));
t.is('Caine Mutiny, The', csvStore.getValue(item,"Title"));
d.callback(true);
}
csvStore.fetchItemByIdentity({identity: "6", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d;
},
function testReadAPI_getValue_2(t){
// summary:
// Simple test of the getValue function of the store.
// description:
// Simple test of the getValue function of the store.
 
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
var csvStore = new dojox.data.CsvStore(args);
 
var d = new doh.Deferred();
function onItem(item){
t.assertTrue(item !== null);
t.is("City of God", csvStore.getValue(item,"Title"));
t.is("2002", csvStore.getValue(item,"Year"));
d.callback(true);
}
csvStore.fetchItemByIdentity({identity: "0", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d;
},
function testReadAPI_getValue_3(t){
// summary:
// Simple test of the getValue function of the store.
// description:
// Simple test of the getValue function of the store.
 
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
var csvStore = new dojox.data.CsvStore(args);
 
var d = new doh.Deferred();
function onItem(item){
t.assertTrue(item !== null);
t.is("1979", csvStore.getValue(item,"Year"));
t.is("Alien", csvStore.getValue(item,"Title"));
d.callback(true);
}
csvStore.fetchItemByIdentity({identity: "4", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d;
},
function testReadAPI_getValue_4(t){
// summary:
// Simple test of the getValue function of the store.
// description:
// Simple test of the getValue function of the store.
 
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
var csvStore = new dojox.data.CsvStore(args);
 
var d = new doh.Deferred();
function onItem(item){
t.assertTrue(item !== null);
t.is("2001: A Space Odyssey", csvStore.getValue(item,"Title"));
t.is("Stanley Kubrick", csvStore.getValue(item,"Producer"));
d.callback(true);
}
csvStore.fetchItemByIdentity({identity: "2", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d;
},
 
function testReadAPI_getValues(t){
// summary:
// Simple test of the getValues function of the store.
// description:
// Simple test of the getValues function of the store.
 
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
var csvStore = new dojox.data.CsvStore(args);
 
var d = new doh.Deferred();
function onItem(item){
t.assertTrue(item !== null);
var names = csvStore.getValues(item,"Title");
t.assertTrue(dojo.isArray(names));
t.is(1, names.length);
t.is("Rain", names[0]);
d.callback(true);
}
csvStore.fetchItemByIdentity({identity: "1", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d;
},
function testIdentityAPI_fetchItemByIdentity(t){
// summary:
// Simple test of the fetchItemByIdentity function of the store.
// description:
// Simple test of the fetchItemByIdentity function of the store.
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
var csvStore = new dojox.data.CsvStore(args);
var d = new doh.Deferred();
function onItem(item){
t.assertTrue(item !== null);
d.callback(true);
}
csvStore.fetchItemByIdentity({identity: "1", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d;
},
 
function testIdentityAPI_fetchItemByIdentity_bad1(t){
// summary:
// Simple test of the fetchItemByIdentity function of the store.
// description:
// Simple test of the fetchItemByIdentity function of the store.
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
var csvStore = new dojox.data.CsvStore(args);
var d = new doh.Deferred();
function onItem(item){
t.assertTrue(item === null);
d.callback(true);
}
csvStore.fetchItemByIdentity({identity: "7", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d;
},
function testIdentityAPI_fetchItemByIdentity_bad2(t){
// summary:
// Simple test of the fetchItemByIdentity function of the store.
// description:
// Simple test of the fetchItemByIdentity function of the store.
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
var csvStore = new dojox.data.CsvStore(args);
var d = new doh.Deferred();
function onItem(item){
t.assertTrue(item === null);
d.callback(true);
}
csvStore.fetchItemByIdentity({identity: "-1", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d;
},
function testIdentityAPI_fetchItemByIdentity_bad3(t){
// summary:
// Simple test of the fetchItemByIdentity function of the store.
// description:
// Simple test of the fetchItemByIdentity function of the store.
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
var csvStore = new dojox.data.CsvStore(args);
var d = new doh.Deferred();
function onItem(item){
t.assertTrue(item === null);
d.callback(true);
}
csvStore.fetchItemByIdentity({identity: "999999", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d;
},
function testIdentityAPI_getIdentity(t){
// summary:
// Simple test of the fetchItemByIdentity function of the store.
// description:
// Simple test of the fetchItemByIdentity function of the store.
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
var csvStore = new dojox.data.CsvStore(args);
var d = new doh.Deferred();
function completed(items, request){
t.is(7, items.length);
var passed = true;
for(var i = 0; i < items.length; i++){
if(!(csvStore.getIdentity(items[i]) === i)){
passed=false;
break;
}
}
t.assertTrue(passed);
d.callback(true);
}
//Get everything...
csvStore.fetch({ onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d; //Object
},
function testIdentityAPI_getIdentityAttributes(t){
// summary:
// Simple test of the getIdentityAttributes
// description:
// Simple test of the fetchItemByIdentity function of the store.
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
var csvStore = new dojox.data.CsvStore(args);
 
var d = new doh.Deferred();
function onItem(item){
t.assertTrue(csvStore.isItem(item));
t.assertEqual(null, csvStore.getIdentityAttributes(item));
d.callback(true);
}
csvStore.fetchItemByIdentity({identity: "1", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d;
},
function testReadAPI_isItem(t){
// summary:
// Simple test of the isItem function of the store
// description:
// Simple test of the isItem function of the store
 
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
var csvStore = new dojox.data.CsvStore(args);
 
var d = new doh.Deferred();
function onItem(item){
t.assertTrue(csvStore.isItem(item));
t.assertTrue(!csvStore.isItem({}));
t.assertTrue(!csvStore.isItem({ item: "not an item" }));
t.assertTrue(!csvStore.isItem("not an item"));
t.assertTrue(!csvStore.isItem(["not an item"]));
d.callback(true);
}
csvStore.fetchItemByIdentity({identity: "1", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d;
},
function testReadAPI_hasAttribute(t){
// summary:
// Simple test of the hasAttribute function of the store
// description:
// Simple test of the hasAttribute function of the store
 
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
var csvStore = new dojox.data.CsvStore(args);
 
var d = new doh.Deferred();
function onItem(item){
t.assertTrue(item !== null);
t.assertTrue(csvStore.hasAttribute(item, "Title"));
t.assertTrue(csvStore.hasAttribute(item, "Producer"));
t.assertTrue(!csvStore.hasAttribute(item, "Year"));
t.assertTrue(!csvStore.hasAttribute(item, "Nothing"));
t.assertTrue(!csvStore.hasAttribute(item, "title"));
 
//Test that null attributes throw an exception
var passed = false;
try{
csvStore.hasAttribute(item, null);
}catch (e){
passed = true;
}
t.assertTrue(passed);
d.callback(true);
}
csvStore.fetchItemByIdentity({identity: "1", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d;
},
function testReadAPI_containsValue(t){
// summary:
// Simple test of the containsValue function of the store
// description:
// Simple test of the containsValue function of the store
 
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
var csvStore = new dojox.data.CsvStore(args);
var d = new doh.Deferred();
function onItem(item){
t.assertTrue(item !== null);
t.assertTrue(csvStore.containsValue(item, "Title", "Alien"));
t.assertTrue(csvStore.containsValue(item, "Year", "1979"));
t.assertTrue(csvStore.containsValue(item, "Producer", "Ridley Scott"));
t.assertTrue(!csvStore.containsValue(item, "Title", "Alien2"));
t.assertTrue(!csvStore.containsValue(item, "Year", "1979 "));
t.assertTrue(!csvStore.containsValue(item, "Title", null));
 
//Test that null attributes throw an exception
var passed = false;
try{
csvStore.containsValue(item, null, "foo");
}catch (e){
passed = true;
}
t.assertTrue(passed);
d.callback(true);
}
csvStore.fetchItemByIdentity({identity: "4", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d;
},
function testReadAPI_getAttributes(t){
// summary:
// Simple test of the getAttributes function of the store
// description:
// Simple test of the getAttributes function of the store
 
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
var csvStore = new dojox.data.CsvStore(args);
 
var d = new doh.Deferred();
function onItem(item){
t.assertTrue(item !== null);
t.assertTrue(csvStore.isItem(item));
 
var attributes = csvStore.getAttributes(item);
t.is(3, attributes.length);
for(var i = 0; i < attributes.length; i++){
t.assertTrue((attributes[i] === "Title" || attributes[i] === "Year" || attributes[i] === "Producer"));
}
d.callback(true);
}
csvStore.fetchItemByIdentity({identity: "4", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d;
},
 
function testReadAPI_getAttributes_onlyTwo(t){
// summary:
// Simple test of the getAttributes function of the store
// description:
// Simple test of the getAttributes function of the store
 
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
var csvStore = new dojox.data.CsvStore(args);
 
var d = new doh.Deferred();
function onItem(item){
// Test an item that does not have all of the attributes
t.assertTrue(item !== null);
t.assertTrue(csvStore.isItem(item));
 
var attributes = csvStore.getAttributes(item);
t.assertTrue(attributes.length === 2);
t.assertTrue(attributes[0] === "Title");
t.assertTrue(attributes[1] === "Producer");
d.callback(true);
}
csvStore.fetchItemByIdentity({identity: "1", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d;
},
 
function testReadAPI_getFeatures(t){
// summary:
// Simple test of the getFeatures function of the store
// description:
// Simple test of the getFeatures function of the store
 
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
var csvStore = new dojox.data.CsvStore(args);
 
var features = csvStore.getFeatures();
var count = 0;
for(i in features){
t.assertTrue((i === "dojo.data.api.Read" || i === "dojo.data.api.Identity"));
count++;
}
t.assertTrue(count === 2);
},
function testReadAPI_fetch_patternMatch0(t){
// summary:
// Function to test pattern matching of everything starting with lowercase e
// description:
// Function to test pattern matching of everything starting with lowercase e
 
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
var csvStore = new dojox.data.CsvStore(args);
 
var d = new doh.Deferred();
function completed(items, request){
t.is(2, items.length);
var valueArray = [ "Alien", "The Sequel to \"Dances With Wolves.\""];
t.assertTrue(dojox.data.tests.stores.CsvStore.verifyItems(csvStore, items, "Title", valueArray));
d.callback(true);
}
csvStore.fetch({query: {Producer: "* Scott"}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d; //Object
},
function testReadAPI_fetch_patternMatch1(t){
// summary:
// Function to test pattern matching of everything with $ in it.
// description:
// Function to test pattern matching of everything with $ in it.
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/patterns.csv");
var csvStore = new dojox.data.CsvStore(args);
var d = new doh.Deferred();
function completed(items, request){
t.assertTrue(items.length === 2);
var valueArray = [ "jfq4@#!$!@Rf14r14i5u", "bit$Bite"];
t.assertTrue(dojox.data.tests.stores.CsvStore.verifyItems(csvStore, items, "value", valueArray));
d.callback(true);
}
csvStore.fetch({query: {value: "*$*"}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d; //Object
},
function testReadAPI_fetch_patternMatch2(t){
// summary:
// Function to test exact pattern match
// description:
// Function to test exact pattern match
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/patterns.csv");
var csvStore = new dojox.data.CsvStore(args);
var d = new doh.Deferred();
function completed(items, request){
t.is(1, items.length);
t.assertTrue(csvStore.getValue(items[0], "value") === "bar*foo");
d.callback(true);
}
csvStore.fetch({query: {value: "bar\*foo"}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d; //Object
},
function testReadAPI_fetch_patternMatch_caseInsensitive(t){
// summary:
// Function to test exact pattern match with case insensitivity set.
// description:
// Function to test exact pattern match with case insensitivity set.
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/patterns.csv");
var csvStore = new dojox.data.CsvStore(args);
var d = new doh.Deferred();
function completed(items, request){
t.is(1, items.length);
t.assertTrue(csvStore.getValue(items[0], "value") === "bar*foo");
d.callback(true);
}
csvStore.fetch({query: {value: "BAR\\*foo"}, queryOptions: {ignoreCase: true}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d; //Object
},
function testReadAPI_fetch_patternMatch_caseSensitive(t){
// summary:
// Function to test exact pattern match with case insensitivity set.
// description:
// Function to test exact pattern match with case insensitivity set.
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/patterns.csv");
var csvStore = new dojox.data.CsvStore(args);
var d = new doh.Deferred();
function completed(items, request){
t.is(0, items.length);
d.callback(true);
}
csvStore.fetch({query: {value: "BAR\\*foo"}, queryOptions: {ignoreCase: false}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d; //Object
},
function testReadAPI_fetch_sortNumeric(t){
// summary:
// Function to test sorting numerically.
// description:
// Function to test sorting numerically.
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/patterns.csv");
var csvStore = new dojox.data.CsvStore(args);
 
var d = new doh.Deferred();
function completed(items, request){
t.assertTrue(items.length === 10);
// TODO: CsvStore treats everything like a string, so these numbers will be sorted lexicographically.
var orderedArray = [ "1", "10", "2", "3", "4", "5", "6", "7", "8", "9" ];
t.assertTrue(dojox.data.tests.stores.CsvStore.verifyItems(csvStore, items, "uniqueId", orderedArray));
d.callback(true);
}
 
var sortAttributes = [{attribute: "uniqueId"}];
csvStore.fetch({onComplete: completed,
onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d),
sort: sortAttributes});
return d; //Object
},
function testReadAPI_fetch_sortNumericDescending(t){
// summary:
// Function to test sorting numerically.
// description:
// Function to test sorting numerically.
 
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/patterns.csv");
var csvStore = new dojox.data.CsvStore(args);
var d = new doh.Deferred();
function completed(items, request){
t.is(10, items.length);
// TODO: CsvStore treats everything like a string, so these numbers will be sorted lexicographically.
var orderedArray = [ "9", "8", "7", "6", "5", "4", "3", "2", "10", "1" ];
t.assertTrue(dojox.data.tests.stores.CsvStore.verifyItems(csvStore, items, "uniqueId", orderedArray));
d.callback(true);
}
var sortAttributes = [{attribute: "uniqueId", descending: true}];
csvStore.fetch({ sort: sortAttributes, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d; //Object
},
function testReadAPI_fetch_sortNumericWithCount(t){
// summary:
// Function to test sorting numerically in descending order, returning only a specified number of them.
// description:
// Function to test sorting numerically in descending order, returning only a specified number of them.
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/patterns.csv");
var csvStore = new dojox.data.CsvStore(args);
var d = new doh.Deferred();
function completed(items, request){
t.is(5, items.length);
// TODO: CsvStore treats everything like a string, so these numbers will be sorted lexicographically.
var orderedArray = [ "9", "8", "7", "6", "5" ];
t.assertTrue(dojox.data.tests.stores.CsvStore.verifyItems(csvStore, items, "uniqueId", orderedArray));
d.callback(true);
}
var sortAttributes = [{attribute: "uniqueId", descending: true}];
csvStore.fetch({sort: sortAttributes,
count: 5,
onComplete: completed,
onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d; //Object
},
function testReadAPI_fetch_sortAlphabetic(t){
// summary:
// Function to test sorting alphabetic ordering.
// description:
// Function to test sorting alphabetic ordering.
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/patterns.csv");
var csvStore = new dojox.data.CsvStore(args);
var d = new doh.Deferred();
function completed(items, request){
//Output should be in this order...
var orderedArray = [ "123abc",
"123abc",
"123abc",
"123abcdefg",
"BaBaMaSaRa***Foo",
"bar*foo",
"bit$Bite",
"foo*bar",
"jfq4@#!$!@Rf14r14i5u",
undefined
];
t.is(10, items.length);
t.assertTrue(dojox.data.tests.stores.CsvStore.verifyItems(csvStore, items, "value", orderedArray));
d.callback(true);
}
var sortAttributes = [{attribute: "value"}];
csvStore.fetch({sort: sortAttributes, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d; //Object
},
function testReadAPI_fetch_sortAlphabeticDescending(t){
// summary:
// Function to test sorting alphabetic ordering in descending mode.
// description:
// Function to test sorting alphabetic ordering in descending mode.
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/patterns.csv");
var csvStore = new dojox.data.CsvStore(args);
var d = new doh.Deferred();
function completed(items, request){
//Output should be in this order...
var orderedArray = [ undefined,
"jfq4@#!$!@Rf14r14i5u",
"foo*bar",
"bit$Bite",
"bar*foo",
"BaBaMaSaRa***Foo",
"123abcdefg",
"123abc",
"123abc",
"123abc"
];
t.is(10, items.length);
t.assertTrue(dojox.data.tests.stores.CsvStore.verifyItems(csvStore, items, "value", orderedArray));
d.callback(true);
}
var sortAttributes = [{attribute: "value", descending: true}];
csvStore.fetch({sort: sortAttributes, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d; //Object
},
function testReadAPI_fetch_sortMultiple(t){
// summary:
// Function to test sorting on multiple attributes.
// description:
// Function to test sorting on multiple attributes.
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/patterns.csv");
var csvStore = new dojox.data.CsvStore(args);
var d = new doh.Deferred();
function completed(items, request){
var orderedArray0 = [ "8", "5", "3", "10", "6", "2", "4", "1", "9", "7" ];
var orderedArray1 = [ "123abc",
"123abc",
"123abc",
"123abcdefg",
"BaBaMaSaRa***Foo",
"bar*foo",
"bit$Bite",
"foo*bar",
"jfq4@#!$!@Rf14r14i5u",
undefined
];
t.is(10, items.length);
t.assertTrue(dojox.data.tests.stores.CsvStore.verifyItems(csvStore, items, "uniqueId", orderedArray0));
t.assertTrue(dojox.data.tests.stores.CsvStore.verifyItems(csvStore, items, "value", orderedArray1));
d.callback(true);
}
var sortAttributes = [{ attribute: "value"}, { attribute: "uniqueId", descending: true}];
csvStore.fetch({sort: sortAttributes, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d; //Object
},
function testReadAPI_fetch_sortMultipleSpecialComparator(t){
// summary:
// Function to test sorting on multiple attributes with a custom comparator.
// description:
// Function to test sorting on multiple attributes with a custom comparator.
 
var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
var csvStore = new dojox.data.CsvStore(args);
csvStore.comparatorMap = {};
csvStore.comparatorMap["Producer"] = function(a,b){
var ret = 0;
// We want to sort authors alphabetical by their last name
function lastName(name){
if(typeof name === "undefined"){ return undefined; }
var matches = name.match(/\s*(\S+)$/); // Grab the last word in the string.
return matches ? matches[1] : name; // Strings with only whitespace will not match.
}
var lastNameA = lastName(a);
var lastNameB = lastName(b);
if(lastNameA > lastNameB || typeof lastNameA === "undefined"){
ret = 1;
}else if(lastNameA < lastNameB || typeof lastNameB === "undefined"){
ret = -1;
}
return ret;
};
var sortAttributes = [{attribute: "Producer", descending: true}, { attribute: "Title", descending: true}];
var d = new doh.Deferred();
function completed(items, findResult){
var orderedArray = [5,4,0,3,2,1,6];
t.assertTrue(items.length === 7);
var passed = true;
for(var i = 0; i < items.length; i++){
if(!(csvStore.getIdentity(items[i]) === orderedArray[i])){
passed=false;
break;
}
}
t.assertTrue(passed);
d.callback(true);
}
csvStore.fetch({sort: sortAttributes, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
return d; //Object
},
function testReadAPI_functionConformance(t){
// summary:
// Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
// description:
// Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
 
var testStore = new dojox.data.CsvStore(dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv"));
var readApi = new dojo.data.api.Read();
var passed = true;
 
for(i in readApi){
if(i.toString().charAt(0) !== '_')
{
var member = readApi[i];
//Check that all the 'Read' defined functions exist on the test store.
if(typeof member === "function"){
console.log("Looking at function: [" + i + "]");
var testStoreMember = testStore[i];
if(!(typeof testStoreMember === "function")){
console.log("Problem with function: [" + i + "]. Got value: " + testStoreMember);
passed = false;
break;
}
}
}
}
t.assertTrue(passed);
},
function testIdentityAPI_functionConformance(t){
// summary:
// Simple test identity API conformance. Checks to see all declared functions are actual functions on the instances.
// description:
// Simple test identity API conformance. Checks to see all declared functions are actual functions on the instances.
 
var testStore = new dojox.data.CsvStore(dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv"));
var identityApi = new dojo.data.api.Identity();
var passed = true;
 
for(i in identityApi){
if(i.toString().charAt(0) !== '_')
{
var member = identityApi[i];
//Check that all the 'Read' defined functions exist on the test store.
if(typeof member === "function"){
console.log("Looking at function: [" + i + "]");
var testStoreMember = testStore[i];
if(!(typeof testStoreMember === "function")){
passed = false;
break;
}
}
}
}
t.assertTrue(passed);
}
]
);
 
 
}
/trunk/api/js/dojo1.0/dojox/data/tests/stores/geography.xml
New file
0,0 → 1,51
<?xml version="1.0" encoding="ISO-8859-1"?>
<opml version="1.0">
<head>
<title>geography.opml</title>
<dateCreated>2006-11-10</dateCreated>
<dateModified>2006-11-13</dateModified>
<ownerName>Magellan, Ferdinand</ownerName>
</head>
<body>
<outline text="Africa" type="continent">
<outline text="Egypt" type="country"/>
<outline text="Kenya" type="country">
<outline text="Nairobi" type="city"/>
<outline text="Mombasa" type="city"/>
</outline>
<outline text="Sudan" type="country">
<outline text="Khartoum" type="city"/>
</outline>
</outline>
<outline text="Asia" type="continent">
<outline text="China" type="country"/>
<outline text="India" type="country"/>
<outline text="Russia" type="country"/>
<outline text="Mongolia" type="country"/>
</outline>
<outline text="Australia" type="continent" population="21 million">
<outline text="Australia" type="country" population="21 million"/>
</outline>
<outline text="Europe" type="continent">
<outline text="Germany" type="country"/>
<outline text="France" type="country"/>
<outline text="Spain" type="country"/>
<outline text="Italy" type="country"/>
</outline>
<outline text="North America" type="continent">
<outline text="Mexico" type="country" population="108 million" area="1,972,550 sq km">
<outline text="Mexico City" type="city" population="19 million" timezone="-6 UTC"/>
<outline text="Guadalajara" type="city" population="4 million" timezone="-6 UTC"/>
</outline>
<outline text="Canada" type="country" population="33 million" area="9,984,670 sq km">
<outline text="Ottawa" type="city" population="0.9 million" timezone="-5 UTC"/>
<outline text="Toronto" type="city" population="2.5 million" timezone="-5 UTC"/>
</outline>
<outline text="United States of America" type="country"/>
</outline>
<outline text="South America" type="continent">
<outline text="Brazil" type="country" population="186 million"/>
<outline text="Argentina" type="country" population="40 million"/>
</outline>
</body>
</opml>
/trunk/api/js/dojo1.0/dojox/data/tests/stores/XmlStore.js
New file
0,0 → 1,881
if(!dojo._hasResource["dojox.data.tests.stores.XmlStore"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.data.tests.stores.XmlStore"] = true;
dojo.provide("dojox.data.tests.stores.XmlStore");
dojo.require("dojox.data.XmlStore");
dojo.require("dojo.data.api.Read");
dojo.require("dojo.data.api.Write");
 
 
dojox.data.tests.stores.XmlStore.getBooks2Store = function(){
return new dojox.data.XmlStore({url: dojo.moduleUrl("dojox.data.tests", "stores/books2.xml").toString(), label: "title"});
};
 
dojox.data.tests.stores.XmlStore.getBooksStore = function(){
return new dojox.data.XmlStore({url: dojo.moduleUrl("dojox.data.tests", "stores/books.xml").toString(), label: "title"});
};
 
doh.register("dojox.data.tests.stores.XmlStore",
[
function testReadAPI_fetch_all(t){
// summary:
// Simple test of fetching all xml items through an XML element called isbn
// description:
// Simple test of fetching all xml items through an XML element called isbn
var store = dojox.data.tests.stores.XmlStore.getBooksStore();
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(20, items.length);
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"*"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_fetch_one(t){
// summary:
// Simple test of fetching one xml items through an XML element called isbn
// description:
// Simple test of fetching one xml items through an XML element called isbn
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(1, items.length);
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
return d; //Object
},
{
name: "testReadAPI_fetch_paging",
timeout: 10000,
runTest: function(t){
// summary:
// Simple test of fetching one xml items through an XML element called isbn
// description:
// Simple test of fetching one xml items through an XML element called isbn
var store = dojox.data.tests.stores.XmlStore.getBooksStore();
var d = new doh.Deferred();
function dumpFirstFetch(items, request){
t.assertEqual(5, items.length);
request.start = 3;
request.count = 1;
request.onComplete = dumpSecondFetch;
store.fetch(request);
}
function dumpSecondFetch(items, request){
t.assertEqual(1, items.length);
request.start = 0;
request.count = 5;
request.onComplete = dumpThirdFetch;
store.fetch(request);
}
function dumpThirdFetch(items, request){
t.assertEqual(5, items.length);
request.start = 2;
request.count = 20;
request.onComplete = dumpFourthFetch;
store.fetch(request);
}
function dumpFourthFetch(items, request){
t.assertEqual(18, items.length);
request.start = 9;
request.count = 100;
request.onComplete = dumpFifthFetch;
store.fetch(request);
}
function dumpFifthFetch(items, request){
t.assertEqual(11, items.length);
request.start = 2;
request.count = 20;
request.onComplete = dumpSixthFetch;
store.fetch(request);
}
function dumpSixthFetch(items, request){
t.assertEqual(18, items.length);
d.callback(true);
}
function completed(items, request){
t.assertEqual(20, items.length);
request.start = 1;
request.count = 5;
request.onComplete = dumpFirstFetch;
store.fetch(request);
}
function error(errData, request){
d.errback(errData);
}
store.fetch({onComplete: completed, onError: error});
return d; //Object
}
},
function testReadAPI_fetch_pattern0(t){
// summary:
// Simple test of fetching one xml items through an XML element called isbn with ? pattern match
// description:
// Simple test of fetching one xml items through an XML element called isbn with ? pattern match
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(1, items.length);
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"?9B574"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_fetch_pattern1(t){
// summary:
// Simple test of fetching one xml items through an XML element called isbn with ? pattern match
// description:
// Simple test of fetching one xml items through an XML element called isbn with ? pattern match
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(4, items.length);
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9B57?"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_fetch_pattern2(t){
// summary:
// Simple test of fetching one xml items through an XML element called isbn with * pattern match
// description:
// Simple test of fetching one xml items through an XML element called isbn with * pattern match
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(5, items.length);
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9*"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_fetch_pattern_caseInsensitive(t){
// summary:
// Simple test of fetching one xml items through an XML element called isbn with ? pattern match and in case insensitive mode.
// description:
// Simple test of fetching one xml items through an XML element called isbn with ? pattern match and in case insensitive mode.
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(1, items.length);
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"?9b574"}, queryOptions: {ignoreCase: true}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_fetch_pattern_caseSensitive(t){
// summary:
// Simple test of fetching one xml items through an XML element called isbn with ? pattern match and in case sensitive mode.
// description:
// Simple test of fetching one xml items through an XML element called isbn with ? pattern match and in case sensitive mode.
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(1, items.length);
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"?9B574"}, queryOptions: {ignoreCase: false}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_fetch_all_rootItem(t){
// summary:
// Simple test of fetching all xml items through an XML element called isbn
// description:
// Simple test of fetching all xml items through an XML element called isbn
var store = new dojox.data.XmlStore({url: dojo.moduleUrl("dojox.data.tests", "stores/books3.xml").toString(),
rootItem:"book"});
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(5, items.length);
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"*"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_fetch_withAttrMap_all(t){
var store = new dojox.data.XmlStore({url: dojo.moduleUrl("dojox.data.tests", "stores/books_isbnAttr.xml").toString(),
attributeMap: {"book.isbn": "@isbn"}});
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(5, items.length);
d.callback(true);
}
function onError(error, request) {
console.debug(error);
d.errback(error);
}
store.fetch({query:{isbn:"*"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_fetch_withAttrMap_one(t){
var store = new dojox.data.XmlStore({url: dojo.moduleUrl("dojox.data.tests", "stores/books_isbnAttr.xml").toString(),
attributeMap: {"book.isbn": "@isbn"}});
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(1, items.length);
d.callback(true);
}
function onError(error, request) {
console.debug(error);
d.errback(error);
}
store.fetch({query:{isbn:"2"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_fetch_withAttrMap_pattern0(t){
// summary:
// Simple test of fetching one xml items through an XML element called isbn with ? pattern match
// description:
// Simple test of fetching one xml items through an XML element called isbn with ? pattern match
var store = new dojox.data.XmlStore({url: dojo.moduleUrl("dojox.data.tests", "stores/books_isbnAttr2.xml").toString(),
attributeMap: {"book.isbn": "@isbn"}});
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(3, items.length);
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"ABC?"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_fetch_withAttrMap_pattern1(t){
// summary:
// Simple test of fetching one xml items through an XML element called isbn with ? pattern match
// description:
// Simple test of fetching one xml items through an XML element called isbn with ? pattern match
var store = new dojox.data.XmlStore({url: dojo.moduleUrl("dojox.data.tests", "stores/books_isbnAttr2.xml").toString(),
attributeMap: {"book.isbn": "@isbn"}});
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(5, items.length);
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A*"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_fetch_withAttrMap_pattern2(t){
// summary:
// Simple test of fetching one xml items through an XML element called isbn with ? pattern match
// description:
// Simple test of fetching one xml items through an XML element called isbn with ? pattern match
var store = new dojox.data.XmlStore({url: dojo.moduleUrl("dojox.data.tests", "stores/books_isbnAttr2.xml").toString(),
attributeMap: {"book.isbn": "@isbn"}});
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(2, items.length);
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"?C*"}, onComplete: onComplete, onError: onError});
return d; //Object
},
 
function testReadAPI_getLabel(t){
// summary:
// Simple test of the getLabel function against a store set that has a label defined.
// description:
// Simple test of the getLabel function against a store set that has a label defined.
 
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
var d = new doh.Deferred();
function onComplete(items, request){
t.assertEqual(items.length, 1);
var label = store.getLabel(items[0]);
t.assertTrue(label !== null);
t.assertEqual("Title of 4", label);
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
return d;
},
function testReadAPI_getLabelAttributes(t){
// summary:
// Simple test of the getLabelAttributes function against a store set that has a label defined.
// description:
// Simple test of the getLabelAttributes function against a store set that has a label defined.
 
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
var d = new doh.Deferred();
function onComplete(items, request){
t.assertEqual(items.length, 1);
var labelList = store.getLabelAttributes(items[0]);
t.assertTrue(dojo.isArray(labelList));
t.assertEqual("title", labelList[0]);
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
return d;
},
 
function testReadAPI_getValue(t){
// summary:
// Simple test of the getValue API
// description:
// Simple test of the getValue API
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(1, items.length);
var item = items[0];
t.assertTrue(store.hasAttribute(item,"isbn"));
t.assertEqual(store.getValue(item,"isbn"), "A9B574");
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_getValues(t){
// summary:
// Simple test of the getValues API
// description:
// Simple test of the getValues API
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(1, items.length);
var item = items[0];
t.assertTrue(store.hasAttribute(item,"isbn"));
var values = store.getValues(item,"isbn");
t.assertEqual(1,values.length);
t.assertEqual("A9B574", values[0]);
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_isItem(t){
// summary:
// Simple test of the isItem API
// description:
// Simple test of the isItem API
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(1, items.length);
var item = items[0];
t.assertTrue(store.isItem(item));
t.assertTrue(!store.isItem({}));
t.assertTrue(!store.isItem("Foo"));
t.assertTrue(!store.isItem(1));
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_isItem_multistore(t){
// summary:
// Simple test of the isItem API across multiple store instances.
// description:
// Simple test of the isItem API across multiple store instances.
var store1 = dojox.data.tests.stores.XmlStore.getBooks2Store();
var store2 = dojox.data.tests.stores.XmlStore.getBooks2Store();
 
var d = new doh.Deferred();
function onComplete1(items, request) {
t.assertEqual(1, items.length);
var item1 = items[0];
t.assertTrue(store1.isItem(item1));
 
function onComplete2(items, request) {
t.assertEqual(1, items.length);
var item2 = items[0];
t.assertTrue(store2.isItem(item2));
t.assertTrue(!store1.isItem(item2));
t.assertTrue(!store2.isItem(item1));
d.callback(true);
}
store2.fetch({query:{isbn:"A9B574"}, onComplete: onComplete2, onError: onError});
}
function onError(error, request) {
d.errback(error);
}
store1.fetch({query:{isbn:"A9B574"}, onComplete: onComplete1, onError: onError});
return d; //Object
},
function testReadAPI_hasAttribute(t){
// summary:
// Simple test of the hasAttribute API
// description:
// Simple test of the hasAttribute API
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(1, items.length);
var item = items[0];
t.assertTrue(store.hasAttribute(item,"isbn"));
t.assertTrue(!store.hasAttribute(item,"bob"));
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_containsValue(t){
// summary:
// Simple test of the containsValue API
// description:
// Simple test of the containsValue API
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(1, items.length);
var item = items[0];
t.assertTrue(store.containsValue(item,"isbn", "A9B574"));
t.assertTrue(!store.containsValue(item,"isbn", "bob"));
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_sortDescending(t){
// summary:
// Simple test of the sorting API in descending order.
// description:
// Simple test of the sorting API in descending order.
var store = dojox.data.tests.stores.XmlStore.getBooksStore();
 
//Comparison is done as a string type (toString comparison), so the order won't be numeric
//So have to compare in 'alphabetic' order.
var order = [9,8,7,6,5,4,3,20,2,19,18,17,16,15,14,13,12,11,10,1];
var d = new doh.Deferred();
function onComplete(items, request) {
console.log("Number of items: " + items.length);
t.assertEqual(20, items.length);
 
for(var i = 0; i < items.length; i++){
t.assertEqual(order[i], store.getValue(items[i],"isbn").toString());
}
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
 
var sortAttributes = [{attribute: "isbn", descending: true}];
store.fetch({query:{isbn:"*"}, sort: sortAttributes, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_sortAscending(t){
// summary:
// Simple test of the sorting API in ascending order.
// description:
// Simple test of the sorting API in ascending order.
var store = dojox.data.tests.stores.XmlStore.getBooksStore();
 
//Comparison is done as a string type (toString comparison), so the order won't be numeric
//So have to compare in 'alphabetic' order.
var order = [1,10,11,12,13,14,15,16,17,18,19,2,20,3,4,5,6,7,8,9];
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(20, items.length);
var itemId = 1;
for(var i = 0; i < items.length; i++){
t.assertEqual(order[i], store.getValue(items[i],"isbn").toString());
}
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
 
var sortAttributes = [{attribute: "isbn"}];
store.fetch({query:{isbn:"*"}, sort: sortAttributes, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_sortDescendingNumeric(t){
// summary:
// Simple test of the sorting API in descending order using a numeric comparator.
// description:
// Simple test of the sorting API in descending order using a numeric comparator.
var store = dojox.data.tests.stores.XmlStore.getBooksStore();
 
//isbn should be treated as a numeric, not as a string comparison
store.comparatorMap = {};
store.comparatorMap["isbn"] = function(a, b){
var ret = 0;
if(parseInt(a.toString()) > parseInt(b.toString())){
ret = 1;
}else if(parseInt(a.toString()) < parseInt(b.toString())){
ret = -1;
}
return ret; //int, {-1,0,1}
};
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(20, items.length);
var itemId = 20;
for(var i = 0; i < items.length; i++){
t.assertEqual(itemId, store.getValue(items[i],"isbn").toString());
itemId--;
}
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
 
var sortAttributes = [{attribute: "isbn", descending: true}];
store.fetch({query:{isbn:"*"}, sort: sortAttributes, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_sortAscendingNumeric(t){
// summary:
// Simple test of the sorting API in ascending order using a numeric comparator.
// description:
// Simple test of the sorting API in ascending order using a numeric comparator.
var store = dojox.data.tests.stores.XmlStore.getBooksStore();
 
//isbn should be treated as a numeric, not as a string comparison
store.comparatorMap = {};
store.comparatorMap["isbn"] = function(a, b){
var ret = 0;
if(parseInt(a.toString()) > parseInt(b.toString())){
ret = 1;
}else if(parseInt(a.toString()) < parseInt(b.toString())){
ret = -1;
}
return ret; //int, {-1,0,1}
};
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(20, items.length);
var itemId = 1;
for(var i = 0; i < items.length; i++){
t.assertEqual(itemId, store.getValue(items[i],"isbn").toString());
itemId++;
}
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
 
var sortAttributes = [{attribute: "isbn"}];
store.fetch({query:{isbn:"*"}, sort: sortAttributes, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_isItemLoaded(t){
// summary:
// Simple test of the isItemLoaded API
// description:
// Simple test of the isItemLoaded API
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(1, items.length);
var item = items[0];
t.assertTrue(store.isItemLoaded(item));
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_getFeatures(t){
// summary:
// Simple test of the getFeatures function of the store
// description:
// Simple test of the getFeatures function of the store
 
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
var features = store.getFeatures();
var count = 0;
for(i in features){
t.assertTrue((i === "dojo.data.api.Read" || i === "dojo.data.api.Write"));
count++;
}
t.assertEqual(2, count);
},
function testReadAPI_getAttributes(t){
// summary:
// Simple test of the getAttributes API
// description:
// Simple test of the getAttributes API
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(1, items.length);
var item = items[0];
var attributes = store.getAttributes(item);
 
//Should be six, as all items should have tagName, childNodes, and text() special attributes
//in addition to any doc defined ones, which in this case are author, title, and isbn
//FIXME: Figure out why IE returns 5! Need to get firebug lite working in IE for that.
//Suspect it's childNodes, may not be defined if there are no child nodes.
for(var i = 0; i < attributes.length; i++){
console.log("attribute found: " + attributes[i]);
}
if(dojo.isIE){
t.assertEqual(5,attributes.length);
}else{
t.assertEqual(6,attributes.length);
}
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testWriteAPI_setValue(t){
// summary:
// Simple test of the setValue API
// description:
// Simple test of the setValue API
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(1, items.length);
var item = items[0];
t.assertTrue(store.containsValue(item,"isbn", "A9B574"));
store.setValue(item, "isbn", "A9B574-new");
t.assertEqual(store.getValue(item,"isbn").toString(), "A9B574-new");
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testWriteAPI_setValues(t){
// summary:
// Simple test of the setValues API
// description:
// Simple test of the setValues API
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(1, items.length);
var item = items[0];
t.assertTrue(store.containsValue(item,"isbn", "A9B574"));
store.setValues(item, "isbn", ["A9B574-new1", "A9B574-new2"]);
var values = store.getValues(item,"isbn");
t.assertEqual(values[0].toString(), "A9B574-new1");
t.assertEqual(values[1].toString(), "A9B574-new2");
store.setValues(values[0], "text()", ["A9B574", "-new3"]);
t.assertEqual(store.getValue(values[0],"text()").toString(), "A9B574-new3");
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testWriteAPI_unsetAttribute(t){
// summary:
// Simple test of the unsetAttribute API
// description:
// Simple test of the unsetAttribute API
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(1, items.length);
var item = items[0];
t.assertTrue(store.containsValue(item,"isbn", "A9B574"));
store.unsetAttribute(item,"isbn");
t.assertTrue(!store.hasAttribute(item,"isbn"));
t.assertTrue(store.isDirty(item));
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testWriteAPI_isDirty(t){
// summary:
// Simple test of the isDirty API
// description:
// Simple test of the isDirty API
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(1, items.length);
var item = items[0];
t.assertTrue(store.containsValue(item,"isbn", "A9B574"));
store.setValue(item, "isbn", "A9B574-new");
t.assertEqual(store.getValue(item,"isbn").toString(), "A9B574-new");
t.assertTrue(store.isDirty(item));
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testWriteAPI_revert(t){
// summary:
// Simple test of the isDirty API
// description:
// Simple test of the isDirty API
var store = dojox.data.tests.stores.XmlStore.getBooks2Store();
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(1, items.length);
var item = items[0];
t.assertTrue(store.containsValue(item,"isbn", "A9B574"));
t.assertTrue(!store.isDirty(item));
store.setValue(item, "isbn", "A9B574-new");
t.assertEqual(store.getValue(item,"isbn").toString(), "A9B574-new");
t.assertTrue(store.isDirty(item));
store.revert();
//Fetch again to see if it reset the state.
function onComplete1(items, request) {
t.assertEqual(1, items.length);
var item = items[0];
t.assertTrue(store.containsValue(item,"isbn", "A9B574"));
d.callback(true);
}
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete1, onError: onError});
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_functionConformance(t){
// summary:
// Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
// description:
// Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
 
var testStore = dojox.data.tests.stores.XmlStore.getBooksStore();
var readApi = new dojo.data.api.Read();
var passed = true;
 
for(i in readApi){
var member = readApi[i];
//Check that all the 'Read' defined functions exist on the test store.
if(typeof member === "function"){
var testStoreMember = testStore[i];
if(!(typeof testStoreMember === "function")){
console.log("Problem with function: [" + i + "]");
passed = false;
break;
}
}
}
t.assertTrue(passed);
},
function testWriteAPI_functionConformance(t){
// summary:
// Simple test write API conformance. Checks to see all declared functions are actual functions on the instances.
// description:
// Simple test write API conformance. Checks to see all declared functions are actual functions on the instances.
 
var testStore = dojox.data.tests.stores.XmlStore.getBooksStore();
var writeApi = new dojo.data.api.Write();
var passed = true;
 
for(i in writeApi){
var member = writeApi[i];
//Check that all the 'Write' defined functions exist on the test store.
if(typeof member === "function"){
var testStoreMember = testStore[i];
if(!(typeof testStoreMember === "function")){
passed = false;
break;
}
}
}
t.assertTrue(passed);
}
]
);
 
 
 
 
 
}
/trunk/api/js/dojo1.0/dojox/data/tests/stores/QueryReadStore.js
New file
0,0 → 1,338
if(!dojo._hasResource["dojox.data.tests.stores.QueryReadStore"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.data.tests.stores.QueryReadStore"] = true;
dojo.provide("dojox.data.tests.stores.QueryReadStore");
dojo.require("dojox.data.QueryReadStore");
dojo.require("dojo.data.api.Read");
 
//dojo.require("dojox.testing.DocTest");
 
dojox.data.tests.stores.QueryReadStore.getStore = function(){
return new dojox.data.QueryReadStore({
url: dojo.moduleUrl("dojox.data.tests", "stores/QueryReadStore.php").toString(),
doClientPaging:true // "true" is actually also the default, but make sure :-).
});
};
 
 
tests.register("dojox.data.tests.stores.QueryReadStore",
[
/*
function testDocTests(t) {
// summary:
// Run all the doc comments.
var doctest = new dojox.testing.DocTest();
doctest.run("dojox.data.QueryReadStore");
t.assertTrue(doctest.errors.length==0);
},
*/
function testReadApi_getValue(t){
// summary:
// description:
var store = dojox.data.tests.stores.QueryReadStore.getStore();
var d = new doh.Deferred();
function onComplete(items, request){
var item = items[0];
// The good cases.
t.assertEqual("Alabama", store.getValue(item, "name"));
t.assertEqual("<img src='images/Alabama.jpg'/>Alabama", store.getValue(item, "label"));
t.assertEqual("AL", store.getValue(item, "abbreviation"));
// Test the defaultValue cases (the third paramter).
t.assertEqual("default value", store.getValue(item, "NAME", "default value"));
// TODO Test for null somehow ...
// Read api says: Returns null if and only if null was explicitly set as the attribute value.
// According to Read-API getValue() an exception is thrown when
// the item is not an item or when the attribute is not a string.
t.assertError(Error, store, "getValue", ["not an item", "NOT THERE"]);
t.assertError(Error, store, "getValue", [item, {}]);
d.callback(true);
}
store.fetch({query:{q:"Alabama"}, onComplete: onComplete});
return d; //Object
},
 
function testReadApi_getValues(t){
// summary:
// description:
var store = dojox.data.tests.stores.QueryReadStore.getStore();
var d = new doh.Deferred();
function onComplete(items, request){
var item = items[0];
// The good cases.
t.assertEqual(["Alabama"], store.getValues(item, "name"));
t.assertEqual(["<img src='images/Alabama.jpg'/>Alabama"], store.getValues(item, "label"));
t.assertEqual(["AL"], store.getValues(item, "abbreviation"));
// TODO Test for null somehow ...
// Read api says: Returns null if and only if null was explicitly set as the attribute value.
 
// Test for not-existing attributes without defaultValues and invalid items.
// TODO
//dojox.data.tests.stores.QueryReadStore.assertError(dojox.data.QueryReadStore.InvalidAttributeError, store, "getValues", [item, "NOT THERE"]);
//dojox.data.tests.stores.QueryReadStore.assertError(dojox.data.QueryReadStore.InvalidItemError, store, "getValues", ["not an item", "NOT THERE"]);
d.callback(true);
}
store.fetch({query:{q:"Alabama"}, onComplete: onComplete});
return d; //Object
},
function testReadApi_getAttributes(t){
// summary:
// description:
var store = dojox.data.tests.stores.QueryReadStore.getStore();
var d = new doh.Deferred();
function onComplete(items, request){
var item = items[0];
// The good case(s).
t.assertEqual(['name', 'label', 'abbreviation'], store.getAttributes(item));
t.assertError(dojox.data.QueryReadStore.InvalidItemError, store, "getAttributes", [{}]);
d.callback(true);
}
store.fetch({query:{q:"Alabama"}, onComplete: onComplete});
return d; //Object
},
 
function testReadApi_hasAttribute(t){
// summary:
// description:
var store = dojox.data.tests.stores.QueryReadStore.getStore();
var d = new doh.Deferred();
function onComplete(items, request){
var item = items[0];
// The positive cases.
t.assertEqual(true, store.hasAttribute(item, "name"));
t.assertEqual(true, store.hasAttribute(item, "label"));
t.assertEqual(true, store.hasAttribute(item, "abbreviation"));
// Make sure attribute case doesnt matter.
t.assertEqual(false, store.hasAttribute(item, "NAME"));
t.assertEqual(false, store.hasAttribute(item, "Name"));
t.assertEqual(false, store.hasAttribute(item, "Label"));
// Pass in an invalid item.
t.assertEqual(false, store.hasAttribute({}, "abbreviation"));
// pass in something that looks like the item with the attribute.
t.assertEqual(false, store.hasAttribute({name:"yo"}, "name"));
d.callback(true);
}
store.fetch({query:{q:"Alaska"}, onComplete: onComplete});
return d; //Object
},
 
function testReadApi_containsValue(t){
// summary:
// description:
var store = dojox.data.tests.stores.QueryReadStore.getStore();
 
var d = new doh.Deferred();
function onComplete(items, request){
var item = items[0];
t.assertTrue(store.containsValue(item, "name", "Alaska"));
d.callback(true);
}
store.fetch({query:{q:"Alaska"}, onComplete: onComplete});
return d; //Object
},
 
function testReadApi_isItem(t){
// summary:
// description:
var store = dojox.data.tests.stores.QueryReadStore.getStore();
var d = new doh.Deferred();
function onComplete(items, request){
// The good case.
t.assertEqual(true, store.isItem(items[0]));
// Try a pure object.
t.assertEqual(false, store.isItem({}));
// Try to look like an item.
t.assertEqual(false, store.isItem({name:"Alaska", label:"Alaska", abbreviation:"AK"}));
d.callback(true);
}
store.fetch({query:{q:"Alaska"}, onComplete: onComplete});
return d; //Object
},
 
function testReadApi_isItemLoaded(t){
// summary:
// description:
var store = dojox.data.tests.stores.QueryReadStore.getStore();
var d = new doh.Deferred();
function onComplete(items, request){
var item = items[0];
// The good case(s).
t.assertTrue(store.isItemLoaded(item));
d.callback(true);
}
store.fetch({query:{q:"Alabama"}, onComplete: onComplete});
return d; //Object
},
 
//function testReadApi_loadItem(t){
// // summary:
// // description:
// t.assertTrue(false);
//},
 
function testReadApi_fetch_all(t){
// summary:
// Simple test of fetching all items.
// description:
// Simple test of fetching all items.
var store = dojox.data.tests.stores.QueryReadStore.getStore();
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(8, items.length);
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{q:"a"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadApi_fetch_one(t){
// summary:
// description:
var store = dojox.data.tests.stores.QueryReadStore.getStore();
var d = new doh.Deferred();
function onComplete(items, request){
t.assertEqual(1, items.length);
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{q:"Alaska"}, onComplete: onComplete, onError: onError});
return d; //Object
},
 
function testReadApi_fetch_client_paging(t){
// summary:
// Lets test that paging on the same request does not trigger
// server requests.
// description:
var store = dojox.data.tests.stores.QueryReadStore.getStore();
 
var lastRequestHash = null;
var firstItems = [];
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(5, items.length);
lastRequestHash = store.lastRequestHash;
firstItems = items;
// Do the next request AFTER the previous one, so we are sure its sequential.
// We need to be sure so we can compare to the data from the first request.
function onComplete1(items, request) {
t.assertEqual(5, items.length);
t.assertEqual(lastRequestHash, store.lastRequestHash);
t.assertEqual(firstItems[1], items[0]);
d.callback(true);
}
req.start = 1;
req.onComplete = onComplete1;
store.fetch(req);
}
function onError(error, request) {
d.errback(error);
}
var req = {query:{q:"a"}, start:0, count:5,
onComplete: onComplete, onError: onError};
store.fetch(req);
return d; //Object
},
function testReadApi_fetch_server_paging(t) {
// Verify that the paging on the server side does work.
// This is the test for http://trac.dojotoolkit.org/ticket/4761
//
// How? We request 10 items from the server, start=0, count=10.
// The second request requests 5 items: start=5, count=5 and those
// 5 items should have the same values as the last 5 of the first
// request.
// This tests if the server side paging does work.
var store = dojox.data.tests.stores.QueryReadStore.getStore();
 
var lastRequestHash = null;
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(10, items.length);
lastRequestHash = store.lastRequestHash;
firstItems = items;
// Do the next request AFTER the previous one, so we are sure its sequential.
// We need to be sure so we can compare to the data from the first request.
function onComplete1(items, request) {
t.assertEqual(5, items.length);
// Compare the hash of the last request, they must be different,
// since another server request was issued.
t.assertTrue(lastRequestHash!=store.lastRequestHash);
t.assertEqual(store.getValue(firstItems[5], "name"), store.getValue(items[0], "name"));
t.assertEqual(store.getValue(firstItems[6], "name"), store.getValue(items[1], "name"));
t.assertEqual(store.getValue(firstItems[7], "name"), store.getValue(items[2], "name"));
t.assertEqual(store.getValue(firstItems[8], "name"), store.getValue(items[3], "name"));
t.assertEqual(store.getValue(firstItems[9], "name"), store.getValue(items[4], "name"));
d.callback(true);
}
// Init a new store, or it will use the old data, since the query has not changed.
store.doClientPaging = false;
store.fetch({start:5, count:5, onComplete: onComplete1, onError: onError});
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{}, start:0, count:10, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadApi_getFeatures(t) {
var store = dojox.data.tests.stores.QueryReadStore.getStore();
var features = store.getFeatures();
t.assertTrue(features["dojo.data.api.Read"]);
t.assertTrue(features["dojo.data.api.Identity"]);
var count = 0;
for (i in features){
count++;
}
t.assertEqual(2, count);
},
function testReadAPI_functionConformance(t){
// summary:
// Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
// description:
// Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
 
var testStore = dojox.data.tests.stores.QueryReadStore.getStore();
var readApi = new dojo.data.api.Read();
var passed = true;
 
for(i in readApi){
var member = readApi[i];
//Check that all the 'Read' defined functions exist on the test store.
if(typeof member === "function"){
var testStoreMember = testStore[i];
if(!(typeof testStoreMember === "function")){
console.log("Problem with function: [" + i + "]");
passed = false;
break;
}
}
}
t.assertTrue(passed);
}
]
);
 
}
/trunk/api/js/dojo1.0/dojox/data/tests/stores/patterns.csv
New file
0,0 → 1,11
uniqueId, value
9, jfq4@#!$!@Rf14r14i5u
6, BaBaMaSaRa***Foo
2, bar*foo
8, 123abc
4, bit$Bite
3, 123abc
10, 123abcdefg
1, foo*bar
7,
5, 123abc
/trunk/api/js/dojo1.0/dojox/data/tests/stores/movies.csv
New file
0,0 → 1,9
Title, Year, Producer
City of God, 2002, Katia Lund
Rain,, Christine Jeffs
2001: A Space Odyssey, , Stanley Kubrick
"This is a ""fake"" movie title", 1957, Sidney Lumet
Alien, 1979 , Ridley Scott
"The Sequel to ""Dances With Wolves.""", 1982, Ridley Scott
"Caine Mutiny, The", 1954, "Dymtryk ""the King"", Edward"
 
/trunk/api/js/dojo1.0/dojox/data/tests/stores/books2.xml
New file
0,0 → 1,28
<?xml version="1.0" encoding="ISO-8859-1"?>
<books>
<book>
<isbn>A9B57C</isbn>
<title>Title of 1</title>
<author>Author of 1</author>
</book>
<book>
<isbn>A9B57F</isbn>
<title>Title of 2</title>
<author>Author of 2</author>
</book>
<book>
<isbn>A9B577</isbn>
<title>Title of 3</title>
<author>Author of 3</author>
</book>
<book>
<isbn>A9B574</isbn>
<title>Title of 4</title>
<author>Author of 4</author>
</book>
<book>
<isbn>A9B5CC</isbn>
<title>Title of 5</title>
<author>Author of 5</author>
</book>
</books>
/trunk/api/js/dojo1.0/dojox/data/tests/stores/OpmlStore.js
New file
0,0 → 1,1075
if(!dojo._hasResource["dojox.data.tests.stores.OpmlStore"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.data.tests.stores.OpmlStore"] = true;
dojo.provide("dojox.data.tests.stores.OpmlStore");
dojo.require("dojox.data.OpmlStore");
dojo.require("dojo.data.api.Read");
 
dojox.data.tests.stores.OpmlStore.getDatasource = function(filepath){
// summary:
// A simple helper function for getting the sample data used in each of the tests.
// description:
// A simple helper function for getting the sample data used in each of the tests.
var dataSource = {};
if(dojo.isBrowser){
dataSource.url = dojo.moduleUrl("dojox.data.tests", filepath).toString();
}else{
// When running tests in Rhino, xhrGet is not available,
// so we have the file data in the code below.
switch(filepath){
case "stores/geography.xml":
var opmlData = "";
opmlData += '<?xml version="1.0" encoding="ISO-8859-1"?>\n';
opmlData += ' <opml version="1.0">\n';
opmlData += ' <head>\n';
opmlData += ' <title>geography.opml</title>\n';
opmlData += ' <dateCreated>2006-11-10</dateCreated>\n';
opmlData += ' <dateModified>2006-11-13</dateModified>\n';
opmlData += ' <ownerName>Magellan, Ferdinand</ownerName>\n';
opmlData += ' </head>\n';
opmlData += ' <body>\n';
opmlData += ' <outline text="Africa" type="continent">\n';
opmlData += ' <outline text="Egypt" type="country"/>\n';
opmlData += ' <outline text="Kenya" type="country">\n';
opmlData += ' <outline text="Nairobi" type="city"/>\n';
opmlData += ' <outline text="Mombasa" type="city"/>\n';
opmlData += ' </outline>\n';
opmlData += ' <outline text="Sudan" type="country">\n';
opmlData += ' <outline text="Khartoum" type="city"/>\n';
opmlData += ' </outline>\n';
opmlData += ' </outline>\n';
opmlData += ' <outline text="Asia" type="continent">\n';
opmlData += ' <outline text="China" type="country"/>\n';
opmlData += ' <outline text="India" type="country"/>\n';
opmlData += ' <outline text="Russia" type="country"/>\n';
opmlData += ' <outline text="Mongolia" type="country"/>\n';
opmlData += ' </outline>\n';
opmlData += ' <outline text="Australia" type="continent" population="21 million">\n';
opmlData += ' <outline text="Australia" type="country" population="21 million"/>\n';
opmlData += ' </outline>\n';
opmlData += ' <outline text="Europe" type="continent">\n';
opmlData += ' <outline text="Germany" type="country"/>\n';
opmlData += ' <outline text="France" type="country"/>\n';
opmlData += ' <outline text="Spain" type="country"/>\n';
opmlData += ' <outline text="Italy" type="country"/>\n';
opmlData += ' </outline>\n';
opmlData += ' <outline text="North America" type="continent">\n';
opmlData += ' <outline text="Mexico" type="country" population="108 million" area="1,972,550 sq km">\n';
opmlData += ' <outline text="Mexico City" type="city" population="19 million" timezone="-6 UTC"/>\n';
opmlData += ' <outline text="Guadalajara" type="city" population="4 million" timezone="-6 UTC"/>\n';
opmlData += ' </outline>\n';
opmlData += ' <outline text="Canada" type="country" population="33 million" area="9,984,670 sq km">\n';
opmlData += ' <outline text="Ottawa" type="city" population="0.9 million" timezone="-5 UTC"/>\n';
opmlData += ' <outline text="Toronto" type="city" population="2.5 million" timezone="-5 UTC"/>\n';
opmlData += ' </outline>\n';
opmlData += ' <outline text="United States of America" type="country"/>\n';
opmlData += ' </outline>\n';
opmlData += ' <outline text="South America" type="continent">\n';
opmlData += ' <outline text="Brazil" type="country" population="186 million"/>\n';
opmlData += ' <outline text="Argentina" type="country" population="40 million"/>\n';
opmlData += ' </outline>\n';
opmlData += ' </body>\n';
opmlData += ' </opml>\n';
break;
case "stores/geography_withspeciallabel.xml":
var opmlData = "";
opmlData += '<?xml version="1.0" encoding="ISO-8859-1"?>\n';
opmlData += '<opml version="1.0">\n';
opmlData += ' <head>\n';
opmlData += ' <title>geography.opml</title>\n';
opmlData += ' <dateCreated>2006-11-10</dateCreated>\n';
opmlData += ' <dateModified>2006-11-13</dateModified>\n';
opmlData += ' <ownerName>Magellan, Ferdinand</ownerName>\n';
opmlData += ' </head>\n';
opmlData += ' <body>\n';
opmlData += ' <outline text="Africa" type="continent" label="Continent/Africa">\n';
opmlData += ' <outline text="Egypt" type="country" label="Country/Egypt"/>\n';
opmlData += ' <outline text="Kenya" type="country" label="Country/Kenya">\n';
opmlData += ' <outline text="Nairobi" type="city" label="City/Nairobi"/>\n';
opmlData += ' <outline text="Mombasa" type="city" label="City/Mombasa"/>\n';
opmlData += ' </outline>\n';
opmlData += ' <outline text="Sudan" type="country" label="Country/Sudan">\n';
opmlData += ' <outline text="Khartoum" type="city" label="City/Khartoum"/>\n';
opmlData += ' </outline>\n';
opmlData += ' </outline>\n';
opmlData += ' <outline text="Asia" type="continent" label="Continent/Asia">\n';
opmlData += ' <outline text="China" type="country" label="Country/China"/>\n';
opmlData += ' <outline text="India" type="country" label="Country/India"/>\n';
opmlData += ' <outline text="Russia" type="country" label="Country/Russia"/>\n';
opmlData += ' <outline text="Mongolia" type="country" label="Country/Mongolia"/>\n';
opmlData += ' </outline>\n';
opmlData += ' <outline text="Australia" type="continent" population="21 million" label="Continent/Australia">\n';
opmlData += ' <outline text="Australia" type="country" population="21 million" label="Country/Australia"/>\n';
opmlData += ' </outline>\n';
opmlData += ' <outline text="Europe" type="continent" label="Contintent/Europe">\n';
opmlData += ' <outline text="Germany" type="country" label="Country/Germany"/>\n';
opmlData += ' <outline text="France" type="country" label="Country/France"/>\n';
opmlData += ' <outline text="Spain" type="country" label="Country/Spain"/>\n';
opmlData += ' <outline text="Italy" type="country" label="Country/Italy"/>\n';
opmlData += ' </outline>\n';
opmlData += ' <outline text="North America" type="continent" label="Continent/North America">\n';
opmlData += ' <outline text="Mexico" type="country" population="108 million" area="1,972,550 sq km" label="Country/Mexico">\n';
opmlData += ' <outline text="Mexico City" type="city" population="19 million" timezone="-6 UTC" label="City/Mexico City"/>\n';
opmlData += ' <outline text="Guadalajara" type="city" population="4 million" timezone="-6 UTC" label="City/Guadalajara"/>\n';
opmlData += ' </outline>\n';
opmlData += ' <outline text="Canada" type="country" population="33 million" area="9,984,670 sq km" label="Country/Canada">\n';
opmlData += ' <outline text="Ottawa" type="city" population="0.9 million" timezone="-5 UTC" label="City/Ottawa"/>\n';
opmlData += ' <outline text="Toronto" type="city" population="2.5 million" timezone="-5 UTC" label="City/Toronto"/>\n';
opmlData += ' </outline>\n';
opmlData += ' <outline text="United States of America" type="country" label="Country/United States of America"/>\n';
opmlData += ' </outline>\n';
opmlData += ' <outline text="South America" type="continent" label="Continent/South America">\n';
opmlData += ' <outline text="Brazil" type="country" population="186 million" label="Country/Brazil"/>\n';
opmlData += ' <outline text="Argentina" type="country" population="40 million" label="Country/Argentina"/>\n';
opmlData += ' </outline>\n';
opmlData += ' </body>\n';
opmlData += '</opml>\n';
break;
}
dataSource.data = opmlData;
}
return dataSource; //Object
}
 
dojox.data.tests.stores.OpmlStore.verifyItems = function(opmlStore, items, attribute, compareArray){
// summary:
// A helper function for validating that the items array is ordered
// the same as the compareArray
if(items.length != compareArray.length){ return false; }
for(var i = 0; i < items.length; i++){
if(!(opmlStore.getValue(items[i], attribute) === compareArray[i])){
return false; //Boolean
}
}
return true; //Boolean
}
 
dojox.data.tests.stores.OpmlStore.error = function(t, d, errData){
// summary:
// The error callback function to be used for all of the tests.
d.errback(errData);
}
 
doh.register("dojox.data.tests.stores.OpmlStore",
[
function testReadAPI_fetch_all(t){
// summary:
// Simple test of a basic fetch on OpmlStore.
// description:
// Simple test of a basic fetch on OpmlStore.
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
var opmlStore = new dojox.data.OpmlStore(args);
var d = new doh.Deferred();
function completedAll(items){
t.is(6, items.length);
d.callback(true);
}
 
//Get everything...
opmlStore.fetch({ onComplete: completedAll, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
return d; //Object
},
function testReadAPI_fetch_one(t){
// summary:
// Simple test of a basic fetch on OpmlStore of a single item.
// description:
// Simple test of a basic fetch on OpmlStore of a single item.
 
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
var opmlStore = new dojox.data.OpmlStore(args);
var d = new doh.Deferred();
function onComplete(items, request){
t.is(1, items.length);
d.callback(true);
}
opmlStore.fetch({ query: {text: "Asia"},
onComplete: onComplete,
onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
});
return d; //Object
},
 
function testReadAPI_fetch_one_Multiple(t){
// summary:
// Simple test of a basic fetch on OpmlStore of a single item.
// description:
// Simple test of a basic fetch on OpmlStore of a single item.
 
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
var opmlStore = new dojox.data.OpmlStore(args);
var d = new doh.Deferred();
var done = [false,false];
function onCompleteOne(items, request){
done[0] = true;
t.is(1, items.length);
if(done[0] && done[1]){
d.callback(true);
}
}
function onCompleteTwo(items, request){
done[1] = true;
t.is(1, items.length);
if(done[0] && done[1]){
d.callback(true);
}
}
 
opmlStore.fetch({ query: {text: "Asia"},
onComplete: onCompleteOne,
onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
});
 
opmlStore.fetch({ query: {text: "North America"},
onComplete: onCompleteTwo,
onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
});
 
return d; //Object
},
 
function testReadAPI_fetch_one_MultipleMixed(t){
// summary:
// Simple test of a basic fetch on OpmlStore of a single item mixing two fetch types.
// description:
// Simple test of a basic fetch on Cpmltore of a single item mixing two fetch types.
 
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
var opmlStore = new dojox.data.OpmlStore(args);
var d = new doh.Deferred();
 
var done = [false, false];
function onComplete(items, request){
done[0] = true;
t.is(1, items.length);
console.log("Found item: " + opmlStore.getValue(items[0],"text") + " with identity: " + opmlStore.getIdentity(items[0]));
t.is(0, opmlStore.getIdentity(items[0]));
if(done[0] && done[1]){
d.callback(true);
}
}
function onItem(item){
done[1] = true;
t.assertTrue(item !== null);
console.log("Found item: " + opmlStore.getValue(item,"text"));
t.is('Egypt', opmlStore.getValue(item,"text")); //Should be the second node parsed, ergo id 1, first node is id 0.
t.is(1, opmlStore.getIdentity(item));
if(done[0] && done[1]){
d.callback(true);
}
}
 
opmlStore.fetch({ query: {text: "Africa"},
onComplete: onComplete,
onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
});
opmlStore.fetchItemByIdentity({identity: "1", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
 
return d; //Object
},
 
function testReadAPI_fetch_one_deep(t){
// summary:
// Simple test of a basic fetch on OpmlStore of a single item that's nested down as a child item.
// description:
// Simple test of a basic fetch on OpmlStore of a single item that's nested down as a child item.
 
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
var opmlStore = new dojox.data.OpmlStore(args);
var d = new doh.Deferred();
function onComplete(items, request){
t.is(1, items.length);
d.callback(true);
}
opmlStore.fetch({ query: {text: "Mexico City"},
queryOptions: {deep:true},
onComplete: onComplete,
onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
});
return d; //Object
},
 
function testReadAPI_fetch_one_deep_off(t){
// summary:
// Simple test of a basic fetch on OpmlStore of a single item that's nested down as a child item.
// description:
// Simple test of a basic fetch on OpmlStore of a single item that's nested down as a child item.
 
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
var opmlStore = new dojox.data.OpmlStore(args);
var d = new doh.Deferred();
function onComplete(items, request){
//Nothing should be found.
t.is(0, items.length);
d.callback(true);
}
opmlStore.fetch({ query: {text: "Mexico City"},
onComplete: onComplete,
onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
});
return d; //Object
},
 
function testReadAPI_fetch_all_streaming(t){
// summary:
// Simple test of a basic fetch on OpmlStore.
// description:
// Simple test of a basic fetch on OpmlStore.
 
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
var opmlStore = new dojox.data.OpmlStore(args);
 
var d = new doh.Deferred();
count = 0;
 
function onBegin(size, requestObj){
t.is(6, size);
}
function onItem(item, requestObj){
t.assertTrue(opmlStore.isItem(item));
count++;
}
function onComplete(items, request){
t.is(6, count);
t.is(null, items);
d.callback(true);
}
 
//Get everything...
opmlStore.fetch({ onBegin: onBegin,
onItem: onItem,
onComplete: onComplete,
onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
});
return d; //Object
},
function testReadAPI_fetch_paging(t){
// summary:
// Test of multiple fetches on a single result. Paging, if you will.
// description:
// Test of multiple fetches on a single result. Paging, if you will.
 
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
var opmlStore = new dojox.data.OpmlStore(args);
var d = new doh.Deferred();
function dumpFirstFetch(items, request){
t.is(5, items.length);
request.start = 3;
request.count = 1;
request.onComplete = dumpSecondFetch;
opmlStore.fetch(request);
}
 
function dumpSecondFetch(items, request){
t.is(1, items.length);
request.start = 0;
request.count = 5;
request.onComplete = dumpThirdFetch;
opmlStore.fetch(request);
}
 
function dumpThirdFetch(items, request){
t.is(5, items.length);
request.start = 2;
request.count = 20;
request.onComplete = dumpFourthFetch;
opmlStore.fetch(request);
}
 
function dumpFourthFetch(items, request){
t.is(4, items.length);
request.start = 9;
request.count = 100;
request.onComplete = dumpFifthFetch;
opmlStore.fetch(request);
}
 
function dumpFifthFetch(items, request){
t.is(0, items.length);
request.start = 2;
request.count = 20;
request.onComplete = dumpSixthFetch;
opmlStore.fetch(request);
}
 
function dumpSixthFetch(items, request){
t.is(4, items.length);
d.callback(true);
}
 
function completed(items, request){
t.is(6, items.length);
request.start = 1;
request.count = 5;
request.onComplete = dumpFirstFetch;
opmlStore.fetch(request);
}
 
opmlStore.fetch({onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
return d; //Object
 
},
function testReadAPI_getLabel(t){
// summary:
// Simple test of the getLabel function against a store set that has a label defined.
// description:
// Simple test of the getLabel function against a store set that has a label defined.
 
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
var opmlStore = new dojox.data.OpmlStore(args);
var d = new doh.Deferred();
function onComplete(items, request){
t.assertEqual(items.length, 1);
var label = opmlStore.getLabel(items[0]);
t.assertTrue(label !== null);
t.assertEqual("Asia", label);
d.callback(true);
}
opmlStore.fetch({ query: {text: "Asia"},
onComplete: onComplete,
onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
});
return d;
},
function testReadAPI_getLabelAttributes(t){
// summary:
// Simple test of the getLabelAttributes function against a store set that has a label defined.
// description:
// Simple test of the getLabelAttributes function against a store set that has a label defined.
 
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
var opmlStore = new dojox.data.OpmlStore(args);
var d = new doh.Deferred();
function onComplete(items, request){
t.assertEqual(items.length, 1);
var labelList = opmlStore.getLabelAttributes(items[0]);
t.assertTrue(dojo.isArray(labelList));
t.assertEqual("text", labelList[0]);
d.callback(true);
}
opmlStore.fetch({ query: {text: "Asia"},
onComplete: onComplete,
onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
});
return d;
},
 
function testReadAPI_getLabel_nondefault(t){
// summary:
// Simple test of the getLabel function against a store set that has a label defined.
// description:
// Simple test of the getLabel function against a store set that has a label defined.
 
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography_withspeciallabel.xml");
args.label="label";
var opmlStore = new dojox.data.OpmlStore(args);
var d = new doh.Deferred();
function onComplete(items, request){
t.assertEqual(items.length, 1);
var label = opmlStore.getLabel(items[0]);
t.assertTrue(label !== null);
t.assertEqual("Continent/Asia", label);
d.callback(true);
}
opmlStore.fetch({ query: {text: "Asia"},
onComplete: onComplete,
onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
});
return d;
},
function testReadAPI_getLabelAttributes_nondefault(t){
// summary:
// Simple test of the getLabelAttributes function against a store set that has a label defined.
// description:
// Simple test of the getLabelAttributes function against a store set that has a label defined.
 
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography_withspeciallabel.xml");
args.label="label";
var opmlStore = new dojox.data.OpmlStore(args);
var d = new doh.Deferred();
function onComplete(items, request){
t.assertEqual(items.length, 1);
var labelList = opmlStore.getLabelAttributes(items[0]);
t.assertTrue(dojo.isArray(labelList));
t.assertEqual("label", labelList[0]);
d.callback(true);
}
opmlStore.fetch({ query: {text: "Asia"},
onComplete: onComplete,
onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
});
return d;
},
 
function testReadAPI_getValue(t){
// summary:
// Simple test of the getValue function of the store.
// description:
// Simple test of the getValue function of the store.
 
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
var opmlStore = new dojox.data.OpmlStore(args);
var d = new doh.Deferred();
function completedAll(items){
t.is(6, items.length);
t.is("Africa", opmlStore.getValue(items[0],"text"));
t.is("Asia", opmlStore.getValue(items[1],"text"));
t.is("Australia", opmlStore.getValue(items[2],"text"));
t.is("Europe", opmlStore.getValue(items[3],"text"));
t.is("North America", opmlStore.getValue(items[4],"text"));
t.is("South America", opmlStore.getValue(items[5],"text"));
t.is("continent", opmlStore.getValue(items[1],"type"));
t.is("21 million", opmlStore.getValue(items[2],"population"));
var firstChild = opmlStore.getValue(items[4],"children");
t.assertTrue(opmlStore.isItem(firstChild));
t.is("Mexico", opmlStore.getValue(firstChild,"text"));
t.is("country", opmlStore.getValue(firstChild,"type"));
t.is("108 million", opmlStore.getValue(firstChild,"population"));
t.is("1,972,550 sq km", opmlStore.getValue(firstChild,"area"));
firstChild = opmlStore.getValue(firstChild,"children");
t.assertTrue(opmlStore.isItem(firstChild));
t.is("Mexico City", opmlStore.getValue(firstChild,"text"));
t.is("city", opmlStore.getValue(firstChild,"type"));
t.is("19 million", opmlStore.getValue(firstChild,"population"));
t.is("-6 UTC", opmlStore.getValue(firstChild,"timezone"));
d.callback(true);
}
 
//Get everything...
opmlStore.fetch({ onComplete: completedAll, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
return d; //Object
},
function testReadAPI_getValues(t){
// summary:
// Simple test of the getValues function of the store.
// description:
// Simple test of the getValues function of the store.
 
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
var opmlStore = new dojox.data.OpmlStore(args);
 
var d = new doh.Deferred();
function completed(items){
t.is(1, items.length);
var children = opmlStore.getValues(items[0],"children");
t.is(3, children.length);
for(var i=0; i<children.length; i++){
t.assertTrue(opmlStore.isItem(children[i]));
}
t.is("Mexico", opmlStore.getValues(children[0],"text")[0]);
t.is("country", opmlStore.getValues(children[0],"type")[0]);
t.is("108 million", opmlStore.getValues(children[0],"population")[0]);
t.is("1,972,550 sq km", opmlStore.getValues(children[0],"area")[0]);
t.is("Canada", opmlStore.getValues(children[1],"text")[0]);
t.is("country", opmlStore.getValues(children[1],"type")[0]);
children = opmlStore.getValues(children[1],"children");
t.is(2, children.length);
for(var i=0; i<children.length; i++){
t.assertTrue(opmlStore.isItem(children[i]));
}
t.is("Ottawa", opmlStore.getValues(children[0],"text")[0]);
t.is("Toronto", opmlStore.getValues(children[1],"text")[0]);
d.callback(true);
}
 
//Get one item...
opmlStore.fetch({ query: {text: "North America"},
onComplete: completed,
onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
return d; //Object
},
function testReadAPI_isItem(t){
// summary:
// Simple test of the isItem function of the store
// description:
// Simple test of the isItem function of the store
 
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
var opmlStore = new dojox.data.OpmlStore(args);
 
var d = new doh.Deferred();
function completedAll(items){
t.is(6, items.length);
for(var i=0; i<6; i++){
t.assertTrue(opmlStore.isItem(items[i]));
}
t.assertTrue(!opmlStore.isItem({}));
t.assertTrue(!opmlStore.isItem({ item: "not an item" }));
t.assertTrue(!opmlStore.isItem("not an item"));
t.assertTrue(!opmlStore.isItem(["not an item"]));
d.callback(true);
}
 
//Get everything...
opmlStore.fetch({ onComplete: completedAll, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
return d; //Object
},
function testReadAPI_hasAttribute(t){
// summary:
// Simple test of the hasAttribute function of the store
// description:
// Simple test of the hasAttribute function of the store
 
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
var opmlStore = new dojox.data.OpmlStore(args);
 
var d = new doh.Deferred();
function onComplete(items){
t.is(1, items.length);
t.assertTrue(items[0] !== null);
t.assertTrue(opmlStore.hasAttribute(items[0], "text"));
t.assertTrue(opmlStore.hasAttribute(items[0], "type"));
t.assertTrue(!opmlStore.hasAttribute(items[0], "population"));
t.assertTrue(!opmlStore.hasAttribute(items[0], "Nothing"));
t.assertTrue(!opmlStore.hasAttribute(items[0], "Text"));
//Test that null attributes throw an exception
var passed = false;
try{
opmlStore.hasAttribute(items[0], null);
}catch (e){
passed = true;
}
t.assertTrue(passed);
d.callback(true);
}
 
//Get one item...
opmlStore.fetch({ query: {text: "Asia"},
onComplete: onComplete,
onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
});
return d; //Object
},
function testReadAPI_containsValue(t){
// summary:
// Simple test of the containsValue function of the store
// description:
// Simple test of the containsValue function of the store
 
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
var opmlStore = new dojox.data.OpmlStore(args);
var d = new doh.Deferred();
function onComplete(items){
t.is(1, items.length);
t.assertTrue(items[0] !== null);
t.assertTrue(opmlStore.containsValue(items[0], "text", "North America"));
t.assertTrue(opmlStore.containsValue(items[0], "type", "continent"));
t.assertTrue(!opmlStore.containsValue(items[0], "text", "America"));
t.assertTrue(!opmlStore.containsValue(items[0], "Type", "continent"));
t.assertTrue(!opmlStore.containsValue(items[0], "text", null));
var children = opmlStore.getValues(items[0], "children");
t.assertTrue(opmlStore.containsValue(items[0], "children", children[0]));
t.assertTrue(opmlStore.containsValue(items[0], "children", children[1]));
t.assertTrue(opmlStore.containsValue(items[0], "children", children[2]));
//Test that null attributes throw an exception
var passed = false;
try{
opmlStore.containsValue(items[0], null, "foo");
}catch (e){
passed = true;
}
t.assertTrue(passed);
d.callback(true);
}
 
//Get one item...
opmlStore.fetch({ query: {text: "North America"},
onComplete: onComplete,
onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
});
return d; //Object
},
function testReadAPI_getAttributes(t){
// summary:
// Simple test of the getAttributes function of the store
// description:
// Simple test of the getAttributes function of the store
 
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
var opmlStore = new dojox.data.OpmlStore(args);
 
var d = new doh.Deferred();
function onComplete(items){
t.is(6, items.length);
t.assertTrue(opmlStore.isItem(items[0]));
var attributes = opmlStore.getAttributes(items[0]);
t.is(3, attributes.length);
for(var i = 0; i < attributes.length; i++){
t.assertTrue((attributes[i] === "text" || attributes[i] === "type" || attributes[i] === "children"));
}
d.callback(true);
}
 
//Get everything...
opmlStore.fetch({ onComplete: onComplete, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
return d; //Object
},
function testReadAPI_getFeatures(t){
// summary:
// Simple test of the getFeatures function of the store
// description:
// Simple test of the getFeatures function of the store
 
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
var opmlStore = new dojox.data.OpmlStore(args);
 
var features = opmlStore.getFeatures();
var count = 0;
for(i in features){
t.assertTrue((i === "dojo.data.api.Read") || (i === "dojo.data.api.Identity"));
count++;
}
t.assertTrue(count === 2);
},
function testReadAPI_fetch_patternMatch0(t){
// summary:
// Function to test pattern matching of everything starting with Capital A
// description:
// Function to test pattern matching of everything starting with Capital A
 
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
var opmlStore = new dojox.data.OpmlStore(args);
 
var d = new doh.Deferred();
function completed(items, request){
t.is(3, items.length);
var valueArray = [ "Africa", "Asia", "Australia"];
t.assertTrue(dojox.data.tests.stores.OpmlStore.verifyItems(opmlStore, items, "text", valueArray));
d.callback(true);
}
opmlStore.fetch({query: {text: "A*"}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
return d; //Object
},
function testReadAPI_fetch_patternMatch1(t){
// summary:
// Function to test pattern matching of everything with America in it.
// description:
// Function to test pattern matching of everything with America in it.
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
var opmlStore = new dojox.data.OpmlStore(args);
var d = new doh.Deferred();
function completed(items, request){
t.assertTrue(items.length === 2);
var valueArray = [ "North America", "South America"];
t.assertTrue(dojox.data.tests.stores.OpmlStore.verifyItems(opmlStore, items, "text", valueArray));
d.callback(true);
}
opmlStore.fetch({query: {text: "*America*"}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
return d; //Object
},
function testReadAPI_fetch_patternMatch2(t){
// summary:
// Function to test exact pattern match
// description:
// Function to test exact pattern match
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
var opmlStore = new dojox.data.OpmlStore(args);
var d = new doh.Deferred();
function completed(items, request){
t.is(1, items.length);
t.assertTrue(opmlStore.getValue(items[0], "text") === "Europe");
d.callback(true);
}
opmlStore.fetch({query: {text: "Europe"}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
return d; //Object
},
function testReadAPI_fetch_patternMatch_caseInsensitive(t){
// summary:
// Function to test exact pattern match with case insensitivity set.
// description:
// Function to test exact pattern match with case insensitivity set.
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
var opmlStore = new dojox.data.OpmlStore(args);
var d = new doh.Deferred();
function completed(items, request){
t.is(1, items.length);
t.assertTrue(opmlStore.getValue(items[0], "text") === "Asia");
d.callback(true);
}
opmlStore.fetch({query: {text: "asia"}, queryOptions: {ignoreCase: true}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
return d; //Object
},
function testReadAPI_fetch_patternMatch_caseSensitive(t){
// summary:
// Function to test exact pattern match with case sensitivity set.
// description:
// Function to test exact pattern match with case sensitivity set.
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
var opmlStore = new dojox.data.OpmlStore(args);
var d = new doh.Deferred();
function completed(items, request){
t.is(0, items.length);
d.callback(true);
}
opmlStore.fetch({query: {text: "ASIA"}, queryOptions: {ignoreCase: false}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
return d; //Object
},
function testReadAPI_fetch_sortAlphabetic(t){
// summary:
// Function to test sorting alphabetic ordering.
// description:
// Function to test sorting alphabetic ordering.
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
var opmlStore = new dojox.data.OpmlStore(args);
var d = new doh.Deferred();
function completed(items, request){
//Output should be in this order...
var orderedArray = [ "Africa", "Asia", "Australia", "Europe", "North America", "South America"];
t.is(6, items.length);
t.assertTrue(dojox.data.tests.stores.OpmlStore.verifyItems(opmlStore, items, "text", orderedArray));
d.callback(true);
}
var sortAttributes = [{attribute: "text"}];
opmlStore.fetch({sort: sortAttributes, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
return d; //Object
},
function testReadAPI_fetch_sortAlphabeticDescending(t){
// summary:
// Function to test sorting alphabetic ordering in descending mode.
// description:
// Function to test sorting alphabetic ordering in descending mode.
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
var opmlStore = new dojox.data.OpmlStore(args);
var d = new doh.Deferred();
function completed(items, request){
//Output should be in this order...
var orderedArray = [ "South America", "North America", "Europe", "Australia", "Asia", "Africa"
];
t.is(6, items.length);
t.assertTrue(dojox.data.tests.stores.OpmlStore.verifyItems(opmlStore, items, "text", orderedArray));
d.callback(true);
}
var sortAttributes = [{attribute: "text", descending: true}];
opmlStore.fetch({sort: sortAttributes, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
return d; //Object
},
function testReadAPI_fetch_sortAlphabeticWithCount(t){
// summary:
// Function to test sorting numerically in descending order, returning only a specified number of them.
// description:
// Function to test sorting numerically in descending order, returning only a specified number of them.
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
var opmlStore = new dojox.data.OpmlStore(args);
var d = new doh.Deferred();
function completed(items, request){
//Output should be in this order...
var orderedArray = [ "South America", "North America", "Europe", "Australia"
];
t.is(4, items.length);
t.assertTrue(dojox.data.tests.stores.OpmlStore.verifyItems(opmlStore, items, "text", orderedArray));
d.callback(true);
}
var sortAttributes = [{attribute: "text", descending: true}];
opmlStore.fetch({sort: sortAttributes,
count: 4,
onComplete: completed,
onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
return d; //Object
},
function testReadAPI_functionConformance(t){
// summary:
// Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
// description:
// Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
 
var testStore = new dojox.data.OpmlStore(dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml"));
var readApi = new dojo.data.api.Read();
var passed = true;
 
for(i in readApi){
if(i.toString().charAt(0) !== '_')
{
var member = readApi[i];
//Check that all the 'Read' defined functions exist on the test store.
if(typeof member === "function"){
var testStoreMember = testStore[i];
if(!(typeof testStoreMember === "function")){
passed = false;
break;
}
}
}
}
t.assertTrue(passed);
},
function testIdentityAPI_fetchItemByIdentity(t){
// summary:
// Simple test of the fetchItemByIdentity function of the store.
// description:
// Simple test of the fetchItemByIdentity function of the store.
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
var opmlStore = new dojox.data.OpmlStore(args);
var d = new doh.Deferred();
function onItem(item){
t.assertTrue(item !== null);
d.callback(true);
}
opmlStore.fetchItemByIdentity({identity: "1", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
return d;
},
 
function testIdentityAPI_fetchItemByIdentity_bad1(t){
// summary:
// Simple test of the fetchItemByIdentity function of the store.
// description:
// Simple test of the fetchItemByIdentity function of the store.
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
var opmlStore = new dojox.data.OpmlStore(args);
var d = new doh.Deferred();
function onItem(item){
t.assertTrue(item === null);
d.callback(true);
}
opmlStore.fetchItemByIdentity({identity: "200", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
return d;
},
function testIdentityAPI_fetchItemByIdentity_bad2(t){
// summary:
// Simple test of the fetchItemByIdentity function of the store.
// description:
// Simple test of the fetchItemByIdentity function of the store.
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
var opmlStore = new dojox.data.OpmlStore(args);
var d = new doh.Deferred();
function onItem(item){
t.assertTrue(item === null);
d.callback(true);
}
opmlStore.fetchItemByIdentity({identity: "-1", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
return d;
},
function testIdentityAPI_fetchItemByIdentity_bad3(t){
// summary:
// Simple test of the fetchItemByIdentity function of the store.
// description:
// Simple test of the fetchItemByIdentity function of the store.
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
var opmlStore = new dojox.data.OpmlStore(args);
var d = new doh.Deferred();
function onItem(item){
t.assertTrue(item === null);
d.callback(true);
}
opmlStore.fetchItemByIdentity({identity: "999999", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
return d;
},
function testIdentityAPI_getIdentity(t){
// summary:
// Simple test of the fetchItemByIdentity function of the store.
// description:
// Simple test of the fetchItemByIdentity function of the store.
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
var opmlStore = new dojox.data.OpmlStore(args);
var d = new doh.Deferred();
function completed(items, request){
var passed = true;
for(var i = 0; i < items.length; i++){
console.log("Identity is: " + opmlStore.getIdentity(items[i]) + " count is : "+ i);
if(!(opmlStore.getIdentity(items[i]) == i)){
passed=false;
break;
}
}
t.assertTrue(passed);
d.callback(true);
}
//Get everything...
opmlStore.fetch({ onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d), queryOptions: {deep: true}});
return d; //Object
},
function testIdentityAPI_functionConformance(t){
// summary:
// Simple test identity API conformance. Checks to see all declared functions are actual functions on the instances.
// description:
// Simple test identity API conformance. Checks to see all declared functions are actual functions on the instances.
 
var testStore = new dojox.data.OpmlStore(dojox.data.tests.stores.CsvStore.getDatasource("stores/geography.xml"));
var identityApi = new dojo.data.api.Identity();
var passed = true;
 
for(i in identityApi){
if(i.toString().charAt(0) !== '_')
{
var member = identityApi[i];
//Check that all the 'Read' defined functions exist on the test store.
if(typeof member === "function"){
console.log("Looking at function: [" + i + "]");
var testStoreMember = testStore[i];
if(!(typeof testStoreMember === "function")){
passed = false;
break;
}
}
}
}
t.assertTrue(passed);
}
]
);
 
 
}
/trunk/api/js/dojo1.0/dojox/data/tests/stores/books3.xml
New file
0,0 → 1,31
<?xml version="1.0" encoding="ISO-8859-1"?>
<books>
<category>
<name>Category 1</name>
<book>
<isbn>1</isbn>
<title>Title of 1</title>
<author>Author of 1</author>
</book>
<book>
<isbn>2</isbn>
<title>Title of 2</title>
<author>Author of 2</author>
</book>
<book>
<isbn>3</isbn>
<title>Title of 3</title>
<author>Author of 3</author>
</book>
<book>
<isbn>4</isbn>
<title>Title of 4</title>
<author>Author of 4</author>
</book>
<book>
<isbn>5</isbn>
<title>Title of 5</title>
<author>Author of 5</author>
</book>
</category>
</books>
/trunk/api/js/dojo1.0/dojox/data/tests/stores/FlickrRestStore.js
New file
0,0 → 1,476
if(!dojo._hasResource["dojox.data.tests.stores.FlickrRestStore"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.data.tests.stores.FlickrRestStore"] = true;
dojo.provide("dojox.data.tests.stores.FlickrRestStore");
dojo.require("dojox.data.FlickrRestStore");
dojo.require("dojo.data.api.Read");
 
 
dojox.data.tests.stores.FlickrRestStore.error = function(t, d, errData){
// summary:
// The error callback function to be used for all of the tests.
d.errback(errData);
}
 
doh.register("dojox.data.tests.stores.FlickrRestStore",
[
{
name: "ReadAPI: Fetch_One",
timeout: 10000, //10 seconds. Flickr can sometimes be slow.
runTest: function(t) {
// summary:
// Simple test of a basic fetch on FlickrRestStore of a single item.
// description:
// Simple test of a basic fetch on FlickrRestStore of a single item.
 
var flickrStore = new dojox.data.FlickrRestStore();
 
var d = new doh.Deferred();
function onComplete(items, request){
t.is(1, items.length);
d.callback(true);
}
flickrStore.fetch({
query: {
userid: "44153025@N00",
apikey: "8c6803164dbc395fb7131c9d54843627"
},
count: 1,
onComplete: onComplete,
onError: dojo.partial(dojox.data.tests.stores.FlickrRestStore.error, doh, d)
});
return d; //Object
}
},
{
name: "ReadAPI: Fetch_20_Streaming",
timeout: 10000, //10 seconds. Flickr can sometimes be slow.
runTest: function(t) {
// summary:
// Simple test of a basic fetch on FlickrRestStore.
// description:
// Simple test of a basic fetch on FlickrRestStore.
var flickrStore = new dojox.data.FlickrRestStore();
 
var d = new doh.Deferred();
var count = 0;
 
function onItem(item, requestObj){
t.assertTrue(flickrStore.isItem(item));
count++;
}
function onComplete(items, request){
t.is(5, count);
t.is(null, items);
d.callback(true);
}
//Get everything...
flickrStore.fetch({
query: {
userid: "44153025@N00",
apikey: "8c6803164dbc395fb7131c9d54843627"
},
onBegin: null,
count: 5,
onItem: onItem,
onComplete: onComplete,
onError: dojo.partial(dojox.data.tests.stores.FlickrRestStore.error, t, d)
});
return d; //Object
}
},
{
name: "ReadAPI: Fetch_Paging",
timeout: 30000, //30 seconds. Flickr can sometimes be slow.
runTest: function(t) {
// summary:
// Test of multiple fetches on a single result. Paging, if you will.
// description:
// Test of multiple fetches on a single result. Paging, if you will.
 
var flickrStore = new dojox.data.FlickrRestStore();
 
var d = new doh.Deferred();
function dumpFirstFetch(items, request){
t.is(5, items.length);
request.start = 3;
request.count = 1;
request.onComplete = dumpSecondFetch;
flickrStore.fetch(request);
}
 
function dumpSecondFetch(items, request){
t.is(1, items.length);
request.start = 0;
request.count = 5;
request.onComplete = dumpThirdFetch;
flickrStore.fetch(request);
}
 
function dumpThirdFetch(items, request){
t.is(5, items.length);
request.start = 2;
request.count = 18;
request.onComplete = dumpFourthFetch;
flickrStore.fetch(request);
}
 
function dumpFourthFetch(items, request){
t.is(18, items.length);
request.start = 9;
request.count = 11;
request.onComplete = dumpFifthFetch;
flickrStore.fetch(request);
}
 
function dumpFifthFetch(items, request){
t.is(11, items.length);
request.start = 4;
request.count = 16;
request.onComplete = dumpSixthFetch;
flickrStore.fetch(request);
}
 
function dumpSixthFetch(items, request){
t.is(16, items.length);
d.callback(true);
}
 
function completed(items, request){
t.is(7, items.length);
request.start = 1;
request.count = 5;
request.onComplete = dumpFirstFetch;
flickrStore.fetch(request);
}
flickrStore.fetch({
query: {
userid: "44153025@N00",
apikey: "8c6803164dbc395fb7131c9d54843627"
},
count: 7,
onComplete: completed,
onError: dojo.partial(dojox.data.tests.stores.FlickrRestStore.error, t, d)
});
return d; //Object
}
},
{
name: "ReadAPI: getLabel",
timeout: 10000, //10 seconds. Flickr can sometimes be slow.
runTest: function(t) {
// summary:
// Simple test of the getLabel function against a store set that has a label defined.
// description:
// Simple test of the getLabel function against a store set that has a label defined.
 
var flickrStore = new dojox.data.FlickrRestStore();
 
var d = new doh.Deferred();
function onComplete(items, request){
t.assertEqual(items.length, 1);
var label = flickrStore.getLabel(items[0]);
t.assertTrue(label !== null);
d.callback(true);
}
flickrStore.fetch({
query: {
userid: "44153025@N00",
apikey: "8c6803164dbc395fb7131c9d54843627"
},
count: 1,
onComplete: onComplete,
onError: dojo.partial(dojox.data.tests.stores.FlickrRestStore.error, t, d)
});
return d;
}
},
{
name: "ReadAPI: getLabelAttributes",
timeout: 10000, //10 seconds. Flickr can sometimes be slow.
runTest: function(t) {
// summary:
// Simple test of the getLabelAttributes function against a store set that has a label defined.
// description:
// Simple test of the getLabelAttributes function against a store set that has a label defined.
 
var flickrStore = new dojox.data.FlickrRestStore();
 
var d = new doh.Deferred();
function onComplete(items, request){
t.assertEqual(items.length, 1);
var labelList = flickrStore.getLabelAttributes(items[0]);
t.assertTrue(dojo.isArray(labelList));
t.assertEqual("title", labelList[0]);
d.callback(true);
}
flickrStore.fetch({
query: {
userid: "44153025@N00",
apikey: "8c6803164dbc395fb7131c9d54843627"
},
count: 1,
onComplete: onComplete,
onError: dojo.partial(dojox.data.tests.stores.FlickrRestStore.error, t, d)
});
return d;
}
},
{
name: "ReadAPI: getValue",
timeout: 10000, //10 seconds. Flickr can sometimes be slow.
runTest: function(t) {
// summary:
// Simple test of the getValue function of the store.
// description:
// Simple test of the getValue function of the store.
var flickrStore = new dojox.data.FlickrRestStore();
 
var d = new doh.Deferred();
function completedAll(items){
t.is(1, items.length);
t.assertTrue(flickrStore.getValue(items[0], "title") !== null);
t.assertTrue(flickrStore.getValue(items[0], "imageUrl") !== null);
t.assertTrue(flickrStore.getValue(items[0], "imageUrlSmall") !== null);
t.assertTrue(flickrStore.getValue(items[0], "imageUrlMedium") !== null);
d.callback(true);
}
 
//Get one item and look at it.
flickrStore.fetch({
query: {
userid: "44153025@N00",
apikey: "8c6803164dbc395fb7131c9d54843627"
},
count: 1,
onComplete: completedAll,
onError: dojo.partial(dojox.data.tests.stores.FlickrRestStore.error, t, d)});
return d; //Object
}
},
{
name: "ReadAPI: getValues",
timeout: 10000, //10 seconds. Flickr can sometimes be slow.
runTest: function(t) {
// summary:
// Simple test of the getValue function of the store.
// description:
// Simple test of the getValue function of the store.
var flickrStore = new dojox.data.FlickrRestStore();
 
var d = new doh.Deferred();
function completedAll(items){
t.is(1, items.length);
var title = flickrStore.getValues(items[0], "title");
t.assertTrue(title instanceof Array);
var imgUrl = flickrStore.getValues(items[0], "imageUrl");
t.assertTrue(imgUrl instanceof Array);
var imgUrlSmall = flickrStore.getValues(items[0], "imageUrlSmall");
t.assertTrue(imgUrlSmall instanceof Array);
var imgUrlMedium = flickrStore.getValues(items[0], "imageUrlMedium");
t.assertTrue(imgUrlMedium instanceof Array);
d.callback(true);
}
//Get one item and look at it.
flickrStore.fetch({
query: {
userid: "44153025@N00",
apikey: "8c6803164dbc395fb7131c9d54843627"
},
count: 1,
onComplete: completedAll,
onError: dojo.partial(dojox.data.tests.stores.FlickrRestStore.error,
t,
d)});
return d; //Object
}
},
{
name: "ReadAPI: isItem",
timeout: 10000, //10 seconds. Flickr can sometimes be slow.
runTest: function(t) {
// summary:
// Simple test of the isItem function of the store
// description:
// Simple test of the isItem function of the store
var flickrStore = new dojox.data.FlickrRestStore();
 
var d = new doh.Deferred();
function completedAll(items){
t.is(5, items.length);
for(var i=0; i < items.length; i++){
t.assertTrue(flickrStore.isItem(items[i]));
}
d.callback(true);
}
 
//Get everything...
flickrStore.fetch({
query: {
userid: "44153025@N00",
apikey: "8c6803164dbc395fb7131c9d54843627"
},
count: 5,
onComplete: completedAll,
onError: dojo.partial(dojox.data.tests.stores.FlickrRestStore.error, t, d)
});
return d; //Object
}
},
{
name: "ReadAPI: hasAttribute",
timeout: 10000, //10 seconds. Flickr can sometimes be slow.
runTest: function(t) {
// summary:
// Simple test of the hasAttribute function of the store
// description:
// Simple test of the hasAttribute function of the store
 
var flickrStore = new dojox.data.FlickrRestStore();
 
var d = new doh.Deferred();
function onComplete(items){
t.is(1, items.length);
t.assertTrue(items[0] !== null);
t.assertTrue(flickrStore.hasAttribute(items[0], "title"));
t.assertTrue(flickrStore.hasAttribute(items[0], "author"));
t.assertTrue(!flickrStore.hasAttribute(items[0], "Nothing"));
t.assertTrue(!flickrStore.hasAttribute(items[0], "Text"));
 
//Test that null attributes throw an exception
var passed = false;
try{
flickrStore.hasAttribute(items[0], null);
}catch (e){
passed = true;
}
t.assertTrue(passed);
d.callback(true);
}
 
//Get one item...
flickrStore.fetch({
query: {
userid: "44153025@N00",
apikey: "8c6803164dbc395fb7131c9d54843627"
},
count: 1,
onComplete: onComplete,
onError: dojo.partial(dojox.data.tests.stores.FlickrRestStore.error, t, d)
});
return d; //Object
}
},
{
name: "ReadAPI: containsValue",
timeout: 10000, //10 seconds. Flickr can sometimes be slow.
runTest: function(t) {
// summary:
// Simple test of the containsValue function of the store
// description:
// Simple test of the containsValue function of the store
 
var flickrStore = new dojox.data.FlickrRestStore();
 
var d = new doh.Deferred();
function onComplete(items){
t.is(1, items.length);
d.callback(true);
}
 
//Get one item...
flickrStore.fetch({
query: {
userid: "44153025@N00",
apikey: "8c6803164dbc395fb7131c9d54843627"
},
count: 1,
onComplete: onComplete,
onError: dojo.partial(dojox.data.tests.stores.FlickrRestStore.error, t, d)
});
return d; //Object
}
},
{
name: "ReadAPI: getAttributes",
timeout: 10000, //10 seconds. Flickr can sometimes be slow.
runTest: function(t) {
// summary:
// Simple test of the getAttributes function of the store
// description:
// Simple test of the getAttributes function of the store
 
var flickrStore = new dojox.data.FlickrRestStore();
 
var d = new doh.Deferred();
function onComplete(items){
t.is(1, items.length);
t.assertTrue(flickrStore.isItem(items[0]));
 
var attributes = flickrStore.getAttributes(items[0]);
t.is(9, attributes.length);
d.callback(true);
}
 
//Get everything...
flickrStore.fetch({
query: {
userid: "44153025@N00",
apikey: "8c6803164dbc395fb7131c9d54843627"
},
count: 1,
onComplete: onComplete,
onError: dojo.partial(dojox.data.tests.stores.FlickrRestStore.error, t, d)
});
return d; //Object
}
},
function testReadAPI_getFeatures(t){
// summary:
// Simple test of the getFeatures function of the store
// description:
// Simple test of the getFeatures function of the store
 
var flickrStore = new dojox.data.FlickrRestStore();
 
var features = flickrStore.getFeatures();
var count = 0;
for(i in features){
t.assertTrue((i === "dojo.data.api.Read"));
count++;
}
t.assertTrue(count === 1);
},
function testReadAPI_functionConformance(t){
// summary:
// Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
// description:
// Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
 
var testStore = new dojox.data.FlickrRestStore();
var readApi = new dojo.data.api.Read();
var passed = true;
 
for(i in readApi){
if(i.toString().charAt(0) !== '_')
{
var member = readApi[i];
//Check that all the 'Read' defined functions exist on the test store.
if(typeof member === "function"){
var testStoreMember = testStore[i];
if(!(typeof testStoreMember === "function")){
passed = false;
break;
}
}
}
}
}
]
);
 
 
}
/trunk/api/js/dojo1.0/dojox/data/tests/stores/FlickrStore.js
New file
0,0 → 1,410
if(!dojo._hasResource["dojox.data.tests.stores.FlickrStore"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.data.tests.stores.FlickrStore"] = true;
dojo.provide("dojox.data.tests.stores.FlickrStore");
dojo.require("dojox.data.FlickrStore");
dojo.require("dojo.data.api.Read");
 
 
dojox.data.tests.stores.FlickrStore.error = function(t, d, errData){
// summary:
// The error callback function to be used for all of the tests.
d.errback(errData);
}
 
doh.register("dojox.data.tests.stores.FlickrStore",
[
{
name: "ReadAPI: Fetch_One",
timeout: 10000, //10 seconds. Flickr can sometimes be slow.
runTest: function(t) {
// summary:
// Simple test of a basic fetch on FlickrStore of a single item.
// description:
// Simple test of a basic fetch on FlickrStore of a single item.
 
var flickrStore = new dojox.data.FlickrStore();
 
var d = new doh.Deferred();
function onComplete(items, request){
t.is(1, items.length);
d.callback(true);
}
flickrStore.fetch({ query: {tags: "animals"},
count: 1,
onComplete: onComplete,
onError: dojo.partial(dojox.data.tests.stores.FlickrStore.error, doh, d)
});
return d; //Object
}
},
{
name: "ReadAPI: Fetch_20_Streaming",
timeout: 10000, //10 seconds. Flickr can sometimes be slow.
runTest: function(t) {
// summary:
// Simple test of a basic fetch on FlickrStore.
// description:
// Simple test of a basic fetch on FlickrStore.
var flickrStore = new dojox.data.FlickrStore();
 
var d = new doh.Deferred();
count = 0;
 
function onBegin(size, requestObj){
t.is(20, size);
}
function onItem(item, requestObj){
t.assertTrue(flickrStore.isItem(item));
count++;
}
function onComplete(items, request){
t.is(20, count);
t.is(null, items);
d.callback(true);
}
 
//Get everything...
flickrStore.fetch({ onBegin: onBegin,
count: 20,
onItem: onItem,
onComplete: onComplete,
onError: dojo.partial(dojox.data.tests.stores.FlickrStore.error, t, d)
});
return d; //Object
}
},
{
name: "ReadAPI: Fetch_Paging",
timeout: 30000, //30 seconds. Flickr can sometimes be slow.
runTest: function(t) {
// summary:
// Test of multiple fetches on a single result. Paging, if you will.
// description:
// Test of multiple fetches on a single result. Paging, if you will.
 
var flickrStore = new dojox.data.FlickrStore();
 
var d = new doh.Deferred();
function dumpFirstFetch(items, request){
t.is(5, items.length);
request.start = 3;
request.count = 1;
request.onComplete = dumpSecondFetch;
flickrStore.fetch(request);
}
 
function dumpSecondFetch(items, request){
t.is(1, items.length);
request.start = 0;
request.count = 5;
request.onComplete = dumpThirdFetch;
flickrStore.fetch(request);
}
 
function dumpThirdFetch(items, request){
t.is(5, items.length);
request.start = 2;
request.count = 20;
request.onComplete = dumpFourthFetch;
flickrStore.fetch(request);
}
 
function dumpFourthFetch(items, request){
t.is(18, items.length);
request.start = 9;
request.count = 100;
request.onComplete = dumpFifthFetch;
flickrStore.fetch(request);
}
 
function dumpFifthFetch(items, request){
t.is(11, items.length);
request.start = 2;
request.count = 20;
request.onComplete = dumpSixthFetch;
flickrStore.fetch(request);
}
 
function dumpSixthFetch(items, request){
t.is(18, items.length);
d.callback(true);
}
 
function completed(items, request){
t.is(7, items.length);
request.start = 1;
request.count = 5;
request.onComplete = dumpFirstFetch;
flickrStore.fetch(request);
}
flickrStore.fetch({count: 7, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.FlickrStore.error, t, d)});
return d; //Object
}
},
{
name: "ReadAPI: getLabel",
timeout: 10000, //10 seconds. Flickr can sometimes be slow.
runTest: function(t) {
// summary:
// Simple test of the getLabel function against a store set that has a label defined.
// description:
// Simple test of the getLabel function against a store set that has a label defined.
 
var flickrStore = new dojox.data.FlickrStore();
 
var d = new doh.Deferred();
function onComplete(items, request){
t.assertEqual(items.length, 1);
var label = flickrStore.getLabel(items[0]);
t.assertTrue(label !== null);
d.callback(true);
}
flickrStore.fetch({ query: {tags: "animals"},
count: 1,
onComplete: onComplete,
onError: dojo.partial(dojox.data.tests.stores.FlickrStore.error, t, d)
});
return d;
}
},
{
name: "ReadAPI: getLabelAttributes",
timeout: 10000, //10 seconds. Flickr can sometimes be slow.
runTest: function(t) {
// summary:
// Simple test of the getLabelAttributes function against a store set that has a label defined.
// description:
// Simple test of the getLabelAttributes function against a store set that has a label defined.
 
var flickrStore = new dojox.data.FlickrStore();
 
var d = new doh.Deferred();
function onComplete(items, request){
t.assertEqual(items.length, 1);
var labelList = flickrStore.getLabelAttributes(items[0]);
t.assertTrue(dojo.isArray(labelList));
t.assertEqual("title", labelList[0]);
d.callback(true);
}
flickrStore.fetch({ query: {tags: "animals"},
count: 1,
onComplete: onComplete,
onError: dojo.partial(dojox.data.tests.stores.FlickrStore.error, t, d)
});
return d;
}
},
{
name: "ReadAPI: getValue",
timeout: 10000, //10 seconds. Flickr can sometimes be slow.
runTest: function(t) {
// summary:
// Simple test of the getValue function of the store.
// description:
// Simple test of the getValue function of the store.
var flickrStore = new dojox.data.FlickrStore();
 
var d = new doh.Deferred();
function completedAll(items){
t.is(1, items.length);
t.assertTrue(flickrStore.getValue(items[0], "title") !== null);
t.assertTrue(flickrStore.getValue(items[0], "imageUrl") !== null);
t.assertTrue(flickrStore.getValue(items[0], "imageUrlSmall") !== null);
t.assertTrue(flickrStore.getValue(items[0], "imageUrlMedium") !== null);
d.callback(true);
}
 
//Get one item and look at it.
flickrStore.fetch({ count: 1, onComplete: completedAll, onError: dojo.partial(dojox.data.tests.stores.FlickrStore.error, t, d)});
return d; //Object
}
},
{
name: "ReadAPI: getValues",
timeout: 10000, //10 seconds. Flickr can sometimes be slow.
runTest: function(t) {
// summary:
// Simple test of the getValue function of the store.
// description:
// Simple test of the getValue function of the store.
var flickrStore = new dojox.data.FlickrStore();
 
var d = new doh.Deferred();
function completedAll(items){
t.is(1, items.length);
t.assertTrue(flickrStore.getValues(items[0], "title") instanceof Array);
t.assertTrue(flickrStore.getValues(items[0], "description") instanceof Array);
t.assertTrue(flickrStore.getValues(items[0], "imageUrl") instanceof Array);
t.assertTrue(flickrStore.getValues(items[0], "imageUrlSmall") instanceof Array);
t.assertTrue(flickrStore.getValues(items[0], "imageUrlMedium") instanceof Array);
d.callback(true);
}
//Get one item and look at it.
flickrStore.fetch({ count: 1, onComplete: completedAll, onError: dojo.partial(dojox.data.tests.stores.FlickrStore.error, t, d)});
return d; //Object
}
},
{
name: "ReadAPI: isItem",
timeout: 10000, //10 seconds. Flickr can sometimes be slow.
runTest: function(t) {
// summary:
// Simple test of the isItem function of the store
// description:
// Simple test of the isItem function of the store
var flickrStore = new dojox.data.FlickrStore();
 
var d = new doh.Deferred();
function completedAll(items){
t.is(5, items.length);
for(var i=0; i < items.length; i++){
t.assertTrue(flickrStore.isItem(items[i]));
}
d.callback(true);
}
 
//Get everything...
flickrStore.fetch({ count: 5, onComplete: completedAll, onError: dojo.partial(dojox.data.tests.stores.FlickrStore.error, t, d)});
return d; //Object
}
},
{
name: "ReadAPI: hasAttribute",
timeout: 10000, //10 seconds. Flickr can sometimes be slow.
runTest: function(t) {
// summary:
// Simple test of the hasAttribute function of the store
// description:
// Simple test of the hasAttribute function of the store
 
var flickrStore = new dojox.data.FlickrStore();
 
var d = new doh.Deferred();
function onComplete(items){
t.is(1, items.length);
t.assertTrue(items[0] !== null);
t.assertTrue(flickrStore.hasAttribute(items[0], "title"));
t.assertTrue(flickrStore.hasAttribute(items[0], "description"));
t.assertTrue(flickrStore.hasAttribute(items[0], "author"));
t.assertTrue(!flickrStore.hasAttribute(items[0], "Nothing"));
t.assertTrue(!flickrStore.hasAttribute(items[0], "Text"));
 
//Test that null attributes throw an exception
var passed = false;
try{
flickrStore.hasAttribute(items[0], null);
}catch (e){
passed = true;
}
t.assertTrue(passed);
d.callback(true);
}
 
//Get one item...
flickrStore.fetch({ query: {tags: "animals"},
count: 1,
onComplete: onComplete,
onError: dojo.partial(dojox.data.tests.stores.FlickrStore.error, t, d)
});
return d; //Object
}
},
{
name: "ReadAPI: containsValue",
timeout: 10000, //10 seconds. Flickr can sometimes be slow.
runTest: function(t) {
// summary:
// Simple test of the containsValue function of the store
// description:
// Simple test of the containsValue function of the store
 
var flickrStore = new dojox.data.FlickrStore();
 
var d = new doh.Deferred();
function onComplete(items){
t.is(1, items.length);
d.callback(true);
}
 
//Get one item...
flickrStore.fetch({ query: {tags: "animals"},
count: 1,
onComplete: onComplete,
onError: dojo.partial(dojox.data.tests.stores.FlickrStore.error, t, d)
});
return d; //Object
}
},
{
name: "ReadAPI: getAttributes",
timeout: 10000, //10 seconds. Flickr can sometimes be slow.
runTest: function(t) {
// summary:
// Simple test of the getAttributes function of the store
// description:
// Simple test of the getAttributes function of the store
 
var flickrStore = new dojox.data.FlickrStore();
 
var d = new doh.Deferred();
function onComplete(items){
t.is(1, items.length);
t.assertTrue(flickrStore.isItem(items[0]));
 
var attributes = flickrStore.getAttributes(items[0]);
t.is(10, attributes.length);
d.callback(true);
}
 
//Get everything...
flickrStore.fetch({ count: 1, onComplete: onComplete, onError: dojo.partial(dojox.data.tests.stores.FlickrStore.error, t, d)});
return d; //Object
}
},
function testReadAPI_getFeatures(t){
// summary:
// Simple test of the getFeatures function of the store
// description:
// Simple test of the getFeatures function of the store
 
var flickrStore = new dojox.data.FlickrStore();
 
var features = flickrStore.getFeatures();
var count = 0;
for(i in features){
t.assertTrue((i === "dojo.data.api.Read"));
count++;
}
t.assertTrue(count === 1);
},
function testReadAPI_functionConformance(t){
// summary:
// Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
// description:
// Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
 
var testStore = new dojox.data.FlickrStore();
var readApi = new dojo.data.api.Read();
var passed = true;
 
for(i in readApi){
if(i.toString().charAt(0) !== '_')
{
var member = readApi[i];
//Check that all the 'Read' defined functions exist on the test store.
if(typeof member === "function"){
var testStoreMember = testStore[i];
if(!(typeof testStoreMember === "function")){
passed = false;
break;
}
}
}
}
t.assertTrue(passed);
}
]
);
 
 
}
/trunk/api/js/dojo1.0/dojox/data/tests/stores/books2.html
New file
0,0 → 1,43
<html>
<head>
<title>Books2.html</title>
</head>
<body>
<table id="books2">
<thead>
<tr>
<th>isbn</th>
<th>title</th>
<th>author</th>
</tr>
</thead>
<tbody>
<tr>
<td>A9B57C</td>
<td>Title of 1</td>
<td>Author of 1</td>
</tr>
<tr>
<td>A9B57F</td>
<td>Title of 2</td>
<td>Author of 2</td>
</tr>
<tr>
<td>A9B577</td>
<td>Title of 3</td>
<td>Author of 3</td>
</tr>
<tr>
<td>A9B574</td>
<td>Title of 4</td>
<td>Author of 4</td>
</tr>
<tr>
<td>A9B5CC</td>
<td>Title of 5</td>
<td>Author of 5</td>
</tr>
</tbody>
</table>
</body>
</html>
/trunk/api/js/dojo1.0/dojox/data/tests/stores/books_isbnAttr2.xml
New file
0,0 → 1,23
<?xml version="1.0" encoding="ISO-8859-1"?>
<books>
<book isbn="ABC1">
<title>Title of 1</title>
<author>Author of 1</author>
</book>
<book isbn="ABC2">
<title>Title of 2</title>
<author>Author of 2</author>
</book>
<book isbn="ABC3">
<title>Title of 3</title>
<author>Author of 3</author>
</book>
<book isbn="ACB4">
<title>Title of 4</title>
<author>Author of 4</author>
</book>
<book isbn="ACF5">
<title>Title of 5</title>
<author>Author of 5</author>
</book>
</books>
/trunk/api/js/dojo1.0/dojox/data/tests/stores/QueryReadStore.php
New file
0,0 → 1,92
<?php
 
header("Content-Type", "text/json");
 
$allItems = array(
array('name'=>"Alabama", 'label'=>"<img src='images/Alabama.jpg'/>Alabama", 'abbreviation'=>"AL"),
array('name'=>"Alaska", 'label'=>"Alaska", 'abbreviation'=>"AK"),
array('name'=>"American Samoa", 'label'=>"American Samoa", 'abbreviation'=>"AS"),
array('name'=>"Arizona", 'label'=>"Arizona", 'abbreviation'=>"AZ"),
array('name'=>"Arkansas", 'label'=>"Arkansas", 'abbreviation'=>"AR"),
array('name'=>"Armed Forces Europe", 'label'=>"Armed Forces Europe", 'abbreviation'=>"AE"),
array('name'=>"Armed Forces Pacific", 'label'=>"Armed Forces Pacific", 'abbreviation'=>"AP"),
array('name'=>"Armed Forces the Americas", 'label'=>"Armed Forces the Americas", 'abbreviation'=>"AA"),
array('name'=>"California", 'label'=>"California", 'abbreviation'=>"CA"),
array('name'=>"Colorado", 'label'=>"Colorado", 'abbreviation'=>"CO"),
array('name'=>"Connecticut", 'label'=>"Connecticut", 'abbreviation'=>"CT"),
array('name'=>"Delaware", 'label'=>"Delaware", 'abbreviation'=>"DE"),
array('name'=>"District of Columbia", 'label'=>"District of Columbia", 'abbreviation'=>"DC"),
array('name'=>"Federated States of Micronesia", 'label'=>"Federated States of Micronesia", 'abbreviation'=>"FM"),
array('name'=>"Florida", 'label'=>"Florida", 'abbreviation'=>"FL"),
array('name'=>"Georgia", 'label'=>"Georgia", 'abbreviation'=>"GA"),
array('name'=>"Guam", 'label'=>"Guam", 'abbreviation'=>"GU"),
array('name'=>"Hawaii", 'label'=>"Hawaii", 'abbreviation'=>"HI"),
array('name'=>"Idaho", 'label'=>"Idaho", 'abbreviation'=>"ID"),
array('name'=>"Illinois", 'label'=>"Illinois", 'abbreviation'=>"IL"),
array('name'=>"Indiana", 'label'=>"Indiana", 'abbreviation'=>"IN"),
array('name'=>"Iowa", 'label'=>"Iowa", 'abbreviation'=>"IA"),
array('name'=>"Kansas", 'label'=>"Kansas", 'abbreviation'=>"KS"),
array('name'=>"Kentucky", 'label'=>"Kentucky", 'abbreviation'=>"KY"),
array('name'=>"Louisiana", 'label'=>"Louisiana", 'abbreviation'=>"LA"),
array('name'=>"Maine", 'label'=>"Maine", 'abbreviation'=>"ME"),
array('name'=>"Marshall Islands", 'label'=>"Marshall Islands", 'abbreviation'=>"MH"),
array('name'=>"Maryland", 'label'=>"Maryland", 'abbreviation'=>"MD"),
array('name'=>"Massachusetts", 'label'=>"Massachusetts", 'abbreviation'=>"MA"),
array('name'=>"Michigan", 'label'=>"Michigan", 'abbreviation'=>"MI"),
array('name'=>"Minnesota", 'label'=>"Minnesota", 'abbreviation'=>"MN"),
array('name'=>"Mississippi", 'label'=>"Mississippi", 'abbreviation'=>"MS"),
array('name'=>"Missouri", 'label'=>"Missouri", 'abbreviation'=>"MO"),
array('name'=>"Montana", 'label'=>"Montana", 'abbreviation'=>"MT"),
array('name'=>"Nebraska", 'label'=>"Nebraska", 'abbreviation'=>"NE"),
array('name'=>"Nevada", 'label'=>"Nevada", 'abbreviation'=>"NV"),
array('name'=>"New Hampshire", 'label'=>"New Hampshire", 'abbreviation'=>"NH"),
array('name'=>"New Jersey", 'label'=>"New Jersey", 'abbreviation'=>"NJ"),
array('name'=>"New Mexico", 'label'=>"New Mexico", 'abbreviation'=>"NM"),
array('name'=>"New York", 'label'=>"New York", 'abbreviation'=>"NY"),
array('name'=>"North Carolina", 'label'=>"North Carolina", 'abbreviation'=>"NC"),
array('name'=>"North Dakota", 'label'=>"North Dakota", 'abbreviation'=>"ND"),
array('name'=>"Northern Mariana Islands", 'label'=>"Northern Mariana Islands", 'abbreviation'=>"MP"),
array('name'=>"Ohio", 'label'=>"Ohio", 'abbreviation'=>"OH"),
array('name'=>"Oklahoma", 'label'=>"Oklahoma", 'abbreviation'=>"OK"),
array('name'=>"Oregon", 'label'=>"Oregon", 'abbreviation'=>"OR"),
array('name'=>"Pennsylvania", 'label'=>"Pennsylvania", 'abbreviation'=>"PA"),
array('name'=>"Puerto Rico", 'label'=>"Puerto Rico", 'abbreviation'=>"PR"),
array('name'=>"Rhode Island", 'label'=>"Rhode Island", 'abbreviation'=>"RI"),
array('name'=>"South Carolina", 'label'=>"South Carolina", 'abbreviation'=>"SC"),
array('name'=>"South Dakota", 'label'=>"South Dakota", 'abbreviation'=>"SD"),
array('name'=>"Tennessee", 'label'=>"Tennessee", 'abbreviation'=>"TN"),
array('name'=>"Texas", 'label'=>"Texas", 'abbreviation'=>"TX"),
array('name'=>"Utah", 'label'=>"Utah", 'abbreviation'=>"UT"),
array('name'=>"Vermont", 'label'=>"Vermont", 'abbreviation'=>"VT"),
array('name'=> "Virgin Islands, U.S.", 'label'=>"Virgin Islands, U.S.", 'abbreviation'=>"VI"),
array('name'=>"Virginia", 'label'=>"Virginia", 'abbreviation'=>"VA"),
array('name'=>"Washington", 'label'=>"Washington", 'abbreviation'=>"WA"),
array('name'=>"West Virginia", 'label'=>"West Virginia", 'abbreviation'=>"WV"),
array('name'=>"Wisconsin", 'label'=>"Wisconsin", 'abbreviation'=>"WI"),
array('name'=>"Wyoming", 'label'=>"Wyoming", 'abbreviation'=>"WY"),
// array('id'=>, 'name'=>''),
);
 
$q = "";
if (array_key_exists("q", $_REQUEST)) {
$q = $_REQUEST['q'];
}
if (strlen($q) && $q[strlen($q)-1]=="*") {
$q = substr($q, 0, strlen($q)-1);
}
$ret = array();
foreach ($allItems as $item) {
if (!$q || strpos(strtolower($item['name']), strtolower($q))===0) {
$ret[] = $item;
}
}
 
// Handle paging, if given.
if (array_key_exists("start", $_REQUEST)) {
$ret = array_slice($ret, $_REQUEST['start']);
}
if (array_key_exists("count", $_REQUEST)) {
$ret = array_slice($ret, 0, $_REQUEST['count']);
}
 
print '/*'.json_encode(array('items'=>$ret)).'*/';
/trunk/api/js/dojo1.0/dojox/data/tests/stores/HtmlTableStore.js
New file
0,0 → 1,702
if(!dojo._hasResource["dojox.data.tests.stores.HtmlTableStore"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.data.tests.stores.HtmlTableStore"] = true;
dojo.provide("dojox.data.tests.stores.HtmlTableStore");
dojo.require("dojox.data.HtmlTableStore");
dojo.require("dojo.data.api.Read");
dojo.require("dojo.data.api.Identity");
 
 
dojox.data.tests.stores.HtmlTableStore.getBooks2Store = function(){
return new dojox.data.HtmlTableStore({url: dojo.moduleUrl("dojox.data.tests", "stores/books2.html").toString(), tableId: "books2"});
};
 
dojox.data.tests.stores.HtmlTableStore.getBooksStore = function(){
return new dojox.data.HtmlTableStore({url: dojo.moduleUrl("dojox.data.tests", "stores/books.html").toString(), tableId: "books"});
};
 
doh.register("dojox.data.tests.stores.HtmlTableStore",
[
/***************************************
dojo.data.api.Read API
***************************************/
function testReadAPI_fetch_all(t){
// summary:
// Simple test of fetching all xml items through an XML element called isbn
// description:
// Simple test of fetching all xml items through an XML element called isbn
var store = dojox.data.tests.stores.HtmlTableStore.getBooksStore();
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(20, items.length);
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"*"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_fetch_one(t){
// summary:
// Simple test of fetching one xml items through an XML element called isbn
// description:
// Simple test of fetching one xml items through an XML element called isbn
var store = dojox.data.tests.stores.HtmlTableStore.getBooks2Store();
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(1, items.length);
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_fetch_paging(t){
// summary:
// Simple test of fetching one xml items through an XML element called isbn
// description:
// Simple test of fetching one xml items through an XML element called isbn
var store = dojox.data.tests.stores.HtmlTableStore.getBooksStore();
var d = new doh.Deferred();
function dumpFirstFetch(items, request){
t.assertEqual(5, items.length);
request.start = 3;
request.count = 1;
request.onComplete = dumpSecondFetch;
store.fetch(request);
}
 
function dumpSecondFetch(items, request){
t.assertEqual(1, items.length);
request.start = 0;
request.count = 5;
request.onComplete = dumpThirdFetch;
store.fetch(request);
}
 
function dumpThirdFetch(items, request){
t.assertEqual(5, items.length);
request.start = 2;
request.count = 20;
request.onComplete = dumpFourthFetch;
store.fetch(request);
}
 
function dumpFourthFetch(items, request){
t.assertEqual(18, items.length);
request.start = 9;
request.count = 100;
request.onComplete = dumpFifthFetch;
store.fetch(request);
}
 
function dumpFifthFetch(items, request){
t.assertEqual(11, items.length);
request.start = 2;
request.count = 20;
request.onComplete = dumpSixthFetch;
store.fetch(request);
}
 
function dumpSixthFetch(items, request){
t.assertEqual(18, items.length);
d.callback(true);
}
 
function completed(items, request){
t.assertEqual(20, items.length);
request.start = 1;
request.count = 5;
request.onComplete = dumpFirstFetch;
store.fetch(request);
}
 
function error(errData, request){
d.errback(errData);
}
 
store.fetch({onComplete: completed, onError: error});
return d; //Object
},
function testReadAPI_fetch_pattern0(t){
// summary:
// Simple test of fetching one xml items through an XML element called isbn with ? pattern match
// description:
// Simple test of fetching one xml items through an XML element called isbn with ? pattern match
var store = dojox.data.tests.stores.HtmlTableStore.getBooks2Store();
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(1, items.length);
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"?9B574"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_fetch_pattern1(t){
// summary:
// Simple test of fetching one xml items through an XML element called isbn with ? pattern match
// description:
// Simple test of fetching one xml items through an XML element called isbn with ? pattern match
var store = dojox.data.tests.stores.HtmlTableStore.getBooks2Store();
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(4, items.length);
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9B57?"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_fetch_pattern2(t){
// summary:
// Simple test of fetching one xml items through an XML element called isbn with * pattern match
// description:
// Simple test of fetching one xml items through an XML element called isbn with * pattern match
var store = dojox.data.tests.stores.HtmlTableStore.getBooks2Store();
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(5, items.length);
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9*"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_fetch_pattern_caseInsensitive(t){
// summary:
// Simple test of fetching one xml items through an XML element called isbn with ? pattern match and in case insensitive mode.
// description:
// Simple test of fetching one xml items through an XML element called isbn with ? pattern match and in case insensitive mode.
var store = dojox.data.tests.stores.HtmlTableStore.getBooks2Store();
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(1, items.length);
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"?9b574"}, queryOptions: {ignoreCase: true}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_fetch_pattern_caseSensitive(t){
// summary:
// Simple test of fetching one xml items through an XML element called isbn with ? pattern match and in case sensitive mode.
// description:
// Simple test of fetching one xml items through an XML element called isbn with ? pattern match and in case sensitive mode.
var store = dojox.data.tests.stores.HtmlTableStore.getBooks2Store();
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(1, items.length);
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"?9B574"}, queryOptions: {ignoreCase: false}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_getLabel(t){
// summary:
// Simple test of the getLabel function against a store set that has a label defined.
// description:
// Simple test of the getLabel function against a store set that has a label defined.
 
var store = dojox.data.tests.stores.HtmlTableStore.getBooks2Store();
var d = new doh.Deferred();
function onComplete(items, request){
t.assertEqual(items.length, 1);
var label = store.getLabel(items[0]);
t.assertTrue(label !== null);
t.assertEqual("Table Row #3", label);
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
return d;
},
function testReadAPI_getLabelAttributes(t){
// summary:
// Simple test of the getLabelAttributes function against a store set that has a label defined.
// description:
// Simple test of the getLabelAttributes function against a store set that has a label defined.
 
var store = dojox.data.tests.stores.HtmlTableStore.getBooks2Store();
var d = new doh.Deferred();
function onComplete(items, request){
t.assertEqual(items.length, 1);
var labelList = store.getLabelAttributes(items[0]);
t.assertTrue(labelList === null);
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
return d;
},
 
function testReadAPI_getValue(t){
// summary:
// Simple test of the getValue API
// description:
// Simple test of the getValue API
var store = dojox.data.tests.stores.HtmlTableStore.getBooks2Store();
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(1, items.length);
var item = items[0];
t.assertTrue(store.hasAttribute(item,"isbn"));
t.assertEqual(store.getValue(item,"isbn"), "A9B574");
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_getValues(t){
// summary:
// Simple test of the getValues API
// description:
// Simple test of the getValues API
var store = dojox.data.tests.stores.HtmlTableStore.getBooks2Store();
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(1, items.length);
var item = items[0];
t.assertTrue(store.hasAttribute(item,"isbn"));
var values = store.getValues(item,"isbn");
t.assertEqual(1,values.length);
t.assertEqual("A9B574", values[0]);
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_isItem(t){
// summary:
// Simple test of the isItem API
// description:
// Simple test of the isItem API
var store = dojox.data.tests.stores.HtmlTableStore.getBooks2Store();
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(1, items.length);
var item = items[0];
t.assertTrue(store.isItem(item));
t.assertTrue(!store.isItem({}));
t.assertTrue(!store.isItem("Foo"));
t.assertTrue(!store.isItem(1));
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_isItem_multistore(t){
// summary:
// Simple test of the isItem API across multiple store instances.
// description:
// Simple test of the isItem API across multiple store instances.
var store1 = dojox.data.tests.stores.HtmlTableStore.getBooksStore();
var store2 = dojox.data.tests.stores.HtmlTableStore.getBooks2Store();
 
var d = new doh.Deferred();
function onComplete1(items, request) {
t.assertEqual(1, items.length);
var item1 = items[0];
t.assertTrue(store1.isItem(item1));
 
function onComplete2(items, request) {
t.assertEqual(1, items.length);
var item2 = items[0];
t.assertTrue(store2.isItem(item2));
t.assertTrue(!store1.isItem(item2));
t.assertTrue(!store2.isItem(item1));
d.callback(true);
}
store2.fetch({query:{isbn:"A9B574"}, onComplete: onComplete2, onError: onError});
}
function onError(error, request) {
d.errback(error);
}
store1.fetch({query:{isbn:"1"}, onComplete: onComplete1, onError: onError});
return d; //Object
},
function testReadAPI_hasAttribute(t){
// summary:
// Simple test of the hasAttribute API
// description:
// Simple test of the hasAttribute API
var store = dojox.data.tests.stores.HtmlTableStore.getBooks2Store();
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(1, items.length);
var item = items[0];
t.assertTrue(store.hasAttribute(item,"isbn"));
t.assertTrue(!store.hasAttribute(item,"bob"));
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_containsValue(t){
// summary:
// Simple test of the containsValue API
// description:
// Simple test of the containsValue API
var store = dojox.data.tests.stores.HtmlTableStore.getBooks2Store();
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(1, items.length);
var item = items[0];
t.assertTrue(store.containsValue(item,"isbn", "A9B574"));
t.assertTrue(!store.containsValue(item,"isbn", "bob"));
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_sortDescending(t){
// summary:
// Simple test of the sorting API in descending order.
// description:
// Simple test of the sorting API in descending order.
var store = dojox.data.tests.stores.HtmlTableStore.getBooksStore();
 
//Comparison is done as a string type (toString comparison), so the order won't be numeric
//So have to compare in 'alphabetic' order.
var order = [9,8,7,6,5,4,3,20,2,19,18,17,16,15,14,13,12,11,10,1];
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(20, items.length);
 
for(var i = 0; i < items.length; i++){
t.assertEqual(order[i], store.getValue(items[i],"isbn").toString());
}
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
 
var sortAttributes = [{attribute: "isbn", descending: true}];
store.fetch({query:{isbn:"*"}, sort: sortAttributes, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_sortAscending(t){
// summary:
// Simple test of the sorting API in ascending order.
// description:
// Simple test of the sorting API in ascending order.
var store = dojox.data.tests.stores.HtmlTableStore.getBooksStore();
 
//Comparison is done as a string type (toString comparison), so the order won't be numeric
//So have to compare in 'alphabetic' order.
var order = [1,10,11,12,13,14,15,16,17,18,19,2,20,3,4,5,6,7,8,9];
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(20, items.length);
var itemId = 1;
for(var i = 0; i < items.length; i++){
t.assertEqual(order[i], store.getValue(items[i],"isbn").toString());
}
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
 
var sortAttributes = [{attribute: "isbn"}];
store.fetch({query:{isbn:"*"}, sort: sortAttributes, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_sortDescendingNumeric(t){
// summary:
// Simple test of the sorting API in descending order using a numeric comparator.
// description:
// Simple test of the sorting API in descending order using a numeric comparator.
var store = dojox.data.tests.stores.HtmlTableStore.getBooksStore();
 
//isbn should be treated as a numeric, not as a string comparison
store.comparatorMap = {};
store.comparatorMap["isbn"] = function(a, b){
var ret = 0;
if(parseInt(a.toString()) > parseInt(b.toString())){
ret = 1;
}else if(parseInt(a.toString()) < parseInt(b.toString())){
ret = -1;
}
return ret; //int, {-1,0,1}
};
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(20, items.length);
var itemId = 20;
for(var i = 0; i < items.length; i++){
t.assertEqual(itemId, store.getValue(items[i],"isbn").toString());
itemId--;
}
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
 
var sortAttributes = [{attribute: "isbn", descending: true}];
store.fetch({query:{isbn:"*"}, sort: sortAttributes, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_sortAscendingNumeric(t){
// summary:
// Simple test of the sorting API in ascending order using a numeric comparator.
// description:
// Simple test of the sorting API in ascending order using a numeric comparator.
var store = dojox.data.tests.stores.HtmlTableStore.getBooksStore();
 
//isbn should be treated as a numeric, not as a string comparison
store.comparatorMap = {};
store.comparatorMap["isbn"] = function(a, b){
var ret = 0;
if(parseInt(a.toString()) > parseInt(b.toString())){
ret = 1;
}else if(parseInt(a.toString()) < parseInt(b.toString())){
ret = -1;
}
return ret; //int, {-1,0,1}
};
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(20, items.length);
var itemId = 1;
for(var i = 0; i < items.length; i++){
t.assertEqual(itemId, store.getValue(items[i],"isbn").toString());
itemId++;
}
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
 
var sortAttributes = [{attribute: "isbn"}];
store.fetch({query:{isbn:"*"}, sort: sortAttributes, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_isItemLoaded(t){
// summary:
// Simple test of the isItemLoaded API
// description:
// Simple test of the isItemLoaded API
var store = dojox.data.tests.stores.HtmlTableStore.getBooks2Store();
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(1, items.length);
var item = items[0];
t.assertTrue(store.isItemLoaded(item));
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_getFeatures(t){
// summary:
// Simple test of the getFeatures function of the store
// description:
// Simple test of the getFeatures function of the store
 
var store = dojox.data.tests.stores.HtmlTableStore.getBooks2Store();
var features = store.getFeatures();
var count = 0;
for(i in features){
t.assertTrue((i === "dojo.data.api.Read" || i === "dojo.data.api.Identity"));
count++;
}
t.assertEqual(2, count);
},
function testReadAPI_getAttributes(t){
// summary:
// Simple test of the getAttributes API
// description:
// Simple test of the getAttributes API
var store = dojox.data.tests.stores.HtmlTableStore.getBooks2Store();
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(1, items.length);
var item = items[0];
var attributes = store.getAttributes(item);
t.assertEqual(3,attributes.length);
for(var i=0; i<attributes.length; i++){
t.assertTrue((attributes[i] === "isbn" || attributes[i] === "title" || attributes[i] === "author"));
}
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testReadAPI_functionConformance(t){
// summary:
// Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
// description:
// Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
 
var testStore = dojox.data.tests.stores.HtmlTableStore.getBooksStore();
var readApi = new dojo.data.api.Read();
var passed = true;
 
for(i in readApi){
var member = readApi[i];
//Check that all the 'Read' defined functions exist on the test store.
if(typeof member === "function"){
var testStoreMember = testStore[i];
if(!(typeof testStoreMember === "function")){
console.log("Problem with function: [" + i + "]");
passed = false;
break;
}
}
}
t.assertTrue(passed);
},
/***************************************
dojo.data.api.Identity API
***************************************/
function testIdentityAPI_getIdentity(t){
// summary:
// Simple test of the getAttributes API
// description:
// Simple test of the getAttributes API
var store = dojox.data.tests.stores.HtmlTableStore.getBooks2Store();
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(1, items.length);
var item = items[0];
t.assertEqual(3,store.getIdentity(item));
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testIdentityAPI_getIdentityAttributes(t){
// summary:
// Simple test of the getAttributes API
// description:
// Simple test of the getAttributes API
var store = dojox.data.tests.stores.HtmlTableStore.getBooks2Store();
 
var d = new doh.Deferred();
function onComplete(items, request) {
t.assertEqual(1, items.length);
var item = items[0];
//Should have none, as it's not a public attribute.
var attributes = store.getIdentityAttributes(item);
t.assertEqual(null, attributes);
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError});
return d; //Object
},
function testIdentityAPI_fetchItemByIdentity(t){
// summary:
// Simple test of the fetchItemByIdentity API
// description:
// Simple test of the fetchItemByIdentity API
var store = dojox.data.tests.stores.HtmlTableStore.getBooks2Store();
 
var d = new doh.Deferred();
function onItem(item, request) {
t.assertTrue(item !== null);
t.assertTrue(store.isItem(item));
t.assertEqual("A9B574", store.getValue(item, "isbn"));
d.callback(true);
}
function onError(error, request) {
d.errback(error);
}
store.fetchItemByIdentity({identity: 3, onItem: onItem, onError: onError});
return d; //Object
},
function testIdentityAPI_functionConformance(t){
// summary:
// Simple test identity API conformance. Checks to see all declared functions are actual functions on the instances.
// description:
// Simple test identity API conformance. Checks to see all declared functions are actual functions on the instances.
 
var testStore = dojox.data.tests.stores.HtmlTableStore.getBooksStore();
var identityApi = new dojo.data.api.Identity();
var passed = true;
 
for(i in identityApi){
var member = identityApi[i];
//Check that all the 'Read' defined functions exist on the test store.
if(typeof member === "function"){
var testStoreMember = testStore[i];
if(!(typeof testStoreMember === "function")){
console.log("Problem with function: [" + i + "]");
passed = false;
break;
}
}
}
t.assertTrue(passed);
}
]
);
 
//Register the remote tests ... when they work.
//doh.registerUrl("dojox.data.tests.stores.HtmlTableStore.remote", dojo.moduleUrl("dojox.data.tests", "ml/test_HtmlTableStore_declaratively.html"));
 
}
/trunk/api/js/dojo1.0/dojox/data/tests/stores/books.xml
New file
0,0 → 1,103
<?xml version="1.0" encoding="ISO-8859-1"?>
<books>
<book>
<isbn>1</isbn>
<title>Title of 1</title>
<author>Author of 1</author>
</book>
<book>
<isbn>2</isbn>
<title>Title of 2</title>
<author>Author of 2</author>
</book>
<book>
<isbn>3</isbn>
<title>Title of 3</title>
<author>Author of 3</author>
</book>
<book>
<isbn>4</isbn>
<title>Title of 4</title>
<author>Author of 4</author>
</book>
<book>
<isbn>5</isbn>
<title>Title of 5</title>
<author>Author of 5</author>
</book>
<book>
<isbn>6</isbn>
<title>Title of 6</title>
<author>Author of 6</author>
</book>
<book>
<isbn>7</isbn>
<title>Title of 7</title>
<author>Author of 7</author>
</book>
<book>
<isbn>8</isbn>
<title>Title of 8</title>
<author>Author of 8</author>
</book>
<book>
<isbn>9</isbn>
<title>Title of 9</title>
<author>Author of 9</author>
</book>
<book>
<isbn>10</isbn>
<title>Title of 10</title>
<author>Author of 10</author>
</book>
<book>
<isbn>11</isbn>
<title>Title of 11</title>
<author>Author of 11</author>
</book>
<book>
<isbn>12</isbn>
<title>Title of 12</title>
<author>Author of 12</author>
</book>
<book>
<isbn>13</isbn>
<title>Title of 13</title>
<author>Author of 13</author>
</book>
<book>
<isbn>14</isbn>
<title>Title of 14</title>
<author>Author of 14</author>
</book>
<book>
<isbn>15</isbn>
<title>Title of 15</title>
<author>Author of 15</author>
</book>
<book>
<isbn>16</isbn>
<title>Title of 16</title>
<author>Author of 16</author>
</book>
<book>
<isbn>17</isbn>
<title>Title of 17</title>
<author>Author of 17</author>
</book>
<book>
<isbn>18</isbn>
<title>Title of 18</title>
<author>Author of 18</author>
</book>
<book>
<isbn>19</isbn>
<title>Title of 19</title>
<author>Author of 19</author>
</book>
<book>
<isbn>20</isbn>
<title>Title of 20</title>
<author>Author of 20</author>
</book>
</books>
/trunk/api/js/dojo1.0/dojox/data/tests/module.js
New file
0,0 → 1,24
if(!dojo._hasResource["dojox.data.tests.module"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.data.tests.module"] = true;
dojo.provide("dojox.data.tests.module");
 
try{
dojo.require("dojox.data.tests.stores.CsvStore");
dojo.requireIf(dojo.isBrowser, "dojox.data.tests.stores.HtmlTableStore");
dojo.requireIf(dojo.isBrowser, "dojox.data.tests.stores.OpmlStore");
dojo.requireIf(dojo.isBrowser, "dojox.data.tests.stores.XmlStore");
dojo.requireIf(dojo.isBrowser, "dojox.data.tests.stores.FlickrStore");
dojo.requireIf(dojo.isBrowser, "dojox.data.tests.stores.FlickrRestStore");
//Load only if in a browser AND if the location is remote (not file. As it needs a PHP server to work).
if(dojo.isBrowser){
if(window.location.protocol !== "file:"){
dojo.require("dojox.data.tests.stores.QueryReadStore");
}
}
dojo.requireIf(dojo.isBrowser, "dojox.data.tests.dom");
}catch(e){
doh.debug(e);
}
 
 
}
/trunk/api/js/dojo1.0/dojox/data/tests/QueryReadStore.html
New file
0,0 → 1,221
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<style type="text/css">
@import "../../../dojo/resources/dojo.css";
@import "../../../dijit/themes/tundra/tundra.css";
@import "../../../dijit/themes/tundra/tundra_rtl.css";
</style>
 
<title>Query read store</title>
 
<script type="text/javascript" src="../../../dojo/dojo.js" djConfig="isDebug: true, parseOnLoad: true"></script>
<script type="text/javascript" src="../../../dojo/data/util/simpleFetch.js"></script>
<script type="text/javascript" src="../../../dojox/data/QueryReadStore.js"></script>
<script type="text/javascript">
dojo.require("dijit.form.ComboBox");
dojo.require("dijit.form.FilteringSelect");
dojo.require("dojox.data.QueryReadStore");
 
dojo.provide("ComboBoxReadStore");
dojo.declare("ComboBoxReadStore", dojox.data.QueryReadStore, {
fetch:function(request) {
// Copy the GET/POST parameters (request.query) we need into
// request.serverQuery. We actually want to have
// the query added to the URL like so: /url.php?q=<searchString>
// The data in "queryOptions" are useless for our backend,
// we ignore them, they are not sent to the server.
// The combobox puts this into the request-parameter:
// {
// query: {name:<searchString>},
// queryOptions: {ignoreCase:true, deep:true},
// ...
// }
// We generate request.serverQuery to be this, since those values will
// be sent to the server.
// {
// q:<searchString>}
// }
// This results in a xhr request to the following URL (in case of GET):
// /url.php?q=<searchString>
//
 
request.serverQuery = {q:request.query.name};
// If we wanted to send the queryOptions too, we could simply do:
// request.serverQuery = {
// q:request.query.name,
// ignoreCase:request.queryOptions.ignoreCase,
// deep:request.queryOptions.deep
// };
// This would then result in this URL, for ignoreCase and deep
// assumed to be true:
// /url.php?q=<searchString>&ignoreCase=true&deep=true
return this.inherited("fetch", arguments);
}
});
 
dojo.provide("ServerPagingReadStore");
dojo.declare("ServerPagingReadStore", dojox.data.QueryReadStore, {
fetch:function(request) {
request.serverQuery = {q:request.query.name, start:request.start, count:request.count};
return this.inherited("fetch", arguments);
}
});
 
var testStore = new dojox.data.QueryReadStore({url:'stores/QueryReadStore.php'});;
function doSearch() {
var queryOptions = {};
if (dojo.byId("ignoreCaseEnabled").checked) {
queryOptions.ignoreCase = dojo.query("#fetchForm")[0].ignoreCase[0].checked;
}
if (dojo.byId("deepEnabled").checked) {
queryOptions.deep = dojo.query("#fetchForm")[0].deep[0].checked;
}
var query = {};
query.q = dojo.byId("searchText").value;
var request = {query:query, queryOptions:queryOptions};
request.start = parseInt(dojo.query("#fetchForm")[0].pagingStart.value);
request.count = parseInt(dojo.query("#fetchForm")[0].pagingCount.value);
 
var requestMethod = "get";
var radioButtons = dojo.query("#fetchForm")[0].requestMethod;
for (var i=0; i<radioButtons.length; i++){
if (radioButtons[i].checked) {
requestMethod = radioButtons[i].value;
}
}
testStore.requestMethod = requestMethod;
testStore.doClientPaging = dojo.query("#fetchForm")[0].doClientPaging.checked;
if (!testStore.doClientPaging) {
// We have to fill the serverQuery, since we also want to send the
// paging data "start" and "count" along with what is in query.
request.serverQuery = {q:request.query.q, start:request.start, count:request.count};
}
request.onComplete = function (items) {
var s = "number of items: "+items.length+"<br /><br />";
for (var i=0; i<items.length; i++) {
s += i+": name: '"+testStore.getValue(items[i], "name")+"'<br />";
}
//s += "<pre>"+dojo.toJson(items)+"</pre>";
dojo.byId("fetchOutput").innerHTML = s;
};
 
console.log(dojo.toJson(request));
testStore.fetch(request);
}
</script>
</head>
<body class="tundra" style="margin:20px;">
<div dojoType="ComboBoxReadStore" jsId="store" url="stores/QueryReadStore.php" requestMethod="get"></div>
This is a ComboBox: <input id="cb" dojoType="dijit.form.ComboBox" store="store" pageSize="5" />
<br /><br /><hr />
 
This is a FilteringSelect: <input id="fs" dojoType="dijit.form.FilteringSelect" store="store" pageSize="5" />
<br />
<form id="filteringSelectForm">
<input id="selectById" value="0" size="3" />
<input type="button" value="set by id" onclick="dijit.byId('fs').setValue(dojo.byId('selectById').value)" />
</form>
<br /><br /><hr />
 
This ComboBox uses a customized QueryReadStore, it prepares the query-string for the URL that
way that the paging parameters "start" and "count" are also send.<br />
<div dojoType="ServerPagingReadStore" jsId="serverPagingStore" url="stores/QueryReadStore.php" requestMethod="get" doClientPaging="false"></div>
<input dojoType="dijit.form.ComboBox" store="serverPagingStore" pageSize="5" />
<br />
<a href="javascript://" onclick="var d = dojo.byId('pagingCode'); d.style.display= d.style.display=='none'?'block':'none';">Click here to see the code!</a>
<div id="pagingCode" style="display:none;">
The HTML might look like this, the important attribute: <em>doClientPaging="false"</em> this takes care that the same query is fired to the server
and its not assumed that the client (the store) does the paging on the old data.
<pre>
&lt;div dojoType="ServerPagingReadStore" jsId="serverPagingStore" url="stores/QueryReadStore.php" requestMethod="get" doClientPaging="false"&gt;&lt;/div&gt;
&lt;input dojoType="dijit.form.ComboBox" store="serverPagingStore" pageSize="10" /&gt;
</pre>
<pre>
dojo.require("dojox.data.QueryReadStore");
dojo.provide("ServerPagingReadStore");
dojo.declare("ServerPagingReadStore", dojox.data.QueryReadStore, {
fetch:function(request) {
request.serverQuery = {q:request.query.name, start:request.start, count:request.count};
return this.inherited("fetch", arguments);
}
});
</pre>
</div>
<br /><br />
<hr />
<style>
fieldset {
border:1px solid black;
display:inline;
padding:10px;
}
div.disabled {
opacity:0.1;
}
</style>
<form id="fetchForm">
<fieldset title="requestMethod">
<legend>requestMethod</legend>
get <input type="radio" value="get" checked="checked" name="requestMethod" />
post <input type="radio" value="post" name="requestMethod" />
</fieldset>
<fieldset title="queryOptions">
<legend>queryOptions</legend>
 
<fieldset id="ignoreCaseFieldset">
<legend><input type="checkbox" id="ignoreCaseEnabled" /> ignoreCase</legend>
<div class="disabled">
true <input type="radio" value="0" checked="checked" name="ignoreCase" />
false <input type="radio" value="1" name="ignoreCase" />
</div>
</fieldset>
<fieldset id="deepFieldset">
<legend><input type="checkbox" id="deepEnabled" /> deep</legend>
<div class="disabled">
true <input type="radio" value="0" name="deep" />
false <input type="radio" value="1" name="deep" checked="checked" />
</div>
</fieldset>
</fieldset>
<fieldset title="paging">
<legend>paging</legend>
start: <input id="pagingStart" value="0" size="3" />
count: <input id="pagingCount" value="10" size="3" />
<br /><br />
do client paging: <input id="doClientPaging" type="checkbox" checked="checked" />
</fieldset>
<script>
var fieldsets = ["ignoreCaseFieldset", "deepFieldset"];
for (var i=0; i<fieldsets.length; i++) {
dojo.connect(dojo.byId(fieldsets[i]), "onchange", toggleFieldset);
}
function toggleFieldset(el) {
var divs = dojo.query("div", el.target.parentNode.parentNode);
if (divs.length) {
var div = divs[0];
if (el.target.checked) {
dojo.removeClass(div, "disabled");
} else {
dojo.addClass(div, "disabled");
}
}
}
</script>
<br /><br />
<input id="searchText" type="text" value="a">
<input id="searchButton" type="button" value="store.fetch()" onclick="doSearch()" />
</form>
<div id="fetchOutput" style="background-color:#FFDDDD; margin-top:1em; float:left;"></div>
</body>
</html>
/trunk/api/js/dojo1.0/dojox/data/CsvStore.js
New file
0,0 → 1,552
if(!dojo._hasResource["dojox.data.CsvStore"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.data.CsvStore"] = true;
dojo.provide("dojox.data.CsvStore");
 
dojo.require("dojo.data.util.filter");
dojo.require("dojo.data.util.simpleFetch");
 
dojo.declare("dojox.data.CsvStore", null, {
// summary:
// The CsvStore implements the dojo.data.api.Read API and reads
// data from files in CSV (Comma Separated Values) format.
// All values are simple string values. References to other items
// are not supported as attribute values in this datastore.
//
// Example data file:
// name, color, age, tagline
// Kermit, green, 12, "Hi, I'm Kermit the Frog."
// Fozzie Bear, orange, 10, "Wakka Wakka Wakka!"
// Miss Piggy, pink, 11, "Kermie!"
//
// Note that values containing a comma must be enclosed with quotes ("")
// Also note that values containing quotes must be escaped with two consecutive quotes (""quoted"")
/* examples:
* var csvStore = new dojox.data.CsvStore({url:"movies.csv");
* var csvStore = new dojox.data.CsvStore({url:"http://example.com/movies.csv");
*/
 
constructor: function(/* Object */ keywordParameters){
// summary: initializer
// keywordParameters: {url: String}
// keywordParameters: {data: String}
// keywordParameters: {label: String} The column label for the column to use for the label returned by getLabel.
this._attributes = []; // e.g. ["Title", "Year", "Producer"]
this._attributeIndexes = {}; // e.g. {Title: 0, Year: 1, Producer: 2}
this._dataArray = []; // e.g. [[<Item0>],[<Item1>],[<Item2>]]
this._arrayOfAllItems = []; // e.g. [{_csvId:0,_csvStore:store},...]
this._loadFinished = false;
if(keywordParameters.url){
this.url = keywordParameters.url;
}
this._csvData = keywordParameters.data;
if(keywordParameters.label){
this.label = keywordParameters.label;
}else if(this.label === ""){
this.label = undefined;
}
this._storeProp = "_csvStore"; // Property name for the store reference on every item.
this._idProp = "_csvId"; // Property name for the Item Id on every item.
this._features = {
'dojo.data.api.Read': true,
'dojo.data.api.Identity': true
};
this._loadInProgress = false; //Got to track the initial load to prevent duelling loads of the dataset.
this._queuedFetches = [];
},
 
url: "", //Declarative hook for setting Csv source url.
 
label: "", //Declarative hook for setting the label attribute.
_assertIsItem: function(/* item */ item){
// summary:
// This function tests whether the item passed in is indeed an item in the store.
// item:
// The item to test for being contained by the store.
if(!this.isItem(item)){
throw new Error("dojox.data.CsvStore: a function was passed an item argument that was not an item");
}
},
_assertIsAttribute: function(/* item || String */ attribute){
// summary:
// This function tests whether the item passed in is indeed a valid 'attribute' like type for the store.
// attribute:
// The attribute to test for being contained by the store.
if(!dojo.isString(attribute)){
throw new Error("dojox.data.CsvStore: a function was passed an attribute argument that was not an attribute object nor an attribute name string");
}
},
 
/***************************************
dojo.data.api.Read API
***************************************/
getValue: function( /* item */ item,
/* attribute || attribute-name-string */ attribute,
/* value? */ defaultValue){
// summary:
// See dojo.data.api.Read.getValue()
// Note that for the CsvStore, an empty string value is the same as no value,
// so the defaultValue would be returned instead of an empty string.
this._assertIsItem(item);
this._assertIsAttribute(attribute);
var itemValue = defaultValue;
if(this.hasAttribute(item, attribute)){
var itemData = this._dataArray[this.getIdentity(item)];
itemValue = itemData[this._attributeIndexes[attribute]];
}
return itemValue; //String
},
 
getValues: function(/* item */ item,
/* attribute || attribute-name-string */ attribute){
// summary:
// See dojo.data.api.Read.getValues()
// CSV syntax does not support multi-valued attributes, so this is just a
// wrapper function for getValue().
var value = this.getValue(item, attribute);
return (value ? [value] : []); //Array
},
 
getAttributes: function(/* item */ item){
// summary:
// See dojo.data.api.Read.getAttributes()
this._assertIsItem(item);
var attributes = [];
var itemData = this._dataArray[this.getIdentity(item)];
for(var i=0; i<itemData.length; i++){
// Check for empty string values. CsvStore treats empty strings as no value.
if(itemData[i] != ""){
attributes.push(this._attributes[i]);
}
}
return attributes; //Array
},
 
hasAttribute: function( /* item */ item,
/* attribute || attribute-name-string */ attribute){
// summary:
// See dojo.data.api.Read.hasAttribute()
// The hasAttribute test is true if attribute has an index number within the item's array length
// AND if the item has a value for that attribute. Note that for the CsvStore, an
// empty string value is the same as no value.
this._assertIsItem(item);
this._assertIsAttribute(attribute);
var attributeIndex = this._attributeIndexes[attribute];
var itemData = this._dataArray[this.getIdentity(item)];
return (typeof attributeIndex != "undefined" && attributeIndex < itemData.length && itemData[attributeIndex] != ""); //Boolean
},
 
containsValue: function(/* item */ item,
/* attribute || attribute-name-string */ attribute,
/* anything */ value){
// summary:
// See dojo.data.api.Read.containsValue()
var regexp = undefined;
if(typeof value === "string"){
regexp = dojo.data.util.filter.patternToRegExp(value, false);
}
return this._containsValue(item, attribute, value, regexp); //boolean.
},
 
_containsValue: function( /* item */ item,
/* attribute || attribute-name-string */ attribute,
/* anything */ value,
/* RegExp?*/ regexp){
// summary:
// Internal function for looking at the values contained by the item.
// description:
// Internal function for looking at the values contained by the item. This
// function allows for denoting if the comparison should be case sensitive for
// strings or not (for handling filtering cases where string case should not matter)
//
// item:
// The data item to examine for attribute values.
// attribute:
// The attribute to inspect.
// value:
// The value to match.
// regexp:
// Optional regular expression generated off value if value was of string type to handle wildcarding.
// If present and attribute values are string, then it can be used for comparison instead of 'value'
var values = this.getValues(item, attribute);
for(var i = 0; i < values.length; ++i){
var possibleValue = values[i];
if(typeof possibleValue === "string" && regexp){
return (possibleValue.match(regexp) !== null);
}else{
//Non-string matching.
if(value === possibleValue){
return true; // Boolean
}
}
}
return false; // Boolean
},
 
isItem: function(/* anything */ something){
// summary:
// See dojo.data.api.Read.isItem()
if(something && something[this._storeProp] === this){
var identity = something[this._idProp];
if(identity >= 0 && identity < this._dataArray.length){
return true; //Boolean
}
}
return false; //Boolean
},
 
isItemLoaded: function(/* anything */ something){
// summary:
// See dojo.data.api.Read.isItemLoaded()
// The CsvStore always loads all items, so if it's an item, then it's loaded.
return this.isItem(something); //Boolean
},
 
loadItem: function(/* item */ item){
// summary:
// See dojo.data.api.Read.loadItem()
// description:
// The CsvStore always loads all items, so if it's an item, then it's loaded.
// From the dojo.data.api.Read.loadItem docs:
// If a call to isItemLoaded() returns true before loadItem() is even called,
// then loadItem() need not do any work at all and will not even invoke
// the callback handlers.
},
 
getFeatures: function(){
// summary:
// See dojo.data.api.Read.getFeatures()
return this._features; //Object
},
 
getLabel: function(/* item */ item){
// summary:
// See dojo.data.api.Read.getLabel()
if(this.label && this.isItem(item)){
return this.getValue(item,this.label); //String
}
return undefined; //undefined
},
 
getLabelAttributes: function(/* item */ item){
// summary:
// See dojo.data.api.Read.getLabelAttributes()
if(this.label){
return [this.label]; //array
}
return null; //null
},
 
 
// The dojo.data.api.Read.fetch() function is implemented as
// a mixin from dojo.data.util.simpleFetch.
// That mixin requires us to define _fetchItems().
_fetchItems: function( /* Object */ keywordArgs,
/* Function */ findCallback,
/* Function */ errorCallback){
// summary:
// See dojo.data.util.simpleFetch.fetch()
var self = this;
 
var filter = function(requestArgs, arrayOfAllItems){
var items = null;
if(requestArgs.query){
items = [];
var ignoreCase = requestArgs.queryOptions ? requestArgs.queryOptions.ignoreCase : false;
 
//See if there are any string values that can be regexp parsed first to avoid multiple regexp gens on the
//same value for each item examined. Much more efficient.
var regexpList = {};
for(var key in requestArgs.query){
var value = requestArgs.query[key];
if(typeof value === "string"){
regexpList[key] = dojo.data.util.filter.patternToRegExp(value, ignoreCase);
}
}
 
for(var i = 0; i < arrayOfAllItems.length; ++i){
var match = true;
var candidateItem = arrayOfAllItems[i];
for(var key in requestArgs.query){
var value = requestArgs.query[key];
if(!self._containsValue(candidateItem, key, value, regexpList[key])){
match = false;
}
}
if(match){
items.push(candidateItem);
}
}
}else{
// We want a copy to pass back in case the parent wishes to sort the array. We shouldn't allow resort
// of the internal list so that multiple callers can get lists and sort without affecting each other.
if(arrayOfAllItems.length> 0){
items = arrayOfAllItems.slice(0,arrayOfAllItems.length);
}
}
findCallback(items, requestArgs);
};
 
if(this._loadFinished){
filter(keywordArgs, this._arrayOfAllItems);
}else{
if(this.url !== ""){
//If fetches come in before the loading has finished, but while
//a load is in progress, we have to defer the fetching to be
//invoked in the callback.
if(this._loadInProgress){
this._queuedFetches.push({args: keywordArgs, filter: filter});
}else{
this._loadInProgress = true;
var getArgs = {
url: self.url,
handleAs: "text"
};
var getHandler = dojo.xhrGet(getArgs);
getHandler.addCallback(function(data){
self._processData(data);
filter(keywordArgs, self._arrayOfAllItems);
self._handleQueuedFetches();
});
getHandler.addErrback(function(error){
self._loadInProgress = false;
throw error;
});
}
}else if(this._csvData){
this._processData(this._csvData);
this._csvData = null;
filter(keywordArgs, this._arrayOfAllItems);
}else{
throw new Error("dojox.data.CsvStore: No CSV source data was provided as either URL or String data input.");
}
}
},
close: function(/*dojo.data.api.Request || keywordArgs || null */ request){
// summary:
// See dojo.data.api.Read.close()
},
// -------------------------------------------------------------------
// Private methods
_getArrayOfArraysFromCsvFileContents: function(/* string */ csvFileContents){
/* summary:
* Parses a string of CSV records into a nested array structure.
* description:
* Given a string containing CSV records, this method parses
* the string and returns a data structure containing the parsed
* content. The data structure we return is an array of length
* R, where R is the number of rows (lines) in the CSV data. The
* return array contains one sub-array for each CSV line, and each
* sub-array contains C string values, where C is the number of
* columns in the CSV data.
*/
/* example:
* For example, given this CSV string as input:
* "Title, Year, Producer \n Alien, 1979, Ridley Scott \n Blade Runner, 1982, Ridley Scott"
* this._dataArray will be set to:
* [["Alien", "1979", "Ridley Scott"],
* ["Blade Runner", "1982", "Ridley Scott"]]
* And this._attributes will be set to:
* ["Title", "Year", "Producer"]
* And this._attributeIndexes will be set to:
* { "Title":0, "Year":1, "Producer":2 }
*/
if(dojo.isString(csvFileContents)){
var lineEndingCharacters = new RegExp("\r\n|\n|\r");
var leadingWhiteSpaceCharacters = new RegExp("^\\s+",'g');
var trailingWhiteSpaceCharacters = new RegExp("\\s+$",'g');
var doubleQuotes = new RegExp('""','g');
var arrayOfOutputRecords = [];
var arrayOfInputLines = csvFileContents.split(lineEndingCharacters);
for(var i = 0; i < arrayOfInputLines.length; ++i){
var singleLine = arrayOfInputLines[i];
if(singleLine.length > 0){
var listOfFields = singleLine.split(',');
var j = 0;
while(j < listOfFields.length){
var space_field_space = listOfFields[j];
var field_space = space_field_space.replace(leadingWhiteSpaceCharacters, ''); // trim leading whitespace
var field = field_space.replace(trailingWhiteSpaceCharacters, ''); // trim trailing whitespace
var firstChar = field.charAt(0);
var lastChar = field.charAt(field.length - 1);
var secondToLastChar = field.charAt(field.length - 2);
var thirdToLastChar = field.charAt(field.length - 3);
if(field.length === 2 && field == "\"\""){
listOfFields[j] = ""; //Special case empty string field.
}else if((firstChar == '"') &&
((lastChar != '"') ||
((lastChar == '"') && (secondToLastChar == '"') && (thirdToLastChar != '"')))){
if(j+1 === listOfFields.length){
// alert("The last field in record " + i + " is corrupted:\n" + field);
return null; //null
}
var nextField = listOfFields[j+1];
listOfFields[j] = field_space + ',' + nextField;
listOfFields.splice(j+1, 1); // delete element [j+1] from the list
}else{
if((firstChar == '"') && (lastChar == '"')){
field = field.slice(1, (field.length - 1)); // trim the " characters off the ends
field = field.replace(doubleQuotes, '"'); // replace "" with "
}
listOfFields[j] = field;
j += 1;
}
}
arrayOfOutputRecords.push(listOfFields);
}
}
// The first item of the array must be the header row with attribute names.
this._attributes = arrayOfOutputRecords.shift();
for(var i=0; i<this._attributes.length; i++){
// Store the index of each attribute
this._attributeIndexes[this._attributes[i]] = i;
}
this._dataArray = arrayOfOutputRecords; //Array
}
},
_processData: function(/* String */ data){
this._getArrayOfArraysFromCsvFileContents(data);
this._arrayOfAllItems = [];
for(var i=0; i<this._dataArray.length; i++){
this._arrayOfAllItems.push(this._createItemFromIdentity(i));
}
this._loadFinished = true;
this._loadInProgress = false;
},
_createItemFromIdentity: function(/* String */ identity){
var item = {};
item[this._storeProp] = this;
item[this._idProp] = identity;
return item; //Object
},
/***************************************
dojo.data.api.Identity API
***************************************/
getIdentity: function(/* item */ item){
// summary:
// See dojo.data.api.Identity.getIdentity()
if(this.isItem(item)){
return item[this._idProp]; //String
}
return null; //null
},
 
fetchItemByIdentity: function(/* Object */ keywordArgs){
// summary:
// See dojo.data.api.Identity.fetchItemByIdentity()
 
//Hasn't loaded yet, we have to trigger the load.
 
if(!this._loadFinished){
var self = this;
if(this.url !== ""){
//If fetches come in before the loading has finished, but while
//a load is in progress, we have to defer the fetching to be
//invoked in the callback.
if(this._loadInProgress){
this._queuedFetches.push({args: keywordArgs});
}else{
this._loadInProgress = true;
var getArgs = {
url: self.url,
handleAs: "text"
};
var getHandler = dojo.xhrGet(getArgs);
getHandler.addCallback(function(data){
var scope = keywordArgs.scope?keywordArgs.scope:dojo.global;
try{
self._processData(data);
var item = self._createItemFromIdentity(keywordArgs.identity);
if(!self.isItem(item)){
item = null;
}
if(keywordArgs.onItem){
keywordArgs.onItem.call(scope, item);
}
self._handleQueuedFetches();
}catch(error){
if(keywordArgs.onError){
keywordArgs.onError.call(scope, error);
}
}
});
getHandler.addErrback(function(error){
this._loadInProgress = false;
if(keywordArgs.onError){
var scope = keywordArgs.scope?keywordArgs.scope:dojo.global;
keywordArgs.onError.call(scope, error);
}
});
}
}else if(this._csvData){
self._processData(self._csvData);
self._csvData = null;
var item = self._createItemFromIdentity(keywordArgs.identity);
if(!self.isItem(item)){
item = null;
}
if(keywordArgs.onItem){
var scope = keywordArgs.scope?keywordArgs.scope:dojo.global;
keywordArgs.onItem.call(scope, item);
}
}
}else{
//Already loaded. We can just look it up and call back.
var item = this._createItemFromIdentity(keywordArgs.identity);
if(!this.isItem(item)){
item = null;
}
if(keywordArgs.onItem){
var scope = keywordArgs.scope?keywordArgs.scope:dojo.global;
keywordArgs.onItem.call(scope, item);
}
}
},
 
getIdentityAttributes: function(/* item */ item){
// summary:
// See dojo.data.api.Identity.getIdentifierAttributes()
//Identity isn't a public attribute in the item, it's the row position index.
//So, return null.
return null;
},
 
_handleQueuedFetches: function(){
// summary:
// Internal function to execute delayed request in the store.
//Execute any deferred fetches now.
if (this._queuedFetches.length > 0) {
for(var i = 0; i < this._queuedFetches.length; i++){
var fData = this._queuedFetches[i];
var delayedFilter = fData.filter;
var delayedQuery = fData.args;
if(delayedFilter){
delayedFilter(delayedQuery, this._arrayOfAllItems);
}else{
this.fetchItemByIdentity(fData.args);
}
}
this._queuedFetches = [];
}
}
});
//Mix in the simple fetch implementation to this class.
dojo.extend(dojox.data.CsvStore,dojo.data.util.simpleFetch);
 
}
/trunk/api/js/dojo1.0/dojox/data/HtmlTableStore.js
New file
0,0 → 1,466
if(!dojo._hasResource["dojox.data.HtmlTableStore"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.data.HtmlTableStore"] = true;
dojo.provide("dojox.data.HtmlTableStore");
 
dojo.require("dojox.data.dom");
dojo.require("dojo.data.util.simpleFetch");
dojo.require("dojo.data.util.filter");
 
dojo.declare("dojox.data.HtmlTableStore", null, {
constructor: function(/*Object*/args){
// summary:
// Initializer for the HTML table store.
// description:
// The HtmlTableStore can be created in one of two ways: a) by parsing an existing
// table DOM node on the current page or b) by referencing an external url and giving
// the id of the table in that page. The remote url will be parsed as an html page.
//
// The HTML table should be of the following form:
// <table id="myTable">
// <thead>
// <tr>
// <th>Attribute1</th>
// <th>Attribute2</th>
// </tr>
// </thead>
// <tbody>
// <tr>
// <td>Value1.1</td>
// <td>Value1.2</td>
// </tr>
// <tr>
// <td>Value2.1</td>
// <td>Value2.2</td>
// </tr>
// </tbody>
// </table>
//
// args:
// An anonymous object to initialize properties. It expects the following values:
// tableId: The id of the HTML table to use.
// OR
// url: The url of the remote page to load
// tableId: The id of the table element in the remote page
if(args.url){
if(!args.tableId)
throw new Error("dojo.data.HtmlTableStore: Cannot instantiate using url without an id!");
this.url = args.url;
this.tableId = args.tableId;
}else{
if(args.tableId){
this._rootNode = dojo.byId(args.tableId);
this.tableId = this._rootNode.id;
}else{
this._rootNode = dojo.byId(this.tableId);
}
this._getHeadings();
for(var i=0; i<this._rootNode.rows.length; i++){
this._rootNode.rows[i].store = this;
}
}
},
 
url: "", // So the parser can instantiate the store via markup.
tableId: "", // So the parser can instantiate the store via markup.
 
_getHeadings: function(){
// summary:
// Function to load the attribute names from the table header so that the
// attributes (cells in a row), can have a reasonable name.
this._headings = [];
dojo.forEach(this._rootNode.tHead.rows[0].cells, dojo.hitch(this, function(th){
this._headings.push(dojox.data.dom.textContent(th));
}));
},
_getAllItems: function(){
// summary:
// Function to return all rows in the table as an array of items.
var items = [];
for(var i=1; i<this._rootNode.rows.length; i++){
items.push(this._rootNode.rows[i]);
}
return items; //array
},
_assertIsItem: function(/* item */ item){
// summary:
// This function tests whether the item passed in is indeed an item in the store.
// item:
// The item to test for being contained by the store.
if(!this.isItem(item)){
throw new Error("dojo.data.HtmlTableStore: a function was passed an item argument that was not an item");
}
},
 
_assertIsAttribute: function(/* String */ attribute){
// summary:
// This function tests whether the item passed in is indeed a valid 'attribute' like type for the store.
// attribute:
// The attribute to test for being contained by the store.
//
// returns:
// Returns the index (column) that the attribute resides in the row.
if(typeof attribute !== "string"){
throw new Error("dojo.data.HtmlTableStore: a function was passed an attribute argument that was not an attribute name string");
return;
}
return dojo.indexOf(this._headings, attribute); //int
},
 
/***************************************
dojo.data.api.Read API
***************************************/
getValue: function( /* item */ item,
/* attribute-name-string */ attribute,
/* value? */ defaultValue){
// summary:
// See dojo.data.api.Read.getValue()
var values = this.getValues(item, attribute);
return (values.length > 0)?values[0]:defaultValue; //Object || int || Boolean
},
 
getValues: function(/* item */ item,
/* attribute-name-string */ attribute){
// summary:
// See dojo.data.api.Read.getValues()
 
this._assertIsItem(item);
var index = this._assertIsAttribute(attribute);
 
if(index>-1){
return [dojox.data.dom.textContent(item.cells[index])] ;
}
return []; //Array
},
 
getAttributes: function(/* item */ item){
// summary:
// See dojo.data.api.Read.getAttributes()
this._assertIsItem(item);
var attributes = [];
for(var i=0; i<this._headings.length; i++){
if(this.hasAttribute(item, this._headings[i]))
attributes.push(this._headings[i]);
}
return attributes; //Array
},
 
hasAttribute: function( /* item */ item,
/* attribute-name-string */ attribute){
// summary:
// See dojo.data.api.Read.hasAttribute()
return this.getValues(item, attribute).length > 0;
},
 
containsValue: function(/* item */ item,
/* attribute-name-string */ attribute,
/* anything */ value){
// summary:
// See dojo.data.api.Read.containsValue()
var regexp = undefined;
if(typeof value === "string"){
regexp = dojo.data.util.filter.patternToRegExp(value, false);
}
return this._containsValue(item, attribute, value, regexp); //boolean.
},
 
_containsValue: function( /* item */ item,
/* attribute-name-string */ attribute,
/* anything */ value,
/* RegExp?*/ regexp){
// summary:
// Internal function for looking at the values contained by the item.
// description:
// Internal function for looking at the values contained by the item. This
// function allows for denoting if the comparison should be case sensitive for
// strings or not (for handling filtering cases where string case should not matter)
//
// item:
// The data item to examine for attribute values.
// attribute:
// The attribute to inspect.
// value:
// The value to match.
// regexp:
// Optional regular expression generated off value if value was of string type to handle wildcarding.
// If present and attribute values are string, then it can be used for comparison instead of 'value'
var values = this.getValues(item, attribute);
for(var i = 0; i < values.length; ++i){
var possibleValue = values[i];
if(typeof possibleValue === "string" && regexp){
return (possibleValue.match(regexp) !== null);
}else{
//Non-string matching.
if(value === possibleValue){
return true; // Boolean
}
}
}
return false; // Boolean
},
 
isItem: function(/* anything */ something){
// summary:
// See dojo.data.api.Read.isItem()
if(something && something.store && something.store === this){
return true; //boolean
}
return false; //boolean
},
 
isItemLoaded: function(/* anything */ something){
// summary:
// See dojo.data.api.Read.isItemLoaded()
return this.isItem(something);
},
 
loadItem: function(/* Object */ keywordArgs){
// summary:
// See dojo.data.api.Read.loadItem()
this._assertIsItem(keywordArgs.item);
},
_fetchItems: function(request, fetchHandler, errorHandler) {
// summary:
// Fetch items (XML elements) that match to a query
// description:
// If '_fetchUrl' is specified, it is used to load an XML document
// with a query string.
// Otherwise and if 'url' is specified, the XML document is
// loaded and list XML elements that match to a query (set of element
// names and their text attribute values that the items to contain).
// A wildcard, "*" can be used to query values to match all
// occurrences.
// If '_rootItem' is specified, it is used to fetch items.
// request:
// A request object
// fetchHandler:
// A function to call for fetched items
// errorHandler:
// A function to call on error
if(this._rootNode){
this._finishFetchItems(request, fetchHandler, errorHandler);
}else{
if(!this.url){
this._rootNode = dojo.byId(this.tableId);
this._getHeadings();
for(var i=0; i<this._rootNode.rows.length; i++){
this._rootNode.rows[i].store = this;
}
}else{
var getArgs = {
url: this.url,
handleAs: "text"
};
var self = this;
var getHandler = dojo.xhrGet(getArgs);
getHandler.addCallback(function(data){
var findNode = function(node, id){
if(node.id == id){
return node; //object
}
if(node.childNodes){
for(var i=0; i<node.childNodes.length; i++){
var returnNode = findNode(node.childNodes[i], id);
if(returnNode){
return returnNode; //object
}
}
}
return null; //null
}
 
var d = document.createElement("div");
d.innerHTML = data;
self._rootNode = findNode(d, self.tableId);
self._getHeadings.call(self);
for(var i=0; i<self._rootNode.rows.length; i++) {
self._rootNode.rows[i].store = self;
}
self._finishFetchItems(request, fetchHandler, errorHandler);
});
getHandler.addErrback(function(error){
errorHandler(error, request);
});
}
}
},
_finishFetchItems: function(request, fetchHandler, errorHandler){
// summary:
// Internal function for processing the passed in request and locating the requested items.
var items = null;
var arrayOfAllItems = this._getAllItems();
if(request.query){
var ignoreCase = request.queryOptions ? request.queryOptions.ignoreCase : false;
items = [];
 
//See if there are any string values that can be regexp parsed first to avoid multiple regexp gens on the
//same value for each item examined. Much more efficient.
var regexpList = {};
for(var key in request.query){
var value = request.query[key]+'';
if(typeof value === "string"){
regexpList[key] = dojo.data.util.filter.patternToRegExp(value, ignoreCase);
}
}
 
for(var i = 0; i < arrayOfAllItems.length; ++i){
var match = true;
var candidateItem = arrayOfAllItems[i];
for(var key in request.query){
var value = request.query[key]+'';
if (!this._containsValue(candidateItem, key, value, regexpList[key])){
match = false;
}
}
if(match){
items.push(candidateItem);
}
}
fetchHandler(items, request);
}else{
// We want a copy to pass back in case the parent wishes to sort the array. We shouldn't allow resort
// of the internal list so that multiple callers can get listsand sort without affecting each other.
if(arrayOfAllItems.length> 0){
items = arrayOfAllItems.slice(0,arrayOfAllItems.length);
}
fetchHandler(items, request);
}
},
 
getFeatures: function(){
// summary:
// See dojo.data.api.Read.getFeatures()
return {
'dojo.data.api.Read': true,
'dojo.data.api.Identity': true
};
},
close: function(/*dojo.data.api.Request || keywordArgs || null */ request){
// summary:
// See dojo.data.api.Read.close()
// nothing to do here!
},
 
getLabel: function(/* item */ item){
// summary:
// See dojo.data.api.Read.getLabel()
if(this.isItem(item))
return "Table Row #" + this.getIdentity(item);
return undefined;
},
 
getLabelAttributes: function(/* item */ item){
// summary:
// See dojo.data.api.Read.getLabelAttributes()
return null;
},
 
/***************************************
dojo.data.api.Identity API
***************************************/
 
getIdentity: function(/* item */ item){
// summary:
// See dojo.data.api.Identity.getIdentity()
this._assertIsItem(item);
//Opera doesn't support the sectionRowIndex,
//So, have to call the indexOf to locate it.
//Blah.
if(!dojo.isOpera){
return item.sectionRowIndex; // int
}else{
return (dojo.indexOf(this._rootNode.rows, item) - 1) // int
}
},
 
getIdentityAttributes: function(/* item */ item){
// summary:
// See dojo.data.api.Identity.getIdentityAttributes()
//Identity isn't taken from a public attribute.
return null;
},
 
fetchItemByIdentity: function(keywordArgs){
// summary:
// See dojo.data.api.Identity.fetchItemByIdentity()
var identity = keywordArgs.identity;
var self = this;
var item = null
 
if(!this._rootNode){
if(!this.url){
this._rootNode = dojo.byId(this.tableId);
this._getHeadings();
for(var i=0; i<this._rootNode.rows.length; i++){
this._rootNode.rows[i].store = this;
}
item = this._rootNode.rows[identity+1];
if (keywordArgs.onItem){
var scope = keywordArgs.scope?keywordArgs.scope:dojo.global;
keywordArgs.onItem.call(scope, item);
}
 
}else{
var getArgs = {
url: this.url,
handleAs: "text"
};
var self = this;
var getHandler = dojo.xhrGet(getArgs);
getHandler.addCallback(function(data){
var findNode = function(node, id){
if(node.id == id){
return node; //object
}
if(node.childNodes) {
for(var i=0; i<node.childNodes.length; i++){
var returnNode = findNode(node.childNodes[i], id);
if(returnNode){
return returnNode; //object
}
}
}
return null; //null
}
var d = document.createElement("div");
d.innerHTML = data;
self._rootNode = findNode(d, self.tableId);
self._getHeadings.call(self);
for(var i=0; i<self._rootNode.rows.length; i++){
self._rootNode.rows[i].store = self;
}
item = self._rootNode.rows[identity+1];
if (keywordArgs.onItem){
var scope = keywordArgs.scope?keywordArgs.scope:dojo.global;
keywordArgs.onItem.call(scope, item);
}
});
getHandler.addErrback(function(error){
if(keywordArgs.onError){
var scope = keywordArgs.scope?keywordArgs.scope:dojo.global;
keywordArgs.onError.call(scope, error);
 
}
});
}
}else{
if(this._rootNode.rows[identity+1]){
item = this._rootNode.rows[identity+1];
if (keywordArgs.onItem){
var scope = keywordArgs.scope?keywordArgs.scope:dojo.global;
keywordArgs.onItem.call(scope, item);
}
}
}
}
});
dojo.extend(dojox.data.HtmlTableStore,dojo.data.util.simpleFetch);
 
}