JS code improvement [SCI-442]

This commit is contained in:
Oleksii Kriuchykhin 2016-10-04 14:43:10 +02:00
parent 246dae4f46
commit 868ffd03d6
2 changed files with 5 additions and 3 deletions

View file

@ -1,9 +1,9 @@
$(document.body).ready(function () {
$('.btn-more-notifications')
.on("ajax:success", function (e, data) {
var list = $('.notifications-list');
var moreBtn = $('.btn-more-notifications');
if (data.html) {
var list = $('.notifications-list');
var moreBtn = $('.btn-more-notifications');
// Remove button if all notifications are shown
if (data.results_number < data.per_page) {
moreBtn.remove();
@ -12,6 +12,8 @@ $(document.body).ready(function () {
moreBtn.attr('href', data.more_notifications_url);
}
$(list).append(data.html);
} else if (data.results_number < 1) {
moreBtn.remove();
}
});
});

View file

@ -3,7 +3,7 @@ class UserNotificationsController < ApplicationController
def index
@last_notification_id = params[:from].to_i || 0
@per_page = 5
@per_page = 10
@notifications =
UserNotification.last_notifications(@current_user,