@@ -39,6 +39,16 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
3939    "updateTemplates" : "qx.event.type.Event" 
4040  } , 
4141
42+   properties : { 
43+     multiSelection : { 
44+       check : "Boolean" , 
45+       init : false , 
46+       nullable : false , 
47+       event : "changeMultiSelection" , 
48+       apply : "__applyMultiSelection" 
49+     } 
50+   } , 
51+ 
4252  members : { 
4353    __studies : null , 
4454    __newStudyBtn : null , 
@@ -131,9 +141,22 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
131141
132142      const  importStudyButton  =  this . __createImportButton ( ) ; 
133143      this . _secondaryBar . add ( importStudyButton ) ; 
144+       importStudyButton . exclude ( ) ; 
145+       osparc . utils . DisabledPlugins . isImportDisabled ( ) 
146+         . then ( isDisabled  =>  { 
147+           importStudyButton . setVisibility ( isDisabled  ? "excluded"  : "visible" ) ; 
148+         } ) ; 
149+ 
150+       this . _secondaryBar . add ( new  qx . ui . core . Spacer ( ) ,  { 
151+         flex : 1 
152+       } ) ; 
153+ 
134154      const  studiesDeleteButton  =  this . __createDeleteButton ( false ) ; 
135155      this . _secondaryBar . add ( studiesDeleteButton ) ; 
136156
157+       const  selectStudiesButton  =  this . __createSelectButton ( ) ; 
158+       this . _secondaryBar . add ( selectStudiesButton ) ; 
159+ 
137160      osparc . utils . Utils . setIdToWidget ( this . _resourcesContainer ,  "studiesList" ) ; 
138161
139162      const  newStudyButton  =  this . __createNewStudyButton ( ) ; 
@@ -142,19 +165,11 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
142165      const  loadingStudiesBtn  =  this . _createLoadMoreButton ( "studiesLoading" ) ; 
143166      this . _resourcesContainer . add ( loadingStudiesBtn ) ; 
144167
145-       this . _resourcesContainer . addListener ( "changeSelection" ,  e  =>  { 
146-         const  nSelected  =  e . getData ( ) . length ; 
147-         this . _resourcesContainer . getChildren ( ) . forEach ( studyItem  =>  { 
148-           if  ( osparc . dashboard . ResourceBrowserBase . isCardButtonItem ( studyItem ) )  { 
149-             studyItem . setMultiSelectionMode ( Boolean ( nSelected ) ) ; 
150-           } 
151-         } ) ; 
152-       } ,  this ) ; 
153-       this . _resourcesContainer . bind ( "selection" ,  this . __newStudyBtn ,  "enabled" ,  { 
154-         converter : selection  =>  ! selection . length 
168+       this . bind ( "multiSelection" ,  this . __newStudyBtn ,  "enabled" ,  { 
169+         converter : val  =>  ! val 
155170      } ) ; 
156-       this . _resourcesContainer . bind ( "selection " ,  importStudyButton ,  "enabled" ,  { 
157-         converter : selection  =>  ! selection . length 
171+       this . bind ( "multiSelection " ,  importStudyButton ,  "enabled" ,  { 
172+         converter : val  =>  ! val 
158173      } ) ; 
159174      this . _resourcesContainer . bind ( "selection" ,  studiesDeleteButton ,  "visibility" ,  { 
160175        converter : selection  =>  selection . length  ? "visible"  : "excluded" 
@@ -249,6 +264,29 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
249264      return  deleteButton ; 
250265    } , 
251266
267+     __createSelectButton : function ( )  { 
268+       const  selectButton  =  new  qx . ui . form . ToggleButton ( ) . set ( { 
269+         marginRight : 8 
270+       } ) ; 
271+       selectButton . bind ( "value" ,  this ,  "multiSelection" ) ; 
272+       selectButton . bind ( "value" ,  selectButton ,  "label" ,  { 
273+         converter : val  =>  val  ? this . tr ( "Cancel Selection" )  : this . tr ( "Select Studies" ) 
274+       } ) ; 
275+       this . bind ( "multiSelection" ,  selectButton ,  "value" ) ; 
276+       return  selectButton ; 
277+     } , 
278+ 
279+     __applyMultiSelection : function ( value )  { 
280+       this . _resourcesContainer . getChildren ( ) . forEach ( studyItem  =>  { 
281+         if  ( osparc . dashboard . ResourceBrowserBase . isCardButtonItem ( studyItem ) )  { 
282+           studyItem . setMultiSelectionMode ( value ) ; 
283+           if  ( value  ===  false )  { 
284+             studyItem . setValue ( false ) ; 
285+           } 
286+         } 
287+       } ) ; 
288+     } , 
289+ 
252290    __getStudyAndStart : function ( loadStudyId )  { 
253291      const  params  =  { 
254292        url : { 
@@ -295,6 +333,7 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
295333      const  commandEsc  =  new  qx . ui . command . Command ( "Esc" ) ; 
296334      commandEsc . addListener ( "execute" ,  e  =>  { 
297335        this . resetSelection ( ) ; 
336+         this . setMultiSelection ( false ) ; 
298337      } ) ; 
299338      osparc . store . Store . getInstance ( ) . addListener ( "changeTags" ,  ( )  =>  { 
300339        this . invalidateStudies ( ) ; 
@@ -427,11 +466,6 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
427466        position : "bottom-right" 
428467      } ) ; 
429468
430-       const  selectButton  =  this . __getSelectMenuButton ( item ,  studyData ) ; 
431-       if  ( selectButton )  { 
432-         menu . add ( selectButton ) ; 
433-       } 
434- 
435469      const  renameStudyButton  =  this . __getRenameStudyMenuButton ( studyData ) ; 
436470      menu . add ( renameStudyButton ) ; 
437471
@@ -453,15 +487,6 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
453487      return  menu ; 
454488    } , 
455489
456-     __getSelectMenuButton : function ( item )  { 
457-       const  selectButton  =  new  qx . ui . menu . Button ( this . tr ( "Select" ) ) ; 
458-       selectButton . addListener ( "execute" ,  ( )  =>  { 
459-         item . setValue ( true ) ; 
460-         this . _resourcesContainer . setLastSelectedItem ( item ) ; 
461-       } ,  this ) ; 
462-       return  selectButton ; 
463-     } , 
464- 
465490    __getRenameStudyMenuButton : function ( studyData )  { 
466491      const  renameButton  =  new  qx . ui . menu . Button ( this . tr ( "Rename" ) ) ; 
467492      renameButton . addListener ( "execute" ,  ( )  =>  { 
@@ -550,8 +575,6 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
550575
551576    __itemClicked : function ( item ,  isShiftPressed )  { 
552577      const  studiesCont  =  this . _resourcesContainer ; 
553-       const  selected  =  item . getValue ( ) ; 
554-       const  selection  =  studiesCont . getSelection ( ) ; 
555578
556579      if  ( isShiftPressed )  { 
557580        const  lastIdx  =  studiesCont . getLastSelectedIndex ( ) ; 
@@ -566,7 +589,7 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
566589      } 
567590      studiesCont . setLastSelectedIndex ( studiesCont . getIndex ( item ) ) ; 
568591
569-       if  ( selected   &&   selection . length   ===   1 )  { 
592+       if  ( ! item . isMultiSelectionMode ( ) )  { 
570593        const  studyData  =  this . __getStudyData ( item . getUuid ( ) ,  false ) ; 
571594        this . _startStudy ( studyData ) ; 
572595      } 
0 commit comments