mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
terminadas tarifas cliente
This commit is contained in:
@ -84,6 +84,10 @@ let ClassSelect = function (domItem, url, placeholder, allowClear = false, param
|
||||
this.onChange = function(callback) {
|
||||
this.item.on('change', callback);
|
||||
};
|
||||
this.offChange = function() {
|
||||
this.item.off('change');
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
export default ClassSelect;
|
||||
|
||||
@ -0,0 +1,83 @@
|
||||
class ModalConvert2Template {
|
||||
|
||||
constructor() {
|
||||
|
||||
this.modalId = 'modalConvert2Template';
|
||||
this.modalHtml = `
|
||||
<div class="modal fade" id="${this.modalId}" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="${this.modalId}Label" aria-hidden="true">
|
||||
<div class="modal-dialog modal-dialog-centered">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h4 id="labelTitleConfirmDialog" class="modal-title">${window.language.ClientePrecios.convertir2plantilla}</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div id='error-nombre'></div>
|
||||
<div class="mb-3">
|
||||
<p>${window.language.ClientePrecios.convertir2plantillaText}</p>
|
||||
<p>${window.language.ClientePrecios.convertir2plantillaText2}</p>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="nombre_plantilla" class="form-label">
|
||||
${window.language.ClientePrecios.nombrePlantilla}
|
||||
</label>
|
||||
<input type="text" id="nombre_plantilla" maxLength="100" class="form-control new-address">
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button id="saveTemplate" type="button" class="btn btn-primary">
|
||||
Guardar
|
||||
</button>
|
||||
<button id="cancelTemplate" type="button" class="btn btn-default">
|
||||
Cancelar
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
this.modalInstance = null;
|
||||
}
|
||||
|
||||
init() {
|
||||
|
||||
const self = this;
|
||||
|
||||
// Insertar el modal en el body del documento si no existe
|
||||
if (!document.getElementById(this.modalId)) {
|
||||
document.body.insertAdjacentHTML('beforeend', this.modalHtml);
|
||||
}
|
||||
|
||||
this.modalInstance = new bootstrap.Modal(document.getElementById(this.modalId));
|
||||
|
||||
// Configurar el evento del botón de cancelar
|
||||
document.getElementById('cancelTemplate').addEventListener('click', () => {
|
||||
this.modalInstance.hide();
|
||||
});
|
||||
}
|
||||
|
||||
// Método para mostrar el modal
|
||||
show(callback) {
|
||||
|
||||
// Mostrar el modal usando Bootstrap
|
||||
this.modalInstance.show();
|
||||
|
||||
// Configurar el evento de confirmación de eliminación
|
||||
document.getElementById('saveTemplate').addEventListener('click', () => {
|
||||
callback(); // Llamar al callback que el usuario haya proporcionado
|
||||
this.modalInstance.hide();
|
||||
});
|
||||
}
|
||||
|
||||
hide() {
|
||||
document.getElementById('nombre_plantilla').value = "";
|
||||
const modal = new bootstrap.Modal(document.getElementById(this.modalId));
|
||||
modal.hide();
|
||||
}
|
||||
|
||||
getNombrePlantilla() {
|
||||
return document.getElementById('nombre_plantilla').value;
|
||||
}
|
||||
}
|
||||
|
||||
export default ModalConvert2Template;
|
||||
@ -1,6 +1,9 @@
|
||||
import Table from '../../components/table.js';
|
||||
import TableEditor from '../../components/tableEditor.js';
|
||||
import ConfirmDeleteModal from '../../components/ConfirmDeleteModal.js';
|
||||
import ConvertToTemplate from './modalConvert2Template.js';
|
||||
import ClassSelect from '../../components/select2.js';
|
||||
import Ajax from '../../components/ajax.js';
|
||||
import { getToken } from '../../common/common.js';
|
||||
|
||||
|
||||
@ -21,7 +24,14 @@ class tarifasClienteView {
|
||||
this.tableTarifas = null;
|
||||
this.editorTarifas = null;
|
||||
this.confirmDeleteModal = null;
|
||||
|
||||
this.deleteModal = null;
|
||||
this.convertToTemplate = null;
|
||||
|
||||
this.plantillas = $(this.domItem.find('#plantillas'));
|
||||
this.selectorPlantilla = new ClassSelect(this.plantillas, '/clienteplantillaprecios/menuitems', '');
|
||||
|
||||
this.convertToTemplateBtn = $('#convert2template');
|
||||
}
|
||||
|
||||
init() {
|
||||
@ -31,24 +41,35 @@ class tarifasClienteView {
|
||||
this.deleteModal = new ConfirmDeleteModal('tarifascliente');
|
||||
this.deleteModal.init();
|
||||
|
||||
this.convertToTemplate = new ConvertToTemplate();
|
||||
this.convertToTemplate.init();
|
||||
|
||||
this.#initEditor();
|
||||
|
||||
this.#initTable();
|
||||
|
||||
this.selectorPlantilla.init();
|
||||
|
||||
this.#getPlantillaPrecios();
|
||||
|
||||
this.convertToTemplateBtn.on('click', function () {
|
||||
self.convertToTemplate.show(self.#convertir2plantilla.bind(self));
|
||||
})
|
||||
|
||||
|
||||
// Editar en linea la fila
|
||||
this.tableTarifas.table.on('click', 'tbody span.edit', function (e) {
|
||||
|
||||
const row = $(this).closest('tr');
|
||||
|
||||
|
||||
// Iniciar la edición en línea para todas las celdas de la fila
|
||||
self.editorTarifas.editor.inline(
|
||||
self.tableTarifas.table.cells(row, '*').nodes(),
|
||||
{
|
||||
cancelHtml: '<a href="javascript:void(0);"><i class="ti ti-x"></i></a>',
|
||||
submitHtml: '<a href="javascript:void(0);"><i class="ti ti-device-floppy"></i></a>',
|
||||
cancelTrigger: row.find('span.cancel')[0],
|
||||
submitTrigger: row.find('span.edit')[0],
|
||||
cancelTrigger: row.find('span.cancel')[0],
|
||||
submitTrigger: row.find('span.edit')[0],
|
||||
submit: 'allIfChanged'
|
||||
}
|
||||
);
|
||||
@ -58,19 +79,19 @@ class tarifasClienteView {
|
||||
this.tableTarifas.table.on('click', '.btn-delete-' + this.tableTarifas.getAlias(), function (e) {
|
||||
const row = $(this).closest('tr')[0]._DT_RowIndex;
|
||||
self.deleteModal.setData($(this).attr('data-id'));
|
||||
self.deleteModal.show(() =>{
|
||||
self.deleteModal.show(() => {
|
||||
if ($.isNumeric(self.deleteModal.getData())) {
|
||||
self.editorTarifas.editor
|
||||
.create( false )
|
||||
.edit( self.tableTarifas.table.rows(row), false)
|
||||
.set( 'deleted_at', new Date().toISOString().slice(0, 19).replace('T', ' ') )
|
||||
.set( 'is_deleted', 1 )
|
||||
.create(false)
|
||||
.edit(self.tableTarifas.table.rows(row), false)
|
||||
.set('deleted_at', new Date().toISOString().slice(0, 19).replace('T', ' '))
|
||||
.set('is_deleted', 1)
|
||||
.submit();
|
||||
self.deleteModal.hide();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -166,10 +187,16 @@ class tarifasClienteView {
|
||||
|
||||
this.editorTarifas.editor.on('postEdit', function (e, json, data, action) {
|
||||
self.#borrarPlantillaTarifa(self.clienteId);
|
||||
self.selectorPlantilla.offChange();
|
||||
self.selectorPlantilla.setOption(0, 'Personalizado');
|
||||
self.selectorPlantilla.onChange(self.#changePlantilla.bind(this));
|
||||
})
|
||||
|
||||
this.editorTarifas.editor.on('postCreate', function (e, json, data, action) {
|
||||
self.#borrarPlantillaTarifa(self.clienteId);
|
||||
self.selectorPlantilla.offChange();
|
||||
self.selectorPlantilla.setOption(0, 'Personalizado');
|
||||
self.selectorPlantilla.onChange(self.#changePlantilla.bind(this));
|
||||
})
|
||||
|
||||
this.editorTarifas.editor.on('postCancel', function (e, json, data) {
|
||||
@ -181,18 +208,82 @@ class tarifasClienteView {
|
||||
});
|
||||
}
|
||||
|
||||
#convertir2plantilla() {
|
||||
if (this.convertToTemplate.getNombrePlantilla().length == 0) {
|
||||
popErrorAlert(window.language.ClientePrecios.errors.error_nombre_template, 'error-nombre')
|
||||
}
|
||||
else {
|
||||
new Ajax('/clientes/clienteplantillaprecios/add',
|
||||
{
|
||||
'from_client_data': 1,
|
||||
'cliente_id': this.clienteId,
|
||||
'nombre': this.convertToTemplate.getNombrePlantilla(),
|
||||
[this.csrf_token]: this.csrf_hash
|
||||
},
|
||||
{},
|
||||
(response) => {
|
||||
if (response.id) {
|
||||
|
||||
this.selectorPlantilla.offChange();
|
||||
this.selectorPlantilla.setOption(response.id, this.convertToTemplate.getNombrePlantilla());
|
||||
this.selectorPlantilla.onChange(this.#changePlantilla.bind(this));
|
||||
}
|
||||
},
|
||||
(error) => {
|
||||
console.log(error);
|
||||
}
|
||||
).post();
|
||||
}
|
||||
}
|
||||
|
||||
#getPlantillaPrecios() {
|
||||
|
||||
new Ajax(
|
||||
'/clienteprecios/getplantilla',
|
||||
{
|
||||
'cliente_id': this.clienteId,
|
||||
[this.csrf_token]: this.csrf_hash
|
||||
},
|
||||
{},
|
||||
(data) => {
|
||||
if (data !== null && typeof data === 'object') {
|
||||
if (data.hasOwnProperty('id') && data.id != null)
|
||||
this.selectorPlantilla.setOption(data.id, data.nombre);
|
||||
else {
|
||||
this.selectorPlantilla.setOption(0, 'Personalizado');
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.selectorPlantilla.setOption(0, 'Personalizado');
|
||||
}
|
||||
this.selectorPlantilla.onChange(this.#changePlantilla.bind(this));
|
||||
},
|
||||
(data) => {
|
||||
this.selectorPlantilla.onChange(this.#changePlantilla.bind(this));
|
||||
console.log(data);
|
||||
}
|
||||
).get();
|
||||
}
|
||||
|
||||
#changePlantilla() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
#borrarPlantillaTarifa(id) {
|
||||
|
||||
const domain = window.location.origin
|
||||
fetch(domain + "/clientes/clienteprecios/update/" + id, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
[self.csrf_token]: self.csrf_hash
|
||||
}),
|
||||
headers: {
|
||||
"Content-type": "application/json; charset=UTF-8"
|
||||
new Ajax(
|
||||
'/clienteprecios/changeplantilla',
|
||||
{
|
||||
'cliente_id': id,
|
||||
[this.csrf_token]: this.csrf_hash
|
||||
},
|
||||
{},
|
||||
() => { },
|
||||
(data) => {
|
||||
console.log(data);
|
||||
}
|
||||
})
|
||||
).post();
|
||||
}
|
||||
|
||||
#initTable() {
|
||||
@ -280,7 +371,7 @@ class tarifasClienteView {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
headerSearcher() {
|
||||
|
||||
|
||||
@ -44,7 +44,8 @@ class PresupuestoCliente {
|
||||
|
||||
this.datos = {};
|
||||
this.ajax_calcular = new Ajax('/presupuestocliente/calcular',
|
||||
{}, this.datos,
|
||||
this.datos,
|
||||
{},
|
||||
this.#procesarPresupuesto.bind(this),
|
||||
() => { $('#loader').modal('hide'); });
|
||||
|
||||
@ -78,7 +79,7 @@ class PresupuestoCliente {
|
||||
}
|
||||
|
||||
|
||||
if ($('#divExcluirRotativa').hasClass('d-none')) {
|
||||
if (this.datosGenerales.excluirRotativa.length == 0) {
|
||||
|
||||
this.direcciones.direccionesCliente.setParams({ 'cliente_id': $("#clienteId").val() })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user