ui: use ember object to wrap localstorag
This commit is contained in:
parent
16445baf00
commit
d4d50862c8
|
@ -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
|
|
@ -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<l; i++){
|
||||
this.set(localStorage.key(i));
|
||||
}
|
||||
localStorage.clear();
|
||||
this.endPropertyChanges();
|
||||
}
|
||||
});
|
||||
|
||||
App.Router.map(function() {
|
||||
// Our parent datacenter resource sets the namespace
|
||||
|
|
|
@ -304,8 +304,9 @@ App.NodesRoute = App.BaseRoute.extend({
|
|||
App.AclsRoute = App.BaseRoute.extend({
|
||||
model: function(params) {
|
||||
var dc = this.modelFor('dc').dc;
|
||||
var token = App.get('settings.token');
|
||||
// Return a promise containing the ACLS
|
||||
return Ember.$.getJSON(formatUrl('/v1/acl/list', dc, "")).then(function(data) {
|
||||
return Ember.$.getJSON(formatUrl('/v1/acl/list', dc, token)).then(function(data) {
|
||||
objs = [];
|
||||
data.map(function(obj){
|
||||
objs.push(App.Acl.create(obj));
|
||||
|
|
Loading…
Reference in New Issue