aboutsummaryrefslogtreecommitdiffstats
path: root/web/cobrands/tfl/js.js
blob: e29b620b0f0b5a6e33f2f935c5a682d29f1644af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
(function(){

translation_strings.name.validName = 'Please enter your full name, Transport for London needs this information – if you do not wish your name to be shown on the site, untick the box below';
translation_strings.incident_date = { date: 'Enter a date in the format dd/mm/yyyy' };
translation_strings.time = 'Enter a time in the format hh:mm';

if (jQuery.validator) {
    jQuery.validator.addMethod('time', function(value, element) {
        return this.optional(element) || /^([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$/.test( value );
    }, translation_strings.time );
}

fixmystreet.tfl_link_update = function() {
    var lat = document.getElementById('fixmystreet.latitude');
    if (!lat) {
        return;
    }
    lat = lat.value;
    var lon = document.getElementById('fixmystreet.longitude').value;
    $('.js-not-tfl-link').each(function(){
        this.search = 'latitude=' + lat + '&longitude=' + lon;
    });
};
$(fixmystreet).on('maps:update_pin', fixmystreet.tfl_link_update);
$(fixmystreet).on('report_new:category_change', fixmystreet.tfl_link_update);

$(function() {
    function update_category_group_label() {
        var group = $("#report_inspect_form select#category option:selected").closest("optgroup").attr('label');
        var $label = $("#report_inspect_form select#category").closest("p").find("label");
        if (group) {
            $label.text("Category (" + group + ")");
        } else {
            $label.text("Category");
        }
    }
    $(document).on('change', "#report_inspect_form select#category", update_category_group_label);
    $(fixmystreet).on('display:report', update_category_group_label);
    update_category_group_label();
});

})();

OpenLayers.Layer.TLRN = OpenLayers.Class(OpenLayers.Layer.XYZ, {
    name: 'TLRN',
    url: [
        "//tilma.mysociety.org/tlrn/${z}/${x}/${y}.png",
        "//a.tilma.mysociety.org/tlrn/${z}/${x}/${y}.png",
        "//b.tilma.mysociety.org/tlrn/${z}/${x}/${y}.png",
        "//c.tilma.mysociety.org/tlrn/${z}/${x}/${y}.png"
    ],
    sphericalMercator: true,
    isBaseLayer: false,
    CLASS_NAME: "OpenLayers.Layer.TLRN"
});

$(function() {
    if (!fixmystreet.map) {
        return;
    }

    // Can't use vector layer on reports, too big, use tiles instead
    if (fixmystreet.page === 'reports') {
        var layer = new OpenLayers.Layer.TLRN();
        fixmystreet.map.addLayer(layer);
        layer.setVisibility(true);
        var pins_layer = fixmystreet.map.getLayersByName("Pins")[0];
        if (pins_layer) {
            layer.setZIndex(pins_layer.getZIndex()-1);
        }
    }
});