in listcalendar, cache formatted duration strings

This commit is contained in:
rlx 2011-10-11 07:05:45 +00:00
parent 3fc1611803
commit 718ec32e44
2 changed files with 33 additions and 37 deletions

View file

@ -26,6 +26,8 @@ Ox.ListCalendar = function(options, self) {
height: self.options.height + 'px' height: self.options.height + 'px'
}); });
self.durationCache = {};
Ox.print('EVENT[0]', self.options.events[0]) Ox.print('EVENT[0]', self.options.events[0])
self.columns = [ self.columns = [
@ -59,11 +61,6 @@ Ox.ListCalendar = function(options, self) {
width: 64 width: 64
}, },
{ {
/*
format: function(value, data) {
return Ox.formatDateRange(data.start, data.end, true).split(' - ')[0];
},
*/
id: 'start', id: 'start',
map: function(value) { map: function(value) {
return Ox.parseDate(value); return Ox.parseDate(value);
@ -74,11 +71,6 @@ Ox.ListCalendar = function(options, self) {
width: 144 width: 144
}, },
{ {
/*
format: function(value, data) {
return Ox.formatDateRange(data.start, data.end, true).split(' - ')[1];
},
*/
id: 'end', id: 'end',
map: function(value) { map: function(value) {
return Ox.parseDate(value); return Ox.parseDate(value);
@ -90,7 +82,12 @@ Ox.ListCalendar = function(options, self) {
}, },
{ {
format: function(value, data) { format: function(value, data) {
return Ox.formatDateRangeDuration(data.start, data.end, true); // return Ox.formatDateRangeDuration(data.start, data.end, true);
var key = data.start + ' - ' + data.end;
if (!self.durationCache[key]) {
self.durationCache[key] = Ox.formatDateRangeDuration(data.start, data.end, true);
}
return self.durationCache[key];
}, },
id: 'id', id: 'id',
map: function(value, data) { map: function(value, data) {
@ -491,26 +488,25 @@ Ox.ListCalendar = function(options, self) {
var id = self.selectedEvent, var id = self.selectedEvent,
index = Ox.getPositionById(self.options.events, id), index = Ox.getPositionById(self.options.events, id),
data = {id: id}; data = {id: id};
self.options.events[index][key] = value;
data[key] = value;
self.$list.value(id, key, value);
if (['name', 'type', 'start', 'end'].indexOf(key) > -1) {
self.$calendar.editEvent(id, key, value);
}
if (key == 'name') {
self.$eventName.options({title: value});
} else if (['start', 'end'].indexOf(key) > -1) {
self.$durationInput.options({
value: Ox.formatDateRangeDuration(
self.$startInput.options('value'),
self.$endInput.options('value')
|| Ox.formatDate(new Date(), '%Y-%m-%d %H%:%M:%S'),
true
)
});
}
self.options.editEvent(data, function(result) { self.options.editEvent(data, function(result) {
// ... self.options.events[index][key] = value;
data[key] = value;
self.$list.value(id, key, value);
if (['name', 'type', 'start', 'end'].indexOf(key) > -1) {
self.$calendar.editEvent(id, key, value);
}
if (key == 'name') {
self.$eventName.options({title: value});
} else if (['start', 'end'].indexOf(key) > -1) {
self.$durationInput.options({
value: Ox.formatDateRangeDuration(
self.$startInput.options('value'),
self.$endInput.options('value')
|| Ox.formatDate(new Date(), '%Y-%m-%d %H%:%M:%S'),
true
)
});
}
}); });
} }
@ -544,14 +540,13 @@ Ox.ListCalendar = function(options, self) {
function removeEvent() { function removeEvent() {
var id = self.selectedEvent, var id = self.selectedEvent,
index = Ox.getPositionById(self.options.events, id); index = Ox.getPositionById(self.options.events, id);
self.options.events.splice(index, 1);
var time0 = +new Date();
self.$list.options({items: Ox.clone(self.options.events, true)});
Ox.print('TIME TO SET LIST OPTIONS:', +new Date() - time0);
self.$calendar.removeEvent();
selectEvent({});
self.options.removeEvent({id: id}, function(result) { self.options.removeEvent({id: id}, function(result) {
// ... self.options.events.splice(index, 1);
var time0 = +new Date();
self.$list.options({items: Ox.clone(self.options.events, true)});
Ox.print('TIME TO SET LIST OPTIONS:', +new Date() - time0);
self.$calendar.removeEvent();
selectEvent({});
}); });
} }

View file

@ -413,6 +413,7 @@ Ox.TextList = function(options, self) {
} }
}); });
} else { } else {
// this is faster
$cell = $('<div>'); $cell = $('<div>');
} }
$cell.addClass( $cell.addClass(