2021-05-31 19:32:31 +08:00
|
|
|
/* global animateSpinner globalActivities HelperModule */
|
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');
|
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;
|
2023-03-09 18:38:47 +08:00
|
|
|
existingLastDay.find('.activities-counter-label strong').text(newNumber);
|
2019-04-10 21:45:17 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-05-31 19:32:31 +08:00
|
|
|
function validateActivityFilterName() {
|
|
|
|
let filterName = $('#saveFilterModal .activity-filter-name-input').val();
|
|
|
|
$('#saveFilterModal .btn-confirm').prop('disabled', filterName.length === 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
$('#saveFilterModal')
|
|
|
|
.on('keyup', '.activity-filter-name-input', function() {
|
|
|
|
validateActivityFilterName();
|
|
|
|
})
|
|
|
|
.on('click', '.btn-confirm', function() {
|
|
|
|
$.ajax({
|
|
|
|
url: this.dataset.saveFilterUrl,
|
|
|
|
type: 'POST',
|
|
|
|
global: false,
|
|
|
|
dataType: 'json',
|
|
|
|
data: {
|
|
|
|
name: $('#saveFilterModal .activity-filter-name-input').val(),
|
|
|
|
filter: globalActivities.getFilters()
|
|
|
|
},
|
|
|
|
success: function(data) {
|
|
|
|
HelperModule.flashAlertMsg(data.message, 'success');
|
|
|
|
$('#saveFilterModal .activity-filter-name-input').val('');
|
|
|
|
validateActivityFilterName();
|
|
|
|
$('#saveFilterModal').modal('hide');
|
|
|
|
},
|
|
|
|
error: function(response) {
|
|
|
|
HelperModule.flashAlertMsg(response.responseJSON.errors.join(','), 'danger');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-02-27 23:02:53 +08:00
|
|
|
initExpandCollapseAllButtons();
|
|
|
|
initShowMoreButton();
|
2019-03-26 00:35:54 +08:00
|
|
|
}());
|