aboutsummaryrefslogtreecommitdiffstats
path: root/t/app/controller/auth.t
blob: 9f08c8aa990ca163218e539aa90d6b81bdb8f0c2 (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
use strict;
use warnings;

use Test::More;

use FixMyStreet::TestMech;
my $mech = FixMyStreet::TestMech->new;

my $test_email    = 'test@example.com';
my $test_password = 'foobar';
$mech->delete_user($test_email);

END {
    $mech->delete_user($test_email);
    done_testing();
}

$mech->get_ok('/auth');

# check that we can't reach a page that is only available to authenticated users
$mech->not_logged_in_ok;

# check that submitting form with no / bad email creates an error.
$mech->get_ok('/auth');

for my $test (
    [ ''                         => 'enter an email address' ],
    [ 'not an email'             => 'check your email address is correct' ],
    [ 'bob@foo'                  => 'check your email address is correct' ],
    [ 'bob@foonaoedudnueu.co.uk' => 'check your email address is correct' ],
  )
{
    my ( $email, $error_message ) = @$test;
    pass "--- testing bad email '$email' gives error '$error_message'";
    $mech->get_ok('/auth');
    $mech->content_lacks($error_message);
    $mech->submit_form_ok(
        {
            form_name => 'general_auth',
            fields    => { email => $email, },
            button    => 'email_login',
        },
        "try to create an account with email '$email'"
    );
    is $mech->uri->path, '/auth', "still on auth page";
    $mech->content_contains($error_message);
}

# create a new account
$mech->clear_emails_ok;
$mech->get_ok('/auth');
$mech->submit_form_ok(
    {
        form_name => 'general_auth',
        fields    => { email => $test_email, },
        button    => 'email_login',
    },
    "create an account for '$test_email'"
);
is $mech->uri->path, '/auth/token', "redirected to welcome page";

# check that we are not logged in yet
$mech->not_logged_in_ok;

# check that we got one email
{
    $mech->email_count_is(1);
    my $email = $mech->get_email;
    $mech->clear_emails_ok;
    is $email->header('Subject'), "Your FixMyStreet.com account details",
      "subject is correct";
    is $email->header('To'), $test_email, "to is correct";

    # extract the link
    my ($link) = $email->body =~ m{(http://\S+)};
    ok $link, "Found a link in email '$link'";

    # check that the user does not exist
    sub get_user {
        FixMyStreet::App->model('DB::User')->find( { email => $test_email } );
    }
    ok !get_user(), "no user exists";

    # visit the confirm link (with bad token) and check user no confirmed
    $mech->get_ok( $link . 'XXX' );
    ok !get_user(), "no user exists";
    $mech->not_logged_in_ok;

    # visit the confirm link and check user is confirmed
    $mech->get_ok($link);
    ok get_user(), "user created";
    is $mech->uri->path, '/my', "redirected to the 'my' section of site";
    $mech->logged_in_ok;

    # logout and try to use the token again
    $mech->log_out_ok;
    $mech->get_ok($link);
    is $mech->uri, $link, "not logged in";
    $mech->content_contains( 'Link too old or already used',
        'token now invalid' );
    $mech->not_logged_in_ok;
}

# get a login email and change password
{
    $mech->clear_emails_ok;
    $mech->get_ok('/auth');
    $mech->submit_form_ok(
        {
            form_name => 'general_auth',
            fields    => { email => "$test_email", },
            button    => 'email_login',
        },
        "email_login with '$test_email'"
    );
    is $mech->uri->path, '/auth/token', "redirected to token page";

    # rest is as before so no need to test

    # follow link and change password - check not prompted for old password
    $mech->not_logged_in_ok;

    $mech->email_count_is(1);
    my $email = $mech->get_email;
    $mech->clear_emails_ok;
    my ($link) = $email->body =~ m{(http://\S+)};
    $mech->get_ok($link);

    $mech->follow_link_ok( { url => '/auth/change_password' } );

    ok my $form = $mech->form_name('change_password'),
      "found change password form";
    is_deeply [ sort grep { $_ } map { $_->name } $form->inputs ],    #
      [ 'confirm', 'new_password' ],
      "check we got expected fields (ie not old_password)";

    # check the various ways the form can be wrong
    for my $test (
        { new => '',       conf => '',           err => 'enter a password', },
        { new => 'secret', conf => '',           err => 'do not match', },
        { new => '',       conf => 'secret',     err => 'do not match', },
        { new => 'secret', conf => 'not_secret', err => 'do not match', },
      )
    {
        $mech->get_ok('/auth/change_password');
        $mech->content_lacks( $test->{err}, "did not find expected error" );
        $mech->submit_form_ok(
            {
                form_name => 'change_password',
                fields =>
                  { new_password => $test->{new}, confirm => $test->{conf}, },
            },
            "change_password with '$test->{new}' and '$test->{conf}'"
        );
        $mech->content_contains( $test->{err}, "found expected error" );
    }

    my $user =
      FixMyStreet::App->model('DB::User')->find( { email => $test_email } );
    ok $user, "got a user";
    ok !$user->password, "user has no password";

    $mech->get_ok('/auth/change_password');
    $mech->submit_form_ok(
        {
            form_name => 'change_password',
            fields =>
              { new_password => $test_password, confirm => $test_password, },
        },
        "change_password with '$test_password' and '$test_password'"
    );
    is $mech->uri->path, '/auth/change_password',
      "still on change password page";
    $mech->content_contains( 'password has been changed',
        "found password changed" );

    $user->discard_changes();
    ok $user->password, "user now has a password";
}

foreach my $remember_me ( '1', '0' ) {
    subtest "login using valid details (remember_me => '$remember_me')" => sub {
        $mech->get_ok('/auth');
        $mech->submit_form_ok(
            {
                form_name => 'general_auth',
                fields    => {
                    email       => $test_email,
                    password    => $test_password,
                    remember_me => ( $remember_me ? 1 : undef ),
                },
                button => 'login',
            },
            "login with '$test_email' & '$test_password"
        );
        is $mech->uri->path, '/my', "redirected to correct page";

        # check that the cookie has no expiry set
        my $expiry = $mech->session_cookie_expiry;
        $remember_me
          ? cmp_ok( $expiry, '>', 86400, "long expiry time" )
          : is( $expiry, 0, "no expiry time" );

        # logout
        $mech->log_out_ok;
    };
}

# try to login with bad details
$mech->get_ok('/auth');
$mech->submit_form_ok(
    {
        form_name => 'general_auth',
        fields    => {
            email    => $test_email,
            password => 'not the password',
        },
        button => 'login',
    },
    "login with '$test_email' & '$test_password"
);
is $mech->uri->path, '/auth', "redirected to correct page";
$mech->content_contains( 'Email or password wrong', 'found error message' );

# more test:
# TODO: test that email are always lowercased
s="p">(var i = 0; i < fixmystreet.markers.features.length; i++) { if (fixmystreet.markers.features[i].attributes.id == window.selected_problem_id) { fixmystreet.markers.features[i].attributes.size = selected_size; } else { fixmystreet.markers.features[i].attributes.size = size; } } fixmystreet.markers.redraw(); }, get_marker_by_id: function(problem_id) { return fixmystreet.markers.getFeaturesByAttribute('id', problem_id)[0]; }, marker_size_for_zoom: function(zoom) { if (zoom >= 15) { return window.selected_problem_id ? 'small' : 'normal'; } else if (zoom >= 13) { return window.selected_problem_id ? 'mini' : 'small'; } else { return 'mini'; } }, selected_marker_size_for_zoom: function(zoom) { if (zoom >= 15) { return 'big'; } else if (zoom >= 13) { return 'normal'; } else { return 'small'; } } }; var drag = { activate: function() { this._drag = new OpenLayers.Control.DragFeature( fixmystreet.markers, { onComplete: function(feature, e) { fixmystreet.update_pin( feature.geometry ); } } ); fixmystreet.map.addControl( this._drag ); this._drag.activate(); }, deactivate: function() { this._drag && this._drag.deactivate(); } }; function zoomToBounds(bounds) { if (!bounds) { return; } var center = bounds.getCenterLonLat(); var z = fixmystreet.map.getZoomForExtent(bounds); if ( z < 13 && $('html').hasClass('mobile') ) { z = 13; } fixmystreet.map.setCenter(center, z); } // `markers.redraw()` in markers_highlight will trigger an // `overFeature` event if the mouse cursor is still over the same // marker on the map, which would then run markers_highlight // again, causing an infinite flicker while the cursor remains over // the same marker. We really only want to redraw the markers when // the cursor moves from one marker to another (ie: when there is an // overFeature followed by an outFeature followed by an overFeature). // Therefore, we keep track of the previous event in // fixmystreet.latest_map_hover_event and only call markers_highlight // if we know the previous event was different to the current one. // (See the `overFeature` and `outFeature` callbacks inside of // fixmystreet.select_feature). function markers_highlight(problem_id) { for (var i = 0; i < fixmystreet.markers.features.length; i++) { if (typeof problem_id == 'undefined') { // There is no highlighted marker, so unfade this marker fixmystreet.markers.features[i].attributes.faded = 0; } else if (problem_id == fixmystreet.markers.features[i].attributes.id) { // This is the highlighted marker, unfade it fixmystreet.markers.features[i].attributes.faded = 0; } else { // This is not the hightlighted marker, fade it fixmystreet.markers.features[i].attributes.faded = 1; } } fixmystreet.markers.redraw(); } function sidebar_highlight(problem_id) { if (typeof problem_id !== 'undefined') { var $a = $('.item-list--reports a[href$="/' + problem_id + '"]'); $a.parent().addClass('hovered'); } else { $('.item-list--reports .hovered').removeClass('hovered'); } } function marker_click(problem_id, evt) { var $a = $('.item-list--reports a[href$="/' + problem_id + '"]'); if (!$a[0]) { return; } // All of this, just so that ctrl/cmd-click on a pin works?! var event; if (window.MouseEvent) { event = new MouseEvent('click', evt); $a[0].dispatchEvent(event); } else if (document.createEvent) { event = document.createEvent("MouseEvents"); event.initMouseEvent( 'click', true, true, window, 1, 0, 0, 0, 0, evt.ctrlKey, evt.altKey, evt.shiftKey, evt.metaKey, 0, null); $a[0].dispatchEvent(event); } else if (document.createEventObject) { event = document.createEventObject(); event.metaKey = evt.metaKey; event.ctrlKey = evt.ctrlKey; if (e.metaKey === undefined) { e.metaKey = e.ctrlKey; } $a[0].fireEvent("onclick", event); } else { $a[0].click(); } } function categories_or_status_changed() { // If the category or status has changed we need to re-fetch map markers fixmystreet.markers.refresh({force: true}); } function onload() { if ( fixmystreet.area.length ) { for (var i=0; i<fixmystreet.area.length; i++) { var area = new OpenLayers.Layer.Vector("KML", { strategies: [ new OpenLayers.Strategy.Fixed() ], protocol: new OpenLayers.Protocol.HTTP({ url: "/mapit/area/" + fixmystreet.area[i] + ".kml?simplify_tolerance=0.0001", format: new OpenLayers.Format.KML() }) }); fixmystreet.map.addLayer(area); if ( fixmystreet.area.length == 1 ) { area.events.register('loadend', null, function(a,b,c) { if ( fixmystreet.area_format ) { area.styleMap.styles['default'].defaultStyle = fixmystreet.area_format; } zoomToBounds( area.getDataExtent() ); }); } } } var pin_layer_style_map = new OpenLayers.StyleMap({ 'default': new OpenLayers.Style({ graphicTitle: "${title}", graphicOpacity: 1, graphicZIndex: 11, backgroundGraphicZIndex: 10 }) }); pin_layer_style_map.addUniqueValueRules('default', 'size', { 'normal': { externalGraphic: fixmystreet.pin_prefix + "pin-${colour}.png", graphicWidth: 48, graphicHeight: 64, graphicXOffset: -24, graphicYOffset: -64, backgroundGraphic: fixmystreet.pin_prefix + "pin-shadow.png", backgroundWidth: 60, backgroundHeight: 30, backgroundXOffset: -7, backgroundYOffset: -30, popupYOffset: -40 }, 'big': { externalGraphic: fixmystreet.pin_prefix + "pin-${colour}-big.png", graphicWidth: 78, graphicHeight: 105, graphicXOffset: -39, graphicYOffset: -105, backgroundGraphic: fixmystreet.pin_prefix + "pin-shadow-big.png", backgroundWidth: 88, backgroundHeight: 40, backgroundXOffset: -10, backgroundYOffset: -35 }, 'small': { externalGraphic: fixmystreet.pin_prefix + "pin-${colour}-small.png", graphicWidth: 24, graphicHeight: 32, graphicXOffset: -12, graphicYOffset: -32, backgroundGraphic: fixmystreet.pin_prefix + "pin-shadow-small.png", backgroundWidth: 30, backgroundHeight: 15, backgroundXOffset: -4, backgroundYOffset: -15, popupYOffset: -20 }, 'mini': { externalGraphic: fixmystreet.pin_prefix + "pin-${colour}-mini.png", graphicWidth: 16, graphicHeight: 20, graphicXOffset: -8, graphicYOffset: -20, popupYOffset: -10 } }); pin_layer_style_map.addUniqueValueRules('default', 'faded', { 0: { graphicOpacity: 1 }, 1: { graphicOpacity: 0.4 } }); var pin_layer_options = { rendererOptions: { yOrdering: true }, styleMap: pin_layer_style_map }; if (fixmystreet.page == 'around') { fixmystreet.bbox_strategy = fixmystreet.bbox_strategy || new OpenLayers.Strategy.FixMyStreet(); pin_layer_options.strategies = [ fixmystreet.bbox_strategy ]; pin_layer_options.protocol = new OpenLayers.Protocol.FixMyStreet({ url: '/ajax', params: fixmystreet.all_pins ? { all_pins: 1 } : { }, format: new OpenLayers.Format.FixMyStreet() }); } fixmystreet.markers = new OpenLayers.Layer.Vector("Pins", pin_layer_options); fixmystreet.markers.events.register( 'loadend', fixmystreet.markers, function(evt) { if (fixmystreet.map.popups.length) { fixmystreet.map.removePopup(fixmystreet.map.popups[0]); } }); var markers = fixmystreet.maps.markers_list( fixmystreet.pins, true ); fixmystreet.markers.addFeatures( markers ); if (fixmystreet.page == 'around' || fixmystreet.page == 'reports' || fixmystreet.page == 'my') { fixmystreet.select_feature = new OpenLayers.Control.SelectFeature( fixmystreet.markers, { hover: true, // Override clickFeature so that we can use it even though // hover is true. http://gis.stackexchange.com/a/155675 clickFeature: function (feature) { marker_click(feature.attributes.id, this.handlers.feature.evt); }, overFeature: function (feature) { if (fixmystreet.latest_map_hover_event != 'overFeature') { document.getElementById('map').style.cursor = 'pointer'; markers_highlight(feature.attributes.id); sidebar_highlight(feature.attributes.id); fixmystreet.latest_map_hover_event = 'overFeature'; } }, outFeature: function (feature) { if (fixmystreet.latest_map_hover_event != 'outFeature') { document.getElementById('map').style.cursor = ''; markers_highlight(); sidebar_highlight(); fixmystreet.latest_map_hover_event = 'outFeature'; } } } ); fixmystreet.map.addControl( fixmystreet.select_feature ); fixmystreet.select_feature.activate(); fixmystreet.map.events.register( 'zoomend', null, fixmystreet.maps.markers_resize ); // If the category filter dropdown exists on the page set up the // event handlers to populate it and react to it changing if ($("select#filter_categories").length) { $("body").on("change", "#filter_categories", categories_or_status_changed); } // Do the same for the status dropdown if ($("select#statuses").length) { $("body").on("change", "#statuses", categories_or_status_changed); } } else if (fixmystreet.page == 'new') { drag.activate(); } fixmystreet.map.addLayer(fixmystreet.markers); if ( fixmystreet.zoomToBounds ) { zoomToBounds( fixmystreet.markers.getDataExtent() ); } $('#hide_pins_link').click(function(e) { e.preventDefault(); var showhide = [ 'Show pins', 'Hide pins', 'Dangos pinnau', 'Cuddio pinnau', "Vis nåler", "Skjul nåler", "Zeige Stecknadeln", "Stecknadeln ausblenden" ]; for (var i=0; i<showhide.length; i+=2) { if (this.innerHTML == showhide[i]) { fixmystreet.markers.setVisibility(true); fixmystreet.select_feature.activate(); this.innerHTML = showhide[i+1]; } else if (this.innerHTML == showhide[i+1]) { fixmystreet.markers.setVisibility(false); fixmystreet.select_feature.deactivate(); this.innerHTML = showhide[i]; } } }); $('#all_pins_link').click(function(e) { e.preventDefault(); fixmystreet.markers.setVisibility(true); var texts = [ 'en', 'Show old', 'Hide old', 'nb', 'Vis gamle', 'Skjul gamle', 'cy', 'Cynnwys hen adroddiadau', 'Cuddio hen adroddiadau' ]; for (var i=0; i<texts.length; i+=3) { if (this.innerHTML == texts[i+1]) { this.innerHTML = texts[i+2]; fixmystreet.markers.protocol.options.params = { all_pins: 1 }; fixmystreet.markers.refresh( { force: true } ); lang = texts[i]; } else if (this.innerHTML == texts[i+2]) { this.innerHTML = texts[i+1]; fixmystreet.markers.protocol.options.params = { }; fixmystreet.markers.refresh( { force: true } ); lang = texts[i]; } } if (lang == 'cy') { document.getElementById('hide_pins_link').innerHTML = 'Cuddio pinnau'; } else if (lang == 'nb') { document.getElementById('hide_pins_link').innerHTML = 'Skjul nåler'; } else { document.getElementById('hide_pins_link').innerHTML = 'Hide pins'; } }); } $(function(){ // Set specific map config - some other JS included in the // template should define this fixmystreet.maps.config(); // Create the basics of the map fixmystreet.map = new OpenLayers.Map( "map", OpenLayers.Util.extend({ controls: fixmystreet.controls, displayProjection: new OpenLayers.Projection("EPSG:4326") }, fixmystreet.map_options) ); // Set it up our way var layer; if (!fixmystreet.layer_options) { fixmystreet.layer_options = [ {} ]; } if (!fixmystreet.layer_name) { fixmystreet.layer_name = ""; } for (var i=0; i<fixmystreet.layer_options.length; i++) { fixmystreet.layer_options[i] = OpenLayers.Util.extend({ // This option is used by XYZ-based layers zoomOffset: fixmystreet.zoomOffset, // This option is used by FixedZoomLevels-based layers minZoomLevel: fixmystreet.zoomOffset, // This option is thankfully used by them both numZoomLevels: fixmystreet.numZoomLevels }, fixmystreet.layer_options[i]); if (fixmystreet.layer_options[i].matrixIds) { layer = new fixmystreet.map_type(fixmystreet.layer_options[i]); } else { layer = new fixmystreet.map_type(fixmystreet.layer_name, fixmystreet.layer_options[i]); } fixmystreet.map.addLayer(layer); } if (!fixmystreet.map.getCenter()) { var centre = new OpenLayers.LonLat( fixmystreet.longitude, fixmystreet.latitude ); centre.transform( new OpenLayers.Projection("EPSG:4326"), fixmystreet.map.getProjectionObject() ); fixmystreet.map.setCenter(centre, fixmystreet.zoom || 3); } if (document.getElementById('mapForm')) { var click = new OpenLayers.Control.Click(); fixmystreet.map.addControl(click); click.activate(); } // Vector layers must be added onload as IE sucks if ($.browser.msie) { $(window).load(onload); } else { onload(); } (function() { var timeout; $('.item-list--reports').on('mouseenter', '.item-list--reports__item', function(){ var href = $('a', this).attr('href'); var id = parseInt(href.replace(/^.*[/]([0-9]+)$/, '$1')); clearTimeout(timeout); markers_highlight(id); }).on('mouseleave', '.item-list--reports__item', function(){ timeout = setTimeout(markers_highlight, 50); }); })(); }); // End maps closure })(); /* Overridding the buttonDown function of PanZoom so that it does zoomTo(0) rather than zoomToMaxExtent() */ OpenLayers.Control.PanZoomFMS = OpenLayers.Class(OpenLayers.Control.PanZoom, { _addButton: function(id1, id2) { var btn = document.createElement('div'), id = id1 + id2; btn.innerHTML = id1 + ' ' + id2; btn.id = this.id + "_" + id; btn.action = id; btn.className = "olButton"; this.div.appendChild(btn); if (OpenLayers.VERSION_NUMBER.indexOf('2.11') > -1) { btn.map = this.map; OpenLayers.Event.observe(btn, "mousedown", OpenLayers.Function.bindAsEventListener(this.buttonDown, btn)); var slideFactorPixels = this.slideFactor; btn.getSlideFactor = function() { return slideFactorPixels; }; } this.buttons.push(btn); return btn; }, moveTo: function(){}, draw: function(px) { // A customised version of .draw() that doesn't specify // and dimensions/positions for the buttons, since we // size and position them all using CSS. OpenLayers.Control.prototype.draw.apply(this, arguments); this.buttons = []; this._addButton("pan", "up"); this._addButton("pan", "left"); this._addButton("pan", "right"); this._addButton("pan", "down"); this._addButton("zoom", "in"); this._addButton("zoom", "out"); return this.div; } }); /* Overriding Permalink so that it can pass the correct zoom to OSM */ OpenLayers.Control.PermalinkFMS = OpenLayers.Class(OpenLayers.Control.Permalink, { _updateLink: function(alter_zoom) { var separator = this.anchor ? '#' : '?'; var href = this.base; if (href.indexOf(separator) != -1) { href = href.substring( 0, href.indexOf(separator) ); } var center = this.map.getCenter(); var zoom = this.map.getZoom(); if ( alter_zoom ) { zoom += fixmystreet.zoomOffset; } href += separator + OpenLayers.Util.getParameterString(this.createParams(center, zoom)); // Could use mlat/mlon here as well if we are on a page with a marker if (this.anchor && !this.element) { window.location.href = href; } else { this.element.href = href; } }, updateLink: function() { this._updateLink(0); } }); OpenLayers.Control.PermalinkFMSz = OpenLayers.Class(OpenLayers.Control.PermalinkFMS, { updateLink: function() { this._updateLink(1); } }); OpenLayers.Strategy.FixMyStreet = OpenLayers.Class(OpenLayers.Strategy.BBOX, { ratio: 1, // The transform in Strategy.BBOX's getMapBounds could mean you end up with // co-ordinates too precise, which could then cause the Strategy to think // it needs to update when it doesn't. So create a new bounds out of the // provided one to make sure it's passed through toFloat(). getMapBounds: function() { var bounds = OpenLayers.Strategy.BBOX.prototype.getMapBounds.apply(this); if (bounds) { bounds = new OpenLayers.Bounds(bounds.toArray()); } return bounds; }, // The above isn't enough, however, because Strategy.BBOX's getMapBounds // and calculateBounds work out the bounds in different ways, the former by // transforming the map's extent to the layer projection, the latter by // adding or subtracting from the centre. As we have a ratio of 1, rounding // errors can still occur. This override makes calculateBounds always equal // getMapBounds (so no movement means no update). calculateBounds: function(mapBounds) { if (!mapBounds) { mapBounds = this.getMapBounds(); } this.bounds = mapBounds; } }); /* Pan data request handler */ // This class is used to get a JSON object from /ajax that contains // pins for the map and HTML for the sidebar. It does a fetch whenever the map // is dragged (modulo a buffer extending outside the viewport). // This subclass is required so we can pass the 'filter_category' and 'status' query // params to /ajax if the user has filtered the map. OpenLayers.Protocol.FixMyStreet = OpenLayers.Class(OpenLayers.Protocol.HTTP, { read: function(options) { // Pass the values of the category and status fields as query params var filter_category = $("#filter_categories").val(); if (filter_category !== undefined) { options.params = options.params || {}; options.params.filter_category = filter_category; } var status = $("#statuses").val(); if (status !== undefined) { options.params = options.params || {}; options.params.status = status; } return OpenLayers.Protocol.HTTP.prototype.read.apply(this, [options]); }, CLASS_NAME: "OpenLayers.Protocol.FixMyStreet" }); /* Pan data handler */ OpenLayers.Format.FixMyStreet = OpenLayers.Class(OpenLayers.Format.JSON, { read: function(json, filter) { // Check we haven't received the data after the map has been clicked. if (fixmystreet.page == 'new') { // If we have, we want to do nothing, which means returning an // array of the back-projected version of the current pin var pin = fixmystreet.markers.features[0].clone(); pin.geometry.transform( fixmystreet.map.getProjectionObject(), new OpenLayers.Projection("EPSG:4326") ); return [ pin ]; } if (typeof json == 'string') { obj = OpenLayers.Format.JSON.prototype.read.apply(this, [json, filter]); } else { obj = json; } var current; if (typeof(obj.current) != 'undefined' && (current = document.getElementById('current'))) { current.innerHTML = obj.current; } return fixmystreet.maps.markers_list( obj.pins, false ); }, CLASS_NAME: "OpenLayers.Format.FixMyStreet" }); /* Click handler */ OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, { defaultHandlerOptions: { 'single': true, 'double': false, 'pixelTolerance': 4, 'stopSingle': false, 'stopDouble': false }, initialize: function(options) { this.handlerOptions = OpenLayers.Util.extend( {}, this.defaultHandlerOptions); OpenLayers.Control.prototype.initialize.apply( this, arguments ); this.handler = new OpenLayers.Handler.Click( this, { 'click': this.trigger }, this.handlerOptions); }, trigger: function(e) { // If we are looking at an individual report, and the report was // ajaxed into the DOM from the all reports page, then clicking // the map background should take us back to the all reports list. if ($('.js-back-to-report-list').length) { $('.js-back-to-report-list').trigger('click'); return true; } var lonlat = fixmystreet.map.getLonLatFromViewPortPx(e.xy); fixmystreet.display.begin_report(lonlat); if ( typeof ga !== 'undefined' && fixmystreet.cobrand == 'fixmystreet' ) { ga('send', 'pageview', { 'page': '/map_click' } ); } } });