Data type Link shows data to loggedin users but not on loggedout users


loggedin users view


not loggedin users view

how to show link data to not logged in users

Hi, Which app? Which version, the UI is very different. Are you asking about ERPNext?

Hi Shiv_P

It is a custom form in erpnext(13.25.1). here is the link: Admission Information

if you click on the Academic Program it is not showing the options, but for loggedin users it is showing.

Thanks

Hey, maybe, it’s the permission issue in the field.

Hi Shiv,

sorry for the late reply. here is the current code from the previous dev:

frappe.ready(function () {
	(frappe.web_form.after_load = () => {

		$(".navbar-brand").css("pointer-events", "none");
		const lead_session = sessionStorage.acad;
		$(".navbar-brand").css("pointer-events", "none");
		const url_base = window.location.origin;
		const Tab = `
			  <div class="container tab mb-5 text12">
			  <h3 class="my-5 font-weight-bold">Student Application Form</h3>
			  <div class="row">
				  <div class="col-md-10">
					  <div class=" d-flex justify-content-center">
						  <div class="col text-center tab-line-active">
							  <img src="/files/Active%20-%20Admission.png" class="icon-tab">
							  <p class="tab_label text18">Admission</p>
						  </div>
						  <div class="col text-center tab-line">
							  <img src="/files/Inactive%20-%20Application.png" class="icon-tab">
							  <p class="tab_label text18">Personal Information</p>
						  </div>
						  <div class="col text-center tab-line">
							  <img src="/files/Inactive%20-%20Application.png" class="icon-tab">
							  <p class="tab_label text18">Educational Background</p>
						  </div>
						  <div class="col text-center tab-line">
							  <img src="/files/Inactive%20-%20Confirmation.png" class="icon-tab">
							  <p class="tab_label text18">Confirmation</p>
						  </div>
					  </div>
				  </div> 
			  </div>
		  </div>
		  <style>
				@media (max-width: 768px) {
					.tab_label {
						display: none;
					}
				}
		   </style>
		  `;

		fetch(
			url_base +
			'/api/resource/Academic Department?fields=["academic_department", "name"]&&order_by=counter'
		)
			.then((response) => response.json())
			.then((data) => {
				$('#acadcDeptSpecial').append($('<option>', {
					value: "not-selected",
					text: "Select Academic Department"
				}));

				data.data.map((item, key) => {
					if ($("#student_type").val() == 'Second Courser') {
						var exclude_acad = ['Junior High School', 'Senior High School'];
						if (!exclude_acad.includes(item.name)) {
							$('#acadcDeptSpecial').append($('<option>', {
								value: item.name,
								text: item.name
							}));
						}
					} else {
						$('#acadcDeptSpecial').append($('<option>', {
							value: item.name,
							text: item.name
						}));
					}
				});

			});

		fetch(
			url_base +
			'/api/resource/Agent?field=["fullname"]'
		)
			.then((response) => response.json())
			.then((data) => {
				data.data.map((item, key) => {
					$('#agent').append($('<option>', {
						value: item.name,
						text: item.name
					}));

				});
			});
		// year level
		var newHTML = `
		  <div class="container">
			  <div class="row">
				  <p class="text28 font-weight-800">Admission Information</p>
			  </div>
			  <div class="row">
				  <p class="text14">Please identify first what Academic Department you want to be admitted.</p>
			  </div>
			  <div class="row">
				  <p class="text-10 text-red">*Required fields</p>
			  </div>
			  <div class="row px-0">
				  	<div class="col-md-6 pl-0">
					  <label class="inputLabel mb-0 p-0" for="psSchoolName">Student Type<span class="text-red"> *</span></label>
					  <input class="longInput form-control mb-2 form-control-sm border bg-white rounded-0 border-secondary"
						  type="text" placeholder="${lead_session}" id="student_type" disabled value="${lead_session}"></input>
					</div>
		  
					<div class="col-md-6 pl-0">
						<label class="mb-0 p-0" for="acadDept">Academic Department<span class="text-red"> *</span></label>
						<select id="acadcDeptSpecial" class="mb-2  text-gray col-md-12 border bg-white border-dark c-p-5"
						aria-label="Default select example">
						</select>
					</div>
					
					
	  				<div class="col-md-6 pl-0">
					<label class="mb-0 p-0" for="program">Program<span class="text-red"> *</span></label>
					<select id="program" class="text-gray col-md-12 border bg-white border-dark c-p-5"
					aria-label="Default select example">
					<option value="not-selected">Select Program</option>
					</select>
	  				</div>
					<div class="col-md-6 pl-0">
					  <label class="mb-0 p-0" for="agent">Agent</label>
					  <select id="agent" class="text-gray col-md-12 border bg-white border-dark c-p-5"
					  aria-label="Default select example">
					  	<option value="not-selected">Select Agent</option>
					  </select>
					</div>
					<div class="col-md-6 pl-0 mt-3 year_level">
					  <label class="mb-0 p-0 label_yearlevel" for="year_level">Year Level</label>
					  <select id="year_level" class="text-gray col-md-12 border bg-white border-dark c-p-5"
					  aria-label="Default select example">
					  	<option value="not-selected">Select Year Level</option>
					  </select>
					</div>
					</div>
		  
				  <div class="col-12 d-flex justify-content-center">
		  
					  <div id="back_to_step1"
						  class="col-lg-1 col-sm-3 back cursor-pointer text-center border boder-0 my-2 mx-2 py-1 px-3">Back
					  </div>
					  <div id="show-button"
						  class="col-lg-1 col-sm-3 continue cursor-pointer text-center border btn-primary boder-0 my-2 mr-2 py-1 px-3">
						  Continue</div>
					  <div id="hide-button"
						  class="col-lg-1 col-sm-3 cursor-not-allowed text-center border btn-secondary boder-0 my-2 mr-2 py-1 px-3">
						  Continue</div>
		  
				  </div>
		  
				  <div class="container text12">
					  <div class="footer mt-5">
						  <hr>
						  <p class="p-5">© Philippine College of Criminology</p>
						  <hr>
					  </div>
				  </div>
		  
				  <div class="col-md-8 text12 pl-0" style="display: none;">
					  <h6 class="font-weight-bold mb-0">Curriculum</h6>
					  <table class="table table-bordered table-striped mb-0">
						  <thead class="">
							  <tr>
								  <th class="th-code">Subject Code</th>
								  <th class="">Title</th>
							  </tr>
						  </thead>
					  </table>
					  <div class="table-wrapper-scroll-y my-custom-scrollbar">
						  <table class="table table-bordered table-striped mb-0">
							  <tbody class="table-body">
		  
							  </tbody>
						  </table>
					  </div>
					  <div class="d-flex sm-button justify-content-center">
						  <div id="back_to_step1" class="back btn cursor-pointer border boder-0 mx-2 py-1 px-3 text12">Back</div>
						  <div id="show-button"
							  class="btn sm-show-button continue cursor-pointer border btn-primary boder-0 mr-2 py-1 px-3 text12">
							  Continue</div>
						  <div id="hide-button"
							  class="btn sm-hide-buttoncursor-not-allowed border btn-secondary boder-0 mr-2 py-1 px-3 text12">
							  Continue</div>
					  </div>
				  </div>
				  

		  </div>
		  
	  `;

		// all html
		const Admission = `
		  <div id="admission"> 
			  ${Tab + newHTML}
		  </div>
	  `;
		$("Body").append(Admission);
		$('.year_level').hide();
		if ($("#student_type").val() == 'Transferee' || $("#student_type").val() == "Second Courser") {
			$('.year_level').show();
		} else {
			$('.year_level').hide();
		}
		function incrementString(string) {
			// Extract string's number
			var number = string.match(/\d+/) === null ? 0 : string.match(/\d+/)[0];
			// Store number's length
			var numberLength = number.length;
			// Increment number by 1
			number = (parseInt(number) + 1).toString();
			// If there were leading 0s, add them again
			while (number.length < numberLength) {
				number = "0" + number;
			}
			return string.replace(/[0-9]/g, "").concat(number);
		}
		$("#show-button").hide();

		// get currriculum
		const get_currriculum = (acad_value) => {
			console.log(acad_value);
			$(".table-body").html('<p id="hide"></p>');
			// Fetch data depends on acad dept and program
			fetch(url_base + "/api/resource/Curriculum/" + acad_value)
				.then((res) => res.json())
				.then((res) => {
					var acadArray = res.data.curriculum_data;
					acadArray.forEach((element) => {
						$("#hide").hide();
						$(".table-body").append(`
				  <tr>
					  <td class="th-code">${element.subject_code}</td>
					  <td>${element.title}</td>
				  </tr>
				  `);
					});
				})
				.catch((error) => {
					$(".table-body").html(`
			  <tr>
				  <td class="th-code"> Select academic department</td>
				  <td></td>
			  </tr>
			  `);
				});
		};
		//dynamic button admission form function
		$("#acadcDept").change(() => {
			$('#year_level').empty();
			$("#program")
				.empty()
				.append(
					$("<option selected value='not-selected'>Select Program</option>")
				);

			var acad_value = $("#acadcDept").val();
			var program_value = $("#program").val();
			var curriculum = acad_value + program_value;
			frappe.web_form.set_value("academic_department", acad_value);

			fetch(
				url_base +
				'/api/resource/Program?filters=[["academic_department","=", "' +
				acad_value +
				'"]]'
			)
				.then((response) => response.json())
				.then((data) => {
					console.log(data);
					data.data.forEach(function (value) {
						$("#program").append(
							$("<option></option>").attr("value", value.name).text(value.name)
						);
					});
				});
			$("#hide-button, .sm-hide-button").show();
			$("#show-button, .sm-show-button").hide();
			$(".table-body").html('<p id="hide"></p>');
		});

		$("#acadcDeptSpecial").change(() => {
			$("#program")
				.empty()
				.append(
					$("<option selected value='not-selected'>Select Program</option>")
				);

			var acad_value = $("#acadcDeptSpecial").val();
			fetch(url_base + "/api/resource/Year Level")
				.then(res => res.json())
				.then(res => {
					const data = res.data;
					console.log($("#acadcDeptSpecial").val());
					let search = (list, text) =>
						list.filter(i => i.name.toLowerCase().includes(text.toLowerCase()));

					let JuniorHighLevel = ["Grade 7", "Grade 8", "Grade 9", "Grade 10"].map(item => {
						let res = search(data, item);
						return res[0];
					});
					let yearLevel = search(data, 'Year');
					let SeniorHighLevel = ["Grade 11", "Grade 12"].map(item => {
						let res = search(data, item);
						return res[0];
					});
					if (acad_value == "Junior High School") {
						$('#year_level').empty();
						$('.label_yearlevel').html(`<p class="mb-0" style="color: #4C5A67 !important">Grade Level</p>`);
						$('#year_level').append(`<option class="year_option" value="Grade 7">Select Grade Level</option>`);
						JuniorHighLevel.map((item, key) => {
							$('#year_level').append($('<option>', {
								value: item.name,
								text: item.name
							}));

						});
					} else if (acad_value == "Senior High School") {
						$('#year_level').empty();
						$('.label_yearlevel').html(`<p class="mb-0" style="color: #4C5A67 !important">Grade Level</p>`);
						$('#year_level').append(`<option class="year_option" value="Grade 11">Select Grade Level</option>`);
						SeniorHighLevel.map((item, key) => {
							$('#year_level').append($('<option>', {
								value: item.name,
								text: item.name
							}));

						});
					} else {
						$('.label_yearlevel').html(`<p class="mb-0" style="color: #4C5A67 !important">Year Level</p>`);
						$('#year_level').empty();
						$('#year_level').append(`<option class="year_option" value="1st Year">Select Year Level</option>`);
						yearLevel.map((item, key) => {
							$('#year_level').append($('<option>', {
								value: item.name,
								text: item.name
							}));

						});
					}
				});
			frappe.web_form.set_value("academic_department", acad_value);

			fetch(
				url_base +
				'/api/resource/Program?filters=[["academic_department","=", "' +
				acad_value +
				'"]]&&order_by=counter'
			)
				.then((response) => response.json())
				.then((data) => {
					if ($("#student_type").val() == 'New Student' && acad_value == 'Junior High School') {
						//data.data.forEach(function (value) {
						$("#program").append(
							$("<option></option>").text("Junior High School")
						);
						$("#program option[value='Junior High School']").prop('selected', true);
						//  });
						$("#show-button, .sm-show-button").show();
						$("#hide-button, .sm-hide-button").hide();
					}
					else {
						data.data.forEach(function (value) {
							$("#program").append(
								$("<option></option>").attr("value", value.name).text(value.name)
							);
						});
					}

				});
			$("#hide-button, .sm-hide-button").show();
			$("#show-button, .sm-show-button").hide();
			$(".table-body").html('<p id="hide"></p>');
		});
		$("#program").change(() => {
			var acad_value = $("#acadcDept").val();
			var program = $("#program").val();
			frappe.web_form.set_value("program", program);

			if (acad_value === "not-selected" || program === "not-selected") {
				$("#hide-button, .sm-hide-button").show();
				$("#show-button, .sm-show-button").hide();
			} else {
				$("#hide-button, .sm-hide-button").hide();
				$("#show-button, .sm-show-button").show();
			}
		});
		// save admission student type, program, ref number
		$("#show-button").click(() => {
			var student_type = $("#student_type").val();
			var program = $("#program").val();
			var acad_value = $("#acadcDeptSpecial").val();
			var year_level;
			console.log(acad_value);
			var agent = "";
			if ($("#agent").val() === "not-selected") {
				agent = "";
			} else {
				agent = $("#agent").val();
			}
			if (student_type == "Transferee" || student_type == "Second Courser") {
				year_level = $("#year_level").val();
			} else {
				if (acad_value == "Junior High School") {
					year_level = "Grade 7";
				} else if (acad_value == "Senior High School") {
					year_level = "Grade 11";
				} else {
					year_level = "1st year";
				}

			}
			console.log(year_level);
			frappe.call({
				method: "pccr_eas.pccr_eas.web_form.lead_admissoin.lead_admissoin.create_initial_student_applicant",
				args: {
					'page_tracker': 'Personal Information',
					'program': program,
					'academic_dept': acad_value,
					'student_type': student_type,
					'agent': agent,
					'year_level': year_level
				},
				callback: function (r) {
					var reference_number = r.message;
					var decodedStringRef = "pccr_110011=" + reference_number;
					var encodedStringRef = btoa(decodedStringRef);
					sessionStorage.setItem("ref_number", encodedStringRef);
					window.location.href = "/personal-information";
				}
			});

		});
		$("#back_to_step1").click(() => {
			window.location.href = "/lead-app";
		});
		// ------- End of saving admission ---------------------
	}),
		(frappe.web_form.after_save = () => {

		});

});