Sha256: b5b555b80f7db23b9f934bd8456f20f383330a6636a2eccb1921b6ee121091f6

Contents?: true

Size: 1.62 KB

Versions: 26

Compression:

Stored size: 1.62 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");
  let latFieldName = "latitude";
  let longFieldName = "longitude";

  if ($addressInputField.length > 0) {
    latFieldName = getCoordinateInputName("latitude", $addressInputField, {})
    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

26 entries across 26 versions & 1 rubygems

Version Path
decidim-proposals-0.27.9 app/packs/src/decidim/proposals/add_proposal.js
decidim-proposals-0.27.8 app/packs/src/decidim/proposals/add_proposal.js
decidim-proposals-0.27.7 app/packs/src/decidim/proposals/add_proposal.js
decidim-proposals-0.27.6 app/packs/src/decidim/proposals/add_proposal.js
decidim-proposals-0.26.10 app/packs/src/decidim/proposals/add_proposal.js
decidim-proposals-0.26.9 app/packs/src/decidim/proposals/add_proposal.js
decidim-proposals-0.27.5 app/packs/src/decidim/proposals/add_proposal.js
decidim-proposals-0.26.8 app/packs/src/decidim/proposals/add_proposal.js
decidim-proposals-0.27.4 app/packs/src/decidim/proposals/add_proposal.js
decidim-proposals-0.27.3 app/packs/src/decidim/proposals/add_proposal.js
decidim-proposals-0.26.7 app/packs/src/decidim/proposals/add_proposal.js
decidim-proposals-0.26.5 app/packs/src/decidim/proposals/add_proposal.js
decidim-proposals-0.27.2 app/packs/src/decidim/proposals/add_proposal.js
decidim-proposals-0.27.1 app/packs/src/decidim/proposals/add_proposal.js
decidim-proposals-0.26.4 app/packs/src/decidim/proposals/add_proposal.js
decidim-proposals-0.27.0 app/packs/src/decidim/proposals/add_proposal.js
decidim-proposals-0.26.3 app/packs/src/decidim/proposals/add_proposal.js
decidim-proposals-0.27.0.rc2 app/packs/src/decidim/proposals/add_proposal.js
decidim-proposals-0.27.0.rc1 app/packs/src/decidim/proposals/add_proposal.js
decidim-proposals-0.26.2 app/packs/src/decidim/proposals/add_proposal.js