123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440 |
- if(!dojo._hasResource["dojox.data.FileStore"]){
- dojo._hasResource["dojox.data.FileStore"] = true;
- dojo.provide("dojox.data.FileStore");
- dojo.declare("dojox.data.FileStore", null, {
- constructor: function(/*Object*/args){
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 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;
- }
- },
-
-
- url: "",
-
-
-
- _storeRef: "_S",
-
-
-
- label: "name",
-
-
-
- _identifier: "path",
-
-
- _attributes: ["children", "directory", "name", "path", "modified", "size", "parentDir"],
-
-
-
-
- pathSeparator: "/",
-
-
-
- options: [],
-
-
- failOk: false,
-
-
- urlPreventCache: true,
- _assertIsItem: function(/* item */ item){
-
-
-
-
- if(!this.isItem(item)){
- throw new Error("dojox.data.FileStore: a function was passed an item argument that was not an item");
- }
- },
- _assertIsAttribute: function(/* attribute-name-string */ attribute){
-
-
-
-
- if(typeof attribute !== "string"){
- throw new Error("dojox.data.FileStore: a function was passed an attribute argument that was not an attribute name string");
- }
- },
- pathAsQueryParam: false,
- getFeatures: function(){
-
-
- return {
- 'dojo.data.api.Read': true, 'dojo.data.api.Identity':true
- };
- },
- getValue: function(item, attribute, defaultValue){
-
-
- var values = this.getValues(item, attribute);
- if(values && values.length > 0){
- return values[0];
- }
- return defaultValue;
- },
- getAttributes: function(item){
-
-
- return this._attributes;
- },
- hasAttribute: function(item, attribute){
-
-
- this._assertIsItem(item);
- this._assertIsAttribute(attribute);
- return (attribute in item);
- },
-
- getIdentity: function(/* item */ item){
-
-
- return this.getValue(item, this._identifier);
- },
-
- getIdentityAttributes: function(item){
-
-
- return [this._identifier];
- },
- isItemLoaded: function(item){
-
-
- var loaded = this.isItem(item);
- if(loaded && typeof item._loaded == "boolean" && !item._loaded){
- loaded = false;
- }
- return loaded;
- },
- loadItem: function(keywordArgs){
-
-
- 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);
- }
- });
- },
- getLabel: function(item){
-
-
- return this.getValue(item,this.label);
- },
-
- getLabelAttributes: function(item){
-
-
- return [this.label];
- },
-
- containsValue: function(item, attribute, value){
-
-
- 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){
-
-
- 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;
- },
- isItem: function(item){
-
-
- if(item && item[this._storeRef] === this){
- return true;
- }
- return false;
- },
-
- close: function(request){
-
-
- },
- fetch: function(request){
-
-
-
-
- request = request || {};
- if(!request.store){
- request.store = this;
- }
- var self = this;
- var scope = request.scope || dojo.global;
-
- 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);
- }
- });
- },
- fetchItemByIdentity: function(keywordArgs){
-
-
- 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);
- }
- });
- },
- _processResult: function(data, request){
- var scope = request.scope || dojo.global;
- try{
-
- if(data.pathSeparator){
- this.pathSeparator = data.pathSeparator;
- }
-
-
- if(request.onBegin){
- request.onBegin.call(scope, data.total, request);
- }
-
- 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);
- }
- }
- },
-
- _processItemArray: function(itemArray){
-
-
- var i;
- for(i = 0; i < itemArray.length; i++){
- this._processItem(itemArray[i]);
- }
- return itemArray;
- },
-
- _processItem: function(item){
-
-
-
-
- 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;
- }
- });
- }
|