diff --git a/assets/js/common/functionsSchema.js b/assets/js/common/functionsSchema.js index 930e06b9..012ebadd 100644 --- a/assets/js/common/functionsSchema.js +++ b/assets/js/common/functionsSchema.js @@ -810,7 +810,14 @@ var ComunicWeb = { */ unreadDropdown: { //TODO : implementd - } + }, + + /** + * Conversation message editor + */ + messageEditor: { + //TODO : implement + }, }, /** diff --git a/assets/js/components/conversations/chatWindows.js b/assets/js/components/conversations/chatWindows.js index e7458c09..0469bd14 100644 --- a/assets/js/components/conversations/chatWindows.js +++ b/assets/js/components/conversations/chatWindows.js @@ -935,6 +935,33 @@ ComunicWeb.components.conversations.chatWindows = { //Add message options if(userIsPoster){ + //Update message content + var updateLi = createElem2({ + type: "li", + appendTo: dropdownMenu + }); + + var updateLink = createElem2({ + type: "a", + appendTo: updateLi, + innerHTML: "Edit" + }); + + updateLink.addEventListener("click", function(){ + ComunicWeb.components.conversations.messageEditor.open(message, function(newContent){ + + //Apply and parse new message + textMessage.innerHTML = removeHtmlTags(newContent); + ComunicWeb.components.textParser.parse({ + element: textMessage, + }); + + }); + }); + + + + //Delete the message var deleteLi = createElem2({ type: "li", diff --git a/assets/js/components/conversations/interface.js b/assets/js/components/conversations/interface.js index 082280cf..ab2604c3 100644 --- a/assets/js/components/conversations/interface.js +++ b/assets/js/components/conversations/interface.js @@ -363,6 +363,29 @@ ComunicWeb.components.conversations.interface = { }, + /** + * Intend to update the content of a single message + * + * @param {Number} messageID The ID of the message to update + * @param {String} content New content for the message + * @param {(success : Boolean) => any} callback Function called when + * the request is terminated + */ + UpdateSingleMessage: function(messageID, content, callback){ + ComunicWeb.common.api.makeAPIrequest( + "conversations/updateMessage", + { + "messageID": messageID, + "content": content + }, + true, + + function(result){ + callback(result.error ? false : true); + } + ); + }, + /** * Intend to delete a single conversation message * diff --git a/assets/js/components/conversations/messageEditor.js b/assets/js/components/conversations/messageEditor.js new file mode 100644 index 00000000..2d5be7bc --- /dev/null +++ b/assets/js/components/conversations/messageEditor.js @@ -0,0 +1,46 @@ +/** + * Conversation message editor + * + * @author Pierre HUBERT + */ + +ComunicWeb.components.conversations.messageEditor = { + + /** + * Open conversation message editor + * + * @param {Object} message Information about the message to open + * @param {(newcontent : String) => any} callback Callback function called only + * when the new message content has been applied + */ + open: function(message, callback){ + + ComunicWeb.common.messages.inputString( + "Update message content", + "Please specify the new content of the message:", + message.message, + + function(content){ + + //Intend to update message content + ComunicWeb.components.conversations.interface.UpdateSingleMessage( + message.ID, + content, + + function(result){ + + if(!result) + return notify("Could not update conversation message content!", "danger"); + + message.message = content; + callback(content); + + } + ); + + } + ); + + } + +} \ No newline at end of file diff --git a/system/config/dev.config.php b/system/config/dev.config.php index 061b6c2f..12a5bbaf 100644 --- a/system/config/dev.config.php +++ b/system/config/dev.config.php @@ -370,6 +370,7 @@ class Dev { "js/components/conversations/cachingOpened.js", "js/components/conversations/utils.js", "js/components/conversations/unreadDropdown.js", + "js/components/conversations/messageEditor.js", //User selector "js/components/userSelect/userSelect.js",