@@ -154,6 +154,7 @@ qx.Class.define("osparc.study.Conversations", {
154154
155155 members : {
156156 __conversations : null ,
157+ __newConversationButton : null ,
157158 __wsHandlers : null ,
158159
159160 _createChildControlImpl : function ( id ) {
@@ -188,7 +189,7 @@ qx.Class.define("osparc.study.Conversations", {
188189 if ( conversation ) {
189190 switch ( eventName ) {
190191 case "conversation:created" :
191- this . __addConversation ( conversation ) ;
192+ this . __addConversationPage ( conversation ) ;
192193 break ;
193194 case "conversation:updated" :
194195 this . __updateConversation ( conversation ) ;
@@ -249,10 +250,10 @@ qx.Class.define("osparc.study.Conversations", {
249250 } ;
250251 osparc . data . Resources . fetch ( "conversations" , "getConversationsPage" , params )
251252 . then ( conversations => {
252- if ( conversations . length === 0 ) {
253- conversations . forEach ( conversation => this . __addConversation ( conversation ) ) ;
253+ if ( conversations . length ) {
254+ conversations . forEach ( conversation => this . __addConversationPage ( conversation ) ) ;
254255 } else {
255- this . __addTemporaryConversation ( ) ;
256+ this . __addTempConversationPage ( ) ;
256257 }
257258 } )
258259 . finally ( ( ) => {
@@ -261,38 +262,41 @@ qx.Class.define("osparc.study.Conversations", {
261262 } ) ;
262263 } ,
263264
264- __createConversation : function ( conversationData ) {
265+ __createConversationPage : function ( conversationData ) {
265266 const studyData = this . getStudyData ( ) ;
266- let conversation = null ;
267+ let conversationPage = null ;
267268 if ( conversationData ) {
268269 const conversationId = conversationData [ "conversationId" ] ;
269- conversation = new osparc . conversation . Conversation ( studyData , conversationId ) ;
270- conversation . setLabel ( conversationData [ "name" ] ) ;
271- conversation . addListener ( "conversationDeleted" , ( ) => {
272- console . log ( "Conversation deleted" ) ;
270+ conversationPage = new osparc . conversation . Conversation ( studyData , conversationId ) ;
271+ conversationPage . setLabel ( conversationData [ "name" ] ) ;
272+ conversationPage . addListener ( "conversationDeleted" , ( ) => {
273+ this . __deleteConversation ( conversationData ) ;
273274 } ) ;
274275 } else {
275276 // create a temporary conversation
276- conversation = new osparc . conversation . Conversation ( studyData ) ;
277- conversation . setLabel ( this . tr ( "new" ) ) ;
277+ conversationPage = new osparc . conversation . Conversation ( studyData ) ;
278+ conversationPage . setLabel ( this . tr ( "new" ) ) ;
278279 }
279- return conversation ;
280+ return conversationPage ;
280281 } ,
281282
282- __addTemporaryConversation : function ( ) {
283- const temporaryConversation = this . __createConversation ( ) ;
284-
285- const conversationsLayout = this . getChildControl ( "conversations-layout" ) ;
286- conversationsLayout . add ( temporaryConversation ) ;
283+ __addTempConversationPage : function ( ) {
284+ const temporaryConversationPage = this . __createConversationPage ( ) ;
285+ this . __addToPages ( temporaryConversationPage ) ;
287286 } ,
288287
289- __addConversation : function ( conversationData ) {
290- const conversation = this . __createConversation ( conversationData ) ;
288+ __addConversationPage : function ( conversationData ) {
289+ const conversationPage = this . __createConversationPage ( conversationData ) ;
290+ this . __addToPages ( conversationPage ) ;
291291
292- const conversationsLayout = this . getChildControl ( "conversations-layout" ) ;
293- conversationsLayout . add ( conversation ) ;
292+ this . __conversations . push ( conversationPage ) ;
293+
294+ return conversationPage ;
295+ } ,
294296
295- this . __conversations . push ( conversation ) ;
297+ __addToPages : function ( conversationPage ) {
298+ const conversationsLayout = this . getChildControl ( "conversations-layout" ) ;
299+ conversationsLayout . add ( conversationPage ) ;
296300
297301 if ( this . __newConversationButton === null ) {
298302 // initialize the new button only once
@@ -303,9 +307,11 @@ qx.Class.define("osparc.study.Conversations", {
303307 backgroundColor : "transparent" ,
304308 } ) ;
305309 newConversationButton . addListener ( "execute" , ( ) => {
310+ const studyData = this . getStudyData ( ) ;
306311 osparc . study . Conversations . addConversation ( studyData [ "uuid" ] , "new " + ( this . __conversations . length + 1 ) )
307312 . then ( conversationDt => {
308- this . __addConversation ( conversationDt ) ;
313+ const newConversationPage = this . __addConversationPage ( conversationDt ) ;
314+ conversationsLayout . setSelection ( [ newConversationPage ] ) ;
309315 } ) ;
310316 } ) ;
311317 conversationsLayout . getChildControl ( "bar" ) . add ( newConversationButton ) ;
@@ -322,6 +328,14 @@ qx.Class.define("osparc.study.Conversations", {
322328 const conversationsLayout = this . getChildControl ( "conversations-layout" ) ;
323329 conversationsLayout . remove ( conversation ) ;
324330 this . __conversations = this . __conversations . filter ( c => c !== conversation ) ;
331+
332+ const conversationPages = conversationsLayout . getSelectables ( ) ;
333+ if ( conversationPages . length ) {
334+ conversationsLayout . setSelection ( [ conversationPages [ 0 ] ] ) ;
335+ } else {
336+ // no conversations left, add a temporary one
337+ this . __addTempConversationPage ( ) ;
338+ }
325339 }
326340 } ,
327341
0 commit comments