Unidades disponibles y nombre de proyecto
This commit is contained in:
@ -10,19 +10,19 @@
|
||||
|
||||
<div class="ui compact segment" id="projects">
|
||||
<div class="ui header">Proyectos</div>
|
||||
@if (count($projects) == 0)
|
||||
<div class="ui message">
|
||||
No hay proyectos en venta.
|
||||
</div>
|
||||
@else
|
||||
<div class="ui link list">
|
||||
@foreach ($projects as $project)
|
||||
<div class="item link" data-id="{{ $project->id }}">
|
||||
{{ $project->descripcion }}
|
||||
@if (count($projects) == 0)
|
||||
<div class="ui message">
|
||||
No hay proyectos en venta.
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
@endif
|
||||
@else
|
||||
<div class="ui link list">
|
||||
@foreach ($projects as $project)
|
||||
<div class="item link" data-id="{{ $project->id }}">
|
||||
{{ $project->descripcion }}
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
<div class="ui two column grid">
|
||||
<div class="column">
|
||||
@ -101,7 +101,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@include('ventas.reservations.add_modal')
|
||||
@include('ventas.reservations.modal.add')
|
||||
@endsection
|
||||
|
||||
@push('page_styles')
|
||||
@ -160,20 +160,24 @@
|
||||
|
||||
this.title_component.innerHTML = event.currentTarget.innerHTML
|
||||
}
|
||||
|
||||
watch() {
|
||||
this.component.querySelectorAll('.item.link').forEach(item => {
|
||||
item.addEventListener('click', this.select.bind(this))
|
||||
})
|
||||
}
|
||||
|
||||
show() {
|
||||
this.component.style.display = this.display.projects
|
||||
this.title_component.style.display = 'none'
|
||||
}
|
||||
|
||||
hide() {
|
||||
this.component.style.display = 'none'
|
||||
this.title_component.style.display = this.display.project
|
||||
}
|
||||
}
|
||||
|
||||
class Controls {
|
||||
display = {
|
||||
up: '',
|
||||
@ -208,10 +212,12 @@
|
||||
value.addEventListener('click', this.action[name].bind(this))
|
||||
})
|
||||
}
|
||||
|
||||
hide() {
|
||||
this.buttons.up.style.display = this.display.up
|
||||
this.buttons.reset.style.display = this.display.reset
|
||||
}
|
||||
|
||||
show() {
|
||||
this.buttons.up.style.display = 'none'
|
||||
this.buttons.reset.style.display = 'none'
|
||||
@ -235,6 +241,7 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Reservations {
|
||||
display = {
|
||||
reservations: '',
|
||||
@ -256,34 +263,33 @@
|
||||
|
||||
this.formatters = formatters
|
||||
|
||||
this.set().columnNames()
|
||||
this.set.columnNames()
|
||||
|
||||
this.hide()
|
||||
}
|
||||
|
||||
set() {
|
||||
return {
|
||||
reservations: reservations => {
|
||||
this.reservations = reservations
|
||||
return this
|
||||
},
|
||||
columnNames: () => {
|
||||
const tds = this.component.querySelector('thead tr').querySelectorAll('th')
|
||||
this.columnNames = []
|
||||
tds.forEach(td => {
|
||||
let name = td.innerHTML.toLowerCase()
|
||||
if (name === '') {
|
||||
return
|
||||
}
|
||||
if (name.includes('?')) {
|
||||
name = name.replaceAll(/[¿?]/g, '')
|
||||
}
|
||||
this.columnNames.push(name)
|
||||
})
|
||||
return this
|
||||
}
|
||||
set = {
|
||||
reservations: reservations => {
|
||||
this.reservations = reservations
|
||||
return this
|
||||
},
|
||||
columnNames: () => {
|
||||
const tds = this.component.querySelector('thead tr').querySelectorAll('th')
|
||||
this.columnNames = []
|
||||
tds.forEach(td => {
|
||||
let name = td.innerHTML.toLowerCase()
|
||||
if (name === '') {
|
||||
return
|
||||
}
|
||||
if (name.includes('?')) {
|
||||
name = name.replaceAll(/[¿?]/g, '')
|
||||
}
|
||||
this.columnNames.push(name)
|
||||
})
|
||||
return this
|
||||
}
|
||||
}
|
||||
|
||||
columnsData() {
|
||||
return this.reservations.map(reservation => {
|
||||
const date = new Date(Date.parse(reservation.fecha) + 24 * 60 * 60 * 1000)
|
||||
@ -298,7 +304,12 @@
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
draw() {
|
||||
if (this.reservations.length === 0) {
|
||||
this.empty()
|
||||
return
|
||||
}
|
||||
const tbody = this.component.querySelector('tbody')
|
||||
tbody.innerHTML = ''
|
||||
this.columnsData().forEach(column => {
|
||||
@ -317,6 +328,7 @@
|
||||
})
|
||||
this.show()
|
||||
}
|
||||
|
||||
drawActions(id) {
|
||||
return `
|
||||
<td class="right aligned">
|
||||
@ -328,6 +340,7 @@
|
||||
</button>
|
||||
</td>`
|
||||
}
|
||||
|
||||
empty() {
|
||||
const tbody = this.component.querySelector('tbody')
|
||||
tbody.innerHTML = ''
|
||||
@ -342,21 +355,25 @@
|
||||
show() {
|
||||
this.component.style.display = this.display.reservations
|
||||
}
|
||||
|
||||
hide() {
|
||||
this.component.style.display = 'none'
|
||||
}
|
||||
}
|
||||
|
||||
class ActiveReservations extends Reservations {
|
||||
constructor({component_id, formatters = {date, ufs}}) {
|
||||
super({component_id, formatters})
|
||||
}
|
||||
|
||||
columnsData() {
|
||||
const data = super.columnsData();
|
||||
return data.map(row => {
|
||||
delete(row['valida'])
|
||||
delete (row['valida'])
|
||||
return row
|
||||
})
|
||||
}
|
||||
|
||||
drawActions(id) {
|
||||
return `
|
||||
<td class="right aligned">
|
||||
@ -369,11 +386,13 @@
|
||||
</td>`
|
||||
}
|
||||
}
|
||||
|
||||
class PendingReservations extends Reservations {
|
||||
constructor({component_id, formatters = {date, ufs}}) {
|
||||
super({component_id, formatters})
|
||||
}
|
||||
}
|
||||
|
||||
class RejectedReservations extends Reservations {
|
||||
constructor({component_id, formatters = {date, ufs}}) {
|
||||
super({component_id, formatters})
|
||||
@ -392,6 +411,7 @@
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
const reservations = {
|
||||
components: {
|
||||
projects: null,
|
||||
@ -415,42 +435,20 @@
|
||||
send: (project_id, url_segment, component) => {
|
||||
const url = `/api/ventas/reservations/project/${project_id}/${url_segment}`
|
||||
return APIClient.fetch(url).then(response => response.json()).then(json => {
|
||||
if (json.reservations.length === 0) {
|
||||
component.empty()
|
||||
return
|
||||
if (json.reservations.length > 0) {
|
||||
component.set.reservations(json.reservations)
|
||||
}
|
||||
component.set().reservations(json.reservations).draw()
|
||||
component.draw()
|
||||
})
|
||||
},
|
||||
active: project_id => {
|
||||
return reservations.get.send(project_id, 'active', reservations.components.reservations.active)
|
||||
/*const url = `/ventas/reservations/project/${project_id}/active`
|
||||
return APIClient.fetch(url).then(json => {
|
||||
if (json.reservations.length === 0) {
|
||||
return
|
||||
}
|
||||
this.components.reservations.active.set().reservations(json.reservations).draw()
|
||||
})*/
|
||||
},
|
||||
pending: project_id => {
|
||||
return reservations.get.send(project_id, 'pending', reservations.components.reservations.pending)
|
||||
/*const url = `/ventas/reservations/project/${project_id}/pending`
|
||||
return APIClient.fetch(url).then(json => {
|
||||
if (json.reservations.length === 0) {
|
||||
return
|
||||
}
|
||||
this.components.reservations.pending.set().reservations(json.reservations).draw()
|
||||
})*/
|
||||
},
|
||||
rejected: project_id => {
|
||||
return reservations.get.send(project_id, 'rejected', reservations.components.reservations.rejected)
|
||||
/*const url = `/ventas/reservations/project/${project_id}/rejected`
|
||||
return APIClient.fetch(url).then(json => {
|
||||
if (json.reservations.length === 0) {
|
||||
return
|
||||
}
|
||||
this.components.reservations.rejected.set().reservations(json.reservations).draw()
|
||||
})*/
|
||||
},
|
||||
reservations: project_id => {
|
||||
reservations.loading.show()
|
||||
@ -510,6 +508,7 @@
|
||||
results: () => {
|
||||
reservations.components.projects.hide()
|
||||
reservations.components.results.style.display = reservations.display.results
|
||||
Object.values(reservations.components.reservations).forEach(reservations => reservations.draw())
|
||||
}
|
||||
},
|
||||
setup(configuration) {
|
||||
@ -518,11 +517,23 @@
|
||||
ufs: new Intl.NumberFormat('es-CL', {minimumFractionDigits: 2, maximumFractionDigits: 2})
|
||||
}
|
||||
this.components.loader = document.getElementById(configuration.ids.loader)
|
||||
this.components.projects = new Projects({component_id: configuration.ids.projects, title_id: configuration.ids.project})
|
||||
this.components.projects = new Projects({
|
||||
component_id: configuration.ids.projects,
|
||||
title_id: configuration.ids.project
|
||||
})
|
||||
this.components.controls = new Controls({component_id: configuration.ids.controls})
|
||||
this.components.reservations.active = new ActiveReservations({component_id: configuration.ids.active, formatters})
|
||||
this.components.reservations.pending = new PendingReservations({component_id: configuration.ids.pending, formatters})
|
||||
this.components.reservations.rejected = new RejectedReservations({component_id: configuration.ids.rejected, formatters})
|
||||
this.components.reservations.active = new ActiveReservations({
|
||||
component_id: configuration.ids.active,
|
||||
formatters
|
||||
})
|
||||
this.components.reservations.pending = new PendingReservations({
|
||||
component_id: configuration.ids.pending,
|
||||
formatters
|
||||
})
|
||||
this.components.reservations.rejected = new RejectedReservations({
|
||||
component_id: configuration.ids.rejected,
|
||||
formatters
|
||||
})
|
||||
|
||||
this.display.loader = this.components.loader.style.display
|
||||
this.loading.hide()
|
||||
@ -532,7 +543,7 @@
|
||||
this.display.results = this.components.results.style.display
|
||||
this.show.projects()
|
||||
|
||||
this.components.modals.add = new AddReservationModal()
|
||||
this.components.modals.add = new AddReservationModal(configuration.ids.projects)
|
||||
}
|
||||
}
|
||||
$(document).ready(() => {
|
||||
|
Reference in New Issue
Block a user