You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
devdocs/assets/javascripts/app/settings.coffee

57 lines
1.0 KiB

11 years ago
class app.Settings
10 years ago
SETTINGS_KEY = 'settings'
DOCS_KEY = 'docs'
@defaults: ->
count: 0
hideDisabled: false
hideIntro: false
news: 0
constructor: (@store) ->
@create() unless @settings = @store.get(SETTINGS_KEY)
create: ->
@settings = @constructor.defaults()
@applyLegacyValues @settings
@save()
return
applyLegacyValues: (settings) ->
for key, v of settings when value = @store.get(key)
settings[key] = value
@store.del(key)
return
save: ->
@store.set SETTINGS_KEY, @settings
set: (key, value) ->
@settings[key] = value
@save()
get: (key) ->
@settings[key]
11 years ago
hasDocs: ->
10 years ago
try !!Cookies.get DOCS_KEY
11 years ago
getDocs: ->
try
10 years ago
Cookies.get(DOCS_KEY)?.split('/') or app.config.default_docs
11 years ago
catch
app.config.default_docs
setDocs: (docs) ->
try
10 years ago
Cookies.set DOCS_KEY, docs.join('/'),
11 years ago
path: '/'
expires: 1e8
catch
return
reset: ->
10 years ago
try Cookies.expire DOCS_KEY
try @store.del(SETTINGS_KEY)
11 years ago
return