updated player version.
authorhamidouk
Mon, 16 Jan 2012 15:41:26 +0100
changeset 397 bfea870f9eb9
parent 396 134fe0c9e811
child 398 db8697ff4594
updated player version.
src/ldt/ldt/static/ldt/js/LdtPlayer-release.js
--- a/src/ldt/ldt/static/ldt/js/LdtPlayer-release.js	Mon Jan 16 09:57:38 2012 +0100
+++ b/src/ldt/ldt/static/ldt/js/LdtPlayer-release.js	Mon Jan 16 15:41:26 2012 +0100
@@ -1404,16 +1404,14 @@
 
 // conversion de couleur Decimal vers HexaDecimal || 000 si fff
 IriSP.DEC_HEXA_COLOR = function (dec) {
-	 var hexa='0123456789ABCDEF';
-   var hex='';
-	 var tmp;
-	 while (dec>15){
-		  tmp = dec-(Math.floor(dec/16))*16;
-		  hex = hexa.charAt(tmp)+hex;
-		  dec = Math.floor(dec/16);
-	 }
-	 hex = hexa.charAt(dec)+hex;	 
-	 return(hex);
+  var val = +dec;
+  var str = val.toString(16);
+  var zeroes = "";
+  if (str.length < 6) {
+    for (var i = 0; i < 6 - str.length; i++)
+      zeroes += "0";
+  }
+  return zeroes + str;
 };
 
 /* shortcut to have global variables in templates */
@@ -1451,6 +1449,10 @@
   return "";
 };
 
+/** test if a value is null or undefined */
+IriSP.null_or_undefined = function(val) {
+  return (typeof(val) === "undefined" || val === null);
+}
 /* for ie compatibility
 if (Object.prototype.__defineGetter__&&!Object.defineProperty) {
    Object.defineProperty=function(obj,prop,desc) {
@@ -3533,9 +3535,9 @@
   this.selector.append(Mustache.to_html(IriSP.overlay_marker_template));
           
   var view_type = this._serializer.getChapitrage();
-  if (typeof(view_type) === "undefined")
-    view_type = this._serializer.getNonTweetIds()[0];    
-  
+  if (typeof(view_type) === "undefined") {
+    view_type = this._serializer.getNonTweetIds()[0];  
+  }
   this.positionMarker = this.selector.children(":first");
   
   this._Popcorn.listen("timeupdate", IriSP.wrap(this, this.positionUpdater));
@@ -3587,8 +3589,10 @@
     
     var hexa_color = IriSP.DEC_HEXA_COLOR(color);
 
+    /*
     if (hexa_color === "FFCC00")
       hexa_color = "333";
+    */
     if (hexa_color.length == 4)
       hexa_color = hexa_color + '00';
     
@@ -4529,36 +4533,89 @@
 
 /** returns a list of ids of tweet lines (aka: groups in cinelab) */
 IriSP.JSONSerializer.prototype.getTweetIds = function() {
-  if (typeof(this._data.lists) === "undefined" || this._data.lists === null)
+  if (IriSP.null_or_undefined(this._data.lists) || IriSP.null_or_undefined(this._data.lists) ||
+      IriSP.null_or_undefined(this._data.views) || IriSP.null_or_undefined(this._data.views[0]))
     return [];
 
-  var tweetsId = [];
   
-  /* first get the list containing the tweets */
-  var tweets = IriSP.underscore.filter(this._data.lists, function(entry) { return entry.id.indexOf("tweet") !== -1 });
+  /* Get the displayable types
+     We've got to jump through a few hoops because the json sometimes defines
+     fields with underscores and sometimes with dashes
+  */
+  var annotation_types = this._data.views[0]["annotation_types"];
+  if (IriSP.null_or_undefined(annotation_types)) {
+    annotation_types = this._data.views[0]["annotation-types"];
+    if (IriSP.null_or_undefined(annotation_types)) {
+      console.log("neither view.annotation_types nor view.annotation-types are defined");      
+      return;
+    }
+  }
+
+  var available_types = this._data["annotation_types"];    
+  if (IriSP.null_or_undefined(available_types)) {
+    available_types = this._data["annotation-types"];
+    if (IriSP.null_or_undefined(available_types)) {
+      console.log("neither annotation_types nor annotation-types are defined");      
+      return;
+    }
+  }
   
-  if (tweets.length === 0)
-    return [];
+  var potential_types = [];
   
-  // FIXME: collect tweets from multiple sources ?
-  tweetsId = IriSP.underscore.pluck(tweets[0].items, "id-ref");
-
+  // Get the list of types which contain "Tw" in their content
+  for (var i = 0; i < available_types.length; i++) {
+    if (/Tw/i.test(available_types[i]["dc:title"])) {
+      potential_types.push(available_types[i].id);
+    }
+  }
+  
+  // Get the intersection of both.
+  var tweetsId = IriSP.underscore.intersection(annotation_types, potential_types);
+  
   return tweetsId;
 };
 
 /** this function returns a list of lines which are not tweet lines */
 IriSP.JSONSerializer.prototype.getNonTweetIds = function() {
-  if (typeof(this._data.lists) === "undefined" || this._data.lists === null)
+  if (IriSP.null_or_undefined(this._data.lists) || IriSP.null_or_undefined(this._data.lists) ||
+      IriSP.null_or_undefined(this._data.views) || IriSP.null_or_undefined(this._data.views[0]))
     return [];
-  
-  /* complicated : for each list in this._data.lists, get the id-ref.
-     flatten the returned array because pluck returns a string afterwards.
+
+  /* Get the displayable types
+     We've got to jump through a few hoops because the json sometimes defines
+     fields with underscores and sometimes with dashes
   */
-  var ids = IriSP.underscore.flatten(IriSP.underscore.map(this._data.lists, function(entry) {                                                         
-                                                         return IriSP.underscore.pluck(entry.items, "id-ref"); }));
-                                                         
-  var illegal_values = this.getTweetIds();
-  return IriSP.underscore.difference(ids, illegal_values);
+  var annotation_types = this._data.views[0]["annotation_types"];
+  if (IriSP.null_or_undefined(annotation_types)) {
+    annotation_types = this._data.views[0]["annotation-types"];
+    if (IriSP.null_or_undefined(annotation_types)) {
+      console.log("neither view.annotation_types nor view.annotation-types are defined");      
+      return;
+    }
+  }
+
+  var available_types = this._data["annotation_types"];    
+  if (IriSP.null_or_undefined(available_types)) {
+    available_types = this._data["annotation-types"];
+    if (IriSP.null_or_undefined(available_types)) {
+      console.log("neither annotation_types nor annotation-types are defined");      
+      return;
+    }
+  }
+
+  var potential_types = [];
+  
+  // Get the list of types which do not contain "Tw" in their content
+  for (var i = 0; i < available_types.length; i++) {
+    if (!(/Tw/i.test(available_types[i]["dc:title"]))) {
+      potential_types.push(available_types[i].id);
+    }
+  }
+
+  // Get the intersection of both.
+  var nonTweetsId = IriSP.underscore.intersection(annotation_types, potential_types);
+  
+  return nonTweetsId;
   
 };