From 5a10d5f75c29f91469fd683794b98fc2698b328e Mon Sep 17 00:00:00 2001 From: Mayhem Date: Mon, 20 Jan 2014 09:04:32 +0100 Subject: [PATCH] Re-select archives when the archives list gets updated or when we select an archive in the settings. --- src/Archive/Redirect.coffee | 36 ++++++++++++++++++++---------------- src/General/Settings.coffee | 2 ++ 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/Archive/Redirect.coffee b/src/Archive/Redirect.coffee index 27593edd1..400ae7ee4 100644 --- a/src/Archive/Redirect.coffee +++ b/src/Archive/Redirect.coffee @@ -1,31 +1,34 @@ Redirect = archives: `<%= JSON.stringify(grunt.file.readJSON('json/archives.json')) %>` - data: - thread: {} - post: {} - file: {} - init: -> + @selectArchives() + @update() + + selectArchives: -> + data = + thread: {} + post: {} + file: {} for boardID, data of Conf['selectedArchives'] for type, uid of data for archive in Conf['archives'] - continue if archive.uid isnt uid or type is 'post' and archive.software isnt 'foolfuuka' + continue if archive.uid isnt uid + break if type is 'post' and archive.software isnt 'foolfuuka' arr = if type is 'file' archive.files else archive.boards - Redirect.data[type][boardID] = archive if boardID in arr + data[type][boardID] = archive if boardID in arr + break for archive in Conf['archives'] for boardID in archive.boards - unless boardID of Redirect.data.thread - Redirect.data.thread[boardID] = archive - unless boardID of Redirect.data.post or archive.software isnt 'foolfuuka' - Redirect.data.post[boardID] = archive - unless boardID of Redirect.data.file or boardID not in archive.files - Redirect.data.file[boardID] = archive - - Redirect.update() - + unless boardID of data.thread + data.thread[boardID] = archive + unless boardID of data.post or archive.software isnt 'foolfuuka' + data.post[boardID] = archive + unless boardID of data.file or boardID not in archive.files + data.file[boardID] = archive + Redirect.data = data update: (cb) -> $.get 'lastarchivecheck', 0, ({lastarchivecheck}) -> now = Date.now() @@ -35,6 +38,7 @@ Redirect = $.ajax '<%= meta.page %>json/archives.json', onload: -> if @status is 200 Conf['archives'] = JSON.parse @response + Redirect.selectArchives() $.set lastarchivecheck: now archives: Conf['archives'] diff --git a/src/General/Settings.coffee b/src/General/Settings.coffee index 45aa8124b..370130eb2 100644 --- a/src/General/Settings.coffee +++ b/src/General/Settings.coffee @@ -435,6 +435,8 @@ Settings = saveSelectedArchive: -> $.get 'selectedArchives', Conf['selectedArchives'], ({selectedArchives}) => (selectedArchives[@dataset.boardID] or= {})[@dataset.type] = +@value + Conf['selectedArchives'] = selectedArchives + Redirect.selectArchives() $.set 'selectedArchives', selectedArchives keybinds: (section) ->