source: Dev/branches/rest-dojo-ui/client/dojox/widget/tests/CalendarStackLayout.js @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

File size: 2.9 KB
Line 
1dojo.provide("dojox.widget.tests.CalendarStackLayout");
2dojo.require("dijit.layout.ContentPane");
3dojo.require("dijit.layout.StackContainer");
4dojo.require("dojox.widget.Calendar");
5dojo.require("dijit._Widget");
6dojo.require("dijit._Container");
7dojo.require("dojo.string");
8
9dojo.declare("dojox.widget.tests.CalendarStackLayout", [dijit._Widget, dijit._Container],{
10        dateToPane: {},
11        startup: function(){
12                if(this._started){
13                        return null;
14                }
15               
16                // Get a list of the stack panes
17                var kids = this.getChildren();
18                var dates = [];
19
20                // Store the dates for each pane
21                dojo.forEach(kids, dojo.hitch(this, function(childContainer){
22                        var dateRef = childContainer.domNode.getAttribute("dateref");
23                        this.dateToPane[dateRef] = childContainer;
24                       
25                        var parts = dateRef.split("-");
26                        var date = new Date();
27                        date.setFullYear(parts[0]);
28                        date.setMonth(Number(parts[1]) - 1);
29                        date.setDate(parts[2]);
30                        dates.push(date.getTime());
31                }));
32               
33                dates.sort();
34                var lastDate = new Date(dates[dates.length -1]);
35                var firstDate = new Date(dates[0]);
36
37                var _this = this;
38
39                function getChildByDate(date){
40                        return _this.dateToPane[
41                                date.getFullYear()
42                                +  "-" + dojo.string.pad(String(date.getMonth() + 1), 2)
43                                + "-" + dojo.string.pad(String(date.getDate()))];
44                }
45
46                // Instantiate the calendar, overriding the getClassForDate and isDisabledDate functions
47                this.calendar = new dojox.widget.Calendar({
48                        getClassForDate: function(date){
49                                return getChildByDate(date) ? " hasAppointment" : " noAppointment";
50                    },
51
52                    isDisabledDate: function(date){
53                                return getChildByDate(date) ? false : true;
54                    }
55                });
56               
57                if(this.calendar.attr("value").getTime() > lastDate.getTime()){
58                        this.calendar.attr("value", lastDate);
59                }else if(this.calendar.attr("value").getTime() < firstDate.getTime()){
60                        this.calendar.attr("value", firstDate);
61                }
62
63                // Instantiate the stack container
64                this.stack = new dijit.layout.StackContainer();
65                dojo.addClass(this.stack.domNode, "calendarStack");
66
67                //Add the calendar and stack container to this widget
68                this.addChild(this.calendar);
69                this.addChild(this.stack);
70
71                // Set up some styles on the calendar and stack container
72                dojo.style(this.stack.domNode, "width", dojo.style(this.calendar.domNode, "width") + "px");
73               
74                dojo.addClass(this.stack.domNode, "dijitCalendarStackDetails");
75
76                // Add all the content panes to the stack container
77                dojo.forEach(kids, dojo.hitch(this,function(childContainer){
78                        this.stack.addChild(childContainer);
79                }));
80
81                // Add a listener to the onValueSelected method of the calendar
82                // to select the correct pane
83                dojo.connect(this.calendar, "onValueSelected", dojo.hitch(this, function(date){
84                        var pane = getChildByDate(date);
85
86                        if(pane){
87                                this.stack.selectChild(pane);
88                        }
89                }));
90               
91                // Show the last pane automatically
92                this.stack.selectChild(kids[kids.length - 1]);
93                        if(!this.stack.started && !this.stack._started){
94                                this.stack.startup();
95                        }
96                return this.inherited(arguments);
97               
98        }
99});
Note: See TracBrowser for help on using the repository browser.