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)

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');            
        }
        
    }

});