Sha256: 17e19543f2fc2b22422c9683466f28b4f6dec6b78be077d5b32cf912b4c268ef

Contents?: true

Size: 1.52 KB

Versions: 11

Compression:

Stored size: 1.52 KB

Contents

import attachGeocoding from "src/decidim/geocoding/attach_input"
import getCoordinateInputName from "src/decidim/geocoding/coordinate_input";

$(() => {
  const $checkbox = $("input:checkbox[name$='[has_address]']");
  const $addressInput = $("#address_input");
  const $addressInputField = $("input", $addressInput);
  const $map = $("#address_map");
  const latFieldName = getCoordinateInputName("latitude", $addressInputField, {})
  const longFieldName = getCoordinateInputName("longitude", $addressInputField, {})
  $map.hide();

  if ($checkbox.length > 0) {
    const toggleInput = () => {
      if ($checkbox[0].checked) {
        $addressInput.show();
        $addressInputField.prop("disabled", false);
      } else {
        $addressInput.hide();
        $addressInputField.prop("disabled", true);
      }
    }
    toggleInput();
    $checkbox.on("change", toggleInput);
  }

  if ($addressInput.length > 0) {
    if ($checkbox[0].checked) {
      $map.show();
    }

    const ctrl = $("[data-decidim-map]").data("map-controller");
    ctrl.setEventHandler("coordinates", (ev) => {
      $(`input[name='${latFieldName}']`).val(ev.lat);
      $(`input[name='${longFieldName}']`).val(ev.lng);
    });

    attachGeocoding($addressInputField, null, (coordinates) => {
      $map.show();
      // Remove previous marker when user updates address in address field
      ctrl.removeMarker();
      ctrl.addMarker({
        latitude: coordinates[0],
        longitude: coordinates[1],
        address: $addressInput.val()
      });
    });
  }
});

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
decidim-enhanced_textwork-1.0.5 app/packs/src/decidim/enhanced_textwork/add_paragraph.js
decidim-enhanced_textwork-1.0.4 app/packs/src/decidim/enhanced_textwork/add_paragraph.js
decidim-enhanced_textwork-1.0.3 app/packs/src/decidim/enhanced_textwork/add_paragraph.js
decidim-enhanced_textwork-1.0.2 app/packs/src/decidim/enhanced_textwork/add_paragraph.js
decidim-enhanced_textwork-1.0.1 app/packs/src/decidim/enhanced_textwork/add_paragraph.js
decidim-enhanced_textwork-1.0.0 app/packs/src/decidim/enhanced_textwork/add_paragraph.js
decidim-proposals-0.25.0 app/packs/src/decidim/proposals/add_proposal.js
decidim-proposals-0.25.0.rc4 app/packs/src/decidim/proposals/add_proposal.js
decidim-proposals-0.25.0.rc3 app/packs/src/decidim/proposals/add_proposal.js
decidim-proposals-0.25.0.rc2 app/packs/src/decidim/proposals/add_proposal.js
decidim-proposals-0.25.0.rc1 app/packs/src/decidim/proposals/add_proposal.js