]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix blurring of invalid file name on rename
authorVincent Petry <pvince81@owncloud.com>
Mon, 23 Jun 2014 14:35:11 +0000 (16:35 +0200)
committerVincent Petry <pvince81@owncloud.com>
Mon, 23 Jun 2014 14:35:11 +0000 (16:35 +0200)
When renaming to an existing file name, blurring the field should not
remove it.

This fix keeps the field until escape is pressed instead of replacing it
with a broken empty space.

apps/files/js/filelist.js
apps/files/tests/js/filelistSpec.js

index fb97b2f4595bb5eee9fa70f5ade9c78d1106e360..fc08d9b54fcdf9e2577ff06fc94c17bc94c02e65 100644 (file)
                                return true;
                        };
 
+                       function restore() {
+                               input.tipsy('hide');
+                               tr.data('renaming',false);
+                               form.remove();
+                               td.children('a.name').show();
+                       }
+
                        form.submit(function(event) {
                                event.stopPropagation();
                                event.preventDefault();
+                               if (input.hasClass('error')) {
+                                       return;
+                               }
+
                                try {
                                        var newName = input.val();
                                        input.tipsy('hide');
                                        input.addClass('error');
                                }
                                if (event.keyCode === 27) {
-                                       input.tipsy('hide');
-                                       tr.data('renaming',false);
-                                       form.remove();
-                                       td.children('a.name').show();
+                                       restore();
                                }
                        });
                        input.click(function(event) {
index 743ebf9706ac55ee5f3e902c5a53ebb772196c2d..0b0ff0412b2bedee12521d019f9d40ab506282c6 100644 (file)
@@ -591,6 +591,47 @@ describe('OCA.Files.FileList tests', function() {
                        expect($tr.find('.action').hasClass('hidden')).toEqual(true);
                        expect($tr.find('.fileactions').hasClass('hidden')).toEqual(true);
 
+                       // input and form are gone
+                       expect(fileList.$fileList.find('input.filename').length).toEqual(0);
+                       expect(fileList.$fileList.find('form').length).toEqual(0);
+               });
+               it('Validates the file name', function() {
+                       var $input, $tr;
+
+                       for (var i = 0; i < testFiles.length; i++) {
+                               fileList.add(testFiles[i], {silent: true});
+                       }
+
+                       // trigger rename prompt
+                       fileList.rename('One.txt');
+                       $input = fileList.$fileList.find('input.filename');
+                       $input.val('Two.jpg');
+
+                       // simulate key to trigger validation
+                       $input.trigger(new $.Event('keyup', {keyCode: 97}));
+
+                       // input is still there with error
+                       expect(fileList.$fileList.find('input.filename').length).toEqual(1);
+                       expect(fileList.$fileList.find('input.filename').hasClass('error')).toEqual(true);
+
+                       // trigger submit does not send server request
+                       $input.closest('form').trigger('submit');
+                       expect(fakeServer.requests.length).toEqual(0);
+
+                       // simulate escape key
+                       $input.trigger(new $.Event('keyup', {keyCode: 27}));
+
+                       // element is added back with the correct name
+                       $tr = fileList.findFileEl('One.txt');
+                       expect($tr.length).toEqual(1);
+                       expect($tr.find('a .nametext').text().trim()).toEqual('One.txt');
+                       expect($tr.find('a.name').is(':visible')).toEqual(true);
+
+                       $tr = fileList.findFileEl('Two.jpg');
+                       expect($tr.length).toEqual(1);
+                       expect($tr.find('a .nametext').text().trim()).toEqual('Two.jpg');
+                       expect($tr.find('a.name').is(':visible')).toEqual(true);
+
                        // input and form are gone
                        expect(fileList.$fileList.find('input.filename').length).toEqual(0);
                        expect(fileList.$fileList.find('form').length).toEqual(0);