Unified · Split
| @@ -13,7 +13,7 @@ · 12 unmodified lines | |||
| 13 | 13 | ||
| 14 | @store = new Store | 14 | @store = new Store |
| 15 | @appCache = new app.AppCache if app.AppCache.isEnabled() | 15 | @appCache = new app.AppCache if app.AppCache.isEnabled() |
| 16 | @settings = new app.Settings | 16 | @settings = new app.Settings @store |
| 17 | 17 | ||
| 18 | @docs = new app.collections.Docs | 18 | @docs = new app.collections.Docs |
| 19 | @disabledDocs = new app.collections.Docs | 19 | @disabledDocs = new app.collections.Docs |
| @@ -91,10 +91,10 @@ · 71 unmodified lines | |||
| 91 | return | 91 | return |
| 92 | 92 | ||
| 93 | welcomeBack: -> | 93 | welcomeBack: -> |
| 94 | @visitCount = @store.get('count') or 0 | 94 | visitCount = @settings.get('count') |
| 95 | @store.set 'count', ++@visitCount | 95 | @settings.set 'count', ++visitCount |
| 96 | new app.views.Notif 'Share', autoHide: null if @visitCount is 5 | 96 | new app.views.Notif 'Share', autoHide: null if visitCount is 5 |
| 97 | new app.views.Notif 'Thanks', autoHide: null if @visitCount is 10 or ((n = app.store.get('news')) and n <= 1417305600000) | 97 | new app.views.Notif 'Thanks', autoHide: null if visitCount is 10 or ((n = @settings.get('news')) and n <= 1417305600000) |
| 98 | new app.views.News() | 98 | new app.views.News() |
| 99 | 99 | ||
| 100 | reload: -> | 100 | reload: -> |
| @@ -1,25 +1,56 @@ | |||
| 1 | class app.Settings | 1 | class app.Settings |
| 2 | SETTINGS_KEY = 'settings' | ||
| 3 | DOCS_KEY = 'docs' | ||
| 4 | |||
| 5 | @defaults: -> | ||
| 6 | count: 0 | ||
| 7 | hideDisabled: false | ||
| 8 | hideIntro: false | ||
| 9 | news: 0 | ||
| 10 | |||
| 11 | constructor: (@store) -> | ||
| 12 | @create() unless @settings = @store.get(SETTINGS_KEY) | ||
| 13 | |||
| 14 | create: -> | ||
| 15 | @settings = @constructor.defaults() | ||
| 16 | @applyLegacyValues @settings | ||
| 17 | @save() | ||
| 18 | return | ||
| 19 | |||
| 20 | applyLegacyValues: (settings) -> | ||
| 21 | for key, v of settings when value = @store.get(key) | ||
| 22 | settings[key] = value | ||
| 23 | @store.del(key) | ||
| 24 | return | ||
| 25 | |||
| 26 | save: -> | ||
| 27 | @store.set SETTINGS_KEY, @settings | ||
| 28 | |||
| 29 | set: (key, value) -> | ||
| 30 | @settings[key] = value | ||
| 31 | @save() | ||
| 32 | |||
| 33 | get: (key) -> | ||
| 34 | @settings[key] | ||
| 35 | |||
| 2 | hasDocs: -> | 36 | hasDocs: -> |
| 3 | try | 37 | try !!Cookies.get DOCS_KEY |
| 4 | !!Cookies.get 'docs' | ||
| 5 | catch | ||
| 6 | 38 | ||
| 7 | getDocs: -> | 39 | getDocs: -> |
| 8 | try | 40 | try |
| 9 | Cookies.get('docs')?.split('/') or app.config.default_docs | 41 | Cookies.get(DOCS_KEY)?.split('/') or app.config.default_docs |
| 10 | catch | 42 | catch |
| 11 | app.config.default_docs | 43 | app.config.default_docs |
| 12 | 44 | ||
| 13 | setDocs: (docs) -> | 45 | setDocs: (docs) -> |
| 14 | try | 46 | try |
| 15 | Cookies.set 'docs', docs.join('/'), | 47 | Cookies.set DOCS_KEY, docs.join('/'), |
| 16 | path: '/' | 48 | path: '/' |
| 17 | expires: 1e8 | 49 | expires: 1e8 |
| 18 | catch | 50 | catch |
| 19 | return | 51 | return |
| 20 | 52 | ||
| 21 | reset: -> | 53 | reset: -> |
| 22 | try | 54 | try Cookies.expire DOCS_KEY |
| 23 | Cookies.expire 'docs' | 55 | try @store.del(SETTINGS_KEY) |
| 24 | catch | ||
| 25 | return | 56 | return |
| @@ -19,11 +19,11 @@ class app.views.RootPage extends app.View · 18 unmodified lines | |||
| 19 | return | 19 | return |
| 20 | 20 | ||
| 21 | setHidden: (value) -> | 21 | setHidden: (value) -> |
| 22 | app.store.set 'hideIntro', value | 22 | app.settings.set 'hideIntro', value |
| 23 | return | 23 | return |
| 24 | 24 | ||
| 25 | isHidden: -> | 25 | isHidden: -> |
| 26 | app.isSingleDoc() or app.store.get 'hideIntro' | 26 | app.isSingleDoc() or app.settings.get 'hideIntro' |
| 27 | 27 | ||
| 28 | onRoute: -> | 28 | onRoute: -> |
| 29 | 29 | ||
| @@ -27,8 +27,8 @@ class app.views.News extends app.views.Notif · 26 unmodified lines | |||
| 27 | new Date(app.news[0][0]).getTime() | 27 | new Date(app.news[0][0]).getTime() |
| 28 | 28 | ||
| 29 | getLastReadTime: -> | 29 | getLastReadTime: -> |
| 30 | app.store.get 'news' | 30 | app.settings.get 'news' |
| 31 | 31 | ||
| 32 | markAllAsRead: -> | 32 | markAllAsRead: -> |
| 33 | app.store.set 'news', @getLastNewsTime() + 1 | 33 | app.settings.set 'news', @getLastNewsTime() + 1 |
| 34 | return | 34 | return |
| @@ -46,10 +46,10 @@ class app.views.DocList extends app.View · 45 unmodified lines | |||
| 46 | return | 46 | return |
| 47 | 47 | ||
| 48 | renderDisabledList: -> | 48 | renderDisabledList: -> |
| 49 | if (hidden = app.store.get 'hideDisabled') is true | 49 | if (hidden = app.settings.get 'hideDisabled') is true |
| 50 | @removeDisabledList() | 50 | @removeDisabledList() |
| 51 | else | 51 | else |
| 52 | app.store.set 'hideDisabled', false unless hidden is false | 52 | app.settings.set 'hideDisabled', false unless hidden is false |
| 53 | @appendDisabledList() | 53 | @appendDisabledList() |
| 54 | return | 54 | return |
| 55 | 55 | ||
| @@ -129,10 +129,10 @@ class app.views.DocList extends app.View · 73 unmodified lines | |||
| 129 | 129 | ||
| 130 | if @disabledTitle.classList.contains('open-title') | 130 | if @disabledTitle.classList.contains('open-title') |
| 131 | @removeDisabledList() | 131 | @removeDisabledList() |
| 132 | app.store.set 'hideDisabled', true | 132 | app.settings.set 'hideDisabled', true |
| 133 | else | 133 | else |
| 134 | @appendDisabledList() | 134 | @appendDisabledList() |
| 135 | app.store.set 'hideDisabled', false | 135 | app.settings.set 'hideDisabled', false |
| 136 | 136 | ||
| 137 | 137 | ||
| 138 | afterRoute: (route, context) => | 138 | afterRoute: (route, context) => |