cms/app-client/app/components/visu-chrono.js
changeset 189 21b30ee23191
parent 120 e5e15547ffb1
child 195 9d083636bd99
equal deleted inserted replaced
188:d2cb39155997 189:21b30ee23191
     1 import Ember from 'ember';
     1 import Ember from 'ember';
     2 
     2 
     3 const { getOwner } = Ember;
     3 const { getOwner } = Ember;
     4 
     4 
     5 export default Ember.Component.extend({
     5 export default Ember.Component.extend({
     6   didInsertElement: function(){
       
     7     var _this = this;
       
     8 
     6 
     9     if (getOwner(this).lookup('controller:application').date !== null){
     7     didInsertElement: function(){
    10       this.highlightQuery(getOwner(this).lookup('controller:application').date);
     8         var self = this;
       
     9 
       
    10         if (getOwner(self).lookup('controller:application').date !== null){
       
    11             this.highlightQuery(getOwner(self).lookup('controller:application').date);
       
    12         }
       
    13 
       
    14         var isMouseDown = false,
       
    15         isHighlighted;
       
    16 
       
    17         Ember.$("#chrono-table li").mousedown(function () {
       
    18             isMouseDown = true;
       
    19             Ember.$(this).toggleClass("highlighted");
       
    20             isHighlighted = Ember.$(this).hasClass("highlighted");
       
    21             self.sendUpdate();
       
    22             return false; // prevent text selection
       
    23         }).mouseover(function () {
       
    24             if (isMouseDown) {
       
    25                 Ember.$(this).toggleClass("highlighted", isHighlighted);
       
    26                 self.sendUpdate();
       
    27             }
       
    28         }).bind("selectstart", function () {
       
    29             return false;
       
    30         });
       
    31 
       
    32         Ember.$(document).mouseup(function () {
       
    33             isMouseDown = false;
       
    34         });
       
    35     },
       
    36 
       
    37     sendUpdate: function(){
       
    38         var dateQuery = [];
       
    39         Ember.$('.highlighted').map(function(index, elt) {
       
    40             dateQuery.push(parseInt(Ember.$(elt).parent().attr('id')) + parseInt(Ember.$(elt).html()));
       
    41         });
       
    42         this.sendAction('action', dateQuery);
       
    43     },
       
    44 
       
    45     highlightQuery: function(list){
       
    46         list.map(function(elt){
       
    47             var year = Math.floor(parseInt(elt)/10)*10;
       
    48             Ember.$("#"+year+" ."+(parseInt(elt)-year)).toggleClass("highlighted", true);
       
    49         });
    11     }
    50     }
    12 
    51 
    13     var isMouseDown = false,
       
    14       isHighlighted;
       
    15     Ember.$("#chrono-table li").mousedown(function () {
       
    16       isMouseDown = true;
       
    17       Ember.$(this).toggleClass("highlighted");
       
    18       isHighlighted = Ember.$(this).hasClass("highlighted");
       
    19       _this.sendUpdate();
       
    20       return false; // prevent text selection
       
    21     }).mouseover(function () {
       
    22       if (isMouseDown) {
       
    23         Ember.$(this).toggleClass("highlighted", isHighlighted);
       
    24         _this.sendUpdate();
       
    25       }
       
    26     }).bind("selectstart", function () {
       
    27       return false;
       
    28     });
       
    29 
       
    30     Ember.$(document).mouseup(function () {
       
    31       isMouseDown = false;
       
    32     });
       
    33   },
       
    34   sendUpdate: function(){
       
    35     var dateQuery = [];
       
    36     Ember.$('.highlighted').map(function(index, elt) {
       
    37       dateQuery.push(parseInt(Ember.$(elt).parent().attr('id')) + parseInt(Ember.$(elt).html()));
       
    38     });
       
    39     this.sendAction('action', dateQuery);
       
    40   },
       
    41   highlightQuery: function(list){
       
    42     list.map(function(elt){
       
    43       var year = Math.floor(parseInt(elt)/10)*10;
       
    44       Ember.$("#"+year+" ."+(parseInt(elt)-year)).toggleClass("highlighted", true);
       
    45     });
       
    46   }
       
    47 });
    52 });