Corrected MAJOR bug in search results new-model
authorveltr
Fri, 06 Jul 2012 18:13:32 +0200
branchnew-model
changeset 925 28efc97b5d78
parent 924 64c2eaafe5e2
child 926 e47ed8eb75cd
Corrected MAJOR bug in search results
src/js/model.js
src/widgets/Annotation.js
src/widgets/AnnotationsList.js
src/widgets/CreateAnnotation.js
src/widgets/Polemic.js
src/widgets/Segments.js
test/jwplayer.htm
--- a/src/js/model.js	Thu Jul 05 19:08:13 2012 +0200
+++ b/src/js/model.js	Fri Jul 06 18:13:32 2012 +0200
@@ -28,19 +28,20 @@
         }
         return "autoid-" + this._ID_BASE + '-' + _n;
     },
-    regexpFromTextOrArray : function(_textOrArray) {
+    regexpFromTextOrArray : function(_textOrArray, _testOnly) {
+        var _testOnly = _testOnly || false;
         function escapeText(_text) {
             return _text.replace(/([\\\*\+\?\|\{\[\}\]\(\)\^\$\.\#\/])/gm, '\\$1');
         }
-        return new RegExp( '('
-            + (
-                typeof _textOrArray === "string"
-                ? escapeText(_textOrArray)
-                : IriSP._(_textOrArray).map(escapeText).join("|")
-            )
-            + ')',
-            'gim'
-        );
+        var _source = 
+            typeof _textOrArray === "string"
+            ? escapeText(_textOrArray)
+            : IriSP._(_textOrArray).map(escapeText).join("|");
+        if (_testOnly) {
+            return new RegExp( _source, 'im');
+        } else {
+            return new RegExp( '(' + _source + ')', 'gim');
+        }
     },
     isoToDate : function(_str) {
         // http://delete.me.uk/2005/03/iso8601.html
@@ -168,21 +169,21 @@
  * here we can search by these criteria
  */
 IriSP.Model.List.prototype.searchByTitle = function(_text) {
-    var _rgxp = IriSP.Model.regexpFromTextOrArray(_text);
+    var _rgxp = IriSP.Model.regexpFromTextOrArray(_text, true);
     return this.filter(function(_element) {
         return _rgxp.test(_element.title);
     });
 }
 
 IriSP.Model.List.prototype.searchByDescription = function(_text) {
-    var _rgxp = IriSP.Model.regexpFromTextOrArray(_text);
+    var _rgxp = IriSP.Model.regexpFromTextOrArray(_text, true);
     return this.filter(function(_element) {
         return _rgxp.test(_element.description);
     });
 }
 
 IriSP.Model.List.prototype.searchByTextFields = function(_text) {
-    var _rgxp =  IriSP.Model.regexpFromTextOrArray(_text);
+    var _rgxp =  IriSP.Model.regexpFromTextOrArray(_text, true);
     return this.filter(function(_element) {
         return _rgxp.test(_element.description) || _rgxp.test(_element.title);
     });
--- a/src/widgets/Annotation.js	Thu Jul 05 19:08:13 2012 +0200
+++ b/src/widgets/Annotation.js	Fri Jul 06 18:13:32 2012 +0200
@@ -30,7 +30,7 @@
     '<div class="Ldt-Annotation-Widget {{#show_top_border}}Ldt-Annotation-ShowTop{{/show_top_border}}">'
     + '<div class="Ldt-Annotation-Inner Ldt-Annotation-Empty{{#start_minimized}} Ldt-Annotation-Minimized{{/start_minimized}}">'
     + '<div class="Ldt-Annotation-HiddenWhenEmpty Ldt-Annotation-MaxMinButton"></div>'
-    + '<div class="Ldt-Annotation-Social Ldt-Annotation-HiddenWhenMinimized"></div>'
+    + '<div class="Ldt-Annotation-Social Ldt-Annotation-HiddenWhenMinimized Ldt-Annotation-HiddenWhenEmpty"></div>'
     + '<h3 class="Ldt-Annotation-HiddenWhenEmpty"><span class="Ldt-Annotation-Title"></span> <span class="Ldt-Annotation-Time">'
     + '( <span class="Ldt-Annotation-Begin"></span> - <span class="Ldt-Annotation-End"></span> )</span></h3>'
     + '<h3 class="Ldt-Annotation-MashupOrigin Ldt-Annotation-HiddenWhenEmpty">{{l10n.excerpt_from}} <span class="Ldt-Annotation-MashupMedia"></span> <span class="Ldt-Annotation-Time">'
--- a/src/widgets/AnnotationsList.js	Thu Jul 05 19:08:13 2012 +0200
+++ b/src/widgets/AnnotationsList.js	Fri Jul 06 18:13:32 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}}
      */
@@ -199,7 +199,7 @@
                     }
                     var _bgcolor;
                     IriSP._(_this.polemics).each(function(_polemic) {
-                        var _rgxp = IriSP.Model.regexpFromTextOrArray(_polemic.keyword);
+                        var _rgxp = IriSP.Model.regexpFromTextOrArray(_polemic.keyword, true);
                         if (_rgxp.test(_title + " " + _description)) {
                             _bgcolor = _polemic.background_color;
                         }
@@ -238,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>'))
--- a/src/widgets/CreateAnnotation.js	Thu Jul 05 19:08:13 2012 +0200
+++ b/src/widgets/CreateAnnotation.js	Fri Jul 06 18:13:32 2012 +0200
@@ -41,7 +41,8 @@
     api_serializer: "ldt_annotate",
     api_endpoint_template: "",
     api_method: "PUT",
-    close_widget_timeout: 0
+    after_send_timeout: 0,
+    close_after_send: false,
 }
 
 IriSP.Widgets.CreateAnnotation.prototype.messages = {
@@ -138,7 +139,9 @@
     }
     this.renderTemplate();
     this.$.find(".Ldt-CreateAnnotation-Close").click(function() {
-        _this.hide();
+        _this.close_after_send
+        ? _this.hide()
+        : _this.showScreen("Main");
         return false;
     });
     this.$.find(".Ldt-CreateAnnotation-TagLi, .Ldt-CreateAnnotation-PolemicLi").click(function() {
@@ -222,7 +225,7 @@
     var _field = this.$.find(".Ldt-CreateAnnotation-Description"),
         _rx = IriSP.Model.regexpFromTextOrArray(_keyword),
         _contents = _field.val();
-    _contents = ( _rx.test(_contents)
+    _contents = ( !!_contents.match(_rx)
         ? _contents.replace(_rx,"")
         : _contents + " " + _keyword
     );
@@ -242,7 +245,7 @@
     _field.css("border-color", !!_contents ? "#666666" : "#ff0000");
     this.$.find(".Ldt-CreateAnnotation-TagLi, .Ldt-CreateAnnotation-PolemicLi").each(function() {
         var _rx = IriSP.Model.regexpFromTextOrArray(IriSP.jQuery(this).text().replace(/(^\s+|\s+$)/g,''));
-        if (_rx.test(_contents)) {
+        if (_contents.match(_rx)) {
             IriSP.jQuery(this).addClass("selected");
         } else {
             IriSP.jQuery(this).removeClass("selected");
@@ -314,8 +317,15 @@
         data: _export.serialize(),
         success: function(_data) {
             _this.showScreen('Saved');
-            if (_this.close_widget_timeout) {
-                window.setTimeout(_this.functionWrapper("hide"),_this.close_widget_timeout);
+            if (_this.after_send_timeout) {
+                window.setTimeout(
+                    function() {
+                        _this.close_after_send
+                        ? _this.hide()
+                        : _this.showScreen("Main");
+                    },
+                    _this.after_send_timeout
+                );
             }
             _export.getAnnotations().removeElement(_annotation, true);
             _export.deSerialize(_data);
@@ -332,7 +342,7 @@
             window.setTimeout(function(){
                 _this.showScreen("Main")
             },
-            (_this.close_widget_timeout || 5000));
+            (_this.after_send_timeout || 5000));
         }
     });
     this.showScreen('Wait');
--- a/src/widgets/Polemic.js	Thu Jul 05 19:08:13 2012 +0200
+++ b/src/widgets/Polemic.js	Fri Jul 06 18:13:32 2012 +0200
@@ -46,7 +46,7 @@
 IriSP.Widgets.Polemic.prototype.onSearch = function(searchString) {
     this.searchString = typeof searchString !== "undefined" ? searchString : '';
     var _found = 0,
-        _re = IriSP.Model.regexpFromTextOrArray(searchString),
+        _re = IriSP.Model.regexpFromTextOrArray(searchString, true),
         _this = this;
     this.$tweets.each(function() {
         var _el = IriSP.jQuery(this);
--- a/src/widgets/Segments.js	Thu Jul 05 19:08:13 2012 +0200
+++ b/src/widgets/Segments.js	Fri Jul 06 18:13:32 2012 +0200
@@ -74,7 +74,7 @@
 IriSP.Widgets.Segments.prototype.onSearch = function(searchString) {
     this.searchString = typeof searchString !== "undefined" ? searchString : '';
     var _found = 0,
-        _re = IriSP.Model.regexpFromTextOrArray(searchString);
+        _re = IriSP.Model.regexpFromTextOrArray(searchString, true);
     if (this.searchString) {
         this.$segments.each(function() {
             var _el = IriSP.jQuery(this);
--- a/test/jwplayer.htm	Thu Jul 05 19:08:13 2012 +0200
+++ b/test/jwplayer.htm	Fri Jul 06 18:13:32 2012 +0200
@@ -55,7 +55,8 @@
                 },
                 {
                     type: "AnnotationsList",
-                    container: "AnnotationsListContainer"
+                    container: "AnnotationsListContainer",
+                    default_thumbnail : "http://ldt.iri.centrepompidou.fr/static/site/ldt/css/imgs/video_sequence.png"
                 },
                 { type: "Mediafragment"}
             ]