Fix loading alphabetical/popularity sorting in themes
authorChloe Laisne <chloe.laisne@gmail.com>
Sat, 15 Oct 2016 20:02:09 +0530
changeset 337 2ea18460d5e3
parent 336 f076ddd29e13
child 338 4a3899b6a7ed
Fix loading alphabetical/popularity sorting in themes
cms/app-client/app/components/sorting-component.js
cms/app-client/app/routes/tabs/thematiques.js
--- a/cms/app-client/app/components/sorting-component.js	Sat Oct 15 16:15:07 2016 +0530
+++ b/cms/app-client/app/components/sorting-component.js	Sat Oct 15 20:02:09 2016 +0530
@@ -19,9 +19,11 @@
         this.$('ul').on('scroll', Ember.run.bind(this, this.scrolling));
     }),
     scrolling: function(event) {
-        if(Ember.$(event.target).scrollTop() + Ember.$(event.target).height() > Ember.$(event.target).get(0).scrollHeight - 50) {
-            this.triggerAction({ action:'loadMore', target: this });
-            Ember.$(event.target).off('scroll');
+        if(Ember.$(event.target).scrollTop() !== 0 ) {
+            if(Ember.$(event.target).scrollTop() + Ember.$(event.target).height() > Ember.$(event.target).get(0).scrollHeight - 50) {
+                this.triggerAction({ action:'loadMore', target: this });
+                Ember.$(event.target).off('scroll');
+            }
         }
     },
 
--- a/cms/app-client/app/routes/tabs/thematiques.js	Sat Oct 15 16:15:07 2016 +0530
+++ b/cms/app-client/app/routes/tabs/thematiques.js	Sat Oct 15 20:02:09 2016 +0530
@@ -29,6 +29,10 @@
         controller.set('themes', this.get('themes'));
     },
 
+    deactivate: function () {
+        this.set('themes', []);
+    },
+
     actions: {
 
         setIndexQueryparams: function() {
@@ -37,11 +41,15 @@
 
         setSortQueryparams: function(sort) {
             this.set('sort', sort);
-            this.get('themes').replaceContent(0, this.get('themes').get('content').length, null);
-            // Force property reset to trigger request.
-            this.propertyWillChange('index');
-            this.set('index', 0);
-            this.propertyDidChange('index');            
+            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);
+            }
         }
         
     }