Refactor settings

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

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

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

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

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

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

Loading…
Cancel
Save