PageSourceSearch

https://carezza.es/assets/nested-eeed9f3f3144cf6e14f6861d9d10091f98bad4d276ad0c4eec84f6f4c76edfef.js

js carezza.es collected 2026-10-05 19:17:38 UTC 3,349 bytes, 96 lines download raw bytes

1import { Controller } from '@hotwired/stimulus'
2class Nested extends Controller {
3  add(e) {
4    e.preventDefault()
5    const t = this.templateTarget.innerHTML.replace(/NEW_RECORD/g, new Date().getTime().toString())
6    this.targetTarget.insertAdjacentHTML('beforebegin', t)
7    if ($('select').not('.select2-hidden-accessible').length > 0) {
8      var object_ids = []
9      $('select')
10        .not('.select2-hidden-accessible')
11        .each((i, s) => {
12          var object_id = $(s).attr('id').split('_').slice(0, -2).join('_')
13          if (object_ids.indexOf(object_id) === -1) {
14            object_ids.push(object_id)
15          }
16        })
17      object_ids.forEach((object_id) => {
18        this.process_select(object_id)
19      })
20    }
21  }
22  process_select(object_id) {
23    $('#' + object_id + '_country_code').select2({
24      placeholder: $(this).data('placeholder'),
25      allowClear: true,
26    })
27    $('#' + object_id + '_region_code').select2({
28      placeholder: $(this).data('placeholder'),
29      allowClear: true,
30    })
31    $('#' + object_id + '_subregion_code').select2({
32      placeholder: $(this).data('placeholder'),
33      allowClear: true,
34    })
35    $('#' + object_id + '_country_code').on('change', function (e) {
36      var country = $('#' + object_id + '_country_code option:selected').val() //$(this).val();
37      if (country === undefined) return
38      $.ajax({
39        type: 'GET',
40        url: '/admin/carmen/?country=' + country,
41      }).then(function (data) {
42        $('#' + object_id + '_region_code')
43          .empty()
44          .trigger('change')
45        $('#' + object_id + '_region_code').append(new Option('', '', false, false))
46        for (var i = 0; i < data.length; i++) {
47          var option = new Option(data[i].id, data[i].text, false, false)
48          $('#' + object_id + '_region_code').append(option)
49        }
50
51        $('#' + object_id + '_region_code').trigger('change')
52      })
53    })
54
55    $('#' + object_id + '_region_code').on('change', function (e) {
56      var country = $('#' + object_id + '_country_code option:selected').val() //$(this).val();
57      var region = $('#' + object_id + '_region_code option:selected').val() //$(this).val();
58      if (region === undefined) return
59
60      $.ajax({
61        type: 'GET',
62        url: '/admin/carmen/?country=' + country + '&region=' + region,
63      }).then(function (data) {
64        $('#' + object_id + '_subregion_code')
65          .empty()
66          .trigger('change')
67        $('#' + object_id + '_subregion_code').show()
68        $('#' + object_id + '_subregion_code').append(new Option('', '', false, false))
69        for (var i = 0; i < data.length; i++) {
70          var option = new Option(data[i].id, data[i].text, false, false)
71          $('#' + object_id + '_subregion_code').append(option)
72        }
73        $('#' + object_id + '_subregion_code').trigger('change')
74      })
75    })
76  }
77
78  remove(e) {
79    e.preventDefault()
80    const t = e.target.closest(this.wrapperSelectorValue)
81    if ('true' === t.dataset.newRecord) t.remove()
82    else {
83      t.style.display = 'none'
84      const e = t.querySelector("input[name*='_destroy']")
85      e.value = '1'
86    }
87  }
88}
89Nested.targets = ['target', 'template']
90Nested.values = {
91  wrapperSelector: {
92    type: String,
93    default: '.nested-form-wrapper',
94  },
95}
96export { Nested as default };

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.