File manager - Edit - /home/autoph/public_html/connectv1/dist/js.bak/vehicle/vehicle_form.js
Back
var modal_reset = false; var new_record_data = false; var upload_image_name = []; var has_sales_record = false; function initVehicle() { $(document).ready(function () { photoDropzoneListener(); hasSalesRecordListener(); initSelect2(); initDatePicker(); addRowBrandsOffered(); onModalCLose(); onSaveButtonClick(); switch(location_source){ case 'vehicle': new_record_data = true; resetVehicleModal(); $('#modal-vehicle').modal('show'); $('#modal-title-vehicle').text("New Vehicle"); $('#proceed-button-vehicle').text("Save Information"); $('.vehicle-modal-overlay').hide(); break; case 'customer_view': new_record_data = true; resetVehicleModal(); $('#modal-vehicle').modal('show'); $('#modal-title-vehicle').text("New Vehicle"); $('#proceed-button-vehicle').text("Save Information"); $('.vehicle-modal-overlay').hide(); break; case 'vehicle_view': initUpdateVehicle(); break; } }); } function initUpdateVehicle(){ new_record_data = false; resetVehicleModal(); $('#modal-vehicle').modal('show'); $('#modal-title-vehicle').text("Edit Vehicle Information"); $('#proceed-button-vehicle').text("Save Information"); readVehicleProfile(vehicle_record_id); readVehicleSaleDetails(vehicle_record_id); readBrandsOffered(vehicle_record_id); } function getSalesAllModalData() { var obj = {}, ref = obj; /* Iterate over every input. */ $("#modal-vehicle :input").each(function() { /* Cache the id of the input. */ var id = this.id; /* Check whether the nodetype attribute is set to 'parent'. */ if (this.getAttribute("nodetype") == "parent") { /* Set a new object to the property and set ref to refer to it. */ ref = obj[id] = {}; } else { /* Set the value of the input to the referred object. */ if (this.getAttribute("json-modal-sale") == "true") { ref[id] = $(this).val(); } } }); /* Stringify the object and return it. */ return JSON.stringify(obj); } function getVehicleAllModalData() { var obj = {}, ref = obj; /* Iterate over every input. */ $("#modal-vehicle :input").each(function() { /* Cache the id of the input. */ var id = this.id; /* Check whether the nodetype attribute is set to 'parent'. */ if (this.getAttribute("nodetype") == "parent") { /* Set a new object to the property and set ref to refer to it. */ ref = obj[id] = {}; } else { /* Set the value of the input to the referred object. */ if (this.getAttribute("json-modal") == "true") { ref[id] = $(this).val(); } } }); /* Stringify the object and return it. */ return JSON.stringify(obj); } function onSaveButtonClick() { $('#proceed-button-vehicle').click(function() { if (isEmpty($('#mod-dd-brand').val())) { addVehicleModalTabSelectedTab(1); $('#mod-dd-brand').focus(); $('#mod-dd-brand').select2('open'); sweetAlertSimple('error', 'Oops...', 'Vehicle brand is required.'); return; } if (isEmpty($('#mod-dd-model').val())) { addVehicleModalTabSelectedTab(1); $('#mod-dd-model').focus(); $('#mod-dd-model').select2('open'); sweetAlertSimple('error', 'Oops...', 'Vehicle model is required.'); return; } if (isEmpty($('#mod-cs-number').val()) && isEmpty($('#mod-plate-number').val())) { addVehicleModalTabSelectedTab(1); $('#mod-cs-number').focus(); sweetAlertSimple('error', 'Oops...', 'Conduction Sticker and Plate Number can\'t be left blank'); return; } if ($('#mod-dd-dms').val() == "" || $('#mod-dd-dms').val() == null) { addVehicleModalTabSelectedTab(1); $('#mod-dd-dms').focus(); $('#mod-dd-dms').select2('open'); sweetAlertSimple('error', 'Oops...', 'Please provide DMS source'); return; } if ($('#mod-dd-company').val() == "" || $('#mod-dd-company').val() == null) { addVehicleModalTabSelectedTab(1); $('#mod-dd-company').focus(); $('#mod-dd-company').select2('open'); sweetAlertSimple('error', 'Oops...', 'Please provide Company source'); return; } if ($('#mod-dd-dealer').val() == "" || $('#mod-dd-dealer').val() == null) { addVehicleModalTabSelectedTab(1); $('#mod-dd-dealer').focus(); $('#mod-dd-dealer').select2('open'); sweetAlertSimple('error', 'Oops...', 'Please provide Dealer source'); return; } if (!checkIfBrandsOfferedIncomplete() && $('#brands-offered-list-table tbody tr').length > 0) { addVehicleModalTabSelectedTab(4); $('#vehicle-offered-section select').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete brand offered details first'); return; } apiKey = '6168105105517357'; //new if (!new_record_data) { apiKey = '4439864615669484'; //update }else{ var status_has_sales = $('#has_sales_record').prop('checked'); if (status_has_sales) { if (isEmpty($('#mod-sales-date').val())) { addVehicleModalTabSelectedTab(4); $('#mod-sales-date').focus(); sweetAlertSimple('error', 'Oops...', 'Sales release date is required.'); return; } } } if (typeof vehicle_record_id === 'undefined' || vehicle_record_id === null) { vehicle_id = '0'; }else{ vehicle_id = vehicle_record_id; } $.ajax({ url: "api/vehicle/vehiclev2.php", method: 'POST', dataType: 'json', data: { apiKey: apiKey, vehicle_id: vehicle_id, image_name: upload_image_name, vehicle_data: getVehicleAllModalData(), vehicle_brands_offered: getAllBrandsOfferedTableData(), sales_data: getSalesAllModalData() }, beforeSend: function() { $('#proceed-button-vehicle').attr('disabled', true); $('.customer-modal-overlay').show(); }, success: function(result) { $('#proceed-button-vehicle').attr('disabled', false); $('.customer-modal-overlay').hide(); if (result.status == 0) { sweetAlertSimple('error', 'Error', result.message); } else if (result.status == 1) { sweetAlertSimple('success', 'Success', result.message); $('#modal-vehicle').modal('hide'); switch(location_source){ case 'vehicle': refreshTable(); break; case 'customer_view': var offset_n = 0; if (!isEmpty($.cookie("vehicle_list_offset"))) { offset_n = parseInt($.cookie("vehicle_list_offset")); } getVehiclesGrid(offset_n, 9); break; case 'vehicle_view': customer_record_id = $("#mod-customer-number").val(); fetchVehicleInfo(vehicle_record_id, customer_record_id); readVehicleImage(vehicle_record_id); readVehicleSaleDetailsMain(vehicle_record_id); readBrandsOfferedMain(vehicle_record_id); break; } } else if (result.status == 3) { //duplicate cs number addVehicleModalTabSelectedTab(1); $('#mod-cs-number').focus(); sweetAlertSimple('error', 'Duplicate', result.message); } else if (result.status == 4) { //duplicate plate number addVehicleModalTabSelectedTab(1); $('#mod-plate-number').focus(); sweetAlertSimple('error', 'Duplicate', result.message); } else if (result.status == 5) { //duplicate vin addVehicleModalTabSelectedTab(1); $('#mod-vin-number').focus(); sweetAlertSimple('error', 'Duplicate', result.message); } else if (result.status == 6) { //duplicate serial number addVehicleModalTabSelectedTab(1); $('#mod-serial-number').focus(); sweetAlertSimple('error', 'Duplicate', result.message); } }, error: function(xhr, status, error) { //hide loader sweetAlertSimple('error', 'Oops...', 'Error has occurred, Try again...'); $('#proceed-button-vehicle').attr('disabled', false); $('#proceed-button-sale').attr('disabled', false); $('.vehicle-modal-overlay').hide(); } }); }); } function onModalCLose() { $('#modal-vehicle').on('hidden.bs.modal', function(e) { $(this) .find("input,textarea") .val('') .end() .find("select").prop("selectedIndex", 0) .find("input[type=checkbox], input[type=radio]") .prop("checked", "") .end(); $(".modal-select2").val('').trigger("change"); }) } function initDatePicker(){ $('#mod-insurance-exp-date').datetimepicker({ format: 'L' }); $('#mod-finance-exp-date').datetimepicker({ format: 'L' }); $('#mod-delivery-date').datetimepicker({ format: 'L' }); $('#mod-sales-date').datetimepicker({ format: 'L' }); $('[data-mask]').inputmask() } function initOwnerSelect2(){ switch(location_source){ case 'vehicle': $('#customer-owner-section').show(); break; case 'customer_view': var newOptionCustomer = new Option(customer_record_id, customer_record_id, true, true); $("#mod-customer-number").append(newOptionCustomer).trigger('change'); break; case 'vehicle_view': $('#customer-owner-section').show(); break; } } function initSelect2(){ $("#mod-customer-number").select2({ // tags:true, placeholder: "Search by name,email and mobile", allowClear: true, language: { noResults: function() { return "Search by name,email and mobile" } }, escapeMarkup: function(markup) { return markup; }, ajax: { url: 'api/customer/customerv2.php', dataType: 'json', delay: 250, data: function(data) { return { apiKey: '6817899882858207', search: data.term // search term }; }, processResults: function(response) { return { results: response }; }, cache: true } }); initOwnerSelect2(); $('#mod-dd-brand').select2({ placeholder: "Select Brand", allowClear: true, "language": { "noResults": function() { return "Select Brand" } }, escapeMarkup: function(markup) { return markup; }, ajax: { url: 'api/brand/brand.php', dataType: 'json', delay: 250, data: function(data) { return { apiKey: '6019050878857324', search: data.term // search term }; }, processResults: function(response) { return { results: response }; }, cache: true } }); $('#mod-dd-brand').on('change', function(event) { $('#mod-dd-model').val('').trigger('change'); }); $("#mod-dd-model").select2({ placeholder: "Select Model", allowClear: true, "language": { "noResults": function() { return 'Select brand first' } }, escapeMarkup: function(markup) { return markup; }, ajax: { url: 'api/model/model.php', dataType: 'json', delay: 250, data: function(data) { return { brand_id: $("#mod-dd-brand").val(), apiKey: '8732194955663346', search: data.term // search term }; }, processResults: function(response) { return { results: response }; }, cache: true } }); $("#mod-dd-color").select2({ tags: true, placeholder: "Select Color", allowClear: true, "language": { "noResults": function() { return 'Search or enter color' } }, escapeMarkup: function(markup) { return markup; }, ajax: { url: 'api/color/color.php', dataType: 'json', delay: 250, data: function(data) { return { apiKey: '4635171175642895', search: data.term // search term }; }, processResults: function(response) { return { results: response }; }, cache: true } }); $('#mod-dd-insurance-type').select2({ // tags: true, placeholder: "Select Insurance Type", allowClear: true }); $('#mod-dd-type').select2({ tags: true, placeholder: "Select Type", allowClear: true }); $('#mod-transmission').select2({ placeholder: "Select Transmission", allowClear: true }); $('#mod-dd-mode-of-sale').select2({ placeholder: "Select Mode of Sale", allowClear: true }); $('#mod-dd-source-of-sale').select2({ placeholder: "Select Source of Sales", allowClear: true }); $('#mod-dd-type-of-payment').select2({ placeholder: "Select Type of Payment", allowClear: true }); $('#mod-dd-dms').select2({ placeholder: "Select DMS", allowClear: true }); $('#mod-dd-company').select2({ placeholder: "Select Company", allowClear: true, "language": { "noResults": function() { return 'Select DMS first' } }, escapeMarkup: function(markup) { return markup; }, ajax: { url: "api/company/company.php", dataType: 'json', delay: 250, data: function(data) { return { search: data.term, // search term dms_id: $('#mod-dd-dms').val(), apiKey: '3568127986733141' }; }, processResults: function(response) { return { results: response }; }, cache: true } }); $('#mod-dd-dealer').select2({ placeholder: "Select Dealer", allowClear: true, "language": { "noResults": function() { return 'Search or enter dealer name' } }, escapeMarkup: function(markup) { return markup; }, ajax: { url: 'api/dealer/dealer.php', dataType: 'json', delay: 250, data: function(data) { return { apiKey: '6209267133015033', company_id: $('#mod-dd-company').val(), search: data.term // search term }; }, processResults: function(response) { return { results: response }; }, cache: true } }); $('#mod-dd-dms').on('change', function(event) { $('#mod-dd-company').val('').trigger('change') }); $('#mod-dd-company').on('change', function(event) { $('#mod-dd-dealer').val('').trigger('change') }); $("#mod-dd-insurance-company").select2({ tags: true, placeholder: "Select Insurance", allowClear: true, "language": { "noResults": function() { return 'Search or enter insurance' } }, escapeMarkup: function(markup) { return markup; }, ajax: { url: 'api/insurance/insurance.php', dataType: 'json', delay: 250, data: function(data) { return { apiKey: '5068581874181452', search: data.term // search term }; }, processResults: function(response) { return { results: response }; }, cache: true } }); $("#mod-dd-model-variant").select2({ tags: false, placeholder: 'Search or enter model variant', allowClear: true, "language": { "noResults": function() { return 'Search or enter model variant' } }, escapeMarkup: function(markup) { return markup; }, ajax: { url: 'api/model/model.php', dataType: 'json', delay: 250, data: function(data) { return { model_id: $('#mod-dd-model').val(), apiKey: '8276291179252248', search: data.term // search term }; }, processResults: function(response) { return { results: response }; }, cache: true } }); $("#mod-dd-finance-company").select2({ tags: true, placeholder: "Select Finance", allowClear: true, "language": { "noResults": function() { return 'Search or enter insurance type' } }, escapeMarkup: function(markup) { return markup; }, ajax: { url: 'api/finance/finance.php', dataType: 'json', delay: 250, data: function(data) { return { apiKey: '9608572737271761', search: data.term // search term }; }, processResults: function(response) { return { results: response }; }, cache: true } }); $("#mod-dd-group-manager").select2({ // tags: true, placeholder: "Select Group Manager", allowClear: true, "language": { "noResults": function() { return 'Search group manager' } }, escapeMarkup: function(markup) { return markup; }, ajax: { url: 'api/employee/employee.php', dataType: 'json', delay: 250, data: function(data) { return { apiKey: '6634138134581199', search: data.term // search term }; }, processResults: function(response) { return { results: response }; }, cache: true } }); $("#mod-dd-sales-consultant").select2({ // tags: true, placeholder: "Select Sales Consultant", allowClear: true, "language": { "noResults": function() { return 'Search sales consultant' } }, escapeMarkup: function(markup) { return markup; }, ajax: { url: 'api/employee/employee.php', dataType: 'json', delay: 250, data: function(data) { return { // gm_id: $('#mod-dd-group-manager').val(), apiKey: '6634138134581199', search: data.term // search term }; }, processResults: function(response) { return { results: response }; }, cache: true } }); $("#mod-dd-group-manager-asa").select2({ // tags: true, placeholder: "Search Group Manager", allowClear: true, escapeMarkup: function(markup) { return markup; }, ajax: { url: 'https://www.autohub.ph/connect/LOAD_SALES_PERSON.php', dataType: 'json', delay: 250, data: function(data) { return { apiKey: '7594712920757225', search: data.term // search term }; }, processResults: function(response) { return { results: response }; }, cache: true } }); $("#mod-dd-sales-consultant-asa").select2({ // tags: true, placeholder: "Search Sales Consultant", allowClear: true, escapeMarkup: function(markup) { return markup; }, ajax: { url: 'https://www.autohub.ph/connect/LOAD_SALES_PERSON.php', dataType: 'json', delay: 250, data: function(data) { return { apiKey: '7594712920757225', search: data.term // search term }; }, processResults: function(response) { return { results: response }; }, cache: true } }); } function photoDropzoneListener(){ Dropzone.autoDiscover = false; $("#upload-sales-photo").dropzone({ url: "api/upload/upload_image.php", // If not using a form element acceptedFiles: '.png,.jpg,.jpeg', //allowed filetypes maxFilesize: 8, maxFiles: 10, clickable: true, addRemoveLinks: true, dictCancelUpload: '', removedfile: function(file) { // alert(file.upload.filename) if (!modal_reset) { $.ajax({ type: 'POST', url: 'api/upload/upload_image.php', dataType: 'json', data: { name: file.upload.filename, request: 'delete' }, sucess: function(data) { console.log('success: ' + data); } }); } // var upload_name = file.upload.filename.substr((file.name.lastIndexOf('.') + 1)); //re.exec(file.name)[1]; upload_image_name.splice($.inArray(file.upload.filename, upload_image_name), 1); //remove image var _ref; return (_ref = file.previewElement) != null ? _ref.parentNode.removeChild(file .previewElement) : void 0; }, renameFile: function(file) { var extension = file.name.substr((file.name.lastIndexOf('.') + 1)); //re.exec(file.name)[1]; extension = extension.toLowerCase(); let newName = uniqImgId() + '.' + extension; //;new Date().getTime() + '_' + file.name; upload_image_name.push(newName) return newName; }, init: function() { this.on("maxfilesexceeded", function(file) { $('#proceed-button-vehicle').attr('disabled', false); sweetAlertSimple('error', 'Oops...', 'Only 10 images.'); return; }); this.on("error", function(file) { $('#proceed-button-vehicle').attr('disabled', false); upload_image_name.splice($.inArray(file.upload.filename, upload_image_name), 1); //remove image // alert("Nice"); return; }); this.on("success", function(file, responseText) { $('#proceed-button-vehicle').attr('disabled', false); }); this.on('sending', function(file, xhr, formData) { $('#proceed-button-vehicle').attr('disabled', true); }); } }); } function hasSalesRecordListener(){ $('#has_sales_record').click(function() { if ($('#has_sales_record').prop('checked')) { $('#div-order-number').show(); $('#sales-info-1').show(); $('#sales-info-2').show(); $('#insurace-finance-section').show(); $('#vehicle-offered-section').show(); $('#has-sales-record').val('1'); } else { $('#div-order-number').hide(); $('#sales-info-1').hide(); $('#sales-info-2').hide(); $('#insurace-finance-section').hide(); $('#vehicle-offered-section').hide(); $('#has-sales-record').val('0'); // hide all fields } }); } function resetVehicleModal() { resetSaleModal(); addVehicleModalTabSelectedTab(1); modal_reset = true; Dropzone.forElement('#upload-sales-photo').removeAllFiles(true); while (upload_image_name.length > 0) { upload_image_name.pop(); } $('#div-order-number').hide(); $('#sales-info-1').hide(); $('#sales-info-2').hide(); $('#insurace-finance-section').hide(); $('#vehicle-offered-section').hide(); $('#has-sales-record').val('0'); $('#has_sales_record').prop('checked', false); $('#has_sales_record_div').show(); } function resetSaleModal() { $("#brands-offered-list-table > tbody").empty(); // addVehicleModalTabSelectedTab(1); } function addVehicleModalTabSelectedTab(type) { $('#vehicle-modal-tab .nav-link').removeClass('active'); $('#vehicle-modal-tab-content .tab-pane').removeClass('show'); $('#vehicle-modal-tab-content .tab-pane').removeClass('active'); switch (type) { case 1: $('#vehicle-modal-tab-information').addClass('active') $('#vehicle-modal-information').addClass('active') $('#vehicle-modal-information').addClass('show') break; case 2: // $('#vehicle-modal-tab-sales-information').addClass('active') // $('#vehicle-modal-sales-information').addClass('active') // $('#vehicle-modal-sales-information').addClass('show') break; case 3: $('#vehicle-modal-tab-sales-picture').addClass('active') $('#vehicle-modal-sales-picture').addClass('active') $('#vehicle-modal-sales-picture').addClass('show') break; case 4: $('#vehicle-modal-tab-sales-record').addClass('active') $('#vehicle-modal-sales-record').addClass('active') $('#vehicle-modal-sales-record').addClass('show') break; } } function uniqImgId() { var id = Math.round(new Date().getTime() + (Math.random() * 100)); return id; } function addRowBrandsOffered() { $('#addRowVehicleOffered').click(function() { if (!checkIfBrandsOfferedIncomplete() && $('#brands-offered-list-table tbody tr').length > 0) { sweetAlertSimple('error', 'Oops...', 'Complete brand offered details first'); } else { addBrandsOfferedItem(); } }); $("#brands-offered-list").on("click", ".btnRemove", function() { $(this).closest("tr").remove(); }); } function checkIfBrandsOfferedIncomplete() { rows = getAllBrandsOfferedTableData(); var brandsOfferedJsonRow = rows; var hasMatch = true; for (var index = 0; index < brandsOfferedJsonRow.length; ++index) { var brandsOfferedJson = brandsOfferedJsonRow[index]; if (brandsOfferedJson.Description == "" && brandsOfferedJson.Brand == "") { hasMatch = false; break; } } return hasMatch; } function getAllBrandsOfferedTableData() { var $table = $("#brands-offered-list-table") rows = [], header = []; $table.find("thead th").each(function() { header.push($(this).html().replace(/\s/g, '_').replace(/\./g, '')); }); $table.find("tbody tr").each(function() { var row = {}; $(this).find("td").each(function(i) { if (header[i] == 'Description') { var key = header[i], value = $(this).find('input').val(); row[key] = value; } else { var key = header[i], value = $(this).find('select').val(); row[key] = value; } }); rows.push(row); }); return rows; } function addBrandsOfferedItem() { var brands_offered_list = document.getElementById('brands-offered-list'); const brands_offered_list_base = document.querySelector('#brands-offered-list-clone tbody tr'); var brandsOfferedItem = []; brands_offered_list.appendChild(brands_offered_list_base.cloneNode(true)); var BrandsOfferedIdDateNow = Date.now(); var newBrandsOfferedBrandId = 'brands-offered-brand-' + BrandsOfferedIdDateNow; var newBrandsOfferedModelId = 'brands-offered-model-' + BrandsOfferedIdDateNow; var newBrandsOfferedDescriptionId = 'brands-offered-description-' + BrandsOfferedIdDateNow; brandsOfferedItem[0] = (newBrandsOfferedBrandId); brandsOfferedItem[1] = (newBrandsOfferedModelId); brandsOfferedItem[2] = (newBrandsOfferedDescriptionId); // alert(interestItem.pop(0)); // alert(interestItem.pop(1)); // Update the ID of the select> in the new row // (it should be the only one with an `id` of '#element'), // and initialize the Select2. $('#select-brand').attr('id', newBrandsOfferedBrandId).select2({ placeholder: "Select Brand", allowClear: true, "language": { "noResults": function() { return 'Search Brand' } }, escapeMarkup: function(markup) { return markup; }, placeholder: 'Search Brand', ajax: { url: 'api/brand/brand.php', dataType: 'json', delay: 250, data: function(data) { return { apiKey: '6019050878857324', search: data.term // search term }; }, processResults: function(response) { return { results: response }; }, cache: true } }); $('#select-model').attr('id', newBrandsOfferedModelId).select2({ // tags: true, placeholder: "Select Model", allowClear: true, "language": { "noResults": function() { return 'Search model' } }, escapeMarkup: function(markup) { return markup; }, placeholder: 'Search model', ajax: { url: 'api/model/model.php', dataType: 'json', delay: 250, data: function(data) { return { apiKey: '8732194955663346', brand_id: $('#' + newBrandsOfferedBrandId).val(), search: data.term // search term }; }, processResults: function(response) { return { results: response }; }, cache: true } }); $('#mod-brands-offered-description').attr('id', newBrandsOfferedDescriptionId); $('#' + newBrandsOfferedBrandId).on('select2:select', function(e) { $('#' + newBrandsOfferedModelId).val('').trigger('change') }); $('#' + newBrandsOfferedBrandId).on("select2:unselecting", function(e) { $('#' + newBrandsOfferedModelId).val('').trigger('change') }); return brandsOfferedItem; // CREATE ROW }
| ver. 1.4 |
.
| PHP 7.3.33 | Generation time: 0 |
proxy
|
phpinfo
|
Settings