@@ -66,6 +66,30 @@ qx.Class.define("osparc.study.ConversationPage", {
6666 members : {
6767 __studyData : null ,
6868
69+ _createChildControlImpl : function ( id ) {
70+ let control ;
71+ switch ( id ) {
72+ case "n-messages" :
73+ control = new qx . ui . basic . Label ( ) ;
74+ this . _add ( control ) ;
75+ break ;
76+ case "conversation" :
77+ control = new osparc . study . Conversation ( this . __studyData ) ;
78+ this . bind ( "conversation" , control , "conversation" ) ;
79+ control . addListener ( "messagesChanged" , ( ) => this . __updateMessagesNumber ( ) ) ;
80+ this . _add ( control , {
81+ flex : 1 ,
82+ } ) ;
83+ break ;
84+ }
85+ return control || this . base ( arguments , id ) ;
86+ } ,
87+
88+ __buildLayout : function ( ) {
89+ this . getChildControl ( "n-messages" ) ;
90+ this . getChildControl ( "conversation" ) ;
91+ } ,
92+
6993 getConversationId : function ( ) {
7094 if ( this . getConversation ( ) ) {
7195 return this . getConversation ( ) . getConversationId ( ) ;
@@ -119,8 +143,8 @@ qx.Class.define("osparc.study.ConversationPage", {
119143 visibility : osparc . data . model . Study . canIWrite ( this . __studyData [ "accessRights" ] ) ? "visible" : "excluded" ,
120144 } ) ;
121145 closeButton . addListener ( "execute" , ( ) => {
122- // if ( this.__messagesList.getChildren().length === 0) {
123- if ( this . _messages . length === 0 ) {
146+ const messages = this . getChildControl ( "conversation" ) . getMessages ( ) ;
147+ if ( messages . length === 0 ) {
124148 osparc . store . ConversationsProject . getInstance ( ) . deleteConversation ( this . __studyData [ "uuid" ] , this . getConversationId ( ) ) ;
125149 } else {
126150 const msg = this . tr ( "Are you sure you want to delete the conversation?" ) ;
@@ -151,28 +175,16 @@ qx.Class.define("osparc.study.ConversationPage", {
151175 this . getChildControl ( "button" ) . setLabel ( newName ) ;
152176 } ,
153177
154- __buildLayout : function ( ) {
155- this . __messagesTitle = new qx . ui . basic . Label ( ) ;
156- this . _add ( this . __messagesTitle ) ;
157-
158- const conversation = new osparc . study . Conversation ( this . __studyData ) ;
159- this . bind ( "conversation" , conversation , "conversation" ) ;
160- this . _add ( conversation , {
161- flex : 1 ,
162- } ) ;
163- } ,
164-
165178 __updateMessagesNumber : function ( ) {
166- if ( ! this . __messagesTitle ) {
167- return ;
168- }
169- const nMessages = this . _messages . filter ( msg => msg [ "type" ] === "MESSAGE" ) . length ;
179+ const nMessagesLabel = this . getChildControl ( "n-messages" ) ;
180+ const messages = this . getChildControl ( "conversation" ) . getMessages ( ) ;
181+ const nMessages = messages . filter ( msg => msg [ "type" ] === "MESSAGE" ) . length ;
170182 if ( nMessages === 0 ) {
171- this . __messagesTitle . setValue ( this . tr ( "No Messages yet" ) ) ;
183+ nMessagesLabel . setValue ( this . tr ( "No Messages yet" ) ) ;
172184 } else if ( nMessages === 1 ) {
173- this . __messagesTitle . setValue ( this . tr ( "1 Message" ) ) ;
185+ nMessagesLabel . setValue ( this . tr ( "1 Message" ) ) ;
174186 } else if ( nMessages > 1 ) {
175- this . __messagesTitle . setValue ( nMessages + this . tr ( " Messages" ) ) ;
187+ nMessagesLabel . setValue ( nMessages + this . tr ( " Messages" ) ) ;
176188 }
177189 } ,
178190 }
0 commit comments