From 1c721a96d70dcffb50c33ee81c8df3d78ef0a28f Mon Sep 17 00:00:00 2001 From: Chip Black Date: Sun, 11 Sep 2011 22:39:36 -0500 Subject: [PATCH] Clean up preferences style, add prefs reset --- HackPreferences.js | 17 +++++++++++++---- Main.css | 9 +++++++++ Main.js | 16 +++++++++++----- hacks/Hack.js | 3 +++ 4 files changed, 36 insertions(+), 9 deletions(-) diff --git a/HackPreferences.js b/HackPreferences.js index a8f9195..550dbc1 100644 --- a/HackPreferences.js +++ b/HackPreferences.js @@ -6,9 +6,12 @@ enyo.kind({ }, components: [ {kind: "Header", content: "Preferences"}, - {kind: "Scroller", flex: 1, horizontal: false, components: [ - {kind: "VFlexBox", align: "center", components: [ - {kind: "RowGroup", name: "prefsContainer", style: "width: 750px"} + {kind: "Scroller", flex: 1, components: [ + {kind: "Control", className: "prefs-center", components: [ + {kind: "RowGroup", name: "prefsContainer"}, + {kind: "HFlexBox", pack: "center", components: [ + {kind: "Button", className: "enyo-button-negative prefs-done-button", caption: "Reset to Defaults", onclick: "resetToDefaults"} + ]} ]} ]}, {kind: "Toolbar", className: "enyo-toolbar-light", components: [ @@ -27,7 +30,6 @@ enyo.kind({ case 'Slider': c = this.$.prefsContainer.createComponent({kind: "HFlexBox", align: "center", components: [{content: p.label, flex: 1}]}); var slider = c.createComponent(p, {owner: this.$.prefsContainer}); - slider.setStyle('width: 400px'); slider.setPosition(values[p.name]); break; default: @@ -54,6 +56,13 @@ enyo.kind({ } this.doClose(o); + this.cleanup(); + }, + resetToDefaults: function() { + this.doClose(null); + this.cleanup(); + }, + cleanup: function() { var controls = this.$.prefsContainer.getControls(); for (var i = 0; i < controls.length; i++) { // We destroy the parent because we want to destroy the diff --git a/Main.css b/Main.css index 6a1d5c2..69308ae 100644 --- a/Main.css +++ b/Main.css @@ -45,3 +45,12 @@ .prefs-done-button { width: 300px; } + +.prefs-center { + width: 500px; + margin: 23px auto 0 auto; +} + +.prefs-center .enyo-slider { + width: 300px; +} diff --git a/Main.js b/Main.js index c8a2c19..35c3a6c 100644 --- a/Main.js +++ b/Main.js @@ -83,11 +83,17 @@ enyo.kind({ } }, 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(); @@ -95,7 +101,7 @@ enyo.kind({ windowDeactivated: function() { this.stopHack(); }, - selectHack: function(inSender, inValue, inOldValue) { + selectHack: function(inSender, inValue) { this.stopHack(); this.index = inValue; this.lastScrollPos = 0; diff --git a/hacks/Hack.js b/hacks/Hack.js index 2b0e5f7..13e1912 100644 --- a/hacks/Hack.js +++ b/hacks/Hack.js @@ -51,5 +51,8 @@ enyo.kind({ enyo.log("Could not save prefs: " + e.toString()); } }, + resetPreferences: function() { + delete localStorage['hacks/' + this.kind]; + }, preferencesChanged: function() { } }); -- 2.25.1