1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-07-01 01:12:41 +00:00
seahub/static/scripts/app/views/activities.js

103 lines
2.8 KiB
JavaScript
Raw Normal View History

2015-07-24 03:37:57 +00:00
define([
'jquery',
'underscore',
'backbone',
'common',
'app/collections/activities',
'app/views/activity-item'
], function($, _, Backbone, Common, ActivityCollection, ActivityItemView) {
'use strict';
2015-07-28 11:54:57 +00:00
var ActivitiesView = Backbone.View.extend({
2015-07-24 03:37:57 +00:00
2015-07-28 11:54:57 +00:00
el: $('#activities'),
2015-07-24 03:37:57 +00:00
2015-07-28 11:54:57 +00:00
activityGroupTemplate: _.template($('#activity-group-tmpl').html()),
2015-07-24 03:37:57 +00:00
events: {
2015-07-28 11:54:57 +00:00
'click #activities-more': 'getMoreActivities'
2015-07-24 03:37:57 +00:00
},
initialize: function () {
this.activities = new ActivityCollection();
2015-07-28 11:54:57 +00:00
this.$activitiesBody = this.$('#activities-body');
this.$activitiesMore = this.$('#activities-more');
2015-07-24 03:37:57 +00:00
this.$loadingTip = this.$('.loading-tip');
this.moreOffset = 0;
},
2015-07-28 11:54:57 +00:00
getMoreActivities: function () {
2015-07-24 03:37:57 +00:00
var _this = this;
this.$loadingTip.show();
2015-07-28 11:54:57 +00:00
this.$activitiesMore.hide();
2015-07-24 03:37:57 +00:00
this.activities.fetch({
remove: false,
data: {'start': _this.moreOffset},
success: function() {
_this.render();
}
});
},
render: function () {
var activitiesJson = this.activities.toJSON(),
len = activitiesJson.length,
more = activitiesJson[len-1]['more'],
allActivities = [];
this.$loadingTip.hide();
2015-07-28 11:54:57 +00:00
this.$activitiesMore.hide();
2015-07-24 03:37:57 +00:00
this.moreOffset = activitiesJson[len-1]['more_offset'];
2015-07-28 11:54:57 +00:00
this.$activitiesBody.empty().show();
2015-07-24 03:37:57 +00:00
for (var i = 0; i < len; i++) {
allActivities = allActivities.concat(activitiesJson[i]['events']);
}
var groupedActivities = _.groupBy(allActivities, 'date');
for (var date in groupedActivities) {
2015-07-28 11:54:57 +00:00
var $activityGroup = $(this.activityGroupTemplate({'date': date})),
2015-07-24 03:37:57 +00:00
activityList = groupedActivities[date];
2015-07-28 11:54:57 +00:00
this.$activitiesBody.append($activityGroup);
2015-07-24 03:37:57 +00:00
_.each(activityList, function (activity) {
var view = new ActivityItemView(activity);
2015-07-28 11:54:57 +00:00
$activityGroup.children('ol').append(view.render().el);
2015-07-24 03:37:57 +00:00
});
}
if (more) {
2015-07-28 11:54:57 +00:00
this.$activitiesMore.show();
2015-07-24 03:37:57 +00:00
}
},
hide: function () {
this.$el.hide();
},
show: function () {
this.$el.show();
2015-07-28 11:54:57 +00:00
this.$activitiesBody.hide();
this.$activitiesMore.hide();
2015-07-24 03:37:57 +00:00
this.$loadingTip.show();
var _this = this;
this.activities.fetch({
data: {'start': 0},
success: function() {
_this.render();
}
});
}
});
2015-07-28 11:54:57 +00:00
return ActivitiesView;
2015-07-24 03:37:57 +00:00
});