60 |
60 |
61 Tlns.Utils.guid = function() { |
61 Tlns.Utils.guid = function() { |
62 return 'xxxx-xxxx-xxxx-xxxx'.replace(/x/g,function() { |
62 return 'xxxx-xxxx-xxxx-xxxx'.replace(/x/g,function() { |
63 return Math.floor(Math.random()*16).toString(16); |
63 return Math.floor(Math.random()*16).toString(16); |
64 }); |
64 }); |
65 } |
|
66 |
|
67 Tlns.Utils.drawArrow = function(_ctx, _color, _x1, _y1, _x2, _y2) { |
|
68 _ctx.strokeStyle = _color; |
|
69 _ctx.fillStyle = _color; |
|
70 _ctx.beginPath(); |
|
71 _ctx.moveTo(_x1,_y1); |
|
72 _ctx.lineTo(_x2,_y2); |
|
73 _ctx.stroke(); |
|
74 var _mod = Math.sqrt(Math.pow(_x2 - _x1, 2) + Math.pow(_y2 - _y1, 2)), |
|
75 _xu = (_x2 - _x1) / _mod, |
|
76 _yu = (_y2 - _y1) / _mod, |
|
77 _xm = (_x1 + _x2) / 2, |
|
78 _ym = (_y1 + _y2) / 2, |
|
79 _arrowWidth = 4, |
|
80 _arrowLength = 8, |
|
81 _x3 = _xm - _arrowLength * _xu + _arrowWidth * _yu, |
|
82 _y3 = _ym - _arrowLength * _yu - _arrowWidth * _xu, |
|
83 _x4 = _xm - _arrowLength * _xu - _arrowWidth * _yu, |
|
84 _y4 = _ym - _arrowLength * _yu + _arrowWidth * _xu; |
|
85 _ctx.beginPath(); |
|
86 _ctx.moveTo(_x3, _y3); |
|
87 _ctx.lineTo(_xm, _ym); |
|
88 _ctx.lineTo(_x4, _y4); |
|
89 _ctx.fill(); |
|
90 _ctx.stroke(); |
|
91 } |
65 } |
92 |
66 |
93 Tlns.Utils.timeFieldProcess = function(_val) { |
67 Tlns.Utils.timeFieldProcess = function(_val) { |
94 var _h = 0, |
68 var _h = 0, |
95 _m = 0, |
69 _m = 0, |
220 Tlns.Defaults.Timeline.timescales[_i].level = _i; |
194 Tlns.Defaults.Timeline.timescales[_i].level = _i; |
221 } |
195 } |
222 |
196 |
223 /* Templates */ |
197 /* Templates */ |
224 |
198 |
225 Tlns.Templates.Timeline = '<ul class="Onglets"><li class="Onglet-Tl active">Frise chronologique</li><li class="Onglet-Ls">Liste des occurrences</li></ul><div class="Tl-Main"><div class="Tl-TopBar"><div class="Tl-TopBar-Button Tl-Border-Right"><div class="Tl-TopBar-AddButton"></div></div><div class="Tl-TopBar-Spacer Tl-Border-Right"></div>' |
199 Tlns.Templates.Timeline = '<ul class="Onglets"><li class="Onglet-Tl active">Frise chronologique</li><li class="Onglet-Ls">Liste des occurrences</li></ul><div class="Tl-Main"><div class="Tl-TopBar">' |
226 + '<div class="Tl-TopBar-Button Tl-Border-Right"><div class="Tl-TopBar-PreviousButton"></div></div><div class="Tl-TopBar-TimeSpan Tl-TopBar-TextBtn Tl-Border-Right">--/--</div>' |
200 + '<div class="Tl-TopBar-Button Tl-Border-Right"><div class="Tl-TopBar-PreviousButton"></div></div><div class="Tl-TopBar-TimeSpan Tl-TopBar-TextBtn Tl-Border-Right">--/--</div>' |
227 + '<div class="Tl-TopBar-Button Tl-Border-Right"><div class="Tl-TopBar-SyncButton"></div></div><div class="Tl-TopBar-Button Tl-Border-Right"><div class="Tl-TopBar-NextButton"></div></div><div class="Tl-TopBar-Spacer Tl-Border-Right"></div>' |
201 + '<div class="Tl-TopBar-Button Tl-Border-Right"><div class="Tl-TopBar-SyncButton"></div></div><div class="Tl-TopBar-Button Tl-Border-Right"><div class="Tl-TopBar-NextButton"></div></div><div class="Tl-TopBar-Spacer Tl-Border-Right"></div>' |
228 + '<div class="Tl-TopBar-Timescales">{{#timescales}}<div class="Tl-TopBar-Button Tl-TopBar-TextBtn Tl-Border-Right" data-level="{{level}}">{{label}}</div>{{/timescales}}</div></div>' |
202 + '<div class="Tl-TopBar-Timescales">{{#timescales}}<div class="Tl-TopBar-Button Tl-TopBar-TextBtn Tl-Border-Right" data-level="{{level}}">{{label}}</div>{{/timescales}}</div></div>' |
229 + '<div class="Tl-BottomPart"><ul class="Tl-UniversLabels"></ul>' |
203 + '<div class="Tl-BottomPart"><ul class="Tl-UniversLabels"></ul>' |
230 + '<div class="Tl-MainPart"><div class="Tl-Layer Tl-Grid"></div><canvas class="Tl-Layer Tl-Canvas"></canvas><canvas class="Tl-Layer Tl-Linking-Canvas"></canvas><div class="Tl-Layer Tl-Occurrences"></div>' |
204 + '<div class="Tl-MainPart"><div class="Tl-Layer Tl-Grid"></div><canvas class="Tl-Layer Tl-Canvas"></canvas><div class="Tl-Layer Tl-Occurrences"></div>' |
231 + '<ul class="Tl-Adding"><li class="Tl-AddingTitle">Ajout d\'une occurrence</li><li><span>Narrative</span><div class="Tl-AddOccurrence Tl-Occnarrative" occurrence-type="narrative" title="Glisser sur la frise chronologique pour ajouter"></div></li>' |
205 + '</div>' |
232 + '<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>' |
|
233 + '<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>' |
206 + '<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>' |
234 |
207 |
235 +'<div class="Ls-Main"><div class="Ls-Filtres">' |
208 +'<div class="Ls-Main"><div class="Ls-Filtres">' |
236 + '<div class="Ls-Column"><h2>Filtres :</h2><h3>Univers :</h3><ul class="Ls-Univers"></ul></div>' |
209 + '<div class="Ls-Column"><h2>Filtres :</h2><h3>Univers :</h3><ul class="Ls-Univers"></ul></div>' |
237 + '<div class="Ls-Column"><h3>Type d\'occurrence :</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>' |
210 + '<div class="Ls-Column"><h3>Type d\'occurrence :</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>' |
248 |
221 |
249 Tlns.Templates.Occurrence = '{{#clusters}}<div class="Tl-Cluster" style="left: {{x}}px; top: {{y}}px;" cluster-contents="{{contents}}">' |
222 Tlns.Templates.Occurrence = '{{#clusters}}<div class="Tl-Cluster" style="left: {{x}}px; top: {{y}}px;" cluster-contents="{{contents}}">' |
250 + '<div class="Tl-ClusterCount">{{occurrences.length}}</div></div>{{/clusters}}' |
223 + '<div class="Tl-ClusterCount">{{occurrences.length}}</div></div>{{/clusters}}' |
251 + '{{#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;">' |
224 + '{{#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;">' |
252 // + '{{#locked}}<div class="Tl-Locked"></div>{{/locked}}' |
225 // + '{{#locked}}<div class="Tl-Locked"></div>{{/locked}}' |
253 + '<div class="Tl-Link"></div></div>{{/occurrences}}{{#open_cluster}}<div class="Tl-ClusterOverlay" style="left: {{x}}px; top: {{y}}px;">' |
226 + '</div>{{/occurrences}}{{#open_cluster}}<div class="Tl-ClusterOverlay" style="left: {{x}}px; top: {{y}}px;">' |
254 + '{{#occurrences}}<div class="Tl-Occurrence Tl-OccInCluster Tl-Occ{{type}} Tl-Occ{{status}}{{#editing}} Tl-Editing{{/editing}}" occurrence-id="{{id}}">' |
227 + '{{#occurrences}}<div class="Tl-Occurrence Tl-OccInCluster Tl-Occ{{type}} Tl-Occ{{status}}{{#editing}} Tl-Editing{{/editing}}" occurrence-id="{{id}}">' |
255 + '{{#locked}}<div class="Tl-Locked"></div>{{/locked}}<div class="Tl-Link"{{#editing}} style="display: block"{{/editing}}></div></div>{{/occurrences}}</div>{{/open_cluster}}'; |
228 + '{{#locked}}<div class="Tl-Locked"></div>{{/locked}}</div>{{/occurrences}}</div>{{/open_cluster}}'; |
256 |
229 |
257 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>' |
230 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>' |
258 + '<p class="Ls-Occ-More">{{formatted_date}} — {{univers.title}} — {{translated_status}} — {{#jt}}Au JT{{/jt}}{{^jt}}Hors JT{{/jt}}{{#format}} — {{format}}{{/format}}</p><div style="clear:both;"></div></li>{{/occurrences}}'; |
231 + '<p class="Ls-Occ-More">{{formatted_date}} — {{univers.title}} — {{translated_status}} — {{#jt}}Au JT{{/jt}}{{^jt}}Hors JT{{/jt}}{{#format}} — {{format}}{{/format}}</p><div style="clear:both;"></div></li>{{/occurrences}}'; |
259 |
232 |
260 Tlns.Templates.OccurrenceTooltip = '<h3 class="Tl-Tooltip-Title">{{title}}</h3><p class="Tl-Tooltip-Date">{{formatted_date}} — {{translated_status}} — {{#jt}}Au JT{{/jt}}{{^jt}}Hors JT{{/jt}}{{#format}} — {{format}}{{/format}}</p>' |
233 Tlns.Templates.OccurrenceTooltip = '<h3 class="Tl-Tooltip-Title">{{title}}</h3><p class="Tl-Tooltip-Date">{{formatted_date}} — {{translated_status}} — {{#jt}}Au JT{{/jt}}{{^jt}}Hors JT{{/jt}}{{#format}} — {{format}}{{/format}}</p>' |
357 this.$.find('.Tl-Overlay-Box').mouseover(function(_event) { |
326 this.$.find('.Tl-Overlay-Box').mouseover(function(_event) { |
358 $(this).show(); |
327 $(this).show(); |
359 }).mouseout(function(_event) { |
328 }).mouseout(function(_event) { |
360 $(this).hide(); |
329 $(this).hide(); |
361 }); |
330 }); |
362 |
331 |
363 this.$.find('.Tl-TopBar-AddButton').click(function() { |
|
364 $(this).toggleClass('active'); |
|
365 _this.$.find('.Tl-Adding').toggle(); |
|
366 }); |
|
367 |
|
368 this.$.find('.Tl-AddOccurrence').mousedown(function(_event) { |
|
369 var _el = $(this), |
|
370 _type = _el.attr("occurrence-type"), |
|
371 _d = _this.timeFromMouse(_event.pageX), |
|
372 _u = _this.universFromMouse(_event.pageY), |
|
373 _occ = _this.createOrUpdateOccurrence( |
|
374 _type, |
|
375 { |
|
376 datePublication: Math.floor(_d / 1000), |
|
377 titre: '<Nouvelle occurrence>', |
|
378 idUnivers: _this.univers[_u].id, |
|
379 statut: 'a_realiser', |
|
380 jt: false |
|
381 } |
|
382 ); |
|
383 _occ.just_created = true; |
|
384 _(_this.occurrences).each(function(_occ) { |
|
385 _occ.editing = false; |
|
386 }); |
|
387 _occ.editing = true; |
|
388 _this.editing_occurrence = _occ; |
|
389 _this.dragging_type = "occurrence"; |
|
390 window.setTimeout(function () { |
|
391 _this.$.find('.Tl-TopBar-AddButton').removeClass('active'); |
|
392 _this.$.find('.Tl-Adding').hide(); |
|
393 }, 200); |
|
394 _this.throttledDrawGrid(); |
|
395 }).mouseup(function(_event) { |
|
396 _this.onMouseUp(_event); |
|
397 return false; |
|
398 }); |
|
399 |
|
400 /* Loading Univers */ |
332 /* Loading Univers */ |
401 $.getJSON(this.url_univers, function(_data) { |
333 $.getJSON(this.url_univers, function(_data) { |
402 _this.onUniversLoaded(_data); |
334 _this.onUniversLoaded(_data); |
403 }); |
335 }); |
404 |
336 |
462 _this.$.find(".Tl-Main").hide(); |
394 _this.$.find(".Tl-Main").hide(); |
463 _this.$.find(".Onglet-Tl").removeClass("active"); |
395 _this.$.find(".Onglet-Tl").removeClass("active"); |
464 _this.$.find(".Onglet-Ls").addClass("active"); |
396 _this.$.find(".Onglet-Ls").addClass("active"); |
465 _this.throttledDrawList(); |
397 _this.throttledDrawList(); |
466 }); |
398 }); |
467 |
399 |
468 |
|
469 /* BINDING MEDIADATA EVENTS */ |
|
470 |
|
471 $("body").bind("AjoutOccurrenceEditeur MiseAJourOccurrenceEditeur", function(_event, _data) { |
|
472 var _type = _data.typeOccurrence.replace(/^Occurrence/i,'').toLowerCase(); |
|
473 _this.createOrUpdateOccurrence(_type, _data); |
|
474 _this.throttledDrawGrid(); |
|
475 _this.throttledDrawList(); |
|
476 }); |
|
477 |
|
478 $("body").bind("SuppressionOccurrenceEditeur", function(_event, _data) { |
|
479 var _id = _data.typeOccurrence.replace(/^Occurrence/i,'').toLowerCase() + '_' + _data.id; |
|
480 _this.deleteOccurrence(_id); |
|
481 _this.throttledDrawGrid(); |
|
482 _this.throttledDrawList(); |
|
483 }); |
|
484 |
|
485 $("body").bind("AjoutDependanceEditeur", function(_event, _data) { |
|
486 var _sourceId = _data.typeOccurrence.replace(/^Occurrence/i,'').toLowerCase() + '_' + _data.id, |
|
487 _targetId = _data.typeOccurrenceCible.replace(/^Occurrence/i,'').toLowerCase() + '_' + _data.idCible; |
|
488 _this.getOccurrence(_sourceId).addDependency(_targetId); |
|
489 _this.throttledDrawGrid(); |
|
490 }); |
|
491 |
|
492 $("body").bind("SuppressionDependanceEditeur", function(_event, _data) { |
|
493 var _sourceId = _data.typeOccurrence.replace(/^Occurrence/i,'').toLowerCase() + '_' + _data.id, |
|
494 _targetId = _data.typeOccurrenceCible.replace(/^Occurrence/i,'').toLowerCase() + '_' + _data.idCible; |
|
495 _this.getOccurrence(_sourceId).removeDependency(_targetId); |
|
496 _this.throttledDrawGrid(); |
|
497 }); |
|
498 |
|
499 $("body").bind("SelectionOccurrenceEditeur", function(_event, _data) { |
|
500 var _id = _data.typeOccurrence.replace(/^Occurrence/i,'').toLowerCase() + '_' + _data.id; |
|
501 _(_this.occurrences).each(function(_occ) { |
|
502 _occ.editing = (_occ.id == _id); |
|
503 }); |
|
504 _this.throttledDrawGrid(); |
|
505 }) |
|
506 |
|
507 |
400 |
508 } |
401 } |
509 |
402 |
510 Tlns.Classes.Timeline.prototype.onMouseDown = function(_event) { |
403 Tlns.Classes.Timeline.prototype.onMouseDown = function(_event) { |
511 this.mouse_down = true; |
404 this.mouse_down = true; |
519 this.dragging_type = "timeline"; |
412 this.dragging_type = "timeline"; |
520 } |
413 } |
521 } |
414 } |
522 |
415 |
523 Tlns.Classes.Timeline.prototype.onMouseUp = function(_event) { |
416 Tlns.Classes.Timeline.prototype.onMouseUp = function(_event) { |
524 if (this.is_dragging) { |
|
525 switch (this.dragging_type) { |
|
526 case "occurrence": |
|
527 var _event = ( this.editing_occurrence.just_created ? "Ajout" : "MiseAJour" ) + "OccurrenceTimeline", |
|
528 _data = { |
|
529 id: this.editing_occurrence.original_id, |
|
530 typeOccurrence: "Occurrence" + this.editing_occurrence.type.replace(/^./,function(_l) { return _l.toUpperCase()}), |
|
531 datePublication : Math.floor(this.editing_occurrence.date / 1000), |
|
532 titre : this.editing_occurrence.title, |
|
533 idUnivers: this.editing_occurrence.univers_id, |
|
534 statut: this.statuses[this.editing_occurrence.status], |
|
535 JT: +!!this.editing_occurrence.jt |
|
536 } |
|
537 $("body").trigger(_event, _data); |
|
538 this.editing_occurrence.just_created = false; |
|
539 this.throttledDrawGrid(); |
|
540 break; |
|
541 case "link": |
|
542 this.throttledDrawGrid(); |
|
543 var _ctx = this.$.find('.Tl-Linking-Canvas')[0].getContext('2d'); |
|
544 _ctx.clearRect(0,0,this.main_width, this.main_height); |
|
545 break; |
|
546 } |
|
547 } else { |
|
548 if (this.dragging_type == "occurrence" || this.dragging_type == "link") { |
|
549 if (this.editing_occurrence.just_created) { |
|
550 this.deleteOccurrence(this.editing_occurrence.id); |
|
551 this.throttledDrawGrid(); |
|
552 } else { |
|
553 var _data = { |
|
554 id: this.editing_occurrence.original_id, |
|
555 typeOccurrence: "Occurrence" + this.editing_occurrence.type.replace(/^./,function(_l) { return _l.toUpperCase()}) |
|
556 } |
|
557 $("body").trigger("SelectionOccurrenceTimeline", _data); |
|
558 } |
|
559 } |
|
560 } |
|
561 this.$.find('.Tl-Link').hide(); |
|
562 this.mouse_down = false; |
417 this.mouse_down = false; |
563 this.is_dragging = false; |
418 this.is_dragging = false; |
564 this.dragging_type = undefined; |
419 this.dragging_type = undefined; |
565 } |
420 } |
566 |
421 |
590 } |
445 } |
591 } |
446 } |
592 if (this.is_dragging) { |
447 if (this.is_dragging) { |
593 this.hideTooltip(); |
448 this.hideTooltip(); |
594 switch (this.dragging_type) { |
449 switch (this.dragging_type) { |
595 case "occurrence": |
|
596 var _d = this.timeFromMouse(_event.pageX); |
|
597 this.editing_occurrence.date = _d; |
|
598 this.editing_occurrence.formatted_date = Tlns.Utils.dateFormat(this.editing_occurrence.date,this.tooltip_date_format); |
|
599 var _u = this.universFromMouse(_event.pageY); |
|
600 this.editing_occurrence.univers = this.univers[_u]; |
|
601 this.editing_occurrence.univers_id = this.univers[_u].id; |
|
602 this.throttledDrawGrid(); |
|
603 break; |
|
604 case "timeline": |
450 case "timeline": |
605 this.setTime(this.time_at_start + Math.floor(( this.start_pos.x - _event.pageX ) / this.current_scale)); |
451 this.setTime(this.time_at_start + Math.floor(( this.start_pos.x - _event.pageX ) / this.current_scale)); |
606 break; |
|
607 case "link": |
|
608 var _ctx = this.$.find('.Tl-Linking-Canvas')[0].getContext('2d'); |
|
609 _ctx.clearRect(0,0,this.main_width, this.main_height); |
|
610 Tlns.Utils.drawArrow( |
|
611 _ctx, |
|
612 '#800080', |
|
613 this.editing_occurrence.x, |
|
614 this.editing_occurrence.y + Math.floor(this.univers_height / 2), |
|
615 _event.pageX - this.dragging_bounds.left, |
|
616 _event.pageY - this.dragging_bounds.top |
|
617 ); |
|
618 break; |
452 break; |
619 } |
453 } |
620 } |
454 } |
621 } |
455 } |
622 |
456 |
688 this.$.find(".Ls-From-Date").val(Tlns.Utils.dateFormat(this.start_time, '{{0dayOfMonth}}/{{0monthNumber}}/{{year}}')); |
522 this.$.find(".Ls-From-Date").val(Tlns.Utils.dateFormat(this.start_time, '{{0dayOfMonth}}/{{0monthNumber}}/{{year}}')); |
689 this.$.find(".Ls-To-Time").val(Tlns.Utils.dateFormat(this.end_time, '{{0hours}}:{{0minutes}}')); |
523 this.$.find(".Ls-To-Time").val(Tlns.Utils.dateFormat(this.end_time, '{{0hours}}:{{0minutes}}')); |
690 this.$.find(".Ls-To-Date").val(Tlns.Utils.dateFormat(this.end_time, '{{0dayOfMonth}}/{{0monthNumber}}/{{year}}')); |
524 this.$.find(".Ls-To-Date").val(Tlns.Utils.dateFormat(this.end_time, '{{0dayOfMonth}}/{{0monthNumber}}/{{year}}')); |
691 this.throttledDrawGrid(); |
525 this.throttledDrawGrid(); |
692 this.throttledDrawList(); |
526 this.throttledDrawList(); |
693 this.throttledShowEditingLinks(); |
|
694 } |
527 } |
695 |
528 |
696 Tlns.Classes.Timeline.prototype.drawGrid = function() { |
529 Tlns.Classes.Timeline.prototype.drawGrid = function() { |
697 if (this.sync_now) { |
530 if (this.sync_now) { |
698 this.$.find('.Tl-TopBar-SyncButton').addClass("active"); |
531 this.$.find('.Tl-TopBar-SyncButton').addClass("active"); |
899 }).mouseover(function(_event) { |
732 }).mouseover(function(_event) { |
900 var _el = $(this), |
733 var _el = $(this), |
901 _id = _el.attr("occurrence-id"); |
734 _id = _el.attr("occurrence-id"); |
902 if (typeof _id !== "undefined") { |
735 if (typeof _id !== "undefined") { |
903 var _occurrence = _this.getOccurrence(_id); |
736 var _occurrence = _this.getOccurrence(_id); |
904 // if (!_occurrence.locked) { |
|
905 _el.find('.Tl-Link').show(); |
|
906 // } |
|
907 if (!_this.is_dragging) { |
737 if (!_this.is_dragging) { |
908 var _html = Mustache.to_html(Tlns.Templates.OccurrenceTooltip, _occurrence); |
738 var _html = Mustache.to_html(Tlns.Templates.OccurrenceTooltip, _occurrence); |
909 _this.showTooltip(_occurrence.x, _occurrence.y, _html, (_event.pageY - _this.dragging_bounds.top) >= (.4 * _this.main_height) ); |
739 _this.showTooltip(_occurrence.x, _occurrence.y, _html, (_event.pageY - _this.dragging_bounds.top) >= (.4 * _this.main_height) ); |
910 // _this.showLinks(_id); |
|
911 } |
740 } |
912 } |
741 } |
913 }).mouseout(function() { |
742 }).mouseout(function() { |
914 var _el = $(this), |
743 var _el = $(this), |
915 _id = _el.attr("occurrence-id"); |
744 _id = _el.attr("occurrence-id"); |
916 if (typeof _id !== "undefined") { |
745 if (typeof _id !== "undefined") { |
917 var _occurrence = _this.getOccurrence(_id); |
746 var _occurrence = _this.getOccurrence(_id); |
918 _this.hideTooltip(); |
747 _this.hideTooltip(); |
919 _this.$.find('.Tl-Link').hide(); |
748 } |
920 _this.throttledShowEditingLinks(); |
749 }); |
921 } |
750 |
922 }).mouseup(function() { |
|
923 var _el = $(this); |
|
924 if (_this.dragging_type == "link") { |
|
925 var _target = _el.attr("occurrence-id"); |
|
926 if (_target != _this.editing_occurrence.id) { |
|
927 _this.editing_occurrence.addDependency(_target); |
|
928 $("body").trigger("AjoutDependanceTimeline", |
|
929 { |
|
930 id: _this.editing_occurrence.original_id, |
|
931 typeOccurrence: "Occurrence" + _this.editing_occurrence.type.replace(/^./,function(_l) { return _l.toUpperCase()}), |
|
932 idCible: _target.replace(/^.*_/,''), |
|
933 typeOccurrenceCible: "Occurrence" + _target.replace(/_.*$/,'').replace(/^./,function(_l) { return _l.toUpperCase()}) |
|
934 } |
|
935 ); |
|
936 } |
|
937 } |
|
938 }); |
|
939 |
|
940 this.$.find('.Tl-Link').mousedown(function() { |
|
941 var _el = $(this).parent(), |
|
942 _id = _el.attr("occurrence-id"); |
|
943 _this.editing_occurrence = _this.getOccurrence(_id); |
|
944 if (typeof _this.editing_occurrence !== "undefined" /* && !_this.editing_occurrence.locked */ ) { |
|
945 _this.dragging_type = "link"; |
|
946 } |
|
947 }) |
|
948 |
|
949 this.$.find('.Tl-Cluster').click(function() { |
751 this.$.find('.Tl-Cluster').click(function() { |
950 var _el = $(this), |
752 var _el = $(this), |
951 _contents = _el.attr("cluster-contents"); |
753 _contents = _el.attr("cluster-contents"); |
952 if (_this.open_cluster == _contents) { |
754 if (_this.open_cluster == _contents) { |
953 _this.open_cluster = false; |
755 _this.open_cluster = false; |
954 } else { |
756 } else { |
955 _this.open_cluster = _contents; |
757 _this.open_cluster = _contents; |
956 } |
758 } |
957 _this.throttledDrawGrid(); |
759 _this.throttledDrawGrid(); |
958 _this.throttledShowEditingLinks(); |
|
959 }) |
760 }) |
960 } |
761 } |
961 |
762 |
962 Tlns.Classes.Timeline.prototype.drawList = function() { |
763 Tlns.Classes.Timeline.prototype.drawList = function() { |
963 var _universfilter = this.$.find(".Ls-Univers li.Ls-Active").map(function(){return $(this).attr("data")}), |
764 var _universfilter = this.$.find(".Ls-Univers li.Ls-Active").map(function(){return $(this).attr("data")}), |
1013 var _id = $(this).attr("data-id"), |
814 var _id = $(this).attr("data-id"), |
1014 _data = { |
815 _data = { |
1015 id: _id.replace(/^.*_/,''), |
816 id: _id.replace(/^.*_/,''), |
1016 typeOccurrence: "Occurrence" + _id.replace(/_.*$/,'').replace(/^./,function(_l) { return _l.toUpperCase()}) |
817 typeOccurrence: "Occurrence" + _id.replace(/_.*$/,'').replace(/^./,function(_l) { return _l.toUpperCase()}) |
1017 } |
818 } |
1018 $("body").trigger("SelectionOccurrenceTimeline", _data); |
|
1019 return false; |
819 return false; |
1020 }); |
820 }); |
1021 } |
|
1022 |
|
1023 Tlns.Classes.Timeline.prototype.showLinks = function(_id) { |
|
1024 var _ctx = this.$.find('.Tl-Canvas')[0].getContext('2d'); |
|
1025 _ctx.clearRect(0,0,this.main_width, this.main_height); |
|
1026 |
|
1027 if (typeof _id !== "undefined") { |
|
1028 var _links = [], |
|
1029 _this = this; |
|
1030 _(this.occurrences).each(function(_occurrence) { |
|
1031 _(_occurrence.dependsOn).each(function(_dependance) { |
|
1032 var _parent = _this.getOccurrence(_dependance); |
|
1033 if (typeof _parent !== "undefined" && (_parent.id == _id || _occurrence.id == _id)) { |
|
1034 _links.push({ |
|
1035 from_x: _occurrence.x, |
|
1036 from_y: _occurrence.y + Math.floor(_this.univers_height / 2), |
|
1037 to_x: _parent.x, |
|
1038 to_y: _parent.y + Math.floor(_this.univers_height / 2) |
|
1039 }); |
|
1040 } |
|
1041 }); |
|
1042 }); |
|
1043 } |
|
1044 _(_links).each(function(_link) { |
|
1045 Tlns.Utils.drawArrow(_ctx, "#505050", _link.from_x,_link.from_y, _link.to_x,_link.to_y); |
|
1046 }); |
|
1047 } |
|
1048 |
|
1049 Tlns.Classes.Timeline.prototype.showEditingLinks = function() { |
|
1050 this.showLinks(typeof this.editing_occurrence !== "undefined" ? this.editing_occurrence.id : undefined); |
|
1051 } |
821 } |
1052 |
822 |
1053 Tlns.Classes.Timeline.prototype.getUnivers = function(_id) { |
823 Tlns.Classes.Timeline.prototype.getUnivers = function(_id) { |
1054 return _(this.univers).find(function(_univ) { |
824 return _(this.univers).find(function(_univ) { |
1055 return (_univ.id == _id); |
825 return (_univ.id == _id); |