timeline/js/timeline.js
changeset 91 5b770cf1a6e3
parent 90 50e3c4ba168a
child 92 8e017d512ef5
--- a/timeline/js/timeline.js	Tue Aug 13 16:46:38 2013 +0200
+++ b/timeline/js/timeline.js	Tue Aug 13 17:25:20 2013 +0200
@@ -180,7 +180,9 @@
 Tlns.Templates.Univers = '<div class="Tl-UniversText">{{title}}</div>';
 
 Tlns.Templates.Occurrence =
-    '{{#occurrences}}<div class="Tl-Occurrence Tl-OccOnGrid Tl-Occ{{type}} Tl-Occ{{status}}" occurrence-id="{{id}}" style="left: {{x}}px; top: {{y}}px;"></div>{{/occurrences}}';
+    '{{#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;">'
+    + '{{#image}}<img src="{{image}}" />{{/image}}'
+    + '</div>{{/occurrences}}';
 
 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>'
@@ -451,11 +453,11 @@
         _occ.y = _occ.univers.y;
     });
     var _visible = _(this.occurrences).filter(function(_occ) {
-        return (_occ.date >= _this.start_time && _occ.date <= _this.end_time && _occ.status);
+        return (_occ.date >= _this.start_time && _occ.date <= _this.end_time  && _occ.status);
     });
     
     var _moved = true, l = 0;
-    while (_moved && l < 200) {
+    while (_moved && l < 10) {
         l++;
         _moved = false;
         for (var _i = 0; _i < _visible.length; _i++) {
@@ -465,7 +467,7 @@
                     && delta < this.grid_spacing
                 ) {
                     var sign = _visible[_i].x < _visible[_j].x ? 1 : -1,
-                        add = sign * (this.cluster_spacing - delta) / 2;
+                        add = sign * (this.grid_spacing - delta) / 2;
                     _moved = true;
                     _visible[_i].x -= add;
                     _visible[_j].x += add;
@@ -501,8 +503,9 @@
         if (typeof _id !== "undefined") {
             var _occurrence = _this.getOccurrence(_id);
             if (!_this.is_dragging) {
-                var _html = Mustache.to_html(Tlns.Templates.OccurrenceTooltip, _occurrence);
-                _this.showTooltip(_occurrence.x, _occurrence.y, _html, (_event.pageY - _this.dragging_bounds.top) >= (.4 * _this.main_height) );
+                var _html = Mustache.to_html(Tlns.Templates.OccurrenceTooltip, _occurrence),
+                    isup = (_event.pageY - _this.dragging_bounds.top) >= (.4 * _this.main_height);
+                _this.showTooltip(_occurrence.x + 42, _occurrence.y + (isup ? 10 : 20), _html,  isup);
             }
         }
     }).mouseout(function() {
@@ -557,7 +560,7 @@
     this.date = new Date(1000 * (_data.dateFirstPublication || _data.dateCreate) || Date.now);
     this.formatted_date = Tlns.Utils.dateFormat(this.date,Tlns.Defaults.Timeline.tooltip_date_format);
     this.title = _data.title;
-    this.univers_id = this.timeline.univers[0].id;
+    this.univers_id = this.timeline.univers[Math.floor(Math.random() * this.timeline.univers.length)].id;
     this.univers = this.timeline.getUnivers(this.univers_id);
     this.type = "publication";
     if (typeof _data.statut !== "undefined" || typeof this.status === "undefined") {
@@ -579,6 +582,10 @@
     if (typeof _data.typeOccurrencePublication !== "undefined" || typeof this.format === "undefined") {
         this.format = _data.typeOccurrencePublication || 'Format non défini';
     }
+    console.log(_data, _data.contentHasMedias);
+    if (_data.contentHasMedias && _data.contentHasMedias.length) {
+        this.image = _data.contentHasMedias[0].media.cinema.replace(/cinema\/[\d]+\/[\d]+/,'cinema/85/38');
+    }
     this.translated_status = Tlns.Defaults.Timeline.statuses[this.status];
 //    this.published = (_data.publication && _data.publication == "En ligne");
 //    this.locked = _data.verrouille || false;