diff --git a/assets/css/components/notifications/dropdown.css b/assets/css/components/notifications/dropdown.css new file mode 100644 index 00000000..83b5b748 --- /dev/null +++ b/assets/css/components/notifications/dropdown.css @@ -0,0 +1,10 @@ +/** + * Notifications dropdown stylesheet + * + * @author Pierre HUBERT + */ + +.no-notification-msg { + text-align: center; + padding: 20px; +} \ No newline at end of file diff --git a/assets/js/components/notifications/dropdown.js b/assets/js/components/notifications/dropdown.js index 4f48896b..03469b3d 100644 --- a/assets/js/components/notifications/dropdown.js +++ b/assets/js/components/notifications/dropdown.js @@ -64,6 +64,49 @@ ComunicWeb.components.notifications.dropdown = { class: "menu" }); + //Add dropdown bottom + var dropdownBottom = createElem2({ + appendTo: dropdownMenu, + type: "li", + class: "footer" + }); + + //Add a button to offer the user to delete all his notifications + var deleteAllLink = createElem2({ + appendTo: dropdownBottom, + type: "a", + href: "#", + innerHTML: "Delete all" + }); + + //Make the delete all notifications link lives + deleteAllLink.onclick = function(){ + + ComunicWeb.common.messages.confirm("Are you sure do you want to delete all the notifications ? This operation can not be cancelled !", function(accept){ + + //We continue only if the user confirmed the operation + if(!accept) + return; + + //Perform a request to the server through the interface + ComunicWeb.components.notifications.interface.delete_all(function(result){ + + //Check for errors + if(result.error){ + ComunicWeb.common.notificationSystem.showNotification("An error occured while trying to delete all the notifications !", "danger"); + return; + } + + //Display success + ComunicWeb.common.notificationSystem.showNotification("The entire list of notification has been cleared.", "success"); + + }); + + + }); + + }; + //Enable slimscroll $(notificationsList).slimScroll({ height: '100%' @@ -121,6 +164,13 @@ ComunicWeb.components.notifications.dropdown = { ComunicWeb.components.notifications.ui.display_notification(notification, list, users); } + //Display a message if there isn't any notification to display + if(result.length == 0){ + + list.innerHTML = "
  • You do not have any notification yet.
  • "; + + } + }, false); diff --git a/assets/js/components/notifications/interface.js b/assets/js/components/notifications/interface.js index 8978ac3d..ab774b46 100644 --- a/assets/js/components/notifications/interface.js +++ b/assets/js/components/notifications/interface.js @@ -58,4 +58,19 @@ ComunicWeb.components.notifications.interface = { ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback); }, + + /** + * Delete all the notifications of the user + * + * @param {function} callback + */ + delete_all: function(callback){ + + //Perform an API request + var apiURI = "notifications/delete_all"; + var params = {}; + + ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback); + + } } \ No newline at end of file diff --git a/system/config/dev.config.php b/system/config/dev.config.php index 9aa0daa6..3ac3b3db 100644 --- a/system/config/dev.config.php +++ b/system/config/dev.config.php @@ -147,6 +147,7 @@ class Dev { "css/components/comments/form.css", //Notifications component + "css/components/notifications/dropdown.css", "css/components/notifications/ui.css", //Pages stylesheets