Redmind commited on
Commit
e9d97c1
·
verified ·
1 Parent(s): 63d697f

Update templates/prompt_template.html

Browse files
Files changed (1) hide show
  1. templates/prompt_template.html +204 -191
templates/prompt_template.html CHANGED
@@ -18,15 +18,17 @@
18
  justify-content: space-between;
19
  align-items: center;
20
  }
 
21
  .card {
22
  padding: 0;
23
  margin-top: -15px;
24
  margin-left: -40px;
25
  }
 
26
  .table-container {
27
  width: 100%;
28
  overflow-x: auto;
29
-
30
  }
31
 
32
  .wrapper {
@@ -45,7 +47,7 @@
45
 
46
  }
47
 
48
- div.dataTables_wrapper div.dataTables_length select{
49
  width: 60px;
50
  display: inline-block;
51
  }
@@ -78,11 +80,13 @@
78
  /* view column*/
79
  width: 5%;
80
  }
 
81
  th:nth-child(5),
82
  td:nth-child(5) {
83
  /* view column*/
84
  width: 5%;
85
  }
 
86
  th:nth-child(6),
87
  td:nth-child(6) {
88
  /* view column*/
@@ -96,7 +100,8 @@
96
  .viewButton {
97
  size: 2px;
98
  }
99
- div.dataTables_wrapper div.dataTables_length select{
 
100
  width: 60px;
101
  display: inline-block;
102
  }
@@ -112,13 +117,17 @@
112
  <div class="content-header">
113
  <div class="container-fluid">
114
  <div class="container mt-2">
115
- <div class="form-group left-align">
116
- <label for="company" class="mr-1" style="margin-left:-60px;margin-top:-11px;">Company Name <span class="text-danger">*</span></label>
117
- <select type="text" id="company" name="company" class="form-control "style="width: 20%;margin-left:-60px;" required>
 
 
118
  <option value="" selected>Select</option>
119
- </select>
 
120
  <div class="col-12 d-flex justify-content-end mb-2">
121
- <button class="btn btn-primary" style="margin-top:-40px;margin-right: -25px;position: fixed;" id="add">Add</button>
 
122
 
123
  <!-- <button class="btn btn-primary" style="margin-top: 20px;" id="add">Add</button> -->
124
  </div>
@@ -136,6 +145,8 @@
136
  <input type="hidden" id="company_id" name="company_id" class="form-control" required>
137
  </div>
138
  </div>
 
 
139
  <!-- Main content-->
140
  <section class="content">
141
  <div class="container-fluid">
@@ -217,8 +228,6 @@
217
 
218
  </div>
219
 
220
-
221
-
222
  <!-- Modal -->
223
  <div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-labelledby="addModalLabel"
224
  aria-hidden="true">
@@ -250,7 +259,7 @@
250
  </form>
251
  </div>
252
  <div class="modal-footer">
253
- <button type="button" id="saveupdate" class="btn btn-primary" style="display: none;">Update</button>
254
  <!-- <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button> -->
255
  <button type="button" id="save" onclick="save_file()" class="btn btn-primary">Save</button>
256
  </div>
@@ -263,62 +272,58 @@
263
  <script src="https://cdn.datatables.net/1.10.25/js/jquery.dataTables.min.js"></script>
264
  <script src="https://cdn.datatables.net/1.10.25/js/dataTables.bootstrap4.min.js"></script>
265
  <script>
266
- $(document).ready(function () {
267
- $('#add').on('click', function () {
268
- const modalTitle = document.getElementById('addModalLabel');
269
- modalTitle.textContent = 'Add Prompt Template Details';
270
- $('#scenario').removeAttr('readonly');
271
- $('#prompt').removeAttr('readonly');
272
- $('#comments').removeAttr('readonly');
273
- $('#saveupdate').hide();
274
- $('#save').show();
275
- clearFormFields();
276
- $('#message-container').empty(); // Clear the message container
277
- $('#addModal').modal('show');
278
- });
279
- $('.modal-footer .btn-secondary, .modal-header .close').on('click', function () {
280
- $('#addModal').modal('hide');
281
- });
282
-
283
- });
284
- document.addEventListener("DOMContentLoaded", function () {
285
 
286
- // clearFormFields();
287
- fetchCompanies();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
288
 
289
  const companySelect = document.getElementById('company');
290
  const addPromptForm = document.getElementById('addPromptForm');
291
- const table = $('#promptTable').DataTable();
292
- // Initialize DataTable at the start
293
- companySelect.addEventListener('change', async function () {
294
- $("#message-container").empty();
295
- const selectedCompanyName = companySelect.options[companySelect.selectedIndex].text;
296
- console.log(`Selected Company Name: ${selectedCompanyName}`);
297
 
298
- if (selectedCompanyName !== "Select") {
299
 
300
- try {
301
- const response = await fetch(`/api/company_id?company_name=${encodeURIComponent(selectedCompanyName)}`);
302
- if (!response.ok) {
303
- contentSection.style.display = 'none';
304
- ("company id does not exist for name does not exist. Please fill in the details.");
305
- const messageContainer = document.getElementById('message-container');
306
- if (messageContainer) {
307
- messageContainer.innerHTML = "<div class='alert alert-danger'>Promptdetails do not exist for this company. Please fill in the details.</div>";
308
- }
309
- throw new Error('Network response was not ok');
310
- }
311
- const data = await response.json();
312
- console.log('data returned', data);
313
- console.log(`Company ID: ${data.company_id}`);
314
- const companyId = data.company_id;
315
- document.getElementById('company_id').value = companyId;
316
-
317
- if (companyId) {
318
  try {
319
- const Response = await fetch(`/api/get_prompt_templates?company_id=${companyId}&company_name=${selectedCompanyName}`);
 
320
  const connectorsResponse = await Response.json();
 
321
  console.log("prompt template data table after connecting to table", connectorsResponse);
 
322
  table.clear();
323
  if (!Array.isArray(connectorsResponse)) {
324
  throw new TypeError('Expected an array of companies');
@@ -356,44 +361,25 @@
356
 
357
  displayErrorMessage("Company id do not exist for this company. Please fill in the details by clicking add button.");
358
  }
359
- } catch (error) {
360
- console.error('No details for this company ID or data documents:', error);
361
- // displayEmptyTable();
362
-
363
- displayErrorMessage("Prompt details do not exist for this company. Please fill in the details.");
364
- contentSection.style.display = 'none';
365
- }
366
- } else {
367
 
368
- table.clear().draw();
369
- document.getElementById('contentSection').style.display = 'none';
370
- // Optionally, you might want to clear the form fields as well
371
- clearFormFields();
372
 
373
- }
374
- });
375
- function displayErrorMessage(message) {
376
- const messageContainer = document.getElementById('message-container');
377
- if (messageContainer) {
378
- messageContainer.innerHTML = `<div class='alert alert-danger'>${message}</div>`;
379
- }
380
- }
381
 
382
- });
383
- // Delete company
384
- function deleteCompany(button) {
385
  var companyId = $(button).data('kid-id');
386
- console.log("k_id deleted",companyId);
387
  $.ajax({
388
  type: "DELETE",
389
  url: `/api/prompt_template_for_del/${companyId}`,
390
  success: function () {
391
  var table = $('#promptTable').DataTable();
392
  table.row($(button).closest('tr')).remove().draw();
393
-
394
  //alert("Company deleted successfully.");
395
  const messageContainer = document.getElementById('message-container');
396
- if(messageContainer)
397
  messageContainer.innerHTML = `
398
  <div class='alert alert-danger'>
399
  Prompt details deleted successfully
@@ -411,12 +397,14 @@
411
  var companyId = $(button).data('kid-id');
412
  const modalTitle = document.getElementById('addModalLabel');
413
  modalTitle.textContent = 'View Prompt Template Details';
414
- console.log("view promt id (Rowid) ===> " , companyId)
 
 
415
  $.getJSON(`/api/getpromttemplate/${companyId}`, function (company) {
416
- console.log("view data scenario =====> ",company.scenario)
417
- console.log("view data prompt =====> ",company.prompt)
418
- console.log("view data comments =====> ",company.comments)
419
- $('#scenario').val(company.scenario).attr('readonly','readonly');
420
  $('#prompt').val(company.prompts).attr('readonly', 'readonly');
421
  $('#comments').val(company.comments).attr('readonly', 'readonly');
422
  $('#save').hide();// Disable the "Save" button when the modal opens
@@ -425,107 +413,111 @@
425
  }).fail(function () {
426
  alert("Error retrieving company details.");
427
  });
428
- }
 
429
  // Edit company details
430
 
431
- function editCompany(button) {
432
- var companyId = $(button).data('kid-id');
433
- const modalTitle = document.getElementById('addModalLabel');
434
- modalTitle.textContent = 'Edit Prompt Templates Details';
435
 
436
- console.info("company id ====#> ", companyId);
437
- $.getJSON(`/api/getpromttemplate/${companyId}`, function (company) {
438
- $('#scenario').val(company.scenario).removeAttr('readonly');
439
- $('#prompt').val(company.prompts).removeAttr('readonly');
440
- $('#comments').val(company.comments).removeAttr('readonly');
441
- $('#save').hide();
442
- $('#saveupdate').show();
 
 
443
 
444
- $('#addModal').modal('show');
445
 
446
- // Update the save button to save the edited company
447
- $('#saveupdate').off('click').on('click', function () {
448
- saveupdate(companyId); // Pass the company ID for updating
449
- });
450
- console.log(" edit process completed !")
451
- }).fail(function () {
452
- alert("Error retrieving company details.");
453
- });
454
- }
455
-
456
- // Save the updated details
457
- function saveupdate(companyId) {
458
- console.log("k_id for updating process _ id ! ..,..", companyId);
459
- const company_id=document.getElementById("company_id").value;
460
- var formData = new FormData();
461
- formData.append('scenario', $('#scenario').val());
462
- formData.append('prompt', $('#prompt').val());
463
- formData.append('comments', $('#comments').val());
464
- console.log("edited form data saved process begin ! ....", formData);
465
-
466
- $.ajax({
467
- url: `/api/putprompttemplates/${companyId}`,
468
- type: 'PUT',
469
- data: formData,
470
- processData: false, // Required for FormData
471
- contentType: false, // Required for FormData
472
- success: function (response) {
473
- // alert('Prompt details updated successfully.');
474
- const messageContainer = document.getElementById('message-container');
475
- if(messageContainer)
 
476
  messageContainer.innerHTML = `
477
  <div class='alert alert-success'>
478
  Prompt Data updated successfully
479
- <button class='close' onclick='dismissMessage()'>OK</button>
480
  </div>`;
481
- $('#addModal').modal('hide'); // Close the modal after saving
482
- fetchUpdatedDocuments(company_id);
483
- },
484
- error: function () {
485
- alert('Form has no changes to update prompt details.');
486
-      }
487
-     });
488
- }
489
- function dismissMessage() {
490
- const messageContainer = document.getElementById('message-container');
491
- if (messageContainer) {
492
- messageContainer.innerHTML = '';
493
- }
494
- }
495
- async function fetchUpdatedDocuments(company_id) {
496
- console.log("company_id",company_id);
497
- var table = $('#promptTable').DataTable();
498
- const Response = await fetch(`/api/prompt_update?company_id=${company_id}`);
499
- const connectorsResponse = await Response.json();
500
- console.log("prompt data table after connecting to table", connectorsResponse);
501
- table.clear();
502
- if (!Array.isArray(connectorsResponse) || connectorsResponse.length === 0) {
503
- //displayEmptyTable();
504
-
505
- displayErrorMessage("Promptdetails do not exist for this company. Please fill in the details.");
506
- contentSection.style.display = 'none';
507
- } else {
508
-
509
- connectorsResponse.forEach((company, index) => {
510
- table.row.add([
511
-
512
- index + 1,
513
- company.scenario,
514
- company.prompts,
515
- `<a href='#' class='btn btn-info btn-sm'data-kid-id='${company.id}' data-action="view" onclick='viewCompany(this)''><i class='fas fa-eye'></i></a>`,
516
- `<a href='#' class='btn btn-warning btn-sm'data-kid-id='${company.id}' data-action="edit" onclick='editCompany(this)'><i class='fas fa-edit'></i></a>`,
517
- //`<a href='#' class='btn btn-danger btn-sm' onclick='deleteCompany(${company.company_id})'><i class='fas fa-trash'></i></a>`,
518
- `<a href='#' class='btn btn-danger btn-sm' data-kid-id='${company.id}' onclick='deleteCompany(this)'><i class='fas fa-trash'></i></a>`,
519
- company.id
520
- // "<a href='#' class='btn btn-info btn-sm'><i class='fas fa-eye'></i></a>",
521
- // "<a href='#' class='btn btn-warning btn-sm'><i class='fas fa-edit'></i></a>",
522
- // "<a href='#' class='btn btn-danger btn-sm'><i class='fas fa-trash'></i></button>"
523
- ]).draw(false);
524
- });
525
- contentSection.style.display = 'block';
526
- }
527
- }
528
- function save_file() {
529
  const form = document.getElementById('addPromptForm');
530
 
531
  // Check if the form is valid
@@ -538,7 +530,7 @@ async function fetchUpdatedDocuments(company_id) {
538
  const scenario = $('#scenario').val();
539
  const prompt = $('#prompt').val();
540
  const comments = $('#comments').val();
541
-
542
  // const view = "<a href='#' class='btn btn-info btn-sm'><i class='fas fa-eye'></i></a>";
543
  // const edit = "<a href='#' class='btn btn-warning btn-sm'><i class='fas fa-edit'></i></a>";
544
  // const dele = "<a href='#' class='btn btn-danger btn-sm'><i class='fas fa-trash'></i></a>";
@@ -550,7 +542,7 @@ async function fetchUpdatedDocuments(company_id) {
550
  formData.append("prompt", prompt),
551
  formData.append("comments", comments),
552
 
553
- //const formData = new FormData();
554
  fetch('/api/save_prompt_details', {
555
  method: 'POST',
556
  body: formData
@@ -563,12 +555,12 @@ async function fetchUpdatedDocuments(company_id) {
563
  })
564
  .then(data => {
565
  const row_id = data.row_id;
566
- console.log("rowid",row_id);
567
  var table = $('#promptTable').DataTable();
568
  var rowCount = table.rows().count();
569
- const view=`<a href='#' class='btn btn-info btn-sm'data-kid-id='${row_id}' data-action="view" onclick='viewCompany(this)''><i class='fas fa-eye'></i></a>`;
570
- const edit=`<a href='#' class='btn btn-warning btn-sm'data-kid-id='${row_id}' data-action="edit" onclick='editCompany(this)'><i class='fas fa-edit'></i></a>`;
571
- const dele= `<a href='#' class='btn btn-danger btn-sm' data-kid-id='${row_id}' onclick='deleteCompany(this)'><i class='fas fa-trash'></i></a>`;
572
  table.row.add([
573
  rowCount + 1,
574
  scenario,
@@ -578,12 +570,12 @@ async function fetchUpdatedDocuments(company_id) {
578
  dele
579
  ]).draw(false);
580
 
581
- // const messageContainer = document.getElementById('message-container');
582
- if(messageContainer)
583
- messageContainer.innerHTML = `
584
  <div class='alert alert-success'>
585
  Data saved successfully
586
- <button class='close' onclick='dismissMessage()'>OK</button>
587
  </div>`;
588
  $('#addModal').modal('hide');
589
  document.getElementById('contentSection').style.display = 'block'; // Show the table section
@@ -619,6 +611,27 @@ async function fetchUpdatedDocuments(company_id) {
619
  document.getElementById('comments').value = "";
620
 
621
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
622
  </script>
623
  </body>
624
 
 
18
  justify-content: space-between;
19
  align-items: center;
20
  }
21
+
22
  .card {
23
  padding: 0;
24
  margin-top: -15px;
25
  margin-left: -40px;
26
  }
27
+
28
  .table-container {
29
  width: 100%;
30
  overflow-x: auto;
31
+
32
  }
33
 
34
  .wrapper {
 
47
 
48
  }
49
 
50
+ div.dataTables_wrapper div.dataTables_length select {
51
  width: 60px;
52
  display: inline-block;
53
  }
 
80
  /* view column*/
81
  width: 5%;
82
  }
83
+
84
  th:nth-child(5),
85
  td:nth-child(5) {
86
  /* view column*/
87
  width: 5%;
88
  }
89
+
90
  th:nth-child(6),
91
  td:nth-child(6) {
92
  /* view column*/
 
100
  .viewButton {
101
  size: 2px;
102
  }
103
+
104
+ div.dataTables_wrapper div.dataTables_length select {
105
  width: 60px;
106
  display: inline-block;
107
  }
 
117
  <div class="content-header">
118
  <div class="container-fluid">
119
  <div class="container mt-2">
120
+ <div class="form-group left-align" id="company-select">
121
+ <!-- <label for="company" class="mr-1" style="margin-left:-60px;margin-top:-11px;">Company Name
122
+ <span class="text-danger">*</span></label>
123
+ <select type="text" id="company" name="company" class="form-control "
124
+ style="width: 20%;margin-left:-60px;" required>
125
  <option value="" selected>Select</option>
126
+ </select> -->
127
+ <h4 id="selectedCompany" style="margin-left: 300px;"></h4>
128
  <div class="col-12 d-flex justify-content-end mb-2">
129
+ <button class="btn btn-primary"
130
+ style="margin-top:-40px;margin-right: -25px;position: fixed;" id="add">Add</button>
131
 
132
  <!-- <button class="btn btn-primary" style="margin-top: 20px;" id="add">Add</button> -->
133
  </div>
 
145
  <input type="hidden" id="company_id" name="company_id" class="form-control" required>
146
  </div>
147
  </div>
148
+
149
+
150
  <!-- Main content-->
151
  <section class="content">
152
  <div class="container-fluid">
 
228
 
229
  </div>
230
 
 
 
231
  <!-- Modal -->
232
  <div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-labelledby="addModalLabel"
233
  aria-hidden="true">
 
259
  </form>
260
  </div>
261
  <div class="modal-footer">
262
+ <button type="button" id="saveupdate" class="btn btn-primary" style="display: none;">Update</button>
263
  <!-- <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button> -->
264
  <button type="button" id="save" onclick="save_file()" class="btn btn-primary">Save</button>
265
  </div>
 
272
  <script src="https://cdn.datatables.net/1.10.25/js/jquery.dataTables.min.js"></script>
273
  <script src="https://cdn.datatables.net/1.10.25/js/dataTables.bootstrap4.min.js"></script>
274
  <script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
275
 
276
+ var table = $('#promptTable').DataTable();
277
+ const role = sessionStorage.getItem('userRole');
278
+ console.log('Current role:', role); // Debug statement to check the role
279
+ const passedCompanyName = sessionStorage.getItem('company_name')
280
+ document.getElementById('selectedCompany').innerText = `Company name: ${passedCompanyName}`;
281
+ const company_id = sessionStorage.getItem('company_id');
282
+ document.getElementById("company_id").value = company_id;
283
+
284
+ data_get_from_db(company_id);
285
+
286
+ // if (role === 'superadmin') {
287
+ // const storecompany_id = sessionStorage.getItem('company_id');
288
+ // data_get_from_db(storecompany_id);
289
+ // document.getElementById('company-select').style.display = 'block';
290
+ // //var companyId = getCookie('company_id')
291
+ // //console.log("company id for superadmin",storecompany_id);
292
+ // fetchCompanies();
293
+
294
+ // } else {
295
+ // document.getElementById('company-select').style.display = 'block';
296
+ // const storecompany_id = sessionStorage.getItem('company_id');
297
+ // console.log('Current company_id:', storecompany_id); // Debug statement to check the role
298
+ // data_get_from_db(storecompany_id);
299
+ // }
300
+
301
+ function moveToNextInput(inputs, currentIndex) {
302
+ const nextInput = inputs[currentIndex + 1];
303
+ if (nextInput) {
304
+ nextInput.focus();
305
+ } else {
306
+ // Optionally, submit the form or trigger the save button
307
+ document.getElementById("save").focus();
308
+ }
309
+ }
310
 
311
  const companySelect = document.getElementById('company');
312
  const addPromptForm = document.getElementById('addPromptForm');
 
 
 
 
 
 
313
 
314
+
315
 
316
+
317
+ async function data_get_from_db(companyId) {
318
+
319
+ if (companyId) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
320
  try {
321
+ const Response = await fetch(`/api/get_prompt_templates?company_id=${companyId}`);
322
+ console.log("responce from api :==> ", Response)
323
  const connectorsResponse = await Response.json();
324
+ console.log("knowledge data table after connecting to table", connectorsResponse);
325
  console.log("prompt template data table after connecting to table", connectorsResponse);
326
+ const table = $('#promptTable').DataTable(); // Initialize DataTable at the start
327
  table.clear();
328
  if (!Array.isArray(connectorsResponse)) {
329
  throw new TypeError('Expected an array of companies');
 
361
 
362
  displayErrorMessage("Company id do not exist for this company. Please fill in the details by clicking add button.");
363
  }
364
+
365
+ }
 
 
 
 
 
 
366
 
 
 
 
 
367
 
 
 
 
 
 
 
 
 
368
 
369
+ // Delete company
370
+ function deleteCompany(button) {
 
371
  var companyId = $(button).data('kid-id');
372
+ console.log("k_id deleted", companyId);
373
  $.ajax({
374
  type: "DELETE",
375
  url: `/api/prompt_template_for_del/${companyId}`,
376
  success: function () {
377
  var table = $('#promptTable').DataTable();
378
  table.row($(button).closest('tr')).remove().draw();
379
+
380
  //alert("Company deleted successfully.");
381
  const messageContainer = document.getElementById('message-container');
382
+ if (messageContainer)
383
  messageContainer.innerHTML = `
384
  <div class='alert alert-danger'>
385
  Prompt details deleted successfully
 
397
  var companyId = $(button).data('kid-id');
398
  const modalTitle = document.getElementById('addModalLabel');
399
  modalTitle.textContent = 'View Prompt Template Details';
400
+ console.log("view promt id (Rowid) ===> ", companyId)
401
+ if(companyId)
402
+ {
403
  $.getJSON(`/api/getpromttemplate/${companyId}`, function (company) {
404
+ console.log("view data scenario =====> ", company.scenario)
405
+ console.log("view data prompt =====> ", company.prompt)
406
+ console.log("view data comments =====> ", company.comments)
407
+ $('#scenario').val(company.scenario).attr('readonly', 'readonly');
408
  $('#prompt').val(company.prompts).attr('readonly', 'readonly');
409
  $('#comments').val(company.comments).attr('readonly', 'readonly');
410
  $('#save').hide();// Disable the "Save" button when the modal opens
 
413
  }).fail(function () {
414
  alert("Error retrieving company details.");
415
  });
416
+ }
417
+ }
418
  // Edit company details
419
 
420
+ function editCompany(button) {
421
+ var companyId = $(button).data('kid-id');
422
+ const modalTitle = document.getElementById('addModalLabel');
423
+ modalTitle.textContent = 'Edit Prompt Templates Details';
424
 
425
+ console.info("company id ====#> ", companyId);
426
+ if(companyId)
427
+ {
428
+ $.getJSON(`/api/getpromttemplate/${companyId}`, function (company) {
429
+ $('#scenario').val(company.scenario).removeAttr('readonly');
430
+ $('#prompt').val(company.prompts).removeAttr('readonly');
431
+ $('#comments').val(company.comments).removeAttr('readonly');
432
+ $('#save').hide();
433
+ $('#saveupdate').show();
434
 
435
+ $('#addModal').modal('show');
436
 
437
+ // Update the save button to save the edited company
438
+ $('#saveupdate').off('click').on('click', function () {
439
+ saveupdate(companyId); // Pass the company ID for updating
440
+ });
441
+ console.log(" edit process completed !")
442
+ }).fail(function () {
443
+ alert("Error retrieving company details.");
444
+ });
445
+ }
446
+ }
447
+
448
+ // Save the updated details
449
+ function saveupdate(companyId) {
450
+ console.log("k_id for updating process _ id ! ..,..", companyId);
451
+ const company_id = document.getElementById("company_id").value;
452
+ var formData = new FormData();
453
+ formData.append('scenario', $('#scenario').val());
454
+ formData.append('prompt', $('#prompt').val());
455
+ formData.append('comments', $('#comments').val());
456
+ console.log("edited form data saved process begin ! ....", formData);
457
+
458
+ $.ajax({
459
+ url: `/api/putprompttemplates/${companyId}`,
460
+ type: 'PUT',
461
+ data: formData,
462
+ processData: false, // Required for FormData
463
+ contentType: false, // Required for FormData
464
+ success: function (response) {
465
+ // alert('Prompt details updated successfully.');
466
+ const messageContainer = document.getElementById('message-container');
467
+ if (messageContainer)
468
  messageContainer.innerHTML = `
469
  <div class='alert alert-success'>
470
  Prompt Data updated successfully
471
+ <button class='close' style='font-size:medium;margin-top:6px;' onclick='dismissMessage()'>OK</button>
472
  </div>`;
473
+ $('#addModal').modal('hide'); // Close the modal after saving
474
+ fetchUpdatedDocuments(company_id);
475
+ },
476
+ error: function () {
477
+ alert('Form has no changes to update prompt details.');
478
+ }
479
+ });
480
+ }
481
+ function dismissMessage() {
482
+ const messageContainer = document.getElementById('message-container');
483
+ if (messageContainer) {
484
+ messageContainer.innerHTML = '';
485
+ }
486
+ }
487
+ async function fetchUpdatedDocuments(company_id) {
488
+ console.log("company_id", company_id);
489
+ var table = $('#promptTable').DataTable();
490
+ const Response = await fetch(`/api/prompt_update?company_id=${company_id}`);
491
+ const connectorsResponse = await Response.json();
492
+ console.log("prompt data table after connecting to table", connectorsResponse);
493
+ table.clear();
494
+ if (!Array.isArray(connectorsResponse) || connectorsResponse.length === 0) {
495
+ //displayEmptyTable();
496
+
497
+ displayErrorMessage("Promptdetails do not exist for this company. Please fill in the details.");
498
+ contentSection.style.display = 'none';
499
+ } else {
500
+
501
+ connectorsResponse.forEach((company, index) => {
502
+ table.row.add([
503
+
504
+ index + 1,
505
+ company.scenario,
506
+ company.prompts,
507
+ `<a href='#' class='btn btn-info btn-sm'data-kid-id='${company.id}' data-action="view" onclick='viewCompany(this)''><i class='fas fa-eye'></i></a>`,
508
+ `<a href='#' class='btn btn-warning btn-sm'data-kid-id='${company.id}' data-action="edit" onclick='editCompany(this)'><i class='fas fa-edit'></i></a>`,
509
+ //`<a href='#' class='btn btn-danger btn-sm' onclick='deleteCompany(${company.company_id})'><i class='fas fa-trash'></i></a>`,
510
+ `<a href='#' class='btn btn-danger btn-sm' data-kid-id='${company.id}' onclick='deleteCompany(this)'><i class='fas fa-trash'></i></a>`,
511
+ company.id
512
+ // "<a href='#' class='btn btn-info btn-sm'><i class='fas fa-eye'></i></a>",
513
+ // "<a href='#' class='btn btn-warning btn-sm'><i class='fas fa-edit'></i></a>",
514
+ // "<a href='#' class='btn btn-danger btn-sm'><i class='fas fa-trash'></i></button>"
515
+ ]).draw(false);
516
+ });
517
+ contentSection.style.display = 'block';
518
+ }
519
+ }
520
+ function save_file() {
521
  const form = document.getElementById('addPromptForm');
522
 
523
  // Check if the form is valid
 
530
  const scenario = $('#scenario').val();
531
  const prompt = $('#prompt').val();
532
  const comments = $('#comments').val();
533
+
534
  // const view = "<a href='#' class='btn btn-info btn-sm'><i class='fas fa-eye'></i></a>";
535
  // const edit = "<a href='#' class='btn btn-warning btn-sm'><i class='fas fa-edit'></i></a>";
536
  // const dele = "<a href='#' class='btn btn-danger btn-sm'><i class='fas fa-trash'></i></a>";
 
542
  formData.append("prompt", prompt),
543
  formData.append("comments", comments),
544
 
545
+ //const formData = new FormData();
546
  fetch('/api/save_prompt_details', {
547
  method: 'POST',
548
  body: formData
 
555
  })
556
  .then(data => {
557
  const row_id = data.row_id;
558
+ console.log("rowid", row_id);
559
  var table = $('#promptTable').DataTable();
560
  var rowCount = table.rows().count();
561
+ const view = `<a href='#' class='btn btn-info btn-sm'data-kid-id='${row_id}' data-action="view" onclick='viewCompany(this)''><i class='fas fa-eye'></i></a>`;
562
+ const edit = `<a href='#' class='btn btn-warning btn-sm'data-kid-id='${row_id}' data-action="edit" onclick='editCompany(this)'><i class='fas fa-edit'></i></a>`;
563
+ const dele = `<a href='#' class='btn btn-danger btn-sm' data-kid-id='${row_id}' onclick='deleteCompany(this)'><i class='fas fa-trash'></i></a>`;
564
  table.row.add([
565
  rowCount + 1,
566
  scenario,
 
570
  dele
571
  ]).draw(false);
572
 
573
+ // const messageContainer = document.getElementById('message-container');
574
+ if (messageContainer)
575
+ messageContainer.innerHTML = `
576
  <div class='alert alert-success'>
577
  Data saved successfully
578
+ <button class='close' style='font-size:medium;margin-top:6px;' onclick='dismissMessage()'>OK</button>
579
  </div>`;
580
  $('#addModal').modal('hide');
581
  document.getElementById('contentSection').style.display = 'block'; // Show the table section
 
611
  document.getElementById('comments').value = "";
612
 
613
  }
614
+
615
+
616
+ $(document).ready(function () {
617
+ $('#add').on('click', function () {
618
+ const modalTitle = document.getElementById('addModalLabel');
619
+ modalTitle.textContent = 'Add Prompt Template Details';
620
+ $('#scenario').removeAttr('readonly');
621
+ $('#prompt').removeAttr('readonly');
622
+ $('#comments').removeAttr('readonly');
623
+ $('#saveupdate').hide();
624
+ $('#save').show();
625
+ clearFormFields();
626
+ $('#message-container').empty(); // Clear the message container
627
+ $('#addModal').modal('show');
628
+ });
629
+ $('.modal-footer .btn-secondary, .modal-header .close').on('click', function () {
630
+ $('#addModal').modal('hide');
631
+ });
632
+
633
+ });
634
+
635
  </script>
636
  </body>
637