Improved www.ttss.krakow.pl
Jacek Kowalski
2017-04-17 0f11d06782f3f2081538bd461bc9019b3c900e40
Add vehicle info before schedule table
3 files modified
31 ■■■■ changed files
index.css 7 ●●●● patch | view | raw | blame | history
index.html 2 ●●●●● patch | view | raw | blame | history
index.js 22 ●●●● patch | view | raw | blame | history
index.css
@@ -35,9 +35,14 @@
}
.vehicleInfo {
    font-size: 21px;
}
#times-table .vehicleInfo {
    float: right;
    margin: -5px 0;
    font-size: 21px;
}
#route-vehicle .vehicleInfo {
    margin-right: .5em;
}
#vehicle-data {
    float: right;
index.html
@@ -98,6 +98,8 @@
                    
                    <h3 id="route-line"></h3>
                    
                    <p id="route-vehicle"></p>
                    <table class="table table-condensed">
                        <thead>
                            <tr>
index.js
@@ -26,6 +26,7 @@
var route_xhr;
var route_line = document.getElementById('route-line');
var route_table = document.getElementById('route-table');
var route_vehicle = document.getElementById('route-vehicle');
var refresh_button = document.getElementById('refresh');
var refresh_text = document.getElementById('refresh-text');
@@ -189,7 +190,9 @@
            addCellWithText(tr, '');
            
            tr.className = 'active';
            tr.addEventListener('click', function(tripId){ return function(){ loadRoute(tripId); } }(data.old[i].tripId) );
            tr.addEventListener('click', function(tripId, vehicleInfo) {
                return function(){ loadRoute(tripId, vehicleInfo); }
            }(data.actual[i].tripId, vehicle));
            times_table.appendChild(tr);
        }
        
@@ -215,7 +218,9 @@
                tr.className = 'warning';
            }
            
            tr.addEventListener('click', function(tripId){ return function(){ loadRoute(tripId); } }(data.actual[i].tripId) );
            tr.addEventListener('click', function(tripId, vehicleInfo) {
                return function(){ loadRoute(tripId, vehicleInfo); }
            }(data.actual[i].tripId, vehicle));
            times_table.appendChild(tr);
        }
        
@@ -236,12 +241,15 @@
    }).fail(fail_ajax).always(loading_end);
}
function loadRoute(tripId) {
function loadRoute(tripId, vehicleInfo) {
    if(!tripId) tripId = route_id;
    if(!tripId) return;
    
    if(!vehicleInfo) vehicleInfo = route_vehicle_info;
    console.log('loadRoute(' + tripId + ')');
    route_id = tripId;
    route_vehicle_info = vehicleInfo;
    
    if(route_xhr) route_xhr.abort();
    route_xhr = $.get(
@@ -255,6 +263,14 @@
        }
        
        setText(route_line, data.routeName + ' ' + data.directionText);
        deleteChildren(route_vehicle);
        if(vehicleInfo) {
            var span = displayVehicle(vehicleInfo);
            setText(route_vehicle, span.title);
            route_vehicle.insertBefore(span, route_vehicle.firstChild);
        }
        deleteChildren(route_table);
        
        for(var i = 0, il = data.old.length; i < il; i++) {