From 8fca36a7cd5af2af34c11f46c7877f66d9c934a8 Mon Sep 17 00:00:00 2001 From: jdcaballerov Date: Mon, 14 Dec 2020 12:52:15 -0500 Subject: [PATCH] Restore preferred snapshots view from localstorage --- archivebox/themes/admin/base.html | 34 +++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/archivebox/themes/admin/base.html b/archivebox/themes/admin/base.html index c5cb51c8..075d75a7 100644 --- a/archivebox/themes/admin/base.html +++ b/archivebox/themes/admin/base.html @@ -189,20 +189,46 @@ }; - function bindSnapshotViewsClick() { + function selectSnapshotListView(){ + myStorage.setItem('currentSnapshotView', 'List'); + redirectWithQuery("{% url 'admin:core_snapshot_changelist' %}"); + }; + + function selectSnapshotGridView(){ + myStorage.setItem('currentSnapshotView', 'Grid'); + redirectWithQuery("{% url 'admin:grid' %}"); + }; + + function setPreferredSnapshotView(view){ + urlPath = window.location.pathname; + + if((view==="Grid") && urlPath != "{% url 'admin:grid' %}"){ + selectSnapshotGridView(); + } + else if((view==="List") && urlPath != "{% url 'admin:core_snapshot_changelist' %}"){ + selectSnapshotListView(); + } + }; + + function setupSnapshotViews() { + myStorage = window.localStorage; + const preferredSnapshotView = localStorage.getItem('currentSnapshotView'); + setPreferredSnapshotView(preferredSnapshotView); + $( document ).ready(function() { + $("#snapshotListView").click(function() { - redirectWithQuery("{% url 'admin:core_snapshot_changelist' %}"); + selectSnapshotListView(); }); $("#snapshotGridView").click(function() { - redirectWithQuery("{% url 'admin:grid' %}"); + selectSnapshotGridView(); }); }); }; $(function () { fix_actions(); - bindSnapshotViewsClick(); + setupSnapshotViews(); }); })(django.jQuery);