From d4d50862c8af43aa2e26f240f49e31fa744e2f1e Mon Sep 17 00:00:00 2001 From: Jack Pearkes Date: Thu, 21 Aug 2014 17:43:08 -0700 Subject: [PATCH] ui: use ember object to wrap localstorag --- ui/acl.md | 6 ++++++ ui/javascripts/app/mixins.js | 0 ui/javascripts/app/router.js | 34 +++++++++++++++++++++++++++++++--- ui/javascripts/app/routes.js | 3 ++- 4 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 ui/acl.md create mode 100644 ui/javascripts/app/mixins.js diff --git a/ui/acl.md b/ui/acl.md new file mode 100644 index 000000000..080e3a450 --- /dev/null +++ b/ui/acl.md @@ -0,0 +1,6 @@ +- ACL management + - KV takes ?token=ACCESS_KEY + - There is a default token + - Allow setting a token + - store the token in local storage + - return error (notification) if the write fails diff --git a/ui/javascripts/app/mixins.js b/ui/javascripts/app/mixins.js new file mode 100644 index 000000000..e69de29bb diff --git a/ui/javascripts/app/router.js b/ui/javascripts/app/router.js index e29f614f6..d3e616e10 100644 --- a/ui/javascripts/app/router.js +++ b/ui/javascripts/app/router.js @@ -1,13 +1,41 @@ window.App = Ember.Application.create({ rootElement: "#app", - currentPath: '', + currentPath: '' +}); + +Ember.Application.initializer({ + name: 'settings', initialize: function(container, application) { - console.log("initialize"); - console.log(localStorage.getItem("foobars")); + application.set('settings', App.Settings.create()); } }); +// Wrap localstorage with an ember object +App.Settings = Ember.Object.extend({ + unknownProperty: function(key) { + return localStorage[key]; + }, + + setUnknownProperty: function(key, value) { + if(Ember.isNone(value)) { + delete localStorage[key]; + } else { + localStorage[key] = value; + } + this.notifyPropertyChange(key); + return value; + }, + + clear: function() { + this.beginPropertyChanges(); + for (var i=0, l=localStorage.length; i