Re-select archives when the archives list gets updated

or when we select an archive in the settings.
This commit is contained in:
Mayhem 2014-01-20 09:04:32 +01:00
parent f66bbee9f1
commit 5a10d5f75c
2 changed files with 22 additions and 16 deletions

View File

@ -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']

View File

@ -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) ->