dojox/widget/Iterator.js

  • Provides:

    • dojox.widget.Iterator
  • Requires:

    • dijit.Declaration in common in project dijit
  • dojox.widget.Iterator

    • type
      Function
    • chains:
      • dijit.Declaration: (prototype)
      • dijit.Declaration: (call)
    • summary
  • dojox.widget.Iterator.constructor

    • summary
  • dojox.widget.Iterator.start

    • summary
  • dojox.widget.Iterator.fetchMax

    • summary
  • dojox.widget.Iterator.query

    • type
      Object
    • summary
  • dojox.widget.Iterator.attrs

    • summary
  • dojox.widget.Iterator.defaultValue

    • summary
  • dojox.widget.Iterator.widgetCtor

    • summary
  • dojox.widget.Iterator.dataValues

    • summary
  • dojox.widget.Iterator.data

    • summary
  • dojox.widget.Iterator.store

    • summary
  • dojox.widget.Iterator._srcIndex

    • summary
  • dojox.widget.Iterator._srcParent

    • summary
  • dojox.widget.Iterator._setSrcIndex

    • type
      Function
    • parameters:
      • s: (typeof )
    • source: [view]
        this._srcIndex = 0;
        this._srcParent = s.parentNode;
        var ts = s;
        while(ts.previousSibling){
         this._srcIndex++;
         ts = ts.previousSibling;
        };
    • summary
  • dojox.widget.Iterator.postscript

    • type
      Function
    • parameters:
      • p: (typeof )
      • s: (typeof )
    • source: [view]
      dojo.provide("dojox.widget.Iterator");
      dojo.require("dijit.Declaration");


      dojo.experimental("dojox.widget.Iterator"); // level: prototype, designed for dijit.chat.demo


      /*
       example:
        from markup:
       |  |  jsId="cstore" url="countries.json">
       |
       | 

       |  
       |   query="{ name: 'A*'}">
       |   ${name} is a ${type}
       |  

       | 



       example:
        programmatic:
       | var store = new dojo.data.ItemFileReadStore({ url: "countries.json" });
       |
       | var iter = new dojox.widget.Iterator({
       |  store: store,
       |  template: ""
       | });
       |


       example:
        programmatic from an array of objects:
       | var dataArr = [
       |  { name: "foo", valueAttr: "bar" },
       |  { name: "thinger", valueAttr: "blah" }
       | ];
       |
       | var iter = new dojox.widget.Iterator({
       |  data: dataArr,
       |  template: ""
       | });


       example:
        programmatic from an array of strings:
       | var dataArr = [
       |  { name: "foo", valueAttr: "bar" },
       |  { name: "thinger", valueAttr: "blah" }
       | ];
       |
       | var iter = new dojox.widget.Iterator({
       |  data: dataArr,
       |  template: ""
       | });


      */




      dojo.declare("dojox.widget.Iterator",
       [ dijit.Declaration ],
       {


       constructor: (function(){
        var ctr = 0;
        return function(){
         this.attrs = [];
         this.children = [];
         this.widgetClass = "dojox.widget.Iterator._classes._"+(ctr++);
        }
       })(),


       start: 0,
       fetchMax: 1000,
       query: { name: "*" },
       attrs: [],
       defaultValue: "",
       widgetCtor: null,
       dataValues: [], // an array of strings
       data: null, // should be a reference to an Array
       store: null,
       _srcIndex: 0,
       _srcParent: null,


       _setSrcIndex: function(s){
        this._srcIndex = 0;
        this._srcParent = s.parentNode;
        var ts = s;
        while(ts.previousSibling){
         this._srcIndex++;
         ts = ts.previousSibling;
        };
       },


       postscript: function(p, s){
        // figure out the position of the source node in it's parent
        this._setSrcIndex(s);
        // this._srcIndex = dojo.query(">", this._srcParent).indexOf(s);


        this.inherited("postscript", arguments);
        var wc = this.widgetCtor = dojo.getObject(this.widgetClass);


        this.attrs = dojo.map(
         wc.prototype.templateString.match(/\$\{([^\s\:\}]+)(?:\:([^\s\:\}]+))?\}/g),
         function(s){ return s.slice(2, -1); }
        );
        dojo.forEach(
         this.attrs,
         function(m){ wc.prototype[m] = ""; }
        );
        this.update();
    • summary
  • dojox.widget.Iterator.clear

    • type
      Function
    • source: [view]
        if(this.children.length){
         this._setSrcIndex(this.children[0].domNode);
        }
        dojo.forEach(this.children, "item.destroy();");
        this.children = [];
    • summary
  • dojox.widget.Iterator.update

    • type
      Function
    • source: [view]
        if(this.store){
         // we're executing a query
         this.fetch();
        }else{
         // we came from an array of objects. Easier!
         this.onDataAvailable(this.data||this.dataValues);
        }
    • summary
  • dojox.widget.Iterator._addItem

    • type
      Function
    • parameters:
      • config: (typeof Object)
      • idx: (typeof )
    • source: [view]
        if(dojo.isString(config)){
         config = { value: config };
        }
        var widget = new this.widgetCtor(config);
        this.children.push(widget);
        dojo.place(widget.domNode, this._srcParent, this._srcIndex+idx);
    • summary
  • dojox.widget.Iterator.getAttrValuesObj

    • type
      Function
    • parameters:
      • item: (typeof )
    • source: [view]
        var obj = {};
        if(dojo.isString(item)){
         dojo.forEach(this.attrs, function(attr){
          obj[attr] = (attr == "value") ? item : this.defaultValue;
         }, this);
        }else{
         dojo.forEach(this.attrs, function(attr){
          if(this.store){
           obj[attr] = this.store.getValue(item, attr)||this.defaultValue;
          }else{
           obj[attr] = item[attr]||this.defaultValue;
          }
         }, this);
        }
        return obj;
    • summary
  • dojox.widget.Iterator.onDataAvailable

    • type
      Function
    • parameters:
      • data: (typeof )
    • source: [view]
        this.clear();
        // console.debug(data);
        dojo.forEach(data, function(item, idx){
         this._addItem(this.getAttrValuesObj(item), idx);
        }, this);
    • summary
  • dojox.widget.Iterator.fetch

    • type
      Function
    • parameters:
      • query: (typeof )
      • start: (typeof )
      • end: (typeof )
    • source: [view]
        this.store.fetch({
         query: query||this.query,
         start: start||this.start,
         count: end||this.fetchMax,
         onComplete: dojo.hitch(this,"onDataAvailable")
        });
    • summary
  • dojox.widget.Iterator.query.name

    • summary
  • dojox.widget.Iterator.children

    • summary
  • dojox.widget.Iterator._classes

    • type
      Object
    • summary
  • dojox.widget

    • type
      Object
    • summary
  • dojox

    • type
      Object
    • summary