]> git.openstreetmap.org Git - rails.git/blob - app/views/site/_potlatch2.html.erb
Improve the unsaved edits warning for Potlatch 2
[rails.git] / app / views / site / _potlatch2.html.erb
1 <div id="map">
2   <%= t 'site.edit.flash_player_required' %>
3 </div>
4
5 <%= javascript_include_tag 'swfobject.js' %>
6
7 <% token = @user.access_token(POTLATCH2_KEY) %>
8
9 <script type="text/javascript" defer="defer">
10   var brokenContentSize = $("content").offsetWidth == 0;
11   var fo = new SWFObject("/potlatch2/potlatch2.swf?d="+Math.round(Math.random()*1000), "potlatch", "100%", "100%", "9", "#FFFFFF");
12   // 700,600 for fixed size, 100%,100% for resizable
13   var changesaved=true;
14   
15   window.onbeforeunload=function() {
16     if (!changesaved) {
17       return '<%= escape_javascript(t('site.edit.potlatch2_unsaved_changes')) %>';
18     }
19   }
20
21   function markChanged(a) { changesaved=a; }
22
23   function doSWF(lat,lon,zoom) {
24     fo.addParam("base","/potlatch2");
25     if (lat) { fo.addVariable("lat",lat); }
26     if (lon) { fo.addVariable("lon",lon); }
27     <% if params['gpx'] %>
28     fo.addVariable('gpx' ,'<%= h(params['gpx']) %>');
29     <% end %>
30     fo.addVariable("zoom",zoom);
31     fo.addVariable("api","http://<%= SERVER_URL %>/api/<%= API_VERSION %>/");
32     fo.addVariable("policy","http://<%= SERVER_URL %>/api/crossdomain.xml");
33     fo.addVariable("connection","XML");
34     fo.addVariable("oauth_token","<%= token.token %>");
35     fo.addVariable("oauth_token_secret","<%= token.secret %>");
36     fo.addVariable("oauth_consumer_key","<%= token.client_application.key %>");
37     fo.addVariable("oauth_consumer_secret","<%= token.client_application.secret %>");
38     fo.addVariable("maximise_function","maximiseMap");
39     fo.addVariable("minimise_function","minimiseMap");
40     fo.write("map");
41   }
42
43   doSWF(<%= @lat || 'null' %>,<%= @lon || 'null' %>,<%= @zoom %>);
44
45   function setPosition(lat, lon, zoom) {
46     $("potlatch").setPosition(lat, lon, Math.max(zoom || 15, 13));
47   }
48 </script>