@@ -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 } ,
0 commit comments