some tidying
This commit is contained in:
parent
04d9089f30
commit
36b32b5c1d
@ -18,23 +18,28 @@ let TrainModel = Backbone.Model.extend({
|
|||||||
this.set('routeUrl', routeUrl);
|
this.set('routeUrl', routeUrl);
|
||||||
this.set('target', target);
|
this.set('target', target);
|
||||||
this.set('visible', false);
|
this.set('visible', false);
|
||||||
|
this.set('trainData', {eta:'OFF', sta: 'OFF'});
|
||||||
this.update();
|
this.update();
|
||||||
},
|
},
|
||||||
update: function () {
|
update: function () {
|
||||||
|
|
||||||
const now = new Date;
|
const now = new Date;
|
||||||
const mod = 60000 - (now.getTime() % 60000);
|
|
||||||
const hours = now.getHours();
|
const hours = now.getHours();
|
||||||
|
const limit = (hours < 6) ? 3600000 : 60000;
|
||||||
|
|
||||||
|
const mod = limit - (now.getTime() % limit);
|
||||||
|
|
||||||
if (hours >= 6) {
|
if (hours >= 6) {
|
||||||
this.getTrain();
|
this.getTrain();
|
||||||
|
} else {
|
||||||
|
this.set('trainData', {eta:'OFF', sta: 'OFF'});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let trainUpdateFn = function () {
|
let trainUpdateFn = function () {
|
||||||
|
|
||||||
this.update();
|
this.update();
|
||||||
};
|
};
|
||||||
|
|
||||||
setTimeout(trainUpdateFn.bind(this), mod + 10);
|
setTimeout(trainUpdateFn.bind(this), mod + 10);
|
||||||
},
|
},
|
||||||
getTrain: function () {
|
getTrain: function () {
|
||||||
@ -209,6 +214,11 @@ let TrainView = Backbone.View.extend({
|
|||||||
|
|
||||||
this.$button = $(`#${target}`);
|
this.$button = $(`#${target}`);
|
||||||
|
|
||||||
|
let output = 'OFF';
|
||||||
|
let status = (output === 'on time') ? 'ontime' : 'delayed';
|
||||||
|
|
||||||
|
this.$button.html(output);
|
||||||
|
this.$button.removeClass('delayed').removeClass('ontime').addClass(status);
|
||||||
|
|
||||||
let cevent = `click #$(target)`;
|
let cevent = `click #$(target)`;
|
||||||
this.events[cevent] = "showTrains";
|
this.events[cevent] = "showTrains";
|
||||||
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user