1 import Ember from 'ember'; |
1 import Ember from 'ember'; |
2 |
2 |
3 const { getOwner } = Ember; |
3 export default Ember.Component.extend({ |
4 |
4 |
5 export default Ember.Component.extend({ |
5 filter: Ember.inject.service(), |
6 |
6 |
7 elementId: "chrono-table", |
7 elementId: "chrono-table", |
8 |
8 |
9 didInsertElement: function(){ |
9 didInsertElement: function(){ |
10 var self = this; |
10 var self = this; |
11 |
11 |
12 if (getOwner(self).lookup('controller:application').date !== null){ |
12 if (this.get('filter').get('date') !== null){ |
13 this.highlightQuery(getOwner(self).lookup('controller:application').date); |
13 this.highlightQuery(this.get('filter').get('date')); |
14 } |
14 } |
15 |
15 |
16 var isMouseDown = false, |
16 var isMouseDown = false, |
17 isHighlighted; |
17 isHighlighted; |
18 |
18 |
19 Ember.$("#chrono-table li").mousedown(function () { |
19 Ember.$("#chrono-table li").mousedown(function () { |
20 isMouseDown = true; |
20 isMouseDown = true; |
21 Ember.$(this).toggleClass("highlighted"); |
21 Ember.$(this).toggleClass("highlighted"); |
22 isHighlighted = Ember.$(this).hasClass("highlighted"); |
22 isHighlighted = Ember.$(this).hasClass("highlighted"); |
23 self.sendUpdate(); |
23 var dates = self.get('filter').get('date').toArray(); |
|
24 var index = dates.indexOf(parseInt(Ember.$(this).attr('id'))); |
|
25 if(index === -1) { |
|
26 dates.push(parseInt(Ember.$(this).attr('id'))); |
|
27 } else { |
|
28 dates.splice(index, 1); |
|
29 } |
|
30 self.get('filter').set('date', dates); |
24 return false; // prevent text selection |
31 return false; // prevent text selection |
25 }).mouseover(function () { |
32 }).mouseover(function () { |
26 if (isMouseDown) { |
33 if (isMouseDown) { |
27 Ember.$(this).toggleClass("highlighted", isHighlighted); |
34 if(Ember.$(this).hasClass("highlighted") !== isHighlighted) { |
28 self.sendUpdate(); |
35 Ember.$(this).toggleClass("highlighted", isHighlighted); |
|
36 var dates = self.get('filter').get('date').toArray(); |
|
37 var index = dates.indexOf(parseInt(Ember.$(this).attr('id'))); |
|
38 if(index === -1) { |
|
39 dates.push(parseInt(Ember.$(this).attr('id'))); |
|
40 } else { |
|
41 dates.splice(index, 1); |
|
42 } |
|
43 self.get('filter').set('date', dates); |
|
44 } |
29 } |
45 } |
30 }).bind("selectstart", function () { |
46 }).bind("selectstart", function () { |
31 return false; |
47 return false; |
32 }); |
48 }); |
33 |
49 |
34 Ember.$(document).mouseup(function () { |
50 Ember.$(document).mouseup(function () { |
35 isMouseDown = false; |
51 isMouseDown = false; |
36 }); |
52 }); |
37 }, |
53 }, |
38 |
54 |
39 sendUpdate: function(){ |
55 highlightQuery: function(dates){ |
40 var dateQuery = []; |
56 dates.map(function(date){ |
41 Ember.$('.highlighted').map(function(index, elt) { |
57 Ember.$("#" + date).toggleClass("highlighted", true); |
42 dateQuery.push(parseInt(Ember.$(elt).parent().attr('id')) + parseInt(Ember.$(elt).html())); |
|
43 }); |
|
44 this.sendAction('action', dateQuery); |
|
45 }, |
|
46 |
|
47 highlightQuery: function(list){ |
|
48 list.map(function(elt){ |
|
49 var year = Math.floor(parseInt(elt)/10)*10; |
|
50 Ember.$("#"+year+" ."+(parseInt(elt)-year)).toggleClass("highlighted", true); |
|
51 }); |
58 }); |
52 } |
59 } |
53 |
60 |
54 }); |
61 }); |