Permalink
Browse files

added AutoPreferencesService; reordered depends.js files

  • Loading branch information...
1 parent c9bfe6e commit 5747fe1f7181526984359c1e8c303a7362bc2457 ryanjduffy committed Jul 21, 2011
Showing with 107 additions and 8 deletions.
  1. +3 −0 src/admob/depends.js
  2. +4 −0 src/calendar-picker/depends.js
  3. +5 −5 src/depends.js
  4. +16 −3 src/example.js
  5. +3 −0 src/prefs/depends.js
  6. +73 −0 src/prefs/prefs.js
  7. +3 −0 src/timer/depends.js
View
3 src/admob/depends.js
@@ -0,0 +1,3 @@
+enyo.depends(
+ "admob.js"
+);
View
4 src/calendar-picker/depends.js
@@ -0,0 +1,4 @@
+enyo.depends(
+ "Calendar.js",
+ "calendar-picker.css"
+);
View
10 src/depends.js
@@ -1,7 +1,7 @@
enyo.depends(
- "example.js",
- "calendar-picker/Calendar.js",
- "calendar-picker/calendar-picker.css",
- "admob/admob.js",
- "timer/timer.js"
+ "calendar-picker/",
+ "admob/",
+ "timer/",
+ "prefs/",
+ "example.js"
);
View
19 src/example.js
@@ -4,7 +4,7 @@ var _Example = {
components:[
{kind:"DividerDrawer", caption:"Calendar Picker", open:true, components:[
{content:"Open by default because otherwise it doesn't render correctly right now"},
- {kind:"extras.CalendarPicker", onSelect:"showDate"},
+ {kind:"extras.CalendarPicker", name:"cal", onSelect:"showDate"},
{kind:"LabeledContainer", label:"Selected Date:", components:[
{name:"dt"}
]}
@@ -18,14 +18,16 @@ var _Example = {
{kind:"DividerDrawer", caption:"Timer", open:false, components:[
{kind:"extras.Timer", name:"timer", onTick:"tick"},
{name:"timerField", content:"Click to Toggle Timer", onclick:"toggleTimer"}
- ]}
+ ]},
+ {kind:"extras.PrefExample", name:"prefs", onLoad:"prefsReady"}
],
create:function() {
this.inherited(arguments);
- this.showDate(null, new Date());
+ //this.showDate(null, new Date());
this.$.admob.request();
},
showDate:function(source, date) {
+ this.$.prefs.setSelectedDate(date.getTime());
this.$.dt.setContent(date.getDate() + "-" + (date.getMonth()+1) + "-" + date.getFullYear());
},
tick:function(source, time) {
@@ -38,7 +40,18 @@ var _Example = {
} else {
this.$.timer.start();
}
+ },
+ prefsReady:function() {
+ this.$.cal.setDate(new Date(this.$.prefs.getSelectedDate()));
}
};
enyo.kind(_Example);
+
+enyo.kind({
+ name:"extras.PrefExample",
+ kind:"extras.AutoPreferencesService",
+ published:{
+ selectedDate:null
+ }
+});
View
3 src/prefs/depends.js
@@ -0,0 +1,3 @@
+enyo.depends(
+ "prefs.js"
+);
View
73 src/prefs/prefs.js
@@ -0,0 +1,73 @@
+var _AutoPref = {
+ name : "extras.AutoPreferencesService",
+ kind : "Component",
+ components : [{
+ kind : "SystemService",
+ name : "getPreferences",
+ method : "getPreferences",
+ onResponse : "getPrefs"
+ }, {
+ kind : "SystemService",
+ name : "setPreferences",
+ method : "setPreferences",
+ onResponse : "setPrefs"
+ }, ],
+ events : {
+ onLoad : "",
+ onSet : "",
+ onError : ""
+ },
+ deferUpdate:false,
+ create : function() {
+ this.inherited(arguments);
+
+ var props = [];
+ for ( var prop in this.published) {
+ props.push(prop);
+ this[prop + "Changed"] = enyo.bind(this, "changeHandler", prop);
+ }
+
+ this.$.getPreferences.call({
+ keys : props
+ });
+ },
+ changeHandler : function(prop) {
+ if (this.deferUpdate)
+ return;
+
+ var o = {};
+ o[prop] = this[prop];
+ this.$.setPreferences.call(o);
+ },
+ defer : function(disable) {
+ this.deferUpdate = !!disable;
+ },
+ update : function() {
+ var o = {};
+ for ( var prop in this.published) {
+ o[prop] = this[prop];
+ }
+
+ this.$.setPreferences.call(o);
+ },
+ setPrefs : function(source, response) {
+ if (!response.returnValue)
+ this.doError(response);
+
+ this.doSet();
+ },
+ getPrefs : function(source, response) {
+ if (!response.returnValue)
+ this.doError(response);
+
+ for ( var prop in this.published) {
+ if(response[prop] !== undefined) {
+ this[prop] = response[prop];
+ }
+ }
+
+ this.doLoad();
+ }
+}
+
+enyo.kind(_AutoPref);
View
3 src/timer/depends.js
@@ -0,0 +1,3 @@
+enyo.depends(
+ "timer.js"
+);

0 comments on commit 5747fe1

Please sign in to comment.