@@ -108,23 +108,11 @@ qx.Class.define("osparc.file.FileLabelWithActions", {
108
108
109
109
setItemSelected : function ( selectedItem ) {
110
110
if ( selectedItem ) {
111
+ this . __selection = [ selectedItem ] ;
111
112
const isFile = osparc . file . FilesTree . isFile ( selectedItem ) ;
112
113
this . getChildControl ( "download-button" ) . setEnabled ( isFile ) ;
113
- this . getChildControl ( "delete-button" ) . setEnabled ( isFile ) ;
114
- const selectedLabel = this . getChildControl ( "selected-label" ) ;
115
- if ( isFile ) {
116
- this . __selection = [ selectedItem ] ;
117
- selectedLabel . set ( {
118
- value : selectedItem . getLabel ( ) ,
119
- toolTipText : selectedItem . getFileId ( )
120
- } ) ;
121
- } else {
122
- this . __selection = [ ] ;
123
- selectedLabel . set ( {
124
- value : "" ,
125
- toolTipText : ""
126
- } ) ;
127
- }
114
+ this . getChildControl ( "delete-button" ) . setEnabled ( true ) ; // folders can also be deleted
115
+ this . getChildControl ( "selected-label" ) . setValue ( selectedItem . getLabel ( ) ) ;
128
116
} else {
129
117
this . resetSelection ( ) ;
130
118
}
@@ -138,7 +126,7 @@ qx.Class.define("osparc.file.FileLabelWithActions", {
138
126
} else {
139
127
const selectedLabel = this . getChildControl ( "selected-label" ) ;
140
128
selectedLabel . set ( {
141
- value : multiSelectionData . length + " files "
129
+ value : multiSelectionData . length + " items "
142
130
} ) ;
143
131
}
144
132
} else {
@@ -168,60 +156,86 @@ qx.Class.define("osparc.file.FileLabelWithActions", {
168
156
}
169
157
} ,
170
158
159
+ __retrieveURLAndDownloadFile : function ( file ) {
160
+ const fileId = file . getFileId ( ) ;
161
+ const locationId = file . getLocation ( ) ;
162
+ osparc . utils . Utils . retrieveURLAndDownload ( locationId , fileId )
163
+ . then ( data => {
164
+ if ( data ) {
165
+ osparc . DownloadLinkTracker . getInstance ( ) . downloadLinkUnattended ( data . link , data . fileName ) ;
166
+ }
167
+ } ) ;
168
+ } ,
169
+
171
170
__deleteSelected : function ( ) {
171
+ const toBeDeleted = [ ] ;
172
+ let isFolderSelected = false ;
172
173
if ( this . isMultiSelect ( ) ) {
173
- const requests = [ ] ;
174
174
this . __selection . forEach ( selection => {
175
- if ( selection && osparc . file . FilesTree . isFile ( selection ) ) {
176
- const request = this . __deleteFile ( selection ) ;
177
- if ( request ) {
178
- requests . push ( request ) ;
175
+ if ( selection ) {
176
+ toBeDeleted . push ( selection ) ;
177
+ if ( osparc . file . FilesTree . isDir ( selection ) ) {
178
+ isFolderSelected = true ;
179
179
}
180
180
}
181
181
} ) ;
182
- Promise . all ( requests )
183
- . then ( datas => {
184
- if ( datas . length ) {
185
- this . fireDataEvent ( "fileDeleted" , datas [ 0 ] ) ;
186
- osparc . FlashMessenger . getInstance ( ) . logAs ( this . tr ( "Files successfully deleted" ) , "INFO" ) ;
187
- }
188
- } ) ;
189
- requests
190
182
} else if ( this . __selection . length ) {
191
183
const selection = this . __selection [ 0 ] ;
192
- if ( selection && osparc . file . FilesTree . isFile ( selection ) ) {
193
- const request = this . __deleteFile ( selection ) ;
194
- if ( request ) {
195
- request
196
- . then ( data => {
197
- this . fireDataEvent ( "fileDeleted" , data ) ;
198
- osparc . FlashMessenger . getInstance ( ) . logAs ( this . tr ( "File successfully deleted" ) , "INFO" ) ;
199
- } ) ;
184
+ if ( selection ) {
185
+ if ( osparc . file . FilesTree . isDir ( selection ) ) {
186
+ isFolderSelected = true ;
200
187
}
201
188
}
202
189
}
190
+
191
+ let msg = this . tr ( "This operation cannot be undone." ) ;
192
+ msg += isFolderSelected ? ( "<br>" + this . tr ( "All the content of the folders will be deleted." ) ) : "" ;
193
+ msg += "<br>" + this . tr ( "Do you want to proceed?" ) ;
194
+ const confirmationWin = new osparc . ui . window . Confirmation ( msg ) . set ( {
195
+ caption : this . tr ( "Delete" ) ,
196
+ confirmText : this . tr ( "Delete" ) ,
197
+ confirmAction : "delete"
198
+ } ) ;
199
+ confirmationWin . center ( ) ;
200
+ confirmationWin . open ( ) ;
201
+ confirmationWin . addListener ( "close" , ( ) => {
202
+ if ( confirmationWin . getConfirmed ( ) ) {
203
+ this . __doDeleteSelected ( toBeDeleted ) ;
204
+ }
205
+ } , this ) ;
203
206
} ,
204
207
205
- __retrieveURLAndDownloadFile : function ( file ) {
206
- const fileId = file . getFileId ( ) ;
207
- const locationId = file . getLocation ( ) ;
208
- osparc . utils . Utils . retrieveURLAndDownload ( locationId , fileId )
209
- . then ( data => {
210
- if ( data ) {
211
- osparc . DownloadLinkTracker . getInstance ( ) . downloadLinkUnattended ( data . link , data . fileName ) ;
208
+ __doDeleteSelected : function ( toBeDeleted ) {
209
+ const requests = [ ] ;
210
+ toBeDeleted . forEach ( selection => {
211
+ if ( selection ) {
212
+ let request = null ;
213
+ if ( osparc . file . FilesTree . isFile ( selection ) ) {
214
+ request = this . __deleteItem ( selection . getFileId ( ) , selection . getLocation ( ) ) ;
215
+ } else {
216
+ request = this . __deleteItem ( selection . getPath ( ) , selection . getLocation ( ) ) ;
217
+ }
218
+ if ( request ) {
219
+ requests . push ( request ) ;
220
+ }
221
+ }
222
+ } ) ;
223
+ Promise . all ( requests )
224
+ . then ( datas => {
225
+ if ( datas . length ) {
226
+ this . fireDataEvent ( "fileDeleted" , datas [ 0 ] ) ;
227
+ osparc . FlashMessenger . getInstance ( ) . logAs ( this . tr ( "Items successfully deleted" ) , "INFO" ) ;
212
228
}
213
229
} ) ;
214
230
} ,
215
231
216
- __deleteFile : function ( file ) {
217
- const fileId = file . getFileId ( ) ;
218
- const locationId = file . getLocation ( ) ;
232
+ __deleteItem : function ( itemId , locationId ) {
219
233
if ( locationId !== 0 && locationId !== "0" ) {
220
- osparc . FlashMessenger . getInstance ( ) . logAs ( this . tr ( "Only files in simcore.s3 can be deleted" ) ) ;
234
+ osparc . FlashMessenger . getInstance ( ) . logAs ( this . tr ( "Only items in simcore.s3 can be deleted" ) ) ;
221
235
return null ;
222
236
}
223
237
const dataStore = osparc . store . Data . getInstance ( ) ;
224
- return dataStore . deleteFile ( locationId , fileId ) ;
238
+ return dataStore . deleteFile ( locationId , itemId ) ;
225
239
} ,
226
240
}
227
241
} ) ;
0 commit comments