author | Chloe Laisne <chloe.laisne@gmail.com> |
Thu, 23 Jun 2016 17:22:57 +0200 | |
changeset 201 | 9ae2cf79d167 |
parent 197 | 7b266ccf6d3d |
child 202 | 0446e07981db |
permissions | -rw-r--r-- |
48
9ef0952033e0
add example of visualisation for "chonologie"
nowmad@nowmads-macbook-pro.local
parents:
diff
changeset
|
1 |
import Ember from 'ember'; |
9ef0952033e0
add example of visualisation for "chonologie"
nowmad@nowmads-macbook-pro.local
parents:
diff
changeset
|
2 |
|
197 | 3 |
export default Ember.Component.extend({ |
120 | 4 |
|
197 | 5 |
filter: Ember.inject.service(), |
189
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
6 |
|
195
9d083636bd99
Layout and style of the /chronologie endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents:
189
diff
changeset
|
7 |
elementId: "chrono-table", |
9d083636bd99
Layout and style of the /chronologie endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents:
189
diff
changeset
|
8 |
|
189
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
9 |
didInsertElement: function(){ |
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
10 |
var self = this; |
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
11 |
|
197 | 12 |
if (this.get('filter').get('date') !== null){ |
13 |
this.highlightQuery(this.get('filter').get('date')); |
|
189
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
14 |
} |
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
15 |
|
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
16 |
var isMouseDown = false, |
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
17 |
isHighlighted; |
77
0889740f79c2
on page load, hilight the objects corresponding to the query params
nowmad@23.1.168.192.in-addr.arpa
parents:
72
diff
changeset
|
18 |
|
189
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
19 |
Ember.$("#chrono-table li").mousedown(function () { |
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
20 |
isMouseDown = true; |
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
21 |
Ember.$(this).toggleClass("highlighted"); |
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
22 |
isHighlighted = Ember.$(this).hasClass("highlighted"); |
197 | 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); |
|
189
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
31 |
return false; // prevent text selection |
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
32 |
}).mouseover(function () { |
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
33 |
if (isMouseDown) { |
197 | 34 |
if(Ember.$(this).hasClass("highlighted") !== isHighlighted) { |
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 |
} |
|
189
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
45 |
} |
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
46 |
}).bind("selectstart", function () { |
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
47 |
return false; |
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
48 |
}); |
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
49 |
|
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
50 |
Ember.$(document).mouseup(function () { |
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
51 |
isMouseDown = false; |
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
52 |
}); |
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
53 |
}, |
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
54 |
|
197 | 55 |
highlightQuery: function(dates){ |
56 |
dates.map(function(date){ |
|
57 |
Ember.$("#" + date).toggleClass("highlighted", true); |
|
189
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
58 |
}); |
77
0889740f79c2
on page load, hilight the objects corresponding to the query params
nowmad@23.1.168.192.in-addr.arpa
parents:
72
diff
changeset
|
59 |
} |
0889740f79c2
on page load, hilight the objects corresponding to the query params
nowmad@23.1.168.192.in-addr.arpa
parents:
72
diff
changeset
|
60 |
|
48
9ef0952033e0
add example of visualisation for "chonologie"
nowmad@nowmads-macbook-pro.local
parents:
diff
changeset
|
61 |
}); |