@@ -284,79 +276,87 @@
} catch (e) { showToast("Error de conexión", true); }
}
- function openEditor(id) {
- const svc = scrapedData.find(s => s.id === id);
- if(!svc) return;
- const raw = svc.raw_data;
- const companyName = raw['Compañía'] || raw['COMPAÑIA'] || raw['Procedencia'] || "";
-
- document.getElementById('modalCompanyLogo').innerHTML = `
})
`;
- document.getElementById('displayRef').innerText = `REF: ${svc.service_ref}`;
- document.getElementById('displayCompany').innerText = companyName;
- document.getElementById('modalStatusBadge').innerHTML = `
SERVICIO ACTIVO`;
+ async function openEditor(id) {
+ const svc = scrapedData.find(s => s.id === id);
+ if(!svc) return;
+ const raw = svc.raw_data;
+ const companyName = raw['Compañía'] || raw['COMPAÑIA'] || raw['Procedencia'] || "";
+
+ document.getElementById('modalCompanyLogo').innerHTML = `
})
`;
+ document.getElementById('displayRef').innerText = `REF: ${svc.service_ref}`;
+ document.getElementById('displayCompany').innerText = companyName;
+ document.getElementById('modalStatusBadge').innerHTML = `
SERVICIO ACTIVO`;
- document.getElementById('impScrapedId').value = id;
- document.getElementById('impName').value = raw['Nombre Cliente'] || raw['CLIENTE'] || "S/N";
-
- const rawPhone = raw['Teléfono'] || raw['TELEFONOS'] || raw['TELEFONO'] || "";
- document.getElementById('impPhone').value = rawPhone.match(/[6789]\d{8}/)?.[0] || "";
-
- const addr = raw['Dirección'] || raw['DOMICILIO'] || "";
- const pop = raw['Población'] || raw['POBLACION-PROVINCIA'] || "";
- document.getElementById('impAddress').value = `${addr} ${pop}`.trim();
- document.getElementById('impCP').value = raw['Código Postal'] || raw['C.P.'] || "";
- document.getElementById('impDesc').value = raw['Descripción'] || "";
-
- const isUrgent = raw['Urgente'] === 'Sí' || raw['Urgente'] === 'true' || raw['URGENTE'] === 'SI';
- document.getElementById('impUrgent').value = isUrgent.toString();
-
- // RECUPERACIÓN DE DATOS GUARDADOS PREVIAMENTE
- document.getElementById('impNotesInt').value = raw['internal_notes'] || "";
- document.getElementById('impNotesExt').value = raw['client_notes'] || "";
-
- // Cargar Gremio y disparar carga de operarios si ya existía
- const savedGuild = raw['guild_id'] || "";
- document.getElementById('impGuild').value = savedGuild;
-
- if(savedGuild) {
- loadOpsForGuild(savedGuild).then(() => {
- document.getElementById('impOperator').value = raw['assigned_to'] || "";
- });
- } else {
- document.getElementById('impOperator').innerHTML = '
';
- }
+ document.getElementById('impScrapedId').value = id;
+ document.getElementById('impName').value = raw['Nombre Cliente'] || raw['CLIENTE'] || "S/N";
+ const rawPhone = raw['Teléfono'] || raw['TELEFONOS'] || raw['TELEFONO'] || "";
+ document.getElementById('impPhone').value = rawPhone.match(/[6789]\d{8}/)?.[0] || "";
+ const addr = raw['Dirección'] || raw['DOMICILIO'] || "";
+ const pop = raw['Población'] || raw['POBLACION-PROVINCIA'] || "";
+ document.getElementById('impAddress').value = `${addr} ${pop}`.trim();
+ document.getElementById('impCP').value = raw['Código Postal'] || raw['C.P.'] || "";
+ document.getElementById('impDesc').value = raw['Descripción'] || "";
+
+ const isUrgent = raw['Urgente'] === 'Sí' || raw['Urgente'] === 'true' || raw['URGENTE'] === 'SI';
+ document.getElementById('impUrgent').value = isUrgent.toString();
+
+ // --- RECUPERACIÓN DE DATOS GUARDADOS PREVIAMENTE ---
+ document.getElementById('impNotesInt').value = raw['internal_notes'] || "";
+ document.getElementById('impNotesExt').value = raw['client_notes'] || "";
+
+ const savedGuild = raw['guild_id'] || "";
+ document.getElementById('impGuild').value = savedGuild;
+
+ if(savedGuild) {
+ // Cargamos operarios y luego seleccionamos el guardado
+ await loadOpsForGuild(savedGuild);
+ document.getElementById('impOperator').value = raw['assigned_to'] || "";
+ } else {
+ document.getElementById('impOperator').innerHTML = '
';
+ }
+
+ document.getElementById('importModal').classList.remove('hidden');
+ lucide.createIcons();
+ }
- document.getElementById('importModal').classList.remove('hidden');
- lucide.createIcons();
-}
function closeModal() { document.getElementById('importModal').classList.add('hidden'); }
async function saveDraftChanges(e) {
const id = document.getElementById('impScrapedId').value;
const btn = e.currentTarget;
btn.disabled = true;
+
const payload = {
name: document.getElementById('impName').value,
phone: document.getElementById('impPhone').value,
address: document.getElementById('impAddress').value,
cp: document.getElementById('impCP').value,
description: document.getElementById('impDesc').value,
+ is_urgent: document.getElementById('impUrgent').value === 'true',
+ // --- CAMPOS CORREGIDOS PARA EL GUARDADO ---
guild_id: document.getElementById('impGuild').value,
- assigned_to: document.getElementById('impOperator').value || null,
+ assigned_to: document.getElementById('impOperator').value,
internal_notes: document.getElementById('impNotesInt').value,
- client_notes: document.getElementById('impNotesExt').value,
- is_urgent: document.getElementById('impUrgent').value === 'true'
+ client_notes: document.getElementById('impNotesExt').value
};
+
try {
const res = await fetch(`${API_URL}/providers/scraped/${id}`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${localStorage.getItem("token")}` },
body: JSON.stringify(payload)
});
- if(res.ok) { showToast("✅ Borrador guardado"); loadInbox(); }
- else { showToast("❌ Error al guardar", true); }
- } catch (e) { showToast("❌ Error de red", true); }
- finally { btn.disabled = false; }
+ if(res.ok) {
+ showToast("✅ Borrador guardado correctamente");
+ loadInbox();
+ } else {
+ showToast("❌ Error al guardar", true);
+ }
+ } catch (e) {
+ showToast("❌ Error de red", true);
+ } finally {
+ btn.disabled = false;
+ }
}
async function handleFinalImport(event) {