Day.js
6.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/**
* @class Ext.calendar.view.Day
* @extends Ext.container.Container
* <p>Unlike other calendar views, is not actually a subclass of {@link Ext.calendar.view.AbstractCalendar AbstractCalendar}.
* Instead it is a {@link Ext.container.Container Container} subclass that internally creates and manages the layouts of
* a {@link Ext.calendar.DayHeaderView DayHeaderView} and a {@link Ext.calendar.DayBodyView DayBodyView}. As such
* DayView accepts any config values that are valid for DayHeaderView and DayBodyView and passes those through
* to the contained views. It also supports the interface required of any calendar view and in turn calls methods
* on the contained views as necessary.</p>
* @constructor
* @param {Object} config The config object
*/
Ext.define('Ext.calendar.view.Day', {
extend: 'Ext.container.Container',
alias: 'widget.dayview',
requires: [
'Ext.calendar.view.AbstractCalendar',
'Ext.calendar.view.DayHeader',
'Ext.calendar.view.DayBody'
],
/**
* @cfg {Boolean} showTime
* True to display the current time in today's box in the calendar, false to not display it (defautls to true)
*/
showTime: true,
/**
* @cfg {Boolean} showTodayText
* True to display the {@link #todayText} string in today's box in the calendar, false to not display it (defautls to true)
*/
showTodayText: true,
/**
* @cfg {String} todayText
* The text to display in the current day's box in the calendar when {@link #showTodayText} is true (defaults to 'Today')
*/
todayText: 'Today',
/**
* @cfg {String} ddCreateEventText
* The text to display inside the drag proxy while dragging over the calendar to create a new event (defaults to
* 'Create event for {0}' where {0} is a date range supplied by the view)
*/
ddCreateEventText: 'Create event for {0}',
/**
* @cfg {String} ddMoveEventText
* The text to display inside the drag proxy while dragging an event to reposition it (defaults to
* 'Move event to {0}' where {0} is the updated event start date/time supplied by the view)
*/
ddMoveEventText: 'Move event to {0}',
/**
* @cfg {Number} dayCount
* The number of days to display in the view (defaults to 1)
*/
dayCount: 1,
// private
initComponent : function(){
// rendering more than 7 days per view is not supported
this.dayCount = this.dayCount > 7 ? 7 : this.dayCount;
var cfg = Ext.apply({}, this.initialConfig);
cfg.showTime = this.showTime;
cfg.showTodatText = this.showTodayText;
cfg.todayText = this.todayText;
cfg.dayCount = this.dayCount;
cfg.wekkCount = 1;
var header = Ext.applyIf({
xtype: 'dayheaderview',
id: this.id+'-hd'
}, cfg);
var body = Ext.applyIf({
xtype: 'daybodyview',
id: this.id+'-bd'
}, cfg);
this.items = [header, body];
this.addCls('ext-cal-dayview ext-cal-ct');
this.callParent(arguments);
},
// private
afterRender : function(){
this.callParent(arguments);
this.header = Ext.getCmp(this.id+'-hd');
this.body = Ext.getCmp(this.id+'-bd');
this.body.on('eventsrendered', this.forceSize, this);
},
// private
refresh : function(){
this.header.refresh();
this.body.refresh();
},
// private
forceSize: function(){
// The defer call is mainly for good ol' IE, but it doesn't hurt in
// general to make sure that the window resize is good and done first
// so that we can properly calculate sizes.
Ext.defer(function(){
var ct = this.el.up('.x-panel-body'),
hd = this.el.down('.ext-cal-day-header'),
h = ct.getHeight() - hd.getHeight();
this.el.child('.ext-cal-body-ct').setHeight(h);
}, 10, this);
},
// private
onResize : function(){
this.forceSize();
},
// private
getViewBounds : function(){
return this.header.getViewBounds();
},
/**
* Returns the start date of the view, as set by {@link #setStartDate}. Note that this may not
* be the first date displayed in the rendered calendar -- to get the start and end dates displayed
* to the user use {@link #getViewBounds}.
* @return {Date} The start date
*/
getStartDate : function(){
return this.header.getStartDate();
},
/**
* Sets the start date used to calculate the view boundaries to display. The displayed view will be the
* earliest and latest dates that match the view requirements and contain the date passed to this function.
* @param {Date} dt The date used to calculate the new view boundaries
*/
setStartDate: function(dt){
this.header.setStartDate(dt, true);
this.body.setStartDate(dt, true);
},
// private
renderItems: function(){
this.header.renderItems();
this.body.renderItems();
},
/**
* Returns true if the view is currently displaying today's date, else false.
* @return {Boolean} True or false
*/
isToday : function(){
return this.header.isToday();
},
/**
* Updates the view to contain the passed date
* @param {Date} dt The date to display
* @return {Date} The new view start date
*/
moveTo : function(dt, noRefresh){
this.header.moveTo(dt, noRefresh);
return this.body.moveTo(dt, noRefresh);
},
/**
* Updates the view to the next consecutive date(s)
* @return {Date} The new view start date
*/
moveNext : function(noRefresh){
this.header.moveNext(noRefresh);
return this.body.moveNext(noRefresh);
},
/**
* Updates the view to the previous consecutive date(s)
* @return {Date} The new view start date
*/
movePrev : function(noRefresh){
this.header.movePrev(noRefresh);
return this.body.movePrev(noRefresh);
},
/**
* Shifts the view by the passed number of days relative to the currently set date
* @param {Number} value The number of days (positive or negative) by which to shift the view
* @return {Date} The new view start date
*/
moveDays : function(value, noRefresh){
this.header.moveDays(value, noRefresh);
return this.body.moveDays(value, noRefresh);
},
/**
* Updates the view to show today
* @return {Date} Today's date
*/
moveToday : function(noRefresh){
this.header.moveToday(noRefresh);
return this.body.moveToday(noRefresh);
}
});