You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1807 lines
75 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <!DOCTYPE html>
  2. <html lang="en" xmlns:th="http://www.thymeleaf.org">
  3. <head th:replace="~{fragments/modules/base/head :: head}"></head>
  4. <style>
  5. .custom-width1 {
  6. width: 140px; /* Adjust the width as needed */
  7. }
  8. .custom-width2 {
  9. width: 200px; /* Adjust the width as needed */
  10. }
  11. .custom-width3 {
  12. width: 100px;
  13. }
  14. table td {
  15. text-align: center;
  16. }
  17. #campaignTable {
  18. display: none;
  19. }
  20. .modal-body {
  21. max-height: 70vh;
  22. overflow-y: auto; /* Enables vertical scrolling */
  23. overflow-x: hidden; /* Hides horizontal scrolling */
  24. padding-right: 15px; /* Prevents content cutoff */
  25. }
  26. </style>
  27. <body>
  28. <!--[if lt IE 8]>
  29. <p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
  30. <![endif]-->
  31. <div class="wrapper">
  32. <!-- header top menu Start -->
  33. <header th:replace="~{fragments/modules/base/header :: header}"></header>
  34. <!-- header top menu end -->
  35. <div class="page-wrap">
  36. <!--=============== Left Menu side Start ================-->
  37. <div th:replace="~{fragments/modules/base/menu :: menu}"></div>
  38. <!--=============== Left side End ================-->
  39. <div class="main-content">
  40. <div class="container-fluid">
  41. <div class="page-header mb-2">
  42. <div class="row align-items-end">
  43. <div class="col-lg-8">
  44. <div class="page-header-title">
  45. <i class="fas fa-headset bg-blue"></i>
  46. <div class="d-inline">
  47. <h5>Agent's Campaign</h5>
  48. <span>1913 Agent's Campaign</span>
  49. </div>
  50. </div>
  51. </div>
  52. <div class="col-lg-4">
  53. <nav class="breadcrumb-container" aria-label="breadcrumb">
  54. <ol class="breadcrumb">
  55. <li class="breadcrumb-item"><a href="/gcc/index"><i
  56. class="ik ik-home"></i></a></li>
  57. <li class="breadcrumb-item" aria-current="page">1913
  58. Campaign</li>
  59. <li class="breadcrumb-item active" aria-current="page">Agents
  60. Campaign</li>
  61. </ol>
  62. </nav>
  63. </div>
  64. </div>
  65. </div>
  66. <h4 class="h4 text-right text-mute" style="font-size: 12px;">
  67. Auto refresh in <font id="refresh-countdown">00</font> seconds
  68. </h4>
  69. <div class="row">
  70. <div class="col-md-12 mt-2">
  71. <div class="card">
  72. <div class="card-block">
  73. <div class="page-header-title">
  74. <h4 style="margin: 0; font-weight: bold;" class="text-center">
  75. <span th:text="${agent_name}"></span>' s Campaign
  76. </h4>
  77. <div
  78. class="mt-2 d-flex justify-content-between align-items-center">
  79. <h5 style="margin: 0; font-weight: bold; font-style: italic;">Campaign
  80. List</h5>
  81. <button type="button" class="btn btn-primary" id="refresh">
  82. <i class="ik ik-refresh-ccw"></i>Refresh
  83. </button>
  84. </div>
  85. <hr>
  86. </div>
  87. <div>
  88. <table id="Agenttask"
  89. class="table table-striped table-bordered table-hover dataTable"
  90. role="grid" style="width: 99%;">
  91. <thead class="thead-dark">
  92. <tr role="row">
  93. <th class="text-center no-sort">S.No</th>
  94. <th class="text-center">Category</th>
  95. <th class="text-center">CampaignName</th>
  96. <th class="text-center">Calls Assigned</th>
  97. <th class="text-center">Calls Completed</th>
  98. <th class="text-center">Calls Pending</th>
  99. <!-- <th class="text-center">C Date</th> -->
  100. </tr>
  101. </thead>
  102. <tbody>
  103. <tr th:each="agentsCampaign, iterStat : ${agentsCampaigns}">
  104. <td th:text="${iterStat.index + 1}" class="text-center"></td>
  105. <!-- Serial number -->
  106. <td th:text="${agentsCampaign['category_name']}"
  107. class="text-center"></td>
  108. <!-- Category name -->
  109. <td th:text="${agentsCampaign['campaign_name']}"
  110. class="text-center"></td>
  111. <!-- Campaign name -->
  112. <td th:text="${agentsCampaign['calls_assigned']}"
  113. class="text-center"></td>
  114. <td th:text="${agentsCampaign['complete_count']}"
  115. class="text-center"></td>
  116. <td th:text="${agentsCampaign['pending_count']}"
  117. class="text-center"></td>
  118. <!-- <td th:text="${agentsCampaign['created_date']}" class="text-center"></td> -->
  119. </tr>
  120. </tbody>
  121. </table>
  122. </div>
  123. </div>
  124. </div>
  125. </div>
  126. <div class="col-md-12" id="tablesforcalls" style="display: block;">
  127. <div class="card">
  128. <div class="card-block">
  129. <div class="page-header-title">
  130. <div class="col-md-12">
  131. <div class="row">
  132. <button id="primaryButton" class="btn btn-success">Non-Processed
  133. Calls</button>
  134. <button id="secondaryButton"
  135. class="btn btn-secondary btn-custom ml-3">Processed
  136. Calls</button>
  137. </div>
  138. </div>
  139. <hr>
  140. </div>
  141. <div>
  142. <div class="table-responsive" id="primaryTable"
  143. style="display: block;">
  144. <table id="AgentDatatable"
  145. class="table table-bordered table-hover dataTable"
  146. role="grid">
  147. <thead class="thead-dark">
  148. <tr role="row">
  149. <th>S.No</th>
  150. <th class="text-center">Name</th>
  151. <th class="text-center">MobileNumber</th>
  152. <th class="text-center">ViewDetails</th>
  153. <th class="text-center custom-width1">Callstatus</th>
  154. <th class="text-center custom-width2">Remarks</th>
  155. <th class="text-center">Submit</th>
  156. </tr>
  157. </thead>
  158. <tbody>
  159. <!-- Loop through the agentsCampaignsList -->
  160. <th:block th:each="item, stat : ${agentsCampaignsList}">
  161. <tr>
  162. <td th:text="${stat.index + 1}"></td>
  163. <!-- S.No (Index + 1) -->
  164. <td class="text-center" th:text="${item.field_1}"></td>
  165. <!-- Name -->
  166. <td class="text-center" th:text="${item.field_2}"></td>
  167. <!-- Address -->
  168. <!-- View Details Button -->
  169. <!-- <td class="text-center">
  170. <button class="btn btn-primary">View</button>
  171. </td>-->
  172. <!-- View Details Button -->
  173. <td class="text-center">
  174. <button class="btn btn-primary view-details"
  175. th:data-categoryid="${item.category_id}"
  176. th:data-campaignid="${item.campaign_id}"
  177. th:data-agentid="${item.agent_id}"
  178. th:data-dataid="${item.data_id}" data-toggle="modal"
  179. data-target="#campaignModal">View</button>
  180. </td>
  181. <!-- <td class="text-center">
  182. <button class="btn btn-primary questionview-details"
  183. th:data-categoryid="${item.category_id}"
  184. th:data-cmpaignid="${item.campaign_id}"
  185. th:data-agentid="${item.agent_id}"
  186. th:data-dataid="${item.data_id}"
  187. data-toggle="modal"
  188. data-target="#questionCampaignView">
  189. View
  190. </button>
  191. </td>-->
  192. <!-- Action Dropdown -->
  193. <td class="text-center"><select
  194. class="form-control action-dropdown"
  195. th:id="'callStatusDropdown-' + ${stat.index}"
  196. name="action">
  197. <option value="">Select Call Status</option>
  198. </select></td>
  199. <!-- <td class="text-center"><select
  200. class="form-control form-control-sm action-select action-dropdown">
  201. <option value="Select Call Status" selected>Select Call Status</option>
  202. <option th:each="status : ${CampActions}"
  203. th:value="${status.call_status}"
  204. th:text="${status.call_status}"></option>
  205. </select>
  206. </td> -->
  207. <!-- Remarks Textarea -->
  208. <td class="text-center"><textarea
  209. class="form-control" name="remarks" id="remarks"
  210. th:text="${item.remarks}"></textarea></td>
  211. <td class="text-center">
  212. <button class="btn btn-primary submit-button submitid"
  213. th:id="'submit-btn-' + ${stat.index}"
  214. th:data-categoryid="${item.category_id}"
  215. th:data-campaignid="${item.campaign_id}"
  216. th:data-agentid="${item.agent_id}"
  217. th:data-dataid="${item.data_id}"
  218. th:onclick="|submitAction('${item.data_id}', '${stat.index}', '${item.agent_id}', '${item.campaign_id}')|">
  219. Submit</button>
  220. </td>
  221. </tr>
  222. </th:block>
  223. </tbody>
  224. </table>
  225. </div>
  226. </div>
  227. <div class="table-responsive" id="secondaryTable"
  228. style="display: none;">
  229. <table id="AgentDatatable1"
  230. class="table table-bordered table-hover dataTable"
  231. role="grid">
  232. <thead class="thead-dark">
  233. <tr role="row">
  234. <th>S.No</th>
  235. <th class="text-center">Name</th>
  236. <th class="text-center">MobileNumber</th>
  237. <th class="text-center">ViewDetails</th>
  238. <th class="text-center custom-width1">Callstatus</th>
  239. <th class="text-center custom-width2">Remarks</th>
  240. </tr>
  241. </thead>
  242. <tbody>
  243. <!-- Loop through the agentsCampaignsList -->
  244. <th:block th:each="item, stat : ${agentsCampaignsList1}">
  245. <tr>
  246. <td th:text="${stat.index + 1}"></td>
  247. <!-- S.No (Index + 1) -->
  248. <td class="text-center" th:text="${item.field_1}"></td>
  249. <!-- Name -->
  250. <td class="text-center" th:text="${item.field_2}"></td>
  251. <!-- Address -->
  252. <td class="text-center">
  253. <button class="btn btn-primary view-details1"
  254. th:data-categoryid="${item.category_id}"
  255. th:data-campaignid="${item.campaign_id}"
  256. th:data-agentid="${item.agent_id}"
  257. th:data-dataid="${item.data_id}" data-toggle="modal"
  258. data-target="#campaignModal2">View</button>
  259. </td>
  260. <td th:text="${item.call_status}"></td>
  261. <!-- Remarks Textarea -->
  262. <td class="text-center"><textarea
  263. class="form-control" name="remarks" id="remarks"
  264. th:text="${item.remarks}" readonly></textarea></td>
  265. </tr>
  266. </th:block>
  267. </tbody>
  268. </table>
  269. </div>
  270. </div>
  271. </div>
  272. </div>
  273. <div class="col-md-12" id="tablesforpendingcalls"
  274. style="display: none;">
  275. <div class="card">
  276. <div class="card-block">
  277. <div class="page-header-title">
  278. <h5 style="margin: 0; font-weight: bold;">
  279. <span id="campaign-names-display"
  280. style="font-weight: bold; color: blue; margin-right: 5px;"></span>-
  281. Further Calls List
  282. </h5>
  283. <hr>
  284. </div>
  285. <div>
  286. <table id="Pendingtasktable"
  287. class="table table-bordered table-hover dataTable"
  288. role="grid">
  289. <thead class="thead-dark">
  290. <tr role="row">
  291. <th>S.No</th>
  292. <th class="text-center">Name</th>
  293. <th class="text-center">Mobile number</th>
  294. <th class="text-center">ViewDetails</th>
  295. <th class="text-center custom-width1">Callstatus</th>
  296. <th class="text-center custom-width2">Remarks</th>
  297. <th class="text-center">Send Message</th>
  298. <th class="text-center">Status</th>
  299. </tr>
  300. </thead>
  301. <tbody>
  302. </tbody>
  303. </table>
  304. </div>
  305. </div>
  306. </div>
  307. </div>
  308. </div>
  309. </div>
  310. </div>
  311. <footer th:replace="~{fragments/modules/base/footer :: footer}"></footer>
  312. </div>
  313. <!-- <div class="modal fade" id="CampaignView" tabindex="-1"
  314. role="dialog" aria-labelledby="CampaignView"
  315. aria-hidden="true" data-backdrop="static" data-keyboard="false">
  316. <div class="modal-dialog modal-lg" role="document">
  317. <div class="modal-content">
  318. <div class="modal-header">
  319. <h5 class="modal-title">Campaign Details</h5>
  320. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  321. <span aria-hidden="true">&times;</span>
  322. </button>
  323. </div>
  324. <div class="modal-body">
  325. <div id="CampaignViewContent">Loading...</div>
  326. </div>
  327. </div>
  328. </div>
  329. </div>
  330. <div class="modal fade" id="questionCampaignView" tabindex="-1"
  331. role="dialog" aria-labelledby="CampaignView"
  332. aria-hidden="true" data-backdrop="static" data-keyboard="false">
  333. <div class="modal-dialog modal-lg" role="document">
  334. <div class="modal-content">
  335. <div class="modal-header">
  336. <h5 class="modal-title">Campaign Details</h5>
  337. <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
  338. <button type="button" class="btn btn-primary" id="submitAnswers">Submit</button>
  339. </div>
  340. <div class="modal-body">
  341. <div id="questionsCampaignView">Loading...</div>
  342. </div>
  343. </div>
  344. </div>
  345. </div> -->
  346. <div class="modal fade" id="campaignModal" tabindex="-1" role="dialog"
  347. aria-labelledby="campaignModalLabel" aria-hidden="true"
  348. data-backdrop="static" data-keyboard="false">
  349. <div class="modal-dialog modal-lg modal-dialog-scrollable"
  350. role="document">
  351. <div class="modal-content">
  352. <div class="modal-header">
  353. <h5 class="modal-title">Details & Questions</h5>
  354. <button type="button" class="close" data-dismiss="modal"
  355. aria-label="Close">
  356. <span aria-hidden="true">&times;</span>
  357. </button>
  358. </div>
  359. <div class="modal-body">
  360. <!-- Section for Campaign Details -->
  361. <div id="campaignDetails">
  362. <h5>Details</h5>
  363. <div id="CampaignViewContent">Loading...</div>
  364. </div>
  365. <hr>
  366. <!-- Section for Questions and Answers -->
  367. <div id="campaignQuestions">
  368. <h5>Questions</h5>
  369. <div id="questionsCampaignView">Loading...</div>
  370. </div>
  371. </div>
  372. <div class="modal-footer d-flex justify-content-center">
  373. <button type="button" class="btn btn-primary" id="submitAnswers">Submit
  374. Answers</button>
  375. <button type="button" class="btn btn-secondary"
  376. data-dismiss="modal">Close</button>
  377. </div>
  378. </div>
  379. </div>
  380. </div>
  381. <div class="modal fade" id="campaignModal2" tabindex="-1" role="dialog"
  382. aria-labelledby="campaignModalLabel" aria-hidden="true"
  383. data-backdrop="static" data-keyboard="false">
  384. <div class="modal-dialog modal-lg modal-dialog-scrollable"
  385. role="document">
  386. <div class="modal-content">
  387. <div class="modal-header">
  388. <h5 class="modal-title">Details & Questions</h5>
  389. <button type="button" class="close" data-dismiss="modal"
  390. aria-label="Close">
  391. <span aria-hidden="true">&times;</span>
  392. </button>
  393. </div>
  394. <div class="modal-body">
  395. <!-- Section for Campaign Details -->
  396. <div id="campaignDetails1">
  397. <h5>Details</h5>
  398. <div id="CampaignViewContent1">Loading...</div>
  399. </div>
  400. <hr>
  401. <!-- Section for Questions and Answers -->
  402. <div id="campaignQuestions1">
  403. <h5>Questions</h5>
  404. <div id="questionsCampaignView1">Loading...</div>
  405. </div>
  406. </div>
  407. <div class="modal-footer d-flex justify-content-center">
  408. <!-- <button type="button" class="btn btn-primary" id="submitAnswers">Submit
  409. Answers</button> -->
  410. <button type="button" class="btn btn-secondary"
  411. data-dismiss="modal">Close</button>
  412. </div>
  413. </div>
  414. </div>
  415. </div>
  416. </div>
  417. <div th:replace="~{fragments/modules/base/app_module_menu_box :: div}"></div>
  418. <script th:replace="~{fragments/modules/base/script :: script}"></script>
  419. <script
  420. src="node_modules/tempusdominus-bootstrap-4/build/js/tempusdominus-bootstrap-4.min.js"></script>
  421. <script>
  422. $(document).ready(function() {
  423. $(".view-details1").click(function () {
  424. let categoryId = $(this).data("categoryid");
  425. let campaignId = $(this).data("campaignid");
  426. let agentId = $(this).attr("data-agentid");
  427. let dataId = $(this).attr("data-dataid");
  428. console.log("Fetching details for categoryId:", categoryId);
  429. console.log("Fetching questions for campaignId:", campaignId);
  430. // Fetch campaign details
  431. $.ajax({
  432. url: "/gcc/api/agents/Campaignview",
  433. type: "GET",
  434. data: { categoryId, agentId, dataId },
  435. success: function (response) {
  436. console.log(response);
  437. let modalContent = `<div class="container-fluid">
  438. <table class="table table-bordered">
  439. <tbody>`;
  440. if (response.length > 0) {
  441. let item = response[0];
  442. let keys = Object.keys(item);
  443. for (let i = 0; i < keys.length; i += 3) {
  444. modalContent += `<tr>`;
  445. // Loop through 3 items per row
  446. for (let j = 0; j < 3; j++) {
  447. if (i + j < keys.length) {
  448. let key = keys[i + j];
  449. let value = item[key] ? item[key] : "-";
  450. /* modalContent += `
  451. <th class="bg-light text-dark p-2 text-center">${key.replace(/_/g, " ")}</th>
  452. <td style="word-wrap: break-word; white-space: normal; max-width: 200px;">${value}</td>`;
  453. } */
  454. let displayValue = (typeof value === "string" && value.startsWith("http"))
  455. ? `<a href="${value}" target="_blank" style="text-decoration: none; color: blue;">${value}</a>`
  456. : value;
  457. modalContent += `
  458. <th class="bg-light text-dark p-2 text-center">${key.replace(/_/g, " ")}</th>
  459. <td style="word-wrap: break-word; white-space: normal; max-width: 200px;">${displayValue}</td>`;
  460. }
  461. }
  462. modalContent += `</tr>`;
  463. }
  464. } else {
  465. modalContent += `<tr><td colspan="6" class="text-center">No data available</td></tr>`;
  466. }
  467. modalContent += `</tbody></table></div>`;
  468. $("#CampaignViewContent1").html(modalContent);
  469. },
  470. error: function () {
  471. $("#CampaignViewContent1").html("<p>Error fetching campaign details.</p>");
  472. }
  473. });
  474. // Fetch related questions
  475. $.ajax({
  476. url: "/gcc/api/agents/questions",
  477. type: "GET",
  478. data: { categoryId, campaignId },
  479. success: function (response) {
  480. console.log(response);
  481. renderQuestions1(response, campaignId, agentId, dataId);
  482. },
  483. error: function () {
  484. $("#questionsCampaignView1").html("<p>Error fetching questions.</p>");
  485. }
  486. });
  487. // Show modal after fetching details
  488. $("#campaignModal1").modal("show");
  489. });
  490. $(".view-details").click(function () {
  491. let categoryId = $(this).data("categoryid");
  492. let campaignId = $(this).data("campaignid");
  493. let agentId = $(this).attr("data-agentid");
  494. let dataId = $(this).attr("data-dataid");
  495. $("#submitAnswers").attr("data-categoryid", categoryId);
  496. $("#submitAnswers").attr("data-campaignid", campaignId);
  497. $("#submitAnswers").attr("data-agentid", agentId);
  498. $("#submitAnswers").attr("data-dataid", dataId);
  499. console.log("Fetching details for categoryId:", categoryId);
  500. console.log("Fetching questions for campaignId:", campaignId);
  501. // Fetch campaign details
  502. $.ajax({
  503. url: "/gcc/api/agents/Campaignview",
  504. type: "GET",
  505. data: { categoryId, agentId, dataId },
  506. success: function (response) {
  507. console.log(response);
  508. let modalContent = `<div class="container-fluid">
  509. <table class="table table-bordered">
  510. <tbody>`;
  511. if (response.length > 0) {
  512. let item = response[0];
  513. let keys = Object.keys(item);
  514. for (let i = 0; i < keys.length; i += 3) {
  515. modalContent += `<tr>`;
  516. // Loop through 3 items per row
  517. for (let j = 0; j < 3; j++) {
  518. if (i + j < keys.length) {
  519. let key = keys[i + j];
  520. let value = item[key] ? item[key] : "-";
  521. /* modalContent += `
  522. <th class="bg-light text-dark p-2 text-center">${key.replace(/_/g, " ")}</th>
  523. <td style="word-wrap: break-word; white-space: normal; max-width: 200px;">${value}</td>`;
  524. } */
  525. let displayValue = (typeof value === "string" && value.startsWith("http"))
  526. ? `<a href="${value}" target="_blank" style="text-decoration: none; color: blue;">${value}</a>`
  527. : value;
  528. modalContent += `
  529. <th class="bg-light text-dark p-2 text-center">${key.replace(/_/g, " ")}</th>
  530. <td style="word-wrap: break-word; white-space: normal; max-width: 200px;">${displayValue}</td>`;
  531. }
  532. }
  533. modalContent += `</tr>`;
  534. }
  535. } else {
  536. modalContent += `<tr><td colspan="6" class="text-center">No data available</td></tr>`;
  537. }
  538. modalContent += `</tbody></table></div>`;
  539. $("#CampaignViewContent").html(modalContent);
  540. },
  541. error: function () {
  542. $("#CampaignViewContent").html("<p>Error fetching campaign details.</p>");
  543. }
  544. });
  545. // Fetch related questions
  546. $.ajax({
  547. url: "/gcc/api/agents/questions",
  548. type: "GET",
  549. data: { categoryId, campaignId },
  550. success: function (response) {
  551. console.log(response);
  552. renderQuestions(response, campaignId, agentId, dataId);
  553. },
  554. error: function () {
  555. $("#questionsCampaignView").html("<p>Error fetching questions.</p>");
  556. }
  557. });
  558. // Show modal after fetching details
  559. $("#campaignModal").modal("show");
  560. });
  561. function renderQuestions1(data, campaignId, agentId, dataId) {
  562. let html = `<div class="container">`;
  563. let allAnswered = true; // Track if all answers exist
  564. data.forEach(question => {
  565. let questionId = question.question_id;
  566. let inputField = "";
  567. // Fetch existing answer
  568. $.ajax({
  569. url: "/gcc/api/agents/fetchAnswer",
  570. type: "GET",
  571. data: { campaignId, agentId, questionId, dataId },
  572. async: false, // Ensure answer is fetched before rendering
  573. success: function (answerResponse) {
  574. let existingAnswer = (answerResponse.length > 0) ? answerResponse[0].campaign_answer : null;
  575. let isReadOnly = existingAnswer ? "readonly" : "";
  576. inputField = generateInputField2(question, existingAnswer, isReadOnly);
  577. // If any question does not have an answer, allow form submission
  578. if (!existingAnswer) {
  579. allAnswered = false;
  580. }
  581. }
  582. });
  583. html += `
  584. <div class="row align-items-center mb-3">
  585. <div class="col-md-8">
  586. <label class="font-weight-bold">${question.questions}<span class="text-danger">*</span></label>
  587. </div>
  588. <div class="col-md-4">${inputField}</div>
  589. </div>`;
  590. });
  591. html += `</div>`;
  592. $("#questionsCampaignView1").html(html);
  593. // Hide submit button if all questions have answers
  594. /* if (allAnswered) {
  595. $("#submitAnswers").hide();
  596. } else {
  597. $("#submitAnswers").show();
  598. } */
  599. }
  600. function renderQuestions(data, campaignId, agentId, dataId) {
  601. let html = `<div class="container">`;
  602. let allAnswered = true; // Track if all answers exist
  603. data.forEach(question => {
  604. let questionId = question.question_id;
  605. let inputField = "";
  606. // Fetch existing answer
  607. $.ajax({
  608. url: "/gcc/api/agents/fetchAnswer",
  609. type: "GET",
  610. data: { campaignId, agentId, questionId, dataId },
  611. async: false, // Ensure answer is fetched before rendering
  612. success: function (answerResponse) {
  613. let existingAnswer = (answerResponse.length > 0) ? answerResponse[0].campaign_answer : null;
  614. let isReadOnly = existingAnswer ? "readonly" : "";
  615. inputField = generateInputField(question, existingAnswer, isReadOnly);
  616. // If any question does not have an answer, allow form submission
  617. if (!existingAnswer) {
  618. allAnswered = false;
  619. }
  620. }
  621. });
  622. html += `
  623. <div class="row align-items-center mb-3">
  624. <div class="col-md-8">
  625. <label class="font-weight-bold">${question.questions}<span class="text-danger">*</span></label>
  626. </div>
  627. <div class="col-md-4">${inputField}</div>
  628. </div>`;
  629. });
  630. html += `</div>`;
  631. $("#questionsCampaignView").html(html);
  632. // Hide submit button if all questions have answers
  633. if (allAnswered) {
  634. $("#submitAnswers").hide();
  635. } else {
  636. $("#submitAnswers").show();
  637. }
  638. }
  639. function generateInputField2(question, existingAnswer, isReadOnly) {
  640. let html = "";
  641. if (question.answer_type_id == 1) { // Text Input
  642. html = `<input type="text" class="form-control answer-input"
  643. data-questionid="${question.question_id}"
  644. value="${existingAnswer || ''}"
  645. readonly
  646. ${isReadOnly}/>`;
  647. }
  648. else if (question.answer_type_id == 2) { // Radio Buttons
  649. question.answers.forEach(ans => {
  650. let checked = (existingAnswer === ans) ? "checked" : "disabled";
  651. let isReadOnlyAttr = existingAnswer ? 'onclick="return false;"' : ""; // Prevent change
  652. html += `
  653. <div class="form-check form-check-inline">
  654. <input class="form-check-input answer-input" type="radio"
  655. name="q_${question.question_id}" value="${ans}"
  656. data-questionid="${question.question_id}"
  657. ${checked} ${isReadOnlyAttr}>
  658. <label class="form-check-label">${ans}</label>
  659. </div>`;
  660. });
  661. }
  662. else if (question.answer_type_id == 3) { // Dropdown (Select)
  663. let isDisabled = existingAnswer ? 'disabled' : 'disabled'; // Disable only when an answer exists
  664. html = `<select class="form-control answer-input"
  665. data-questionid="${question.question_id}" ${isDisabled}>
  666. <option value="" disabled ${!existingAnswer ? "selected" : ""}>
  667. Select an option
  668. </option>`; // Show "Select an option" only if no answer exists
  669. question.answers.forEach(ans => {
  670. let selected = (existingAnswer === ans) ? "selected" : "";
  671. html += `<option value="${ans}" ${selected}>${ans}</option>`;
  672. });
  673. html += `</select>`;
  674. }
  675. else if (question.answer_type_id == 4) { // Checkbox
  676. question.answers.forEach(ans => {
  677. let checked = (existingAnswer && existingAnswer.includes(ans)) ? "checked" : "disabled";
  678. let isReadOnlyAttr = existingAnswer ? 'onclick="return false;"' : ""; // Prevent change
  679. html += `
  680. <div class="form-check">
  681. <input class="form-check-input answer-input" type="checkbox"
  682. value="${ans}" data-questionid="${question.question_id}"
  683. ${checked} ${isReadOnlyAttr}>
  684. <label class="form-check-label">${ans}</label>
  685. </div>`;
  686. });
  687. }
  688. return html;
  689. }
  690. function generateInputField(question, existingAnswer, isReadOnly) {
  691. let html = "";
  692. if (question.answer_type_id == 1) { // Text Input
  693. html = `<input type="text" class="form-control answer-input"
  694. data-questionid="${question.question_id}"
  695. value="${existingAnswer || ''}"
  696. ${isReadOnly}/>`;
  697. }
  698. else if (question.answer_type_id == 2) { // Radio Buttons
  699. question.answers.forEach(ans => {
  700. let checked = (existingAnswer === ans) ? "checked" : "";
  701. let isReadOnlyAttr = existingAnswer ? 'onclick="return false;"' : ""; // Prevent change
  702. html += `
  703. <div class="form-check form-check-inline">
  704. <input class="form-check-input answer-input" type="radio"
  705. name="q_${question.question_id}" value="${ans}"
  706. data-questionid="${question.question_id}"
  707. ${checked} ${isReadOnlyAttr}>
  708. <label class="form-check-label">${ans}</label>
  709. </div>`;
  710. });
  711. }
  712. else if (question.answer_type_id == 3) { // Dropdown (Select)
  713. let isDisabled = existingAnswer ? 'disabled' : ''; // Disable only when an answer exists
  714. html = `<select class="form-control answer-input"
  715. data-questionid="${question.question_id}" ${isDisabled}>
  716. <option value="" disabled ${!existingAnswer ? "selected" : ""}>
  717. Select an option
  718. </option>`; // Show "Select an option" only if no answer exists
  719. question.answers.forEach(ans => {
  720. let selected = (existingAnswer === ans) ? "selected" : "";
  721. html += `<option value="${ans}" ${selected}>${ans}</option>`;
  722. });
  723. html += `</select>`;
  724. }
  725. else if (question.answer_type_id == 4) { // Checkbox
  726. question.answers.forEach(ans => {
  727. let checked = (existingAnswer && existingAnswer.includes(ans)) ? "checked" : "";
  728. let isReadOnlyAttr = existingAnswer ? 'onclick="return false;"' : ""; // Prevent change
  729. html += `
  730. <div class="form-check">
  731. <input class="form-check-input answer-input" type="checkbox"
  732. value="${ans}" data-questionid="${question.question_id}"
  733. ${checked} ${isReadOnlyAttr}>
  734. <label class="form-check-label">${ans}</label>
  735. </div>`;
  736. });
  737. }
  738. return html;
  739. }
  740. // Submit only new answers
  741. $("#submitAnswers").off('click').on('click', function () {
  742. let answersArray = [];
  743. let allAnswered = true; // Flag to check if all required fields are answered
  744. let categoryId = $(this).attr("data-categoryid");
  745. let campaignId = $(this).attr("data-campaignid");
  746. let agentId = $(this).attr("data-agentid");
  747. let dataId = $(this).attr("data-dataid");
  748. let processedQuestions = new Set(); // To prevent duplicate question processing
  749. $(".answer-input").each(function () {
  750. let questionId = $(this).data("questionid");
  751. let answerValue = null;
  752. if (processedQuestions.has(questionId)) {
  753. return; // Skip duplicate question IDs
  754. }
  755. if ($(this).is(":radio")) {
  756. answerValue = $(`input[name="q_${questionId}"]:checked`).val();
  757. } else if ($(this).is("select")) {
  758. answerValue = $(this).val();
  759. } else if ($(this).is(":checkbox")) {
  760. answerValue = $(`input[data-questionid="${questionId}"]:checked`).map(function () {
  761. return $(this).val();
  762. }).get().join(", ");
  763. } else {
  764. answerValue = $(this).val();
  765. }
  766. if (!answerValue || answerValue.trim() === "") {
  767. allAnswered = false;
  768. //$(this).addClass("is-invalid");
  769. } else {
  770. $(this).removeClass("is-invalid");
  771. processedQuestions.add(questionId);
  772. answersArray.push({
  773. campaign_id: campaignId,
  774. data_id: dataId,
  775. agent_id: agentId,
  776. question_id: questionId,
  777. campaign_answer: answerValue
  778. });
  779. }
  780. });
  781. if (!allAnswered) {
  782. Swal.fire({
  783. icon: "warning",
  784. title: "Missing Fields!",
  785. text: "Please fill in all required fields before submitting.",
  786. confirmButtonText: "OK"
  787. });
  788. return;
  789. }
  790. console.log("Submitting Answers:", answersArray);
  791. $('#submitAnswers').attr('disabled', true).text('Processing');
  792. $.ajax({
  793. url: "/gcc/api/agents/submitAnswers",
  794. type: "POST",
  795. contentType: "application/json",
  796. data: JSON.stringify({ answers: answersArray }),
  797. success: function (response) {
  798. $('#submitAnswers').attr('disabled', false).text('Submit Answers');
  799. Swal.fire({
  800. title: 'Success!',
  801. text: response,
  802. icon: 'success',
  803. allowOutsideClick: false, // Disable clicking outside the modal to close it
  804. allowEscapeKey: false, // Disable escape key to close the modal
  805. allowEnterKey: false, // Disable enter key to close the modal
  806. confirmButtonText: "OK"
  807. }).then(() => {
  808. $('#submitAnswers').attr('disabled', false).text('Submit Answers');
  809. $('#campaignModal').modal('hide');
  810. });
  811. },
  812. error: function (xhr) {
  813. $('#submitAnswers').attr('disabled', false).text('Submit Answers');
  814. let errorMessage = "";
  815. if (xhr.responseText) {
  816. errorMessage = xhr.responseText; // Use backend message if available
  817. }
  818. Swal.fire({
  819. icon: "error",
  820. title: "Submission Failed!",
  821. text: errorMessage,
  822. confirmButtonText: "OK"
  823. });
  824. }
  825. });
  826. });
  827. let option_val = '';
  828. $.ajax({
  829. url: "/gcc/api/agents/callstatus",
  830. type: "GET",
  831. success: function (data) {
  832. //dropdown.empty();
  833. //dropdown.append('<option value="">Select Call Status</option>');
  834. $.each(data, function (index, item) {
  835. option_val = option_val + '<option value="' + item.id + '">' + item.call_status + '</option>';
  836. //console.log(option_val);
  837. });
  838. add_data();
  839. }
  840. });
  841. function add_data(){
  842. $(".action-dropdown").each(function () {
  843. //alert($(this));
  844. let dropdown = $(this);
  845. //if (!dropdown.find("option[value='']").length) {
  846. dropdown.empty();
  847. dropdown.append('<option value="">Select Call Status</option>');
  848. dropdown.append(option_val);
  849. // }
  850. });
  851. }
  852. /* $(".action-dropdown").each(function () {
  853. let dropdown = $(this);
  854. $.ajax({
  855. url: "/gcc/api/agents/callstatus",
  856. type: "GET",
  857. success: function (data) {
  858. dropdown.empty();
  859. dropdown.append('<option value="">Select Call Status</option>');
  860. $.each(data, function (index, item) {
  861. dropdown.append('<option value="' + item.id + '">' + item.call_status + '</option>');
  862. });
  863. }
  864. });
  865. }); */
  866. /* function submitAction(dataId, index,agentId,campaignId) {
  867. let row = $(`#submit-btn-${index}`).closest("tr");
  868. // Get selected dropdown value and textarea value
  869. let callStatus = row.find(".action-dropdown").val(); // Ensure you're getting the correct value
  870. let remarks = row.find("textarea[name='remarks']").val() || "N/A";
  871. console.log("sxdnx",remarks);
  872. // Make an AJAX POST request to submit the data
  873. $.ajax({
  874. url: '/gcc/api/agents/savecall', // URL to your Spring Boot controller for handling POST
  875. type: 'POST',
  876. contentType: 'application/json',
  877. data: JSON.stringify({
  878. data_id: dataId,
  879. agent_id: agentId,
  880. campaign_id:campaignId,
  881. call_status: callStatus, // Use "call_status" as the key to match the controller parameter name
  882. remarks: remarks
  883. }),
  884. success: function(response) {
  885. console.log('Data Updated successfully:', response);
  886. // Update the button and form fields after successful submission
  887. Swal.fire({
  888. title: 'Success!',
  889. text: 'Data Updated successfully!',
  890. icon: 'success',
  891. timer: 2000,
  892. showConfirmButton: false
  893. })
  894. let button = $(`#submit-btn-${index}`);
  895. button.text('Submitted').removeClass('btn-primary').addClass('btn-primary').prop('disabled', true);
  896. $(`#AgentDatatable tbody .action-dropdown[data-index="${index}"]`).prop('disabled', true);
  897. $(`#AgentDatatable tbody textarea[name="remarks"]`).eq(index).prop('disabled', true);
  898. },
  899. error: function(xhr, status, error) {
  900. console.error('Error submitting data:', error);
  901. }
  902. });
  903. }*/
  904. var buttons = [
  905. {
  906. extend: 'pageLength',
  907. className: 'btn btn-warning'
  908. },
  909. {
  910. title: 'Data export',
  911. extend: 'copyHtml5',
  912. text: 'Copy',
  913. className: 'btn btn-secondary'
  914. },
  915. {
  916. extend: 'excelHtml5',
  917. text: 'Excel',
  918. className: 'btn btn-secondary'
  919. },
  920. {
  921. extend: 'csvHtml5',
  922. text: 'CSV',
  923. className: 'btn btn-secondary'
  924. },
  925. {
  926. extend: 'pdfHtml5',
  927. text: 'PDF',
  928. className: 'btn btn-secondary'
  929. }
  930. ];
  931. $('#Agenttask').DataTable({
  932. dom: 'Bftip',
  933. columnDefs: [
  934. {targets: 'no-sort', orderable: false}
  935. ],
  936. lengthMenu: [
  937. [50, 100, 200, 500, -1],
  938. ['50 rows', '100 rows', '200 rows', '500 rows', 'Show all']
  939. ],
  940. scrollY: '20vh',
  941. fixedColumns: {
  942. left: 1,
  943. right: 1
  944. },
  945. buttons: buttons,
  946. fixedHeader: true,
  947. autoWidth: true,
  948. responsive: true,
  949. searching: true,
  950. select: false,
  951. processing: false,
  952. });
  953. var table= $('#AgentDatatable').DataTable({
  954. dom: 'Bftip',
  955. columnDefs: [
  956. {targets: 'no-sort', orderable: false}
  957. ],
  958. lengthMenu: [
  959. [50, 100, 200, 500, -1],
  960. ['50 rows', '100 rows', '200 rows', '500 rows', 'Show all']
  961. ],
  962. scrollY: '50vh',
  963. fixedColumns: {
  964. left: 1,
  965. right: 1
  966. },
  967. buttons: buttons,
  968. fixedHeader: true,
  969. autoWidth: true,
  970. responsive: true,
  971. searching: true,
  972. select: false,
  973. processing: true,
  974. });
  975. table.on('draw', function () {
  976. var pageInfo = table.page.info();
  977. //console.log('User navigated to page: ' + (pageInfo.page + 1)); // Page numbers are zero-based
  978. add_data();
  979. });
  980. $('#AgentDatatable1').DataTable({
  981. dom: 'Bftip',
  982. columnDefs: [
  983. {targets: 'no-sort', orderable: false}
  984. ],
  985. lengthMenu: [
  986. [50, 100, 200, 500, -1],
  987. ['50 rows', '100 rows', '200 rows', '500 rows', 'Show all']
  988. ],
  989. scrollY: '50vh',
  990. fixedColumns: {
  991. left: 1,
  992. right: 1
  993. },
  994. buttons: buttons,
  995. fixedHeader: true,
  996. autoWidth: true,
  997. responsive: true,
  998. searching: true,
  999. select: false,
  1000. processing: false,
  1001. });
  1002. });
  1003. $('#primaryButton').addClass('btn-success').removeClass('btn-secondary');
  1004. $('#secondaryButton').addClass('btn-secondary').removeClass('btn-success');
  1005. $('#primaryButton').click(function () {
  1006. $('#primaryTable').show();
  1007. $('#secondaryTable').hide();
  1008. $(this).addClass('btn-success').removeClass('btn-secondary');
  1009. $('#secondaryButton').addClass('btn-secondary').removeClass('btn-success');
  1010. $('#AgentDatatable').DataTable().columns.adjust().draw();
  1011. });
  1012. $('#secondaryButton').click(function () {
  1013. $('#primaryTable').hide();
  1014. $('#secondaryTable').show();
  1015. $(this).addClass('btn-success').removeClass('btn-secondary');
  1016. $('#primaryButton').addClass('btn-secondary').removeClass('btn-success');
  1017. $('#AgentDatatable1').DataTable().columns.adjust().draw();
  1018. });
  1019. document.getElementById("refresh").addEventListener("click", function() {
  1020. location.reload(); // Reloads the current page
  1021. });
  1022. function submitAction(dataId, index, agentId, campaignId) {
  1023. let row = $(`#submit-btn-${index}`).closest("tr");
  1024. // Get selected dropdown value and textarea value
  1025. let callStatusDropdown = row.find(".action-dropdown"); // Get the dropdown element
  1026. let callStatus = callStatusDropdown.find("option:selected").text().trim(); // Get selected text
  1027. //let callStatus = callStatusDropdown.val();
  1028. let remarks = row.find("textarea[name='remarks']").val() || "N/A"; // Default to "N/A" if empty
  1029. console.log("Data ID:", dataId);
  1030. console.log("Agent ID:", agentId);
  1031. console.log("Campaign ID:", campaignId);
  1032. console.log("Call Status:", callStatus);
  1033. console.log("Remarks:", remarks);
  1034. if (!callStatus || callStatus === "Select Call Status") {
  1035. console.log("❌ Call status is required.");
  1036. Swal.fire({
  1037. title: 'Validation Error!',
  1038. text: 'Please select a Call Status before submitting.',
  1039. icon: 'warning',
  1040. confirmButtonText: 'OK'
  1041. });
  1042. return;
  1043. }
  1044. if (remarks === "" || remarks === "N/A") {
  1045. console.log("❌ Remarks cannot be empty.");
  1046. Swal.fire({
  1047. title: 'Validation Error!',
  1048. text: 'Please enter remarks before submitting.',
  1049. icon: 'warning',
  1050. confirmButtonText: 'OK'
  1051. });
  1052. return;
  1053. }
  1054. // If call status is not "INFORMATION GIVEN", submit immediately
  1055. if (callStatus !== "INFORMATION GIVEN") {
  1056. submitData(dataId, agentId, campaignId, callStatus, remarks, row, index);
  1057. return;
  1058. }
  1059. // If call status is "INFORMATION GIVEN", check database counts first
  1060. $.ajax({
  1061. url: `/gcc/api/agents/checkCounts?dataId=${dataId}&campaignId=${campaignId}`,
  1062. type: 'GET',
  1063. success: function(response) {
  1064. console.log("DB Count Check Response:", response);
  1065. if (response.length > 0) { // ✅ Ensure response contains data
  1066. let answersCount = response[0].answersCount || 0;
  1067. let questionsCount = response[0].questionsCount || 0;
  1068. console.log("Answers Count:", answersCount);
  1069. console.log("Questions Count:", questionsCount);
  1070. // ✅ If call status is NOT "INFORMATION GIVEN", allow submission directly
  1071. if (callStatus === "INFORMATION GIVEN" && questionsCount !== answersCount) {
  1072. console.log("❌ Counts do not match! Submission blocked.");
  1073. Swal.fire({
  1074. title: 'Incomplete!',
  1075. text: `You have answered only ${answersCount} out of ${questionsCount} required questions.`,
  1076. icon: 'error',
  1077. confirmButtonText: 'OK'
  1078. });
  1079. } else {
  1080. console.log("✅ Proceeding with submission.");
  1081. submitData(dataId, agentId, campaignId, callStatus, remarks, row, index);
  1082. }
  1083. } else {
  1084. console.log("❌ No count data received. Blocking submission.");
  1085. Swal.fire({
  1086. title: 'Error!',
  1087. text: 'Could not retrieve question counts. Please try again later.',
  1088. icon: 'error'
  1089. });
  1090. }
  1091. },
  1092. error: function(xhr, status, error) {
  1093. console.error('Error fetching count data:', error);
  1094. Swal.fire({
  1095. title: 'Error!',
  1096. text: 'Failed to check question counts. Please contact support.',
  1097. icon: 'error'
  1098. });
  1099. }
  1100. });
  1101. }
  1102. // Function to submit data
  1103. function submitData(dataId, agentId, campaignId, callStatus, remarks, row, index) {
  1104. $('.submitid').prop('disabled', true).text('Submitting');
  1105. $.ajax({
  1106. url: '/gcc/api/agents/savecall',
  1107. type: 'POST',
  1108. contentType: 'application/json',
  1109. data: JSON.stringify({
  1110. data_id: dataId,
  1111. agent_id: agentId,
  1112. campaign_id: campaignId,
  1113. call_status: callStatus,
  1114. remarks: remarks
  1115. }),
  1116. success: function(response) {
  1117. $('.submitid').prop('disabled', false).text('Submit');
  1118. console.log('Data Updated successfully:', response);
  1119. Swal.fire({
  1120. title: 'Success!',
  1121. text: 'Data Updated successfully!',
  1122. icon: 'success',
  1123. allowOutsideClick: false, // Disable clicking outside the modal to close it
  1124. allowEscapeKey: false, // Disable escape key to close the modal
  1125. allowEnterKey: false, // Disable enter key to close the modal
  1126. showConfirmButton: true
  1127. }).then((result) => {
  1128. if (result.isConfirmed) {
  1129. //console.log("ok button clicked");
  1130. $('.submitid').prop('disabled', false).text('Submit');
  1131. const table = $('#AgentDatatable').DataTable();
  1132. // Remove the row from the table
  1133. table.row(row).remove().draw(false);
  1134. // Recalculate and update S.No column
  1135. table.rows().every(function(index) {
  1136. $(this.node()).find('td:first-child').text(index + 1);
  1137. });
  1138. table.draw(false);
  1139. }
  1140. });
  1141. },
  1142. error: function(xhr, status, error) {
  1143. console.error('Error submitting data:', error);
  1144. }
  1145. });
  1146. }
  1147. // Make an AJAX POST request to submit the data
  1148. //working
  1149. /* function submitAction(dataId, index,agentId,campaignId) {
  1150. // Get selected dropdown value and textarea value
  1151. let row = $(`#submit-btn-${index}`).closest("tr");
  1152. // Get selected dropdown value and textarea value
  1153. let callStatusDropdown = row.find(".action-dropdown"); // Ensure you're getting the correct value
  1154. let callStatus = callStatusDropdown.find("option:selected").text();
  1155. let remarks = row.find("textarea[name='remarks']").val() || "N/A";
  1156. console.log(dataId);
  1157. console.log(agentId);
  1158. console.log(campaignId);
  1159. console.log(callStatus);
  1160. console.log(remarks);
  1161. // Make an AJAX POST request to submit the data
  1162. $.ajax({
  1163. url: '/gcc/api/agents/savecall', // URL to your Spring Boot controller for handling POST
  1164. type: 'POST',
  1165. contentType: 'application/json',
  1166. data: JSON.stringify({
  1167. data_id: dataId,
  1168. agent_id: agentId,
  1169. campaign_id:campaignId,
  1170. call_status: callStatus, // Use "call_status" as the key to match the controller parameter name
  1171. remarks: remarks
  1172. }),
  1173. success: function(response) {
  1174. console.log('Data Updated successfully:', response);
  1175. // Update the button and form fields after successful submission
  1176. Swal.fire({
  1177. title: 'Success!',
  1178. text: 'Data Updated successfully!',
  1179. icon: 'success',
  1180. timer: 2000,
  1181. showConfirmButton: true
  1182. }).then((result) => {
  1183. if (result.isConfirmed) {
  1184. console.log("ok button");
  1185. $('.submitid').prop('disabled', false).text('Submit');
  1186. const table = $('#AgentDatatable').DataTable();
  1187. // Remove the row
  1188. table.row($(row)).remove();
  1189. // Reorder S.No column
  1190. table.rows().every(function (index) {
  1191. const row = this.node();
  1192. $(row).find('td:first-child').text(index + 1); // Update S.No
  1193. });
  1194. // Redraw the table
  1195. table.draw(false);
  1196. }
  1197. });
  1198. },
  1199. error: function(xhr, status, error) {
  1200. console.error('Error submitting data:', error);
  1201. }
  1202. });
  1203. }*/
  1204. /* function PendingCampaignDetails(campaignId, callsPerAgent, agentId) {
  1205. console.log('Calling PendingCampaignDetails with:', {
  1206. callsPerAgent: callsPerAgent,
  1207. campaignId: campaignId,
  1208. agentId: agentId
  1209. });
  1210. $.ajax({
  1211. url: `/gcc/api/campaign/getCampaignDetailsbyId?campaign_id=${campaignId}`,
  1212. type: 'GET',
  1213. success: function (response) {
  1214. console.log(response);
  1215. if (response) {
  1216. // Populate modal fields with data
  1217. //$('#campaign_id').val(response.campaign_id);
  1218. $('#campaign_names').val(response.campaign_name); // Assuming the key in the response is 'campaign_name'
  1219. // Display the campaign name near the h5 element
  1220. $('#campaign-names-display').text(response.campaign_name); // Add text dynamically to the element
  1221. } else {
  1222. console.error('Error fetching campaign details:', error);
  1223. }
  1224. },
  1225. error: function (xhr, status, error) {
  1226. console.error('Error fetching campaign details:', error);
  1227. alert('An error occurred while fetching campaign details.');
  1228. }
  1229. });
  1230. // Get the card element by its ID (e.g., 'tablesforcalls')
  1231. var cardElement = document.getElementById('tablesforpendingcalls');
  1232. // Toggle the display property based on current state
  1233. if (cardElement.style.display === 'block') {
  1234. cardElement.style.display = 'none'; // Hide the card if it's currently displayed
  1235. } else {
  1236. cardElement.style.display = 'block'; // Show the card if it's hidden
  1237. }
  1238. $.ajax({
  1239. url: '/gcc/api/campaign/startcampaign?campaign_id=' + campaignId + '&calls_per_agent=' + callsPerAgent, // URL to your Spring Boot controller
  1240. type: 'GET', // GET request
  1241. contentType: 'application/json',
  1242. success: function(response) {
  1243. console.log('Campaign started successfully:', response);
  1244. // We are focusing on matching the agent_id since campaign_id is constant (24)
  1245. let dataIds = [];
  1246. response.forEach(function(item) {
  1247. console.log('Checking agent_id:', item.agent_id, 'against passed agent_id:', agentId);
  1248. if (item.agent_id === agentId) {
  1249. dataIds = item.data_ids; // Get the corresponding data_ids
  1250. console.log('Match found. Data IDs:', dataIds);
  1251. }
  1252. });
  1253. if (dataIds.length > 0) {
  1254. console.log('Data IDs for Agent ID ' + agentId + ':', dataIds);
  1255. // Fetch the data for the matched data IDs
  1256. $.ajax({
  1257. url: '/gcc/api/agents/getPendingDataByIds?ids=' + dataIds.join(','), // dataIds is the array [6, 7]
  1258. type: 'GET',
  1259. contentType: 'application/json',
  1260. success: function(response) {
  1261. console.log('Data retrieved successfully:', response);
  1262. // Initialize DataTable if not already done
  1263. let table = $('#Pendingtasktable').DataTable();
  1264. // Clear existing rows in the table
  1265. table.clear();
  1266. // Process and append the new data to the DataTable
  1267. let rows = [];
  1268. response.forEach(function(item, index) {
  1269. let row = [
  1270. index + 1, // S.No
  1271. item.id, // ID
  1272. item.name, // Name
  1273. item.address, // Address
  1274. item.dues, // Dues
  1275. item.cellnumber, // Mobile Number
  1276. `<div class="text-center">
  1277. <button class="btn btn-primary" onclick="ViewDetails('${item.viewdetails}')">View</button>
  1278. </div>`,
  1279. // Dropdown for Action
  1280. `<div class="text-center">
  1281. <select class="form-control action-dropdown2" name="action" data-index="${index}">
  1282. <option value="NONE" ${item.call_status === "NONE" ? "selected" : ""}>Call Status</option>
  1283. <option value="INFORMATION_GIVEN" ${item.call_status === "INFORMATION_GIVEN" ? "selected" : ""}>INFORMATION GIVEN</option>
  1284. <option value="UNATTENDED" ${item.call_status === "UNATTENDED" ? "selected" : ""}>UNATTENDED</option>
  1285. <option value="CALL_BACK_LATER" ${item.call_status === "CALL_BACK_LATER" ? "selected" : ""}>CALL BACK LATER</option>
  1286. <option value="SWITCH_OFF" ${item.call_status === "SWITCH_OFF" ? "selected" : ""}>SWITCH OFF</option>
  1287. <option value="WRONG_NUMBER" ${item.call_status === "WRONG_NUMBER" ? "selected" : ""}>WRONG NUMBER</option>
  1288. </select>
  1289. </div>`,
  1290. // Textarea for Remarks (populate saved remarks)
  1291. `<div class="text-center">
  1292. <textarea class="form-control" name="remarks">${item.remarks ? item.remarks : ""}</textarea>
  1293. </div>`,
  1294. // WhatsApp Message Button
  1295. `<div class="text-center">
  1296. <button class="btn btn-success" onclick="sendWhatsAppMessage('${item.cellnumber}', '${item.id}', '${item.viewdetails}')">Send</button>
  1297. </div>`,
  1298. // Centered Button for Submit Action (Initially disabled)
  1299. `<div class="text-center">
  1300. <button class="btn btn-primary submit-button" id="submitt-btn-${index}" disabled onclick="editAction(${item.data_id}, ${index}, ${agentId},${campaignId})">${item.call_status && item.call_status !== 'NONE' ? 'Update' : 'Update'}</button>
  1301. </div>`
  1302. ];
  1303. rows.push(row);
  1304. });
  1305. // Append the rows to your table
  1306. $('#Pendingtasktable').DataTable().rows.add(rows).draw();
  1307. // Add event listener to each dropdown to enable/disable the button
  1308. $('.action-dropdown2').on('change', function() {
  1309. let selectedValue = $(this).val();
  1310. let index = $(this).data('index');
  1311. let button = $('#submitt-btn-' + index);
  1312. // Enable the button if a valid option is selected, otherwise keep it disabled
  1313. if (selectedValue === 'NONE') {
  1314. button.prop('disabled', true);
  1315. button.text('Update');
  1316. button.removeClass('btn-primary').addClass('btn-primary');
  1317. } else {
  1318. button.prop('disabled', false);
  1319. button.text('Update');
  1320. button.removeClass('btn-primary').addClass('btn-primary');
  1321. }
  1322. });
  1323. $('.action-dropdown2').on('change', function () {
  1324. let selectedValue = $(this).val(); // Dropdown value
  1325. let index = $(this).data('index'); // Index of the row
  1326. let button = $('#submit-btn-' + index); // The submit button
  1327. let remarksField = $('textarea[name="remarks"]').eq(index); // The remarks textarea
  1328. // Function to check if the button should be enabled
  1329. function toggleButtonState() {
  1330. let remarksValue = remarksField.val().trim(); // Trimmed value of remarks
  1331. if (selectedValue !== 'NONE' && remarksValue !== '') {
  1332. button.prop('disabled', false);
  1333. button.text('Update');
  1334. button.removeClass('btn-primary').addClass('btn-primary');
  1335. } else {
  1336. button.prop('disabled', true);
  1337. button.text('Update');
  1338. button.removeClass('btn-primary').addClass('btn-primary');
  1339. }
  1340. }
  1341. // Toggle button state based on the current conditions
  1342. toggleButtonState();
  1343. // Add an event listener to the remarks field to recheck conditions
  1344. remarksField.on('input', function () {
  1345. toggleButtonState();
  1346. });
  1347. });
  1348. },
  1349. error: function(xhr, status, error) {
  1350. console.error('Error retrieving data:', error);
  1351. }
  1352. });
  1353. }
  1354. else {
  1355. console.log('No matching data found for Agent ID ' + agentId);
  1356. }
  1357. },
  1358. error: function(xhr, status, error) {
  1359. console.error('Error starting campaign:', error);
  1360. }
  1361. });
  1362. initializeAgentsDataTable();
  1363. // Show the #tablesforcalls div
  1364. //document.getElementById('tablesforpendingcalls').style.display = 'block';
  1365. } */
  1366. /* function editAction(dataId, index,agentId,campaignId) {
  1367. // Get selected dropdown value and textarea value
  1368. let action = $('.action-dropdown2[data-index="' + index + '"]').val(); // Ensure you're getting the correct value
  1369. let remarks = $(`#Pendingtasktable tbody textarea[name="remarks"]`).eq(index).val();
  1370. // Make an AJAX POST request to submit the data
  1371. $.ajax({
  1372. url: '/gcc/api/agents/savecall', // URL to your Spring Boot controller for handling POST
  1373. type: 'POST',
  1374. contentType: 'application/json',
  1375. data: JSON.stringify({
  1376. data_id: dataId,
  1377. agent_id: agentId,
  1378. campaign_id:campaignId,
  1379. call_status: action, // Use "call_status" as the key to match the controller parameter name
  1380. remarks: remarks
  1381. }),
  1382. success: function(response) {
  1383. console.log('Data Updated successfully:', response);
  1384. // Update the button and form fields after successful submission
  1385. Swal.fire({
  1386. title: 'Success!',
  1387. text: 'Data Updated successfully!',
  1388. icon: 'success',
  1389. timer: 2000,
  1390. showConfirmButton: false
  1391. })
  1392. },
  1393. error: function(xhr, status, error) {
  1394. console.error('Error submitting data:', error);
  1395. }
  1396. });
  1397. } */
  1398. function initializeAgentsDataTable() {
  1399. if (!$.fn.DataTable.isDataTable('#AgentDatatable')) {
  1400. $('#AgentDatatable').DataTable({
  1401. dom: 'Bftip',
  1402. columnDefs: [{ targets: 'no-sort', orderable: false }],
  1403. lengthMenu: [
  1404. [50, 100, 200, 500, -1],
  1405. ['50 rows', '100 rows', '200 rows', '500 rows', 'Show all']
  1406. ],
  1407. scrollY: '60vh',
  1408. fixedColumns: { left: 1, right: 1 },
  1409. buttons: [
  1410. { extend: 'pageLength', className: 'btn btn-warning' },
  1411. { extend: 'copyHtml5', text: 'Copy', className: 'btn btn-secondary' },
  1412. { extend: 'excelHtml5', text: 'Excel', className: 'btn btn-secondary' },
  1413. { extend: 'csvHtml5', text: 'CSV', className: 'btn btn-secondary' },
  1414. { extend: 'pdfHtml5', text: 'PDF', className: 'btn btn-secondary' }
  1415. ],
  1416. fixedHeader: true,
  1417. autoWidth: true,
  1418. responsive: true,
  1419. searching: true,
  1420. select: false,
  1421. processing: false
  1422. });
  1423. }
  1424. // Initialize the Pendingtasktable if it is not already initialized
  1425. if (!$.fn.DataTable.isDataTable('#Pendingtasktable')) {
  1426. $('#Pendingtasktable').DataTable({
  1427. dom: 'Bftip',
  1428. columnDefs: [{ targets: 'no-sort', orderable: false }],
  1429. lengthMenu: [
  1430. [50, 100, 200, 500, -1],
  1431. ['50 rows', '100 rows', '200 rows', '500 rows', 'Show all']
  1432. ],
  1433. scrollY: '60vh',
  1434. fixedColumns: { left: 1, right: 1 },
  1435. buttons: [
  1436. { extend: 'pageLength', className: 'btn btn-warning' },
  1437. { extend: 'copyHtml5', text: 'Copy', className: 'btn btn-secondary' },
  1438. { extend: 'excelHtml5', text: 'Excel', className: 'btn btn-secondary' },
  1439. { extend: 'csvHtml5', text: 'CSV', className: 'btn btn-secondary' },
  1440. { extend: 'pdfHtml5', text: 'PDF', className: 'btn btn-secondary' }
  1441. ],
  1442. fixedHeader: true,
  1443. autoWidth: true,
  1444. responsive: true,
  1445. searching: true,
  1446. select: false,
  1447. processing: false
  1448. });
  1449. }
  1450. }
  1451. //view url for specific id details
  1452. function ViewDetails(url) {
  1453. if(url)
  1454. {
  1455. window.open( url,'_blank');
  1456. }
  1457. else
  1458. { Swal.fire({
  1459. title: 'Error!',
  1460. text: 'NO Data Available!',
  1461. icon: 'error',
  1462. timer: 2000,
  1463. showConfirmButton: false
  1464. })
  1465. }
  1466. }
  1467. //whatsapp message function
  1468. /* function sendWhatsAppMessage(cellnumber, billNo, viewdetailsUrl) {
  1469. // Build the dynamic WhatsApp message URL
  1470. let msgUrl = `https://media.smsgupshup.com/GatewayAPI/rest?userid=2000233507&password=h2YjFNcJ&send_to=${cellnumber}&v=1.1&format=json&msg_type=IMAGE&method=SENDMEDIAMESSAGE&caption=Greetings+from+Greater+Chennai+Corporation%2C%0A%0AProperty+Bill+No+${billNo}%0A%0ASkip+the+hassle+and+pay+your+property+tax+easily+on+WhatsApp.+It%E2%80%99s+quick%2C+stress-free%2C+and+just+a+few+taps+away%21+%F0%9F%93%B2%0A%0ASimply+click+the+button+below+to+view+your+payment+details+and+complete+your+payment+today%21+%F0%9F%92%B8&media_url=https%3A%2F%2Fres.cloudinary.com%2Fdpub5muar%2Fimage%2Fupload%2Fv1727080053%2Fang8tqjqdcxuqoeiuvjl.jpg&isTemplate=true&cta_button_url=${encodeURIComponent(viewdetailsUrl)}`;
  1471. // Send the WhatsApp message
  1472. $.ajax({
  1473. url: '/gcc/api/whatsapp/send-whatsapp-message', // Replace with your service path
  1474. type: 'POST',
  1475. data: { msgUrl: msgUrl },
  1476. success: function(response) {
  1477. console.log('WhatsApp message sent successfully', response);
  1478. //alert('WhatsApp message sent!');
  1479. Swal.fire({
  1480. title: 'Success!',
  1481. text: 'Message sent successfully!',
  1482. icon: 'success',
  1483. timer: 2000,
  1484. showConfirmButton: false
  1485. })
  1486. },
  1487. error: function(xhr, status, error) {
  1488. console.error('Error sending WhatsApp message:', error);
  1489. //alert('Failed to send WhatsApp message.');
  1490. Swal.fire({
  1491. title: 'Error!',
  1492. text: 'Message Not sent!',
  1493. icon: 'error',
  1494. timer: 2000,
  1495. showConfirmButton: false
  1496. })
  1497. }
  1498. });
  1499. } */
  1500. </script>
  1501. </body>
  1502. </html>