Simplify import/export of settings.
Also clear all stored data before importing.
This commit is contained in:
parent
c6fc3428aa
commit
ac8e05dd22
@ -1,7 +1,4 @@
|
||||
<div class="imp-exp">
|
||||
<button class="export">Export Settings</button>
|
||||
<button class="import">Import Settings</button>
|
||||
<button class="reset">Reset Settings</button>
|
||||
<input type="file" hidden>
|
||||
</div>
|
||||
<p class="imp-exp-result"></p>
|
||||
<button class="export">Export Settings</button>
|
||||
<button class="import">Import Settings</button>
|
||||
<button class="reset">Reset Settings</button>
|
||||
<input type="file" hidden>
|
||||
|
||||
@ -138,34 +138,29 @@ Settings =
|
||||
$.get Conf, (Conf) ->
|
||||
# XXX don't export archives.
|
||||
delete Conf['archives']
|
||||
Settings.downloadExport {version: g.VERSION, date: Date.now(), Conf}
|
||||
downloadExport: (data) ->
|
||||
Settings.downloadExport 'Settings', {version: g.VERSION, date: Date.now(), Conf}
|
||||
downloadExport: (title, data) ->
|
||||
a = $.el 'a',
|
||||
download: "<%= meta.name %> v#{g.VERSION}-#{data.date}.json"
|
||||
download: "<%= meta.name %> v#{g.VERSION} #{title}.#{data.date}.json"
|
||||
href: "data:application/json;base64,#{btoa unescape encodeURIComponent JSON.stringify data, null, 2}"
|
||||
<% if (type === 'userscript') { %>
|
||||
p = $ '.imp-exp-result', Settings.dialog
|
||||
$.rmAll p
|
||||
$.add p, a
|
||||
<% } %>
|
||||
<% if (type === 'userscript') { %>$.add d.body, a<% } %>
|
||||
a.click()
|
||||
<% if (type === 'userscript') { %>$.rm a<% } %>
|
||||
import: ->
|
||||
$('input', @parentNode).click()
|
||||
$('input[type=file]', @parentNode).click()
|
||||
onImport: ->
|
||||
return unless file = @files[0]
|
||||
output = @parentNode.nextElementSibling
|
||||
unless confirm 'Your current settings will be entirely overwritten, are you sure?'
|
||||
output.textContent = 'Import aborted.'
|
||||
return
|
||||
return unless confirm 'Your current settings will be entirely overwritten, are you sure?'
|
||||
reader = new FileReader()
|
||||
reader.onload = (e) ->
|
||||
try
|
||||
Settings.loadSettings JSON.parse e.target.result
|
||||
if confirm 'Import successful. Reload now?'
|
||||
window.location.reload()
|
||||
catch err
|
||||
output.textContent = 'Import failed due to an error.'
|
||||
alert 'Import failed due to an error.'
|
||||
c.error err.stack
|
||||
return
|
||||
if confirm 'Import successful. Reload now?'
|
||||
window.location.reload()
|
||||
reader.readAsText file
|
||||
loadSettings: (data) ->
|
||||
version = data.version.split '.'
|
||||
@ -243,7 +238,7 @@ Settings =
|
||||
if data.Conf['WatchedThreads']
|
||||
data.Conf['watchedThreads'] = boards: ThreadWatcher.convert data.Conf['WatchedThreads']
|
||||
delete data.Conf['WatchedThreads']
|
||||
$.set data.Conf
|
||||
$.clear -> $.set data.Conf
|
||||
reset: ->
|
||||
if confirm 'Your current settings will be entirely wiped, are you sure?'
|
||||
$.clear -> window.location.reload() if confirm 'Reset successful. Reload now?'
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user