Filling edit form
This commit is contained in:
@ -113,17 +113,19 @@
|
||||
].join('')
|
||||
}
|
||||
}
|
||||
const type = unit.type.charAt(0).toUpperCase() + unit.type.slice(1)
|
||||
|
||||
return [
|
||||
'<div class="fields">',
|
||||
`<div class="fields unit" data-id="${unit.idx}">`,
|
||||
'<div class="four wide field">',
|
||||
`<label>${unit.type.charAt(0).toUpperCase() + unit.type.slice(1)}</label>`,
|
||||
`<label>${type}</label>`,
|
||||
`<div class="ui search selection dropdown ${this.prefix}_units">`,
|
||||
`<input type="hidden" name="${this.prefix}_units[]" />`,
|
||||
'<i class="dropdown icon"></i>',
|
||||
`<div class="default text">${unit.type.charAt(0).toUpperCase() + unit.type.slice(1)}</div>`,
|
||||
`<div class="default text">${type}</div>`,
|
||||
'<div class="menu">',
|
||||
this.data.types[unit.type].map(unit => {
|
||||
return `<div class="item" data-value="${unit.value}">${unit.name}</div>`
|
||||
this.data.types[unit.type].map(u => {
|
||||
return `<div class="item" data-value="${u.value}">${u.name}</div>`
|
||||
}).join(''),
|
||||
'</div>',
|
||||
'</div>',
|
||||
@ -146,17 +148,31 @@
|
||||
}
|
||||
reset() {
|
||||
this.data.units = []
|
||||
this.components.units.innerHTML = ''
|
||||
this.draw.units()
|
||||
}
|
||||
add(type) {
|
||||
const idx = Math.max(this.data.units.length, 0, Math.max(...this.data.units.map(unit => unit.idx)) + 1)
|
||||
this.data.units.push({idx, type})
|
||||
this.draw.units()
|
||||
return idx
|
||||
}
|
||||
remove(idx) {
|
||||
this.data.units = this.data.units.filter(unit => unit.idx !== idx)
|
||||
this.draw.units()
|
||||
}
|
||||
async fill(unitValues) {
|
||||
if (reservations.locks.units !== null) {
|
||||
await reservations.locks.units
|
||||
}
|
||||
unitValues.forEach(unitValue => {
|
||||
const type = unitValue.unit.proyecto_tipo_unidad.tipo_unidad.descripcion
|
||||
const idx = this.add(type)
|
||||
const field = this.components.units.querySelector(`div.unit[data-id="${idx}"]`)
|
||||
$(field.querySelector('div.dropdown.edit_units')).dropdown('set selected', unitValue.unit.id)
|
||||
$(field.querySelector('div.input')).val(unitValue.value)
|
||||
})
|
||||
}
|
||||
setup() {
|
||||
this.components.buttons_holder = document.getElementById(this.ids.buttons_holder)
|
||||
this.components.units = document.getElementById(this.ids.units)
|
||||
|
||||
Reference in New Issue
Block a user