cms/app-client/app/routes/tabs/thematiques.js
author Chloe Laisne <chloe.laisne@gmail.com>
Tue, 12 Jul 2016 09:48:11 +0200
changeset 237 69a9f3687902
parent 236 ac6928e86d14
child 240 aa101458cd4e
permissions -rw-r--r--
Scrolling system in thematiques: more button and append data on scroll

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, model) {
        this._super(...arguments);
        // 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');            
        }
        
    }

});