Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

added AutoPreferencesService; reordered depends.js files

  • Loading branch information...
commit 5747fe1f7181526984359c1e8c303a7362bc2457 1 parent c9bfe6e
Ryan Duffy authored
3  src/admob/depends.js
... ...
@@ -0,0 +1,3 @@
  1
+enyo.depends(
  2
+	"admob.js"
  3
+);
4  src/calendar-picker/depends.js
... ...
@@ -0,0 +1,4 @@
  1
+enyo.depends(
  2
+	"Calendar.js",
  3
+	"calendar-picker.css"
  4
+);
10  src/depends.js
... ...
@@ -1,7 +1,7 @@
1 1
 enyo.depends(
2  
-	"example.js",
3  
-	"calendar-picker/Calendar.js",
4  
-	"calendar-picker/calendar-picker.css",
5  
-	"admob/admob.js",
6  
-	"timer/timer.js"
  2
+	"calendar-picker/",
  3
+	"admob/",
  4
+	"timer/",
  5
+	"prefs/",
  6
+	"example.js"
7 7
 );
19  src/example.js
@@ -4,7 +4,7 @@ var _Example = {
4 4
 	components:[
5 5
 		{kind:"DividerDrawer", caption:"Calendar Picker", open:true, components:[
6 6
 			{content:"Open by default because otherwise it doesn't render correctly right now"},
7  
-			{kind:"extras.CalendarPicker", onSelect:"showDate"},
  7
+			{kind:"extras.CalendarPicker", name:"cal", onSelect:"showDate"},
8 8
 			{kind:"LabeledContainer", label:"Selected Date:", components:[
9 9
 				{name:"dt"}
10 10
 			]}
@@ -18,14 +18,16 @@ var _Example = {
18 18
 		{kind:"DividerDrawer", caption:"Timer", open:false, components:[
19 19
 			{kind:"extras.Timer", name:"timer", onTick:"tick"},
20 20
 			{name:"timerField", content:"Click to Toggle Timer", onclick:"toggleTimer"}
21  
-		]}
  21
+		]},
  22
+		{kind:"extras.PrefExample", name:"prefs", onLoad:"prefsReady"}
22 23
 	],
23 24
 	create:function() {
24 25
 		this.inherited(arguments);
25  
-		this.showDate(null, new Date());
  26
+		//this.showDate(null, new Date());
26 27
 		this.$.admob.request();
27 28
 	},
28 29
 	showDate:function(source, date) {
  30
+		this.$.prefs.setSelectedDate(date.getTime());
29 31
 		this.$.dt.setContent(date.getDate() + "-" + (date.getMonth()+1) + "-" + date.getFullYear());
30 32
 	},
31 33
 	tick:function(source, time) {
@@ -38,7 +40,18 @@ var _Example = {
38 40
 		} else {
39 41
 			this.$.timer.start();
40 42
 		}
  43
+	},
  44
+	prefsReady:function() {
  45
+		this.$.cal.setDate(new Date(this.$.prefs.getSelectedDate()));
41 46
 	}
42 47
 };
43 48
 
44 49
 enyo.kind(_Example);
  50
+
  51
+enyo.kind({
  52
+	name:"extras.PrefExample",
  53
+	kind:"extras.AutoPreferencesService",
  54
+	published:{
  55
+		selectedDate:null
  56
+	}
  57
+});
3  src/prefs/depends.js
... ...
@@ -0,0 +1,3 @@
  1
+enyo.depends(
  2
+	"prefs.js"
  3
+);
73  src/prefs/prefs.js
... ...
@@ -0,0 +1,73 @@
  1
+var _AutoPref = {
  2
+	name : "extras.AutoPreferencesService",
  3
+	kind : "Component",
  4
+	components : [{
  5
+		kind : "SystemService",
  6
+		name : "getPreferences",
  7
+		method : "getPreferences",
  8
+		onResponse : "getPrefs"
  9
+	}, {
  10
+		kind : "SystemService",
  11
+		name : "setPreferences",
  12
+		method : "setPreferences",
  13
+		onResponse : "setPrefs"
  14
+	}, ],
  15
+	events : {
  16
+		onLoad : "",
  17
+		onSet : "",
  18
+		onError : ""
  19
+	},
  20
+	deferUpdate:false,
  21
+	create : function() {
  22
+		this.inherited(arguments);
  23
+
  24
+		var props = [];
  25
+		for ( var prop in this.published) {
  26
+			props.push(prop);
  27
+			this[prop + "Changed"] = enyo.bind(this, "changeHandler", prop);
  28
+		}
  29
+
  30
+		this.$.getPreferences.call({
  31
+			keys : props
  32
+		});
  33
+	},
  34
+	changeHandler : function(prop) {
  35
+		if (this.deferUpdate)
  36
+			return;
  37
+		
  38
+		var o = {};
  39
+		o[prop] = this[prop];
  40
+		this.$.setPreferences.call(o);
  41
+	},
  42
+	defer : function(disable) {
  43
+		this.deferUpdate = !!disable;
  44
+	},
  45
+	update : function() {
  46
+		var o = {};
  47
+		for ( var prop in this.published) {
  48
+			o[prop] = this[prop];
  49
+		}
  50
+
  51
+		this.$.setPreferences.call(o);
  52
+	},
  53
+	setPrefs : function(source, response) {
  54
+		if (!response.returnValue)
  55
+			this.doError(response);
  56
+
  57
+		this.doSet();
  58
+	},
  59
+	getPrefs : function(source, response) {
  60
+		if (!response.returnValue)
  61
+			this.doError(response);
  62
+		
  63
+		for ( var prop in this.published) {
  64
+			if(response[prop] !== undefined) {
  65
+				this[prop] = response[prop];
  66
+			}
  67
+		}
  68
+
  69
+		this.doLoad();
  70
+	}
  71
+}
  72
+
  73
+enyo.kind(_AutoPref);
3  src/timer/depends.js
... ...
@@ -0,0 +1,3 @@
  1
+enyo.depends(
  2
+	"timer.js"
  3
+);

0 notes on commit 5747fe1

Please sign in to comment.
Something went wrong with that request. Please try again.