<%#
# @file
# Code to request access to a map
# /maps/:id/request_access
#%>

<% content_for :title, 'Request Access | Metamaps' %>
<% content_for :mobile_title, 'Request Access'  %>

<div id="yield">
  <div class='request_access'>
    <div class='monkey'></div>
    <div class='explainer_text'>
      Hmmm. This map is private, but you can request to edit it from the map creator.
    </div>
    <div class='make_request'>REQUEST ACCESS</div>
  </div>
</div>

<script>
$(document).ready(function() {
  $('.make_request').click(function() {
    var that = $(this)
    that.off('click')
    that.text('requesting...')
    $.ajax({
      url: '/maps/<%= params[:id] %>/access_request',
      type: 'POST',
      contentType: 'application/json',
      statusCode: {
        200: function () { that.text('Request Sent'); setTimeout(function () {window.location.href = '/'}, 2000) },
        400: function () { that.text('An error occurred') }
      }
    })
  })
})
</script>
