src/js/serializers/JSONSerializer.js
branchpopcorn-port
changeset 842 4ae2247a59f4
parent 820 7968346b9689
child 861 05f75ca6b5de
equal deleted inserted replaced
841:8da49ff273e0 842:4ae2247a59f4
    19 };
    19 };
    20 
    20 
    21 /** load JSON-cinelab data and also sort the annotations by start time
    21 /** load JSON-cinelab data and also sort the annotations by start time
    22     @param callback function to call when the data is ready.
    22     @param callback function to call when the data is ready.
    23  */
    23  */
    24 IriSP.JSONSerializer.prototype.sync = function(callback) {
    24 IriSP.JSONSerializer.prototype.sync = function(callback, force_refresh) {
    25   /* we don't have to do much because jQuery handles json for us */
    25   /* we don't have to do much because jQuery handles json for us */
    26 
    26 
    27   var self = this;
    27   var self = this;
    28 
    28 
    29   var fn = function(data) {
    29   var fn = function(data) {
    41 	            return a_begin - b_begin;
    41 	            return a_begin - b_begin;
    42 	          });
    42 	          });
    43 	  }     
    43 	  }     
    44       callback(data);      
    44       callback(data);      
    45   };
    45   };
    46   
    46   this._DataLoader.get(this._url, fn, force_refresh);
    47   this._DataLoader.get(this._url, fn);
       
    48 };
    47 };
    49 
    48 
    50 /** @return the metadata about the media being read FIXME: always return the first media. */
    49 /** @return the metadata about the media being read FIXME: always return the first media. */
    51 IriSP.JSONSerializer.prototype.currentMedia = function() {  
    50 IriSP.JSONSerializer.prototype.currentMedia = function() {  
    52   return this._data.medias[0]; /* FIXME: don't hardcode it */
    51   return (typeof this._data.medias == "object" && this._data.medias.length) ? this._data.medias[0] : IriSP.__jsonMetadata.medias[0];
    53 };
    52 };
       
    53 
       
    54 IriSP.JSONSerializer.prototype.getDuration = function() {
       
    55     var _m = this.currentMedia();
       
    56     if (_m === null || typeof _m.meta == "undefined") {
       
    57         return 0;
       
    58     }
       
    59     return +(IriSP.get_aliased(_m.meta, ["dc:duration", "duration"]) || 0);
       
    60 }
       
    61 
    54 
    62 
    55 /** searches for an annotation which matches title, description and keyword 
    63 /** searches for an annotation which matches title, description and keyword 
    56    "" matches any field. 
    64    "" matches any field. 
    57    Note: it ignores tweets.
    65    Note: it ignores tweets.
    58    @return a list of matching ids.
    66    @return a list of matching ids.
   431   if (typeof(val) === "undefined")
   439   if (typeof(val) === "undefined")
   432     val = this.getId("Publ");
   440     val = this.getId("Publ");
   433     
   441     
   434   return val;
   442   return val;
   435 };
   443 };
   436 
       
   437 IriSP.JSONSerializer.prototype.getDuration = function() {
       
   438     return +(IriSP.get_aliased(this.currentMedia().meta, ["dc:duration", "duration"]) || 0);
       
   439 }