cms/app-client/app/components/visu-chrono.js
author nowmad@23.1.168.192.in-addr.arpa
Fri, 18 Dec 2015 15:21:52 +0100
changeset 77 0889740f79c2
parent 72 9a7ea5349882
child 81 848e4a5ad4d9
permissions -rw-r--r--
on page load, hilight the objects corresponding to the query params

import Ember from 'ember';

export default Ember.Component.extend({
  didInsertElement: function(){
    var _this = this;

    if (this.get('container').lookup('controller:application').date !== null){
      this.highlightQuery(this.get('container').lookup('controller:application').date.split(','));
    }

    var isMouseDown = false,
      isHighlighted;
    $("#our_table li").mousedown(function () {
      isMouseDown = true;
      $(this).toggleClass("highlighted");
      isHighlighted = $(this).hasClass("highlighted");
      _this.sendUpdate();
      return false; // prevent text selection
    }).mouseover(function () {
      if (isMouseDown) {
        $(this).toggleClass("highlighted", isHighlighted);
        _this.sendUpdate();
      }
    }).bind("selectstart", function () {
      return false;
    })

    $(document).mouseup(function () {
      isMouseDown = false;
    });
  },
  sendUpdate: function(){
    var dateQuery = $('.highlighted').map(function(index, elt) {
      return parseInt($(elt).parent().attr('id')) + parseInt($(elt).html());
    }).get().join(',');
    dateQuery = (dateQuery == "") ? null : dateQuery;
    this.sendAction('action', dateQuery);
  },
  highlightQuery: function(list){
    list.map(function(elt, index){
      var year = Math.floor(parseInt(elt)/10)*10;
      $("#"+year+" ."+(parseInt(elt)-year)).toggleClass("highlighted", true);
    });
  }
});