cms/app-client/app/components/visu-chrono.js
author Chloe Laisne <chloe.laisne@gmail.com>
Mon, 20 Jun 2016 17:04:59 +0200
changeset 195 9d083636bd99
parent 189 21b30ee23191
child 197 7b266ccf6d3d
permissions -rw-r--r--
Layout and style of the /chronologie endpoint
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
120
e5e15547ffb1 correct deprecation warning
ymh <ymh.work@gmail.com>
parents: 98
diff changeset
     3
const { getOwner } = Ember;
e5e15547ffb1 correct deprecation warning
ymh <ymh.work@gmail.com>
parents: 98
diff changeset
     4
48
9ef0952033e0 add example of visualisation for "chonologie"
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
     5
export default Ember.Component.extend({
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
21b30ee23191 /langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents: 120
diff changeset
    12
        if (getOwner(self).lookup('controller:application').date !== null){
21b30ee23191 /langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents: 120
diff changeset
    13
            this.highlightQuery(getOwner(self).lookup('controller:application').date);
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");
21b30ee23191 /langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents: 120
diff changeset
    23
            self.sendUpdate();
21b30ee23191 /langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents: 120
diff changeset
    24
            return false; // prevent text selection
21b30ee23191 /langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents: 120
diff changeset
    25
        }).mouseover(function () {
21b30ee23191 /langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents: 120
diff changeset
    26
            if (isMouseDown) {
21b30ee23191 /langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents: 120
diff changeset
    27
                Ember.$(this).toggleClass("highlighted", isHighlighted);
21b30ee23191 /langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents: 120
diff changeset
    28
                self.sendUpdate();
21b30ee23191 /langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents: 120
diff changeset
    29
            }
21b30ee23191 /langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents: 120
diff changeset
    30
        }).bind("selectstart", function () {
21b30ee23191 /langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents: 120
diff changeset
    31
            return false;
21b30ee23191 /langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents: 120
diff changeset
    32
        });
21b30ee23191 /langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents: 120
diff changeset
    33
21b30ee23191 /langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents: 120
diff changeset
    34
        Ember.$(document).mouseup(function () {
21b30ee23191 /langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents: 120
diff changeset
    35
            isMouseDown = false;
21b30ee23191 /langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents: 120
diff changeset
    36
        });
21b30ee23191 /langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents: 120
diff changeset
    37
    },
21b30ee23191 /langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents: 120
diff changeset
    38
21b30ee23191 /langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents: 120
diff changeset
    39
    sendUpdate: function(){
21b30ee23191 /langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents: 120
diff changeset
    40
        var dateQuery = [];
21b30ee23191 /langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents: 120
diff changeset
    41
        Ember.$('.highlighted').map(function(index, elt) {
21b30ee23191 /langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents: 120
diff changeset
    42
            dateQuery.push(parseInt(Ember.$(elt).parent().attr('id')) + parseInt(Ember.$(elt).html()));
21b30ee23191 /langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents: 120
diff changeset
    43
        });
21b30ee23191 /langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents: 120
diff changeset
    44
        this.sendAction('action', dateQuery);
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
21b30ee23191 /langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents: 120
diff changeset
    47
    highlightQuery: function(list){
21b30ee23191 /langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents: 120
diff changeset
    48
        list.map(function(elt){
21b30ee23191 /langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents: 120
diff changeset
    49
            var year = Math.floor(parseInt(elt)/10)*10;
21b30ee23191 /langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents: 120
diff changeset
    50
            Ember.$("#"+year+" ."+(parseInt(elt)-year)).toggleClass("highlighted", true);
21b30ee23191 /langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents: 120
diff changeset
    51
        });
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
    52
    }
0889740f79c2 on page load, hilight the objects corresponding to the query params
nowmad@23.1.168.192.in-addr.arpa
parents: 72
diff changeset
    53
48
9ef0952033e0 add example of visualisation for "chonologie"
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    54
});