1/** 2 * tec-motore-proposte-rev.js â Integrazione Motore Proposte in fase Revisione (Ondata A) 3 */ 4(function (root) { 5 'use strict'; 6 7 var _hooks = null; 8 var _ctxCache = { id: null, ctx: null }; 9 10 root._wsMotoreProposteInit = function (hooks) { 11 _hooks = hooks || null; 12 }; 13 14 function _h(name) { 15 return _hooks && typeof _hooks[name] === 'function' ? _hooks[name] : null; 16 } 17 18 root._wsBuildApplicabilitaCtx = function () { 19 var dFn = typeof root.D === 'function' ? root.D : null; 20 var d = dFn ? dFn() : {}; 21 var getVal = _h('getVal'); 22 var pid = (typeof root.currentProjectId !== 'undefined' && root.currentProjectId) || (d && d.id) || ''; 23 if (_ctxCache.id === pid && _ctxCache.ctx) return _ctxCache.ctx; 24 var ctx = { 25 d: d, 26 settore: d.settore || d.settoreTecnologica || '', 27 ateco: d.atecoPrimario || d.atecoCode || (getVal ? getVal('atecoPrimario') : '') || '', 28 fieldApplicable: _h('fieldApplicable') 29 }; 30 if (root._tecAteco && typeof root._tecAteco.settoreDaAteco === 'function') { 31 try { ctx.settore = ctx.settore || root._tecAteco.settoreDaAteco(ctx.ateco) || ''; } catch (_) {} 32 } 33 ctx.settoreUc = String(ctx.settore).toUpperCase(); 34 _ctxCache = { id: pid, ctx: ctx }; 35 return ctx; 36 }; 37 38 root._wsIsMotoreNonApplicabile = function (fieldKey) { 39 var getStatus = _h('getStatus'); 40 if (getStatus && getStatus(fieldKey) === 'non_applicabile') return true; 41 var ev = root._wsApplicabilitaEval(fieldKey); 42 return ev && ev.applicabile === false; 43 }; 44 45 root._wsApplicabilitaEval = function (fieldKey, ctx) { 46 if (!root._tecApplicabilita || typeof root._tecApplicabilita.eval !== 'function') { 47 return { applicabile: true, motivo: '', norma: '' }; 48 } 49 return root._tecApplicabilita.eval(fieldKey, ctx || root._wsBuildApplicabilitaCtx()); 50 }; 51 52 root._wsRevKeysNonApplicabili = function () { 53 var reg = root.DVR_FIELD_REGISTRY || {}; 54 var getStatus = _h('getStatus'); 55 if (!getStatus) return []; 56 return Object.keys(reg).filter(function (k) { 57 return getStatus(k) === 'non_applicabile'; 58 }); 59 }; 60 61 root._wsRevKeysUndecidedFiltered = function (baseKeys) { 62 var getStatus = _h('getStatus'); 63 baseKeys = baseKeys || (typeof root._wsRevKeysUndecidedCore === 'function' ? root._wsRevKeysUndecidedCore() : []); 64 if (!getStatus) return baseKeys; 65 return baseKeys.filter(function (k) { return getStatus(k) !== 'non_applicabile'; }); 66 }; 67 68 root._wsRevSortByCls = function (keys) { 69 var reg = root.DVR_FIELD_REGISTRY || {}; 70 return (keys || []).slice().sort(function (a, b) { 71 var ca = (reg[a] && reg[a].cls) || 9; 72 var cb = (reg[b] && reg[b].cls) || 9; 73 if (ca !== cb) return ca - cb; 74 var sa = (reg[a] && reg[a].sev === 'alta') ? 0 : 1; 75 var sb = (reg[b] && reg[b].sev === 'alta') ? 0 : 1; 76 if (sa !== sb) return sa - sb; 77 return String(a).localeCompare(String(b)); 78 }); 79 }; 80 81 function _syncMeta(updates) { 82 var sync = _h('syncMeta'); 83 if (sync) sync(updates); 84 } 85 86 root._wsMotoreProposteRunSeed = function (force) { 87 _ctxCache = { id: null, ctx: null }; 88 var getStatus = _h('getStatus'); 89 var isFilled = _h('isFilled'); 90 var getVal = _h('getVal'); 91 var getProposed = _h('getProposed'); 92 var sync = _h('syncMeta'); 93 if (!getStatus || !sync || !root._tecApplicabilita) return 0; 94 var seedVer = (root._tecApplicabilita && root._tecApplicabilita.SEED_VERSION) || '1'; 95 var pid = (typeof root.currentProjectId !== 'undefined' && root.currentProjectId) || ''; 96 var p = typeof root.pDVR !== 'undefined' ? root.pDVR : null; 97 if (!force && p && p._motore_proposte_seed === seedVer) return 0; 98 var reg = root.DVR_FIELD_REGISTRY || {}; 99 var ctx = root._wsBuildApplicabilitaCtx(); 100 var updates = { _motore_proposte_seed: seedVer }; 101 var n = 0; 102 Object.keys(reg).forEach(function (k) { 103 var st = getStatus(k); 104 if (st === 'confermato' || st === 'modificato' || st === 'rifiutato') return; 105 var val = getVal ? getVal(k) : ''; 106 if (isFilled && isFilled(val)) return; 107 var ev = root._wsApplicabilitaEval(k, ctx); 108 if (!ev.applicabile) { 109 if (st !== 'non_applicabile' || !getMetaReason(k)) {
110 updates['_status_' + k] = 'non_applicabile'; 111 updates['_source_' + k] = 'tecdvr:non_applicabile'; 112 updates['_reasoning_' + k] = ev.motivo || ''; 113 updates['_norma_applic_' + k] = ev.norma || ''; 114 updates['_conf_' + k] = ''; 115 updates['_proposed_' + k] = ''; 116 n++; 117 } 118 return; 119 } 120 if (st === 'non_applicabile') { 121 updates['_status_' + k] = 'proposto'; 122 updates['_source_' + k] = 'tecnico:forza_applicabile'; 123 n++; 124 } 125 if (getProposed && getProposed(k)) return; 126 if (typeof root._proposteKB !== 'function') return; 127 var prop = root._proposteKB(k, ctx); 128 if (!prop || prop.valore == null || prop.valore === '') return; 129 updates['_proposed_' + k] = prop.valore; 130 updates['_status_' + k] = 'proposto'; 131 updates['_source_' + k] = prop.fonte || 'regola_kb'; 132 updates['_conf_' + k] = String(prop.confidenza || 75); 133 updates['_reasoning_' + k] = prop.motivo || ''; 134 if (prop.norma) updates['_norma_applic_' + k] = prop.norma; 135 n++; 136 }); 137 if (Object.keys(updates).length) sync(updates); 138 return n; 139 140 function getMetaReason(fk) { 141 var getMeta = _h('getMeta'); 142 return getMeta ? getMeta(fk, '_reasoning_') : ''; 143 } 144 }; 145 146 root._wsEnsureMotoreProposteSeed = function () { 147 if (typeof root._wsActiveStep === 'undefined' || root._wsActiveStep !== 2) return 0; 148 return root._wsMotoreProposteRunSeed(false); 149 }; 150 151 root._wsRevForceApplicabile = function (fieldKey) { 152 var sync = _h('syncMeta'); 153 var setD = typeof root.setD === 'function' ? root.setD : null; 154 if (!sync || !fieldKey) return; 155 var updates = {}; 156 updates['_status_' + fieldKey] = 'proposto'; 157 updates['_source_' + fieldKey] = 'tecnico:forza_applicabile'; 158 updates['_force_applicabile_' + fieldKey] = true; 159 if (setD) setD('_force_applicabile_' + fieldKey, true); 160 sync(updates); 161 if (typeof root._wsRevRefreshTable === 'function') root._wsRevRefreshTable(); 162 if (typeof root.showToast === 'function') root.showToast('Campo riattivato â ora applicabile', 'info'); 163 }; 164 165 root._wsRevConfirmAltaConfidenza = function () { 166 var getStatus = _h('getStatus'); 167 var getMeta = _h('getMeta'); 168 if (!getStatus) return; 169 var keys = root._wsRevKeysUndecidedFiltered( 170 typeof root._wsRevKeysUndecidedCore === 'function' ? root._wsRevKeysUndecidedCore() : [] 171 ); 172 var batch = keys.filter(function (k) { 173 if (getStatus(k) !== 'proposto') return false; 174 var conf = parseInt(getMeta ? getMeta(k, '_conf_') : 0, 10); 175 return conf >= 90; 176 }); 177 if (!batch.length) { 178 if (typeof root.showToast === 'function') root.showToast('Nessuna proposta ad alta confidenza da confermare', 'info'); 179 return; 180 } 181 if (!confirm('Confermare ' + batch.length + ' proposte ad alta confidenza (â¥90%)?')) return; 182 batch.forEach(function (k, i) { 183 setTimeout(function () { 184 if (typeof root._wsRevConfirmField === 'function') root._wsRevConfirmField(k, null); 185 }, i * 80); 186 }); 187 if (typeof root.showToast === 'function') root.showToast('Conferma in blocco avviata (' + batch.length + ' campi)', 'success'); 188 }; 189 190 root._wsRevMotivoBlock = function (fieldKey) { 191 var getMeta = _h('getMeta'); 192 var esc = _h('esc') || function (s) { return String(s || ''); }; 193 if (!getMeta) return ''; 194 var motivo = getMeta(fieldKey, '_reasoning_') || getMeta(fieldKey, '_norma_applic_') || ''; 195 var norma = getMeta(fieldKey, '_norma_applic_') || ''; 196 var reg = (root.DVR_FIELD_REGISTRY || {})[fieldKey] || {}; 197 if (!motivo && reg.norma) motivo = reg.norma; 198 else if (norma && motivo.indexOf(norma) < 0) motivo = motivo ? (motivo + ' · ' + norma) : norma; 199 if (!motivo) return ''; 200 return '<div class="ws-rev-perche" style="font-size:10px;color:#64748b;margin-top:4px;line-height:1.4"><strong>Perché:</strong> ' + esc(motivo) + '</div>'; 201 }; 202 203 root._wsSourceBadgeMotore = function (src, fieldKey, st) { 204 var esc = _h('esc') || function (s) { return String(s || ''); }; 205 var s = String(src || ''); 206 if (st === 'non_applicabile' || s.indexOf('non_applicabile') >= 0) { 207 return '<span class="ws-badge-na" style="background:#f1f5f9;color:#64748b;padding:2px 8px;border-radius:5px;font-size:9px;font-weight:700">' 208 + '<i class="fas fa-ban" style="font-size:8px;margin-right:3px"></i>Non applicabile</span>'; 209 } 210 if (s === 'regola_kb' || s.indexOf('regola_kb') >= 0) { 211 return '<span class="ws-badge-kb" style="background:#DBEAFE;color:#1D4ED8;padding:2px 8px;border-radius:5px;font-size:9px;font-weight:700">' 212 + '<i class="fas fa-book" style="font-size:8px;margin-right:3px"></i>Regola Tec DVR</span>'; 213 } 214 if (s.indexOf('doc:') === 0) { 215 var fn = s.replace(/^doc:/, '').trim(); 216 var short = fn.length > 18 ? fn.substring(0, 16) + '...' : fn; 217 return '<span class="ws-badge-doc" onclick="event.stopPropagation();window._wsGoToDocInAcquisisci(\'' + esc(fn).replace(/'/g, ''') + '\')" title="' + esc(fn) + '" ' 218 + 'style="background:#D1FAE5;color:#065F46;padding:2px 8px;border-radius:5px;font-size:9px;font-weight:700">' 219 + '<i class="fas fa-file-alt" style="font-size:8px;margin-right:3px"></i>' + esc(short) + '</span>'; 220 } 221 return null; 222 }; 223 224 root._wsRevRowNonApplicabileActions = function (k) { 225 return '<button type="button" onclick="event.stopPropagation();window._wsRevForceApplicabile(\'' + k + '\')" ' 226 + 'style="font-size:9px;padding:2px 8px;border:1px solid #cbd5e1;background:#fff;border-radius:4px;color:#475569;cursor:pointer">Forza applicabile</button>'; 227 }; 228})(typeof window !== 'undefined' ? window : globalThis);
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.