| | |
| | | var alert_text = document.getElementById('alert-text'); |
| | | var alert_close = document.getElementById('alert-close'); |
| | | |
| | | var progress = document.getElementById('progress'); |
| | | |
| | | var parseStatusBoarding = '>>>'; |
| | | function parseStatus(status) { |
| | | switch(status.status) { |
| | |
| | | } |
| | | |
| | | function fail(message, more) { |
| | | if(refresh_timer) clearInterval(refresh_timer); |
| | | if(times_timer) clearTimeout(times_timer); |
| | | |
| | | setText(alert_text, message); |
| | |
| | | } |
| | | } |
| | | |
| | | function fail_hide() { |
| | | alert.style.display = 'none'; |
| | | } |
| | | |
| | | function loading_start() { |
| | | progress.style.display = 'block'; |
| | | } |
| | | |
| | | function loading_end() { |
| | | progress.style.display = 'none'; |
| | | } |
| | | |
| | | function loadTimes(stopId = null, clearRoute = false) { |
| | | if(!stopId) stopId = stop_id; |
| | | if(!stopId) return; |
| | |
| | | |
| | | refresh_button.removeAttribute('disabled'); |
| | | |
| | | loading_start(); |
| | | times_xhr = $.get( |
| | | ttss_base + '/passageInfo/stopPassages/stop' |
| | | + '?stop=' + encodeURIComponent(stopId) |
| | |
| | | addCellWithText(tr, data.actual[i].patternText); |
| | | addCellWithText(tr, data.actual[i].direction); |
| | | var status = parseStatus(data.actual[i]); |
| | | addCellWithText(tr, status); |
| | | var status_cell = addCellWithText(tr, status); |
| | | var delay = parseDelay(data.actual[i]); |
| | | addCellWithText(tr, delay); |
| | | var delay_cell = addCellWithText(tr, delay); |
| | | |
| | | if(status == parseStatusBoarding) tr.className = 'success'; |
| | | else if(parseInt(delay) > 9) tr.className = 'danger'; |
| | | else if(parseInt(delay) > 3) tr.className = 'warning'; |
| | | if(status == parseStatusBoarding) { |
| | | tr.className = 'success'; |
| | | status_cell.className = 'status-boarding'; |
| | | } else if(parseInt(delay) > 9) { |
| | | tr.className = 'danger'; |
| | | delay_cell.className = 'status-delayed'; |
| | | } else if(parseInt(delay) > 3) { |
| | | tr.className = 'warning'; |
| | | } |
| | | times_table.appendChild(tr); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | startTimer(new Date()); |
| | | fail_hide(); |
| | | |
| | | times_timer = setTimeout(function(){ loadTimes(); }, ttss_refresh); |
| | | }).fail(fail_ajax); |
| | | }).fail(fail_ajax).always(loading_end); |
| | | } |
| | | |
| | | function declinate(num, singular, plural) { |
| | |
| | | e.preventDefault(); |
| | | if(!stop_name_autocomplete.value) return; |
| | | stop_id = stop_name_autocomplete.value; |
| | | window.location.hash = '#!' + stop_id; |
| | | loadTimes(stop_id, true); |
| | | }); |
| | | |
| | |
| | | alert_close.addEventListener('click', function(e) { |
| | | alert.style.display = 'none'; |
| | | }); |
| | | |
| | | if(window.location.hash.match(/^#![0-9]+$/)) { |
| | | stop_id = parseInt(window.location.hash.slice(2)); |
| | | loadTimes(stop_id); |
| | | } |
| | | } |
| | | |
| | | init(); |