1
0
Fork 0
fgdata/Phi/topics/Environment/DateTime.js

89 lines
2.6 KiB
JavaScript
Raw Normal View History

2015-01-25 12:02:20 +00:00
define([
'jquery', 'knockout', 'text!./DateTime.html', 'fgcommand', 'kojqui/datepicker', 'kojqui/spinner'
], function(jquery, ko, htmlString, fgcommand ) {
function ViewModel(params) {
var self = this;
self.timesOfToday = [
'Clock Time', 'Dawn', 'Morning', 'Noon', 'Afternoon', 'Dusk', 'Evening', 'Night',
];
self.setTimeOfToday = function(type) {
var offsetTypes = {
"Clock Time": "real",
"Dawn": "dawn",
"Morning": "morning",
"Noon": "noon",
"Afternoon": "afternoon",
"Dusk": "dusk",
"Evening": "evening",
"Night": "night",
}
offsetType = offsetTypes[type] || null;
if( ! offsetType ) {
console.log("unknown time offset type ", type );
return;
}
fgcommand.timeofday(offsetType);
}
self.wrapHour = function(evt, ui) {
2015-02-06 10:23:51 +00:00
return self._wrap(evt,ui,0,24);
2015-01-25 12:02:20 +00:00
}
self.wrapMinute = function(evt, ui) {
2015-02-06 10:23:51 +00:00
return self._wrap(evt,ui,0,60);
2015-01-25 12:02:20 +00:00
}
self._wrap = function(evt,ui,min,max) {
2015-02-06 10:23:51 +00:00
if (ui.value >= max) {
$(evt.target).spinner("value", ui.value - max);
2015-01-25 12:02:20 +00:00
return false;
} else if (ui.value < min) {
2015-02-06 10:23:51 +00:00
$(evt.target).spinner("value", ui.value + max);
2015-01-25 12:02:20 +00:00
return false;
}
2015-02-06 10:23:51 +00:00
$(evt.target).spinner("value",ui.value);
return true;
2015-01-25 12:02:20 +00:00
}
self.gmtProp = ko.observable().extend({ fgprop: 'gmt' });
2015-02-06 10:23:51 +00:00
self.simTimeUTC = ko.pureComputed({
read: function() {
return new Date(self.gmtProp() + "Z");
},
write: function(newValue) {
console.log("new time: ", newValue );
}
2015-01-25 12:02:20 +00:00
});
self.hour = ko.pureComputed({
read: function() {
2015-02-06 10:23:51 +00:00
return self.simTimeUTC().getUTCHours();
2015-01-25 12:02:20 +00:00
},
write: function(newValue) {
2015-02-06 10:23:51 +00:00
console.log("new hour", newValue );
2015-01-25 12:02:20 +00:00
}
});
self.minute = ko.pureComputed({
read: function() {
2015-02-06 10:23:51 +00:00
return self.simTimeUTC().getUTCMinutes();
2015-01-25 12:02:20 +00:00
},
write: function(newValue) {
2015-02-06 10:23:51 +00:00
console.log("new minute", newValue );
2015-01-25 12:02:20 +00:00
}
});
}
ViewModel.prototype.dispose = function() {
}
// Return component definition
return {
viewModel : ViewModel,
template : htmlString
};
});