@@ -205,13 +205,16 @@ var OCdialogs = {
205205 }
206206
207207 var emptyText = t ( 'core' , 'No files in here' ) ;
208+ var newText = t ( 'files' , 'New folder' ) ;
208209 if ( type === this . FILEPICKER_TYPE_COPY || type === this . FILEPICKER_TYPE_MOVE || type === this . FILEPICKER_TYPE_COPY_MOVE ) {
209210 emptyText = t ( 'core' , 'No more subfolders in here' ) ;
210211 }
211212
212213 this . filepicker . loading = true ;
213214 this . filepicker . filesClient = ( OCA . Sharing && OCA . Sharing . PublicApp && OCA . Sharing . PublicApp . fileList ) ? OCA . Sharing . PublicApp . fileList . filesClient : OC . Files . getClient ( ) ;
214215
216+ this . filelist = null ;
217+
215218 $ . when ( this . _getFilePickerTemplate ( ) ) . then ( function ( $tmpl ) {
216219 self . filepicker . loading = false ;
217220 var dialogName = 'oc-dialog-filepicker-content' ;
@@ -229,7 +232,8 @@ var OCdialogs = {
229232 self . $filePicker = $tmpl . octemplate ( {
230233 dialog_name : dialogName ,
231234 title : title ,
232- emptytext : emptyText
235+ emptytext : emptyText ,
236+ newtext : newText
233237 } ) . data ( 'path' , '' ) . data ( 'multiselect' , multiselect ) . data ( 'mimetype' , mimetypeFilter ) ;
234238
235239 if ( modal === undefined ) {
@@ -254,6 +258,86 @@ var OCdialogs = {
254258 self . _getGridSettings ( ) ;
255259 }
256260
261+ var newButton = self . $filePicker . find ( '.actions.creatable .button-add' ) ;
262+ newButton . on ( 'focus' , function ( ) {
263+ self . $filePicker . ocdialog ( 'setEnterCallback' , function ( ) {
264+ event . stopImmediatePropagation ( ) ;
265+ event . preventDefault ( ) ;
266+ newButton . click ( ) ;
267+ } ) ;
268+ } ) ;
269+ newButton . on ( 'blur' , function ( ) {
270+ self . $filePicker . ocdialog ( 'unsetEnterCallback' ) ;
271+ } ) ;
272+
273+ OC . registerMenu ( newButton , self . $filePicker . find ( '.menu' ) , function ( ) {
274+ $input . focus ( ) ;
275+ self . $filePicker . ocdialog ( 'setEnterCallback' , function ( ) {
276+ event . stopImmediatePropagation ( ) ;
277+ event . preventDefault ( ) ;
278+ self . $form . submit ( ) ;
279+ } ) ;
280+ var newName = $input . val ( ) ;
281+ lastPos = newName . lastIndexOf ( '.' ) ;
282+ if ( lastPos === - 1 ) {
283+ lastPos = newName . length ;
284+ }
285+ $input . selectRange ( 0 , lastPos ) ;
286+ } ) ;
287+ var $form = self . $filePicker . find ( '.filenameform' ) ;
288+ var $input = $form . find ( 'input[type=\'text\']' ) ;
289+ var $submit = $form . find ( 'input[type=\'submit\']' ) ;
290+ $submit . on ( 'click' , function ( event ) {
291+ event . stopImmediatePropagation ( ) ;
292+ event . preventDefault ( ) ;
293+ $form . submit ( ) ;
294+ } ) ;
295+
296+ var checkInput = function ( ) {
297+ var filename = $input . val ( ) ;
298+ try {
299+ if ( ! Files . isFileNameValid ( filename ) ) {
300+ // Files.isFileNameValid(filename) throws an exception itself
301+ } else if ( self . filelist . find ( function ( file ) { return file . name === this ; } , filename ) ) {
302+ throw t ( 'files' , '{newName} already exists' , { newName : filename } , undefined , {
303+ escape : false
304+ } ) ;
305+ } else {
306+ return true ;
307+ }
308+ } catch ( error ) {
309+ $input . attr ( 'title' , error ) ;
310+ $input . tooltip ( { placement : 'right' , trigger : 'manual' , 'container' : '.newFolderMenu' } ) ;
311+ $input . tooltip ( 'fixTitle' ) ;
312+ $input . tooltip ( 'show' ) ;
313+ $input . addClass ( 'error' ) ;
314+ }
315+ return false ;
316+ } ;
317+
318+ $form . on ( 'submit' , function ( event ) {
319+ event . stopPropagation ( ) ;
320+ event . preventDefault ( ) ;
321+
322+ if ( checkInput ( ) ) {
323+ var newname = $input . val ( ) ;
324+ self . filepicker . filesClient . createDirectory ( self . $filePicker . data ( 'path' ) + "/" + newname ) . always ( function ( status ) {
325+ self . _fillFilePicker ( self . $filePicker . data ( 'path' ) + newname ) ;
326+ } ) ;
327+ OC . hideMenus ( ) ;
328+ self . $filePicker . ocdialog ( 'unsetEnterCallback' ) ;
329+ self . $filePicker . click ( ) ;
330+ $input . val ( newText ) ;
331+ }
332+ } ) ;
333+ $input . keypress ( function ( event ) {
334+ if ( event . keyCode === 13 || event . which === 13 ) {
335+ event . stopImmediatePropagation ( ) ;
336+ event . preventDefault ( ) ;
337+ $form . submit ( ) ;
338+ }
339+ } ) ;
340+
257341 self . $filePicker . ready ( function ( ) {
258342 self . $fileListHeader = self . $filePicker . find ( '.filelist thead tr' ) ;
259343 self . $filelist = self . $filePicker . find ( '.filelist tbody' ) ;
@@ -912,6 +996,7 @@ var OCdialogs = {
912996 self . $fileListHeader . find ( '[data-sort=' + self . filepicker . sortField + '] .sort-indicator' ) . addClass ( 'icon-triangle-s' ) ;
913997 }
914998 self . filepicker . filesClient . getFolderContents ( dir ) . then ( function ( status , files ) {
999+ self . filelist = files ;
9151000 if ( filter && filter . length > 0 && filter . indexOf ( '*' ) === - 1 ) {
9161001 files = files . filter ( function ( file ) {
9171002 return file . type === 'dir' || filter . indexOf ( file . mimetype ) !== - 1 ;
0 commit comments