1919qx . Class . define ( "osparc.conversation.AddMessage" , {
2020 extend : qx . ui . core . Widget ,
2121
22- /**
23- * @param studyData {Object} serialized Study Data
24- * @param conversationId {String} Conversation Id
25- */
26- construct : function ( studyData , conversationId = null , message = null ) {
22+ construct : function ( ) {
2723 this . base ( arguments ) ;
2824
29- this . __studyData = studyData ;
30- this . __conversationId = conversationId ;
31- this . __message = message ;
32-
3325 this . _setLayout ( new qx . ui . layout . VBox ( 5 ) ) ;
3426
3527 this . __buildLayout ( ) ;
3628 } ,
3729
30+ properties : {
31+ conversationId : {
32+ check : "String" ,
33+ init : null ,
34+ nullable : true ,
35+ event : "changeConversationId"
36+ } ,
37+
38+ studyData : {
39+ check : "Object" ,
40+ init : null ,
41+ nullable : true ,
42+ event : "changeStudyData" ,
43+ apply : "__applyStudyData" ,
44+ } ,
45+
46+ message : {
47+ check : "String" ,
48+ init : null ,
49+ nullable : true ,
50+ event : "changeMessage" ,
51+ apply : "__applyMessage" ,
52+ }
53+ } ,
54+
3855 events : {
3956 "messageAdded" : "qx.event.type.Data" ,
4057 "messageUpdated" : "qx.event.type.Data" ,
4158 } ,
4259
4360 members : {
44- __studyData : null ,
45- __conversationId : null ,
46- __message : null ,
47-
4861 _createChildControlImpl : function ( id ) {
4962 let control ;
5063 switch ( id ) {
@@ -111,7 +124,7 @@ qx.Class.define("osparc.conversation.AddMessage", {
111124 allowGrowX : false ,
112125 alignX : "right"
113126 } ) ;
114- control . setEnabled ( osparc . data . model . Study . canIWrite ( this . __studyData [ "accessRights" ] ) ) ;
127+ control . addListener ( "execute" , this . __addCommentPressed , this ) ;
115128 this . _add ( control ) ;
116129 break ;
117130 case "notify-user-button" :
@@ -120,7 +133,7 @@ qx.Class.define("osparc.conversation.AddMessage", {
120133 allowGrowX : false ,
121134 alignX : "right"
122135 } ) ;
123- control . setEnabled ( osparc . data . model . Study . canIWrite ( this . __studyData [ "accessRights" ] ) ) ;
136+ control . addListener ( "execute" , ( ) => this . __notifyUserTapped ( ) ) ;
124137 this . _add ( control ) ;
125138 break ;
126139 }
@@ -130,24 +143,37 @@ qx.Class.define("osparc.conversation.AddMessage", {
130143
131144 __buildLayout : function ( ) {
132145 this . getChildControl ( "thumbnail" ) ;
133- const commentField = this . getChildControl ( "comment-field" ) ;
134-
135- const addMessageButton = this . getChildControl ( "add-comment-button" ) ;
136- if ( this . __message ) {
137- // edit mode
138- addMessageButton . setLabel ( this . tr ( "Edit message" ) ) ;
139- addMessageButton . addListener ( "execute" , ( ) => this . __editComment ( ) ) ;
146+ this . getChildControl ( "comment-field" ) ;
147+ this . getChildControl ( "add-comment-button" ) ;
148+ this . getChildControl ( "notify-user-button" ) ;
149+ } ,
140150
141- commentField . setText ( this . __message [ "content" ] ) ;
151+ __applyStudyData : function ( studyData ) {
152+ if ( studyData ) {
153+ const canIWrite = osparc . data . model . Study . canIWrite ( this . __studyData [ "accessRights" ] )
154+ this . getChildControl ( "add-comment-button" ) . setEnabled ( canIWrite ) ;
155+ this . getChildControl ( "notify-user-button" ) . show ( ) ;
156+ this . getChildControl ( "notify-user-button" ) . setEnabled ( canIWrite ) ;
142157 } else {
143- // new message
144- addMessageButton . addListener ( "execute" , ( ) => this . __addComment ( ) ) ;
158+ this . getChildControl ( "notify-user-button" ) . exclude ( ) ;
159+ }
160+ } ,
161+
162+ __applyMessage : function ( message ) {
163+ if ( message ) {
164+ // edit mode
165+ const commentField = this . getChildControl ( "comment-field" ) ;
166+ commentField . setText ( message [ "content" ] ) ;
145167
146- const notifyUserButton = this . getChildControl ( "notify-user -button" ) ;
147- notifyUserButton . addListener ( "execute" , ( ) => this . __notifyUserTapped ( ) ) ;
168+ const addMessageButton = this . getChildControl ( "add-comment -button" ) ;
169+ addMessageButton . setLabel ( this . tr ( "Edit message" ) ) ;
148170 }
149171 } ,
150172
173+ __addCommentPressed : function ( ) {
174+ this . getMessage ( ) ? this . __editComment ( ) : this . __addComment ( ) ;
175+ } ,
176+
151177 __addComment : function ( ) {
152178 if ( this . __conversationId ) {
153179 this . __postMessage ( ) ;
@@ -161,6 +187,19 @@ qx.Class.define("osparc.conversation.AddMessage", {
161187 }
162188 } ,
163189
190+ __editComment : function ( ) {
191+ const commentField = this . getChildControl ( "comment-field" ) ;
192+ const content = commentField . getChildControl ( "text-area" ) . getValue ( ) ;
193+ if ( content ) {
194+ osparc . store . ConversationsProject . getInstance ( ) . editMessage ( this . __studyData [ "uuid" ] , this . __conversationId , this . __message [ "messageId" ] , content )
195+ . then ( data => {
196+ this . fireDataEvent ( "messageUpdated" , data ) ;
197+ commentField . getChildControl ( "text-area" ) . setValue ( "" ) ;
198+ } ) ;
199+ }
200+ } ,
201+
202+ /* NOTIFY USERS */
164203 __notifyUserTapped : function ( ) {
165204 const showOrganizations = false ;
166205 const showAccessRights = false ;
@@ -227,28 +266,21 @@ qx.Class.define("osparc.conversation.AddMessage", {
227266 } ) ;
228267 }
229268 } ,
269+ /* NOTIFY USERS */
230270
231271 __postMessage : function ( ) {
232272 const commentField = this . getChildControl ( "comment-field" ) ;
233273 const content = commentField . getChildControl ( "text-area" ) . getValue ( ) ;
234274 if ( content ) {
235- osparc . store . ConversationsProject . getInstance ( ) . addMessage ( this . __studyData [ "uuid" ] , this . __conversationId , content )
236- . then ( data => {
237- this . fireDataEvent ( "messageAdded" , data ) ;
238- commentField . getChildControl ( "text-area" ) . setValue ( "" ) ;
239- } ) ;
240- }
241- } ,
242-
243- __editComment : function ( ) {
244- const commentField = this . getChildControl ( "comment-field" ) ;
245- const content = commentField . getChildControl ( "text-area" ) . getValue ( ) ;
246- if ( content ) {
247- osparc . store . ConversationsProject . getInstance ( ) . editMessage ( this . __studyData [ "uuid" ] , this . __conversationId , this . __message [ "messageId" ] , content )
248- . then ( data => {
249- this . fireDataEvent ( "messageUpdated" , data ) ;
250- commentField . getChildControl ( "text-area" ) . setValue ( "" ) ;
251- } ) ;
275+ if ( this . __studyData ) {
276+ osparc . store . ConversationsProject . getInstance ( ) . addMessage ( this . __studyData [ "uuid" ] , this . __conversationId , content )
277+ . then ( data => {
278+ this . fireDataEvent ( "messageAdded" , data ) ;
279+ commentField . getChildControl ( "text-area" ) . setValue ( "" ) ;
280+ } ) ;
281+ } else {
282+ // Support
283+ }
252284 }
253285 } ,
254286
0 commit comments