cms/app-client/app/routes/tabs/thematiques.js
author ymh <ymh.work@gmail.com>
Sat, 12 Nov 2016 17:21:25 +0100
changeset 414 5c6c526a7fc1
parent 394 48458e099b05
child 474 245b4df137d3
permissions -rw-r--r--
Display for single notice, preparation for share link

import Ember from 'ember';
import _ from 'lodash/lodash';

export default Ember.Route.extend({

    player: Ember.inject.service(),
    filter: Ember.inject.service(),

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

    themes: [],

    model: Ember.observer('index', function() {
        var self = this;
        var filterQueryParams = _.clone(this.get('filter').get('queryParamsValues'));
        var promise = this.store.query('theme', _.merge(filterQueryParams, {
            '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', []);
    },

    activate: function() {
        this.get('player').set('window', false);
    },

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

    }

});