import ClassSelect from '../../components/select2.js'; import tarifasClienteView from './tarifasCliente.js'; import Ajax from '../../components/ajax.js'; class Cliente { constructor() { this.tarifas = new tarifasClienteView($('#tarifascliente')); this.pais = new ClassSelect($("#paisId"), '/paises/menuitems2', "Seleccione un país", {[this.csrf_token]: this.csrf_hash}); this.soporte = new ClassSelect($("#soporteId"), '/users/getMenuComerciales', "Seleccione un usuario", {[this.csrf_token]: this.csrf_hash}); this.comercial = new ClassSelect($("#comercialId"), '/users/getMenuComerciales', "Seleccione un usuario", {[this.csrf_token]: this.csrf_hash}); this.formaPago = new ClassSelect($("#formaPagoId"), '/formas-pago/menuitems', "Seleccione una forma de pago", {[this.csrf_token]: this.csrf_hash}); this.provincia = new ClassSelect($("#provinciaId"), '/provincias/menuitems2', "Seleccione una provincia", {[this.csrf_token]: this.csrf_hash}); this.comunidadAutonoma = new ClassSelect($("#comunidadAutonomaId"), '/comunidades-autonomas/menuitems2', "Seleccione una comunidad autónoma", {[this.csrf_token]: this.csrf_hash}); } init() { // Fuerza el foco en el campo de búsqueda de select2 $(document).on('select2:open', () => { document.querySelector('.select2-search__field').focus(); }); this.pais.init(); this.soporte.init(); this.comercial.init(); this.formaPago.init(); this.provincia.init(); this.comunidadAutonoma.init(); this.tarifas.init(); $(document).keypress(function (e) { var key = e.which; if (key == 13) // the enter key code { e.preventDefault() if ($('#addressForm').hasClass('show')) { $("#saveAdd").click(); } else if ($('#convert2Template').hasClass('show')) { $("#saveTemplate").click(); } else { $('#saveForm').click(); } } }); } } document.addEventListener('DOMContentLoaded', function () { const locale = document.querySelector('meta[name="locale"]').getAttribute('content'); new Ajax('/translate/getTranslation', { locale: locale, translationFile: ['ClienteContactos', 'ClientePrecios'] }, {}, function(translations) { window.language = JSON.parse(translations); new Cliente().init(); }, function (error) { console.log("Error getting translations:", error); } ).post(); });