Spaces:
Runtime error
Runtime error
Update templates/company_profile.html
Browse files168 unmodified lines1691701711721731721731741751761771781 unmodified line18018118218318318418518618718818919018919019119253 unmodified lines24624724824925025125225325425511 unmodified lines26726826927027127227327427527627727826726826927928028128228328428528628728828929029129212 unmodified lines30530630730830931031131231331431531631731815 unmodified lines3343353363373383393403413423133433443453463475 unmodified lines3533543553253563573283293303313323333343353363373383393403413423433443583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994003494014024034044054064074087 unmodified lines41641741841936536642042142242342419 unmodified lines4444454463924474484494508 unmodified lines4594604614074624634644654668 unmodified lines4754764774224784794804815 unmodified lines48748848943449049149249313 unmodified lines5075085094545105115125135145155165175185195205215225235245255265278 unmodified lines53653753847653954054154234 unmodified lines577578579517580581582583168 unmodified lines <div class="row mb-2"> <div class="col-12"> <div class="col-12 d-flex justify-content-end mb-3"> <button class="btn btn-primary" style="margin-bottom:-30px;position:fixed" id="add">Add</button> <button class="btn btn-primary" style="margin-bottom:-30px;position:fixed" id="add">Add</button> </div> </div> <input type="hidden" id="userRole" name="userRole" value={{role}}> <div class="row"> <div id="message-container" style="margin-left: 200px;width:600px;"></div> </div>1 unmodified line </div> </div> <!-- Main content --> <section class="content"> <section class="content" id="startTable" style="display: none;"> <div class="container-fluid"> <div class="row"> <div class="col-12"> <div class="card"> <div class="card-body table-container"> <table id="companyTable" class="custom-select-lm table table-bordered table-striped"> <table id="companyTable" class="custom-select-lm table table-bordered table-striped"> <thead> <tr> <th>Sno</th>53 unmodified lines Please select at least one LLM tool. </div> </div> <div class="form-group"> <label for="domain">UserName<span class="text-danger">*</span></label> <input type="text" class="form-control" id="username" name="username" required> </div> </form> </div> <div class="modal-footer">11 unmodified lines document.addEventListener('DOMContentLoaded', function () {
const role = sessionStorage.getItem('userRole'); const company_id=sessionStorage.getItem('company_id'); console.log('Current role:', role); // Debug statement to check the role document.getElementById('userRole').value = role; $('#addModal').hide(); // Make sure this is called initially
if (role === 'superadmin') { console.log("insidse compamy profile super admin"); $('#startTable').show(); console.log('Current role:', role); // Debug statement to chec document.getElementById('add').style.display = 'block'; $('#addModal').hide(); document.getElementById('add').style.display = 'block'; } else { console.log("insidse company profile admin"); document.getElementById('add').style.display = 'none'; const modalTitle = document.getElementById('addModalLabel'); modalTitle.textContent = 'Company Details'; viewCompany(company_id);
} fetchCompanies(); }); window.addEventListener('pageshow', function (event) {12 unmodified lines placeholder: 'Select', allowClear: true }); }); // Show modal function $('#add').on('click', function () { const modalTitle = document.getElementById('addModalLabel'); modalTitle.textContent = 'Add Company Details'; console.log('Modal title after setting:', modalTitle.textContent); // This should log the new title
$('#addModal').modal('show'); $('#save').show(); $('#saveupdate').hide();15 unmodified lines $(document).on('click', '.btn-edit', function () { const companyId = $(this).data('id'); console.log("company_id in edit", companyId); if (companyId) { const modalTitle = document.getElementById('addModalLabel'); modalTitle.textContent = 'Edit Company Details'; console.log('Modal title:', modalTitle.textContent);
editCompany(companyId); Editcompany(companyId); } });
// Delete company5 unmodified lines } });
}); // View company details function viewCompany(companyId) { // Fetch company details by ID const modalTitle = document.getElementById('addModalLabel'); modalTitle.textContent = 'View Company Details'; $.getJSON(`/api/getcompanydetails/${companyId}`, function (company) { // alert(`Company Name: ${company.company_name}\nCompany Code: ${company.company_code}\nDomain: ${company.domain}\nLLM Tools: ${company.llm_tools}`); $('#company_name').val(company.company_name).attr('readonly', 'readonly'); $('#company_code').val(company.company_code).attr('readonly', 'readonly'); $('#domain').val(company.domain).attr('readonly', 'readonly'); $('#llm_tools').val(company.llm_tools.split(',')).trigger('change'); $('#llm_tools').prop('disabled', true); // Disable the select input
// Open the modal for editing $('#saveupdate').hide(); $('#save').hide();// Disable the "Save" button when the modal opens $('#addModal').modal('show'); }).fail(function () { alert("Error retrieving company details."); // Fetch company details by ID const username = sessionStorage.getItem('username'); const modalTitle = document.getElementById('addModalLabel'); modalTitle.textContent = 'View Company Details';
$.getJSON(`/api/getcompanydetails/${companyId}`, function (company) { // Set values and attributes for the form fields $('#company_name').val(company.company_name).attr('readonly', 'readonly'); $('#company_code').val(company.company_code).attr('readonly', 'readonly'); $('#domain').val(company.domain).attr('readonly', 'readonly');
// Clear existing options in the dropdown $('#llm_tools').empty();
// Add the options that are present in company.llm_tools const availableOptions = { 'Database': 'Database', 'Static Documents': 'Static Documents', 'API': 'API' };
if (Array.isArray(company.llm_tools)) { company.llm_tools.forEach(tool => { if (availableOptions[tool]) { $('#llm_tools').append(new Option(availableOptions[tool], tool, true, true)); } }); }
$('#llm_tools').prop('disabled', true); // Disable the dropdown
$('#username').val(username).attr('readonly', 'readonly'); // Set username field
// Show the modal with view details only $('#saveupdate').hide(); $('#save').hide(); $('#addModal').modal('show'); }).fail(function () { alert("Error retrieving company details."); });}
// Edit company details function editCompany(companyId) { function Editcompany(companyId) { const username=sessionStorage.getItem('username'); const modalTitle = document.getElementById('addModalLabel'); modalTitle.textContent = 'Edit Company Details'; console.log('Modal title after setting:', modalTitle.textContent); // Should log "Edit Company Details" // Fetch company details by ID $.getJSON(`/api/getcompanydetails/${companyId}`, function (company) { $('#company_name').removeAttr('readonly');7 unmodified lines $('#company_code').val(company.company_code); $('#domain').val(company.domain); $('#llm_tools').val(company.llm_tools.split(',')).trigger('change'); $('#username').val(username).attr('readonly', 'readonly');// Disable the select input
// Open the modal for editing //sessionStorage.setItem('llmTools', company.llm_tools); // Store as a string $('#addModal').modal('show');
// Update the save button to save the edited company19 unmodified lines messageContainer.innerHTML = ` <div class='alert alert-danger'> Company details deleted successfully. <button class='close' onclick='dismissMessage()'>OK</button> <button class='close' style='font-size:medium;margin-top:6px;' onclick='dismissMessage()'>OK</button> </div>`; fetchCompanies(); // Refresh the table },8 unmodified lines company_name: $('#company_name').val(), company_code: $('#company_code').val(), domain: $('#domain').val(), llm_tools: $('#llm_tools').val().join(',') // Assuming llm_tools is a multi-select llm_tools: $('#llm_tools').val().join(','), username: $('#username').val() // Assuming llm_tools is a multi-select }; console.log("company_data", companyData);
8 unmodified lines messageContainer.innerHTML = ` <div class='alert alert-success'> Company Data Updated successfully <button class='close' onclick='dismissMessage()'>OK</button> <button class='close' style='font-size:medium;margin-top:6px;' onclick='dismissMessage()'>OK</button> </div>`; $('#addModal').modal('hide'); // Close the modal after saving fetchCompanies();5 unmodified lines messageContainer.innerHTML = ` <div class='alert alert-danger'> No changes have been made to update company details. <button class='close' onclick='dismissMessage()'>OK</button> <button class='close' style='font-size:medium;margin-top:6px;' onclick='dismissMessage()'>OK</button> </div>`; $('#addModal').modal('hide'); //alert('No changes have been made to update company details.');13 unmodified lines const company_name = document.getElementById('company_name').value; const company_code = document.getElementById('company_code').value; const domain = document.getElementById('domain').value; const llm_tools = $('#llm_tools').val(); // Get selected values from Select2 const llm_tools = $('#llm_tools').val(); const username=$('#username').val();
// Prepare FormData let formData = new FormData(); const password="password"; const rolesave="admin"; formData.append("company_name", company_name); formData.append("company_code", company_code); formData.append("domain", domain); formData.append("llm_tools", llm_tools.join(',')); formData.append("username",username); formData.append("password",password); formData.append("role",rolesave);
$.ajax({ type: "POST",8 unmodified lines messageContainer.innerHTML = ` <div class='alert alert-success'> Data saved successfully <button class='close' onclick='dismissMessage()'>OK</button> <button class='close' style='font-size:medium;margin-top:6px;' onclick='dismissMessage()'>OK</button> </div>`; fetchCompanies(); // Refresh table data
34 unmodified lines company.domain, company.llm_tools, // Join array of tools into a string `<a href='#' class='btn btn-info btn-sm'onclick='viewCompany(${company.company_id})'><i class='fas fa-eye'></i></a>`, `<a href='#' class='btn btn-warning btn-sm'onclick='editCompany(${company.company_id})'><i class='fas fa-edit'></i></a>`, `<a href='#' class='btn btn-warning btn-sm'onclick='Editcompany(${company.company_id})'><i class='fas fa-edit'></i></a>`, `<a href='#' class='btn btn-danger btn-sm' onclick='deleteCompany(${company.company_id})'><i class='fas fa-trash'></i></a>`
]).draw(false);templates/company_profile.html+100-37