PageSourceSearch

https://www.allodons.fr/assets/controllers/amounts_currency_converter_controller-2b1104c0.js

js allodons.fr collected 2026-09-26 09:16:05 UTC 2,441 bytes, 66 lines download raw bytes

1import { Controller } from "@hotwired/stimulus";
2
3// Auto-conversion EUR → USD + ILS sur le drawer "Montants suggérés".
4//
5// Quand le manager édite l'input EUR, on parse les montants (CSV virgule),
6// convertit chacun via le taux passé en data-value, arrondit à un nombre
7// "naturel" pour rester suggérable, puis remplit les inputs USD et ILS.
8//
9// EUR reste maître. USD et ILS restent éditables manuellement après remplissage
10// (l'utilisateur peut ajuster). La prochaine modif sur EUR écrasera à nouveau.
11//
12// Usage drawer :
13//   <div data-controller="amounts-currency-converter"
14//        data-amounts-currency-converter-eur-to-usd-value="1.08"
15//        data-amounts-currency-converter-eur-to-ils-value="4.10">
16//     <input data-amounts-currency-converter-target="eur"
17//            data-action="input->amounts-currency-converter#convertFromEur" ... />
18//     <input data-amounts-currency-converter-target="usd" ... />
19//     <input data-amounts-currency-converter-target="ils" ... />
20//   </div>
21export default class extends Controller {
22  static targets = ["eur", "usd", "ils"];
23  static values = {
24    eurToUsd: { type: Number, default: 1.08 },
25    eurToIls: { type: Number, default: 4.10 }
26  };
27
28  convertFromEur() {
29    const raw = (this.eurTarget.value || "").trim();
30    if (!raw) {
31      // EUR vidé → on vide aussi USD et ILS (fallback sur les défauts au render).
32      if (this.hasUsdTarget) this.usdTarget.value = "";
33      if (this.hasIlsTarget) this.ilsTarget.value = "";
34      return;
35    }
36    const eurValues = raw
37      .split(",")
38      .map(v => parseInt(v.trim(), 10))
39      .filter(v => !isNaN(v) && v > 0);
40
41    if (this.hasUsdTarget) {
42      this.usdTarget.value = eurValues
43        .map(v => this.niceRound(v * this.eurToUsdValue))
44        .join(", ");
45    }
46    if (this.hasIlsTarget) {
47      this.ilsTarget.value = eurValues
48        .map(v => this.niceRound(v * this.eurToIlsValue))
49        .join(", ");
50    }
51  }
52
53  // Arrondi "naturel" pour des montants suggérés lisibles :
54  //   < 10    → nearest 1
55  //   < 100   → nearest 5
56  //   < 1000  → nearest 10
57  //   < 10000 → nearest 50
58  //   ≥ 10000 → nearest 100
59  niceRound(v) {
60    if (v < 10) return Math.max(1, Math.round(v));
61    if (v < 100) return Math.round(v / 5) * 5;
62    if (v < 1000) return Math.round(v / 10) * 10;
63    if (v < 10000) return Math.round(v / 50) * 50;
64    return Math.round(v / 100) * 100;
65  }
66}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.