timeline/js/timeline.js
changeset 83 f8b1d6f5bb33
parent 82 f00eb382bff1
child 84 2448fdcef656
--- a/timeline/js/timeline.js	Thu Jul 19 17:30:02 2012 +0200
+++ b/timeline/js/timeline.js	Fri Jul 20 16:37:23 2012 +0200
@@ -134,6 +134,21 @@
     }
 }
 
+Tlns.Utils.clickActiveProcess = function(_el) {
+    if (_el.hasClass("Ls-Active")) {
+        if (!_el.siblings(":not(.Ls-Active)").length) {
+            _el.siblings().removeClass("Ls-Active");
+        } else {
+            if (!_el.siblings(".Ls-Active").length) {
+                _el.siblings().addClass("Ls-Active");
+            }
+            _el.removeClass("Ls-Active");
+        }
+    } else {
+        _el.addClass("Ls-Active");
+    }
+}
+
 /* Defaults */
 
 Tlns.Defaults.Timeline = {
@@ -217,30 +232,32 @@
     + '<li><span>De Publication</span><div class="Tl-AddOccurrence Tl-Occpublication" occurrence-type="publication" title="Glisser sur la frise chronologique pour ajouter"></div></li></ul></div>'
     + '<div class="Tl-Overlay-Container"><div class="Tl-Overlay-Box"><div class="Tl-Overlay"><div class="Tl-Overlay-Tip-Top"></div><div class="Tl-Overlay-Main"></div><div class="Tl-Overlay-Tip-Bottom"></div></div></div></div></div></div>'
     
-    +'<div class="Ls-Main"><div class="Ls-Filtres"><h2>Filtres&nbsp;:</h2>'
-    + '<div class="Ls-Column"><h3>Univers&nbsp;:</h3><ul class="Ls-Univers"></ul></div>'
+    +'<div class="Ls-Main"><div class="Ls-Filtres">'
+    + '<div class="Ls-Column"><h2>Filtres&nbsp;:</h2><h3>Univers&nbsp;:</h3><ul class="Ls-Univers"></ul></div>'
     + '<div class="Ls-Column"><h3>Type d\'occurrence&nbsp;:</h3><ul class="Ls-Occtypes"><li data="narrative" class="Ls-Critere Ls-Active Ls-CrWithIcon"><div class="Ls-OccIcon Tl-Occnarrative"></div>Narratives</li><li data="publication" class="Ls-Critere Ls-Active Ls-CrWithIcon"><div class="Ls-OccIcon Tl-Occpublication"></div>de Publication</li></ul>'
-    + '<h3>Statut&nbsp;:</h3><ul class="Ls-Occstatuses"><li data="a_realiser" class="Ls-Critere Ls-Active Ls-CrWithIcon"><div class="Ls-OccIcon Tl-Occpublication Tl-Occa_realiser"></div>À réaliser</li><li data="a_valider" class="Ls-Critere Ls-Active Ls-CrWithIcon"><div class="Ls-OccIcon Tl-Occpublication Tl-Occa_valider"></div>À valider</li><li data="valide" class="Ls-Critere Ls-Active Ls-CrWithIcon"><div class="Ls-OccIcon Tl-Occpublication Tl-Occvalide"></div>Validé</li></ul>'
-    + '<h3>Est au JT&nbsp;:</h3><ul class="Ls-IsJt"><li class="Ls-Critere Ls-Active" data="1">Oui</li><li class="Ls-Critere Ls-Active" data="0">Non</li></ul></div>'
-    + '<div class="Ls-Column"><h3>Recherche par titre&nbsp;:</h3><p><input class="Ls-Search" type="search" placeholder="Rechercher" /></p><h3>Date&nbsp;:</h3><p><label class="Ls-Label">Du </label><input class="Ls-From-Date Ls-Input" /></p><p><label class="Ls-Label">à </label><input class="Ls-From-Time Ls-Input" /></p><p><label class="Ls-Label">Au </label><input class="Ls-To-Date Ls-Input" /></p><p><label class="Ls-Label">à </label><input class="Ls-To-Time Ls-Input" /></p></div>'
+    + '<h3>Statut&nbsp;:</h3><ul class="Ls-Occstatuses"><li data="a_realiser" class="Ls-Critere Ls-Active Ls-CrWithIcon"><div class="Ls-OccIcon Tl-Occpublication Tl-Occa_realiser"></div>À réaliser</li><li data="a_valider" class="Ls-Critere Ls-Active Ls-CrWithIcon"><div class="Ls-OccIcon Tl-Occpublication Tl-Occa_valider"></div>À valider</li><li data="valide" class="Ls-Critere Ls-Active Ls-CrWithIcon"><div class="Ls-OccIcon Tl-Occpublication Tl-Occvalide"></div>Validé</li></ul></div>'
+    + '<div class="Ls-Column"><h3>Format&nbsp;:</h3><ul class="Ls-Formats"></ul><h3>Est au JT&nbsp;:</h3><ul class="Ls-IsJt"><li class="Ls-Critere Ls-Active" data="1">Oui</li><li class="Ls-Critere Ls-Active" data="0">Non</li></ul></div>'
+    + '<div class="Ls-Column"><h3>Réinitialiser filtres&nbsp;:</h3><ul><li class="Ls-Critere Ls-Active Ls-All">Tous les contenus</li></ul><h3>Recherche par titre&nbsp;:</h3><p><input class="Ls-Search" type="search" placeholder="Rechercher" /></p><h3>Date&nbsp;:</h3><p><label class="Ls-Label">Du </label><input class="Ls-From-Date Ls-Input" /></p><p><label class="Ls-Label">à </label><input class="Ls-From-Time Ls-Input" /></p><p><label class="Ls-Label">Au </label><input class="Ls-To-Date Ls-Input" /></p><p><label class="Ls-Label">à </label><input class="Ls-To-Time Ls-Input" /></p></div>'
     + '</div><div class="Ls-Resultats"><h2>Occurrences&nbsp;:</h2><ul class="Ls-Occurrences"></ul></div></div>';
 
 Tlns.Templates.Univers = '<span class="Tl-UniversText">{{title}}</span>';
 
 Tlns.Templates.Univers_List = '{{#univers}}<li data="{{id}}" class="Ls-Critere Ls-Active">{{title}}</li>{{/univers}}';
 
+Tlns.Templates.Formats_List = '{{#formats}}<li class="Ls-Critere Ls-Active">{{.}}</li>{{/formats}}';
+
 Tlns.Templates.Occurrence = '{{#clusters}}<div class="Tl-Cluster" style="left: {{x}}px; top: {{y}}px;" cluster-contents="{{contents}}">'
     + '<div class="Tl-ClusterCount">{{occurrences.length}}</div></div>{{/clusters}}'
     + '{{#occurrences}}<div class="Tl-Occurrence Tl-OccOnGrid Tl-Occ{{type}} Tl-Occ{{status}}{{#editing}} Tl-Editing{{/editing}}" occurrence-id="{{id}}" style="left: {{x}}px; top: {{y}}px;">'
 //  + '{{#locked}}<div class="Tl-Locked"></div>{{/locked}}'
-    + '<div class="Tl-Link"{{#editing}} style="display: block"{{/editing}}></div></div>{{/occurrences}}{{#open_cluster}}<div class="Tl-ClusterOverlay" style="left: {{x}}px; top: {{y}}px;">'
+    + '<div class="Tl-Link"></div></div>{{/occurrences}}{{#open_cluster}}<div class="Tl-ClusterOverlay" style="left: {{x}}px; top: {{y}}px;">'
     + '{{#occurrences}}<div class="Tl-Occurrence Tl-OccInCluster Tl-Occ{{type}} Tl-Occ{{status}}{{#editing}} Tl-Editing{{/editing}}" occurrence-id="{{id}}">'
     + '{{#locked}}<div class="Tl-Locked"></div>{{/locked}}<div class="Tl-Link"{{#editing}} style="display: block"{{/editing}}></div></div>{{/occurrences}}</div>{{/open_cluster}}';
 
 Tlns.Templates.Occurrence_List = '{{#occurrences}}<li class="Ls-Occurrence" data-id="{{id}}"><div class="Ls-OccIcon Tl-Occ{{type}} Tl-Occ{{status}}"></div><h4 class="Ls-Occurrence-Title"><a href="#">{{title}}</a></h4>'
-    + '<p class="Ls-Occ-More">{{formatted_date}} &mdash; {{univers.title}} &mdash; {{translated_status}} &mdash; {{#jt}}Au JT{{/jt}}{{^jt}}Hors JT{{/jt}}</p><div style="clear:both;"></div></li>{{/occurrences}}';
+    + '<p class="Ls-Occ-More">{{formatted_date}} &mdash; {{univers.title}} &mdash; {{translated_status}} &mdash; {{#jt}}Au JT{{/jt}}{{^jt}}Hors JT{{/jt}}{{#format}} &mdash; {{format}}{{/format}}</p><div style="clear:both;"></div></li>{{/occurrences}}';
 
-Tlns.Templates.OccurrenceTooltip = '<h3 class="Tl-Tooltip-Title">{{title}}</h3><p class="Tl-Tooltip-Date">{{formatted_date}} &mdash; {{translated_status}}</p>'
+Tlns.Templates.OccurrenceTooltip = '<h3 class="Tl-Tooltip-Title">{{title}}</h3><p class="Tl-Tooltip-Date">{{formatted_date}} &mdash; {{translated_status}} &mdash; {{#jt}}Au JT{{/jt}}{{^jt}}Hors JT{{/jt}}{{#format}} &mdash; {{format}}{{/format}}</p>'
     + '<p class="Tl-Tooltip-Description">{{description}}</p>'
 //    + '<p class="Tl-Tooltip-Characters">{{univers.mainCharacter}}{{#characters}}, {{.}}{{/characters}}</p>'
 
@@ -360,6 +377,9 @@
                 }
             );
         _occ.just_created = true;
+        _(_this.occurrences).each(function(_occ) {
+            _occ.editing = false;
+        });
         _occ.editing = true;
         _this.editing_occurrence = _occ;
         _this.dragging_type = "occurrence";
@@ -381,7 +401,7 @@
     /* LIST */
     
     this.$.find("li.Ls-Critere").click(function() {
-        $(this).toggleClass("Ls-Active");
+        Tlns.Utils.clickActiveProcess($(this));
         _this.throttledDrawList();
     });
     this.$.find(".Ls-Search").bind("keyup change click", function() {
@@ -416,6 +436,14 @@
     }).bind("keyup", function() {
         _this.throttledDrawList();
     });
+    this.$.find(".Ls-All").click(function() {
+       _this.$.find(".Ls-Critere").addClass("Ls-Active");
+       _this.throttledDrawList();
+    });
+    this.$.find(".Ls-None").click(function() {
+       _this.$.find(".Ls-Critere").removeClass("Ls-Active");
+       _this.throttledDrawList();
+    });
     
     this.$.find(".Onglet-Tl").click(function() {
         _this.$.find(".Tl-Main").show();
@@ -464,6 +492,14 @@
         _this.throttledDrawGrid();
     });
     
+    $("body").bind("SelectionOccurrenceEditeur", function(_event, _data) {
+        var _id = _data.typeOccurrence.replace(/^Occurrence/i,'').toLowerCase() + '_' + _data.id;
+        _(_this.occurrences).each(function(_occ) {
+            _occ.editing = (_occ.id == _id);
+        });
+        _this.throttledDrawGrid();
+    })
+    
     
 }
 
@@ -495,12 +531,10 @@
                         JT: +!!this.editing_occurrence.jt
                     }
                 $("body").trigger(_event, _data);
-                this.editing_occurrence.editing = false;
                 this.editing_occurrence.just_created = false;
                 this.throttledDrawGrid();
             break;
             case "link":
-                this.editing_occurrence.editing = false;
                 this.throttledDrawGrid();
                 var _ctx = this.$.find('.Tl-Linking-Canvas')[0].getContext('2d');
                 _ctx.clearRect(0,0,this.main_width, this.main_height);
@@ -513,13 +547,14 @@
                 this.throttledDrawGrid();
             } else {
                 var _data = {
-                    id: this.editing_occurrence.original_id,
-                    typeOccurrence: "Occurrence" + this.editing_occurrence.type.replace(/^./,function(_l) { return _l.toUpperCase()})
-                }
+                        id: this.editing_occurrence.original_id,
+                        typeOccurrence: "Occurrence" + this.editing_occurrence.type.replace(/^./,function(_l) { return _l.toUpperCase()})
+                    }
                 $("body").trigger("SelectionOccurrenceTimeline", _data);
             }
-        }
+        } 
     }
+    this.$.find('.Tl-Link').hide();
     this.mouse_down = false;
     this.is_dragging = false;
     this.dragging_type = undefined;
@@ -583,10 +618,22 @@
         this.univers.push(new Tlns.Classes.Univers(_data[_i], this, _i));
     }
     
-    this.$.find(".Ls-Univers").html(Mustache.to_html(Tlns.Templates.Univers_List, this));
+    this.$.find(".Ls-Univers").html(
+        Mustache.to_html(
+            Tlns.Templates.Univers_List,
+            {
+                univers: _(this.univers).map(function(_u) {
+                    return {
+                        id: _u.id,
+                        title: _u.title.replace(/(^.{10,20})[\s].+$/m,'$1&hellip;')
+                    }
+                })
+            }
+        )
+    );
     var _this = this;
     this.$.find(".Ls-Univers li.Ls-Critere").click( function() {
-        $(this).toggleClass("Ls-Active");
+        Tlns.Utils.clickActiveProcess($(this));
         _this.throttledDrawList();
     });
     this.loadOccurrences();
@@ -678,6 +725,19 @@
     if (!this.mouse_down) {
         this.drawOccurrences();
     }
+    this.$.find(".Ls-Formats").html(
+        Mustache.to_html(
+            Tlns.Templates.Formats_List,
+            {
+                formats: _(this.occurrences).chain().pluck('format').unique().value()
+            }
+        )
+    );
+    var _this = this;
+    this.$.find(".Ls-Formats li.Ls-Critere").click( function() {
+        Tlns.Utils.clickActiveProcess($(this));
+        _this.throttledDrawList();
+    });
     this.throttledDrawList();
 }
 
@@ -839,8 +899,14 @@
             _this.editing_occurrence = _this.getOccurrence(_id);
             if (typeof _this.dragging_type === "undefined" && typeof _this.editing_occurrence !== "undefined" /* && !_this.editing_occurrence.locked */ ) {
                 _this.dragging_type = "occurrence";
+            }
+            if (!_this.editing_occurrence.editing) {
+                _(_this.occurrences).each(function(_occ) {
+                    _occ.editing = false;
+                });
                 _this.editing_occurrence.editing = true;
             }
+            _this.throttledDrawGrid();
         }
     }).mouseover(function(_event) {
         var _el = $(this),
@@ -861,9 +927,7 @@
         if (typeof _id !== "undefined") {
             var _occurrence = _this.getOccurrence(_id);
             _this.hideTooltip();
-            if (!_occurrence.editing) {
-                $(this).find('.Tl-Link').hide();
-            }
+            _this.$.find('.Tl-Link').hide();
         }
     }).mouseup(function() {
         var _el = $(this);
@@ -889,7 +953,6 @@
         _this.editing_occurrence = _this.getOccurrence(_id);
         if (typeof _this.editing_occurrence !== "undefined" /* && !_this.editing_occurrence.locked */ ) {
             _this.dragging_type = "link";
-            _this.editing_occurrence.editing = true;
         }
     })
     
@@ -908,6 +971,7 @@
 Tlns.Classes.Timeline.prototype.drawList = function() {
     var _universfilter = this.$.find(".Ls-Univers li.Ls-Active").map(function(){return $(this).attr("data")}),
         _occtypefilter = this.$.find(".Ls-Occtypes li.Ls-Active").map(function(){return $(this).attr("data")}),
+        _formatsfilter = this.$.find(".Ls-Formats li.Ls-Active").map(function(){return $(this).text()}),
         _statusfilter = this.$.find(".Ls-Occstatuses li.Ls-Active").map(function(){return $(this).attr("data")}),
         _jtfilter = this.$.find(".Ls-IsJt li.Ls-Active").map(function(){return !!+$(this).attr("data")}),
         _title = this.$.find(".Ls-Search").val() || "",
@@ -934,10 +998,11 @@
                     var _titletest = (!!_occ.title.match(_titleregexp)),
                         _keep = (
                                ( !_title || _titletest )
-                            && (_(_occtypefilter).indexOf(_occ.type) !== -1)
-                            && (_(_universfilter).indexOf(_occ.univers_id) !== -1)
-                            && (_(_statusfilter).indexOf(_occ.status) !== -1)
-                            && (_(_jtfilter).indexOf(_occ.jt) !== -1)
+                            && _(_occtypefilter).include(_occ.type)
+                            && _(_universfilter).include(_occ.univers_id)
+                            && _(_statusfilter).include(_occ.status)
+                            && _(_formatsfilter).include(_occ.format)
+                            && _(_jtfilter).include(_occ.jt)
                             && ( !_fromDate || _occ.date >= _startdate )
                             && ( !_toDate || _occ.date <= _enddate )
                         );
@@ -1040,6 +1105,9 @@
                 this.status = false;
         }
     }
+    if (typeof _data.typeOccurrencePublication !== "undefined" || typeof this.format === "undefined") {
+        this.format = _data.typeOccurrencePublication || 'Format non défini';
+    }
     if (typeof _data.JT !== "undefined") {
         this.jt = !!+_data.JT;
     }
@@ -1059,7 +1127,7 @@
         }
     }
     var _tmp = $('<p>').html(_data.accroche || "");
-    this.description = _tmp.text().trim().replace(/(^.{60,80})[\s].+$/m,'$1&hellip;');
+    this.description = _tmp.text().trim().replace(/(\n|\r|\r\n)/mg,' ').replace(/(^.{60,80})[\s].+$/m,'$1&hellip;');
 }
 
 Tlns.Classes.Occurrence.prototype.addDependency = function(_id) {