commit:5045171980085a8227a7fdd2a04724a2fd9830b2
author:Chip Black
committer:Chip Black
date:Sun Sep 11 21:36:21 2011 -0500
parents:98d8bc4d5f0bc0b315b54369a8f288d93e9b2c44
Add dialog for hacks without prefs, add prefs save/load
diff --git a/Main.js b/Main.js
line changes: +9/-3
index 9a0a209..c8a2c19
--- 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: "noPrefsDialog", kind: "ModalDialog", caption: "No Preferences", components: [
+				{kind: "Button", content: "Okay", onclick: "closeNoPrefsDialog"}
 			]}
 		]},
 		{name: "preferencesView", kind: "HackPreferences", onClose: "savePreferences"}
@@ -68,15 +71,15 @@ 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) {
@@ -172,5 +175,8 @@ enyo.kind({
 	stopScroll: function(inSender) {
 		this.lastScrollPos = this.$.hacksCarousel.scrollLeft;
 		this.startHack();
+	},
+	closeNoPrefsDialog: function() {
+		this.$.noPrefsDialog.close();
 	}
 });

diff --git a/hacks/Hack.js b/hacks/Hack.js
line changes: +23/-4
index 2133299..2b0e5f7
--- a/hacks/Hack.js
+++ b/hacks/Hack.js
@@ -4,6 +4,16 @@ enyo.kind({
 	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() {
@@ -23,14 +33,23 @@ enyo.kind({
 		}
 		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() { }
 });