Refactor settings

pull/165/head
Thibaut 10 years ago
parent 5c1a9ed640
commit b898ac18c8

@ -13,7 +13,7 @@
@store = new Store
@appCache = new app.AppCache if app.AppCache.isEnabled()
@settings = new app.Settings
@settings = new app.Settings @store
@docs = new app.collections.Docs
@disabledDocs = new app.collections.Docs
@ -91,10 +91,10 @@
return
welcomeBack: ->
@visitCount = @store.get('count') or 0
@store.set 'count', ++@visitCount
new app.views.Notif 'Share', autoHide: null if @visitCount is 5
new app.views.Notif 'Thanks', autoHide: null if @visitCount is 10 or ((n = app.store.get('news')) and n <= 1417305600000)
visitCount = @settings.get('count')
@settings.set 'count', ++visitCount
new app.views.Notif 'Share', autoHide: null if visitCount is 5
new app.views.Notif 'Thanks', autoHide: null if visitCount is 10 or ((n = @settings.get('news')) and n <= 1417305600000)
new app.views.News()
reload: ->

@ -1,25 +1,56 @@
class app.Settings
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]
hasDocs: ->
try
!!Cookies.get 'docs'
catch
try !!Cookies.get DOCS_KEY
getDocs: ->
try
Cookies.get('docs')?.split('/') or app.config.default_docs
Cookies.get(DOCS_KEY)?.split('/') or app.config.default_docs
catch
app.config.default_docs
setDocs: (docs) ->
try
Cookies.set 'docs', docs.join('/'),
Cookies.set DOCS_KEY, docs.join('/'),
path: '/'
expires: 1e8
catch
return
reset: ->
try
Cookies.expire 'docs'
catch
try Cookies.expire DOCS_KEY
try @store.del(SETTINGS_KEY)
return

@ -19,11 +19,11 @@ class app.views.RootPage extends app.View
return
setHidden: (value) ->
app.store.set 'hideIntro', value
app.settings.set 'hideIntro', value
return
isHidden: ->
app.isSingleDoc() or app.store.get 'hideIntro'
app.isSingleDoc() or app.settings.get 'hideIntro'
onRoute: ->

@ -27,8 +27,8 @@ class app.views.News extends app.views.Notif
new Date(app.news[0][0]).getTime()
getLastReadTime: ->
app.store.get 'news'
app.settings.get 'news'
markAllAsRead: ->
app.store.set 'news', @getLastNewsTime() + 1
app.settings.set 'news', @getLastNewsTime() + 1
return

@ -46,10 +46,10 @@ class app.views.DocList extends app.View
return
renderDisabledList: ->
if (hidden = app.store.get 'hideDisabled') is true
if (hidden = app.settings.get 'hideDisabled') is true
@removeDisabledList()
else
app.store.set 'hideDisabled', false unless hidden is false
app.settings.set 'hideDisabled', false unless hidden is false
@appendDisabledList()
return
@ -129,10 +129,10 @@ class app.views.DocList extends app.View
if @disabledTitle.classList.contains('open-title')
@removeDisabledList()
app.store.set 'hideDisabled', true
app.settings.set 'hideDisabled', true
else
@appendDisabledList()
app.store.set 'hideDisabled', false
app.settings.set 'hideDisabled', false
afterRoute: (route, context) =>

Loading…
Cancel
Save