mirror of
				https://github.com/pierre42100/ComunicWeb
				synced 2025-11-04 12:14:12 +00:00 
			
		
		
		
	Can create friendship relations
This commit is contained in:
		@@ -90,6 +90,48 @@ ComunicWeb.components.friends.list = {
 | 
				
			|||||||
		return true;
 | 
							return true;
 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Send (create) a friendship request
 | 
				
			||||||
 | 
						 * 
 | 
				
			||||||
 | 
						 * @param {Integer} friendID The friend ID to respond
 | 
				
			||||||
 | 
						 * @param {Function} afterResponse Specify an action to do next
 | 
				
			||||||
 | 
						 * @return {Boolean} True for a success
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						sendRequest: function(friendID, afterResponse){
 | 
				
			||||||
 | 
							//Prepare the API request
 | 
				
			||||||
 | 
							var apiURI = "friends/sendRequest"
 | 
				
			||||||
 | 
							var params = {
 | 
				
			||||||
 | 
								"friendID": friendID,
 | 
				
			||||||
 | 
							};
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							//Process request
 | 
				
			||||||
 | 
							ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, afterResponse);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							//Success
 | 
				
			||||||
 | 
							return true;
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Remove (ancel) a friendship request
 | 
				
			||||||
 | 
						 * 
 | 
				
			||||||
 | 
						 * @param {Integer} friendID The target friendID
 | 
				
			||||||
 | 
						 * @param {Function} afterResponse Specify an action to do next
 | 
				
			||||||
 | 
						 * @return {Boolean} True for a success
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						removeRequest: function(friendID, afterResponse){
 | 
				
			||||||
 | 
							//Prepare the API request
 | 
				
			||||||
 | 
							var apiURI = "friends/removeRequest"
 | 
				
			||||||
 | 
							var params = {
 | 
				
			||||||
 | 
								"friendID": friendID,
 | 
				
			||||||
 | 
							};
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							//Process request
 | 
				
			||||||
 | 
							ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, afterResponse);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							//Success
 | 
				
			||||||
 | 
							return true;
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Get the current status of a friendship relation
 | 
						 * Get the current status of a friendship relation
 | 
				
			||||||
	 * 
 | 
						 * 
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -98,26 +98,66 @@ ComunicWeb.pages.userPage.friendshipStatus = {
 | 
				
			|||||||
			else if(response.sent_request){
 | 
								else if(response.sent_request){
 | 
				
			||||||
				
 | 
									
 | 
				
			||||||
				//Offer the user to cancel a frienship request
 | 
									//Offer the user to cancel a frienship request
 | 
				
			||||||
				createElem2({
 | 
									var cancelRequest = createElem2({
 | 
				
			||||||
					appendTo: target,
 | 
										appendTo: target,
 | 
				
			||||||
					type: "button",
 | 
										type: "button",
 | 
				
			||||||
					class: "btn btn-xs btn-danger",
 | 
										class: "btn btn-xs btn-danger",
 | 
				
			||||||
					innerHTML: "Cancel request"
 | 
										innerHTML: "Cancel request"
 | 
				
			||||||
				});
 | 
									});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									cancelRequest.onclick = function(){
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
										//Lock button
 | 
				
			||||||
 | 
										this.disabled = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
										//Send the request
 | 
				
			||||||
 | 
										ComunicWeb.components.friends.list.removeRequest(userID, function(response){
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
											//Check for errors
 | 
				
			||||||
 | 
											if(response.error){
 | 
				
			||||||
 | 
												ComunicWeb.common.notificationSystem.showNotification("An error occured while trying to remove the request !");
 | 
				
			||||||
 | 
											}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
											//Reload this component
 | 
				
			||||||
 | 
											ComunicWeb.pages.userPage.friendshipStatus.display(userID, target);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
										});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			//Display default message
 | 
								//Display send request message
 | 
				
			||||||
			else {
 | 
								else if(response.are_friend == false) {
 | 
				
			||||||
				
 | 
									
 | 
				
			||||||
				//Offer the user to send a frienship request
 | 
									//Offer the user to send a frienship request
 | 
				
			||||||
				createElem2({
 | 
									var sendRequestButton = createElem2({
 | 
				
			||||||
					appendTo: target,
 | 
										appendTo: target,
 | 
				
			||||||
					type: "button",
 | 
										type: "button",
 | 
				
			||||||
					class: "btn btn-xs btn-primary",
 | 
										class: "btn btn-xs btn-primary",
 | 
				
			||||||
					innerHTML: "Send request"
 | 
										innerHTML: "Send request"
 | 
				
			||||||
				});
 | 
									});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									sendRequestButton.onclick = function(){
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
										//Lock button
 | 
				
			||||||
 | 
										this.disabled = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
										//Send the request
 | 
				
			||||||
 | 
										ComunicWeb.components.friends.list.sendRequest(userID, function(response){
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
											//Check for errors
 | 
				
			||||||
 | 
											if(response.error){
 | 
				
			||||||
 | 
												ComunicWeb.common.notificationSystem.showNotification("An error occured while trying to send the request !");
 | 
				
			||||||
 | 
											}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
											//Reload this component
 | 
				
			||||||
 | 
											ComunicWeb.pages.userPage.friendshipStatus.display(userID, target);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
										});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user