Spaces:
Runtime error
Runtime error
Update templates/company_profile.html
Browse files1 unmodified line23456786 unmodified lines1516171819203 unmodified lines24252627282915 unmodified lines454647484950515249 unmodified lines1021031041051061071081091101111121131141151161171189 unmodified lines12812913013113213335 unmodified lines1691701711721731741751761771781793 unmodified lines1831841851861871881891901911921931946 unmodified lines20120220320420520620720828 unmodified lines23723823924024124224324424524624724824925025125225318 unmodified lines2722732742752762772782792802812822832842852862872882892902912922932942952963 unmodified lines30030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933023 unmodified lines3543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054063 unmodified lines41041141241341441541641741841942042142242333 unmodified lines4574584594604614624634644654664674684694704714724734744754764774784793 unmodified lines4834844854864874884894904914924934944954964974984995005013 unmodified lines5055065075085095105115125135145154 unmodified lines52052152252352452552655 unmodified lines5825835845855865875885895905915925935945955965975985996006016021 unmodified line<html lang="en"><head><title>Company Profile</title><script src="https://code.jquery.com/jquery-3.6.0.min.js"></script><script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>6 unmodified linesrel="stylesheet" /><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css" /><style>body {background-color: transparent !important;}3 unmodified linesmargin-top: 10px;margin-left: -50px;}.content-wrapper {background-color: transparent !important;15 unmodified lines.table-responsive {width: 100%;}.table {49 unmodified linesth:nth-child(3),td:nth-child(3) {width: 10%;}th:nth-child(4),td:nth-child(4) {width: 15%;}th:nth-child(5),td:nth-child(5) {width: 20%;}th:nth-child(6),9 unmodified linestd:nth-child(8) {width: 10%;}.alert {position: relative;padding: 15px;35 unmodified lines<div class="content-header"><div class="container-fluid"><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></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>3 unmodified lines</div><!-- Main 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=" table table-bordered table-striped"><thead><tr><th>Sno</th>6 unmodified lines<th>Delete</th></tr></thead><tbody></tbody></table></div></div>28 unmodified lines<label for="domain">Domain<span class="text-danger">*</span></label><input type="text" class="form-control" id="domain" name="domain" required></div><div class="form-group"><label for="llm_tools">LLM Tools<span class="text-danger">*</span></label><select class="form-control" id="llm_tools" name="llm_tools" multiple required><option value="Database">Database</option><option value="Static Documents">Static Documents</option><option value="API">API</option></select><div class="invalid-feedback">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>18 unmodified linesconst company_id=sessionStorage.getItem('company_id');console.log('Current role:', role); // Debug statement to check the roledocument.getElementById('userRole').value = role;$('#addModal').hide(); // Make sure this is called initiallyif (role === 'superadmin') {console.log("insidse compamy profile super admin");$('#startTable').show();$('#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) {if (event.persisted || (window.performance && window.performance.navigation.type === 2)) {window.location.reload();3 unmodified lines$(document).ready(function () {// Initialize DataTable$('#companyTable').DataTable();// Initialize Select2$('#llm_tools').select2({theme: 'bootstrap4',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();clearmodal();$('#save').prop('disabled', false); // Disable the "Save" button when the modal opens});$('.modal-footer .btn-secondary, .modal-header .close').on('click', function () {$('#addModal').modal('hide');});$(document).on('click', '.btn-view', function () {const companyId = $(this).data('id');23 unmodified linesdeleteCompany(companyId); // Call the delete function with the company ID}});// View company detailsfunction viewCompany(companyId) {// Fetch company details by IDconst 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_toolsconst 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 detailsfunction Editcompany(companyId) {const username=sessionStorage.getItem('username');const modalTitle = document.getElementById('addModalLabel');modalTitle.textContent = 'Edit Company Details';3 unmodified lines$('#company_name').removeAttr('readonly');$('#company_code').removeAttr('readonly');$('#domain').removeAttr('readonly');$('#llm_tools').prop('disabled', false);$('#save').hide();$('#saveupdate').show();// Populate the form with the company's details$('#company_name').val(company.company_name);$('#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//sessionStorage.setItem('llmTools', company.llm_tools); // Store as a string33 unmodified lines}function saveupdate(companyId) {console.log("company_id", companyId);var companyData = {company_name: $('#company_name').val(),company_code: $('#company_code').val(),domain: $('#domain').val(),llm_tools: $('#llm_tools').val().join(','),username: $('#username').val() // Assuming llm_tools is a multi-select};console.log("company_data", companyData);$.ajax({url: `/api/putcompanydetails/${companyId}`,type: 'PUT',data: companyData,success: function (response) {// alert('Company details updated successfully.');const messageContainer = document.getElementById('message-container');if(messageContainer)messageContainer.innerHTML = `<div class='alert alert-success'>Company Data Updated successfully3 unmodified linesfetchCompanies();},error: function () {const messageContainer = document.getElementById('message-container');if(messageContainer)messageContainer.innerHTML = `<div class='alert alert-danger'>No changes have been made to update company details.<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.');}});}function saveProfile() {const form = document.getElementById('companyForm');3 unmodified linesform.reportValidity();return;}// Gather form dataconst 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();const username=$('#username').val();4 unmodified linesformData.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);55 unmodified lines`<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);});} catch (error) {console.error('Error fetching companies:', error);}}function clearmodal() {$('#companyForm')[0].reset(); // Reset all form fields$('#llm_tools').val(null).trigger('change'); // Clear and reset the Select2 field$('#llm_tools').select2({theme: 'bootstrap4',placeholder: 'Select',allowClear: true}); // Reinitialize Select2}</script></body>1 unmodified line234567896 unmodified lines1617181920212223242526273 unmodified lines31323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868715 unmodified lines10310410510610710810911049 unmodified lines1601611621631641651661671681691701711721731741751769 unmodified lines18618718818919019119235 unmodified lines2282292302312322332342352362372383 unmodified lines2422432442452462472482492502512522532542552562572582592602612622632642652662672686 unmodified lines27527627727827928028128 unmodified lines31031131231331431531631731831932032132232332432532632732818 unmodified lines3473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933 unmodified lines39739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545623 unmodified lines4804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145153 unmodified lines51952052152252352452552652752852953053153233 unmodified lines5665675685695705715725735745755765775785795805815825835845855865875885895903 unmodified lines5945955965975985996006016026036046056066076086096106116126133 unmodified lines6176186196206216226236246256266276286296304 unmodified lines63563663763863964064155 unmodified lines6976986997007017027037047057067077087097107117127137147157167177187197207217221 unmodified line<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Company Profile</title><script src="https://code.jquery.com/jquery-3.6.0.min.js"></script><script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>6 unmodified linesrel="stylesheet" /><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css" /><style>#add {display: inline-block ;margin-right: 15px !important; /* Optional: Adjust margin if needed */}body {background-color: transparent !important;}3 unmodified linesmargin-top: 10px;margin-left: -50px;}/* Ensure the DataTable wrapper takes the full width */.dataTables_wrapper {width: 100%;}/* Ensure the DataTable wrapper takes the full width */.dataTables_wrapper {width: 100%;}/* Style for the custom dropdown */.custom-dropdown {position: relative;display: inline-block;margin-left: 10px; /* Space between label and dropdown */}.dropdown-button {background-color: white;color: black;padding: 5px;border: 1px solid black;border-radius: 4px;cursor: pointer;text-align: left;width: 60px; /* Adjust width as needed */}.dropdown-content {display: none;position: absolute;background-color: #f9f9f9;min-width: 80px; /* Adjust width as needed */box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);z-index: 1;border: 1px solid #ddd;top: 100%; /* Position below the button */left: 0;}.dropdown-content a {padding: 10px;text-decoration: none;display: block;color: #333;}.dropdown-content a:hover {background-color: #ddd;}.content-wrapper {background-color: transparent !important;15 unmodified lines.table-responsive {width: 95%;overflow-x:none;}.table {49 unmodified linesth:nth-child(3),td:nth-child(3) {width: 20%;}th:nth-child(4),td:nth-child(4) {width: 20%;}th:nth-child(5),td:nth-child(5) {width: 10%;}th:nth-child(6),9 unmodified linestd:nth-child(8) {width: 10%;}.alert {position: relative;padding: 15px;35 unmodified lines<div class="content-header"><div class="container-fluid"><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></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>3 unmodified lines</div><!-- Main content --><section class="content" id="startTable" style="display: none;"><div class="row"><div class="col-12"><div class="card"><div class="card-body table-container"><div class="dataTables_wrapper"><div class="row"><div class="dataTables_length" ><label style="display: inline-block;margin-right:800px; margin-bottom: -40px;" >Show entries:<div class="custom-dropdown"><button class="dropdown-button">5</button><div class="dropdown-content"><a href="#" data-length="5">5</a><a href="#" data-length="10">10</a><a href="#" data-length="50">50</a><a href="#" data-length="100">100</a></div></div></label></div><table id="companyTable" class="table display mb-4 dataTablesCard dataTable table-responsive-xl card-table" ><thead><tr><th>Sno</th>6 unmodified lines<th>Delete</th></tr></thead></table></div></div>28 unmodified lines<label for="domain">Domain<span class="text-danger">*</span></label><input type="text" class="form-control" id="domain" name="domain" required></div><div class="form-group" ><label for="llm_tools">LLM Tools<span class="text-danger">*</span></label><select class="form-select" id="llm_tools" name="llm_tools[]" multiple required><option value="Database">Database</option><option value="Static Documents">Static Documents</option><option value="API">API</option></select><div class="invalid-feedback">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>18 unmodified linesconst company_id=sessionStorage.getItem('company_id');console.log('Current role:', role); // Debug statement to check the roledocument.getElementById('userRole').value = role;const passedCompanyName = sessionStorage.getItem('company_name')document.getElementById('selectedCompany').innerText = `Company Name: ${passedCompanyName}`;$('#addModal').hide(); // Make sure this is called initiallyfunction checkForAddButton() {const addButton = document.getElementById('add');if (addButton) {// Stop checking once the element is foundclearInterval(checkInterval);if (role === 'superadmin') {console.log("insidse compamy profile super admin");$('#startTable').show();$('#addModal').hide();$('#add').show();} else {console.log("insidse company profile admin");$('#add').hide();const modalTitle = document.getElementById('addModalLabel');modalTitle.textContent = 'Company Details';viewCompany(company_id);}}}const checkInterval = setInterval(checkForAddButton, 100); //document.querySelector('.dropdown-button').addEventListener('click', function() {const dropdownContent = document.querySelector('.dropdown-content');dropdownContent.style.display = dropdownContent.style.display === 'block' ? 'none' : 'block';});fetchCompanies();});window.addEventListener('click', function(event) {if (!event.target.matches('.dropdown-button')) {const dropdownContents = document.querySelectorAll('.dropdown-content');dropdownContents.forEach(function(content) {content.style.display = 'none';});}});window.addEventListener('pageshow', function (event) {if (event.persisted || (window.performance && window.performance.navigation.type === 2)) {window.location.reload();3 unmodified lines$(document).ready(function () {// Initialize DataTable//$('#companyTable').DataTable();$('#companyTable').DataTable({"paging": true,"pageLength":5,"lengthChange": false,"searching": true,"ordering": true,"info": true,"autoWidth": false,"responsive": true});// Initialize Select2$('select').select2({theme: 'bootstrap4',placeholder: 'Select',allowClear: true,dropdownParent: $('#addModal')});// 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$('#company_name').removeAttr('readonly');$('#company_code').removeAttr('readonly');$('#domain').removeAttr('readonly');$('select').prop('disabled', false);$('#username').removeAttr('readonly');$('#addModal').modal('show');$('#save').show();$('#saveupdate').hide();clearmodal();$('#save').prop('disabled', false); // Disable the "Save" button when the modal opens});$('.modal-footer .btn-secondary, .modal-header .close').on('click', function () {$('#addModal').modal('hide');});$('#addModal').on('shown.bs.modal', function() {$('#companyTable').DataTable().columns.adjust().draw();// Initialize Select2 only if not already initializedif (!$('#llm_tools').hasClass('select2-hidden-accessible')) {$('select').select2({theme: 'bootstrap4',placeholder: 'Select LLM Tools',allowClear: true,dropdownParent: $('#addModal')});}});$(document).on('click', '.btn-view', function () {const companyId = $(this).data('id');23 unmodified linesdeleteCompany(companyId); // Call the delete function with the company ID}});});// View company detailsfunction viewCompany(companyId) {const username = sessionStorage.getItem('username');const modalTitle = document.getElementById('addModalLabel');modalTitle.textContent = 'View Company Details';// Fetch company details by ID$.getJSON(`/api/getcompanydetails/${companyId}`, function (company) {console.log("Fetched company details:", company);// Set the company fields to readonly$('#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');$('select').val(company.llm_tools.split(',')).trigger('change');$('select').prop('disabled', true);$('#username').val(username).attr('readonly', 'readonly');// Show the modal$('#saveupdate').hide();$('#save').hide();$('#addModal').modal('show');}).fail(function () {console.error("Error retrieving company details.");});}// Edit company detailsfunction Editcompany(companyId) {const username=sessionStorage.getItem('username');const modalTitle = document.getElementById('addModalLabel');modalTitle.textContent = 'Edit Company Details';3 unmodified lines$('#company_name').removeAttr('readonly');$('#company_code').removeAttr('readonly');$('#domain').removeAttr('readonly');$('select').prop('disabled', false);$('#save').hide();$('#saveupdate').show();// Populate the form with the company's details$('#company_name').val(company.company_name);$('#company_code').val(company.company_code);$('#domain').val(company.domain);$('select').val(company.llm_tools.split(',')).trigger('change');$('#username').val(username).attr('readonly', 'readonly');// Disable the select input//sessionStorage.setItem('llmTools', company.llm_tools); // Store as a string33 unmodified lines}function saveupdate(companyId) {console.log("company_id", companyId);const llm_tools= $('#llm_tools').select2("val");var formData = new FormData();formData.append('company_name', $('#company_name').val());formData.append('company_code', $('#company_code').val());formData.append('domain', $('#domain').val());formData.append('llm_tools',llm_tools); // Assuming llm_tools is a multi-selectconsole.log("company_data", formData);$.ajax({url: `/api/putcompanydetails/${companyId}`,type: 'PUT',data: formData,processData: false, // Important for FormDatacontentType: false,success: function (response) {// alert('Company details updated successfully.');const messageContainer = document.getElementById('message-container');if (messageContainer)messageContainer.innerHTML = `<div class='alert alert-success'>Company Data Updated successfully3 unmodified linesfetchCompanies();},error: function () {const messageContainer = document.getElementById('message-container');if (messageContainer)messageContainer.innerHTML = `<div class='alert alert-danger'>No changes have been made to update company details.<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.');}});}function saveProfile() {const form = document.getElementById('companyForm');3 unmodified linesform.reportValidity();return;}// Gather form dataconst 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').select2("val");console.log("Selected LLM Tools:", llm_tools);// console.log("llm_tools element:", document.getElementById('llm_tools'));const username=$('#username').val();4 unmodified linesformData.append("company_name", company_name);formData.append("company_code", company_code);formData.append("domain", domain);formData.append("llm_tools", llm_tools);formData.append("username",username);formData.append("password",password);formData.append("role",rolesave);55 unmodified lines`<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>`])});table.draw(false);} catch (error) {console.error('Error fetching companies:', error);}}function clearmodal() {$('#companyForm')[0].reset(); // Reset all form fields$('#llm_tools').val(null).trigger('change'); // Clear and reset the Select2 field without reinitializing}document.querySelectorAll('.dropdown-content a').forEach(function(item) {item.addEventListener('click', function() {const length = item.getAttribute('data-length');// Set the DataTable page length$('#companyTable').DataTable().page.len(parseInt(length)).draw();document.querySelector('.dropdown-button').textContent = length;});});</script></body>
templates/company_profile.html+206-86