mirror of
https://github.com/pierre42100/ComunicWeb
synced 2024-11-26 13:59:23 +00:00
Created submitUpdateForm function
This commit is contained in:
parent
6408ab9b23
commit
5c6588513e
@ -160,15 +160,15 @@ ComunicWeb.components.conversations.chatWindows = {
|
|||||||
/**
|
/**
|
||||||
* Show conversation settings (button + pane)
|
* Show conversation settings (button + pane)
|
||||||
*
|
*
|
||||||
* @param {Object} infos Informations about the conversation
|
* @param {Object} conversation Informations about the conversation
|
||||||
* @return {Boolean} True for a success
|
* @return {Boolean} True for a success
|
||||||
*/
|
*/
|
||||||
showConversationSettings: function(infos){
|
showConversationSettings: function(conversation){
|
||||||
|
|
||||||
//Create and display conversation settings button wheel
|
//Create and display conversation settings button wheel
|
||||||
infos.box.settingsButton = createElem2({
|
conversation.box.settingsButton = createElem2({
|
||||||
type: "button",
|
type: "button",
|
||||||
insertBefore: infos.box.membersButton,
|
insertBefore: conversation.box.membersButton,
|
||||||
class: "btn btn-box-tool",
|
class: "btn btn-box-tool",
|
||||||
type: "button"
|
type: "button"
|
||||||
});
|
});
|
||||||
@ -176,19 +176,19 @@ ComunicWeb.components.conversations.chatWindows = {
|
|||||||
//Add button icon
|
//Add button icon
|
||||||
createElem2({
|
createElem2({
|
||||||
type: "i",
|
type: "i",
|
||||||
appendTo: infos.box.settingsButton,
|
appendTo: conversation.box.settingsButton,
|
||||||
class: "fa fa-gear",
|
class: "fa fa-gear",
|
||||||
});
|
});
|
||||||
|
|
||||||
//Create settings pane
|
//Create settings pane
|
||||||
var settingsPane = createElem2({
|
var settingsPane = createElem2({
|
||||||
type: "div",
|
type: "div",
|
||||||
appendTo: infos.box.boxBody,
|
appendTo: conversation.box.boxBody,
|
||||||
class: "conversation-settings-pane",
|
class: "conversation-settings-pane",
|
||||||
});
|
});
|
||||||
|
|
||||||
//Make the settings button lives
|
//Make the settings button lives
|
||||||
infos.box.settingsButton.onclick = function(){
|
conversation.box.settingsButton.onclick = function(){
|
||||||
//Update settings pane classname
|
//Update settings pane classname
|
||||||
if(settingsPane.className.includes(" open"))
|
if(settingsPane.className.includes(" open"))
|
||||||
settingsPane.className = settingsPane.className.replace(" open", ""); //Close the pane
|
settingsPane.className = settingsPane.className.replace(" open", ""); //Close the pane
|
||||||
@ -200,22 +200,84 @@ ComunicWeb.components.conversations.chatWindows = {
|
|||||||
var settingsForm = ComunicWeb.components.conversations.utils.createConversationForm(settingsPane);
|
var settingsForm = ComunicWeb.components.conversations.utils.createConversationForm(settingsPane);
|
||||||
|
|
||||||
//Update form informations
|
//Update form informations
|
||||||
settingsForm.createButton.innerHTML = "Update conversation";
|
settingsForm.createButton.innerHTML = "Update settings";
|
||||||
|
|
||||||
//Update conversation name
|
//Update conversation name
|
||||||
if(infos.infos.name)
|
if(conversation.infos.name)
|
||||||
settingsForm.conversationNameInput.value = infos.infos.name;
|
settingsForm.conversationNameInput.value = conversation.infos.name;
|
||||||
|
|
||||||
//Update conversation members
|
//Check if user is a ocnversation moderator or not
|
||||||
ComunicWeb.components.userSelect.pushEntries(settingsForm.usersElement, infos.infos.members);
|
if(conversation.infos.ID_owner == userID()){
|
||||||
|
//Update conversation members
|
||||||
|
ComunicWeb.components.userSelect.pushEntries(settingsForm.usersElement, conversation.infos.members);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//We disable name field
|
||||||
|
settingsForm.conversationNameInput.disabled = "true";
|
||||||
|
|
||||||
|
//We hide conversation users (presents in members pane)
|
||||||
|
settingsForm.usersElement.parentNode.style.display = "none";
|
||||||
|
}
|
||||||
|
|
||||||
//Update follow conversation checkbox
|
//Update follow conversation checkbox
|
||||||
|
if(conversation.infos.following == "1"){
|
||||||
|
$(settingsForm.followConversationInput).iCheck("check");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$(settingsForm.followConversationInput).iCheck("uncheck");
|
||||||
|
}
|
||||||
|
|
||||||
console.log(infos);
|
//Save settings form in global form
|
||||||
console.log(settingsForm);
|
conversation.settingsForm = settingsForm;
|
||||||
|
|
||||||
|
//Make update settings button lives
|
||||||
|
settingsForm.createButton.onclick = function(){
|
||||||
|
ComunicWeb.components.conversations.chatWindows.submitUpdateForm(conversation);
|
||||||
|
};
|
||||||
|
|
||||||
//Success
|
//Success
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process submited update conversation form
|
||||||
|
*
|
||||||
|
* @param {Object} conversation Informations about the conversation
|
||||||
|
* @return {Boolean} True for a success
|
||||||
|
*/
|
||||||
|
submitUpdateForm: function(conversation){
|
||||||
|
console.log(conversation);
|
||||||
|
|
||||||
|
//Then, get informations about the input
|
||||||
|
var newValues = {
|
||||||
|
following: conversation.settingsForm.followConversationInput.checked,
|
||||||
|
}
|
||||||
|
|
||||||
|
//Add other fields if the user is a conversation moderator
|
||||||
|
if(conversation.infos.ID_owner == userID()){
|
||||||
|
//Specify conversation name
|
||||||
|
var nameValue = conversation.settingsForm.conversationNameInput.value
|
||||||
|
newValues.name = (nameValue === "" ? false : nameValue);
|
||||||
|
|
||||||
|
//Get conversation members
|
||||||
|
newValues.members = ComunicWeb.components.userSelect.getResults(conversation.settingsForm.usersElement);
|
||||||
|
|
||||||
|
//Check if any users were selected
|
||||||
|
if(newValues.members.length === 0){
|
||||||
|
//Inform user that its input is invalid
|
||||||
|
ComunicWeb.common.notificationSystem.showNotification("Please select at least one user !", "danger", 3);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//Now, freeze the submit button
|
||||||
|
conversation.settingsForm.createButton.disabled = "true";
|
||||||
|
|
||||||
|
//Peform a request through the interface
|
||||||
|
|
||||||
|
//Success
|
||||||
|
return true;
|
||||||
|
},
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user