cms/app-client/app/routes/application.js
changeset 392 4fbe94af93e8
parent 344 70451a4dc9ae
child 394 48458e099b05
equal deleted inserted replaced
391:4f6118afabee 392:4fbe94af93e8
     1 import Ember from 'ember';
     1 import Ember from 'ember';
       
     2 import _ from 'lodash/lodash';
     2 
     3 
     3 export default Ember.Route.extend({
     4 export default Ember.Route.extend({
     4 
     5 
       
     6     filter: Ember.inject.service(),
     5     page: 1,
     7     page: 1,
     6     limit: 10,
     8     limit: 10,
     7 
     9 
     8     documents: [],
    10     documents: [],
     9     model: Ember.observer('page', function() {
    11     model: Ember.observer('page', function() {
    20             self.set('documents', value);
    22             self.set('documents', value);
    21         });
    23         });
    22         return promise;
    24         return promise;
    23     }),
    25     }),
    24 
    26 
    25     serializeQueryParam: function(value, urlKey) {
       
    26         if (urlKey === 'date') {
       
    27             return value;
       
    28         }
       
    29         return '' + value;
       
    30     },
       
    31 
       
    32     setupController: function(controller) {
    27     setupController: function(controller) {
    33         this._super(...arguments);
    28         this._super(...arguments);
    34         controller.set('page', this.get('page'));
    29         controller.set('page', this.get('page'));
    35         controller.set('limit', this.get('limit'));
    30         controller.set('limit', this.get('limit'));
    36         controller.set('documents', this.get('documents'));
    31         controller.set('documents', this.get('documents'));
    37     },
    32     },
    38 
    33 
    39     deserializeQueryParam: function(value, urlKey) {
    34     /**
    40         if (urlKey === 'date') {
    35       Serializes value of the query parameter based on defaultValueType
    41             var array = [];
    36       @method serializeQueryParam
    42             for (var i = 0; i < value.length; i++) {
    37       @param {Object} value
    43                 array.push(value[i]);
    38       @param {String} urlKey
    44             }
    39       @param {String} defaultValueType
    45             return array;
    40       @private
       
    41     */
       
    42     serializeQueryParam(value, urlKey, defaultValueType) {
       
    43         if(_.contains(this.get('filter').get('queryParams'), urlKey)) {
       
    44             return this.get('filter').serializeQueryParam(value, urlKey, defaultValueType);
    46         }
    45         }
    47         return value;
    46         return this._super(value, urlKey, defaultValueType);
    48     },
    47     },
       
    48 
       
    49     /**
       
    50       Deserializes value of the query parameter based on defaultValueType
       
    51       @method deserializeQueryParam
       
    52       @param {Object} value
       
    53       @param {String} urlKey
       
    54       @param {String} defaultValueType
       
    55       @private
       
    56     */
       
    57     deserializeQueryParam(value, urlKey, defaultValueType) {
       
    58         if(_.contains(this.get('filter').get('queryParams'), urlKey)) {
       
    59             return this.get('filter').deserializeQueryParam(value, urlKey, defaultValueType);
       
    60         }
       
    61         return this._super(value, urlKey, defaultValueType);
       
    62     },
       
    63 
    49 
    64 
    50     actions: {
    65     actions: {
    51 
    66 
    52         setPageQueryparams: function(type) {
    67         setPageQueryparams: function(type) {
    53             var page = this.get('page');
    68             var page = this.get('page');
    59             this.propertyWillChange('page');
    74             this.propertyWillChange('page');
    60             this.set('page', page);
    75             this.set('page', page);
    61             this.propertyDidChange('page');
    76             this.propertyDidChange('page');
    62         },
    77         },
    63 
    78 
       
    79 
    64         willTransition: function() {
    80         willTransition: function() {
    65             // Prevent navigation from removing query parameters
    81             // Prevent navigation from removing query parameters
    66             var _this = this,
    82             this.transitionTo({ queryParams: this.controller.get('queryParams') });
    67                 queryParams = {};
       
    68             this.controller.get('queryParams').map(function(parameter){
       
    69                 if(typeof parameter === 'object') {
       
    70                     Object.keys(parameter).forEach(function(value) {
       
    71                         queryParams[value] = _this.controller.get(value);
       
    72                     });
       
    73                 } else {
       
    74                     queryParams[parameter] = _this.controller.get(parameter);
       
    75                 }
       
    76             });
       
    77             this.transitionTo({ queryParams: queryParams });
       
    78         },
    83         },
    79 
    84 
    80         didTransition: function() {
    85         didTransition: function() {
    81             // Append body classname depending on the route
    86             // Append body classname depending on the route
    82             Ember.$('body').removeClass((this.controller.get('currentPath') || '').replace(/\//g, '-').dasherize());
    87             Ember.$('body').removeClass((this.controller.get('currentPath') || '').replace(/\//g, '-').dasherize());