dojox/data/FileStore.js

  • Provides:

    • dojox.data.FileStore
  • dojox.data.FileStore

    • type
      Function
    • parameters:
      • args: (typeof Object)
    • source: [view]
        if(args && args.label){
         this.label = args.label;
        }
        if(args && args.url){
         this.url = args.url;
        }
        if(args && args.options){
         if(dojo.isArray(args.options)){
          this.options = args.options;
         }else{
          if(dojo.isString(args.options)){
           this.options = args.options.split(",");
          }
         }
        }
        if(args && args.pathAsQueryParam){
         this.pathAsQueryParam = true;
        }
        if(args && "urlPreventCache" in args){
         this.urlPreventCache = args.urlPreventCache?true:false;
        }
    • summary
      A simple store that provides a datastore interface to a filesystem.
    • description
      A simple store that provides a datastore interface to a filesystem.  It takes a few parameters
      for initialization:
    • example
      options="expand,dirsOnly,showHiddenFiles"
  • dojox.data.FileStore.url

    • tags: public
    • type
      The
    • summary
      URL of the service which provides the file store serverside implementation.
  • dojox.data.FileStore._storeRef

    • tags: private
    • type
      string
    • summary
      Internal variable used to denote an item came from this store instance.
  • dojox.data.FileStore.label

    • tags: public
    • type
      The
    • summary
      attribute of the file to use as the huma-readable text.  Default is 'name'.
      The purpose of this store is to represent a file as a datastore item.  The
      datastore item by default has the following attributes that can be examined on it.
      directory:	Boolean indicating if the file item represents a directory.
      name:	The filename with no path informatiom.
      path:	The file complete file path including name, relative to the location the
      file service scans from
      size:	The size of the file, in bytes.
      parentDir:	The parent directory path.
      children:	Any child files contained by a directory file item.
      
      Note that the store's server call pattern is RESTlike.
      
      The store also supports the passing of configurable options to the back end service, such as
      expanding all child files (no lazy load), displaying hidden files, displaying only directories, and so on.
      These are defined through a comma-separated list in declarative, or through setting the options array in programmatic.
  • dojox.data.FileStore._identifier

    • tags: private
    • type
      string
    • summary
      Default attribute to use to represent the item's identifier.
      Path should always be unique in the store instance.
  • dojox.data.FileStore._attributes

    • tags: private
    • type
      string
    • summary
      Internal variable of attributes all file items should have.
  • dojox.data.FileStore.pathSeparator

    • tags: public
    • type
      string
    • summary
      The path separator to use when chaining requests for children
      Can be overriden by the server on initial load
  • dojox.data.FileStore.options

    • tags: public
    • type
      array
    • summary
      Array of options to always send when doing requests.
      Back end service controls this, like 'dirsOnly', 'showHiddenFiles', 'expandChildren', etc.
  • dojox.data.FileStore.failOk

    • tags: public
    • type
      boolean
    • summary
      Flag to pass on to xhr functions to check if we are OK to fail the call silently
  • dojox.data.FileStore.urlPreventCache

    • tags: public
    • type
      string
    • summary
      Flag to dennote if preventCache should be passed to xhrGet.
  • dojox.data.FileStore._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("dojox.data.FileStore: a function was passed an item argument that was not an item");
        }
    • summary
      This function tests whether the item passed in is indeed an item in the store.
  • dojox.data.FileStore._assertIsAttribute

    • type
      Function
    • parameters:
      • attribute: (typeof attribute-name-string)
        The attribute to test for being contained by the store.
    • source: [view]
        if(typeof attribute !== "string"){
         throw new Error("dojox.data.FileStore: a function was passed an attribute argument that was not an attribute name string");
        }
    • summary
      This function tests whether the item passed in is indeed a valid 'attribute' like type for the store.
  • dojox.data.FileStore.pathAsQueryParam

    • summary
  • dojox.data.FileStore.getFeatures

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

    • type
      Function
    • parameters:
      • item: (typeof )
      • attribute: (typeof )
      • defaultValue: (typeof )
    • source: [view]
        var values = this.getValues(item, attribute);
        if(values && values.length > 0){
         return values[0];
        }
        return defaultValue;
    • summary
      See dojo.data.api.Read.getValue()
  • dojox.data.FileStore.getAttributes

    • type
      Function
    • parameters:
      • item: (typeof )
    • source: [view]
        return this._attributes;
    • summary
      See dojo.data.api.Read.getAttributes()
  • dojox.data.FileStore.hasAttribute

    • type
      Function
    • parameters:
      • item: (typeof )
      • attribute: (typeof )
    • source: [view]
        this._assertIsItem(item);
        this._assertIsAttribute(attribute);
        return (attribute in item);
    • summary
      See dojo.data.api.Read.hasAttribute()
  • dojox.data.FileStore.getIdentity

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

    • type
      Function
    • parameters:
      • item: (typeof )
    • source: [view]
        return [this._identifier];
    • summary
      See dojo.data.api.Read.getLabelAttributes()
  • dojox.data.FileStore.isItemLoaded

    • type
      Function
    • parameters:
      • item: (typeof )
    • source: [view]
         var loaded = this.isItem(item);
         if(loaded && typeof item._loaded == "boolean" && !item._loaded){
          loaded = false;
         }
         return loaded;
    • summary
      See dojo.data.api.Read.isItemLoaded()
  • dojox.data.FileStore.loadItem

    • type
      Function
    • parameters:
      • keywordArgs: (typeof )
    • source: [view]
        var item = keywordArgs.item;
        var self = this;
        var scope = keywordArgs.scope || dojo.global;


        var content = {};


        if(this.options.length > 0){
         content.options = dojo.toJson(this.options);
        }


        if(this.pathAsQueryParam){
         content.path = item.parentPath + this.pathSeparator + item.name;
        }
        var xhrData = {
         url: this.pathAsQueryParam? this.url : this.url + "/" + item.parentPath + "/" + item.name,
         handleAs: "json-comment-optional",
         content: content,
         preventCache: this.urlPreventCache,
         failOk: this.failOk
        };


        var deferred = dojo.xhrGet(xhrData);
        deferred.addErrback(function(error){
          if(keywordArgs.onError){
           keywordArgs.onError.call(scope, error);
          }
        });

        
        deferred.addCallback(function(data){
         delete item.parentPath;
         delete item._loaded;
         dojo.mixin(item, data);
         self._processItem(item);
         if(keywordArgs.onItem){
          keywordArgs.onItem.call(scope, item);
         }
        });
    • summary
      See dojo.data.api.Read.loadItem()
    • chains:
      • keywordArgs.onError: (call)
      • keywordArgs.onItem: (call)
  • dojox.data.FileStore.getLabel

    • type
      Function
    • parameters:
      • item: (typeof )
    • source: [view]
        return this.getValue(item,this.label);
    • summary
      See dojo.data.api.Read.getLabel()
  • dojox.data.FileStore.getLabelAttributes

    • type
      Function
    • parameters:
      • item: (typeof )
    • source: [view]
        return [this.label];
    • summary
      See dojo.data.api.Read.getLabelAttributes()
  • dojox.data.FileStore.containsValue

    • type
      Function
    • parameters:
      • item: (typeof )
      • attribute: (typeof )
      • value: (typeof )
    • source: [view]
        var values = this.getValues(item,attribute);
        for(var i = 0; i < values.length; i++){
         if(values[i] == value){
          return true;
         }
        }
        return false;
    • summary
      See dojo.data.api.Read.containsValue()
  • dojox.data.FileStore.getValues

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

        
        var value = item[attribute];
        if(typeof value !== "undefined" && !dojo.isArray(value)){
         value = [value];
        }else if(typeof value === "undefined"){
         value = [];
        }
        return value;
    • summary
      See dojo.data.api.Read.getValue()
  • dojox.data.FileStore.isItem

    • type
      Function
    • parameters:
      • item: (typeof )
    • source: [view]
        if(item && item[this._storeRef] === this){
         return true;
        }
        return false;
    • summary
      See dojo.data.api.Read.isItem()
  • dojox.data.FileStore.close

    • type
      Function
    • parameters:
      • request: (typeof )
    • source: [view]
        // summary:
        // See dojo.data.api.Read.close()
    • summary
      See dojo.data.api.Read.close()
  • dojox.data.FileStore.fetch

    • type
      Function
    • parameters:
      • request: (typeof A)
        request object
    • source: [view]
        request = request || {};
        if(!request.store){
         request.store = this;
        }
        var self = this;
        var scope = request.scope || dojo.global;


        //Generate what will be sent over.
        var reqParams = {};
        if(request.query){
         reqParams.query = dojo.toJson(request.query);
        }


        if(request.sort){
         reqParams.sort = dojo.toJson(request.sort);
        }


        if(request.queryOptions){
         reqParams.queryOptions = dojo.toJson(request.queryOptions);
        }


        if(typeof request.start == "number"){
         reqParams.start = "" + request.start;
        }
        if(typeof request.count == "number"){
         reqParams.count = "" + request.count;
        }


        if(this.options.length > 0){
         reqParams.options = dojo.toJson(this.options);
        }


        var getArgs = {
         url: this.url,
         preventCache: this.urlPreventCache,
         failOk: this.failOk,
         handleAs: "json-comment-optional",
         content: reqParams
        };




        var deferred = dojo.xhrGet(getArgs);


        deferred.addCallback(function(data){self._processResult(data, request);});
        deferred.addErrback(function(error){
         if(request.onError){
          request.onError.call(scope, error, request);
         }
        });
    • summary
      Fetch  items that match to a query
    • chains:
      • request.onError: (call)
  • dojox.data.FileStore.fetchItemByIdentity

    • type
      Function
    • parameters:
      • keywordArgs: (typeof )
    • source: [view]
        var path = keywordArgs.identity;
        var self = this;
        var scope = keywordArgs.scope || dojo.global;


        var content = {};


        if(this.options.length > 0){
         content.options = dojo.toJson(this.options);
        }


        if(this.pathAsQueryParam){
         content.path = path;
        }
        var xhrData = {
         url: this.pathAsQueryParam? this.url : this.url + "/" + path,
         handleAs: "json-comment-optional",
         content: content,
         preventCache: this.urlPreventCache,
         failOk: this.failOk
        };


        var deferred = dojo.xhrGet(xhrData);
        deferred.addErrback(function(error){
          if(keywordArgs.onError){
           keywordArgs.onError.call(scope, error);
          }
        });

        
        deferred.addCallback(function(data){
         var item = self._processItem(data);
         if(keywordArgs.onItem){
          keywordArgs.onItem.call(scope, item);
         }
        });
    • summary
      See dojo.data.api.Read.loadItem()
    • chains:
      • keywordArgs.onError: (call)
      • keywordArgs.onItem: (call)
  • dojox.data.FileStore._processResult

    • type
      Function
    • parameters:
      • data: (typeof )
      • request: (typeof )
    • source: [view]
         var scope = request.scope || dojo.global;
         try{
          //If the data contains a path separator, set ours
          if(data.pathSeparator){
           this.pathSeparator = data.pathSeparator;
          }
          //Invoke the onBegin handler, if any, to return the
          //size of the dataset as indicated by the service.
          if(request.onBegin){
           request.onBegin.call(scope, data.total, request);
          }
          //Now process all the returned items thro
          var items = this._processItemArray(data.items);
          if(request.onItem){
          var i;
          for(i = 0; i < items.length; i++){
           request.onItem.call(scope, items[i], request);
          }
          items = null;
          }
          if(request.onComplete){
           request.onComplete.call(scope, items, request);
          }
         }catch (e){
          if(request.onError){
           request.onError.call(scope, e, request);
          }else{
           console.log(e);
          }
         }
    • chains:
      • request.onBegin: (call)
      • request.onItem: (call)
      • request.onComplete: (call)
      • request.onError: (call)
    • summary
  • dojox.data.FileStore._processItemArray

    • type
      Function
    • parameters:
      • itemArray: (typeof )
    • source: [view]
         var i;
         for(i = 0; i < itemArray.length; i++){
          this._processItem(itemArray[i]);
         }
         return itemArray;
    • summary
      Internal function for processing an array of items for return.
  • dojox.data.FileStore._processItem

    • type
      Function
    • parameters:
      • item: (typeof )
    • source: [view]
        if(!item){return null;}
        item[this._storeRef] = this;
        if(item.children && item.directory){
         if(dojo.isArray(item.children)){
          var children = item.children;
          var i;
          for(i = 0; i < children.length; i++ ){
           var name = children[i];
           if(dojo.isObject(name)){
            children[i] = this._processItem(name);
           }else{
            children[i] = {name: name, _loaded: false, parentPath: item.path};
            children[i][this._storeRef] = this;
           }
          }
         }else{
          delete item.children;
         }
        }
        return item;
    • summary
      Internal function for processing an item returned from the store.
      It sets up the store ref as well as sets up the attributes necessary
      to invoke a lazy load on a child, if there are any.
  • item

    • mixins:
      • data: (normal)
    • summary
  • dojox.data

    • type
      Object
    • summary
  • dojox

    • type
      Object
    • summary