Mini Kabibi Habibi
DXTravel.MyTrips = function(params) {
var nextTripsSource = DXTravel.db.trips.toDataSource({
filter: ["endDate", ">=", new Date],
sort: "startDate",
map: function(t) {
return new DXTravel.TabletTripViewModel(t);
},
postProcess: function(list) {
// custom grouping
return [
{
key: "Next trip",
items: [list[0]]
},
{
key: "Other upcoming trips",
items: list.slice(1)
}
];
}
});
var chartSource = DXTravel.db.trips.toDataSource({
filter: ["endDate", "<", new Date],
sort: "startDate",
group: function(t) {
return t.startDate.getFullYear();
},
select: function(group) {
var days = 0;
$.each(group.items, function() {
days += (this.endDate - this.startDate) / DXTravel.MS_PER_DAY
});
return {
year: group.key,
days: days
}
}
});
var mapMarkersSource = DXTravel.db.trips.toDataSource({
filter: ["endDate", "<", new Date],
select: ["location"],
map: function(i) {
return {
location: i.location
};
}
});
// TODO! dispose dataSources when the event is available
return {
viewShown: function() {
mapMarkersSource.load();
},
mapMarkersSource: mapMarkersSource,
nextTripsSource: nextTripsSource,
chartSource: chartSource,
backAction: "#Index",
backText: "Home",
};
};