Add board selection to the archive selection.

Close seaweedchan/issues/80
This commit is contained in:
Zixaphir 2013-05-14 09:40:50 -07:00
parent 6bc0e8de92
commit 1bb474d28f
5 changed files with 284 additions and 224 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -346,34 +346,83 @@ Settings =
boards = {}
for name, archive of Redirect.archives
for boardID in archive.boards
if boardID is g.BOARD.ID
data = boards[boardID] or= {
thread: []
post: []
file: []
}
data.thread.push name
if archive.software is 'foolfuuka'
data.post.push name
if archive.files.contains boardID
data.file.push name
data = boards[boardID] or= {
thread: []
post: []
file: []
}
data.thread.push name
data.post.push name if archive.software is 'foolfuuka'
data.file.push name if archive.files.contains boardID
rows = []
boardOptions = []
for boardID in Object.keys(boards).sort() # Alphabetical order
row = $.el 'tr'
row = $.el 'tr',
className: "board-#{boardID}"
row.hidden = boardID isnt g.BOARD.ID
rows.push row
boardOptions.push $.el 'option',
textContent: "/#{boardID}/"
value: "board-#{boardID}"
selected: boardID is g.BOARD.ID
data = boards[boardID]
Settings.addArchiveCell row, boardID, data, 'thread'
Settings.addArchiveCell row, boardID, data, 'post'
Settings.addArchiveCell row, boardID, data, 'file'
$.add row, [
Settings.addArchiveCell boardID, data, 'thread'
Settings.addArchiveCell boardID, data, 'post'
Settings.addArchiveCell boardID, data, 'file'
]
$.add $('tbody', section), rows
boardSelect = $('#archive-board-select', section)
$.add boardSelect, boardOptions
table = $.id 'archive-table'
$.on boardSelect, 'change', ->
$('tbody > :not([hidden])', table).hidden = true
$("tbody > .#{@value}", table).hidden = false
$.get 'selectedArchives', Conf['selectedArchives'], ({selectedArchives}) ->
for boardID, data of selectedArchives
for type, name of data
if option = $ "select[data-boardid='#{boardID}'][data-type='#{type}'] > option[value='#{name}']", section
option.selected = true
return
return
addArchiveCell: (boardID, data, type) ->
{length} = data[type]
td = $.el 'td',
className: 'archive-cell'
unless length
td.textContent = '--'
return td
options = []
i = 0
while i < length
archive = data[type][i++]
options.push $.el 'option',
textContent: archive
value: archive
td.innerHTML = '<select></select>'
select = td.firstElementChild
unless select.disabled = length is 1
# XXX GM can't into datasets
select.setAttribute 'data-boardid', boardID
select.setAttribute 'data-type', type
$.on select, 'change', Settings.saveSelectedArchive
$.add select, options
td
saveSelectedArchive: ->
$.get 'selectedArchives', Conf['selectedArchives'], ({selectedArchives}) =>
(selectedArchives[@dataset.boardid] or= {})[@dataset.type] = @value
$.set 'selectedArchives', selectedArchives
boardnav: ->
Header.generateBoardList @value
@ -417,32 +466,6 @@ Settings =
usercss: ->
CustomCSS.update()
addArchiveCell: (row, boardID, data, type) ->
options = []
for archive in data[type]
options.push $.el 'option',
textContent: archive
value: archive
td = $.el 'td',
className: 'archive-cell'
{length} = options
if length
td.innerHTML = '<select></select>'
select = td.firstElementChild
unless select.disabled = length is 1
# XXX GM can't into datasets
select.setAttribute 'data-boardid', boardID
select.setAttribute 'data-type', type
$.on select, 'change', Settings.saveSelectedArchive
$.add select, options
else
td.textContent = '--'
$.add row, td
saveSelectedArchive: ->
$.get 'selectedArchives', Conf['selectedArchives'], ({selectedArchives}) =>
(selectedArchives[@dataset.boardid] or= {})[@dataset.type] = @value
$.set 'selectedArchives', selectedArchives
keybinds: (section) ->
section.innerHTML = """
<%= grunt.file.read('src/General/html/Settings/Keybinds.html').replace(/>\s+</g, '><').trim() %>

View File

@ -1,6 +1,7 @@
<fieldset>
<legend>Archiver</legend>
<div class="warning" #{if Conf['404 Redirect'] then 'hidden' else ''}><code>404 Redirect</code> is disabled.</div>
<select id='archive-board-select'></select>
<table id='archive-table'>
<thead>
<th>Thread redirection</th>