cms/app-client/app/helpers/is-checked.js
author ymh <ymh.work@gmail.com>
Fri, 04 Nov 2016 19:03:25 +0100
changeset 392 4fbe94af93e8
parent 245 c9dd78a43b07
child 465 9df336529b2f
permissions -rw-r--r--
Improve filter service. Centralize filter management in a single point
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
244
d7ab83ecf737 Checked/indeterminate states with /langues endpoint checkboxes
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
     1
import Ember from 'ember';
d7ab83ecf737 Checked/indeterminate states with /langues endpoint checkboxes
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
     2
d7ab83ecf737 Checked/indeterminate states with /langues endpoint checkboxes
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
     3
export function isChecked(params) {
d7ab83ecf737 Checked/indeterminate states with /langues endpoint checkboxes
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
     4
    var dates = params[0];
392
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 245
diff changeset
     5
    if(dates == null) {
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 245
diff changeset
     6
        return false;
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 245
diff changeset
     7
    }
244
d7ab83ecf737 Checked/indeterminate states with /langues endpoint checkboxes
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
     8
d7ab83ecf737 Checked/indeterminate states with /langues endpoint checkboxes
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
     9
    var decade = [];
d7ab83ecf737 Checked/indeterminate states with /langues endpoint checkboxes
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
    10
    var next = params[1] + 10;
d7ab83ecf737 Checked/indeterminate states with /langues endpoint checkboxes
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
    11
    while(params[1] < next) {
d7ab83ecf737 Checked/indeterminate states with /langues endpoint checkboxes
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
    12
        decade.push(params[1]);
d7ab83ecf737 Checked/indeterminate states with /langues endpoint checkboxes
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
    13
        params[1] ++;
d7ab83ecf737 Checked/indeterminate states with /langues endpoint checkboxes
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
    14
    }
d7ab83ecf737 Checked/indeterminate states with /langues endpoint checkboxes
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
    15
d7ab83ecf737 Checked/indeterminate states with /langues endpoint checkboxes
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
    16
    var filter = decade.filter(function(date){ return dates.indexOf(date) > -1; });
d7ab83ecf737 Checked/indeterminate states with /langues endpoint checkboxes
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
    17
    if(filter.length === decade.length) {
245
c9dd78a43b07 Transcript model and erializer
Chloe Laisne <chloe.laisne@gmail.com>
parents: 244
diff changeset
    18
        return true;
244
d7ab83ecf737 Checked/indeterminate states with /langues endpoint checkboxes
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
    19
    }
d7ab83ecf737 Checked/indeterminate states with /langues endpoint checkboxes
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
    20
    return false;
d7ab83ecf737 Checked/indeterminate states with /langues endpoint checkboxes
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
    21
}
d7ab83ecf737 Checked/indeterminate states with /langues endpoint checkboxes
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
    22
d7ab83ecf737 Checked/indeterminate states with /langues endpoint checkboxes
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
    23
export default Ember.Helper.helper(isChecked);