fix a corner case in Ox.formatDateRangeDuration()
This commit is contained in:
parent
46ef208be2
commit
ccece375c0
4 changed files with 28 additions and 12 deletions
|
@ -46,9 +46,6 @@ Ox.Calendar = function(options, self) {
|
||||||
//height: self.options.height + 'px'
|
//height: self.options.height + 'px'
|
||||||
})
|
})
|
||||||
.bindEvent({
|
.bindEvent({
|
||||||
anyclick: function(e) {
|
|
||||||
!$(e.target).is('.OxInput') && that.gainFocus();
|
|
||||||
},
|
|
||||||
key_0: function() {
|
key_0: function() {
|
||||||
panToSelected();
|
panToSelected();
|
||||||
},
|
},
|
||||||
|
@ -81,6 +78,9 @@ Ox.Calendar = function(options, self) {
|
||||||
},
|
},
|
||||||
key_up: function() {
|
key_up: function() {
|
||||||
scrollBy(-1);
|
scrollBy(-1);
|
||||||
|
},
|
||||||
|
mousedown: function(e) {
|
||||||
|
!$(e.target).is('.OxInput') && that.gainFocus();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -490,10 +490,14 @@ Ox.ListCalendar = function(options, self) {
|
||||||
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;
|
self.options.events[index][key] = value;
|
||||||
//Ox.print('EQUAL?', Ox.isEqual(self.$list.options('items'), self.options.events));
|
|
||||||
//alert(self.options.events[index][key] + '\n' + self.$list.options('items')[index][key]);
|
|
||||||
data[key] = value;
|
data[key] = value;
|
||||||
if (['start', 'end'].indexOf(key) > -1) {
|
self.$list.options({items: Ox.clone(self.options.events, true)});
|
||||||
|
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({
|
self.$durationInput.options({
|
||||||
value: Ox.formatDateRangeDuration(
|
value: Ox.formatDateRangeDuration(
|
||||||
self.$startInput.options('value'),
|
self.$startInput.options('value'),
|
||||||
|
@ -503,10 +507,7 @@ Ox.ListCalendar = function(options, self) {
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
self.$list.options({items: Ox.clone(self.options.events, true)});
|
|
||||||
if (['name', 'type', 'start', 'end'].indexOf(key) > -1) {
|
|
||||||
self.$calendar.editEvent(id, key, value);
|
|
||||||
}
|
|
||||||
self.options.editEvent(data, function(result) {
|
self.options.editEvent(data, function(result) {
|
||||||
// ...
|
// ...
|
||||||
});
|
});
|
||||||
|
|
|
@ -177,6 +177,7 @@ Ox.Select = function(options, self) {
|
||||||
|
|
||||||
self.setOption = function(key, value) {
|
self.setOption = function(key, value) {
|
||||||
if (key == 'value') {
|
if (key == 'value') {
|
||||||
|
Ox.print('SETTING VALUE OPTION', value)
|
||||||
that.selectItem(value);
|
that.selectItem(value);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -223,6 +224,8 @@ Ox.Select = function(options, self) {
|
||||||
//Ox.print('selected::', that.selected())
|
//Ox.print('selected::', that.selected())
|
||||||
return that.selected()[0].id;
|
return that.selected()[0].id;
|
||||||
} else {
|
} else {
|
||||||
|
that.selectItem(arguments[0]);
|
||||||
|
return that;
|
||||||
/*
|
/*
|
||||||
Ox.print('ELSE');
|
Ox.print('ELSE');
|
||||||
that.selectItem(arguments[0]);
|
that.selectItem(arguments[0]);
|
||||||
|
|
|
@ -382,19 +382,31 @@ Ox.formatDateRangeDuration = function(start, end, utc) {
|
||||||
Ox.forEach(keys, function(key, i) {
|
Ox.forEach(keys, function(key, i) {
|
||||||
while (true) {
|
while (true) {
|
||||||
if (key == 'month') {
|
if (key == 'month') {
|
||||||
|
// set the day to the same day in the next month,
|
||||||
|
// or to its last day if the next month is shorter
|
||||||
|
var day = Ox.getDate(date, utc);
|
||||||
Ox.setDate(date, Math.min(
|
Ox.setDate(date, Math.min(
|
||||||
Ox.getDate(date, utc),
|
day,
|
||||||
Ox.getDaysInMonth(
|
Ox.getDaysInMonth(
|
||||||
Ox.getFullYear(date, utc),
|
Ox.getFullYear(date, utc),
|
||||||
Ox.getMonth(date, utc) + 2
|
Ox.getMonth(date, utc) + 2,
|
||||||
|
utc
|
||||||
)
|
)
|
||||||
), utc);
|
), utc);
|
||||||
}
|
}
|
||||||
|
// advance the date by one unit
|
||||||
Ox['set' + parts[i]](date, Ox['get' + parts[i]](date, utc) + 1, utc);
|
Ox['set' + parts[i]](date, Ox['get' + parts[i]](date, utc) + 1, utc);
|
||||||
|
Ox.print(key, '.....', date)
|
||||||
if (date <= dates[1]) {
|
if (date <= dates[1]) {
|
||||||
|
// still within the range, add one unit
|
||||||
values[i] = (values[i] || 0) + 1;
|
values[i] = (values[i] || 0) + 1;
|
||||||
} else {
|
} else {
|
||||||
|
// outside the range, rewind the date by one unit
|
||||||
Ox['set' + parts[i]](date, Ox['get' + parts[i]](date, utc) - 1, utc);
|
Ox['set' + parts[i]](date, Ox['get' + parts[i]](date, utc) - 1, utc);
|
||||||
|
if (key == 'month') {
|
||||||
|
// and revert to original day
|
||||||
|
Ox.setDate(date, day, utc);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue