From 5045171980085a8227a7fdd2a04724a2fd9830b2 Mon Sep 17 00:00:00 2001 From: Chip Black Date: Sun, 11 Sep 2011 21:36:21 -0500 Subject: [PATCH 1/1] Add dialog for hacks without prefs, add prefs save/load --- Main.js | 12 +++++++++--- hacks/Hack.js | 27 +++++++++++++++++++++++---- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/Main.js b/Main.js index 9a0a209..c8a2c19 100644 --- 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 index 2133299..2b0e5f7 100644 --- 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() { } }); -- 2.34.1