]> source.dussan.org Git - nextcloud-server.git/commitdiff
Disallow ctrl click to select when selection not allowed
authorVincent Petry <pvince81@owncloud.com>
Thu, 15 Jan 2015 17:16:27 +0000 (18:16 +0100)
committerVincent Petry <pvince81@owncloud.com>
Thu, 15 Jan 2015 17:16:27 +0000 (18:16 +0100)
apps/files/js/filelist.js
apps/files/tests/js/filelistSpec.js

index f28c24fda87bc93a6475364fb808fa213964830e..c5c665cee77cb57de6447e53b16db5c9ddcf2dd3 100644 (file)
                 */
                _onClickFile: function(event) {
                        var $tr = $(event.target).closest('tr');
-                       if (event.ctrlKey || event.shiftKey) {
+                       if (this._allowSelection && (event.ctrlKey || event.shiftKey)) {
                                event.preventDefault();
                                if (event.shiftKey) {
                                        var $lastTr = $(this._lastChecked);
index c1c8e4ce33789d0f93be1c29a479d685688b6799..59e3f8a9d4eee5e436e8df9d91a1e809ed3297d5 100644 (file)
@@ -1790,6 +1790,36 @@ describe('OCA.Files.FileList tests', function() {
                        expect(fileList.$el.find('.select-all').prop('checked')).toEqual(false);
                        expect(fileList.getSelectedFiles()).toEqual([]);
                });
+               describe('Disabled selection', function() {
+                       beforeEach(function() {
+                               fileList._allowSelection = false;
+                               fileList.setFiles(testFiles);
+                       });
+                       it('Does not render checkboxes', function() {
+                               expect(fileList.$fileList.find('.selectCheckBox').length).toEqual(0);
+                       });
+                       it('Does not select a file with Ctrl or Shift if selection is not allowed', function() {
+                               var $tr = fileList.findFileEl('One.txt');
+                               var $tr2 = fileList.findFileEl('Three.pdf');
+                               var e;
+                               e = new $.Event('click');
+                               e.ctrlKey = true;
+                               $tr.find('td.filename .name').trigger(e);
+
+                               // click on second entry, does not clear the selection
+                               e = new $.Event('click');
+                               e.ctrlKey = true;
+                               $tr2.find('td.filename .name').trigger(e);
+
+                               expect(fileList.getSelectedFiles().length).toEqual(0);
+
+                               // deselect now
+                               e = new $.Event('click');
+                               e.shiftKey = true;
+                               $tr2.find('td.filename .name').trigger(e);
+                               expect(fileList.getSelectedFiles().length).toEqual(0);
+                       });
+               })
        });
        describe('File actions', function() {
                it('Clicking on a file name will trigger default action', function() {