From 5b604ac2511019f79723d77705b0ebcf2a829375 Mon Sep 17 00:00:00 2001 From: buinsky Date: Mon, 8 Dec 2014 03:03:53 +0300 Subject: [PATCH] Save torrent list sort order in local storage --- src/webui/www/public/scripts/dynamicTable.js | 10 ++++++---- src/webui/www/public/scripts/mocha-init.js | 7 +++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/webui/www/public/scripts/dynamicTable.js b/src/webui/www/public/scripts/dynamicTable.js index b1687b04f..4e032b362 100644 --- a/src/webui/www/public/scripts/dynamicTable.js +++ b/src/webui/www/public/scripts/dynamicTable.js @@ -42,18 +42,20 @@ var dynamicTable = new Class({ this.priority_hidden = false; this.progressIndex = progressIndex; this.context_menu = context_menu; - this.table.sortedColumn = 'name'; // Default is NAME - this.table.reverseSort = false; + this.table.sortedColumn = getLocalStorageItem('sorted_column', 'name'); + this.table.reverseSort = getLocalStorageItem('reverse_sort', 'false');; }, setSortedColumn : function (column) { if (column != this.table.sortedColumn) { this.table.sortedColumn = column; - this.table.reverseSort = false; + this.table.reverseSort = 'false'; } else { // Toggle sort order - this.table.reverseSort = !this.table.reverseSort; + this.table.reverseSort = this.table.reverseSort == 'true' ? 'false' : 'true'; } + localStorage.setItem('sorted_column', column); + localStorage.setItem('reverse_sort', this.table.reverseSort); }, getCurrentTorrentHash : function () { diff --git a/src/webui/www/public/scripts/mocha-init.js b/src/webui/www/public/scripts/mocha-init.js index 5d6676a51..651bf19eb 100644 --- a/src/webui/www/public/scripts/mocha-init.js +++ b/src/webui/www/public/scripts/mocha-init.js @@ -22,6 +22,13 @@ if (typeof localStorage == 'undefined') { } } +function getLocalStorageItem(name, defaultVal) { + val = localStorage.getItem(name); + if (val === null || val === undefined) + val = defaultVal; + return val; +} + initializeWindows = function() { function addClickEvent(el, fn) {