some tidying

This commit is contained in:
Martin Donnelly 2017-08-08 01:25:41 +01:00
parent 04d9089f30
commit 36b32b5c1d
2 changed files with 13 additions and 3 deletions

View File

@ -18,23 +18,28 @@ let TrainModel = Backbone.Model.extend({
this.set('routeUrl', routeUrl);
this.set('target', target);
this.set('visible', false);
this.set('trainData', {eta:'OFF', sta: 'OFF'});
this.update();
},
update: function () {
const now = new Date;
const mod = 60000 - (now.getTime() % 60000);
const hours = now.getHours();
const limit = (hours < 6) ? 3600000 : 60000;
const mod = limit - (now.getTime() % limit);
if (hours >= 6) {
this.getTrain();
} else {
this.set('trainData', {eta:'OFF', sta: 'OFF'});
}
let trainUpdateFn = function () {
this.update();
};
setTimeout(trainUpdateFn.bind(this), mod + 10);
},
getTrain: function () {
@ -209,6 +214,11 @@ let TrainView = Backbone.View.extend({
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)`;
this.events[cevent] = "showTrains";

File diff suppressed because one or more lines are too long