diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2018-03-20 03:36:08 +0100 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2018-03-20 03:36:08 +0100 |
| commit | 3221435ab09834cc95ef472528def0569cc92bc6 (patch) | |
| tree | c51ed29c1e2aa20ed146d6fe4dfc9db1ef0ffe03 /public/assets/js/lib/views/details/files.js | |
| parent | 8c0a0474ff9306ddaa5c54f616c8937c0bce099b (diff) | |
store sort of files
Diffstat (limited to 'public/assets/js/lib/views/details/files.js')
| -rw-r--r-- | public/assets/js/lib/views/details/files.js | 75 |
1 files changed, 61 insertions, 14 deletions
diff --git a/public/assets/js/lib/views/details/files.js b/public/assets/js/lib/views/details/files.js index 3c7f84f..cdefc1f 100644 --- a/public/assets/js/lib/views/details/files.js +++ b/public/assets/js/lib/views/details/files.js @@ -4,8 +4,9 @@ var FilesView = FormView.extend({ events: { "click .file": "pick", - "click #sortByName": "sortByName", - "click #sortByDate": "sortByDate", + "click #sortByName": "clickSortByName", + "click #sortByDate": "clickSortByDate", + "click #sortBySize": "clickSortBySize", }, initialize: function(){ @@ -14,7 +15,7 @@ var FilesView = FormView.extend({ this.templateTotal = this.$(".templateTotal").html() }, - load: function(files){ + load: function(files, thread){ if (! files.length) { this.$el.hide() } @@ -35,23 +36,36 @@ var FilesView = FormView.extend({ audio.init() } - this.sortByName() + this.resort(thread.settings.sort || "name_asc") }, files: [], sortedFiles: [], currentSort: 'name', reversed: false, - reverse: function(e){ - if (this.currentSort === 'name') { - this.sortByName() + resort: function(sort, reverse){ + if (sort.indexOf("_")) { + var s = sort.split("_") + sort = s[0] + reverse = s[1] + } + if (reverse === "asc" || !reverse) { + this.reversed = false } else { - this.sortByDate() + this.reversed = true + } + switch (sort) { + case 'name': + return this.sortByName() + case 'date': + return this.sortByDate() + case 'size': + return this.sortBySize() } }, - sortByName: function(e){ + clickSortByName: function(e){ e && e.preventDefault() if (this.currentSort !== 'name') { this.currentSort = 'name' @@ -59,10 +73,10 @@ var FilesView = FormView.extend({ } else { this.reversed = !this.reversed } - this.sort((a,b) => cmp(a.filename, b.filename)) + this.sortByName() return this }, - sortByDate: function(e){ + clickSortByDate: function(e){ e && e.preventDefault() if (this.currentSort !== 'date') { this.currentSort = 'date' @@ -70,13 +84,37 @@ var FilesView = FormView.extend({ } else { this.reversed = !this.reversed } - this.sort((a,b) => cmp(a.date, b.date)) + this.sortByDate() + return this + }, + clickSortBySize: function(e){ + e && e.preventDefault() + if (this.currentSort !== 'size') { + this.currentSort = 'size' + this.reversed = true + } else { + this.reversed = !this.reversed + } + this.sortBySize() return this }, + + sortByName: function(){ + this.currentSort = 'name' + this.sort((a,b) => cmp(a.filename, b.filename)) + }, + sortByDate: function(){ + this.currentSort = 'date' + this.sort((a,b) => cmp(a.date, b.date)) + }, + sortBySize: function(){ + this.currentSort = 'size' + this.sort((a,b) => cmp(a.size, b.size)) + }, sort: function(f){ this.$el.empty() - this.sortedFiles = this.reversed ? this.files.sort(f) : this.files.sort(f).reverse() + this.sortedFiles = this.reversed ? this.files.sort(f).reverse() : this.files.sort(f) this.sortedFiles.forEach(file => { this.appendFile(file) }) @@ -142,4 +180,13 @@ var FilesView = FormView.extend({ audio.play( e.target.dataset.index ) // index set in audio.js }, -})
\ No newline at end of file +}) + +var FILE_SORTS = [ + { key: "name_asc", label: "Name, a-z" }, + { key: "name_desc", label: "Name, z-a" }, + { key: "date_asc", label: "Date, oldest" }, + { key: "date_desc", label: "Date, newest" }, + { key: "size_asc", label: "Size, smallest" }, + { key: "size_desc", label: "Size, largest" }, +] |
