cms/app-client/app/routes/tabs/thematiques.js
author Chloe Laisne <chloe.laisne@gmail.com>
Fri, 22 Jul 2016 16:11:44 +0200
changeset 247 7a5d729992b8
parent 243 0f29cc270f9e
child 299 2c16302b06f7
permissions -rw-r--r--
Design and animate transcript

import Ember from 'ember';

export default Ember.Route.extend({

    index: 0,
    limit: 40,
    sort: 'alphabetical',

    themes: [],

    all: Ember.computed(function() {
        return this.store.findAll('theme');
    }),

    model: Ember.observer('index', function() {
        var self = this;
        var promise = this.store.query('theme', {
            'limit': this.get('limit'),
            'index': this.get('index'),
            'sort': this.get('sort')
        });
        promise.then(function(value) {
            if (self.get('themes').length) {
                value = self.get('themes').pushObjects(value.get('content'));
            }
            self.set('themes', value);
        });
        return promise;
    }),

    setupController: function(controller) {
        this._super(...arguments);
        controller.set('all', this.get('all'));
        // Add ArrayProxy to template context.
        controller.set('themes', this.get('themes'));
    },

    actions: {

        setIndexQueryparams: function() {
            this.set('index', this.get('index') + 1);
        },

        setSortQueryparams: function(sort) {
            this.set('sort', sort);
            this.get('themes').replaceContent(0, this.get('themes').get('content').length, null);
            // Force property reset to trigger request.
            this.propertyWillChange('index');
            this.set('index', 0);
            this.propertyDidChange('index');            
        }
        
    }

});