diff options
author | Vincent Petry <pvince81@owncloud.com> | 2014-05-16 12:43:36 +0200 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2014-05-16 17:42:38 +0200 |
commit | 5a0281add84b0754404c9fa617c4f527fcef04dc (patch) | |
tree | 803d60bfc7bea9511a439754948ffea9e7543f6a /apps/files/js | |
parent | d5f60a8eb0b3521ba0d85e9191468f09ea37803e (diff) | |
download | nextcloud-server-5a0281add84b0754404c9fa617c4f527fcef04dc.tar.gz nextcloud-server-5a0281add84b0754404c9fa617c4f527fcef04dc.zip |
Fixed issues with renaming
- summary is now untouched on rename instead of bogus incrementation
- fixes "Share" status icon by only triggring "fileActionsReady" once
- row is now reinserted even when rename is cancelled, this removes the
hacky/buggy code that tried to rename the element back
- added unit tests to cover the fixed cases
Diffstat (limited to 'apps/files/js')
-rw-r--r-- | apps/files/js/filelist.js | 43 |
1 files changed, 21 insertions, 22 deletions
diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 38766e2b801..3dcd9dd3eaa 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -1184,10 +1184,22 @@ event.preventDefault(); try { var newName = input.val(); + input.tipsy('hide'); + form.remove(); + if (newName !== oldname) { checkInput(); - // mark as loading + // mark as loading (temp element) td.css('background-image', 'url('+ OC.imagePath('core', 'loading.gif') + ')'); + tr.attr('data-file', newName); + var basename = newName; + if (newName.indexOf('.') > 0 && tr.data('type') !== 'dir') { + basename = newName.substr(0, newName.lastIndexOf('.')); + } + td.find('a.name span.nametext').text(basename); + td.children('a.name').show(); + tr.find('.fileactions, .action').addClass('hidden'); + $.ajax({ url: OC.filePath('files','ajax','rename.php'), data: { @@ -1207,30 +1219,17 @@ // reinsert row self.files.splice(tr.index(), 1); tr.remove(); - self.add(fileInfo); + self.add(fileInfo, {updateSummary: false}); + self.$fileList.trigger($.Event('fileActionsReady')); } }); + } else { + // add back the old file info when cancelled + self.files.splice(tr.index(), 1); + tr.remove(); + self.add(oldFileInfo, {updateSummary: false}); + self.$fileList.trigger($.Event('fileActionsReady')); } - input.tipsy('hide'); - tr.data('renaming',false); - tr.attr('data-file', newName); - var path = td.children('a.name').attr('href'); - // FIXME this will fail if the path contains the filename. - td.children('a.name').attr('href', path.replace(encodeURIComponent(oldname), encodeURIComponent(newName))); - var basename = newName; - if (newName.indexOf('.') > 0 && tr.data('type') !== 'dir') { - basename = newName.substr(0, newName.lastIndexOf('.')); - } - td.find('a.name span.nametext').text(basename); - if (newName.indexOf('.') > 0 && tr.data('type') !== 'dir') { - if ( ! td.find('a.name span.extension').exists() ) { - td.find('a.name span.nametext').append('<span class="extension"></span>'); - } - td.find('a.name span.extension').text(newName.substr(newName.lastIndexOf('.'))); - } - form.remove(); - self.fileActions.display( tr.find('td.filename'), true); - td.children('a.name').show(); } catch (error) { input.attr('title', error); input.tipsy({gravity: 'w', trigger: 'manual'}); |