Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2150 mathias 1
<html>
2
	<head>
3
		<title>Testing dojox.dtl using a blog example</title>
4
		<script src="../../../dojo/dojo.js" djConfig="parseOnLoad: true, usePlainJson: true"></script>
5
		<script>
6
			dojo.require("dojox.dtl.widget");
7
 
8
			dojo.provide("demo");
9
 
10
			dojo.declare("demo.Blog", dojox.dtl._Widget,
11
			{
12
				buffer: dojox.dtl.render.html.sensitivity.NODE,
13
				constructor: function(props, node){
14
					this.contexts = {
15
						list: false,
16
						blogs: {},
17
						pages: {}
18
					}
19
					this.templates = {
20
						list: new dojox.dtl.HtmlTemplate(dojo.moduleUrl("dojox.dtl.demos.templates", "blog_list.html")),
21
						detail: new dojox.dtl.HtmlTemplate(dojo.moduleUrl("dojox.dtl.demos.templates", "blog_detail.html")),
22
						page: new dojox.dtl.HtmlTemplate(dojo.moduleUrl("dojox.dtl.demos.templates", "blog_page.html"))
23
					}
24
				},
25
				postCreate: function(){
26
					if(this.contexts.list){
27
						this.render(this.templates.list, this.contexts.list);
28
					}else{
29
						dojo.xhrGet({
30
							url: dojo.moduleUrl("dojox.dtl.demos.json.blog", "get_blog_list.json"),
31
							handleAs: "json"
32
						}).addCallback(this, "_loadList");
33
					}
34
				},
35
				_showList: function(obj){
36
					this.render(this.templates.list, this.contexts.list);
37
				},
38
				_showDetail: function(obj){
39
					var key = obj.target.className.substring(5);
40
 
41
					if(this.contexts.blogs[key]){
42
						this.render(this.templates.detail, this.contexts.blogs[key]);
43
					}else{
44
						dojo.xhrGet({
45
							url: dojo.moduleUrl("dojox.dtl.demos.json.blog", "get_blog_" + key + ".json"),
46
							handleAs: "json",
47
							load: function(data){
48
								data.key = key;
49
								return data;
50
							}
51
						}).addCallback(this, "_loadDetail");
52
					}
53
				},
54
				_showPage: function(obj){
55
					var key = obj.target.className.substring(5);
56
 
57
					if(this.contexts.pages[key]){
58
						this.render(this.templates.page, this.contexts.pages[key]);
59
					}else{
60
						dojo.xhrGet({
61
							url: dojo.moduleUrl("dojox.dtl.demos.json.blog", "get_page_" + key + ".json"),
62
							handleAs: "json",
63
							load: function(data){
64
								data.key = key;
65
								return data;
66
							}
67
						}).addCallback(this, "_loadPage");
68
					}
69
				},
70
				_loadList: function(data){
71
					this.contexts.list = new dojox.dtl.Context(data).extend({
72
						title: "Blog Posts",
73
						base: {
74
							url: dojo.moduleUrl("dojox.dtl.demos.templates", "blog_base.html"),
75
							shared: true
76
						}
77
					});
78
					this.render(this.templates.list, this.contexts.list);
79
				},
80
				_loadDetail: function(data){
81
					var context = {
82
						title: "Blog Post",
83
						blog: data
84
					}
85
					context.blog.date = new Date(context.blog.date);
86
					context.blog.title = this.contexts.list.get("blog_list", {})[data.key].title;
87
					this.contexts.blogs[data.key] = new dojox.dtl.Context(context).extend({
88
						base: {
89
							url: dojo.moduleUrl("dojox.dtl.demos.templates", "blog_base.html"),
90
							shared: true
91
						}
92
					});
93
					this.render(this.templates.detail, this.contexts.blogs[data.key]);
94
				},
95
				_loadPage: function(data){
96
					this.contexts.pages[data.key] = new dojox.dtl.Context(data).extend({
97
						base: {
98
							url: dojo.moduleUrl("dojox.dtl.demos.templates", "blog_base.html"),
99
							shared: true
100
						}
101
					});
102
					this.render(this.templates.page, this.contexts.pages[data.key]);
103
				}
104
			});
105
 
106
			dojo.require("dojo.parser");
107
		</script>
108
	</head>
109
	<body>
110
		<div dojoType="dojox.dtl.AttachPoint">
111
			<div dojoType="demo.Blog" />
112
		</div>
113
	</body>
114
</html>