]> source.dussan.org Git - nextcloud-server.git/commitdiff
Client side sort for sharing overview
authorVincent Petry <pvince81@owncloud.com>
Fri, 15 Aug 2014 14:52:41 +0000 (16:52 +0200)
committerVincent Petry <pvince81@owncloud.com>
Fri, 15 Aug 2014 14:52:41 +0000 (16:52 +0200)
Since the server doesn't support sorting, use client side sort directly
instead of calling reload() first.

apps/files/js/filelist.js
apps/files_sharing/js/sharedfilelist.js

index d443dd2fd7dc5e1c167ae2f9cc4714d485b044ea..fc251c9201aab7f02e4cefcaf63be65c692ce827 100644 (file)
                 */
                _sortComparator: null,
 
+               /**
+                * Whether to do a client side sort.
+                * When false, clicking on a table header will call reload().
+                * When true, clicking on a table header will simply resort the list.
+                */
+               _clientSideSort: false,
+
                /**
                 * Current directory
                 */
                        sort = $target.attr('data-sort');
                        if (sort) {
                                if (this._sort === sort) {
-                                       this.setSort(sort, (this._sortDirection === 'desc')?'asc':'desc');
+                                       this.setSort(sort, (this._sortDirection === 'desc')?'asc':'desc', true);
                                }
                                else {
                                        if ( sort === 'name' ) {        //default sorting of name is opposite to size and mtime
-                                               this.setSort(sort, 'asc');
+                                               this.setSort(sort, 'asc', true);
                                        }
                                        else {
-                                               this.setSort(sort, 'desc');
+                                               this.setSort(sort, 'desc', true);
                                        }
                                }
-                               this.reload();
                        }
                },
 
                 *
                 * @param sort sort attribute name
                 * @param direction sort direction, one of "asc" or "desc"
+                * @param update true to update the list, false otherwise (default)
                 */
-               setSort: function(sort, direction) {
+               setSort: function(sort, direction, update) {
                        var comparator = FileList.Comparators[sort] || FileList.Comparators.name;
                        this._sort = sort;
                        this._sortDirection = (direction === 'desc')?'desc':'asc';
                                .removeClass(this.SORT_INDICATOR_DESC_CLASS)
                                .toggleClass('hidden', false)
                                .addClass(direction === 'desc' ? this.SORT_INDICATOR_DESC_CLASS : this.SORT_INDICATOR_ASC_CLASS);
+                       if (update) {
+                               if (this._clientSideSort) {
+                                       this.files.sort(this._sortComparator);
+                                       this.setFiles(this.files);
+                               }
+                               else {
+                                       this.reload();
+                               }
+                       }
                },
 
                /**
index 7a43185a2d7b2beb53ca1598c3e0f77228cef456..d29285dc1de7a21fdd8b4febdd14cfc4598eb90c 100644 (file)
@@ -28,6 +28,8 @@
                _sharedWithUser: false,
                _linksOnly: false,
 
+               _clientSideSort: true,
+
                initialize: function($el, options) {
                        OCA.Files.FileList.prototype.initialize.apply(this, arguments);
                        if (this.initialized) {