define('application/widgets/clock', [
'rofl/widgets/label',
'rofl/lib/utils',
'antie/runtimecontext',
'rofl/lib/date.format'
], function (
Label,
Utils,
RuntimeContext
) {
'use strict';
var application = RuntimeContext.getCurrentApplication();
return Label.extend({
/**
* Initialises the widget.
*/
init: function init () {
init.base.call(this, '');
this.addClass('clock');
this.setTime();
this.startInitialTimeout();
},
/**
* Starts the initial timeout.
*/
startInitialTimeout: function () {
var miliSecondsInMinute = 60 * 1000;
this._timeout = setTimeout(Utils.bind(function () {
this.setTime();
this.startInterval();
}, this), miliSecondsInMinute - ((application.getDate()).getSeconds() * 1000)); // Activate first timeout when minute changes.
},
/**
* Sets the current time.
*/
setTime: function () {
var date = application.getDate();
this.setText(date.format('H:i'));
},
/**
* Starts the interval.
*/
startInterval: function () {
this._interval = setInterval(Utils.bind(this.setTime, this), 60 * 1000);
},
/**
* Disposes the widget.
*/
dispose: function dispose () {
dispose.base.call(this);
clearTimeout(this._timeout);
clearInterval(this._interval);
}
});
});