/*
    Calls at the page loading.
*/
$(function() {
    // Open a user notification.
    $(document).on('click', '#notifications-content .dropdown-item', function() {
        var $this = $(this);
        var reloadURL = $(this).attr('data-reload-url');
        var deleteURL = $(this).attr('data-delete-url');
        var $modal = $($('#notifications-content').attr('data-target'));

        $('.delete-item', $modal).attr('href', deleteURL).attr('data-delete-parent', '#'+$this.attr('id'));
        $('.modal-body', $modal).attr('data-reload-url', reloadURL).html('');
        $modal.modal('show');

        if (!$this.hasClass('read')) {
            var count = parseInt($('#dropdownNotifications .badge').text(), 10);
            if (_.isNaN(count) || count <= 1) {
                $('#dropdownNotifications i').hide();
            } else {
                $('#dropdownNotifications .badge').text(count-1);
            }

            $this.addClass('read');
        }
    });
});

/*
    Removes the notification from the list after deleting it.
*/
function closeNotificationModal() {
    $($('#notifications-content').attr('data-target')).modal('hide');
}