dojox/data/AppStore.js

  • Provides:

    • dojox.data.AppStore
  • dojox.data.AppStore

    • type
      Function
    • parameters:
      • args: (typeof Object)
        An anonymous object to initialize properties.  It expects the following values:
    • source: [view]
        if(args && args.url){
         this.url = args.url;
        }
        if(args && args.urlPreventCache){
         this.urlPreventCache = args.urlPreventCache;
        }
        if(!this.url){
         throw new Error("A URL is required to instantiate an APP Store object");
        }
    • summary
      The APP data store.
    • description
      The APP Store is instantiated either in markup or programmatically by supplying a
      url of the Collection to be used.
    • mixins:
      • dojo.data.util.simpleFetch: (prototype)
  • dojox.data.AppStore.url

    • tags: public
    • type
      The
    • summary
      url of the Collection to load.
  • dojox.data.AppStore.urlPreventCache

    • tags: public
    • type
      Whether
    • summary
      or not to append on cache prevention params (as defined by dojo.xhr*)
  • dojox.data.AppStore.xmethod

    • tags: public
    • type
      boolean
    • summary
      Whether to use X-Method-Override for PUT/DELETE.
  • dojox.data.AppStore._atomIO

    • summary
  • dojox.data.AppStore._feed

    • summary
  • dojox.data.AppStore._requests

    • summary
  • dojox.data.AppStore._processing

    • summary
  • dojox.data.AppStore._updates

    • summary
  • dojox.data.AppStore._adds

    • summary
  • dojox.data.AppStore._deletes

    • summary
  • dojox.data.AppStore._setFeed

    • type
      Function
    • parameters:
      • feed: (typeof dojox.atom.io.model.Feed)
        object
        The Feed to use for this data store.
      • data: (typeof unused)
        Signature for this function is defined by AtomIO.getFeed, since this is a callback.
    • source: [view]
        this._feed = feed;
        var i;
        for(i=0; i   this._feed.entries[i].store = this;
        }
        if(this._requests){
         for(i=0; i    var request = this._requests[i];
          if(request.request && request.fh && request.eh){
           this._finishFetchItems(request.request, request.fh, request.eh);
          }else if(request.clear){
           this._feed = null;
          }else if(request.add){
           this._feed.addEntry(request.add);
          }else if(request.remove){
           this._feed.removeEntry(request.remove);
          }
         }
        }
        this._requests = null;
    • summary
      Sets the internal feed using a dojox.atom.io.model.Feed object.
    • description
      Sets the internal feed using a dojox.atom.io.model.Feed object.  Also adds
      a property to the entries to track that they belong to this store. It
      also parses stored requests (since we were waiting on a callback) and
      executes those as well.
  • dojox.data.AppStore._getAllItems

    • type
      Function
    • source: [view]
        var items = [];
        for(var i=0; i   items.push(this._feed.entries[i]);
        }
        return items; //array
    • summary
      Function to return all entries in the Feed as an array of items.
    • description
      Function to return all entries in the Feed as an array of items.
    • return_summary
      Array of all entries in the feed.
    • returns
      array
  • dojox.data.AppStore._assertIsItem

    • type
      Function
    • parameters:
      • item: (typeof item)
        The item to test for being contained by the store.
    • source: [view]
        if(!this.isItem(item)){
         throw new Error("This error message is provided when a function is called in the following form: "
          + "getAttribute(argument, attributeName). The argument variable represents the member "
          + "or owner of the object. The error is created when an item that does not belong "
          + "to this store is specified as an argument.");
        }
    • summary
      This function tests whether the item is an item.
    • description
      This function tests whether the item passed in is indeed an item
      in the store.
  • dojox.data.AppStore._assertIsAttribute

    • type
      Function
    • parameters:
      • attribute: (typeof String)
        The attribute to test for being contained by the store.
    • source: [view]
        if(typeof attribute !== "string"){
         throw new Error("The attribute argument must be a string. The error is created "
         + "when a different type of variable is specified such as an array or object.");
        }


        for(var key in dojox.atom.io.model._actions){
         if(key == attribute){
          return true;
         }
        }
        return false;
    • summary
      This function tests whether the item is an attribute.
    • description
      This function tests whether the item passed in is indeed a valid
      'attribute' like type for the store.
    • return_summary
      Returns a boolean indicating whether this is a valid attribute.
  • dojox.data.AppStore._addUpdate

    • type
      Function
    • parameters:
      • update: (typeof Object)
        dojox.atom.io.model.Entry object
        The updated Entry we've changed.
    • source: [view]
        if(!this._updates){
         this._updates = [update];
        }else{
         this._updates.push(update);
        }
    • summary
      Internal function to add an updated entry to our updates array
    • description
      Internal function to add an updated entry to our updates array
  • dojox.data.AppStore.getValue

    • type
      Function
    • parameters:
      • item: (typeof item)
      • attribute: (typeof attribute-name-string)
      • defaultValue: (typeof value)
    • source: [view]
        var values = this.getValues(item, attribute);
        return (values.length > 0)?values[0]:defaultValue; //Object || int || Boolean
    • summary
      See dojo.data.api.Read.getValue()
    • returns
      Object || int || Boolean
  • dojox.data.AppStore.getValues

    • type
      Function
    • parameters:
      • item: (typeof item)
      • attribute: (typeof attribute-name-string)
    • source: [view]
        this._assertIsItem(item);
        var flag = this._assertIsAttribute(attribute);


        if(flag){
         if((attribute === "author" || attribute === "contributor" || attribute === "link") && item[attribute+"s"]){
          return item[attribute+"s"];
         }
         if(attribute === "category" && item.categories){
          return item.categories;
         }
         if(item[attribute]){
          item = item[attribute];
          if(item.declaredClass == "dojox.atom.io.model.Content"){
           return [item.value];
          }
          return [item] ;
         }
        }
        return []; //Array
    • summary
      See dojo.data.api.Read.getValues()
    • returns
      Array
  • dojox.data.AppStore.getAttributes

    • type
      Function
    • parameters:
      • item: (typeof item)
    • source: [view]
        this._assertIsItem(item);
        var attributes = [];
        for(var key in dojox.atom.io.model._actions){
         if(this.hasAttribute(item, key)){
          attributes.push(key);
         }
        }
        return attributes; //Array
    • summary
      See dojo.data.api.Read.getAttributes()
    • returns
      Array
  • dojox.data.AppStore.hasAttribute

    • type
      Function
    • parameters:
      • item: (typeof item)
      • attribute: (typeof attribute-name-string)
    • source: [view]
        return this.getValues(item, attribute).length > 0;
    • summary
      See dojo.data.api.Read.hasAttribute()
  • dojox.data.AppStore.containsValue

    • type
      Function
    • parameters:
      • item: (typeof item)
      • attribute: (typeof attribute-name-string)
      • value: (typeof anything)
    • source: [view]
        var regexp = undefined;
        if(typeof value === "string"){
         regexp = dojo.data.util.filter.patternToRegExp(value, false);
        }
        return this._containsValue(item, attribute, value, regexp); //boolean.
    • summary
      See dojo.data.api.Read.containsValue()
    • returns
      boolean.
  • dojox.data.AppStore._containsValue

    • type
      Function
    • parameters:
      • item: (typeof item)
        The data item to examine for attribute values.
      • attribute: (typeof attribute-name-string)
        The attribute to inspect.
      • value: (typeof anything)
        The value to match.
      • regexp: (typeof 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'
      • trim: (typeof Boolean)
    • source: [view]
        var values = this.getValues(item, attribute);
        for(var i = 0; i < values.length; ++i){
         var possibleValue = values[i];
         if(typeof possibleValue === "string" && regexp){
          if(trim){
           possibleValue = possibleValue.replace(new RegExp(/^\s+/),""); // START
           possibleValue = possibleValue.replace(new RegExp(/\s+$/),""); // END
          }
          possibleValue = possibleValue.replace(/\r|\n|\r\n/g, "");
          return (possibleValue.match(regexp) !== null);
         }else{
          //Non-string matching.
          if(value === possibleValue){
           return true; // Boolean
          }
         }
        }
        return false; // Boolean
    • 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)
    • returns
      Boolean
  • dojox.data.AppStore.isItem

    • type
      Function
    • parameters:
      • something: (typeof anything)
    • source: [view]
        return something && something.store && something.store === this; //boolean
    • summary
      See dojo.data.api.Read.isItem()
    • returns
      boolean
  • dojox.data.AppStore.isItemLoaded

    • type
      Function
    • parameters:
      • something: (typeof anything)
    • source: [view]
        return this.isItem(something);
    • summary
      See dojo.data.api.Read.isItemLoaded()
  • dojox.data.AppStore.loadItem

    • type
      Function
    • parameters:
      • keywordArgs: (typeof Object)
    • source: [view]
        this._assertIsItem(keywordArgs.item);
    • summary
      See dojo.data.api.Read.loadItem()
  • dojox.data.AppStore._fetchItems

    • type
      Function
    • parameters:
      • request: (typeof A)
        request object
      • fetchHandler: (typeof A)
        function to call for fetched items
      • errorHandler: (typeof A)
        function to call on error
    • source: [view]
        if(this._feed){
         this._finishFetchItems(request, fetchHandler, errorHandler);
        }else{
         var flag = false;
         if(!this._requests){
          this._requests = [];
          flag = true;
         }
         this._requests.push({request: request, fh: fetchHandler, eh: errorHandler});
         if(flag){
          this._atomIO = new dojox.atom.io.Connection(false, this.urlPreventCache);
          this._atomIO.getFeed(this.url,this._setFeed, null, this);
         }
        }
    • summary
      Fetch items (Atom entries) that match to a query
    • description
      Fetch items (Atom entries) that match to a query
  • dojox.data.AppStore._finishFetchItems

    • type
      Function
    • parameters:
      • request: (typeof A)
        request object
      • fetchHandler: (typeof A)
        function to call for fetched items
      • errorHandler: (typeof A)
        function to call on error
    • source: [view]
        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 = {};
         var key;
         var value;
         for(key in request.query){
          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(key in request.query){
           value = request.query[key]+'';
           if(!this._containsValue(candidateItem, key, value, regexpList[key], request.trim)){
            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 listsand sort without affecting each other.
         if(arrayOfAllItems.length> 0){
          items = arrayOfAllItems.slice(0,arrayOfAllItems.length);
         }
        }
        try{
         fetchHandler(items, request);
        }catch(e){
         errorHandler(e, request);
        }
    • summary
      Internal function for finishing a fetch request.
    • description
      Internal function for finishing a fetch request.  Needed since the feed
      might not have been loaded, so we finish the fetch in a callback.
  • dojox.data.AppStore.getFeatures

    • type
      Function
    • source: [view]
        return {
         'dojo.data.api.Read': true,
         'dojo.data.api.Write': true,
         'dojo.data.api.Identity': true
        };
    • summary
      See dojo.data.api.Read.getFeatures()
  • dojox.data.AppStore.close

    • type
      Function
    • parameters:
      • request: (typeof dojo.data.api.Request || keywordArgs || null)
    • source: [view]
        this._feed = null;
    • summary
      See dojo.data.api.Read.close()
      nothing to do here!
  • dojox.data.AppStore.getLabel

    • type
      Function
    • parameters:
      • item: (typeof item)
    • source: [view]
        if(this.isItem(item)){
         return this.getValue(item, "title", "No Title");
        }
        return undefined;
    • summary
      See dojo.data.api.Read.getLabel()
  • dojox.data.AppStore.getLabelAttributes

    • type
      Function
    • parameters:
      • item: (typeof item)
    • source: [view]
        return ["title"];
    • summary
      See dojo.data.api.Read.getLabelAttributes()
  • dojox.data.AppStore.getIdentity

    • type
      Function
    • parameters:
      • item: (typeof item)
    • source: [view]
        this._assertIsItem(item);
        return this.getValue(item, "id");
    • summary
      See dojo.data.api.Identity.getIdentity()
  • dojox.data.AppStore.getIdentityAttributes

    • type
      Function
    • parameters:
      • item: (typeof item)
    • source: [view]
         return ["id"];
    • summary
      See dojo.data.api.Identity.getIdentityAttributes()
  • dojox.data.AppStore.fetchItemByIdentity

    • type
      Function
    • parameters:
      • keywordArgs: (typeof )
    • source: [view]
        this._fetchItems({query:{id:keywordArgs.identity}, onItem: keywordArgs.onItem, scope: keywordArgs.scope},
         function(items, request){
          var scope = request.scope;
          if(!scope){
           scope = dojo.global;
          }
          if(items.length < 1){
           request.onItem.call(scope, null);
          }else{
           request.onItem.call(scope, items[0]);
          }
        }, keywordArgs.onError);
    • summary
      See dojo.data.api.Identity.fetchItemByIdentity()
    • chains:
      • request.onItem: (call)
  • dojox.data.AppStore.newItem

    • type
      Function
    • parameters:
      • keywordArgs: (typeof Object)
    • source: [view]
        var entry = new dojox.atom.io.model.Entry();
        var value = null;
        var temp = null;
        var i;
        for(var key in keywordArgs){
         if(this._assertIsAttribute(key)){
          value = keywordArgs[key];
          switch(key){
           case "link":
            for(i in value){
             temp = value[i];
             entry.addLink(temp.href,temp.rel,temp.hrefLang,temp.title,temp.type);
            }
            break;
           case "author":
            for(i in value){
             temp = value[i];
             entry.addAuthor(temp.name, temp.email, temp.uri);
            }
            break;
           case "contributor":
            for(i in value){
             temp = value[i];
             entry.addContributor(temp.name, temp.email, temp.uri);
            }
            break;
           case "category":
            for(i in value){
             temp = value[i];
             entry.addCategory(temp.scheme, temp.term, temp.label);
            }
            break;
           case "icon":
           case "id":
           case "logo":
           case "xmlBase":
           case "rights":
            entry[key] = value;
            break;
           case "updated":
           case "published":
           case "issued":
           case "modified":
            entry[key] = dojox.atom.io.model.util.createDate(value);
            break;
           case "content":
           case "summary":
           case "title":
           case "subtitle":
            entry[key] = new dojox.atom.io.model.Content(key);
            entry[key].value = value;
            break;
           default:
            entry[key] = value;
            break;
          }
         }
        }
        entry.store = this;
        entry.isDirty = true;


        if(!this._adds){
         this._adds = [entry];
        }else{
         this._adds.push(entry);
        }


        if(this._feed){
         this._feed.addEntry(entry);
        }else{
         if(this._requests){
          this._requests.push({add:entry});
         }else{
          this._requests = [{add:entry}];
          this._atomIO = new dojox.atom.io.Connection(false, this.urlPreventCache);
          this._atomIO.getFeed(this.url,dojo.hitch(this,this._setFeed));
         }
        }
        return true;
    • summary
      See dojo.data.api.Write.newItem()
  • dojox.data.AppStore.deleteItem

    • type
      Function
    • parameters:
      • item: (typeof item)
    • source: [view]
        this._assertIsItem(item);


        if(!this._deletes){
         this._deletes = [item];
        }else{
         this._deletes.push(item);
        }


        if(this._feed){
         this._feed.removeEntry(item);
        }else{
         if(this._requests){
          this._requests.push({remove:item});
         }else{
          this._requests = [{remove:item}];
          this._atomIO = new dojox.atom.io.Connection(false, this.urlPreventCache);
          this._atomIO.getFeed(this.url,dojo.hitch(this,this._setFeed));
         }
        }
        item = null;
        return true;
    • summary
      See dojo.data.api.Write.deleteItem()
  • dojox.data.AppStore.setValue

    • type
      Function
    • parameters:
      • item: (typeof item)
      • attribute: (typeof string)
      • value: (typeof almost anything)
    • source: [view]
        this._assertIsItem(item);

        
        var update = {item: item};
        if(this._assertIsAttribute(attribute)){
         switch(attribute){
          case "link":
           update.links = item.links;
           this._addUpdate(update);
           item.links = null;
           item.addLink(value.href,value.rel,value.hrefLang,value.title,value.type);
           item.isDirty = true;
           return true;
          case "author":
           update.authors = item.authors;
           this._addUpdate(update);
           item.authors = null;
           item.addAuthor(value.name, value.email, value.uri);
           item.isDirty = true;
           return true;
          case "contributor":
           update.contributors = item.contributors;
           this._addUpdate(update);
           item.contributors = null;
           item.addContributor(value.name, value.email, value.uri);
           item.isDirty = true;
           return true;
          case "category":
           update.categories = item.categories;
           this._addUpdate(update);
           item.categories = null;
           item.addCategory(value.scheme, value.term, value.label);
           item.isDirty = true;
           return true;
          case "icon":
          case "id":
          case "logo":
          case "xmlBase":
          case "rights":
           update[attribute] = item[attribute];
           this._addUpdate(update);
           item[attribute] = value;
           item.isDirty = true;
           return true;
          case "updated":
          case "published":
          case "issued":
          case "modified":
           update[attribute] = item[attribute];
           this._addUpdate(update);
           item[attribute] = dojox.atom.io.model.util.createDate(value);
           item.isDirty = true;
           return true;
          case "content":
          case "summary":
          case "title":
          case "subtitle":
           update[attribute] = item[attribute];
           this._addUpdate(update);
           item[attribute] = new dojox.atom.io.model.Content(attribute);
           item[attribute].value = value;
           item.isDirty = true;
           return true;
          default:
           update[attribute] = item[attribute];
           this._addUpdate(update);
           item[attribute] = value;
           item.isDirty = true;
           return true;
         }
        }
        return false;
    • summary
      See dojo.data.api.Write.setValue()
  • dojox.data.AppStore.setValues

    • type
      Function
    • parameters:
      • item: (typeof item)
      • attribute: (typeof string)
      • values: (typeof array)
    • source: [view]
        if(values.length === 0){
         return this.unsetAttribute(item, attribute);
        }
        this._assertIsItem(item);

        
        var update = {item: item};
        var value;
        var i;
        if(this._assertIsAttribute(attribute)){
         switch(attribute){
          case "link":
           update.links = item.links;
           item.links = null;
           for(i in values){
            value = values[i];
            item.addLink(value.href,value.rel,value.hrefLang,value.title,value.type);
           }
           item.isDirty = true;
           return true;
          case "author":
           update.authors = item.authors;
           item.authors = null;
           for(i in values){
            value = values[i];
            item.addAuthor(value.name, value.email, value.uri);
           }
           item.isDirty = true;
           return true;
          case "contributor":
           update.contributors = item.contributors;
           item.contributors = null;
           for(i in values){
            value = values[i];
            item.addContributor(value.name, value.email, value.uri);
           }
           item.isDirty = true;
           return true;
          case "categories":
           update.categories = item.categories;
           item.categories = null;
           for(i in values){
            value = values[i];
            item.addCategory(value.scheme, value.term, value.label);
           }
           item.isDirty = true;
           return true;
          case "icon":
          case "id":
          case "logo":
          case "xmlBase":
          case "rights":
           update[attribute] = item[attribute];
           item[attribute] = values[0];
           item.isDirty = true;
           return true;
          case "updated":
          case "published":
          case "issued":
          case "modified":
           update[attribute] = item[attribute];
           item[attribute] = dojox.atom.io.model.util.createDate(values[0]);
           item.isDirty = true;
           return true;
          case "content":
          case "summary":
          case "title":
          case "subtitle":
           update[attribute] = item[attribute];
           item[attribute] = new dojox.atom.io.model.Content(attribute);
           item[attribute].values[0] = values[0];
           item.isDirty = true;
           return true;
          default:
           update[attribute] = item[attribute];
           item[attribute] = values[0];
           item.isDirty = true;
           return true;
         }
        }
        this._addUpdate(update);
        return false;
    • summary
      See dojo.data.api.Write.setValues()
  • dojox.data.AppStore.unsetAttribute

    • type
      Function
    • parameters:
      • item: (typeof item)
      • attribute: (typeof string)
    • source: [view]
        this._assertIsItem(item);
        if(this._assertIsAttribute(attribute)){
         if(item[attribute] !== null){
          var update = {item: item};
          switch(attribute){
           case "author":
           case "contributor":
           case "link":
            update[attribute+"s"] = item[attribute+"s"];
            break;
           case "category":
            update.categories = item.categories;
            break;
           default:
            update[attribute] = item[attribute];
            break;
          }
          item.isDirty = true;
          item[attribute] = null;
          this._addUpdate(update);
          return true;
         }
        }
        return false; // boolean
    • summary
      See dojo.data.api.Write.unsetAttribute()
    • returns
      boolean
  • dojox.data.AppStore.save

    • type
      Function
    • parameters:
      • keywordArgs: (typeof object)
        {
        onComplete: function
        onError: function
        scope: object
        }
    • source: [view]
        var i;
        for(i in this._adds){
         this._atomIO.addEntry(this._adds[i], null, function(){}, keywordArgs.onError, false, keywordArgs.scope);
        }

         
        this._adds = null;

        
        for(i in this._updates){
         this._atomIO.updateEntry(this._updates[i].item, function(){}, keywordArgs.onError, false, this.xmethod, keywordArgs.scope);
        }

         
        this._updates = null;

        
        for(i in this._deletes){
         this._atomIO.removeEntry(this._deletes[i], function(){}, keywordArgs.onError, this.xmethod, keywordArgs.scope);
        }

         
        this._deletes = null;

        
        this._atomIO.getFeed(this.url,dojo.hitch(this,this._setFeed));

        
        if(keywordArgs.onComplete){
         var scope = keywordArgs.scope || dojo.global;
         keywordArgs.onComplete.call(scope);
        }
    • summary
      See dojo.data.api.Write.save()
    • chains:
      • keywordArgs.onComplete: (call)
  • dojox.data.AppStore.revert

    • type
      Function
    • source: [view]
        var i;
        for(i in this._adds){
         this._feed.removeEntry(this._adds[i]);
        }

         
        this._adds = null;

        
        var update, item, key;
        for(i in this._updates){
         update = this._updates[i];
         item = update.item;
         for(key in update){
          if(key !== "item"){
           item[key] = update[key];
          }
         }
        }
        this._updates = null;

        
        for(i in this._deletes){
         this._feed.addEntry(this._deletes[i]);
        }
        this._deletes = null;
        return true;
    • summary
      See dojo.data.api.Write.revert()
  • dojox.data.AppStore.isDirty

    • type
      Function
    • parameters:
      • item: (typeof item)
    • source: [view]
        if(item){
         this._assertIsItem(item);
         return item.isDirty?true:false; //boolean
        }
        return (this._adds !== null || this._updates !== null); //boolean
    • summary
      See dojo.data.api.Write.isDirty()
    • returns
      boolean
  • dojox.data

    • type
      Object
    • summary
  • dojox

    • type
      Object
    • summary