Spaces:
Runtime error
Runtime error
Update templates/company_profile.html
Browse files168 unmodified lines1691701711721731741751761771781 unmodified line18018118218318418518618718818919019119219353 unmodified lines24724824925025125211 unmodified lines26426526626726826927027127212 unmodified lines28528628728828929029129229329415 unmodified lines3103113123133143153165 unmodified lines3223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533547 unmodified lines36236336436536636736836919 unmodified lines3893903913923933943958 unmodified lines4044054064074084094108 unmodified lines4194204214224234244255 unmodified lines43143243343443543643713 unmodified lines4514524534544554564574584594604614624634648 unmodified lines47347447547647747847934 unmodified lines514515516517518519520168 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></div></div><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"><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"><thead><tr><th>Sno</th>53 unmodified linesPlease select at least one LLM tool.</div></div></form></div><div class="modal-footer">11 unmodified linesdocument.addEventListener('DOMContentLoaded', function () {const role = sessionStorage.getItem('userRole');console.log('Current role:', role); // Debug statement to checdocument.getElementById('add').style.display = 'block';fetchCompanies();});window.addEventListener('pageshow', function (event) {12 unmodified linesplaceholder: 'Select',allowClear: true});// Show modal function$('#add').on('click', function () {const modalTitle = document.getElementById('addModalLabel');modalTitle.textContent = 'Add Company Details';$('#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);editCompany(companyId);});// Delete company5 unmodified lines}});});// View company detailsfunction viewCompany(companyId) {// Fetch company details by IDconst 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.");});}// Edit company detailsfunction editCompany(companyId) {const modalTitle = document.getElementById('addModalLabel');modalTitle.textContent = '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');// Open the modal for editing$('#addModal').modal('show');// Update the save button to save the edited company19 unmodified linesmessageContainer.innerHTML = `<div class='alert alert-danger'>Company details deleted successfully.<button class='close' onclick='dismissMessage()'>OK</button></div>`;fetchCompanies(); // Refresh the table},8 unmodified linescompany_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};console.log("company_data", companyData);8 unmodified linesmessageContainer.innerHTML = `<div class='alert alert-success'>Company Data Updated successfully<button class='close' onclick='dismissMessage()'>OK</button></div>`;$('#addModal').modal('hide'); // Close the modal after savingfetchCompanies();5 unmodified linesmessageContainer.innerHTML = `<div class='alert alert-danger'>No changes have been made to update company details.<button class='close' onclick='dismissMessage()'>OK</button></div>`;$('#addModal').modal('hide');//alert('No changes have been made to update company details.');13 unmodified linesconst 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// Prepare FormDatalet formData = new FormData();formData.append("company_name", company_name);formData.append("company_code", company_code);formData.append("domain", domain);formData.append("llm_tools", llm_tools.join(','));$.ajax({type: "POST",8 unmodified linesmessageContainer.innerHTML = `<div class='alert alert-success'>Data saved successfully<button class='close' onclick='dismissMessage()'>OK</button></div>`;fetchCompanies(); // Refresh table data34 unmodified linescompany.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-danger btn-sm' onclick='deleteCompany(${company.company_id})'><i class='fas fa-trash'></i></a>`]).draw(false);168 unmodified lines1691701711721731741751761771781 unmodified line18018118218318418518618718818919019119253 unmodified lines24624724824925025125225325425511 unmodified lines26726826927027127227327427527627727827928028128228328428528628728828929029129212 unmodified lines30530630730830931031131231331431531631731815 unmodified lines3343353363373383393403413423433443453463475 unmodified lines3533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074087 unmodified lines41641741841942042142242342419 unmodified lines4444454464474484494508 unmodified lines4594604614624634644654668 unmodified lines4754764774784794804815 unmodified lines48748848949049149249313 unmodified lines5075085095105115125135145155165175185195205215225235245255265278 unmodified lines53653753853954054154234 unmodified lines577578579580581582583168 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></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" 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"><thead><tr><th>Sno</th>53 unmodified linesPlease 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 linesdocument.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 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) {12 unmodified linesplaceholder: '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);}});// Delete company5 unmodified lines}});// 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';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//sessionStorage.setItem('llmTools', company.llm_tools); // Store as a string$('#addModal').modal('show');// Update the save button to save the edited company19 unmodified linesmessageContainer.innerHTML = `<div class='alert alert-danger'>Company details deleted successfully.<button class='close' style='font-size:medium;margin-top:6px;' onclick='dismissMessage()'>OK</button></div>`;fetchCompanies(); // Refresh the table},8 unmodified linescompany_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);8 unmodified linesmessageContainer.innerHTML = `<div class='alert alert-success'>Company Data Updated successfully<button class='close' style='font-size:medium;margin-top:6px;' onclick='dismissMessage()'>OK</button></div>`;$('#addModal').modal('hide'); // Close the modal after savingfetchCompanies();5 unmodified linesmessageContainer.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.');13 unmodified linesconst 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();// Prepare FormDatalet 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 linesmessageContainer.innerHTML = `<div class='alert alert-success'>Data saved successfully<button class='close' style='font-size:medium;margin-top:6px;' onclick='dismissMessage()'>OK</button></div>`;fetchCompanies(); // Refresh table data34 unmodified linescompany.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-danger btn-sm' onclick='deleteCompany(${company.company_id})'><i class='fas fa-trash'></i></a>`]).draw(false);
templates/company_profile.html+100-37