PageSourceSearch

https://www.admiraltaverns.co.uk/wp-content/themes/customsite/js/portal-scripts.js?ver=1877968803090007

js admiraltaverns.co.uk collected 2026-10-02 19:50:35 UTC 27,480 bytes, 879 lines download raw bytes

1// when the page is first loaded.
2jQuery(document).ready(function () {
3
4	console.log('test');
5
6	jQuery(function () {
7		jQuery('[data-toggle="tooltip"]').tooltip({
8			trigger: 'click' // Show tooltip on click
9		});
10	});
11
12	// clear the upload from the file uploader on click.
13	if (jQuery('#coderra_clear_document_upload').length > 0) {
14
15		document.getElementById("coderra_clear_document_upload").addEventListener("click", function () {
16
17			document.getElementById("coderra_document_upload").value = "";
18
19		});
20
21	}
22
23	// on click of edit set the upload id.
24	jQuery(document).on('click', '.at-document-edit', function (e) {
25
26		var data_document_id = jQuery(this).attr('data-document-id');
27		jQuery('input#data-document-id').val(data_document_id);
28
29	});
30
31	// on close remove the document id and hide the notices.
32	jQuery("#coderra_documents_modal").on('hide.bs.modal', function () {
33
34		jQuery('input#data-document-id').val('');
35		jQuery('#coderra_document_form_response').empty().addClass('d-none');
36
37	});
38
39	// on close remove the file preview.
40	jQuery("#coderra_documents_preview_modal").on('hide.bs.modal', function () {
41
42		jQuery('#coderra_documents_preview_modal .modal-body').empty();
43
44	});
45
46	// Submit for for uploads.
47	jQuery(document).on('click', '#coderra_document_upload_submit', function (e) {
48
49		e.preventDefault();
50
51		var fd = new FormData();
52		var fileInput = jQuery('#coderra_document_upload')[0].files[0];
53		var data_document_id = jQuery('input#data-document-id').val();
54
55		console.log(fileInput);
56
57		// Check if a file is selected
58		if (fileInput) {
59
60			// Append the selected file to FormData
61			fd.append('file', fileInput);
62
63			// Guest support: if logged out, pass guest identifiers so PHP routes to /at-temp-docs/.
64			if (typeof coderra_tenancy_is_logged_in === 'function' && !coderra_tenancy_is_logged_in()) {
65
66				var guestEmail = String(jQuery('#coderra_guest_verified_email').val() || '').trim().toLowerCase();
67				var guestAppId = String(jQuery('#coderra_guest_app_id').val() || '').trim();
68
69				if (!guestEmail || !guestAppId) {
70
71					// Re-enable buttons and show message.
72					jQuery('#coderra_document_upload_submit').removeClass('disabled');
73					jQuery('#coderra_clear_document_upload').removeClass('disabled');
74					jQuery('#coderra_document_form_response').html('<div class="alert alert-danger"><p class="mb-0"><strong>Please verify your email token before uploading documents.</strong></p></div>');
75
76					return;
77				}
78
79				fd.append('guest_email', guestEmail);
80				fd.append('guest_app_id', guestAppId);
81			}
82
83			// Add other data to FormData if needed
84			fd.append('action', 'coderra_document_upload_action');
85			fd.append('data_document_id', data_document_id);
86
87			jQuery.ajax({
88				type: 'POST',
89				url: coderra_document_upload_action.ajax_url,
90				data: fd,
91				contentType: false,
92				processData: false,
93				beforeSend: function (xhr) {
94
95					// disable the buttons.
96					jQuery('#coderra_document_upload_submit').addClass('disabled');
97					jQuery('#coderra_clear_document_upload').addClass('disabled');
98
99					// let the user know what is happening.
100					jQuery('#coderra_document_form_response').html('<div class="alert alert-warning"><p class="mb-0"><strong>Uploading... Please wait.</strong></p></div>');
101
102				},
103				error: function (error) {
104
105					// enable the buttons.
106					jQuery('#coderra_document_upload_submit').removeClass('disabled');
107					jQuery('#coderra_clear_document_upload').removeClass('disabled');
108
109					// Handle the error response
110					jQuery('#coderra_document_form_response').html('<div class="alert alert-danger"><p class="mb-0"><strong>Error uploading the file.</strong></p></div>');
111				},
112				success: function (response) {
113
114					console.log(response);
115
116					// enable the buttons.
117					jQuery('#coderra_document_upload_submit').removeClass('disabled');
118					jQuery('#coderra_clear_document_upload').removeClass('disabled');
119
120					// Handle the success response.
121					jQuery('#coderra_document_form_response').html('<div class="alert alert-success"><p class="mb-0"><strong>Upload successful!</strong></p></div>');
122
123					// Notify other scripts (e.g. custom tenancy form) that a document has been uploaded.
124					jQuery(document).trigger('coderra:documentUploaded', [data_document_id, response]);
125
126					// Reset the file input for convenience.
127					jQuery('#coderra_document_upload').val('');
128
129					// Find the card element with the specified document ID.
130					var cardElement = jQuery('.card[data-document-id="' + data_document_id + '"]');
131
132					// Check if the card element is found.
133					if (cardElement.length > 0) {
134
135						cardElement.find('.at-document-user-modified-date').html(response.data.modified_date);
136
137						// Update document actions
138						// Update document actions
139						var actionsHTML =
140							'<div class="at-document-action-button at-document-preview d-inline px-2" ' +
141							'data-bs-toggle="modal" data-bs-target="#coderra_documents_preview_modal" ' +
142							'data-document-action="at_preview_document" data-document-id="' + data_document_id + '">' +
143							'Preview' +
144							'</div>' +
145							'<div class="at-document-action-button at-document-edit d-inline px-2" ' +
146							'data-bs-toggle="modal" data-bs-target="#coderra_documents_modal" ' +
147							'data-document-action="at_edit_document" data-document-id="' + data_document_id + '">' +
148							'Edit' +
149							'</div>' +
150							'<div class="at-document-action-button at-document-download d-inline px-2" ' +
151							'data-document-action="at_download_document" data-document-id="' + data_document_id + '">' +
152							'Download' +
153							'</div>' +
154							'<div class="at-document-action-button at-document-remove d-inline px-2" ' +
155							'data-document-action="at_remove_document" data-document-id="' + data_document_id + '">' +
156							'<i class="fas fa-times-circle"></i>' +
157							'</div>';
158
159						cardElement.find('.at-document-actions').html(actionsHTML);
160					}
161
162					// Set a timeout to add the 'd-none' class after 3000 milliseconds (3 seconds)
163					setTimeout(function () {
164						jQuery('#coderra_document_form_response').empty();
165					}, 3000);
166
167					// clear the upload form.
168					document.getElementById("coderra_document_upload").value = "";
169
170					// Set a timeout to add the 'd-none' class after 3000 milliseconds (3 seconds)
171					setTimeout(function () {
172						jQuery('#coderra_documents_modal').modal('hide');
173					}, 3000);
174				}
175			});
176		}
177	});
178
179	// Trigger the download on button click
180	jQuery(document).on('click', '.at-document-download', function (e) {
181
182		e.preventDefault();
183
184		var document_id = jQuery(this).attr('data-document-id');
185
186		// Create a form element dynamically
187		var form = document.createElement('form');
188		form.method = 'POST';
189		form.action = coderra_document_upload_action.ajax_url;
190
191		// Create an input field for document_id
192		var input = document.createElement('input');
193		input.type = 'hidden';
194		input.name = 'document_id';
195		input.value = document_id;
196
197		// Append the input to the form
198		form.appendChild(input);
199
200		// Create an input field for the action
201		var actionInput = document.createElement('input');
202		actionInput.type = 'hidden';
203		actionInput.name = 'action';
204		actionInput.value = 'coderra_document_download_action';
205
206		// Append the action input to the form
207		form.appendChild(actionInput);
208
209		// Create an input field for the action_type
210		var actionTypeInput = document.createElement('input');
211		actionTypeInput.type = 'hidden';
212		actionTypeInput.name = 'action_type';
213		actionTypeInput.value = 'download';
214
215		// Append the form to the body
216		document.body.appendChild(form);
217
218		// Submit the form
219		form.submit();
220
221		// Remove the form from the body after submission
222		document.body.removeChild(form);
223	});
224
225
226	// Trigger the image preview.
227	jQuery(document).on('click', '.at-document-preview', function (e) {
228
229		e.preventDefault();
230
231		var document_id = jQuery(this).attr('data-document-id');
232
233		// set the modal.
234		const modalBody = jQuery('#coderra_documents_preview_modal .modal-body');
235
236		// Add a loader and update title.
237		modalBody.html('<p>Loading...</p>');
238
239		// Perform AJAX request to fetch the document content and type for preview
240		jQuery.ajax({
241			type: 'POST',
242			url: coderra_document_upload_action.ajax_url,
243			data: {
244				action: 'coderra_document_preview_action',
245				document_id: document_id,
246				action_type: 'preview'  // Specify the action type as preview
247			},
248			beforeSend: function () {
249				modalBody.html('<iframe id="viewer-iframe" style="width: 100%; height: 500px; border: none;" hidden></iframe>');
250			},
251			success: function (response) {
252
253				console.log(response);
254
255				if (response.success && response.data.url) {
256					const fileUrl = response.data.url;
257					const iframe = document.getElementById('viewer-iframe');
258
259					if (iframe) {
260						iframe.src = fileUrl;
261						iframe.hidden = false; // Display the iframe
262					} else {
263						modalBody.html('<p>Failed to initialize viewer. Please try again.</p>');
264					}
265				} else {
266					modalBody.html(`<p>Error loading document: ${response.data.message}</p>`);
267				}
268			},
269			error: function (error) {
270				console.log('AJAX Error:', error);
271				modalBody.html('<p>Failed to load content.</p>');
272			},
273		});
274	});
275
276
277	jQuery(document).on('click', '.at-document-remove', function (e) {
278
279		e.preventDefault();
280
281		var documentId = jQuery(this).attr('data-document-id');
282
283		// Show confirmation dialog
284		if (confirm('Are you sure you want to delete this upload?')) {
285
286			var defaultDocID = jQuery(this).closest('.card').attr('data-document-id');
287			var cardBody = jQuery(this).closest('.card-body');
288
289			// AJAX call to delete the file
290			jQuery.ajax({
291				type: 'POST',
292				url: coderra_document_upload_action.ajax_url,
293				data: {
294					action: 'coderra_document_remove_action',
295					document_id: documentId
296				},
297				success: function (response) {
298
299					if (response.success) {
300
301						alert('File deleted successfully.');
302
303						cardBody.find('.at-document-user-modified-date').empty();
304						cardBody.find('.at-document-actions').empty();
305
306						// Re-add the default upload button
307						var defaultState = '<div class="at-document-action-button at-document-edit d-inline px-2" ' +
308							'data-bs-toggle="modal" data-bs-target="#coderra_documents_modal" ' +
309							'data-document-action="at_edit_document" data-document-id="' + defaultDocID + '">' +
310							'Upload' +
311							'</div>';
312
313						cardBody.find('.at-document-actions').html(defaultState);
314
315					} else {
316
317						// Error deleting file
318						alert('Error deleting file: ' + response.data.message);
319					}
320				},
321				error: function (xhr, status, error) {
322
323					alert('Error: ' + error);
324				}
325			});
326		} else {
327			// User clicked Cancel, do nothing
328			return false;
329		}
330	});
331
332	// make updates to the user profile.
333	jQuery('#portal_profile_form').submit(function (event) {
334
335		event.preventDefault();
336
337		// Get form data
338		var formData = jQuery(this).serialize();
339		var redirect = coderra_document_upload_action.matches_url;
340
341		// Validate required profile fields.
342		var errors = [];
343
344		if (!jQuery('#pub_locations').val()) {
345			errors.push('Please select a preferred location.');
346		}
347
348		if (!jQuery('input[name="user_pub_agreements"]:checked').length) {
349			errors.push('Please select an agreement type.');
350		}
351
352		if (errors.length) {
353
354			jQuery('.portal_profile_form_notice').html(errors.join('<br>'));
355
356			jQuery('.portal_profile_form_alert')
357				.removeClass('d-none alert-success alert-dismissible fade show')
358				.addClass('alert-danger')
359				.css('display', 'block');
360
361			jQuery('html, body').animate({
362				scrollTop: jQuery('.portal_profile_form_alert').offset().top - 120
363			}, 300);
364
365			return;
366		}
367
368		jQuery.ajax({
369			type: 'POST',
370			url: coderra_document_upload_action.ajax_url,
371			dataType: 'json',
372			data: formData + '&action=coderra_portal_profile_action',
373
374			success: function (response) {
375
376				if (response && response.success) {
377
378					jQuery('.portal_profile_form_notice').text(
379						response.data && response.data.message ? response.data.message : 'Updated!'
380					);
381
382					jQuery('.portal_profile_form_alert')
383						.removeClass('d-none alert-danger')
384						.addClass('alert-success');
385
386					setTimeout(function () {
387						jQuery('.portal_profile_form_notice').empty();
388						jQuery('.portal_profile_form_alert').addClass('d-none');
389					}, 3000);
390
391					if (redirect) {
392						window.location.href = redirect;
393					}
394
395					return;
396				}
397
398				jQuery('.portal_profile_form_notice').text(
399					response && response.data && response.data.message
400						? response.data.message
401						: 'Error submitting the form. Please try again.'
402				);
403
404				jQuery('.portal_profile_form_alert')
405					.removeClass('d-none alert-success')
406					.addClass('alert-danger');
407			},
408
409			error: function (xhr) {
410
411				var message = 'Error submitting the form. Please try again.';
412
413				if (
414					xhr &&
415					xhr.responseJSON &&
416					xhr.responseJSON.data &&
417					xhr.responseJSON.data.message
418				) {
419					message = xhr.responseJSON.data.message;
420				}
421
422				jQuery('.portal_profile_form_notice').text(message);
423
424				jQuery('.portal_profile_form_alert')
425					.removeClass('d-none alert-success')
426					.addClass('alert-danger');
427			}
428		});
429	});
430
431	// portal filter.
432	if (jQuery('#admiral_portal_matches').length > 0) {
433
434		// match the height of the cards.
435		jQuery('#admiral_portal_matches .card-body').matchHeight({ byRow: true });
436
437		// update the page and pub count.
438		admiral_update_portal_filter();
439
440		jQuery('#admiral_portal_matches .grid-item').each(function () {
441
442			let exclude_id = jQuery(this).find('a.pub-card').attr('data-pub-id');
443
444			// Find the .favourite-this div and append after it
445			jQuery(this).find('.favourite-this').after('<div class="exclude-this" data-exclude="' + exclude_id + '"><i class="fas fa-2x fa-times"></i></div>');
446		});
447
448	}
449
450	jQuery(document).on('click', '.portal-match-control', function (e) {
451
452		jQuery('.portal-match-control.active').removeClass('active');
453		jQuery(this).addClass('active');
454
455		var portal_filter_action = jQuery(this).attr('data-filter-action');
456		var portal_filter_page = 1;
457
458		jQuery.ajax({
459			url: coderra_document_upload_action.ajax_url,
460			data: {
461				portal_filter_action: portal_filter_action,
462				portal_filter_page: portal_filter_page,
463				action: 'coderra_portal_matches_action',
464			},
465			type: 'POST',
466			success: function (data) {
467
468				if (data.length > 0) {
469
470					// update the matches.
471					jQuery('#admiral_portal_matches').html(data);
472
473					jQuery('#admiral_portal_matches .card-body').matchHeight({ byRow: true });
474
475					if (portal_filter_action !== 'favourites') {
476
477						jQuery('#admiral_portal_matches .grid-item').each(function () {
478
479							let exclude_id = jQuery(this).find('a.pub-card').attr('data-pub-id');
480
481							// Find the .favourite-this div and append after it
482							jQuery(this).find('.favourite-this').after('<div class="exclude-this" data-exclude="' + exclude_id + '"><i class="fas fa-2x fa-times"></i></div>');
483						});
484					}
485
486					// update the page and pub count.
487					admiral_update_portal_filter();
488
489				} else {
490
491					// update the matches.
492					jQuery('#admiral_portal_matches').html(data);
493
494					jQuery('.portal_filter_count').text('0');
495					jQuery('.portal_page_number').text('1');
496
497				}
498			},
499		});
500	});
501
502	jQuery(document).on('click', '#portal_pagination ul.pagination li', function () {
503
504		// sort out all the active classes.
505		if (!jQuery(this).hasClass('active')) {
506
507			jQuery('#portal_pagination ul.pagination li.active').removeClass('active');
508			jQuery('#portal_pagination ul.pagination li.active a').removeClass('current');
509
510			jQuery(this).addClass('active');
511			jQuery(this).find('a.nav-link').addClass('current');
512
513		}
514
515		// set the action and page for the filter.
516		var portal_filter_action = jQuery('.portal-match-control.active').attr('data-filter-action');
517		var portal_filter_page = parseInt(jQuery('ul.pagination li.active a.current').attr('data-page'));
518
519		// update the filter with our values.
520		jQuery('.portal_page_number').html(portal_filter_page);
521
522		jQuery.ajax({
523			url: coderra_document_upload_action.ajax_url,
524			data: {
525				portal_filter_action: portal_filter_action,
526				portal_filter_page: portal_filter_page,
527				action: 'coderra_portal_matches_action',
528			},
529			type: 'POST',
530			success: function (data) {
531
532				if (data.length > 0) {
533
534					// update the matches.
535					jQuery('#admiral_portal_matches').html(data);
536
537					// match the heights.
538					jQuery('#admiral_portal_matches .card-body').matchHeight({ byRow: true });
539
540				}
541			},
542		});
543
544		jQuery('html, body').animate({ scrollTop: jQuery('.portal_matches_controls').offset().top - 50 }, 1000);
545
546	});
547
548	jQuery(document).on('click', '.exclude-this', function () {
549
550		let exclude_id = jQuery(this).attr('data-exclude');
551		let this_exclude = jQuery(this).closest('.grid-item');
552		let storedExcludeId = exclude_id;
553
554		// AJAX request to get the image path for preview
555		jQuery.ajax({
556			url: coderra_document_upload_action.ajax_url,
557			data: {
558				exclude_id: storedExcludeId,
559				action: 'coderra_excludes_action',
560			},
561			type: 'POST',
562			success: function (data) {
563
564				if (jQuery('.portal-recommended-pub-wrapper').length > 0) {
565
566					// AJAX request to get the image path for preview
567					jQuery.ajax({
568						url: coderra_document_upload_action.ajax_url,
569						data: {
570							action: 'coderra_portal_recommended_pubs_action',
571						},
572						type: 'POST',
573						beforeSend: function (xhr) {
574
575							jQuery('.portal-recommended-pub-wrapper').addClass('disabled');
576							jQuery('.portal-recommended-pub-wrapper .coderra-loader').removeClass('d-none');
577
578						},
579						success: function (data) {
580
581							// replace the data.
582							jQuery('.portal-recommended-pub-wrapper').replaceWith(data);
583
584							initialize_light_slider();
585
586							jQuery(this_exclude).remove();
587
588							let portal_filter_count = parseInt(jQuery('.portal_filter_count').text());
589							let filter_new_count = portal_filter_count - 1;
590							jQuery('.portal_filter_count').html(filter_new_count);
591
592							jQuery('.portal-recommended-pub-wrapper').removeClass('disabled');
593							jQuery('.portal-recommended-pub-wrapper .coderra-loader').addClass('d-none');
594
595						},
596					});
597				} else {
598
599					// remove it.
600					jQuery(this_exclude).remove();
601
602					let portal_filter_count = parseInt(jQuery('.portal_filter_count').text());
603					let filter_new_count = portal_filter_count - 1;
604					jQuery('.portal_filter_count').html(filter_new_count);
605
606					// match the heights.
607					jQuery('#admiral_portal_matches .card-body').matchHeight({ byRow: true });
608
609				}
610			},
611		});
612	});
613
614	// Submit for for uploads.
615	jQuery(document).on('click', '#gform_wrapper_4 .applicant-1-passport .ginput_container_fileupload:not(.no-user-file), #gform_wrapper_4 .applicant-1-license .ginput_container_fileupload:not(.no-user-file), #gform_wrapper_4 .applicant-1-address .ginput_container_fileupload:not(.no-user-file), #gform_wrapper_4 .applicant-2-passport .ginput_container_fileupload:not(.no-user-file), #gform_wrapper_4 .applicant-2-license .ginput_container_fileupload:not(.no-user-file), #gform_wrapper_4 .applicant-2-address .ginput_container_fileupload:not(.no-user-file)', function (e) {
616
617		// If the button is disabled, do nothing.
618		if (jQuery(this).find('.gform_button_select_files').prop('disabled') === true) {
619			return;
620		}
621
622		// Check if file has this doc class.
623		if (jQuery(this).closest('.gfield').hasClass('no-user-file')) {
624			return;
625		}
626
627		// Only stop default actions if the modal is not open.
628		if (!jQuery('body').hasClass('modal-open')) {
629
630			e.preventDefault();
631
632		} else {
633
634			return;
635		}
636
637		// Determine document type based on the clicked element's class.
638		let document_id = null;
639		let field = jQuery(this).closest('.gfield');
640
641		// determine the document id.
642		if (jQuery(this).closest('.applicant-1-passport').length) {
643			document_id = 32122;
644		} else if (jQuery(this).closest('.applicant-1-license').length) {
645			document_id = 32124;
646		} else if (jQuery(this).closest('.applicant-1-address').length) {
647			document_id = 32126;
648		} else if (jQuery(this).closest('.applicant-2-passport').length) {
649			document_id = 32123;
650		} else if (jQuery(this).closest('.applicant-2-license').length) {
651			document_id = 32125;
652		} else if (jQuery(this).closest('.applicant-2-address').length) {
653			document_id = 32127;
654		}
655
656		// If no valid document_id is determined, do nothing.
657		if (!document_id) {
658			return;
659		}
660
661		// Flag to prevent multiple triggers
662		if (field.data('upload-triggered')) {
663			return;
664		}
665		field.data('upload-triggered', true); // Set flag
666
667		var button_id = jQuery(this).find('.gform_button_select_files').attr('id');
668		var field_id = jQuery(this).closest('.gfield').attr('id');
669		var form_id = jQuery(this).closest('form').attr('id');
670
671		// set the modal.
672		const modalBody = jQuery('#coderra_show_user_documents .modal-body');
673
674		// Update the buttons for selecting a document.
675		jQuery('#portal-form-select-doc').attr('data-document-id', document_id);
676		jQuery('#portal-form-select-doc').attr('data-browse-btn', button_id);
677		jQuery('#portal-form-select-doc').attr('data-field-id', field_id);
678		jQuery('#portal-form-select-doc').attr('data-form-id', form_id);
679
680		// Update the buttons for uploading docs.
681		jQuery('#portal-form-upload-new').attr('data-browse-btn', button_id);
682
683		// Perform AJAX request to fetch the document content and type for preview
684		jQuery.ajax({
685			type: 'POST',
686			url: coderra_document_upload_action.ajax_url,
687			data: {
688				action: 'coderra_document_preview_action',
689				document_id: document_id,
690				action_type: 'preview',
691			},
692			beforeSend: function () {
693				modalBody.html('');
694			},
695			success: function (response) {
696
697				if (response.success && response.data.url) {
698
699					// Add the html to the modal.
700					modalBody.html('<iframe id="viewer-iframe" style="width: 100%; height: 500px; border: none;" hidden></iframe>');
701
702					// Show the modal.
703					jQuery('#coderra_show_user_documents').modal('show');
704
705					const fileUrl = response.data.url;
706					const iframe = document.getElementById('viewer-iframe');
707					const fileName = response.data.uploaded_filename;
708
709					// Update the file name.
710					jQuery('#portal-form-select-doc').attr('data-document-name', fileName);
711
712					if (iframe) {
713						iframe.src = fileUrl;
714						iframe.hidden = false; // Display the iframe
715					} else {
716						modalBody.html('<p>Failed to initialize viewer. Please try again.</p>');
717					}
718
719					field.data('upload-triggered', false); // Reset flag
720
721				} else {
722					// Only trigger file upload once
723					if (!field.hasClass('no-user-file')) {
724						field.addClass('no-user-file');
725
726						setTimeout(function () {
727							jQuery('#' + button_id).trigger('click');
728						}, 100);
729					}
730
731					field.data('upload-triggered', false); // Reset flag
732				}
733			},
734			error: function (error) {
735				console.log('AJAX Error:', error);
736				modalBody.html('<p>Failed to load content.</p>');
737				field.data('upload-triggered', false); // Reset flag
738			},
739		});
740	});
741
742	// Submit for for uploads.
743	jQuery(document).on('click', '#portal-form-upload-new', function (e) {
744
745		// Get the button.
746		var btn = jQuery(this).attr('data-browse-btn');
747
748		// Hide the modal and show the GF uploader.
749		jQuery('#coderra_show_user_documents').modal('hide');
750		jQuery('#' + btn).trigger('click');
751
752	});
753
754	// Submit for for uploads.
755	jQuery(document).on('click', '#portal-form-select-doc', function (e) {
756
757		e.preventDefault();
758
759		var btn = jQuery(this).attr('data-browse-btn');
760		var document_id = jQuery(this).attr('data-document-id');
761		var field_id = jQuery(this).attr('data-field-id');
762		var file_name = jQuery(this).attr('data-document-name');
763		var form_id = jQuery(this).attr('data-form-id');
764
765		// Perform AJAX request to fetch the document content and type for preview
766		jQuery.ajax({
767			type: 'POST',
768			url: coderra_document_upload_action.ajax_url,
769			data: {
770				action: 'coderra_document_preview_action',
771				document_id: document_id,
772				action_type: 'gravity_tmp',
773				field_id: field_id,
774				form_id: form_id,
775			},
776			success: function (response) {
777
778				if (response.success && response.data.url) {
779
780					var temp_filename = response.data.temp_filename;
781					var gf_form_id = response.data.form_id;
782					var gf_field_id = response.data.field_id;
783					var uploaded_filename = response.data.uploaded_filename;
784
785					// Hide the modal.
786					jQuery('#coderra_show_user_documents').modal('hide');
787
788					// Disable the button.
789					jQuery('#' + btn).prop('disabled', true);
790
791					// Create the HTML for the preloaded file.
792					var preloadedFileHtml = `
793								<div id="user_document_file_${gf_form_id}_${gf_field_id}" class="ginput_preview">
794									<span class="gfield_fileupload_filename">${uploaded_filename}</span>
795									<span class="gfield_fileupload_progress gfield_fileupload_progress_complete">
796										<span class="gfield_fileupload_progressbar">
797											<span class="gfield_fileupload_progressbar_progress" style="width: 100%;"></span>
798										</span>
799										<span class="gfield_fileupload_percent">100%</span>
800									</span>
801									<button class="gform_delete_file gform-theme-button gform-theme-button--simple" onclick="gformDeleteUploadedFile(${gf_form_id},${gf_field_id}, this); coderraEnableFileButton(${btn});">
802										<span class="dashicons dashicons-trash" aria-hidden="true"></span>
803										<span class="screen-reader-text">Delete this file: ${uploaded_filename}</span>
804									</button>
805								</div>
806							`;
807
808					// Append the preloaded file to the preview list.
809					jQuery('#' + field_id).find(".ginput_preview_list").html(preloadedFileHtml);
810
811					// Add the file to the hidden input.
812					gformAddUploadedFile(gf_form_id, gf_field_id, temp_filename, uploaded_filename);
813
814				}
815			},
816			error: function (error) {
817				console.log('AJAX Error:', error);
818			},
819		});
820	});
821
822	// Reset modal when dismissed.
823	jQuery('#coderra_show_user_documents').on('hidden.bs.modal', function () {
824		jQuery('#coderra-portal-modal .modal-body').empty();
825	});
826
827});
828
829function admiral_update_portal_filter() {
830
831	if (jQuery('.portal_filter_count').length > 0) {
832
833		var portal_filter_count = jQuery('.portal-matches-data').attr('data-portal-count');
834
835		jQuery('.portal_filter_count').html(portal_filter_count);
836
837	}
838
839	if (jQuery('.portal_page_number').length > 0) {
840
841		var portal_filter_count = jQuery('.portal-matches-data').attr('data-portal-page');
842
843		jQuery('.portal_page_number').html(portal_filter_count);
844
845	}
846}
847
848// Enable the uploads button again.
849function coderraEnableFileButton(element) {
850	jQuery(element).prop('disabled', false);
851}
852
853// Add our uploads to the hidden input.
854function gformAddUploadedFile(formId, fieldId, tempFilename, uploadedFilename) {
855	// Get the hidden input for the uploaded files
856	const uploadedFilesInput = document.querySelector(`#gform_uploaded_files_${formId}`);
857	if (!uploadedFilesInput) return;
858
859	// Parse the current JSON value or initialize an empty object
860	let uploadedFiles = {};
861	try {
862		uploadedFiles = JSON.parse(uploadedFilesInput.value || '{}');
863	} catch (e) {
864		console.error('Error parsing gform_uploaded_files:', e);
865	}
866
867	// Add the new file data to the correct field
868	const fieldKey = `input_${fieldId}`;
869	if (!uploadedFiles[fieldKey]) {
870		uploadedFiles[fieldKey] = [];
871	}
872	uploadedFiles[fieldKey].push({
873		temp_filename: tempFilename,
874		uploaded_filename: uploadedFilename
875	});
876
877	// Update the hidden input with the modified JSON
878	uploadedFilesInput.value = JSON.stringify(uploadedFiles);
879}

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.