Add dialog for hacks without prefs, add prefs save/load
authorChip Black <bytex64@bytex64.net>
Mon, 12 Sep 2011 02:36:21 +0000 (21:36 -0500)
committerChip Black <bytex64@bytex64.net>
Mon, 12 Sep 2011 02:36:21 +0000 (21:36 -0500)
Main.js
hacks/Hack.js

diff --git a/Main.js b/Main.js
index 9a0a209..c8a2c19 100644 (file)
--- a/Main.js
+++ b/Main.js
@@ -12,6 +12,9 @@ enyo.kind({
                                {name: "hacksListSelector", kind: "ListSelector", popupAlign: "left", onChange: "selectHack", style: "width: 200px"},
                                {kind: "Spacer"},
                                {name: "notice", className: "notice"}
                                {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"}
                        ]}
                ]},
                {name: "preferencesView", kind: "HackPreferences", onClose: "savePreferences"}
@@ -68,15 +71,15 @@ enyo.kind({
        },
        openPreferences: function() {
                var view = this.$.hacksCarousel.fetchView('center');
        },
        openPreferences: function() {
                var view = this.$.hacksCarousel.fetchView('center');
-               view.stop();
 
                var meta = view.getPreferencesMetadata();
 
                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 {
                        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) {
                }
        },
        savePreferences: function(inSender, prefs) {
@@ -172,5 +175,8 @@ enyo.kind({
        stopScroll: function(inSender) {
                this.lastScrollPos = this.$.hacksCarousel.scrollLeft;
                this.startHack();
        stopScroll: function(inSender) {
                this.lastScrollPos = this.$.hacksCarousel.scrollLeft;
                this.startHack();
+       },
+       closeNoPrefsDialog: function() {
+               this.$.noPrefsDialog.close();
        }
 });
        }
 });
index 2133299..2b0e5f7 100644 (file)
@@ -4,6 +4,16 @@ enyo.kind({
        name: "Hack",
        kind: "VFlexBox",
        preferences: [],
        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() {
        stop: function() {
        },
        start: function() {
@@ -23,14 +33,23 @@ enyo.kind({
                }
                return o;
        },
                }
                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];
                }
                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() { }
 });
 });