cms/app-client/app/routes/tabs/thematiques.js
author ymh <ymh.work@gmail.com>
Sat, 06 Aug 2016 21:29:33 +0700
changeset 261 02e2396bcbbc
parent 243 0f29cc270f9e
child 299 2c16302b06f7
permissions -rw-r--r--
Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
176
d1baf7ccecc8 Add `thematiques` components
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
     1
import Ember from 'ember';
d1baf7ccecc8 Add `thematiques` components
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
     2
d1baf7ccecc8 Add `thematiques` components
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
     3
export default Ember.Route.extend({
d1baf7ccecc8 Add `thematiques` components
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
     4
237
69a9f3687902 Scrolling system in thematiques: more button and append data on scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents: 236
diff changeset
     5
    index: 0,
69a9f3687902 Scrolling system in thematiques: more button and append data on scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents: 236
diff changeset
     6
    limit: 40,
69a9f3687902 Scrolling system in thematiques: more button and append data on scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents: 236
diff changeset
     7
    sort: 'alphabetical',
69a9f3687902 Scrolling system in thematiques: more button and append data on scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents: 236
diff changeset
     8
69a9f3687902 Scrolling system in thematiques: more button and append data on scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents: 236
diff changeset
     9
    themes: [],
69a9f3687902 Scrolling system in thematiques: more button and append data on scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents: 236
diff changeset
    10
240
aa101458cd4e Player forward and backward
Chloe Laisne <chloe.laisne@gmail.com>
parents: 237
diff changeset
    11
    all: Ember.computed(function() {
aa101458cd4e Player forward and backward
Chloe Laisne <chloe.laisne@gmail.com>
parents: 237
diff changeset
    12
        return this.store.findAll('theme');
aa101458cd4e Player forward and backward
Chloe Laisne <chloe.laisne@gmail.com>
parents: 237
diff changeset
    13
    }),
aa101458cd4e Player forward and backward
Chloe Laisne <chloe.laisne@gmail.com>
parents: 237
diff changeset
    14
237
69a9f3687902 Scrolling system in thematiques: more button and append data on scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents: 236
diff changeset
    15
    model: Ember.observer('index', function() {
69a9f3687902 Scrolling system in thematiques: more button and append data on scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents: 236
diff changeset
    16
        var self = this;
69a9f3687902 Scrolling system in thematiques: more button and append data on scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents: 236
diff changeset
    17
        var promise = this.store.query('theme', {
69a9f3687902 Scrolling system in thematiques: more button and append data on scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents: 236
diff changeset
    18
            'limit': this.get('limit'),
69a9f3687902 Scrolling system in thematiques: more button and append data on scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents: 236
diff changeset
    19
            'index': this.get('index'),
69a9f3687902 Scrolling system in thematiques: more button and append data on scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents: 236
diff changeset
    20
            'sort': this.get('sort')
69a9f3687902 Scrolling system in thematiques: more button and append data on scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents: 236
diff changeset
    21
        });
69a9f3687902 Scrolling system in thematiques: more button and append data on scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents: 236
diff changeset
    22
        promise.then(function(value) {
69a9f3687902 Scrolling system in thematiques: more button and append data on scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents: 236
diff changeset
    23
            if (self.get('themes').length) {
69a9f3687902 Scrolling system in thematiques: more button and append data on scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents: 236
diff changeset
    24
                value = self.get('themes').pushObjects(value.get('content'));
69a9f3687902 Scrolling system in thematiques: more button and append data on scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents: 236
diff changeset
    25
            }
69a9f3687902 Scrolling system in thematiques: more button and append data on scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents: 236
diff changeset
    26
            self.set('themes', value);
243
0f29cc270f9e Fix firefox focus
Chloe Laisne <chloe.laisne@gmail.com>
parents: 240
diff changeset
    27
        });
237
69a9f3687902 Scrolling system in thematiques: more button and append data on scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents: 236
diff changeset
    28
        return promise;
69a9f3687902 Scrolling system in thematiques: more button and append data on scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents: 236
diff changeset
    29
    }),
236
ac6928e86d14 Adapt theme query limit and offset and sorting order in fixtures
Chloe Laisne <chloe.laisne@gmail.com>
parents: 176
diff changeset
    30
243
0f29cc270f9e Fix firefox focus
Chloe Laisne <chloe.laisne@gmail.com>
parents: 240
diff changeset
    31
    setupController: function(controller) {
237
69a9f3687902 Scrolling system in thematiques: more button and append data on scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents: 236
diff changeset
    32
        this._super(...arguments);
240
aa101458cd4e Player forward and backward
Chloe Laisne <chloe.laisne@gmail.com>
parents: 237
diff changeset
    33
        controller.set('all', this.get('all'));
237
69a9f3687902 Scrolling system in thematiques: more button and append data on scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents: 236
diff changeset
    34
        // Add ArrayProxy to template context.
69a9f3687902 Scrolling system in thematiques: more button and append data on scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents: 236
diff changeset
    35
        controller.set('themes', this.get('themes'));
69a9f3687902 Scrolling system in thematiques: more button and append data on scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents: 236
diff changeset
    36
    },
69a9f3687902 Scrolling system in thematiques: more button and append data on scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents: 236
diff changeset
    37
69a9f3687902 Scrolling system in thematiques: more button and append data on scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents: 236
diff changeset
    38
    actions: {
69a9f3687902 Scrolling system in thematiques: more button and append data on scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents: 236
diff changeset
    39
69a9f3687902 Scrolling system in thematiques: more button and append data on scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents: 236
diff changeset
    40
        setIndexQueryparams: function() {
69a9f3687902 Scrolling system in thematiques: more button and append data on scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents: 236
diff changeset
    41
            this.set('index', this.get('index') + 1);
69a9f3687902 Scrolling system in thematiques: more button and append data on scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents: 236
diff changeset
    42
        },
69a9f3687902 Scrolling system in thematiques: more button and append data on scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents: 236
diff changeset
    43
69a9f3687902 Scrolling system in thematiques: more button and append data on scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents: 236
diff changeset
    44
        setSortQueryparams: function(sort) {
69a9f3687902 Scrolling system in thematiques: more button and append data on scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents: 236
diff changeset
    45
            this.set('sort', sort);
69a9f3687902 Scrolling system in thematiques: more button and append data on scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents: 236
diff changeset
    46
            this.get('themes').replaceContent(0, this.get('themes').get('content').length, null);
69a9f3687902 Scrolling system in thematiques: more button and append data on scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents: 236
diff changeset
    47
            // Force property reset to trigger request.
69a9f3687902 Scrolling system in thematiques: more button and append data on scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents: 236
diff changeset
    48
            this.propertyWillChange('index');
69a9f3687902 Scrolling system in thematiques: more button and append data on scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents: 236
diff changeset
    49
            this.set('index', 0);
69a9f3687902 Scrolling system in thematiques: more button and append data on scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents: 236
diff changeset
    50
            this.propertyDidChange('index');            
69a9f3687902 Scrolling system in thematiques: more button and append data on scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents: 236
diff changeset
    51
        }
69a9f3687902 Scrolling system in thematiques: more button and append data on scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents: 236
diff changeset
    52
        
176
d1baf7ccecc8 Add `thematiques` components
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
    53
    }
d1baf7ccecc8 Add `thematiques` components
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
    54
d1baf7ccecc8 Add `thematiques` components
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
    55
});