cms/app-client/app/routes/application.js
changeset 392 4fbe94af93e8
parent 344 70451a4dc9ae
child 394 48458e099b05
--- a/cms/app-client/app/routes/application.js	Thu Nov 03 11:14:41 2016 +0100
+++ b/cms/app-client/app/routes/application.js	Fri Nov 04 19:03:25 2016 +0100
@@ -1,7 +1,9 @@
 import Ember from 'ember';
+import _ from 'lodash/lodash';
 
 export default Ember.Route.extend({
 
+    filter: Ember.inject.service(),
     page: 1,
     limit: 10,
 
@@ -22,13 +24,6 @@
         return promise;
     }),
 
-    serializeQueryParam: function(value, urlKey) {
-        if (urlKey === 'date') {
-            return value;
-        }
-        return '' + value;
-    },
-
     setupController: function(controller) {
         this._super(...arguments);
         controller.set('page', this.get('page'));
@@ -36,17 +31,37 @@
         controller.set('documents', this.get('documents'));
     },
 
-    deserializeQueryParam: function(value, urlKey) {
-        if (urlKey === 'date') {
-            var array = [];
-            for (var i = 0; i < value.length; i++) {
-                array.push(value[i]);
-            }
-            return array;
+    /**
+      Serializes value of the query parameter based on defaultValueType
+      @method serializeQueryParam
+      @param {Object} value
+      @param {String} urlKey
+      @param {String} defaultValueType
+      @private
+    */
+    serializeQueryParam(value, urlKey, defaultValueType) {
+        if(_.contains(this.get('filter').get('queryParams'), urlKey)) {
+            return this.get('filter').serializeQueryParam(value, urlKey, defaultValueType);
         }
-        return value;
+        return this._super(value, urlKey, defaultValueType);
     },
 
+    /**
+      Deserializes value of the query parameter based on defaultValueType
+      @method deserializeQueryParam
+      @param {Object} value
+      @param {String} urlKey
+      @param {String} defaultValueType
+      @private
+    */
+    deserializeQueryParam(value, urlKey, defaultValueType) {
+        if(_.contains(this.get('filter').get('queryParams'), urlKey)) {
+            return this.get('filter').deserializeQueryParam(value, urlKey, defaultValueType);
+        }
+        return this._super(value, urlKey, defaultValueType);
+    },
+
+
     actions: {
 
         setPageQueryparams: function(type) {
@@ -61,20 +76,10 @@
             this.propertyDidChange('page');
         },
 
+
         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) {
-                        queryParams[value] = _this.controller.get(value);
-                    });
-                } else {
-                    queryParams[parameter] = _this.controller.get(parameter);
-                }
-            });
-            this.transitionTo({ queryParams: queryParams });
+            this.transitionTo({ queryParams: this.controller.get('queryParams') });
         },
 
         didTransition: function() {