oxjs/source/UI/js/Form/DateTimeInput.js

71 lines
1.9 KiB
JavaScript
Raw Normal View History

2011-11-05 16:46:53 +00:00
'use strict';
2012-05-21 10:38:18 +00:00
2011-05-16 10:49:48 +00:00
/*@
2012-05-31 10:32:54 +00:00
Ox.DateTimeInput <f> DateTimeInput Element
2011-05-16 10:49:48 +00:00
options <o> Options object
ampm <b|false> false is 24h true is am/pm
format <s|short> options are short, medium, long
seconds <b|false> show seconds
value <d> defautls to now
weekday <b|false> weekday
self <o> Shared private variable
([options[, self]]) -> <o:Ox.InputGroup> DateTimeInput Element
change <!> triggered on change of value
2011-05-16 10:49:48 +00:00
@*/
2011-04-22 22:03:10 +00:00
Ox.DateTimeInput = function(options, self) {
2011-12-21 13:42:47 +00:00
var that;
self = Ox.extend(self || {}, {
options: Ox.extend({
ampm: false,
format: 'short',
milliseconds: false,
seconds: false,
value: (function() {
var date = new Date();
return Ox.formatDate(
date,
'%F ' + (options && (options.seconds || options.milliseconds) ? '%T' : '%H:%M')
) + (options && options.milliseconds ? '.' + Ox.pad(date % 1000, 3) : '');
2011-12-21 13:42:47 +00:00
}()),
weekday: false
}, options || {})
});
2011-04-22 22:03:10 +00:00
2011-12-21 13:42:47 +00:00
self.options.seconds = self.options.seconds || self.options.milliseconds;
2011-04-22 22:03:10 +00:00
that = Ox.InputGroup(Ox.extend(self.options, {
2011-12-21 13:42:47 +00:00
inputs: [
Ox.DateInput({
format: self.options.format,
id: 'date',
weekday: self.options.weekday
}),
Ox.TimeInput({
ampm: self.options.ampm,
id: 'time',
seconds: self.options.seconds
})
],
join: join,
separators: [
{title: '', width: 8}
],
split: split
}), self);
2011-12-21 13:42:47 +00:00
function join() {
return that.options('inputs').map(function($input) {
2011-12-21 15:33:52 +00:00
return $input.value();
2011-12-21 13:42:47 +00:00
}).join(' ');
}
2011-04-22 22:03:10 +00:00
2011-12-21 13:42:47 +00:00
function split() {
return self.options.value.split(' ');
2011-04-22 22:03:10 +00:00
}
return that;
};