bump revision
[Hacks.git] / Main.js
diff --git a/Main.js b/Main.js
index 9a0a209..2b68860 100644 (file)
--- a/Main.js
+++ b/Main.js
@@ -12,29 +12,34 @@ enyo.kind({
                                {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"}
        ],
        hacksList: [
-               {name: "Nimbus", kind: "Nimbus", dark: false},
-               {name: "HexaSpinner", kind: "HexaSpinnerHack", dark: false},
-               {name: "Landscape", kind: "Landscape", dark: false},
-               {name: "Munch", kind: "Munch", dark: true},
-               {name: "Orbit", kind: "Orbit", dark: false},
-               {name: "Pixelfade", kind: "Pixelfade", dark: true},
-               //{name: "Swarm", kind: "Swarm", dark: false},       // crashy
-               //{name: "Spinner.CGA", kind: "XSpinnerCGA", dark: true}, // no webfont support
-               {name: "Spinner", kind: "XSpinner", dark: true}
+               {name: "Nimbus", kind: "Nimbus"},
+               {name: "HexaSpinner", kind: "HexaSpinnerHack"},
+               {name: "Landscape", kind: "Landscape"},
+               {name: "Munch", kind: "Munch"},
+               {name: "Orbit", kind: "Orbit"},
+               {name: "Pixelfade", kind: "Pixelfade"},
+               //{name: "Swarm", kind: "Swarm"},       // crashy
+               //{name: "Spinner.CGA", kind: "XSpinnerCGA"}, // no webfont support
+               {name: "Spinner", kind: "XSpinner"}
        ],
        create: function() {
                this.inherited(arguments);
-               /*
-               this.index = localStorage.getItem('hack.index');
-               if (!this.index)
+               try {
+                       this.index = parseInt(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));
        },
@@ -47,6 +52,7 @@ enyo.kind({
                        });
                }
                this.$.hacksListSelector.setItems(displayList);
+               this.$.hacksListSelector.setValue(this.index);
                this.startHack();
                window.addEventListener('resize', this.resizeHack.bind(this), false);
                this.setNotice('Swipe for more...');
@@ -68,23 +74,29 @@ enyo.kind({
        },
        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();
@@ -92,12 +104,11 @@ enyo.kind({
        windowDeactivated: function() {
                this.stopHack();
        },
-       selectHack: function(inSender, inValue, inOldValue) {
+       selectHack: function(inSender, inValue) {
                this.stopHack();
                this.index = inValue;
                this.lastScrollPos = 0;
                this.$.hacksCarousel.setCenterView(this.getHack(this.index));
-               this.$.info.addRemoveClass('dark', this.hacksList[this.index].dark);
                // For some reason, setCenterView above fires the startScroll
                // event without a subsequent stopScroll event.  To work around
                // this, we defer the start until later.
@@ -108,7 +119,11 @@ enyo.kind({
                //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');
@@ -142,7 +157,6 @@ enyo.kind({
                        this.$.hacksListSelector.setValue(this.index);
                        this.hackHidden('right');
                        this.infoFade();
-                       this.$.info.addRemoveClass('dark', this.hacksList[this.index].dark);
                }
                if (this.index == 0)
                        return null;
@@ -155,7 +169,6 @@ enyo.kind({
                        this.$.hacksListSelector.setValue(this.index);
                        this.hackHidden('left');
                        this.infoFade();
-                       this.$.info.addRemoveClass('dark', this.hacksList[this.index].dark);
                }
                if (this.index == this.hacksList.length - 1)
                        return null;
@@ -172,5 +185,8 @@ enyo.kind({
        stopScroll: function(inSender) {
                this.lastScrollPos = this.$.hacksCarousel.scrollLeft;
                this.startHack();
+       },
+       closeNoPrefsDialog: function() {
+               this.$.noPrefsDialog.close();
        }
 });