//>>built define("dojox/data/HtmlStore", ["dojo/_base/declare", "dojo/_base/array", "dojo/_base/lang", "dojo/dom", "dojo/_base/xhr", "dojo/_base/window", "dojo/data/util/simpleFetch", "dojo/data/util/filter", "dojox/xml/parser"], function(declare, array, lang, dom, xhr, winUtil, simpleFetch, filter, xmlParser) { var HtmlStore = declare("dojox.data.HtmlStore", null, { constructor: function(/*Object*/args){ // summary: // Initializer for the HTML table store. // description: // The HtmlStore can be created in one of two ways: a) by parsing an existing // table or list DOM node on the current page or b) by referencing an external url and giving // the id of the table or list in that page. The remote url will be parsed as an html page. // // The HTML table or list should be of the following form: // // | // | // | // | // | // | // | // | // | // | // | // | // | // | // | // | // | // |
Attribute1Attribute2
Value1.1Value1.2
Value2.1Value2.2
// // -or- // // | // // -or- // // |
    // |
  1. Value.1
  2. // |
  3. Value.2
  4. // |
// // args: // An anonymous object to initialize properties. It expects the following values: // dataId: The id of the HTML table to use. // OR // url: The url of the remote page to load // dataId: The id of the table element in the remote page // and the option: // trimWhitespace: Trim off any surrounding whitespace from the headers (attribute // names) and text content of the items in question. Default is false for // backwards compatibility. if(args && "urlPreventCache" in args){ this.urlPreventCache = args.urlPreventCache?true:false; } if(args && "trimWhitespace" in args){ this.trimWhitespace = args.trimWhitespace?true:false; } if(args.url){ if(!args.dataId){ throw new Error("dojo.data.HtmlStore: Cannot instantiate using url without an id!"); } this.url = args.url; this.dataId = args.dataId; }else{ if(args.dataId){ this.dataId = args.dataId; } } if(args && "fetchOnCreate" in args){ this.fetchOnCreate = args.fetchOnCreate?true:false; } if(this.fetchOnCreate && this.dataId){ this.fetch(); } }, // url: [public] string // The URL from which to load an HTML document for data loading url: "", // dataId: [public] string // The id in the document for an element from which to get the data. dataId: "", // trimWhitepace: [public] boolean // Boolean flag to denote if the store should trim whitepace around // header and data content of a node. This matters if reformatters // alter the white spacing around the tags. The default is false for // backwards compat. trimWhitespace: false, // urlPreventCache: [public] boolean // Flag to denote if peventCache should be used on xhrGet calls. urlPreventCache: false, // fetchOnCreate: [public] boolean // Flag to denote if it should try to load from a data id (nested in the page) // The moment the store is created, instead of waiting for first // fetch call. fetchOnCreate: false, _indexItems: function(){ // summary: // Function to index items found under the id. // tags: // private this._getHeadings(); if(this._rootNode.rows){//tables if(this._rootNode.tBodies && this._rootNode.tBodies.length > 0){ this._rootNode = this._rootNode.tBodies[0]; } var i; for(i=0; i 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){ var text; if(item.cells){ text = xmlParser.textContent(item.cells[index]); }else{//return Value for lists text = xmlParser.textContent(item); } return [this.trimWhitespace?lang.trim(text):text]; } return []; //Array }, getAttributes: function(/* item */ item){ // summary: // See dojo.data.api.Read.getAttributes() this._assertIsItem(item); var attributes = []; for(var i=0; i 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 = 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() return something && dom.isDescendant(something, this._rootNode); }, 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 = dom.byId(this.dataId); this._indexItems(); this._finishFetchItems(request, fetchHandler, errorHandler); }else{ var getArgs = { url: this.url, handleAs: "text", preventCache: this.urlPreventCache }; var self = this; var getHandler = xhr.get(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 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)){ if(item.cells){ return "Item #" + this.getIdentity(item); }else{ return this.getValue(item,"name"); } } return undefined; }, getLabelAttributes: function(/* item */ item){ // summary: // See dojo.data.api.Read.getLabelAttributes() if(item.cells){ return null; }else{ return ["name"]; } }, /*************************************** dojo.data.api.Identity API ***************************************/ getIdentity: function(/* item */ item){ // summary: // See dojo.data.api.Identity.getIdentity() this._assertIsItem(item); if(this.hasAttribute(item, "name")){ return this.getValue(item,"name"); }else{ return item._ident; } }, 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; var scope = null; if(!this._rootNode){ if(!this.url){ this._rootNode = dom.byId(this.dataId); this._indexItems(); if(self._rootNode.rows){ //Table item = this._rootNode.rows[identity + 1]; }else{ //Lists for(var i = 0; i < self._rootNode.childNodes.length; i++){ if(self._rootNode.childNodes[i].nodeType === 1 && identity === xmlParser.textContent(self._rootNode.childNodes[i])){ item = self._rootNode.childNodes[i]; } } } if(keywordArgs.onItem){ scope = keywordArgs.scope?keywordArgs.scope:winUtil.global; keywordArgs.onItem.call(scope, item); } }else{ var getArgs = { url: this.url, handleAs: "text" }; var getHandler = xhr.get(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