File manager - Edit - /home/autoph/public_html/projects/tickets-autohub/public/js/authentication/roles/form.js
Back
(function(e){ "use strict"; function checkRoleVal(){ $('#_userRole').on('change', function(e){ var selectedRoleName = $(this).find('option:selected').text(); $.ajax({ type: "POST", url: "/users/getAbilitiesByRole/" + $(this).val(), dataType: 'json', data: null, processData: false, contentType: false, headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') }, success: function(result){ var abilities = $("<div></div>"); var roleTitle = $("<h6></h6>"); roleTitle.html("Change To: <br/><br/>" + selectedRoleName + ":"); abilities.append(roleTitle); // Reset the existing content of the _roleAbilities div $('#_roleAbilities').empty(); // Append the abilities div to the _roleAbilities div $('#_roleAbilities').append(abilities); $.each(result, function(index, key) { var ability = $("<div></div>"); ability.text("🗸 " + key.title); abilities.append(ability); }); }, error: function(error){ } }); }); } $("#_company").on('change', function() { const comArr = $(this).val(); if($('#multiple-select-clear-field-company').val()!='') { $('#multiple-select-clear-field-dealer').attr('disabled',false); } else { $('#multiple-select-clear-field-dealer').attr('disabled',true); } $.ajax({ url: "/roles/fetch-dealer", type: "POST", data: { com_id: comArr }, headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') }, success: function(result) { $('#multiple-select-clear-field-dealer').empty(); $('#multiple-select-clear-field-dealer').append('<option value="" disabled selected>Select Dealer</option>'); $.each(result[0], function(index, dealer) { $('#multiple-select-clear-field-dealer').append( '<option value="' + dealer.id + '">' + dealer.dealer_name + '</option>' ); }); }, error: function(error) { console.log(error); } }); }); function fetchDealers(){ $.ajax({ url: "/roles/fetch-dealer", type: "POST", data: { com_id: $("#_company").val(), }, headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') }, success: function(result) { // $('#multiple-select-clear-field-dealer').empty(); // $('#multiple-select-clear-field-dealer').append('<option value="" disabled selected>Select Dealer</option>'); $.each(result[0], function(index, dealer) { // Check if dealer.id matches the user's deal_code const isSelected = dealer.id == userDelaerID ? 'selected' : ''; $('#multiple-select-clear-field-dealer').append( '<option value="' + dealer.id + '" ' + isSelected + '>' + dealer.dealer_name + '</option>' ); }); }, error: function(error) { console.log(error); } }); } // $("#_company").on('change', function() { // const comArr = $(this).val(); // if($('#_company').val()!='') // { // $('#multiple-select-clear-field-dealer').attr('disabled',false); // } // else // { // $('#multiple-select-clear-field-dealer').attr('disabled',true); // } // $.ajax({ // url: "/roles/fetch-dealer", // type: "POST", // data: { // com_id: comArr // }, // headers: { // 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') // }, // success: function(result) { // const userDelaerID = "{{ user->deal_id}}"; // $('#multiple-select-clear-field-dealer').empty(); // $('#multiple-select-clear-field-dealer').append('<option value="" disabled selected>Select Dealer</option>'); // // $.each(result[0], function(index, dealer) { // // $('#multiple-select-clear-field-dealer').append( // // '<option value="' + dealer.id + '">' + dealer.dealer_name + '</option>' // // ); // // }); // $.each(result[0], function(index, dealer) { // // Check if dealer.id matches the user's deal_code // const isSelected = dealer.id == userDelaerID ? 'selected' : ''; // $('#multiple-select-clear-field-dealer').append( // '<option value="' + dealer.id + '" ' + isSelected + '>' + dealer.dealer_name + '</option>' // ); // }); // }, // error: function(error) { // console.log(error); // } // }); // }); function getUserAbilities(){ $.ajax({ type: "POST", url: "/users/getUserAbility/" + user.id, dataType: 'json', data: null, processData: false, contentType: false, headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') }, success: function(result){ $.each(result.roles, function(index, role) { // Create a new div element for the role var roleDiv = $("<div></div>"); // Create an h6 element for the role title var roleTitle = $("<h6></h6>"); roleTitle.html("Current:<br/><br/>" + role.title + " Level:"); // Append the role title to the role div roleDiv.append(roleTitle); // Append the role div to the existing div with id "abilitiesDiv" $('#abilitiesDiv').append(roleDiv); // Iterate over the abilities of the current role $.each(role.abilities, function(index, ability) { // Create a new div element for each ability var abilityDiv = $("<div></div>"); // Set the text content of the ability div abilityDiv.text("🗸 " + ability.title); // Append the ability div to the role div roleDiv.append(abilityDiv); }); }); }, error: function(error){ // console.log(error); // swal.fire({ // 'icon':"error", // 'text': error.statusText // }); } }); } function submit(){ $('#_editUserForm').on('submit', (e)=>{ e.preventDefault(); if ($("#_userRole").val() === '') { roleError.style.display = 'block'; e.preventDefault(); // Prevent form submission } else { if (roleError) { roleError.style.display = 'none'; } } var formData = new FormData(); formData.append('id',user.id); formData.append('f_name',$('#_fName').val()); formData.append('l_name',$('#_lName').val()); formData.append('email',$('#_email').val()); formData.append('viber',$("#_viber").val()); formData.append('anydesk',$("#_anydesk").val()); formData.append('position',$('#_position').val()); formData.append('role',$('#_userRole').val()); formData.append('department_id',$("#_department").val()); formData.append('company_id',$('#_company').val()); formData.append('dealership_id',$('#multiple-select-clear-field-dealer').val()); $.ajax({ type: "POST", url: "/users/update", dataType: 'json', data: formData, processData: false, contentType: false, headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') }, success: function(result){ toastRWithTime(result.message,"success"); window.location.reload(); // swal.fire({ // 'text': result.message // }); // window.location.href = "/category"; }, error: function(error){ // console.log(error); // swal.fire({ // 'icon':"error", // 'text': error.statusText // }); } }); }); } $(function(){ getUserAbilities(); submit(); checkRoleVal(); fetchDealers(); }); })();
| ver. 1.4 |
.
| PHP 8.1.32 | Generation time: 0.13 |
proxy
|
phpinfo
|
Settings