{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"}
],
create: function() {
this.inherited(arguments);
- /*
- this.index = localStorage.getItem('hack.index');
- if (!this.index)
+ try {
+ this.index = localStorage.getItem('hack.index');
+ if (!this.index)
+ this.index = 0;
+ } catch(e) {
+ enyo.log("Could not load last hack index");
this.index = 0;
- */
- this.index = 0;
+ }
this.lastScrollPos = 0;
this.$.hacksCarousel.setCenterView(this.getHack(this.index));
},
},
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) {
- enyo.log("Saving prefs: " + JSON.stringify(prefs));
- this.back();
var view = this.$.hacksCarousel.fetchView('center');
- view.setPreferences(prefs);
- view.start();
+ if (prefs == null) {
+ enyo.log("Clearing prefs");
+ view.resetPreferences(prefs);
+ this.selectHack(this, this.index);
+ } else {
+ enyo.log("Saving prefs: " + JSON.stringify(prefs));
+ view.setPreferences(prefs);
+ view.start();
+ }
+ this.back();
},
windowActivated: function() {
this.startHack();
windowDeactivated: function() {
this.stopHack();
},
- selectHack: function(inSender, inValue, inOldValue) {
+ selectHack: function(inSender, inValue) {
this.stopHack();
this.index = inValue;
this.lastScrollPos = 0;
//enyo.log('starting view ' + view);
if (view)
view.start();
- //localStorage.setItem('hack.index', this.index);
+ try {
+ localStorage.setItem('hack.index', this.index);
+ } catch(e) {
+ enyo.log("Could not set hack index");
+ }
},
stopHack: function(direction) {
var view = this.$.hacksCarousel.fetchView(direction || 'center');
stopScroll: function(inSender) {
this.lastScrollPos = this.$.hacksCarousel.scrollLeft;
this.startHack();
+ },
+ closeNoPrefsDialog: function() {
+ this.$.noPrefsDialog.close();
}
});