1/******* Do not edit this file ******* 2Simple Custom CSS and JS - by Silkypress.com 3Saved: Nov 04 2023 | 03:43:24 */ 4/* Default comment here */ 5 function toggleDivVisibility(count) { 6 var x = document.getElementById("extraInfo" + count); 7 var image = document.getElementById("viewMoreButton" + count); 8 9 if(x != null){ 10 11 if (x.style.display === "none") { 12 x.style.display = "block"; 13 image.src = "https://sub.streetcare.us/wp-content/uploads/2023/10/viewLess.png" 14 } else { 15 x.style.display = "none"; 16 image.src = "https://sub.streetcare.us/wp-content/uploads/2023/10/viewMore.png" 17 18 } 19 } 20 } 21 function communityHelpPage() { 22 23 24 (function ($) { 25 let dataArr = []; 26 'use strict'; 27 $(document).ready(function () { 28 const showFirestoreDatabase = () => { 29 const db = firebase.firestore(); 30 const firestoreEl = jQuery('#custom-firebase'); 31 32 // You can get the collectionName and documentName from the shortcode attribute 33 const collectionName = 'visitLogNewForm'; 34 35 if (collectionName) { 36 const docRef = db.collection(collectionName); 37 dataArr = []; 38 39 docRef.get().then(querySnapshot => { 40 41 let currentPage = 1; 42const itemsPerPage = 10; 43 const filterNeedToggle = document.getElementById('filterNeedToggle').checked; 44 const filterSearchText = document.getElementById('filterSearchText').value.toLowerCase(); 45 46 querySnapshot.forEach(doc => { 47 const docId = doc.id; 48 const data = doc.data(); 49 const visitWhere = data['visitWhere']; 50 const visitWhen = parseAndConvertToStandardFormat(data['visitWhen']); 51 const isVisitWhenField = 'visitWhen' in data; 52 const peopleNeedFutherHelpDetail = data['peopleNeedFutherHelpDetail']; 53 const displayFields = [ 54 'visitWhen', 55 'visitWhere', 56 'peopleHelped', 57 'peopleHelpedDetail', 58 'whatGiven', 59 'peopleNeedFutherHelpDetail', 60 'futherHelpWhere', 61 'futherHelpTime', 62 'futherHelpKind', 63 'futherHelpDueDate', 64 'futherHelpAdditionalInf', 65 ]; 66 const whatGiven = data['whatGiven']; 67 const futherHelpKind = data['futherHelpKind']; 68 69 70 const visitWhereFilter = document.getElementById('filterVisitWhere').value.toLowerCase(); 71 const visitWhenFilter = document.getElementById('filterVisitWhen').value; // Get the filter value 72 73 // Check if the toggle is on and if peopleNeedFutherHelpDetail is not null 74 75 if ((!filterNeedToggle || typeof peopleNeedFutherHelpDetail !== "undefined") && 76 (visitWhereFilter === '' || visitWhere.toLowerCase().includes(visitWhereFilter)) && 77 (visitWhenFilter === '' || (isVisitWhenField && visitWhen.includes(visitWhenFilter))) 78 && 79 (filterSearchText === '' || displayFields.some(field => data[field] && typeof data[field] === 'string' && data[field].toLowerCase().includes(filterSearchText)) 80 || 81 (Array.isArray(whatGiven) && whatGiven.some(item => item.toLowerCase().includes(filterSearchText))) 82 83 84 || 85 (Array.isArray(futherHelpKind) && futherHelpKind.some(item => item.toLowerCase().includes(filterSearchText))) 86 87 ) 88 89 ) { // Check for visitWhen filter 90 dataArr.push({ visitWhere, visitWhen, data, docId }); 91 } 92 }); 93 94 const isChecked = document.getElementById('filterNeedToggle').checked; 95 96 97 98 99 // Sort data by visitWhen in descending order (most recent to least recent) 100 dataArr.sort((a, b) => b.visitWhen.localeCompare(a.visitWhen)); 101 102 103 104 // Clear the existing table data 105 106 107 // Wrap the table in a container div 108 // Close the heading row 109 let count = 0; 110 function updateTableData() { 111 const startIndex = (currentPage - 1) * itemsPerPage; 112 const endIndex = startIndex + itemsPerPage; 113 const dataToDisplay = dataArr.slice(startIndex, endIndex); 114 115 // Clear the existing table data 116 const tableBody = document.getElementById('myTable'); 117 tableBody.innerHTML = ''; 118 let html = '<div class="table-container">'; 119 // 120 dataToDisplay.forEach(entry => { 121 122 html += '<div class="table-row">'; // Use a div for each row 123 124 // Loop through the display fields 125 const displayFields = [ 126 'visitWhen', 127 'visitWhere', 128 'peopleHelped', 129 'peopleHelpedDetail', 130 'whatGiven', 131 'peopleNeedFutherHelpDetail', 132 'futherHelpWhere', 133 'futherHelpTime', 134 'futherHelpKind', 135 'futherHelpDueDate', 136 'futherHelpAdditionalInf', 137 138 ]; 139 140 let visitWhen; 141 let visitWhere; 142 let peopleHelped; 143 let peopleHelpedDetail; 144 let whatGiven; 145 let willContinue = null; 146 let futherHelpWhere; 147 let futherHelpTime; 148 let futherHelpKind;
149 let futherHelpDueDate; 150 let futherHelpAdditionalInf; 151 let whatGivenArray; 152 let peopleNeedFutherHelpDetail; 153 let kind; 154 155 156 157 displayFields.forEach(field => { 158 visitWhen = convertToElapsedTime(entry['visitWhen']); 159 visitWhere = entry.data['visitWhere'] 160 peopleHelped = entry.data['peopleHelped']; 161 peopleHelpedDetail = entry.data['peopleHelpedDetail']; 162 163 if (field === 'whatGiven' && entry.data[field] !== null) { 164 // Display the visitWhen as elapsed time (seconds, minutes, hours, or date and time) 165 if (entry && entry.data && field && entry.data[field] && Array.isArray(entry.data[field])) { 166 whatGiven = entry.data[field].join(', '); 167 whatGivenArray = entry.data[field]; 168 169 } 170 } 171 172 if (field === 'peopleNeedFutherHelpDetail' && typeof entry.data[field] !== 'undefined') { 173 peopleNeedFutherHelpDetail = entry.data["peopleNeedFutherHelpDetail"] 174 willContinue = entry.data[field]; 175 futherHelpWhere = entry.data['futherHelpWhere']; 176 futherHelpTime = entry.data['futherHelpTime']; 177 futherHelpKind = entry.data['futherHelpKind'].join(', '); 178 kind = entry.data['futherHelpKind']; 179 futherHelpDueDate = entry.data['futherHelpDueDate']; 180 futherHelpAdditionalInf = entry.data['futherHelpAdditionalInf']; 181 } 182 }); 183 184 html += ` 185<div class="container"> 186 <div class="grid-item" id="mainLocation" style="margin-bottom:1rem;">${visitWhere}</div> 187 <div class="grid-item"> 188 <span class="label">Helped: </span> 189 <span class="content">${peopleHelpedDetail}<br/></span> 190 <span class="label">Number of people helped: </span> 191 <span class="content">${peopleHelped}<br/></span> 192 </div> 193 <div class="grid-item"> 194 <div class="help-container"> 195 <div class="grid-container"> 196`; 197 198 if (whatGiven !== null && typeof whatGiven !== 'undefined') { 199 for (let i = 0; i < whatGivenArray.length; i++) { 200 var words = whatGivenArray[i].split(/[\s/]+/); 201 var iconTag = "iconTags" + words[0]; 202 html += ` 203 <div class="custom${iconTag}"> 204 <img class="${iconTag}" alt="${words[0]}"> 205 </div> 206 `; 207 } 208 } 209 210 html += ` 211 </div> 212 </div> 213 </div> 214 <div class="grid-item" style="opacity:0.6"> 215 ${visitWhen} 216 </div> 217 <div class="grid-item">`; 218 if (willContinue !== null) { 219 html += `<div class="custom-container">I need help<br/></div> 220 <div class="viewMoreLabel"> 221 <button onclick="toggleDivVisibility(${count}) " class = "t1"> 222 View More 223 <img id="viewMoreButton${count}" src="https://sub.streetcare.us/wp-content/uploads/2023/10/viewMore.png" alt="Image Placeholder" style="width:1rem;height:1rem;display:inline-block;"/> 224 </button> 225 </div>`; 226 227 } 228 html += ` </div> 229 <br/> 230</div> 231</div> 232<div> 233 <div id="extraInfo${count}" class="extrainfo" style="display: none;"> 234 <div> 235 <div> 236 <span class="label">Help required by:</span> 237 <span class="content">${peopleNeedFutherHelpDetail}<br/></span> 238 <span class="label">Location:</span> 239 <span class="content">${futherHelpWhere}<br/></span> 240 <span class="label">Date:</span> 241 <span class="content">${futherHelpTime}<br/></span> 242 </div> 243 <div class="help-container"> 244 <div class="label">Help Provided:</div> 245 <div class="grid-container">`; 246 if (whatGiven !== null && typeof whatGiven !== 'undefined') { 247 for (let i = 0; i < whatGivenArray.length; i++) { 248 var words = whatGivenArray[i].split(/[\s/]+/); 249 var iconTag = "MainTags" + words[0]; 250 251 html += ` 252 <div class="custom${iconTag}"> 253 <img class="${iconTag}" alt="${words[0]}"> 254 ${whatGivenArray[i]} 255 </div> 256 `; 257 } 258 } 259 html += `</div> 260 </div><br /> 261 <div class="help-container"> 262 <div class="label">Further help needed:</div> 263 <div class="grid-container">`; 264 if (futherHelpKind !== null && typeof futherHelpKind !== 'undefined') { 265 for (let i = 0; i < kind.length; i++) { 266 var words = kind[i].split(/[\s/]+/); 267 var iconTag = "MainTags" + words[0]; 268 269 html += ` 270 <div class="custom${iconTag}"> 271 <img class="${iconTag}" alt="${words[0]}"> 272 ${kind[i]} 273 </div> 274 `; 275 } 276 } 277 html += `</div> 278 </div> 279<div> 280<span class="label">Follow-up Date :</span>
281 <span class="content">${futherHelpDueDate}<br/></span> 282<span class="label">Information:</span> 283 <span class="content">${futherHelpAdditionalInf}<br/></span> 284 285</div> 286 </div> 287 </div> 288 289 290`; 291 count++; 292 293 }); 294 295 296 document.getElementById('currentPage').textContent = `Page ${currentPage}`; 297 firestoreEl.html(html); 298 } 299 document.getElementById('prevPage').addEventListener('click', () => { 300 if (currentPage > 1) { 301 currentPage--; 302 updateTableData(); 303 } 304 }); 305 306 document.getElementById('nextPage').addEventListener('click', () => { 307 const totalPages = Math.ceil(dataArr.length / itemsPerPage); 308 if (currentPage < totalPages) { 309 currentPage++; 310 updateTableData(); 311 } 312 }); 313 314 // Initial data display 315 updateTableData(); 316 317 318 if (isChecked) { 319 for (let i = 0; i < dataArr.length; i++) { 320 321 const extraInfoDiv = document.getElementById('extraInfo' + i); 322 extraInfoDiv.style.display = 'block'; 323 } 324 } 325 326 327 }).catch(error => { 328 console.error('Error fetching data:', error); 329 }); 330 } else { 331 console.warn('Please check your collection name in the shortcode!'); 332 } 333 }; 334 335 // 336 337 338 339 const parseAndConvertToStandardFormat = (dateString) => { 340 // Check if the dateString is in a recognized format 341 const dateFormats = [ 342 /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{3}Z)?$/, 343 /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/, 344 /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}$/, 345 /^\d{4}-\d{1,2}-\d{1,2} \d{2}:\d{2}:\d{2}$/, 346 /^\d{4}-\d{1,2}-\d{1,2} \d{2}:\d{2}$/, 347 /^\d{1,2}\/\d{1,2}\/\d{4} \d{1,2}:\d{2}:\d{2}$/, 348 ]; 349 350 for (const format of dateFormats) { 351 if (format.test(dateString)) { 352 // Parse the recognized format 353 const date = new Date(dateString); 354 return date.toISOString().slice(0, 19).replace('T', ' '); 355 } 356 } 357 358 return dateString; // Unrecognized format, return as is 359}; 360 361 const convertToElapsedTime = (timestamp) => { 362 const now = new Date().getTime(); 363 const parsedTimestamp = new Date(timestamp); 364 const diffInMilliseconds = now - parsedTimestamp; 365 const diffInSeconds = Math.floor(diffInMilliseconds / 1000); 366 const diffInMinutes = Math.floor(diffInSeconds / 60); 367 const diffInHours = Math.floor(diffInMinutes / 60); 368 369 if (diffInSeconds < 60 && diffInSeconds > 0) { 370 return diffInSeconds + ' seconds ago'; 371 } else if (diffInMinutes < 60 && diffInSeconds > 0) { 372 return diffInMinutes + ' minutes ago'; 373 } else if (diffInHours < 24 && diffInSeconds > 0) { 374 return diffInHours + ' hours ago'; 375 } else { 376 // Format as date and time 377 const year = parsedTimestamp.getFullYear();
378 const month = (parsedTimestamp.getMonth() + 1).toString().padStart(2, '0'); // Month is zero-based 379 const day = parsedTimestamp.getDate().toString().padStart(2, '0'); 380 const hours = parsedTimestamp.getHours().toString().padStart(2, '0'); 381 const minutes = parsedTimestamp.getMinutes().toString().padStart(2, '0'); 382 const formattedDate = `${year}-${month}-${day} ${hours}:${minutes}`; 383 return formattedDate; 384 } 385 }; 386 387 const waitForFirebase = setInterval(() => { 388 if (typeof firebase !== 'undefined' && firebase.apps.length) { 389 showFirestoreDatabase(); 390 clearInterval(waitForFirebase); 391 } 392 }, 1000); 393 394 395 // Add event listeners to both filter input fields 396 const filterVisitWhereInput = document.getElementById('filterVisitWhere'); 397 const filterVisitWhenInput = document.getElementById('filterVisitWhen'); // Get the filter input for visitWhen 398 const filterSearchTextInput = document.getElementById('filterSearchText'); // Get the filter input for visitWhen 399 400 401 filterVisitWhereInput.addEventListener('input', showFirestoreDatabase); 402 filterVisitWhenInput.addEventListener('input', showFirestoreDatabase); 403 filterSearchTextInput.addEventListener('input', showFirestoreDatabase); 404 405 // Add event listener for visitWhen filter 406 document.getElementById('filterNeedToggle').addEventListener('change', showFirestoreDatabase); // Add event listener for the toggle checkbox 407 408 409 }); 410 })(jQuery); 411}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.