Unidades disponibles y nombre de proyecto
This commit is contained in:
@ -128,7 +128,7 @@
|
||||
</button>
|
||||
</div>
|
||||
<div id="add_promotions"></div>
|
||||
<h4 class="ui dividing header">Unidades</h4>
|
||||
<h4 class="ui dividing header">Unidades <span id="add_project_name"></span></h4>
|
||||
<div class="fields" id="add_unit_buttons"></div>
|
||||
<div id="add_units"></div>
|
||||
</form>
|
||||
@ -365,6 +365,8 @@
|
||||
broker: '',
|
||||
promotion_button: '',
|
||||
promotions: '',
|
||||
projects: '',
|
||||
project_name: '',
|
||||
unit_buttons: '',
|
||||
units: ''
|
||||
}
|
||||
@ -381,6 +383,8 @@
|
||||
$broker: null,
|
||||
promotion_button: null,
|
||||
promotions: null,
|
||||
projects: null,
|
||||
project_name: null,
|
||||
unit_buttons: null,
|
||||
units: null,
|
||||
$loader: null
|
||||
@ -403,7 +407,7 @@
|
||||
terraza: 'tree',
|
||||
}
|
||||
}
|
||||
constructor() {
|
||||
constructor(projects_id) {
|
||||
this.ids = {
|
||||
modal: 'add_reservation_modal',
|
||||
form: 'add_reservation_form',
|
||||
@ -416,6 +420,8 @@
|
||||
broker: 'add_broker',
|
||||
promotion_button: 'add_promotion',
|
||||
promotions: 'add_promotions',
|
||||
projects: projects_id,
|
||||
project_name: 'add_project_name',
|
||||
unit_buttons: 'add_unit_buttons',
|
||||
units: 'add_units',
|
||||
loader: 'add_rut_loader'
|
||||
@ -425,6 +431,7 @@
|
||||
load(project_id) {
|
||||
this.reset()
|
||||
this.data.current_project = project_id
|
||||
this.components.project_name.textContent = this.components.projects.querySelector(`.item[data-id="${project_id}"]`).textContent
|
||||
this.components.form.querySelector('input[name="add_project_id"]').value = project_id
|
||||
|
||||
this.get.brokers(project_id)
|
||||
@ -572,27 +579,32 @@
|
||||
resolve(this.data.units[project_id])
|
||||
})
|
||||
}
|
||||
const uri = `/api/proyecto/${project_id}/unidades`
|
||||
const uri = `/api/proyecto/${project_id}/unidades/disponibles`
|
||||
return APIClient.fetch(uri).then(response => response.json()).then(json => {
|
||||
if (json.total === 0) {
|
||||
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] = {}
|
||||
}
|
||||
Object.entries(json.unidades).forEach(([type, units]) => {
|
||||
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] = []
|
||||
}
|
||||
units.forEach(unit => {
|
||||
this.data.units[project_id][type].push({
|
||||
text: unit.descripcion,
|
||||
name: unit.descripcion,
|
||||
value: unit.id
|
||||
})
|
||||
this.data.units[project_id][type].push({
|
||||
text: unit.descripcion,
|
||||
name: unit.descripcion,
|
||||
value: unit.id
|
||||
})
|
||||
})
|
||||
Object.entries(this.data.units[project_id]).forEach(([type, units]) => {
|
||||
units.sort((a, b) => {
|
||||
return parseInt(a.text) - parseInt(b.text)
|
||||
})
|
||||
this.data.units[project_id][type] = units
|
||||
})
|
||||
return this.data.units[project_id]
|
||||
})
|
||||
},
|
||||
@ -692,6 +704,8 @@
|
||||
this.components.$region = $(`#${this.ids.region}`)
|
||||
this.components.$broker = $(`#${this.ids.broker}`)
|
||||
this.components.promotions = new AddModalPromotions()
|
||||
this.components.projects = document.getElementById(this.ids.projects)
|
||||
this.components.project_name = document.getElementById(this.ids.project_name)
|
||||
this.components.units = new AddModalUnits()
|
||||
|
||||
this.components.$modal.modal({
|
Reference in New Issue
Block a user