From 868ffd03d615abf336aa9bc2e1d3ea6e8d00f78b Mon Sep 17 00:00:00 2001 From: Oleksii Kriuchykhin Date: Tue, 4 Oct 2016 14:43:10 +0200 Subject: [PATCH] JS code improvement [SCI-442] --- app/assets/javascripts/notifications.js | 6 ++++-- app/controllers/user_notifications_controller.rb | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/notifications.js b/app/assets/javascripts/notifications.js index 38185e762..c8c697bc8 100644 --- a/app/assets/javascripts/notifications.js +++ b/app/assets/javascripts/notifications.js @@ -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(); } }); }); diff --git a/app/controllers/user_notifications_controller.rb b/app/controllers/user_notifications_controller.rb index b5bf2616f..afbc518f9 100644 --- a/app/controllers/user_notifications_controller.rb +++ b/app/controllers/user_notifications_controller.rb @@ -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,