cms/app-client/app/routes/application.js
author Chloe Laisne <chloe.laisne@gmail.com>
Thu, 23 Jun 2016 17:22:57 +0200
changeset 201 9ae2cf79d167
parent 199 b7c691c6179d
child 203 2ee21302dc47
permissions -rw-r--r--
Quickfix this is undefined

import Ember from 'ember';

export default Ember.Route.extend({

    model: function() {
        return this.store.findAll('document');
    },

    serializeQueryParam: function(value, urlKey) {
        if (urlKey === 'date') {
            return value;
        }
        return '' + value;
    },

    deserializeQueryParam: function(value, urlKey) {
        if (urlKey === 'date') {
            var arr = [];
            for (var i = 0; i < value.length; i++) {
                arr.push(parseInt(value[i]));
            }
            return arr;
        }
        return value;
    },

    actions: {

        willTransition: function() {
            // Prevent navigation from removing query parameters
            var _this = this,
                queryParams = {};
            this.controller.get('queryParams').map(function(parameter){
                if(typeof parameter === 'object') {
                    Object.keys(parameter).forEach(function(value, key, array) {
                        queryParams[value] = _this.controller.get(value);
                    });
                } else {
                    queryParams[parameter] = _this.controller.get(parameter);
                }
            });
            this.transitionTo({ queryParams: queryParams });
        },

        didTransition: function() {
            // Append body classname depending on the route
            Ember.$('body').removeClass((this.controller.get('currentPath') || '').replace(/\//g, '-').dasherize());
            Ember.run.once(this, function() {
                Ember.$('body').addClass((this.controller.get('currentPath') ||'').replace(/\//g, '-').dasherize());
            });
        }

    }

});