ikuseiGmbH/smart-village-app-cms

View on GitHub
app/views/defect_reports/_modal_content.html.erb

Summary

Maintainability
Test Coverage
<div class="modal fade" id="content_<%= defect_report.id %>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <div>
          <strong><%= defect_report.categories.first.try(:name) %></strong>
          <h5 class="modal-title" id="exampleModalLabel">
            <%= defect_report.content_blocks.first.try(:title) %>
          </h5>
        </div>
        <button class="close" type="button" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">×</span>
        </button>
      </div>
      <div class="modal-body">
        <%= defect_report.content_blocks.first.try(:body) %>

        <% image_url = defect_report.media_contents.first.try(:source_url).try(:url) %>

        <% if image_url %>
          <%= image_tag(image_url, class: "mt-3") %>
        <% end %>

        <% address = defect_report.addresses.try(:first) %>

        <% if address.present? %>
          <% street = address.street %>
          <% zip = address.zip %>
          <% city = address.city %>

          <div class="row">
            <div class="col mt-3">
              <%= "Adresse: #{street}, #{zip} #{city}" if street && zip && city %>

              <%= hidden_field_tag "#{defect_report.id}-geo_location_latitude", address.try(:geo_location).try(:latitude) %>
              <%= hidden_field_tag "#{defect_report.id}-geo_location_longitude", address.try(:geo_location).try(:longitude) %>
              <div id="leafletMap-<%= defect_report.id %>" class="leafletMap" data-map-click="false" data-map-in-modal="true"></div>
            </div>
          </div>
        <% end %>
      </div>
      <div class="modal-footer">
        <div class="mr-auto">
          Name: <%= defect_report.contacts.first.try(:first_name) %>
          <br />
          E-Mail:
          <a
            href="mailto:<%= defect_report.contacts.first.try(:email) %>"
            title="mail to <%= defect_report.contacts.first.try(:email) %>"
            target="_blank"
          >
            <%= defect_report.contacts.first.try(:email) %>
          </a>
          <br />
          Telefon: <%= defect_report.contacts.first.try(:phone) %>
        </div>
      </div>
    </div>
  </div>
</div>

<script>
  $('[data-target="#content_<%= defect_report.id %>"]').on('click', function() {
    setTimeout(() => {
      window.map['leafletMap-<%= defect_report.id %>'].invalidateSize();
    }, 500);
  });
</script>