File manager - Edit - /home/autoph/public_html/projects/tickets-autohub/public/js/authentication/vehicle/index.js
Back
(function(e){ "use strict"; var search_type_filter = []; var ticketList = null; var id = null; var comp_id; var deal_id; var date_from = null; var date_to = null; function delay(callback, ms) { var timer = 0; return function () { var context = this, args = arguments; clearTimeout(timer); timer = setTimeout(function () { callback.apply(context, args); }, ms || 0); }; } function getDataTableData(){ var datas = {}; datas.option = $('select[name="_carplus_ticket_option"]').val(); datas.company = comp_id; datas.dealer = deal_id; // datas.data = { // option: '', // Replace with your desired value // date_from: date_from, // Assign the global date_from value // date_to: date_to, // Assign the global date_to value // }; return datas; } function initActionView(){ $('[data-action-view]').each(function(){ $(this).on('click', function(){ var row = $(this).closest('tr'); id = ticketList.row(row).data().id; var hiddenInput = $(`<input type="hidden" name="_idShow" value="${id}">`); var hiddenButton = $(`<div class="row justify-content-end mt-2"><div class="col-auto"><button class="btn btn-primary" name="submit_note" id="submit_note">Add Note</button></div></div>`) $("#vehicle_view #vehicleInformation").append(hiddenInput); // if(abilities.includes('')) $('.add_notes').append(hiddenButton); $('#vehicle_view').modal('show'); }); }); } function fetchVehicleTicket($id){ let res; Swal.fire({ title: 'Loading...', allowOutsideClick: false, // Prevent users from dismissing the loading message didOpen: () => { Swal.showLoading(); } }); $.ajax({ type: "GET", url: "/ticket/carplus/information", dataType: 'json', data: { id: $id, }, headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') }, success: function(result){ res = result; }, complete: function(){ if(abilities.includes('close-carplus-ticket')){ $('#vehicleInformation .card-body.tab-content input').each(function() { $(this).prop('readonly', true); // Set the "readonly" attribute }); $('#vehicleInformation .card-body.tab-content #v_financing').each(function() { $(this).prop('readonly', true); // Set the "readonly" attribute }); } let table = $(`<table class="table table-striped" style="width:100%"> <thead> <tr> <th>Note</th> <th>Sender</th> <th>Date Added</th> </tr> </thead> <tbody></tbody> </table>`); $('#v_fname').val(res.vehicle['owner_fname']); $('#v_mname').val(res.vehicle['owner_mname']); $('#v_lname').val(res.vehicle['owner_lname']); $('#v_address').val(res.vehicle['owner_address']); $('#v_contact').val(res.vehicle['owner_phone']); $('#v_email').val(res.vehicle['owner_email']); $('#v_make').val(res.vehicle['vehicle_make']); $('#v_model').val(res.vehicle['vehicle_model']); $('#v_year').val(res.vehicle['vehicle_year']); $('#v_vin').val(res.vehicle['vehicle_vin']); $('#v_lp').val(res.vehicle['license_plate']); $('#v_color').val(res.vehicle['vehicle_color']); $('#v_pd').val(res.vehicle['purchase_date']); $('#v_pprice').val(res.vehicle['purchase_price']); $('#v_dealer').val(res.vehicle['dealer_location']); $('#v_financing').val(res.vehicle['financing_details']); $('#v_regep').val(res.vehicle['registration_expiry']); $('#v_regno').val(res.vehicle['registration_number']); $('#v_regstate').val(res.vehicle['registration_state']); $('#v_insurance').val(res.vehicle['insurance_provider']); $('#v_polno').val(res.vehicle['policy_number']); $('#v_polexp').val(res.vehicle['policy_expiry']); $('#v_lsd').val(res.vehicle['last_service_date']); $('#v_lst').val(res.vehicle['last_service_type']); $('#v_nsd').val(res.vehicle['next_service_due']); $('#v_sp').val(res.vehicle['service_provider']); res.notes.forEach(function(key,value){ let date = moment(key['created_at']).format('MMMM D, Y'); table.append($(`<tbody><tr><td>${key['note']}</td><td>${key['f_name'] + " " + key['l_name']}</td><td>${date}</td></tr></tbody>`)); }); $('.notes_tbl').empty().append(table); $('.notes_tbl').css('display',"block"); Swal.close(); }, error: function(error){ } }); } function initList(){ $("#txt_search").on( "keyup", delay(function (e) { ticketList.search($("#txt_search").val()).draw(); }, 500) ); $('select[name="_ticket_option"]').on('change', function(e){ ticketList.draw(false); }); var search_type_default = "Ticket ID"; var search_types = ["Ticket ID", "Sender", "Dealer", "Company"]; $.each(search_types, function (i, n) { $("._ticket_search_type").append( `<li class="dropdown-item cursor-pointer py-0"><span class="text-sm">` + n + `</span></li>` ); }); $("._ticket_search_type li").each(function () { if ($(this).text() == search_type_default) { $(this).removeClass("active").addClass("active"); var active_items_arr = []; active_items_arr.push(search_type_default); search_type_filter = JSON.stringify(active_items_arr); } $(this).on("click", function () { //remove all selected menu $("._ticket_search_type") .find("li.active") .map(function () { $(this).removeClass("active"); }); $(this).toggleClass("active"); var active_items = $("._ticket_search_type") .find("li.active") .map(function () { var item = {}; // item.id = this.value; item.status = $(this).text(); return item; }); var active_items_arr = []; $.each(active_items, function (i, n) { active_items_arr.push(n.status); }); search_type_filter = JSON.stringify(active_items_arr); // refreshOrcrPlateTable(); // if ($('#txt_search').val() != '') { ticketList.ajax.reload(); // } }); }); var cols = [ { title: "Ticket ID", data: 'id', className: 'align-middle p-1 dt-left', orderable: true, width: "20%", render: function(data, type, row, meta){ return `CARPLUS_${data}`; } }, { title: "Sender", data: 'sender', className: 'align-middle p-1 dt-left', orderable: true, width: "20%", }, { title: "Company", data: 'comp_code', className: 'align-middle p-1 dt-left', orderable: true, width: "10%", }, { title: "Dealer", data: 'deal_code', className: 'align-middle p-1 dt-left', orderable: true, width: "10%", }, { title: "Status", data: 'status', className: 'align-middle p-1 dt-left', orderable: true, width: "10%", }, { title: "Date Created", data: 'created_at', className: 'align-middle p-1 dt-left', orderable: true, width: "10%", }, { title: "Action", data: null, className: 'align-middle p-1 dt-left', // orderable: true, width: "20%", render: function(data, type, row, meta){ if(abilities.includes('close-carplus-ticket')){ return ` <div class="row justify-content-center"> <a data-action-view style="cursor:pointer; width: fit-content;" class="m-1 btn btn-sm btn-info btn-icon" title="Edit"><i class="fa fa-eye" aria-hidden="true"></i> View</a> </div> `; } else { return ` <div class="row justify-content-center"> <a data-action-view style="cursor:pointer; width: fit-content;" class="m-1 btn btn-sm btn-info btn-icon" title="Edit"><i class="fa fa-eye" aria-hidden="true"></i> Edit</a> </div> `; } } } ]; // <a data-action-remove style="cursor:pointer; width: fit-content;" class="m-1 btn btn-sm btn-danger btn-icon" title="Delete"><i class="fa fa-trash" aria-hidden="true"></i> Delete</a> ticketList = $('#carplusTickets').DataTable({ fnDrawCallback: function () { initActionView(); // initActionDestroy(); }, // processing: true, // language: { // "processing":'<div class="spinner-border text-primary" role="status"><span class="sr-only">Loading...</span></div>' // }, order: [[0, "desc"]], retrieve: true, columns: cols, paging: true, lengthChange: false, searching: true, pageLength: 5, info: true, autoWidth: true, responsive: true, processing: true, serverSide: true, autoWidth: true, columnDefs: [ { width: '20%', targets: 0 } ], fixedColumns: true, ajax: { url:'/ticket/carplus/fetchTickets', data: function (d){ return $.extend({},d,{ search_type: search_type_filter, data: getDataTableData(), }); } }, sDom: "lrtip", }); } function submitNote(){ $('.add_notes').on('click', '#submit_note', function(e) { e.preventDefault(); $.ajax({ type: "POST", url: "/ticket/carplus/addNote/" + $('[name="_idShow"]').val(), dataType: 'json', data: { note: $('#v_notes').val() }, headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') }, success: function(result){ toastRWithTime(result.message,"success"); $('#v_notes').val(''); }, error: function(error){ toastRWithTime(error.responseJSON.message,"error"); } }); }); } function closeVehicleTicket(){ $('#vehicle_view').on('click', '#close_v_ticket', function(e){ e.preventDefault(); // alert($('[name="_idShow"]').val()); swal.fire({ title: 'Are you sure?', text: "You won't be able to revert this!", icon: 'warning', iconColor: 'red', showCancelButton: true, confirmButtonColor: '#3085d6', cancelButtonColor: '#d33', confirmButtonText: 'Yes, close it!' }).then((result)=>{ if(result.isConfirmed){ $.ajax({ type: "POST", url: "/ticket/carplus/close/" + $('[name="_idShow"]').val(), dataType: 'json', data: null, headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') }, success: function(result){ toastRWithTime(result.message,"success"); $('#vehicle_view').modal('hide'); ticketList.draw(false); }, error: function(error){ toastRWithTime(error.responseJSON.message,"error"); } }); } }); }); } // function changeDate(){ // date_from = $('#from_date').val(); // date_to = $('#to_date').val(); // if(date_from && !date_to){ // toastRWithTime("Please specify an end date","error"); // } else if (!date_from && date_to){ // toastRWithTime("Please specify a start date","error"); // } else { // return {date_from:date_from,date_to:date_to} // } // } $(function(){ initList(); submitNote(); closeVehicleTicket(); // $('#from_date').on('change', function(e){ // changeDate(); // }); // $('#to_date').on('change', function(e){ // changeDate(); // ticketList.draw(false); // }); $('[name="_reloadTicketsTable"]').on('click', function(e){ ticketList.draw(false); }); $('[name="_addCarplusTicket"]').on('click', function(e){ window.location.href = "/ticket/carplus/create"; }); $('#vehicle_view').on('shown.bs.modal', function(e){ fetchVehicleTicket($('[name="_idShow"]').val()); }); $('#vehicle_view').on('hidden.bs.modal', function(e){ $('[name="submit_note"]').remove(); $('[name="_idShow"]').remove(); }); $('[name="_carplus_ticket_option"]').on('change', function(){ ticketList.draw(false); }); $('#v_pprice').inputmask({ mask: "99,999,999.99", placeholder: "_", numericInput: true, radixPoint: "." }); $('[name="_vehicle_ticket_comp"]').select2({ dropdownParent: $('#vehicle_filter'), allowClear: true, language: { noResults: function () { return "No Data Available"; }, }, escapeMarkup: function (markup) { return markup; }, placeholder: "Select Companies", ajax: { url:"/companies/getCompanies", dataType: 'json', delay: 250, data: function (data) { return { search: data.term, limit: 1, }; }, processResults: function (response) { return { results: response.results, }; }, cache: true, } }); $('[name="_vehicle_ticket_deal"]').select2({ allowClear: true, placeholder: "Select Dealers", // ajax: { // // Initially set the URL to an empty string // url: '', // dataType: 'json', // delay: 250, // data: function (data) { // return { // search: data.term, // comp_id: $('[name="_vehicle_ticket_comp"]').val(), // Get the selected comp_id // limit: 1, // }; // }, // processResults: function (response) { // return { // results: response.results, // }; // }, // cache: true, // } }); $('[name="_vehicle_ticket_comp"]').on('change', function(e){ comp_id = $(this).val(); // ticketList.draw(false); $.ajax({ url: "/dealers/getDealersPerCompany/" + comp_id, method: 'GET', data: null, processData: false, contentType: false, headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') }, success: function(response) { $('[name="_vehicle_ticket_deal"]').empty(); $.each(response['results'], function(key,value){ $('[name="_vehicle_ticket_deal"]').append(`<option value="`+ value.id +`">`+ value.text +`</option>`) }) }, error: function(error){ } }); }); $('[name="_vehicle_ticket_deal"]').on('change', function(e){ deal_id = $(this).val(); ticketList.draw(false); }); }); })();
| ver. 1.4 |
.
| PHP 8.1.32 | Generation time: 0 |
proxy
|
phpinfo
|
Settings