1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-18 16:36:15 +00:00

[group discussion] added 'load more'

This commit is contained in:
llj
2016-03-25 17:54:53 +08:00
parent fdeec88eb3
commit 025af00900
5 changed files with 65 additions and 2 deletions

View File

@@ -1267,6 +1267,11 @@ textarea:-moz-placeholder {/* for FF */
text-align:center;
margin:10px 0;
}
.load-more-discussion {
color:#eb8205;
cursor:pointer;
text-align:center;
}
/********** container ***********/
#main, #footer {
width:950px;

View File

@@ -75,8 +75,11 @@ class GroupDiscussions(APIView):
"created_at": isoformat_timestr
})
return HttpResponse(json.dumps(msgs), status=200,
content_type=json_content_type)
return HttpResponse(json.dumps({
"msgs": msgs,
"current_page": page,
"page_num": paginator.num_pages,
}), status=200, content_type=json_content_type)
@api_check_group
def post(self, request, group_id, format=None):

View File

@@ -159,6 +159,7 @@
</div>
<div class="popover-con">
<span class="loading-icon loading-tip"></span>
<p class="load-more-discussion hide js-load-more">{% trans "More..." %}</p>
<ul id="group-discussion-list" class="hide"></ul>
<p class="no-discussion-tip hide">{% trans "No discussion in this group yet." %}</p>
<p class="error hide"></p>

View File

@@ -15,6 +15,13 @@ define([
url: function() {
return Common.getUrl({name: 'group_discussions', group_id: this.group_id});
},
parse: function(data) {
this.current_page = data.current_page;
this.page_num = data.page_num;
return data.msgs;
}
});

View File

@@ -22,6 +22,7 @@ define([
this.$listContainer = this.$('#group-discussion-list');
this.$emptyTip = this.$('.no-discussion-tip');
this.$error = this.$('.error');
this.$loadMore = this.$('.js-load-more');
var _this = this;
$(window).resize(function() {
@@ -44,6 +45,7 @@ define([
events: {
'click .close': 'hide',
'click .js-load-more': 'loadMore',
'submit form': 'formSubmit'
},
@@ -70,9 +72,15 @@ define([
this.collection.each(this.addOne, this);
this.$listContainer.show();
this.scrollConToBottom();
if (this.collection.current_page < this.collection.page_num) {
this.$loadMore.show();
} else {
this.$loadMore.hide();
}
} else {
this.$emptyTip.show();
this.$listContainer.hide();
this.$loadMore.hide();
}
},
@@ -146,6 +154,45 @@ define([
$input.focus();
},
loadMore: function() {
var _this = this;
this.$loadMore.hide();
this.$loadingTip.show();
this.collection.fetch({
cache: false,
remove: false,
data: {
'avatar_size': 64,
'page': this.collection.current_page + 1
},
success: function(collection, response, opts) {
},
error: function(collection, response, opts) {
var err_msg;
if (response.responseText) {
if (response['status'] == 401 || response['status'] == 403) {
err_msg = gettext("Permission error");
} else {
err_msg = gettext("Error");
}
} else {
err_msg = gettext('Please check the network.');
}
_this.$error.html(err_msg).show();
},
complete: function() {
_this.$loadingTip.hide();
if (_this.collection.current_page < _this.collection.page_num) {
_this.$loadMore.show();
} else {
_this.$loadMore.hide();
}
}
});
},
formSubmit: function() {
var _this = this;
var content = $.trim(this.$('[name="message"]').val());