mirror of
				https://github.com/pierre42100/ComunicWeb
				synced 2025-11-04 04:04:20 +00:00 
			
		
		
		
	New structure to dropdown.js
This commit is contained in:
		@@ -6,12 +6,27 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
ComunicWeb.components.notifications.dropdown = {
 | 
					ComunicWeb.components.notifications.dropdown = {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Display new data dropdowns
 | 
				
			||||||
 | 
						 * 
 | 
				
			||||||
 | 
						 * @param {HTMLElement} target The target for the notification area
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						display: function(target){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							//Display the number of notifications
 | 
				
			||||||
 | 
							var notifs_number_elem = this.display_notifications_dropdown(target);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							//Initialize service
 | 
				
			||||||
 | 
							ComunicWeb.components.notifications.service.init(notifs_number_elem, true);
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Display notifications dropdown
 | 
						 * Display notifications dropdown
 | 
				
			||||||
	 * 
 | 
						 * 
 | 
				
			||||||
	 * @param {HTMLElement} target The target of the notification dropdown
 | 
						 * @param {HTMLElement} target The target of the notification dropdown
 | 
				
			||||||
 | 
						 * @return {HTMLElement} The HTML element that contains the number of unread notifications
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	display: function(target){
 | 
						display_notifications_dropdown: function(target){
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		//Create the button
 | 
							//Create the button
 | 
				
			||||||
		var dropdown = createElem2({
 | 
							var dropdown = createElem2({
 | 
				
			||||||
@@ -112,16 +127,13 @@ ComunicWeb.components.notifications.dropdown = {
 | 
				
			|||||||
			height: '100%'
 | 
								height: '100%'
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		//Initialize service
 | 
					 | 
				
			||||||
		ComunicWeb.components.notifications.service.init(notificationsNumber, true);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		//Refresh the notifications list if the user click the dropdown button
 | 
							//Refresh the notifications list if the user click the dropdown button
 | 
				
			||||||
		dropdownToggle.onclick = function(){
 | 
							dropdownToggle.onclick = function(){
 | 
				
			||||||
 | 
								ComunicWeb.components.notifications.dropdown.refresh_list_notifications(notificationsList);
 | 
				
			||||||
			ComunicWeb.components.notifications.dropdown.refresh_list(notificationsList);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
 | 
							//Return the number of notifications target
 | 
				
			||||||
 | 
							return notificationsNumber;
 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
@@ -129,7 +141,7 @@ ComunicWeb.components.notifications.dropdown = {
 | 
				
			|||||||
	 * 
 | 
						 * 
 | 
				
			||||||
	 * @param {HTMLElement} list The notifications list to refresh
 | 
						 * @param {HTMLElement} list The notifications list to refresh
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	refresh_list: function(list){
 | 
						refresh_list_notifications: function(list){
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		//Perform a request on the API
 | 
							//Perform a request on the API
 | 
				
			||||||
		ComunicWeb.components.notifications.interface.get_list_unread(function(result){
 | 
							ComunicWeb.components.notifications.interface.get_list_unread(function(result){
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -36,7 +36,7 @@ ComunicWeb.components.notifications.interface = {
 | 
				
			|||||||
		//Perform the request
 | 
							//Perform the request
 | 
				
			||||||
		ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback);
 | 
							ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	}
 | 
						},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Get the list of unread notifications
 | 
						 * Get the list of unread notifications
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -24,17 +24,17 @@ ComunicWeb.components.notifications.service = {
 | 
				
			|||||||
				return clearInterval(interval);
 | 
									return clearInterval(interval);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			//Get the number of notifications from the API
 | 
								//Get the number of notifications from the API
 | 
				
			||||||
			ComunicWeb.components.notifications.interface.getNbUnreads(function(response){
 | 
								ComunicWeb.components.notifications.interface.getAllUnread(function(response){
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				//Continue in case of success
 | 
									//Continue in case of success
 | 
				
			||||||
				if(response.error)
 | 
									if(response.error)
 | 
				
			||||||
					return;
 | 
										return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				//Update the target
 | 
									//Update the target
 | 
				
			||||||
				target.innerHTML = response.number;
 | 
									target.innerHTML = response.notifications;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				//If the number of notifications equals 0, hide the target if required
 | 
									//If the number of notifications equals 0, hide the target if required
 | 
				
			||||||
				if(response.number == 0 && auto_hide)
 | 
									if(response.notifications == 0 && auto_hide)
 | 
				
			||||||
					target.style.display = "none";
 | 
										target.style.display = "none";
 | 
				
			||||||
				else
 | 
									else
 | 
				
			||||||
					target.style.display = "block";
 | 
										target.style.display = "block";
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user