Add dialog for hacks without prefs, add prefs save/load
{name: "hacksListSelector", kind: "ListSelector", popupAlign: "left", onChange: "selectHack", style: "width: 200px"},
{kind: "Spacer"},
{name: "notice", className: "notice"}
+ ]},
+ {name: "noPrefsDialog", kind: "ModalDialog", caption: "No Preferences", components: [
+ {kind: "Button", content: "Okay", onclick: "closeNoPrefsDialog"}
]}
]},
{name: "preferencesView", kind: "HackPreferences", onClose: "savePreferences"}
},
openPreferences: function() {
var view = this.$.hacksCarousel.fetchView('center');
- view.stop();
var meta = view.getPreferencesMetadata();
- if (meta) {
+ if (meta.length) {
+ view.stop();
var values = view.getPreferences();
this.$.preferencesView.load(this.hacksList[this.index].name, meta, values);
this.selectView(this.$.preferencesView);
} else {
- alert("No prefs");
+ this.$.noPrefsDialog.openAtCenter();
}
},
savePreferences: function(inSender, prefs) {
stopScroll: function(inSender) {
this.lastScrollPos = this.$.hacksCarousel.scrollLeft;
this.startHack();
+ },
+ closeNoPrefsDialog: function() {
+ this.$.noPrefsDialog.close();
}
});
name: "Hack",
kind: "VFlexBox",
preferences: [],
+ create: function() {
+ this.inherited(arguments);
+ try {
+ var str = localStorage['hacks/' + this.kind];
+ if (str)
+ this.setPreferences(JSON.parse(str), true, true);
+ } catch(e) {
+ enyo.log("Could not load preferences: " + e.toString());
+ }
+ },
stop: function() {
},
start: function() {
}
return o;
},
- setPreferences: function(prefs) {
+ setPreferences: function(prefs, nosave, nonotify) {
for (var i in prefs) {
if (this[i] == undefined)
throw new Error('Cannot set nonexistent preference "' + i + '"');
this[i] = prefs[i];
}
- this.preferencesChanged();
+ if (!nosave)
+ this.savePreferences();
+ if (!nonotify)
+ this.preferencesChanged();
+ },
+ savePreferences: function() {
+ try {
+ localStorage['hacks/' + this.kind] = JSON.stringify(this.getPreferences());
+ } catch(e) {
+ enyo.log("Could not save prefs: " + e.toString());
+ }
},
- preferencesChanged: function() {
- }
+ preferencesChanged: function() { }
});