dojox/data/FlickrStore.js

  • Provides:

    • dojox.data.FlickrStore
  • dojox.data.FlickrStore

    • type
      Function
    • parameters:
      • args: (typeof Object)
    • source: [view]
        if(args && args.label){
         this.label = args.label;
        }
        if(args && "urlPreventCache" in args){
         this.urlPreventCache = args.urlPreventCache?true:false;
        }
    • summary
      Initializer for the FlickrStore store.
    • description
      The FlickrStore is a Datastore interface to one of the basic services
      of the Flickr service, the public photo feed.  This does not provide
      access to all the services of Flickr.
      This store cannot do * and ? filtering as the flickr service
      provides no interface for wildcards.
    • mixins:
      • dojo.data.util.simpleFetch: (prototype)
  • dojox.data.FlickrStore._storeRef

    • summary
  • dojox.data.FlickrStore.label

    • summary
  • dojox.data.FlickrStore.urlPreventCache

    • summary
  • dojox.data.FlickrStore._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.FlickrStore: 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.FlickrStore._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.FlickrStore: 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.FlickrStore.getFeatures

    • type
      Function
    • source: [view]
        return {
         'dojo.data.api.Read': true
        };
    • summary
      See dojo.data.api.Read.getFeatures()
  • dojox.data.FlickrStore.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.FlickrStore.getAttributes

    • type
      Function
    • parameters:
      • item: (typeof )
    • source: [view]
        return [
         "title", "description", "author", "datePublished", "dateTaken",
         "imageUrl", "imageUrlSmall", "imageUrlMedium", "tags", "link"
        ];
    • summary
      See dojo.data.api.Read.getAttributes()
  • dojox.data.FlickrStore.hasAttribute

    • type
      Function
    • parameters:
      • item: (typeof )
      • attribute: (typeof )
    • source: [view]
        var v = this.getValue(item,attribute);
        if(v || v === "" || v === false){
         return true;
        }
        return false;
    • summary
      See dojo.data.api.Read.hasAttributes()
  • dojox.data.FlickrStore.isItemLoaded

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

    • type
      Function
    • parameters:
      • keywordArgs: (typeof )
    • source: [view]
        // summary:
        // See dojo.data.api.Read.loadItem()
    • summary
      See dojo.data.api.Read.loadItem()
  • dojox.data.FlickrStore.getLabel

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

    • type
      Function
    • parameters:
      • item: (typeof )
    • source: [view]
        return [this.label];
    • summary
      See dojo.data.api.Read.getLabelAttributes()
  • dojox.data.FlickrStore.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.FlickrStore.getValues

    • type
      Function
    • parameters:
      • item: (typeof )
      • attribute: (typeof )
    • source: [view]
        this._assertIsItem(item);
        this._assertIsAttribute(attribute);
        var u = dojo.hitch(this, "_unescapeHtml");
        var s = dojo.hitch(dojo.date.stamp, "fromISOString");
        switch(attribute){
         case "title":
          return [ u(item.title) ];
         case "author":
          return [ u(item.author) ];
         case "datePublished":
          return [ s(item.published) ];
         case "dateTaken":
          return [ s(item.date_taken) ];
         case "imageUrlSmall":
          return [ item.media.m.replace(/_m\./, "_s.") ];
         case "imageUrl":
          return [ item.media.m.replace(/_m\./, ".") ];
         case "imageUrlMedium":
          return [ item.media.m ];
         case "link":
          return [ item.link ];
         case "tags":
          return item.tags.split(" ");
         case "description":
          return [ u(item.description) ];
         default:
          return [];
        }
    • summary
      See dojo.data.api.Read.getValue()
  • dojox.data.FlickrStore.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.FlickrStore.close

    • type
      Function
    • parameters:
      • request: (typeof )
    • source: [view]
        // summary:
        // See dojo.data.api.Read.close()
    • summary
      See dojo.data.api.Read.close()
  • dojox.data.FlickrStore._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]
        var rq = request.query = request.query || {};


        //Build up the content to send the request for.
        var content = {
         format: "json",
         tagmode:"any"
        };


        dojo.forEach(
         [ "tags", "tagmode", "lang", "id", "ids" ],
         function(i){
          if(rq[i]){ content[i] = rq[i]; }
         }
        );


        content.id = rq.id || rq.userid || rq.groupid;


        if(rq.userids){
         content.ids = rq.userids;
        }


        //Linking this up to Flickr is a PAIN!
        var handle = null;
        var getArgs = {
         url: dojox.data.FlickrStore.urlRegistry.match(request),
         preventCache: this.urlPreventCache,
         content: content
        };
        var myHandler = dojo.hitch(this, function(data){
         if(!!handle){
          dojo.disconnect(handle);
         }


         //Process the items...
         fetchHandler(this._processFlickrData(data), request);
        });
        handle = dojo.connect("jsonFlickrFeed", myHandler);
        var deferred = dojo.io.script.get(getArgs);

        
        //We only set up the errback, because the callback isn't ever really used because we have
        //to link to the jsonFlickrFeed function....
        deferred.addErrback(function(error){
         dojo.disconnect(handle);
         errorHandler(error, request);
        });
    • summary
      Fetch flickr items that match to a query
  • dojox.data.FlickrStore._processFlickrData

    • type
      Function
    • parameters:
      • data: (typeof )
    • source: [view]
         var items = [];
         if(data.items){
          items = data.items;
          //Add on the store ref so that isItem can work.
          for(var i = 0; i < data.items.length; i++){
           var item = data.items[i];
           item[this._storeRef] = this;
          }
         }
         return items;
    • summary
  • dojox.data.FlickrStore._unescapeHtml

    • type
      Function
    • parameters:
      • str: (typeof String)
        String.
        The string to un-escape
    • source: [view]
      define("dojox/data/FlickrStore", ["dojo", "dojox", "dojo/data/util/simpleFetch", "dojo/io/script", "dojo/date/stamp", "dojo/AdapterRegistry"], function(dojo, dojox) {


      dojo.declare("dojox.data.FlickrStore", null, {
       constructor: function(/*Object*/args){
        // summary:
        //  Initializer for the FlickrStore store.
        // description:
        //  The FlickrStore is a Datastore interface to one of the basic services
        //  of the Flickr service, the public photo feed. This does not provide
        //  access to all the services of Flickr.
        //  This store cannot do * and ? filtering as the flickr service
        //  provides no interface for wildcards.
        if(args && args.label){
         this.label = args.label;
        }
        if(args && "urlPreventCache" in args){
         this.urlPreventCache = args.urlPreventCache?true:false;
        }
       },


       _storeRef: "_S",


       label: "title",


       //Flag to allor control of if cache prevention is enabled or not.
       urlPreventCache: true,


       _assertIsItem: function(/* item */ item){
        // summary:
        // This function tests whether the item passed in is indeed an item in the store.
        // item:
        //  The item to test for being contained by the store.
        if(!this.isItem(item)){
         throw new Error("dojox.data.FlickrStore: a function was passed an item argument that was not an item");
        }
       },


       _assertIsAttribute: function(/* attribute-name-string */ attribute){
        // summary:
        //  This function tests whether the item passed in is indeed a valid 'attribute' like type for the store.
        // attribute:
        //  The attribute to test for being contained by the store.
        if(typeof attribute !== "string"){
         throw new Error("dojox.data.FlickrStore: a function was passed an attribute argument that was not an attribute name string");
        }
       },


       getFeatures: function(){
        // summary:
        // See dojo.data.api.Read.getFeatures()
        return {
         'dojo.data.api.Read': true
        };
       },


       getValue: function(item, attribute, defaultValue){
        // summary:
        // See dojo.data.api.Read.getValue()
        var values = this.getValues(item, attribute);
        if(values && values.length > 0){
         return values[0];
        }
        return defaultValue;
       },


       getAttributes: function(item){
        // summary:
        // See dojo.data.api.Read.getAttributes()
        return [
         "title", "description", "author", "datePublished", "dateTaken",
         "imageUrl", "imageUrlSmall", "imageUrlMedium", "tags", "link"
        ];
       },


       hasAttribute: function(item, attribute){
        // summary:
        // See dojo.data.api.Read.hasAttributes()
        var v = this.getValue(item,attribute);
        if(v || v === "" || v === false){
         return true;
        }
        return false;
       },


       isItemLoaded: function(item){
         // summary:
         // See dojo.data.api.Read.isItemLoaded()
         return this.isItem(item);
       },


       loadItem: function(keywordArgs){
        // summary:
        // See dojo.data.api.Read.loadItem()
       },


       getLabel: function(item){
        // summary:
        // See dojo.data.api.Read.getLabel()
        return this.getValue(item,this.label);
       },

       
       getLabelAttributes: function(item){
        // summary:
        // See dojo.data.api.Read.getLabelAttributes()
        return [this.label];
       },


       containsValue: function(item, attribute, value){
        // summary:
        // See dojo.data.api.Read.containsValue()
        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){
        // summary:
        // See dojo.data.api.Read.getValue()


        this._assertIsItem(item);
        this._assertIsAttribute(attribute);
        var u = dojo.hitch(this, "_unescapeHtml");
        var s = dojo.hitch(dojo.date.stamp, "fromISOString");
        switch(attribute){
         case "title":
          return [ u(item.title) ];
         case "author":
          return [ u(item.author) ];
         case "datePublished":
          return [ s(item.published) ];
         case "dateTaken":
          return [ s(item.date_taken) ];
         case "imageUrlSmall":
          return [ item.media.m.replace(/_m\./, "_s.") ];
         case "imageUrl":
          return [ item.media.m.replace(/_m\./, ".") ];
         case "imageUrlMedium":
          return [ item.media.m ];
         case "link":
          return [ item.link ];
         case "tags":
          return item.tags.split(" ");
         case "description":
          return [ u(item.description) ];
         default:
          return [];
        }
       },


       isItem: function(item){
        // summary:
        // See dojo.data.api.Read.isItem()
        if(item && item[this._storeRef] === this){
         return true;
        }
        return false;
       },

       
       close: function(request){
        // summary:
        // See dojo.data.api.Read.close()
       },


       _fetchItems: function(request, fetchHandler, errorHandler){
        // summary:
        //  Fetch flickr items that match to a query
        // request:
        //  A request object
        // fetchHandler:
        //  A function to call for fetched items
        // errorHandler:
        //  A function to call on error


        var rq = request.query = request.query || {};


        //Build up the content to send the request for.
        var content = {
         format: "json",
         tagmode:"any"
        };


        dojo.forEach(
         [ "tags", "tagmode", "lang", "id", "ids" ],
         function(i){
          if(rq[i]){ content[i] = rq[i]; }
         }
        );


        content.id = rq.id || rq.userid || rq.groupid;


        if(rq.userids){
         content.ids = rq.userids;
        }


        //Linking this up to Flickr is a PAIN!
        var handle = null;
        var getArgs = {
         url: dojox.data.FlickrStore.urlRegistry.match(request),
         preventCache: this.urlPreventCache,
         content: content
        };
        var myHandler = dojo.hitch(this, function(data){
         if(!!handle){
          dojo.disconnect(handle);
         }


         //Process the items...
         fetchHandler(this._processFlickrData(data), request);
        });
        handle = dojo.connect("jsonFlickrFeed", myHandler);
        var deferred = dojo.io.script.get(getArgs);

        
        //We only set up the errback, because the callback isn't ever really used because we have
        //to link to the jsonFlickrFeed function....
        deferred.addErrback(function(error){
         dojo.disconnect(handle);
         errorHandler(error, request);
        });
       },


       _processFlickrData: function(data){
         var items = [];
         if(data.items){
          items = data.items;
          //Add on the store ref so that isItem can work.
          for(var i = 0; i < data.items.length; i++){
           var item = data.items[i];
           item[this._storeRef] = this;
          }
         }
         return items;
       },


       _unescapeHtml: function(/*String*/ str){
        // summary:
        //  Utility function to un-escape XML special characters in an
        //  HTML string.
        // str: String.
        //  The string to un-escape
        // returns:
        //  HTML String converted back to the normal text (unescaped)
        //  characters (<,>,&, ", etc,).


        //TODO:
        //  Check to see if theres already compatible escape() in
        //  dojo.string or dojo.html
        return  str.replace(/&/gm, "&").
           replace(/</gm, "<").
           replace(/>/gm, ">").
           replace(/"/gm, "\"").
           replace(/'/gm, "'");
    • summary
      Utility function to un-escape XML special characters in an
      HTML string.
  • jsonFlickrFeed

    • type
      Function
    • parameters:
      • data: (typeof )
    • source: [view]
      }
    • summary
  • feedsUrl

    • summary
  • reg

    • summary
  • dojox.data

    • type
      Object
    • summary
  • dojox

    • type
      Object
    • summary