mirror of
				https://github.com/pierre42100/ComunicWeb
				synced 2025-11-04 04:04:20 +00:00 
			
		
		
		
	Created friendship request buttons
This commit is contained in:
		@@ -696,6 +696,20 @@ var ComunicWeb = {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								/**
 | 
				
			||||||
 | 
								 * Handle the rendering of the friendship status
 | 
				
			||||||
 | 
								 */
 | 
				
			||||||
 | 
								friendshipStatus: {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									/**
 | 
				
			||||||
 | 
									 * Display the friendship status
 | 
				
			||||||
 | 
									 */
 | 
				
			||||||
 | 
									display: function(userID, target){},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									//TODO : implement
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		/**
 | 
							/**
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -90,6 +90,25 @@ ComunicWeb.components.friends.list = {
 | 
				
			|||||||
		return true;
 | 
							return true;
 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Get the current status of a friendship relation
 | 
				
			||||||
 | 
						 * 
 | 
				
			||||||
 | 
						 * @param {Integer} friendID The ID of the target friend
 | 
				
			||||||
 | 
						 * @param {Function} callback What to do once we get the response
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						getStatus: function(friendID, callback){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							//Prepare the API request
 | 
				
			||||||
 | 
							var apiURI = "friends/getStatus";
 | 
				
			||||||
 | 
							var params = {
 | 
				
			||||||
 | 
								"friendID": friendID
 | 
				
			||||||
 | 
							};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							//Process request
 | 
				
			||||||
 | 
							ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Empty friends cache list
 | 
						 * Empty friends cache list
 | 
				
			||||||
	 * 
 | 
						 * 
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -110,7 +110,15 @@ ComunicWeb.pages.userPage.accessForbidden = {
 | 
				
			|||||||
		});
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		//Add friendship request message
 | 
							//Add friendship request message
 | 
				
			||||||
		
 | 
							var requestArea = createElem2({
 | 
				
			||||||
 | 
								appendTo: boxBody,
 | 
				
			||||||
 | 
								type: "div",
 | 
				
			||||||
 | 
								class: "text-center",
 | 
				
			||||||
 | 
								innerHTML: "Loading..."
 | 
				
			||||||
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							//Load friendship infos
 | 
				
			||||||
 | 
							ComunicWeb.pages.userPage.friendshipStatus.display(userInfos.userID, requestArea);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
							
								
								
									
										88
									
								
								assets/js/pages/userPage/friendshipStatus.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										88
									
								
								assets/js/pages/userPage/friendshipStatus.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,88 @@
 | 
				
			|||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Handle the update of the friendship status
 | 
				
			||||||
 | 
					 * 
 | 
				
			||||||
 | 
					 * @author Pierre HUBERT
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ComunicWeb.pages.userPage.friendshipStatus = {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Display the friendship status
 | 
				
			||||||
 | 
						 * 
 | 
				
			||||||
 | 
						 * @param {Integer} userID The ID of the target user
 | 
				
			||||||
 | 
						 * @param {HTMLElement} target The target element
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						display: function(userID, target){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							//Get the current status of the friendship
 | 
				
			||||||
 | 
							ComunicWeb.components.friends.list.getStatus(userID, function(response){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								//Empty the target area
 | 
				
			||||||
 | 
								emptyElem(target);
 | 
				
			||||||
 | 
								target.innerHTML = "";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								//Check for errors
 | 
				
			||||||
 | 
								if(response.error){
 | 
				
			||||||
 | 
									message = ComunicWeb.common.messages.createCalloutElem("Error", "Couldn't load friendship informations !", "danger");
 | 
				
			||||||
 | 
									target.appendChild(message);
 | 
				
			||||||
 | 
									return;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								//Check if the user has received a friendship request
 | 
				
			||||||
 | 
								if(response.received_request){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									//Offer the user to reject a frienship request
 | 
				
			||||||
 | 
									createElem2({
 | 
				
			||||||
 | 
										appendTo: target,
 | 
				
			||||||
 | 
										type: "button",
 | 
				
			||||||
 | 
										class: "btn btn-xs btn-danger",
 | 
				
			||||||
 | 
										innerHTML: "Reject request"
 | 
				
			||||||
 | 
									});
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									createElem2({
 | 
				
			||||||
 | 
										appendTo: target,
 | 
				
			||||||
 | 
										type: "span",
 | 
				
			||||||
 | 
										innerHTML: " ",
 | 
				
			||||||
 | 
									})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									//Offer the user to accept a frienship request
 | 
				
			||||||
 | 
									createElem2({
 | 
				
			||||||
 | 
										appendTo: target,
 | 
				
			||||||
 | 
										type: "button",
 | 
				
			||||||
 | 
										class: "btn btn-xs btn-success",
 | 
				
			||||||
 | 
										innerHTML: "Accept request"
 | 
				
			||||||
 | 
									});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								//Check if user has sent a friendship request
 | 
				
			||||||
 | 
								else if(response.sent_request){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									//Offer the user to cancel a frienship request
 | 
				
			||||||
 | 
									createElem2({
 | 
				
			||||||
 | 
										appendTo: target,
 | 
				
			||||||
 | 
										type: "button",
 | 
				
			||||||
 | 
										class: "btn btn-xs btn-danger",
 | 
				
			||||||
 | 
										innerHTML: "Cancel request"
 | 
				
			||||||
 | 
									});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								//Display default message
 | 
				
			||||||
 | 
								else {
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									//Offer the user to send a frienship request
 | 
				
			||||||
 | 
									createElem2({
 | 
				
			||||||
 | 
										appendTo: target,
 | 
				
			||||||
 | 
										type: "button",
 | 
				
			||||||
 | 
										class: "btn btn-xs btn-primary",
 | 
				
			||||||
 | 
										innerHTML: "Send request"
 | 
				
			||||||
 | 
									});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -175,6 +175,7 @@ $config['JSfiles'] = array(
 | 
				
			|||||||
		//User page
 | 
							//User page
 | 
				
			||||||
		"%PATH_ASSETS%js/pages/userPage/main.js",
 | 
							"%PATH_ASSETS%js/pages/userPage/main.js",
 | 
				
			||||||
		"%PATH_ASSETS%js/pages/userPage/accessForbidden.js",
 | 
							"%PATH_ASSETS%js/pages/userPage/accessForbidden.js",
 | 
				
			||||||
 | 
							"%PATH_ASSETS%js/pages/userPage/friendshipStatus.js",
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		//Login page
 | 
							//Login page
 | 
				
			||||||
		"%PATH_ASSETS%js/pages/login.js",
 | 
							"%PATH_ASSETS%js/pages/login.js",
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user