Filling edit form

This commit is contained in:
Juan Pablo Vial
2025-11-12 19:49:08 -03:00
parent e278695137
commit 54969eeeab
6 changed files with 116 additions and 89 deletions

View File

@ -23,7 +23,6 @@
$modal: null,
form: null,
$date: null,
$rut: null,
rut: null,
digit: null,
$birthdate: null,
@ -90,7 +89,7 @@
this.get.brokers(project_id)
this.get.promotions(project_id).then(() => {
const promotions = reservations.data.promotions[project_id]
const promotions = structuredClone(reservations.data.promotions[project_id])
this.components.promotions.data.promotions = promotions.map(promotion => {
return {
text: promotion.description,
@ -101,7 +100,7 @@
this.components.promotions.draw.promotions()
})
this.get.units(project_id).then(() => {
const unitTypes = reservations.data.units[project_id]
const unitTypes = structuredClone(reservations.data.units[project_id])
Object.entries(unitTypes).map(([type, units]) => {
units = units.map(unit => {
return {
@ -142,24 +141,6 @@
this.components.$comuna.dropdown('set selected', this.data.current_user.direccion.comuna.id)
}
})
/*const uri = `/api/region/${region_id}/comunas`
return APIClient.fetch(uri).then(response => response.json()).then(json => {
if (json.comunas.length === 0) {
return
}
this.data.comunas[region_id] = json.comunas.map(comuna => {
return {
text: comuna.descripcion,
name: comuna.descripcion,
value: comuna.id
}
})
this.components.$comuna.dropdown('change values', this.data.comunas[region_id])
if (this.data.current_user !== null && this.data.current_user?.direccion?.comuna !== null) {
this.components.$comuna.dropdown('set selected', this.data.current_user.direccion.comuna.id)
}
})*/
},
brokers: project_id => {
if (project_id in this.data.brokers) {
@ -167,41 +148,10 @@
resolve(this.data.brokers[project_id])
})
}
return reservations.get.brokers(project_id).then(brokers => {
this.data.brokers[project_id] = brokers
return reservations.get.brokers(project_id).then(() => {
this.data.brokers[project_id] = reservations.data.brokers[project_id]
this.fill.brokers()
})
/*const uri = `/api/proyecto/${project_id}/brokers`
return APIClient.fetch(uri).then(response => response.json()).then(json => {
if (json.contracts.length === 0) {
return
}
const formatter = new Intl.NumberFormat('es-CL', { style: 'percent', minimumFractionDigits: 2 })
this.data.brokers[project_id] = json.contracts.map(contract => {
return {
id: contract.id,
broker_rut: contract.broker_rut,
commission: formatter.format(contract.commission),
name: '',
text: '',
}
})
const promises = []
json.contracts.forEach(contract => {
promises.push(this.get.broker(contract.broker_rut))
})
return Promise.all(promises).then(data => {
data.forEach(broker => {
if (!('rut' in broker)) {
return
}
const idx = this.data.brokers[project_id].findIndex(contract => contract.broker_rut === broker.rut)
this.data.brokers[project_id][idx].name = this.data.brokers[project_id][idx].text = `${broker.name} - ${this.data.brokers[project_id][idx].commission}`
})
this.fill.brokers()
})
})*/
},
broker: (broker_rut) => {
const uri = `/api/proyectos/broker/${broker_rut}`
@ -221,13 +171,6 @@
return reservations.get.promotions(project_id).then(promotions => {
this.data.promotions[project_id] = promotions
})
/*const uri = `/api/proyecto/${project_id}/promotions`
return APIClient.fetch(uri).then(response => response.json()).then(json => {
if (json.promotions.length === 0) {
return this.data.promotions[project_id] = []
}
return this.data.promotions[project_id] = json.promotions
})*/
},
units: project_id => {
if (project_id in this.data.units) {
@ -238,25 +181,6 @@
return reservations.get.units(project_id).then(units => {
this.data.units[project_id] = units
})
/*const uri = `/api/proyecto/${project_id}/unidades/disponibles`
return APIClient.fetch(uri).then(response => response.json()).then(json => {
if (json.unidades.length === 0) {
this.data.units[project_id] = {}
return this.data.units[project_id]
}
if (!(project_id in this.data.units)) {
this.data.units[project_id] = {}
}
json.unidades.forEach(unit => {
const type = unit.proyecto_tipo_unidad.tipo_unidad.descripcion
if (!(type in this.data.units[project_id])) {
this.data.units[project_id][type] = []
}
this.data.units[project_id][type].push(unit)
})
return this.data.units[project_id]
})*/
},
user: rut => {
if (this.data.current_user !== null && this.data.current_user?.rut === rut) {