danh2000
22 Aug 2008, 4:36 AM
Hi,
Like many other people at the moment I've created a CalendarPanel with Month, Day, Week views etc, and the ability to load and display events via a DataStore.
8930
.. But I'm not ready to realease it yet:
My current implementation works well, but if I'm going to realease this as a user component I'm going to need to abstract out the implementation details: My Views need to know how to access data from the event records in the store, but I recognise that different users will have different methods of storing/defining events.
For instance one user may store an event startDate and startTime as seperate fields, another may store them together, one user may use the startTime and endTime to define all day events and another may have a boolean allDay flag...
Anyway, the only reliable way that I can come up with to abstract this out is to ask the developer using the calendar component to provide the field definitions, and to provide methods that know how to access the data that the calendar view needs (like implementing interface methods).
Something like this:
Ext.ux.xcalendar.EventRecord = function(){
var _define = function(fields,methods){
var r = Ext.data.Record.create(fields);
Ext.apply(r.prototype,methods);
return r;
};
return {
define: _define
};
}();
And to use:
var EventRecord = Ext.ux.xcalendar.EventRecord.define([
{name: 'id',type:'int'},
{name: 'startDate', type:'date', dateFormat:'d/m/Y'},
{name: 'startTime', type:'date', dateFormat:'H:i'},
{name: 'endDate', type:'date', dateFormat:'d/m/Y'},
{name: 'endTime', type:'date', dateFormat:'H:i'},
{name: 'allDay',type:'boolean'},
{name: 'title'},
{name: 'detail'}
],{
isAllDay : function() {
return this.get('allDay');
},
getStartTime:
getStartDay:
getStartMonth:
getTitle:
....
....
....
....
This could then be passed into the store which the calendar uses, and the calendar views would use the interface methods to access, filter and display the event details.
However I'm not entirely happy with this approach for some reason. Can anyone come up with an alternate approach or maybe some suggestions for improvement?
Thanks in advance,
Like many other people at the moment I've created a CalendarPanel with Month, Day, Week views etc, and the ability to load and display events via a DataStore.
8930
.. But I'm not ready to realease it yet:
My current implementation works well, but if I'm going to realease this as a user component I'm going to need to abstract out the implementation details: My Views need to know how to access data from the event records in the store, but I recognise that different users will have different methods of storing/defining events.
For instance one user may store an event startDate and startTime as seperate fields, another may store them together, one user may use the startTime and endTime to define all day events and another may have a boolean allDay flag...
Anyway, the only reliable way that I can come up with to abstract this out is to ask the developer using the calendar component to provide the field definitions, and to provide methods that know how to access the data that the calendar view needs (like implementing interface methods).
Something like this:
Ext.ux.xcalendar.EventRecord = function(){
var _define = function(fields,methods){
var r = Ext.data.Record.create(fields);
Ext.apply(r.prototype,methods);
return r;
};
return {
define: _define
};
}();
And to use:
var EventRecord = Ext.ux.xcalendar.EventRecord.define([
{name: 'id',type:'int'},
{name: 'startDate', type:'date', dateFormat:'d/m/Y'},
{name: 'startTime', type:'date', dateFormat:'H:i'},
{name: 'endDate', type:'date', dateFormat:'d/m/Y'},
{name: 'endTime', type:'date', dateFormat:'H:i'},
{name: 'allDay',type:'boolean'},
{name: 'title'},
{name: 'detail'}
],{
isAllDay : function() {
return this.get('allDay');
},
getStartTime:
getStartDay:
getStartMonth:
getTitle:
....
....
....
....
This could then be passed into the store which the calendar uses, and the calendar views would use the interface methods to access, filter and display the event details.
However I'm not entirely happy with this approach for some reason. Can anyone come up with an alternate approach or maybe some suggestions for improvement?
Thanks in advance,