2019-08-26 21:49:33 +08:00
|
|
|
/* global animateSpinner globalActivities */
|
2019-02-27 23:02:53 +08:00
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
2019-03-26 00:35:54 +08:00
|
|
|
(function() {
|
2019-02-27 23:02:53 +08:00
|
|
|
function initExpandCollapseAllButtons() {
|
2019-03-26 00:35:54 +08:00
|
|
|
$('#global-activities-colapse-all').on('click', function(ev) {
|
|
|
|
ev.preventDefault();
|
2019-02-27 23:02:53 +08:00
|
|
|
$('.activities-group').collapse('hide');
|
|
|
|
});
|
2019-03-26 00:35:54 +08:00
|
|
|
$('#global-activities-expand-all').on('click', function(ev) {
|
|
|
|
ev.preventDefault();
|
2019-02-27 23:02:53 +08:00
|
|
|
$('.activities-group').collapse('show');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function initShowMoreButton() {
|
|
|
|
var moreButton = $('.btn-more-activities');
|
|
|
|
moreButton.on('click', function(ev) {
|
2019-08-26 21:49:33 +08:00
|
|
|
var filters = globalActivities.getFilters();
|
2019-02-27 23:02:53 +08:00
|
|
|
ev.preventDefault();
|
|
|
|
animateSpinner(null, true);
|
2019-04-12 21:37:45 +08:00
|
|
|
filters.page = moreButton.data('next-page');
|
|
|
|
filters.starting_timestamp = $('.ga-activities-list').data('starting-timestamp');
|
2019-02-27 23:02:53 +08:00
|
|
|
$.ajax({
|
2019-03-15 22:52:30 +08:00
|
|
|
url: $('.ga-activities-list').data('activities-url'),
|
|
|
|
data: filters,
|
2019-02-27 23:02:53 +08:00
|
|
|
dataType: 'json',
|
|
|
|
type: 'POST',
|
|
|
|
success: function(json) {
|
2019-04-10 21:45:17 +08:00
|
|
|
var newFirstDay;
|
|
|
|
var existingLastDay;
|
|
|
|
|
|
|
|
// Attach newly fetched activities to temporary placeholder
|
|
|
|
$(json.activities_html).appendTo('#ga-more-activities-placeholder');
|
|
|
|
|
|
|
|
newFirstDay = $('#ga-more-activities-placeholder').find('.activities-day').first();
|
|
|
|
existingLastDay = $('.ga-activities-list').find('.activities-day').last();
|
|
|
|
|
|
|
|
if (newFirstDay.data('date') === existingLastDay.data('date')) {
|
|
|
|
let newNumber;
|
|
|
|
existingLastDay.find('.activities-group').append(newFirstDay.find('.activities-group').html());
|
|
|
|
newNumber = existingLastDay.find('.activity-card').length;
|
|
|
|
existingLastDay.find('.activities-counter-label strong').html(newNumber);
|
|
|
|
newFirstDay.remove();
|
|
|
|
}
|
|
|
|
|
|
|
|
$('.ga-activities-list').append($('#ga-more-activities-placeholder').html());
|
|
|
|
$('#ga-more-activities-placeholder').html('');
|
|
|
|
|
2019-04-12 21:37:45 +08:00
|
|
|
if (json.next_page) {
|
|
|
|
moreButton.data('next-page', json.next_page);
|
2019-02-27 23:02:53 +08:00
|
|
|
} else {
|
|
|
|
moreButton.addClass('hidden');
|
|
|
|
}
|
|
|
|
animateSpinner(null, false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
initExpandCollapseAllButtons();
|
|
|
|
initShowMoreButton();
|
2019-03-26 00:35:54 +08:00
|
|
|
}());
|