Spaces:
Sleeping
Sleeping
Update templates/company_profile.html
Browse files- templates/company_profile.html +206 -86
templates/company_profile.html
CHANGED
|
@@ -2,7 +2,8 @@
|
|
| 2 |
<html lang="en">
|
| 3 |
|
| 4 |
<head>
|
| 5 |
-
|
|
|
|
| 6 |
<title>Company Profile</title>
|
| 7 |
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
| 8 |
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
|
@@ -15,6 +16,12 @@
|
|
| 15 |
rel="stylesheet" />
|
| 16 |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css" />
|
| 17 |
<style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
body {
|
| 19 |
background-color: transparent !important;
|
| 20 |
}
|
|
@@ -24,6 +31,57 @@
|
|
| 24 |
margin-top: 10px;
|
| 25 |
margin-left: -50px;
|
| 26 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
.content-wrapper {
|
| 29 |
background-color: transparent !important;
|
|
@@ -45,8 +103,8 @@
|
|
| 45 |
|
| 46 |
|
| 47 |
.table-responsive {
|
| 48 |
-
width:
|
| 49 |
-
|
| 50 |
}
|
| 51 |
|
| 52 |
.table {
|
|
@@ -102,17 +160,17 @@
|
|
| 102 |
|
| 103 |
th:nth-child(3),
|
| 104 |
td:nth-child(3) {
|
| 105 |
-
width:
|
| 106 |
}
|
| 107 |
|
| 108 |
th:nth-child(4),
|
| 109 |
td:nth-child(4) {
|
| 110 |
-
width:
|
| 111 |
}
|
| 112 |
|
| 113 |
th:nth-child(5),
|
| 114 |
td:nth-child(5) {
|
| 115 |
-
width:
|
| 116 |
}
|
| 117 |
|
| 118 |
th:nth-child(6),
|
|
@@ -128,6 +186,7 @@
|
|
| 128 |
td:nth-child(8) {
|
| 129 |
width: 10%;
|
| 130 |
}
|
|
|
|
| 131 |
.alert {
|
| 132 |
position: relative;
|
| 133 |
padding: 15px;
|
|
@@ -169,11 +228,11 @@
|
|
| 169 |
<div class="content-header">
|
| 170 |
<div class="container-fluid">
|
| 171 |
<div class="row mb-2">
|
| 172 |
-
<div class="col-12">
|
| 173 |
<div class="col-12 d-flex justify-content-end mb-3">
|
| 174 |
<button class="btn btn-primary" style="margin-bottom:-30px;position:fixed" id="add">Add</button>
|
| 175 |
</div>
|
| 176 |
-
</div>
|
| 177 |
<input type="hidden" id="userRole" name="userRole" value={{role}}>
|
| 178 |
<div class="row">
|
| 179 |
<div id="message-container" style="margin-left: 200px;width:600px;"></div>
|
|
@@ -183,12 +242,27 @@
|
|
| 183 |
</div>
|
| 184 |
<!-- Main content -->
|
| 185 |
<section class="content" id="startTable" style="display: none;">
|
| 186 |
-
|
| 187 |
<div class="row">
|
| 188 |
<div class="col-12">
|
| 189 |
<div class="card">
|
| 190 |
<div class="card-body table-container">
|
| 191 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
<thead>
|
| 193 |
<tr>
|
| 194 |
<th>Sno</th>
|
|
@@ -201,8 +275,7 @@
|
|
| 201 |
<th>Delete</th>
|
| 202 |
</tr>
|
| 203 |
</thead>
|
| 204 |
-
|
| 205 |
-
</tbody>
|
| 206 |
</table>
|
| 207 |
</div>
|
| 208 |
</div>
|
|
@@ -237,17 +310,19 @@
|
|
| 237 |
<label for="domain">Domain<span class="text-danger">*</span></label>
|
| 238 |
<input type="text" class="form-control" id="domain" name="domain" required>
|
| 239 |
</div>
|
| 240 |
-
<div class="form-group">
|
| 241 |
<label for="llm_tools">LLM Tools<span class="text-danger">*</span></label>
|
| 242 |
-
<select class="form-
|
| 243 |
<option value="Database">Database</option>
|
| 244 |
<option value="Static Documents">Static Documents</option>
|
| 245 |
<option value="API">API</option>
|
| 246 |
</select>
|
|
|
|
| 247 |
<div class="invalid-feedback">
|
| 248 |
Please select at least one LLM tool.
|
| 249 |
</div>
|
| 250 |
</div>
|
|
|
|
| 251 |
<div class="form-group">
|
| 252 |
<label for="domain">UserName<span class="text-danger">*</span></label>
|
| 253 |
<input type="text" class="form-control" id="username" name="username" required>
|
|
@@ -272,25 +347,47 @@
|
|
| 272 |
const company_id=sessionStorage.getItem('company_id');
|
| 273 |
console.log('Current role:', role); // Debug statement to check the role
|
| 274 |
document.getElementById('userRole').value = role;
|
|
|
|
|
|
|
| 275 |
$('#addModal').hide(); // Make sure this is called initially
|
| 276 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 277 |
if (role === 'superadmin') {
|
| 278 |
console.log("insidse compamy profile super admin");
|
| 279 |
|
| 280 |
$('#startTable').show();
|
| 281 |
$('#addModal').hide();
|
| 282 |
-
|
| 283 |
-
|
|
|
|
| 284 |
} else {
|
| 285 |
console.log("insidse company profile admin");
|
| 286 |
-
|
| 287 |
const modalTitle = document.getElementById('addModalLabel');
|
| 288 |
modalTitle.textContent = 'Company Details';
|
| 289 |
viewCompany(company_id);
|
| 290 |
-
|
| 291 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 292 |
fetchCompanies();
|
| 293 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 294 |
window.addEventListener('pageshow', function (event) {
|
| 295 |
if (event.persisted || (window.performance && window.performance.navigation.type === 2)) {
|
| 296 |
window.location.reload();
|
|
@@ -300,31 +397,60 @@
|
|
| 300 |
|
| 301 |
$(document).ready(function () {
|
| 302 |
// Initialize DataTable
|
| 303 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 304 |
// Initialize Select2
|
| 305 |
-
$('
|
| 306 |
theme: 'bootstrap4',
|
| 307 |
placeholder: 'Select',
|
| 308 |
-
allowClear: true
|
|
|
|
| 309 |
});
|
| 310 |
-
|
| 311 |
-
});
|
| 312 |
// Show modal function
|
| 313 |
$('#add').on('click', function () {
|
| 314 |
const modalTitle = document.getElementById('addModalLabel');
|
| 315 |
modalTitle.textContent = 'Add Company Details';
|
| 316 |
console.log('Modal title after setting:', modalTitle.textContent); // This should log the new title
|
| 317 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 318 |
$('#addModal').modal('show');
|
| 319 |
$('#save').show();
|
| 320 |
$('#saveupdate').hide();
|
|
|
|
|
|
|
| 321 |
clearmodal();
|
| 322 |
$('#save').prop('disabled', false); // Disable the "Save" button when the modal opens
|
| 323 |
});
|
| 324 |
$('.modal-footer .btn-secondary, .modal-header .close').on('click', function () {
|
| 325 |
$('#addModal').modal('hide');
|
| 326 |
});
|
| 327 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 328 |
|
| 329 |
$(document).on('click', '.btn-view', function () {
|
| 330 |
const companyId = $(this).data('id');
|
|
@@ -354,53 +480,36 @@
|
|
| 354 |
deleteCompany(companyId); // Call the delete function with the company ID
|
| 355 |
}
|
| 356 |
});
|
| 357 |
-
|
| 358 |
// View company details
|
| 359 |
-
|
| 360 |
-
// Fetch company details by ID
|
| 361 |
const username = sessionStorage.getItem('username');
|
| 362 |
const modalTitle = document.getElementById('addModalLabel');
|
| 363 |
modalTitle.textContent = 'View Company Details';
|
| 364 |
|
|
|
|
| 365 |
$.getJSON(`/api/getcompanydetails/${companyId}`, function (company) {
|
| 366 |
-
|
|
|
|
|
|
|
| 367 |
$('#company_name').val(company.company_name).attr('readonly', 'readonly');
|
| 368 |
$('#company_code').val(company.company_code).attr('readonly', 'readonly');
|
| 369 |
$('#domain').val(company.domain).attr('readonly', 'readonly');
|
|
|
|
|
|
|
|
|
|
| 370 |
|
| 371 |
-
//
|
| 372 |
-
$('#llm_tools').empty();
|
| 373 |
-
|
| 374 |
-
// Add the options that are present in company.llm_tools
|
| 375 |
-
const availableOptions = {
|
| 376 |
-
'Database': 'Database',
|
| 377 |
-
'Static Documents': 'Static Documents',
|
| 378 |
-
'API': 'API'
|
| 379 |
-
};
|
| 380 |
-
|
| 381 |
-
if (Array.isArray(company.llm_tools)) {
|
| 382 |
-
company.llm_tools.forEach(tool => {
|
| 383 |
-
if (availableOptions[tool]) {
|
| 384 |
-
$('#llm_tools').append(new Option(availableOptions[tool], tool, true, true));
|
| 385 |
-
}
|
| 386 |
-
});
|
| 387 |
-
}
|
| 388 |
-
|
| 389 |
-
$('#llm_tools').prop('disabled', true); // Disable the dropdown
|
| 390 |
-
|
| 391 |
-
$('#username').val(username).attr('readonly', 'readonly'); // Set username field
|
| 392 |
-
|
| 393 |
-
// Show the modal with view details only
|
| 394 |
$('#saveupdate').hide();
|
| 395 |
$('#save').hide();
|
| 396 |
$('#addModal').modal('show');
|
| 397 |
}).fail(function () {
|
| 398 |
-
|
| 399 |
});
|
| 400 |
}
|
| 401 |
-
|
| 402 |
// Edit company details
|
| 403 |
function Editcompany(companyId) {
|
|
|
|
| 404 |
const username=sessionStorage.getItem('username');
|
| 405 |
const modalTitle = document.getElementById('addModalLabel');
|
| 406 |
modalTitle.textContent = 'Edit Company Details';
|
|
@@ -410,14 +519,14 @@
|
|
| 410 |
$('#company_name').removeAttr('readonly');
|
| 411 |
$('#company_code').removeAttr('readonly');
|
| 412 |
$('#domain').removeAttr('readonly');
|
| 413 |
-
$('
|
| 414 |
$('#save').hide();
|
| 415 |
$('#saveupdate').show();
|
| 416 |
// Populate the form with the company's details
|
| 417 |
$('#company_name').val(company.company_name);
|
| 418 |
$('#company_code').val(company.company_code);
|
| 419 |
$('#domain').val(company.domain);
|
| 420 |
-
$('
|
| 421 |
$('#username').val(username).attr('readonly', 'readonly');// Disable the select input
|
| 422 |
|
| 423 |
//sessionStorage.setItem('llmTools', company.llm_tools); // Store as a string
|
|
@@ -457,23 +566,25 @@
|
|
| 457 |
}
|
| 458 |
function saveupdate(companyId) {
|
| 459 |
console.log("company_id", companyId);
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
console.log("company_data",
|
| 468 |
|
| 469 |
$.ajax({
|
| 470 |
url: `/api/putcompanydetails/${companyId}`,
|
| 471 |
type: 'PUT',
|
| 472 |
-
data:
|
|
|
|
|
|
|
| 473 |
success: function (response) {
|
| 474 |
-
|
| 475 |
-
|
| 476 |
-
|
| 477 |
messageContainer.innerHTML = `
|
| 478 |
<div class='alert alert-success'>
|
| 479 |
Company Data Updated successfully
|
|
@@ -483,19 +594,20 @@
|
|
| 483 |
fetchCompanies();
|
| 484 |
},
|
| 485 |
error: function () {
|
| 486 |
-
|
| 487 |
-
|
| 488 |
-
|
| 489 |
messageContainer.innerHTML = `
|
| 490 |
<div class='alert alert-danger'>
|
| 491 |
No changes have been made to update company details.
|
| 492 |
<button class='close' style='font-size:medium;margin-top:6px;' onclick='dismissMessage()'>OK</button>
|
| 493 |
</div>`;
|
| 494 |
-
|
| 495 |
-
|
| 496 |
}
|
| 497 |
});
|
| 498 |
}
|
|
|
|
| 499 |
function saveProfile() {
|
| 500 |
const form = document.getElementById('companyForm');
|
| 501 |
|
|
@@ -505,11 +617,14 @@
|
|
| 505 |
form.reportValidity();
|
| 506 |
return;
|
| 507 |
}
|
|
|
|
| 508 |
// Gather form data
|
| 509 |
const company_name = document.getElementById('company_name').value;
|
| 510 |
const company_code = document.getElementById('company_code').value;
|
| 511 |
const domain = document.getElementById('domain').value;
|
| 512 |
-
const llm_tools = $('#llm_tools').val
|
|
|
|
|
|
|
| 513 |
const username=$('#username').val();
|
| 514 |
|
| 515 |
|
|
@@ -520,7 +635,7 @@
|
|
| 520 |
formData.append("company_name", company_name);
|
| 521 |
formData.append("company_code", company_code);
|
| 522 |
formData.append("domain", domain);
|
| 523 |
-
formData.append("llm_tools", llm_tools
|
| 524 |
formData.append("username",username);
|
| 525 |
formData.append("password",password);
|
| 526 |
formData.append("role",rolesave);
|
|
@@ -582,21 +697,26 @@
|
|
| 582 |
`<a href='#' class='btn btn-warning btn-sm'onclick='Editcompany(${company.company_id})'><i class='fas fa-edit'></i></a>`,
|
| 583 |
`<a href='#' class='btn btn-danger btn-sm' onclick='deleteCompany(${company.company_id})'><i class='fas fa-trash'></i></a>`
|
| 584 |
|
| 585 |
-
])
|
| 586 |
-
});
|
| 587 |
} catch (error) {
|
| 588 |
console.error('Error fetching companies:', error);
|
| 589 |
}
|
| 590 |
}
|
| 591 |
function clearmodal() {
|
| 592 |
-
|
| 593 |
-
|
| 594 |
-
|
| 595 |
-
|
| 596 |
-
|
| 597 |
-
|
| 598 |
-
|
| 599 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 600 |
|
| 601 |
</script>
|
| 602 |
</body>
|
|
|
|
| 2 |
<html lang="en">
|
| 3 |
|
| 4 |
<head>
|
| 5 |
+
<meta charset="UTF-8">
|
| 6 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 7 |
<title>Company Profile</title>
|
| 8 |
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
| 9 |
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
|
|
|
| 16 |
rel="stylesheet" />
|
| 17 |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css" />
|
| 18 |
<style>
|
| 19 |
+
|
| 20 |
+
#add {
|
| 21 |
+
display: inline-block ;
|
| 22 |
+
margin-right: 15px !important; /* Optional: Adjust margin if needed */
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
body {
|
| 26 |
background-color: transparent !important;
|
| 27 |
}
|
|
|
|
| 31 |
margin-top: 10px;
|
| 32 |
margin-left: -50px;
|
| 33 |
}
|
| 34 |
+
/* Ensure the DataTable wrapper takes the full width */
|
| 35 |
+
.dataTables_wrapper {
|
| 36 |
+
width: 100%;
|
| 37 |
+
}
|
| 38 |
+
/* Ensure the DataTable wrapper takes the full width */
|
| 39 |
+
.dataTables_wrapper {
|
| 40 |
+
width: 100%;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
/* Style for the custom dropdown */
|
| 46 |
+
.custom-dropdown {
|
| 47 |
+
position: relative;
|
| 48 |
+
display: inline-block;
|
| 49 |
+
margin-left: 10px; /* Space between label and dropdown */
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
.dropdown-button {
|
| 53 |
+
background-color: white;
|
| 54 |
+
color: black;
|
| 55 |
+
padding: 5px;
|
| 56 |
+
border: 1px solid black;
|
| 57 |
+
border-radius: 4px;
|
| 58 |
+
cursor: pointer;
|
| 59 |
+
text-align: left;
|
| 60 |
+
width: 60px; /* Adjust width as needed */
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
.dropdown-content {
|
| 64 |
+
display: none;
|
| 65 |
+
position: absolute;
|
| 66 |
+
background-color: #f9f9f9;
|
| 67 |
+
min-width: 80px; /* Adjust width as needed */
|
| 68 |
+
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
|
| 69 |
+
z-index: 1;
|
| 70 |
+
border: 1px solid #ddd;
|
| 71 |
+
top: 100%; /* Position below the button */
|
| 72 |
+
left: 0;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
.dropdown-content a {
|
| 76 |
+
padding: 10px;
|
| 77 |
+
text-decoration: none;
|
| 78 |
+
display: block;
|
| 79 |
+
color: #333;
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
.dropdown-content a:hover {
|
| 83 |
+
background-color: #ddd;
|
| 84 |
+
}
|
| 85 |
|
| 86 |
.content-wrapper {
|
| 87 |
background-color: transparent !important;
|
|
|
|
| 103 |
|
| 104 |
|
| 105 |
.table-responsive {
|
| 106 |
+
width: 95%;
|
| 107 |
+
overflow-x:none;
|
| 108 |
}
|
| 109 |
|
| 110 |
.table {
|
|
|
|
| 160 |
|
| 161 |
th:nth-child(3),
|
| 162 |
td:nth-child(3) {
|
| 163 |
+
width: 20%;
|
| 164 |
}
|
| 165 |
|
| 166 |
th:nth-child(4),
|
| 167 |
td:nth-child(4) {
|
| 168 |
+
width: 20%;
|
| 169 |
}
|
| 170 |
|
| 171 |
th:nth-child(5),
|
| 172 |
td:nth-child(5) {
|
| 173 |
+
width: 10%;
|
| 174 |
}
|
| 175 |
|
| 176 |
th:nth-child(6),
|
|
|
|
| 186 |
td:nth-child(8) {
|
| 187 |
width: 10%;
|
| 188 |
}
|
| 189 |
+
|
| 190 |
.alert {
|
| 191 |
position: relative;
|
| 192 |
padding: 15px;
|
|
|
|
| 228 |
<div class="content-header">
|
| 229 |
<div class="container-fluid">
|
| 230 |
<div class="row mb-2">
|
| 231 |
+
<!-- <div class="col-12">
|
| 232 |
<div class="col-12 d-flex justify-content-end mb-3">
|
| 233 |
<button class="btn btn-primary" style="margin-bottom:-30px;position:fixed" id="add">Add</button>
|
| 234 |
</div>
|
| 235 |
+
</div> -->
|
| 236 |
<input type="hidden" id="userRole" name="userRole" value={{role}}>
|
| 237 |
<div class="row">
|
| 238 |
<div id="message-container" style="margin-left: 200px;width:600px;"></div>
|
|
|
|
| 242 |
</div>
|
| 243 |
<!-- Main content -->
|
| 244 |
<section class="content" id="startTable" style="display: none;">
|
| 245 |
+
|
| 246 |
<div class="row">
|
| 247 |
<div class="col-12">
|
| 248 |
<div class="card">
|
| 249 |
<div class="card-body table-container">
|
| 250 |
+
<div class="dataTables_wrapper">
|
| 251 |
+
<div class="row">
|
| 252 |
+
<div class="dataTables_length" >
|
| 253 |
+
<label style="display: inline-block;margin-right:800px; margin-bottom: -40px;" >Show entries:
|
| 254 |
+
<div class="custom-dropdown">
|
| 255 |
+
<button class="dropdown-button">5</button>
|
| 256 |
+
<div class="dropdown-content">
|
| 257 |
+
<a href="#" data-length="5">5</a>
|
| 258 |
+
<a href="#" data-length="10">10</a>
|
| 259 |
+
<a href="#" data-length="50">50</a>
|
| 260 |
+
<a href="#" data-length="100">100</a>
|
| 261 |
+
</div>
|
| 262 |
+
</div>
|
| 263 |
+
</label>
|
| 264 |
+
</div>
|
| 265 |
+
<table id="companyTable" class="table display mb-4 dataTablesCard dataTable table-responsive-xl card-table" >
|
| 266 |
<thead>
|
| 267 |
<tr>
|
| 268 |
<th>Sno</th>
|
|
|
|
| 275 |
<th>Delete</th>
|
| 276 |
</tr>
|
| 277 |
</thead>
|
| 278 |
+
|
|
|
|
| 279 |
</table>
|
| 280 |
</div>
|
| 281 |
</div>
|
|
|
|
| 310 |
<label for="domain">Domain<span class="text-danger">*</span></label>
|
| 311 |
<input type="text" class="form-control" id="domain" name="domain" required>
|
| 312 |
</div>
|
| 313 |
+
<div class="form-group" >
|
| 314 |
<label for="llm_tools">LLM Tools<span class="text-danger">*</span></label>
|
| 315 |
+
<select class="form-select" id="llm_tools" name="llm_tools[]" multiple required>
|
| 316 |
<option value="Database">Database</option>
|
| 317 |
<option value="Static Documents">Static Documents</option>
|
| 318 |
<option value="API">API</option>
|
| 319 |
</select>
|
| 320 |
+
|
| 321 |
<div class="invalid-feedback">
|
| 322 |
Please select at least one LLM tool.
|
| 323 |
</div>
|
| 324 |
</div>
|
| 325 |
+
|
| 326 |
<div class="form-group">
|
| 327 |
<label for="domain">UserName<span class="text-danger">*</span></label>
|
| 328 |
<input type="text" class="form-control" id="username" name="username" required>
|
|
|
|
| 347 |
const company_id=sessionStorage.getItem('company_id');
|
| 348 |
console.log('Current role:', role); // Debug statement to check the role
|
| 349 |
document.getElementById('userRole').value = role;
|
| 350 |
+
const passedCompanyName = sessionStorage.getItem('company_name')
|
| 351 |
+
document.getElementById('selectedCompany').innerText = `Company Name: ${passedCompanyName}`;
|
| 352 |
$('#addModal').hide(); // Make sure this is called initially
|
| 353 |
+
function checkForAddButton() {
|
| 354 |
+
const addButton = document.getElementById('add');
|
| 355 |
+
|
| 356 |
+
if (addButton) {
|
| 357 |
+
// Stop checking once the element is found
|
| 358 |
+
clearInterval(checkInterval);
|
| 359 |
if (role === 'superadmin') {
|
| 360 |
console.log("insidse compamy profile super admin");
|
| 361 |
|
| 362 |
$('#startTable').show();
|
| 363 |
$('#addModal').hide();
|
| 364 |
+
$('#add').show();
|
| 365 |
+
|
| 366 |
+
|
| 367 |
} else {
|
| 368 |
console.log("insidse company profile admin");
|
| 369 |
+
$('#add').hide();
|
| 370 |
const modalTitle = document.getElementById('addModalLabel');
|
| 371 |
modalTitle.textContent = 'Company Details';
|
| 372 |
viewCompany(company_id);
|
|
|
|
| 373 |
}
|
| 374 |
+
}
|
| 375 |
+
}
|
| 376 |
+
const checkInterval = setInterval(checkForAddButton, 100); //
|
| 377 |
+
document.querySelector('.dropdown-button').addEventListener('click', function() {
|
| 378 |
+
const dropdownContent = document.querySelector('.dropdown-content');
|
| 379 |
+
dropdownContent.style.display = dropdownContent.style.display === 'block' ? 'none' : 'block';
|
| 380 |
+
});
|
| 381 |
fetchCompanies();
|
| 382 |
});
|
| 383 |
+
window.addEventListener('click', function(event) {
|
| 384 |
+
if (!event.target.matches('.dropdown-button')) {
|
| 385 |
+
const dropdownContents = document.querySelectorAll('.dropdown-content');
|
| 386 |
+
dropdownContents.forEach(function(content) {
|
| 387 |
+
content.style.display = 'none';
|
| 388 |
+
});
|
| 389 |
+
}
|
| 390 |
+
});
|
| 391 |
window.addEventListener('pageshow', function (event) {
|
| 392 |
if (event.persisted || (window.performance && window.performance.navigation.type === 2)) {
|
| 393 |
window.location.reload();
|
|
|
|
| 397 |
|
| 398 |
$(document).ready(function () {
|
| 399 |
// Initialize DataTable
|
| 400 |
+
//$('#companyTable').DataTable();
|
| 401 |
+
$('#companyTable').DataTable({
|
| 402 |
+
|
| 403 |
+
"paging": true,
|
| 404 |
+
"pageLength":5,
|
| 405 |
+
"lengthChange": false,
|
| 406 |
+
"searching": true,
|
| 407 |
+
"ordering": true,
|
| 408 |
+
"info": true,
|
| 409 |
+
"autoWidth": false,
|
| 410 |
+
"responsive": true
|
| 411 |
+
});
|
| 412 |
+
|
| 413 |
// Initialize Select2
|
| 414 |
+
$('select').select2({
|
| 415 |
theme: 'bootstrap4',
|
| 416 |
placeholder: 'Select',
|
| 417 |
+
allowClear: true,
|
| 418 |
+
dropdownParent: $('#addModal')
|
| 419 |
});
|
| 420 |
+
|
|
|
|
| 421 |
// Show modal function
|
| 422 |
$('#add').on('click', function () {
|
| 423 |
const modalTitle = document.getElementById('addModalLabel');
|
| 424 |
modalTitle.textContent = 'Add Company Details';
|
| 425 |
console.log('Modal title after setting:', modalTitle.textContent); // This should log the new title
|
| 426 |
+
$('#company_name').removeAttr('readonly');
|
| 427 |
+
$('#company_code').removeAttr('readonly');
|
| 428 |
+
$('#domain').removeAttr('readonly');
|
| 429 |
+
$('select').prop('disabled', false);
|
| 430 |
+
$('#username').removeAttr('readonly');
|
| 431 |
$('#addModal').modal('show');
|
| 432 |
$('#save').show();
|
| 433 |
$('#saveupdate').hide();
|
| 434 |
+
|
| 435 |
+
|
| 436 |
clearmodal();
|
| 437 |
$('#save').prop('disabled', false); // Disable the "Save" button when the modal opens
|
| 438 |
});
|
| 439 |
$('.modal-footer .btn-secondary, .modal-header .close').on('click', function () {
|
| 440 |
$('#addModal').modal('hide');
|
| 441 |
});
|
| 442 |
+
$('#addModal').on('shown.bs.modal', function() {
|
| 443 |
+
$('#companyTable').DataTable().columns.adjust().draw();
|
| 444 |
+
// Initialize Select2 only if not already initialized
|
| 445 |
+
if (!$('#llm_tools').hasClass('select2-hidden-accessible')) {
|
| 446 |
+
$('select').select2({
|
| 447 |
+
theme: 'bootstrap4',
|
| 448 |
+
placeholder: 'Select LLM Tools',
|
| 449 |
+
allowClear: true,
|
| 450 |
+
dropdownParent: $('#addModal')
|
| 451 |
+
});
|
| 452 |
+
}
|
| 453 |
+
});
|
| 454 |
|
| 455 |
$(document).on('click', '.btn-view', function () {
|
| 456 |
const companyId = $(this).data('id');
|
|
|
|
| 480 |
deleteCompany(companyId); // Call the delete function with the company ID
|
| 481 |
}
|
| 482 |
});
|
| 483 |
+
});
|
| 484 |
// View company details
|
| 485 |
+
function viewCompany(companyId) {
|
|
|
|
| 486 |
const username = sessionStorage.getItem('username');
|
| 487 |
const modalTitle = document.getElementById('addModalLabel');
|
| 488 |
modalTitle.textContent = 'View Company Details';
|
| 489 |
|
| 490 |
+
// Fetch company details by ID
|
| 491 |
$.getJSON(`/api/getcompanydetails/${companyId}`, function (company) {
|
| 492 |
+
console.log("Fetched company details:", company);
|
| 493 |
+
|
| 494 |
+
// Set the company fields to readonly
|
| 495 |
$('#company_name').val(company.company_name).attr('readonly', 'readonly');
|
| 496 |
$('#company_code').val(company.company_code).attr('readonly', 'readonly');
|
| 497 |
$('#domain').val(company.domain).attr('readonly', 'readonly');
|
| 498 |
+
$('select').val(company.llm_tools.split(',')).trigger('change');
|
| 499 |
+
$('select').prop('disabled', true);
|
| 500 |
+
$('#username').val(username).attr('readonly', 'readonly');
|
| 501 |
|
| 502 |
+
// Show the modal
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 503 |
$('#saveupdate').hide();
|
| 504 |
$('#save').hide();
|
| 505 |
$('#addModal').modal('show');
|
| 506 |
}).fail(function () {
|
| 507 |
+
console.error("Error retrieving company details.");
|
| 508 |
});
|
| 509 |
}
|
|
|
|
| 510 |
// Edit company details
|
| 511 |
function Editcompany(companyId) {
|
| 512 |
+
|
| 513 |
const username=sessionStorage.getItem('username');
|
| 514 |
const modalTitle = document.getElementById('addModalLabel');
|
| 515 |
modalTitle.textContent = 'Edit Company Details';
|
|
|
|
| 519 |
$('#company_name').removeAttr('readonly');
|
| 520 |
$('#company_code').removeAttr('readonly');
|
| 521 |
$('#domain').removeAttr('readonly');
|
| 522 |
+
$('select').prop('disabled', false);
|
| 523 |
$('#save').hide();
|
| 524 |
$('#saveupdate').show();
|
| 525 |
// Populate the form with the company's details
|
| 526 |
$('#company_name').val(company.company_name);
|
| 527 |
$('#company_code').val(company.company_code);
|
| 528 |
$('#domain').val(company.domain);
|
| 529 |
+
$('select').val(company.llm_tools.split(',')).trigger('change');
|
| 530 |
$('#username').val(username).attr('readonly', 'readonly');// Disable the select input
|
| 531 |
|
| 532 |
//sessionStorage.setItem('llmTools', company.llm_tools); // Store as a string
|
|
|
|
| 566 |
}
|
| 567 |
function saveupdate(companyId) {
|
| 568 |
console.log("company_id", companyId);
|
| 569 |
+
const llm_tools= $('#llm_tools').select2("val");
|
| 570 |
+
var formData = new FormData();
|
| 571 |
+
formData.append('company_name', $('#company_name').val());
|
| 572 |
+
formData.append('company_code', $('#company_code').val());
|
| 573 |
+
formData.append('domain', $('#domain').val());
|
| 574 |
+
formData.append('llm_tools',llm_tools); // Assuming llm_tools is a multi-select
|
| 575 |
+
|
| 576 |
+
console.log("company_data", formData);
|
| 577 |
|
| 578 |
$.ajax({
|
| 579 |
url: `/api/putcompanydetails/${companyId}`,
|
| 580 |
type: 'PUT',
|
| 581 |
+
data: formData,
|
| 582 |
+
processData: false, // Important for FormData
|
| 583 |
+
contentType: false,
|
| 584 |
success: function (response) {
|
| 585 |
+
// alert('Company details updated successfully.');
|
| 586 |
+
const messageContainer = document.getElementById('message-container');
|
| 587 |
+
if (messageContainer)
|
| 588 |
messageContainer.innerHTML = `
|
| 589 |
<div class='alert alert-success'>
|
| 590 |
Company Data Updated successfully
|
|
|
|
| 594 |
fetchCompanies();
|
| 595 |
},
|
| 596 |
error: function () {
|
| 597 |
+
|
| 598 |
+
const messageContainer = document.getElementById('message-container');
|
| 599 |
+
if (messageContainer)
|
| 600 |
messageContainer.innerHTML = `
|
| 601 |
<div class='alert alert-danger'>
|
| 602 |
No changes have been made to update company details.
|
| 603 |
<button class='close' style='font-size:medium;margin-top:6px;' onclick='dismissMessage()'>OK</button>
|
| 604 |
</div>`;
|
| 605 |
+
$('#addModal').modal('hide');
|
| 606 |
+
//alert('No changes have been made to update company details.');
|
| 607 |
}
|
| 608 |
});
|
| 609 |
}
|
| 610 |
+
|
| 611 |
function saveProfile() {
|
| 612 |
const form = document.getElementById('companyForm');
|
| 613 |
|
|
|
|
| 617 |
form.reportValidity();
|
| 618 |
return;
|
| 619 |
}
|
| 620 |
+
|
| 621 |
// Gather form data
|
| 622 |
const company_name = document.getElementById('company_name').value;
|
| 623 |
const company_code = document.getElementById('company_code').value;
|
| 624 |
const domain = document.getElementById('domain').value;
|
| 625 |
+
const llm_tools = $('#llm_tools').select2("val");
|
| 626 |
+
console.log("Selected LLM Tools:", llm_tools);
|
| 627 |
+
// console.log("llm_tools element:", document.getElementById('llm_tools'));
|
| 628 |
const username=$('#username').val();
|
| 629 |
|
| 630 |
|
|
|
|
| 635 |
formData.append("company_name", company_name);
|
| 636 |
formData.append("company_code", company_code);
|
| 637 |
formData.append("domain", domain);
|
| 638 |
+
formData.append("llm_tools", llm_tools);
|
| 639 |
formData.append("username",username);
|
| 640 |
formData.append("password",password);
|
| 641 |
formData.append("role",rolesave);
|
|
|
|
| 697 |
`<a href='#' class='btn btn-warning btn-sm'onclick='Editcompany(${company.company_id})'><i class='fas fa-edit'></i></a>`,
|
| 698 |
`<a href='#' class='btn btn-danger btn-sm' onclick='deleteCompany(${company.company_id})'><i class='fas fa-trash'></i></a>`
|
| 699 |
|
| 700 |
+
])
|
| 701 |
+
});table.draw(false);
|
| 702 |
} catch (error) {
|
| 703 |
console.error('Error fetching companies:', error);
|
| 704 |
}
|
| 705 |
}
|
| 706 |
function clearmodal() {
|
| 707 |
+
$('#companyForm')[0].reset(); // Reset all form fields
|
| 708 |
+
$('#llm_tools').val(null).trigger('change'); // Clear and reset the Select2 field without reinitializing
|
| 709 |
+
}
|
| 710 |
+
|
| 711 |
+
document.querySelectorAll('.dropdown-content a').forEach(function(item) {
|
| 712 |
+
item.addEventListener('click', function() {
|
| 713 |
+
const length = item.getAttribute('data-length');
|
| 714 |
+
// Set the DataTable page length
|
| 715 |
+
$('#companyTable').DataTable().page.len(parseInt(length)).draw();
|
| 716 |
+
document.querySelector('.dropdown-button').textContent = length;
|
| 717 |
+
});
|
| 718 |
+
});
|
| 719 |
+
|
| 720 |
|
| 721 |
</script>
|
| 722 |
</body>
|