web/res/metadataplayer/AnnotationsList.js
changeset 654 a5977736d2b0
parent 638 e0d4e8431de3
child 668 eb7e39c732c6
--- a/web/res/metadataplayer/AnnotationsList.js	Tue Jul 03 18:19:39 2012 +0200
+++ b/web/res/metadataplayer/AnnotationsList.js	Fri Jul 06 18:22:13 2012 +0200
@@ -19,7 +19,7 @@
     /* number of milliseconds before/after the current timecode when calling the segment API
      */
     ajax_granularity : 300000, 
-    default_thumbnail : "http://ldt.iri.centrepompidou.fr/static/site/ldt/css/imgs/video_sequence.png",
+    default_thumbnail : "",
     /* URL when the annotation is not in the current project,
      * e.g. http://ldt.iri.centrepompidou.fr/ldtplatform/ldt/front/player/{{media}}/{{project}}/{{annotationType}}#id={{annotation}}
      */
@@ -27,14 +27,27 @@
     annotation_type : false,
     refresh_interval : 0,
     limit_count : 10,
-    newest_first : false
+    newest_first : false,
+    polemics : [{
+        keyword: "++",
+        background_color: "#c9ecc6"
+    },{
+        keyword: "--",
+        background_color: "#f9c5c6"
+    },{
+        keyword: "??",
+        background_color: "#cec5f9"
+    },{
+        keyword: "==",
+        background_color: "#f9f4c6"
+    }]
 };
 
 IriSP.Widgets.AnnotationsList.prototype.template =
     '<div class="Ldt-AnnotationsListWidget">'
     + '<ul class="Ldt-AnnotationsList-ul">'
     + '{{#annotations}}'
-    + '<li class="Ldt-AnnotationsList-li Ldt-TraceMe" trace-info="annotation-id:{{id}}">'
+    + '<li class="Ldt-AnnotationsList-li Ldt-TraceMe" trace-info="annotation-id:{{id}}" style="{{specific_style}}">'
     + '<div class="Ldt-AnnotationsList-ThumbContainer">'
     + '<a href="{{url}}">'
     + '<img class="Ldt-AnnotationsList-Thumbnail" src="{{thumbnail}}" />'
@@ -107,7 +120,6 @@
                 begin : Math.max(0, _currentAnnotation.annotation.begin.milliseconds - this.ajax_granularity),
                 end : Math.min(_currentMedia.duration.milliseconds, _currentAnnotation.annotation.end.milliseconds + this.ajax_granularity)
             });
-        console.log("Getting", _url);
         this.currentSource = this.player.loadMetadata(IriSP._.defaults({
             "url" : _url
         }, this.metadata));
@@ -168,23 +180,40 @@
                                 _this.foreign_url,
                                 {
                                     project : _annotation.project,
-                                    media : _annotation.media.id.replace(/^.*:/,''),
+                                    media : _annotation.media.id,
                                     annotation : _annotation.id,
-                                    annotationType : _annotation.annotationType.id.replace(/^.*:/,'')
+                                    annotationType : _annotation.annotationType.id
                                 }
                             )
                             : '#id=' + _annotation.id
                             )
                     );
+                    var _title = (_annotation.title || "").replace(_annotation.description,''),
+                        _description = _annotation.description;
+                    if (!_annotation.title) {
+                        _title = _annotation.creator;
+                    }
+                    if (!_annotation.description && _annotation.creator) {
+                        _description = _annotation.title;
+                        _title = _annotation.creator;
+                    }
+                    var _bgcolor;
+                    IriSP._(_this.polemics).each(function(_polemic) {
+                        var _rgxp = IriSP.Model.regexpFromTextOrArray(_polemic.keyword, true);
+                        if (_rgxp.test(_title + " " + _description)) {
+                            _bgcolor = _polemic.background_color;
+                        }
+                    });
                     var _res = {
                         id : _annotation.id,
-                        title : _annotation.title.replace(_annotation.description,''),
-                        description : _annotation.description,
+                        title : _title,
+                        description : _description,
                         begin : _annotation.begin.toString(),
                         end : _annotation.end.toString(),
                         thumbnail : typeof _annotation.thumbnail !== "undefined" && _annotation.thumbnail ? _annotation.thumbnail : _this.default_thumbnail,
                         url : _url,
-                        tags : _annotation.getTagTexts()
+                        tags : _annotation.getTagTexts(),
+                        specific_style : (typeof _bgcolor !== "undefined" ? "background: " + _bgcolor : "")
                     }
                     return _res;
             }),
@@ -209,7 +238,7 @@
         })
         
         if(this.searchString) {
-            var _searchRe = new RegExp('(' + this.searchString.replace(/(\W)/gm,'\\$1') + ')','gim');
+            var _searchRe = IriSP.Model.regexpFromTextOrArray(this.searchString);
             this.$.find(".Ldt-AnnotationsList-Title a, .Ldt-AnnotationsList-Description").each(function() {
                 var _$ = IriSP.jQuery(this);
                 _$.html(_$.text().replace(/(^\s+|\s+$)/g,'').replace(_searchRe, '<span class="Ldt-AnnotationsList-highlight">$1</span>'))