Skip to content
This repository has been archived by the owner on Nov 8, 2018. It is now read-only.

Commit

Permalink
Merge pull request #1432 from owncloud/infinite-scrolling
Browse files Browse the repository at this point in the history
Load next messages automatically when reaching end of the list
  • Loading branch information
ChristophWurst committed Apr 20, 2016
2 parents f270d0f + 83f7c29 commit f2e9fc9
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 19 deletions.
17 changes: 13 additions & 4 deletions js/controller/foldercontroller.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
/**
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
*
* ownCloud - Mail
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
* @copyright Christoph Wurst 2016
*/

define(function(require) {
Expand Down
17 changes: 13 additions & 4 deletions js/views/messagecontent.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
/**
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
*
* ownCloud - Mail
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
* @copyright Christoph Wurst 2016
*/

define(function(require) {
Expand Down
42 changes: 31 additions & 11 deletions js/views/messages.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
/**
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
*
* ownCloud - Mail
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
* @copyright Christoph Wurst 2015
*/

define(function(require) {
Expand All @@ -22,13 +31,15 @@ define(function(require) {

return Backbone.Marionette.CompositeView.extend({
collection: null,
$scrollContainer: undefined,
childView: MessagesItemView,
childViewContainer: '#mail-message-list',
template: Handlebars.compile(MessageListTemplate),
currentMessageId: null,
loadingMore: false,
events: {
'click #load-new-mail-messages': 'loadNew',
'click #load-more-mail-messages': 'loadMore'
'click #load-more-mail-messages': 'loadMore',
},
filterCriteria: null,
initialize: function() {
Expand All @@ -47,6 +58,10 @@ define(function(require) {
this.listenTo(Radio.ui, 'messagesview:filter:clear', this.clearFilter);
this.listenTo(Radio.ui, 'messagesview:message:setactive', this.setActiveMessage);
},
onShow: function() {
this.$scrollContainer = this.$el.parent();
this.$scrollContainer.scroll(_.bind(this.onScroll, this));
},
getEmptyView: function() {
if (this.filterCriteria) {
return NoSearchResultMessageListView;
Expand All @@ -58,9 +73,6 @@ define(function(require) {
changeFlags: function(model) {
var unseen = model.get('flags').get('unseen');
var prevUnseen = model.get('flags')._previousAttributes.unseen;
//if(_.isUndefined(model._previousAttributes.flags.unseen)) {
// prevUnseen = model._previousAttributes.flags.get('unseen');
//}
if (unseen !== prevUnseen) {
this.trigger('change:unseen', model, unseen);
}
Expand Down Expand Up @@ -113,6 +125,16 @@ define(function(require) {
loadMore: function() {
this.loadMessages(false);
},
onScroll: function() {
if (this.loadingMore === true) {
// Ignore events until loading has finished
return;
}
if ((this.$scrollContainer.scrollTop() + this.$scrollContainer.height()) > (this.$el.height() - 150)) {
this.loadingMore = true;
this.loadMessages(false);
}
},
filterCurrentMailbox: function(query) {
this.filterCriteria = {
text: query
Expand Down Expand Up @@ -154,9 +176,6 @@ define(function(require) {
}
// Add messages
_this.collection.add(jsondata);

$('#app-content').removeClass('icon-loading');

Radio.ui.trigger('messagesview:message:setactive', require('state').currentMessageId);
});

Expand All @@ -178,6 +197,7 @@ define(function(require) {
.removeClass('icon-loading-small')
.val(t('mail', 'Check messages'))
.prop('disabled', false);
_this.loadingMore = false;
});
},
addMessages: function(data) {
Expand Down

0 comments on commit f2e9fc9

Please sign in to comment.