mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
201 lines
6.4 KiB
JavaScript
201 lines
6.4 KiB
JavaScript
|
|
import Ajax from '../../../components/ajax.js'
|
|
import { alertConfirmAction } from '../../../components/alerts/sweetAlert.js'
|
|
class MaquinistaTareaView {
|
|
constructor(domItem) {
|
|
this.item = domItem
|
|
this.tareaId = this.item.data("id");
|
|
this.btnPlay = this.item.find("#btn-start-tarea")
|
|
this.btnPause = this.item.find("#btn-pause-tarea")
|
|
this.btnDelay = this.item.find("#btn-stop-tarea")
|
|
this.btnFinish = this.item.find("#btn-finish-tarea")
|
|
this.btnDeleteProgress = this.item.find("#btn-delete-tarea")
|
|
this.actionButtons = this.item.find('.action-btn')
|
|
this.tareaCardClass = '.tarea-card-action-block'
|
|
this.inputClick = $('.ot-tarea-click')
|
|
}
|
|
init() {
|
|
this.actionButtons.on('click', this.eventActionButton.bind(this))
|
|
this.btnDelay.on('click', this.delayEventActionButton.bind(this))
|
|
this.btnDeleteProgress.on('click', this.handleDeleteTareaProgress.bind(this))
|
|
this.handleGetTareaProgress();
|
|
this.inputClick.on('input', this.handleUpdateClickInput.bind(this))
|
|
}
|
|
|
|
eventActionButton(event) {
|
|
let statusClick = $(event.currentTarget).data('estado');
|
|
this.showBasedOnStatus(statusClick);
|
|
console.info(`Estado ${statusClick}`)
|
|
this.handleUpdateTareaProgress(statusClick)
|
|
}
|
|
delayEventActionButton(event) {
|
|
let statusClick = $(event.currentTarget).data('estado');
|
|
this.delayTarea()
|
|
}
|
|
actionLoader(status = true) {
|
|
if (status) {
|
|
Notiflix.Block.circle(this.tareaCardClass);
|
|
} else {
|
|
Notiflix.Block.remove(this.tareaCardClass);
|
|
}
|
|
}
|
|
showPlay() {
|
|
this.btnPause.addClass('d-none')
|
|
this.btnPlay.removeClass('d-none')
|
|
this.btnFinish.removeClass('d-none')
|
|
|
|
}
|
|
showPause() {
|
|
this.btnPlay.addClass('d-none')
|
|
this.btnFinish.addClass('d-none')
|
|
this.btnPause.removeClass('d-none')
|
|
|
|
}
|
|
disableButtons() {
|
|
this.actionButtons.attr('disabled', 'disabled')
|
|
}
|
|
enableButtons() {
|
|
this.actionButtons.removeAttr('disabled')
|
|
}
|
|
handleUpdateClickInput(event) {
|
|
let tareaId = $(event.currentTarget).data('id');
|
|
let name = $(event.currentTarget).attr('name')
|
|
let value = $(event.currentTarget).val()
|
|
let formData = {
|
|
orden_trabajo_tarea_id: tareaId
|
|
}
|
|
|
|
formData[name] = value;
|
|
let ajax = new Ajax('/produccion/ordentrabajo/update/tarea',
|
|
formData,
|
|
null,
|
|
this.handleUpdateClickInputSucess.bind(this),
|
|
this.handleGetTareaProgressError.bind(this)
|
|
)
|
|
if (value) {
|
|
ajax.post()
|
|
}
|
|
|
|
}
|
|
handleUpdateClickInputSucess(response) {
|
|
popSuccessAlert(response.message)
|
|
}
|
|
handleUpdateClickInputError(error) {
|
|
popErrorAlert(error)
|
|
}
|
|
handleDeleteTareaProgress() {
|
|
let ajax = new Ajax('/produccion/ordentrabajo/tarea/progress/' + this.tareaId,
|
|
null,
|
|
null,
|
|
this.handleDeleteTareaProgressSuccess.bind(this),
|
|
this.handleDeleteTareaProgressError.bind(this)
|
|
)
|
|
alertConfirmAction('Se borrará todo el progreso y se reiniciará el progreso')
|
|
.then(result => {
|
|
if (result.isConfirmed) {
|
|
this.actionLoader(true)
|
|
ajax.delete()
|
|
}
|
|
})
|
|
}
|
|
handleDeleteTareaProgressSuccess() {
|
|
window.location.reload()
|
|
}
|
|
handleDeleteTareaProgressError(error) {
|
|
popErrorAlert(error)
|
|
}
|
|
|
|
handleGetTareaProgress() {
|
|
this.actionLoader()
|
|
let ajax = new Ajax(`/produccion/ordentrabajo/tarea/progress/${this.tareaId}`, null, null,
|
|
this.handleGetTareaProgressSuccess.bind(this),
|
|
this.handleGetTareaProgressError.bind(this),
|
|
|
|
)
|
|
if (this.tareaId) {
|
|
ajax.get();
|
|
}
|
|
}
|
|
handleGetTareaProgressSuccess(response) {
|
|
if (response.progress_dates) {
|
|
let lastStatus = response.progress_dates.findLast(e => e.estado != null).estado
|
|
console.log("Last status :", lastStatus)
|
|
this.showBasedOnStatus(lastStatus)
|
|
}
|
|
if (response.tiempo_trabajado) {
|
|
this.item.find('#tiempo-real-info').html(response.tiempo_trabajado)
|
|
}
|
|
this.actionLoader(false)
|
|
|
|
}
|
|
handleGetTareaProgressError(error) {
|
|
this.actionLoader(false)
|
|
}
|
|
handleUpdateTareaProgress(status) {
|
|
this.actionLoader(true)
|
|
let ajax = new Ajax(`/produccion/ordentrabajo/update/tarea/progress`,
|
|
{
|
|
'ot_tarea_id': this.tareaId,
|
|
'estado': status
|
|
}, null,
|
|
this.handleUpdateTareaProgressSuccess.bind(this),
|
|
this.handleUpdateTareaProgressError.bind(this),
|
|
)
|
|
if (this.tareaId) {
|
|
ajax.post();
|
|
}
|
|
}
|
|
handleUpdateTareaProgressSuccess(response) {
|
|
if (response.data) {
|
|
if (response.data.estado == 'D') {
|
|
window.location.href = '/produccion/ordentrabajo/maquinista/maquinas/view'
|
|
}
|
|
this.showBasedOnStatus(response.data.status)
|
|
}
|
|
this.actionLoader(false)
|
|
}
|
|
handleUpdateTareaProgressError(error) {
|
|
popErrorAlert(error.error)
|
|
this.actionLoader(false)
|
|
}
|
|
|
|
showBasedOnStatus(status) {
|
|
if (['P', 'S'].includes(status)) {
|
|
this.enableButtons()
|
|
this.showPlay()
|
|
}
|
|
if (['F', 'E'].includes(status)) {
|
|
this.disableButtons()
|
|
this.showPlay()
|
|
}
|
|
if (status == 'I') {
|
|
this.enableButtons()
|
|
this.showPause()
|
|
}
|
|
if (status == 'D') {
|
|
window.href
|
|
}
|
|
}
|
|
eventUnloadWindow(event) {
|
|
// return confirm('¿Estás seguro de abandonar la página? La tarea se marcará como pausada')
|
|
alertConfirmAction('La tarea se marcará como pausada')
|
|
.then(result => {
|
|
|
|
if (result.isConfirmed) {
|
|
return ""
|
|
}
|
|
})
|
|
}
|
|
delayTarea() {
|
|
alertConfirmAction('La tarea se marcará como aplazada y podrás continuar después')
|
|
.then(result => {
|
|
if (result.isConfirmed) {
|
|
this.handleUpdateTareaProgress('D')
|
|
}
|
|
})
|
|
}
|
|
|
|
|
|
}
|
|
|
|
export default MaquinistaTareaView; |