]> git.pond.sub.org Git - eow/blob - static/dojo-release-1.1.1/dojox/dtl/demos/demo_Blog.html
add Dojo 1.1.1
[eow] / static / dojo-release-1.1.1 / dojox / dtl / demos / demo_Blog.html
1 <html>
2         <head>
3                 <title>Testing dojox.dtl using a blog example</title>
4                 <script src="../../../dojo/dojo.js" djConfig="usePlainJson: true, parseOnLoad: true"></script>
5                 <script>
6                         dojo.require("dijit._Widget");
7                         dojo.require("dojox.dtl._HtmlTemplated");
8                         dojo.require("dojo.parser");
9
10                         dojo.declare("demo.Blog", [dijit._Widget, dojox.dtl._HtmlTemplated],
11                         {
12                                 buffer: dojox.dtl.render.html.sensitivity.NODE,
13                                 templatePath: dojo.moduleUrl("dojox.dtl.demos.templates", "blog_list.html"),
14                                 base: {
15                                         url: dojo.moduleUrl("dojox.dtl.demos.templates", "blog_base.html"),
16                                         shared: true
17                                 },
18                                 constructor: function(props, node){
19                                         this.list = false;
20                                         this.blogs = {};
21                                         this.pages = {};
22                                 },
23                                 postCreate: function(){
24                                         if(!this.list){
25                                                 dojo.xhrGet({
26                                                         url: dojo.moduleUrl("dojox.dtl.demos.json.blog", "get_blog_list.json"),
27                                                         handleAs: "json"
28                                                 }).addCallback(this, "_loadList");
29                                         }
30                                 },
31                                 _showList: function(obj){
32                                         this.title = "Blog Posts";
33                                         this.setTemplate(this.templatePath);
34                                 },
35                                 _showDetail: function(obj){
36                                         var key = obj.target.className.substring(5);
37
38                                         if(this.blogs[key]){
39                                                 this.title = "Blog Post";
40                                                 this.blog = this.blogs[key];
41                                                 this.blog.title = this.blog_list[key].title;
42                                                 this.setTemplate(dojo.moduleUrl("dojox.dtl.demos.templates", "blog_detail.html"));
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.pages[key]){
58                                                 this.title = this.pages[key].title;
59                                                 this.body = this.pages[key].body;
60                                                 this.setTemplate(dojo.moduleUrl("dojox.dtl.demos.templates", "blog_page.html"));
61                                         }else{
62                                                 dojo.xhrGet({
63                                                         url: dojo.moduleUrl("dojox.dtl.demos.json.blog", "get_page_" + key + ".json"),
64                                                         handleAs: "json",
65                                                         load: function(data){
66                                                                 data.key = key;
67                                                                 return data;
68                                                         }
69                                                 }).addCallback(this, "_loadPage");
70                                         }
71                                 },
72                                 _loadList: function(data){
73                                         this.title = "Blog Posts";
74                                         dojo.mixin(this, data);
75                                         this.render();
76                                 },
77                                 _loadDetail: function(data){
78                                         data.date = new Date(data.date);
79                                         this.blogs[data.key] = data;
80                                         this.title = "Blog Post";
81                                         this.blog = data;
82                                         this.blog.title = this.blog_list[data.key].title;
83                                         this.setTemplate(dojo.moduleUrl("dojox.dtl.demos.templates", "blog_detail.html"));
84                                 },
85                                 _loadPage: function(data){
86                                         this.pages[data.key] = data;
87                                         dojo.mixin(this, data);
88                                         this.setTemplate(dojo.moduleUrl("dojox.dtl.demos.templates", "blog_page.html"));
89                                 }
90                         });
91                 </script>
92         </head>
93         <body>
94                 <div dojoType="demo.Blog" />
95         </body>
96 </html>