cms/app-client/app/controllers/application.js
changeset 394 48458e099b05
parent 392 4fbe94af93e8
child 401 9ff56cc0c656
--- a/cms/app-client/app/controllers/application.js	Sun Nov 06 03:44:16 2016 +0100
+++ b/cms/app-client/app/controllers/application.js	Tue Nov 08 01:22:56 2016 +0100
@@ -5,28 +5,40 @@
 
     player: Ember.inject.service(),
     filter: Ember.inject.service(),
+    constants: Ember.inject.service(),
 
+    page: 1,
+    limit: Ember.computed(function() {
+      return this.get('constants').DOCUMENTS_PAGINATION_PERPAGE;
+    }),
 
     playerVideoscreenObserver: Ember.observer('player.videoscreen', function() {
         Ember.$('body').toggleClass('videoscreen', this.get('player').get('videoscreen'));
     }),
 
-    // queryParams: ['location', 'date', 'notice', 'language', 'discourse', 'theme'],
-    // queryParams: Ember.computed('filter.queryParams', 'notice', function() {
-    //     const queryParamsList = this.get('filter').get('queryParams');
-    //     return _.merge(queryParamsList, {'notice' : this.get('notice')});
-    // }),
     queryParams : Ember.computed('filter.queryParams', function() {
         var res = _.clone(this.get('filter').get('queryParams'));
         res.push('notice');
+        res.push('page');
         return res;
     }),
 
-    location: Ember.computed.alias('filter.location'),
-    date: Ember.computed.alias('filter.date'),
-    language: Ember.computed.alias('filter.language'),
-    discourse: Ember.computed.alias('filter.discourse'),
-    theme: Ember.computed.alias('filter.theme'),
+    // this has to be done because queryParameters can not be computed properties...
+    // Of course, we rather had computed properties.
+    // c.f. : https://github.com/emberjs/ember.js/issues/11592
+    date: null,
+    discourse: null,
+    language: null,
+    location: null,
+    theme: null,
+
+    languageObserver: Ember.observer('language', 'date', 'date.[]', 'discourse', 'discourse.[]', 'location', 'theme', 'theme.[]', function() {
+        this.get('filter').setProperties(this.getProperties('language', 'date', 'discourse', 'theme', 'location'));
+    }),
+    filterObserver: Ember.observer('filter', 'filter.language', 'filter.date', 'filter.date.[]', 'filter.discourse', 'filter.discourse.[]', 'filter.location', 'filter.theme', 'filter.theme.[]', function() {
+        this.set('language', this.get('filter').get('language'));
+        this.setProperties(this.get('filter').getProperties('language', 'date', 'discourse', 'theme', 'location'));
+    }),
 
     itemObserver: Ember.observer('player.item', function() {
         var self = this;
@@ -62,21 +74,23 @@
     init: function() {
         this._super(...arguments);
         this.get('player');
+        this.get('filter');
     },
 
     actions: {
 
-        changeDocument: function(docDirection){
-            var direction = (docDirection === "next") ? 1 : -1;
-            var currentObject = this.get("filteredDocuments").findBy('id', this.get("currentItem").get('id'));
-            if ( currentObject !== 'undefined'){
-                var index = this.get("filteredDocuments").indexOf(currentObject);
-                if ( typeof(this.get("filteredDocuments").objectAt(index+direction)) !== 'undefined'){
-                    return this.set('currentId', this.get("filteredDocuments").objectAt(index+direction).id);
-                }
+        setPageQueryparams: function(type) {
+            var page = this.get('page');
+            if(type === 'previous') {
+                page = page - 1;
+            } else if(type === 'next') {
+                page = page + 1;
             }
-            return this.set('currentId', this.get('filteredDocuments').get('firstObject').id);
+            this.propertyWillChange('page');
+            this.set('page', page);
+            this.propertyDidChange('page');
         },
+
         play: function(item){
             this.set("currentId", item.id);
         }