PageSourceSearch

https://transiti.net/wp-content/plugins/crm-utils/js/ld-partner.js?ver=1.0.0

js transiti.net collected 2026-10-06 05:25:48 UTC 11,201 bytes, 268 lines download raw bytes

1(function ($) {
2    'use strict';
3
4    /* =====================================================
5       UTILITY: escape HTML
6       ===================================================== */
7    function esc(str) {
8        return $('<div>').text(String(str)).html();
9    }
10
11    /* =====================================================
12       APRI EDITOR INLINE (click sulla matita)
13       ===================================================== */
14    $(document).on('click', '.ldp-edit-btn', function (e) {
15        e.preventDefault();
16
17        var $btn   = $(this);
18        var $field = $btn.closest('.ldp-field');
19        var key    = $btn.attr('data-key');
20        var type   = $btn.attr('data-type');
21        var postId = $btn.attr('data-post');
22        var $val   = $field.find('.ldp-field-value').first();
23        var $wrap  = $field.find('.ldp-edit-wrap').first();
24
25        if ($wrap.is(':visible')) return;
26
27        // Memorizza key/type/postId sul wrap per il salvataggio
28        $wrap.attr('data-key',  key);
29        $wrap.attr('data-type', type);
30        $wrap.attr('data-post', postId);
31
32        if (type === 'select' || type === 'checkbox' || type === 'radio') {
33            // Usa il data-key del field (non del bottone) per checkbox/select/radio
34            var acfKey = $field.attr('data-key');
35            $.post(ldpAjax.url, {
36                action : 'ldp_get_acf_choices',
37                nonce  : ldpAjax.nonce,
38                key    : acfKey,
39                post_id: postId
40            }, function (res) {
41                if (res.success) {
42                    buildEditor($field, $val, $wrap, key, type, postId, res.data.choices, res.data.current);
43                } else {
44                    alert('Errore nel recupero delle scelte: ' + (res.data || ''));
45                }
46            }).fail(function () {
47                alert('Errore di rete nel recupero delle scelte.');
48            });
49
50        } else if (type === 'wysiwyg') {
51            buildEditor($field, $val, $wrap, key, type, postId, [], $val.html());
52
53        } else {
54            buildEditor($field, $val, $wrap, key, type, postId, [], $val.text().trim());
55        }
56    });
57
58    /* =====================================================
59       COSTRUISCE IL FORM DI EDITING
60       ===================================================== */
61    function buildEditor($field, $val, $wrap, key, type, postId, choices, currentVal) {
62        var html = '';
63
64        switch (type) {
65
66            case 'select':
67                html = '<select class="ldp-input">';
68                $.each(choices, function (optVal, optLabel) {
69                    var sel = (optVal === currentVal || optLabel === currentVal) ? ' selected' : '';
70                    html += '<option value="' + esc(optVal) + '"' + sel + '>' + esc(optLabel) + '</option>';
71                });
72                html += '</select>';
73                break;
74
75            case 'radio':
76                html = '<div class="ldp-radios">';
77                $.each(choices, function (optVal, optLabel) {
78                    var chk = (optVal === currentVal || optLabel === currentVal) ? ' checked' : '';
79                    html += '<label style="display:inline-block;margin-right:12px">'
80                          + '<input type="radio" class="ldp-input" name="ldp_radio_' + esc(key) + '" value="' + esc(optVal) + '"' + chk + '> '
81                          + esc(optLabel)
82                          + '</label>';
83                });
84                html += '</div>';
85                break;
86
87            case 'checkbox':
88                var currentArr = currentVal ? currentVal.split(' / ').map(function (s) { return s.trim(); }) : [];
89                html = '<div class="ldp-checkboxes">';
90                $.each(choices, function (optVal, optLabel) {
91                    var chk = (currentArr.indexOf(optLabel) !== -1 || currentArr.indexOf(optVal) !== -1) ? ' checked' : '';
92                    html += '<label style="display:block;margin:2px 0">'
93                          + '<input type="checkbox" class="ldp-input" value="' + esc(opt
93Val) + '"' + chk + '> '
94                          + esc(optLabel)
95                          + '</label>';
96                });
97                html += '</div>';
98                break;
99
100            case 'wysiwyg':
101                html = '<textarea class="ldp-input" rows="6" style="width:100%;box-sizing:border-box">' + currentVal + '</textarea>';
102                break;
103
104            case 'name_surname':
105                var parts   = currentVal.split(' ');
106                var nome    = parts[0] || '';
107                var cognome = parts.slice(1).join(' ') || '';
108                html  = 'Nome: <input type="text" class="ldp-input-name" value="' + esc(nome) + '" placeholder="Nome" style="width:110px"> ';
109                html += 'Cognome: <input type="text" class="ldp-input-surname" value="' + esc(cognome) + '" placeholder="Cognome" style="width:110px">';
110                break;
111
112            case 'number':
113                html = '<input type="number" class="ldp-input" value="' + esc(currentVal) + '" style="width:80px">';
114                break;
115
116            case 'email':
117                html = '<input type="email" class="ldp-input" value="' + esc(currentVal) + '" style="width:200px">';
118                break;
119
120            case 'date':
121                html = '<input type="date" class="ldp-input" value="' + esc(currentVal) + '">';
122                break;
123
124            default: // text
125                html = '<input type="text" class="ldp-input" value="' + esc(currentVal) + '" style="min-width:180px">';
126                break;
127        }
128
129        html += ' <button class="ldp-save-btn">Salva</button>';
130        html += ' <button class="ldp-cancel-btn">Annulla</button>';
131        html += ' <span class="ldp-notice"></span>';
132
133        $val.hide();
134        $wrap.html(html).show();
135        $wrap.find('input, select, textarea').first().focus();
136    }
137
138    /* =====================================================
139       ANNULLA
140       ===================================================== */
141    $(document).on('click', '.ldp-cancel-btn', function () {
142        var $wrap  = $(this).closest('.ldp-edit-wrap');
143        var $field = $(this).closest('.ldp-field');
144        $wrap.hide().html('');
145        $field.find('.ldp-field-value').first().show();
146    });
147
148    /* =====================================================
149       SALVA (AJAX)
150       ===================================================== */
151    $(document).on('click', '.ldp-save-btn', function () {
152        var $btn    = $(this);
153        var $wrap   = $btn.closest('.ldp-edit-wrap');
154        var $field  = $btn.closest('.ldp-field');
155        var $val    = $field.find('.ldp-field-value').first();
156        var key     = $wrap.attr('data-key');
157        var type    = $wrap.attr('data-type');
158        var postId  = $wrap.attr('data-post');
159        var $notice = $wrap.find('.ldp-notice');
160        var value;
161
162        switch (type) {
163            case 'checkbox':
164                value = [];
165                $wrap.find('input[type=checkbox]:checked').each(function () {
166                    value.push($(this).val());
167                });
168                break;
169
170            case 'radio':
171                value = $wrap.find('input[type=radio]:checked').val() || '';
172                break;
173
174            case 'name_surname':
175                value = {
176                    nome   : $wrap.find('.ldp-input-name').val().trim(),
177                    cognome: $wrap.find('.ldp-input-surname').val().trim()
178                };
179                break;
180
181            default:
182                value = $wrap.find('.ldp-input').val();
183                break;
184        }
185
186        $btn.prop('disabled', true);
187        $wrap.find('.ldp-cancel-btn').prop('disabled', true);
188        $notice.text('Salvataggio…').removeClass('ok err');
189
190        $.post(ldpAjax.url, {
191            action : 'ldp_save_field',
192            nonce  : ldpAjax.nonce,
193            key    : key,
194            type   : type,
195            post_id: postId,
196            value  : value
197        }, function (res) {
198            $btn.prop('disabled', false);
199            $wrap.find('.ldp-cancel-btn').prop('disabled', false);
200
201            if (res.success) {
202                $notice.text('✓ Salvato').addClass('ok');
203                var display = res.data.display;
204
205                if (type === 'wysiwyg') {
206                    $val.html(display);
207                } else if (type === 'email') {
208                    $val.html('<a href="mailto:' + esc(display) + '">' + esc(display) + '</a>');
209                } else if (type === 'name_surname') {
210                    $val.text(display);
211                    $('h1.ldp-field .ldp-field-value').text(display);
212                }
212 else if (type === 'radio' && key === 'prt_type') {
213                    // Aggiorna il valore visualizzato
214                    $val.text(display);
215                    // Mostra/nascondi i blocchi condizionali
216                    togglePartnerBlocks(display);
217                } else {
218                    $val.text(display);
219                }
220
221                setTimeout(function () {
222                    $wrap.hide().html('');
223                    $val.show();
224                }, 800);
225
226            } else {
227                $notice.text('✗ ' + (res.data || 'Errore sconosciuto')).addClass('err');
228            }
229
230        }).fail(function (xhr) {
231            $btn.prop('disabled', false);
232            $wrap.find('.ldp-cancel-btn').prop('disabled', false);
233            $notice.text('✗ Errore di rete (' + xhr.status + ')').addClass('err');
234        });
235    });
236
237    /* =====================================================
238       INVIO / ESC su input singoli
239       ===================================================== */
240    $(document).on('keydown', '.ldp-edit-wrap input', function (e) {
241        if (e.key === 'Enter') {
242            e.preventDefault();
243            $(this).closest('.ldp-edit-wrap').find('.ldp-save-btn').trigger('click');
244        }
245        if (e.key === 'Escape') {
246            $(this).closest('.ldp-edit-wrap').find('.ldp-cancel-btn').trigger('click');
247        }
248    });
249
250    /* =====================================================
251       VISIBILITÀ CONDIZIONALE: Professionista / Organizzazione / Non definito
252       Mostra il blocco corretto in base al valore di prt_type
253       ===================================================== */
254    function togglePartnerBlocks(tipo) {
255        if (tipo === 'Professionista') {
256            $('.ldp-prt-professionista').show();
257            $('.ldp-prt-organizzazione').hide();
258        } else if (tipo === 'Organizzazione') {
259            $('.ldp-prt-organizzazione').show();
260            $('.ldp-prt-professionista').hide();
261        } else {
262            // "Non definito" o valore vuoto: nascondi entrambi
263            $('.ldp-prt-professionista').hide();
264            $('.ldp-prt-organizzazione').hide();
265        }
266    }
267
268})(jQuery);

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.