Skip to content

Commit c8ed06c

Browse files
committed
progress on edit message
1 parent f6e25c1 commit c8ed06c

File tree

4 files changed

+60
-21
lines changed

4 files changed

+60
-21
lines changed

services/static-webserver/client/source/class/osparc/conversation/AddMessage.js

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@ qx.Class.define("osparc.conversation.AddMessage", {
2323
* @param studyData {Object} serialized Study Data
2424
* @param conversationId {String} Conversation Id
2525
*/
26-
construct: function(studyData, conversationId = null) {
26+
construct: function(studyData, conversationId = null, message = null) {
2727
this.base(arguments);
2828

2929
this.__studyData = studyData;
3030
this.__conversationId = conversationId;
31+
this.__message = message;
3132

3233
this._setLayout(new qx.ui.layout.VBox(5));
3334

@@ -36,11 +37,13 @@ qx.Class.define("osparc.conversation.AddMessage", {
3637

3738
events: {
3839
"commentAdded": "qx.event.type.Data",
40+
"messageEdited": "qx.event.type.Data",
3941
},
4042

4143
members: {
4244
__studyData: null,
4345
__conversationId: null,
46+
__message: null,
4447

4548
_createChildControlImpl: function(id) {
4649
let control;
@@ -120,13 +123,22 @@ qx.Class.define("osparc.conversation.AddMessage", {
120123

121124
__buildLayout: function() {
122125
this.getChildControl("thumbnail");
123-
this.getChildControl("comment-field");
126+
const commentField = this.getChildControl("comment-field");
124127

125128
const addMessageButton = this.getChildControl("add-comment-button");
126-
addMessageButton.addListener("execute", () => this.__addComment());
129+
if (this.__message) {
130+
// edit mode
131+
addMessageButton.setLabel(this.tr("Edit message"));
132+
addMessageButton.addListener("execute", () => this.__editComment());
133+
134+
commentField.setText(this.__message["content"]);
135+
} else {
136+
// new message
137+
addMessageButton.addListener("execute", () => this.__addComment());
127138

128-
const notifyUserButton = this.getChildControl("notify-user-button");
129-
notifyUserButton.addListener("execute", () => this.__notifyUserTapped());
139+
const notifyUserButton = this.getChildControl("notify-user-button");
140+
notifyUserButton.addListener("execute", () => this.__notifyUserTapped());
141+
}
130142
},
131143

132144
__addComment: function() {
@@ -211,13 +223,24 @@ qx.Class.define("osparc.conversation.AddMessage", {
211223

212224
__postMessage: function() {
213225
const commentField = this.getChildControl("comment-field");
214-
const comment = commentField.getChildControl("text-area").getValue();
215-
if (comment) {
216-
osparc.study.Conversations.addMessage(this.__studyData["uuid"], this.__conversationId, comment)
226+
const content = commentField.getChildControl("text-area").getValue();
227+
if (content) {
228+
osparc.study.Conversations.addMessage(this.__studyData["uuid"], this.__conversationId, content)
217229
.then(data => {
218230
this.fireDataEvent("commentAdded", data);
219231
commentField.getChildControl("text-area").setValue("");
220-
osparc.FlashMessenger.logAs(this.tr("Message added"), "INFO");
232+
});
233+
}
234+
},
235+
236+
__editComment: function() {
237+
const commentField = this.getChildControl("comment-field");
238+
const content = commentField.getChildControl("text-area").getValue();
239+
if (content) {
240+
osparc.study.Conversations.editMessage(this.__studyData["uuid"], this.__conversationId, this.__message["messageId"], content)
241+
.then(data => {
242+
this.fireDataEvent("messageEdited", data);
243+
commentField.getChildControl("text-area").setValue("");
221244
});
222245
}
223246
},

services/static-webserver/client/source/class/osparc/conversation/Conversation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ qx.Class.define("osparc.conversation.Conversation", {
238238
let control = null;
239239
switch (message["type"]) {
240240
case "MESSAGE":
241-
control = new osparc.conversation.MessageUI(message);
241+
control = new osparc.conversation.MessageUI(message, this.__studyData);
242242
control.addListener("messageEdited", () => this.fetchMessages());
243243
control.addListener("messageDeleted", () => this.fetchMessages());
244244
break;

services/static-webserver/client/source/class/osparc/conversation/MessageUI.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ qx.Class.define("osparc.conversation.MessageUI", {
2121

2222
/**
2323
* @param message {Object} message
24+
* @param studyData {Object?null} serialized Study Data
2425
*/
25-
construct: function(message) {
26+
construct: function(message, studyData = null) {
2627
this.base(arguments);
2728

2829
this.__message = message;
30+
this.__studyData = studyData;
2931

3032
const isMyMessage = this.self().isMyMessage(this.__message);
3133
const layout = new qx.ui.layout.Grid(12, 4);
@@ -187,13 +189,14 @@ qx.Class.define("osparc.conversation.MessageUI", {
187189
},
188190

189191
__editMessage: function() {
190-
const messageContent = this.getChildControl("message-content");
191-
const editDialog = new osparc.ui.dialog.EditMessageDialog(this.__message, messageContent.getValue());
192-
editDialog.addListener("messageEdited", e => {
193-
messageContent.setValue(e.getData());
194-
this.fireDataEvent("messageEdited", e.getData());
192+
const addMessage = new osparc.conversation.AddMessage(this.__studyData, this.__message["conversationId"], this.__message);
193+
addMessage.addListener("messageEdited", () => this.fireDataEvent("messageEdited"));
194+
const title = this.tr("Edit message");
195+
osparc.ui.window.Window.popUpInWindow(addMessage, title, 550, 135).set({
196+
clickAwayClose: false,
197+
resizable: true,
198+
showClose: true,
195199
});
196-
editDialog.open();
197200
},
198201

199202
__deleteMessage: function() {
@@ -207,10 +210,7 @@ qx.Class.define("osparc.conversation.MessageUI", {
207210
if (win.getConfirmed()) {
208211
console.log(this.__message);
209212
osparc.study.Conversations.deleteMessage(this.__message["studyId"], this.__message["conversationId"], this.__message["messageId"])
210-
.then(() => {
211-
this.fireEvent("messageDeleted");
212-
osparc.FlashMessenger.logAs(this.tr("Message deleted"), "INFO");
213-
});
213+
.then(() => this.fireEvent("messageDeleted"));
214214
}
215215
});
216216
},

services/static-webserver/client/source/class/osparc/study/Conversations.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,22 @@ qx.Class.define("osparc.study.Conversations", {
9494
.catch(err => osparc.FlashMessenger.logError(err));
9595
},
9696

97+
editMessage: function(studyId, conversationId, messageId, message) {
98+
const params = {
99+
url: {
100+
studyId,
101+
conversationId,
102+
messageId,
103+
},
104+
data: {
105+
"content": message,
106+
"type": "MESSAGE",
107+
},
108+
};
109+
return osparc.data.Resources.fetch("conversations", "editMessage", params)
110+
.catch(err => osparc.FlashMessenger.logError(err));
111+
},
112+
97113
deleteMessage: function(studyId, conversationId, messageId) {
98114
const params = {
99115
url: {

0 commit comments

Comments
 (0)