cms/app-client/app/routes/tabs/thematiques.js
author Chloe Laisne <chloe.laisne@gmail.com>
Sat, 15 Oct 2016 20:02:09 +0530
changeset 337 2ea18460d5e3
parent 299 2c16302b06f7
child 338 4a3899b6a7ed
permissions -rw-r--r--
Fix loading alphabetical/popularity sorting in themes

import Ember from 'ember';

export default Ember.Route.extend({

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

    themes: [],

    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('themes', this.get('themes'));
    },

    deactivate: function () {
        this.set('themes', []);
    },

    actions: {

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

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

});