@@ -231,119 +231,15 @@ qx.Class.define("osparc.dashboard.TutorialBrowser", {
231231
232232 // MENU //
233233 _populateCardMenu : function ( card ) {
234- const menu = card . getMenu ( ) ;
235- const templateData = card . getResourceData ( ) ;
236-
237- const editButton = this . __getEditTemplateMenuButton ( templateData ) ;
238- if ( editButton ) {
239- menu . add ( editButton ) ;
240- menu . addSeparator ( ) ;
241- }
242-
243- const openButton = this . _getOpenMenuButton ( templateData ) ;
244- if ( openButton ) {
245- menu . add ( openButton ) ;
246- }
247-
248- const shareButton = this . _getShareMenuButton ( card ) ;
249- if ( shareButton ) {
250- menu . add ( shareButton ) ;
251- }
252-
253- const tagsButton = this . _getTagsMenuButton ( card ) ;
254- if ( tagsButton ) {
255- menu . add ( tagsButton ) ;
256- }
257-
258- const deleteButton = this . __getDeleteTemplateMenuButton ( templateData ) ;
259- if ( deleteButton && editButton ) {
260- menu . addSeparator ( ) ;
261- menu . add ( deleteButton ) ;
262- }
263- } ,
264-
265- __getEditTemplateMenuButton : function ( templateData ) {
266- const isCurrentUserOwner = osparc . data . model . Study . canIWrite ( templateData [ "accessRights" ] ) ;
267- if ( ! isCurrentUserOwner ) {
268- return null ;
269- }
270-
271- const editButton = new qx . ui . menu . Button ( this . tr ( "Open" ) ) ;
272- editButton . addListener ( "execute" , ( ) => this . __editTemplate ( templateData ) , this ) ;
273- return editButton ;
234+ this . _populateTemplateCardMenu ( card ) ;
274235 } ,
275236
276237 __getTemplateData : function ( id ) {
277238 return this . _resourcesList . find ( template => template . uuid === id ) ;
278239 } ,
279240
280241 _deleteResourceRequested : function ( templateId ) {
281- this . __deleteTemplateRequested ( this . __getTemplateData ( templateId ) ) ;
282- } ,
283-
284- __deleteTemplateRequested : function ( templateData ) {
285- const rUSure = this . tr ( "Are you sure you want to delete " ) ;
286- const msg = rUSure + "<b>" + templateData . name + "</b>?" ;
287- const win = new osparc . ui . window . Confirmation ( msg ) . set ( {
288- caption : this . tr ( "Delete" ) ,
289- confirmText : this . tr ( "Delete" ) ,
290- confirmAction : "delete"
291- } ) ;
292- win . center ( ) ;
293- win . open ( ) ;
294- win . addListener ( "close" , ( ) => {
295- if ( win . getConfirmed ( ) ) {
296- this . __doDeleteTemplate ( templateData ) ;
297- }
298- } , this ) ;
299- } ,
300-
301- __getDeleteTemplateMenuButton : function ( templateData ) {
302- const isCurrentUserOwner = osparc . data . model . Study . canIDelete ( templateData [ "accessRights" ] ) ;
303- if ( ! isCurrentUserOwner ) {
304- return null ;
305- }
306-
307- const deleteButton = new qx . ui . menu . Button ( this . tr ( "Delete" ) , "@FontAwesome5Solid/trash/12" ) ;
308- deleteButton . set ( {
309- appearance : "menu-button"
310- } ) ;
311- osparc . utils . Utils . setIdToWidget ( deleteButton , "studyItemMenuDelete" ) ;
312- deleteButton . addListener ( "execute" , ( ) => this . __deleteTemplateRequested ( templateData ) , this ) ;
313- return deleteButton ;
314- } ,
315-
316- __editTemplate : function ( studyData ) {
317- const isStudyCreation = false ;
318- this . _startStudyById ( studyData . uuid , null , null , isStudyCreation ) ;
319- } ,
320-
321- __doDeleteTemplate : function ( studyData ) {
322- const myGid = osparc . auth . Data . getInstance ( ) . getGroupId ( ) ;
323- const collabGids = Object . keys ( studyData [ "accessRights" ] ) ;
324- const amICollaborator = collabGids . indexOf ( myGid ) > - 1 ;
325-
326- let operationPromise = null ;
327- if ( collabGids . length > 1 && amICollaborator ) {
328- const arCopy = osparc . utils . Utils . deepCloneObject ( studyData [ "accessRights" ] ) ;
329- // remove collaborator
330- delete arCopy [ myGid ] ;
331- operationPromise = osparc . store . Study . patchStudyData ( studyData , "accessRights" , arCopy ) ;
332- } else {
333- // delete study
334- operationPromise = osparc . store . Store . getInstance ( ) . deleteStudy ( studyData . uuid ) ;
335- }
336- operationPromise
337- . then ( ( ) => this . __removeFromTemplateList ( studyData . uuid ) )
338- . catch ( err => osparc . FlashMessenger . logError ( err ) ) ;
339- } ,
340-
341- __removeFromTemplateList : function ( templateId ) {
342- const idx = this . _resourcesList . findIndex ( study => study [ "uuid" ] === templateId ) ;
343- if ( idx > - 1 ) {
344- this . _resourcesList . splice ( idx , 1 ) ;
345- }
346- this . _resourcesContainer . removeCard ( templateId ) ;
242+ this . _deleteTemplateRequested ( this . __getTemplateData ( templateId ) ) ;
347243 } ,
348244 // MENU //
349245
0 commit comments