Administration >> System preferences >> IntranetUserJs
// Hide the fieldsets and elements//
document.addEventListener("DOMContentLoaded", function() {
// Find the fieldsets with the classes "rows" and "memberentry_address"
const addressFieldset = document.querySelector("#memberentry_address");
const altAddressFieldset = document.querySelector("#memberentry_altaddress");
// Find an array of label IDs and corresponding input IDs to hide
const elementsToHide = [
{ labelId: "firstname", inputId: "firstname" },
{ labelId: "othernames", inputId: "othernames" },
{ labelId: "phonepro", inputId: "phonepro" },
{ labelId: "emailpro", inputId: "emailpro" },
{ labelId: "fax", inputId: "fax" },
{ labelId: "opacnote", inputId: "opacnote" },
{ labelId: "borrowernotes", inputId: "borrowernotes" },
{ labelId: "middle_name", inputId: "middle_name" },
{ labelId: "initials", inputId: "initials" },
{ labelId: "pronouns", inputId: "pronouns" },
{ labelId: "primary_contact_method", inputId: "primary_contact_method" },
// Add more elements if needed
];
// Hide the fieldsets and elements by setting their display property to "none"
if (addressFieldset) {
addressFieldset.style.display = "none";
}
if (altAddressFieldset) {
altAddressFieldset.style.display = "none";
}
elementsToHide.forEach(element => {
const label = document.querySelector(`label[for='${element.labelId}']`);
const input = document.querySelector(`#${element.inputId}`);
const hint = document.querySelector(`#${element.inputId} + .hint`); // Get associated hint element
if (label) {
label.style.display = "none";
}
if (input) {
input.style.display = "none";
}
if (hint) {
hint.style.display = "none"; // Hide associated hint
}
});
});
// Modify Member Entry Form for "Name" Field
// Changes the label and converts input to uppercase for the "surname" field
$(document).ready(function() {
// Change label for the field with name "surname" to "Name" on member entry form page
if ($('#pat_memberentrygen').length) {
$('label[for="surname"]').text('Name:');
}
// Convert the value of the "surname" field to Title Case as the user types
$('#surname').on('input', function() {
var surname = $(this).val();
$(this).val(toTitleCase(surname));
});
// Function to convert a string to Title Case
function toTitleCase(str) {
return str.replace(/\w\S*/g, function(txt) {
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
});
}
});
$(document).ready(function () {
// Change Primary phone label on member details page
if ($('#pat_moremember').length) {
$('#patron-phone .label').text('WhatsApp Number:');
}
// Change phone label on member entry form page
if ($('#pat_memberentrygen').length) {
$('label[for="phone"]').text('WhatsApp number:');
// Add validation for WhatsApp number field
$('#phone').prop('required', true);
// Add event listener to validate the entered number format on form submission
$('#entryform').submit(function (event) {
var enteredNumber = $('#phone').val();
// Validate if the entered number starts with '91'
if (!enteredNumber.startsWith('91')) {
// Prevent form submission
event.preventDefault();
// You can display an error message or take appropriate action
alert('Please enter a valid WhatsApp number with "91" as the prefix Eg: 919567664972.');
// Clear the input or handle the error as needed
$('#phone').val('');
}
});
}
});
/* change sort1 label on member details page */
if ( $('#pat_moremember').length ) {
$('#patron-sort1 .label').text('Designation/Course name:');
}
/* change sort1 label on member entry form page */
if ( $('#pat_memberentrygen').length ) {
$('label[for="sort1"]').text('Designation/Course name:');
}
/* change sort2 label on member details page */
if ( $('#pat_moremember').length ) {
$('#patron-sort2 .label').text('Blood group:');
}
/* change sort2 label on member entry form page */
if ( $('#pat_memberentrygen').length ) {
$('label[for="sort2"]').text('Blood group:');
}
// Hide Other phone on member details page
if ($('#pat_moremember').length) {
$('#patron-Other phone').hide();
}
// Hide Other phone on member entry form page
if ($('#pat_memberentrygen').length) {
$('#Other phone').closest('div').hide();
}
$(document).ready(function () {
if ($('#pat_memberentrygen').length > 0) {
// Copy card number to userid
$("#cardnumber").on("input", function () {
var cardNum = this.value;
$("#userid").val(cardNum);
// Set password as "Abcd123#"
$("#password").val("Abcd123#");
// Set password2 as "Abcd123#"
$("#password2").val("Abcd123#");
});
}
});
//Hide Other Phone //
document.addEventListener("DOMContentLoaded", function() {
// Find the <li> elements with the label "Other phone"
const otherPhoneLiElements = document.querySelectorAll('li label[for="mobile"]');
// Hide each <li> element with the label "Other phone"
otherPhoneLiElements.forEach(liElement => {
liElement.parentNode.style.display = "none";
});
});
///whatsapp number label cahnge in profile?//
$(document).ready(function() {
// Update WhatsApp Number label text
$('#patron-information .label:contains("Primary phone:")').text('WhatsApp Number');
});
//Alert staff about missing WhatsApp upon checkout//
// Confirm that we're on the "Checking Out" page
var isCheckingOutPage = /circulation\.pl/.test(window.location.pathname);
// Check if there is a WhatsApp number link on the page
var hasPhoneNumberLink = $('a[href^="tel:"]').length;
if (isCheckingOutPage && hasPhoneNumberLink === 0) {
alert('WhatsApp number is missing! Please update it');
}
$(document).ready(function() {
// Confirm that we're on the "Checking Out" page
var isCheckingOutPage = /circulation\.pl/.test(window.location.pathname);
// Get the value of the date of birth input field
var dateOfBirth = $('patrondateofbirth').val().trim(); // Replace '#dateofbirth' with the actual ID or class of your date of birth input field
if (isCheckingOutPage && dateOfBirth === '') {
alert('Date of birth is missing! Please update it.');
}
});
//Library Closure Widget (v22.05)
if ( $('#main_intranet-main').length ) {
var branch = $('#logged-in-info-full .logged-in-branch-code').text();
$('#container-main .col-sm-3').prepend('<h3 style="padding: 0.3em; margin: 0;"><span class="closures_title">Upcoming closures</span></h3><div id="closures"></div>');
$.getJSON("/cgi-bin/koha/svc/report?id=139&sql_params=" + branch + "&sql_params=" + branch + "&sql_params=" + branch + "&sql_params=" + branch + "&sql_params=" + branch + "&sql_params=" + branch + "&sql_params=" + branch, function(data) {
let closureData = '<div class="closureData" style="margin: 0.3em; margin-bottom: 1em; background-color:#E6F0F2; opacity:0.75; border-radius:6px; padding:3px; border:2px solid #B9D8D9;">';
$.each(data, function(index, value) {
var newClosureDate = value[0];
console.log(index + '/' + value);
newClosureDate = newClosureDate.replace(/-/g,'‑');
if(index % 2==0){
closureData += '<div class="closureRow" style="display: table-row;">';
} else {
closureData += '<div class="closureRow" style="display: table-row; background-color:#d5dfe0;">';
}
closureData += '<div style="display: table-cell;"><strong>' + newClosureDate + ': </strong></div><div style="display: table-cell; width: 100%;"><em>' + value[1] + '</em></div></div>';
});
closureData += '</div>';
$('#closures').html( closureData );
});
}
//END Library Closure Widget
// Check if two days have passed since the last popup
function shouldShowPopup() {
var lastPopupTime = localStorage.getItem('lastPopupTime');
if (!lastPopupTime) {
// First time, show the popup
return true;
} else {
// Check if two days have passed since the last popup
var twoDaysInMillis = 2 * 24 * 60 * 60 * 1000; // two days in milliseconds
var currentTime = new Date().getTime();
return (currentTime - lastPopupTime) >= twoDaysInMillis;
}
}
// Show the popup and update the last popup time in localStorage
function showPopup() {
alert('Ensure WhatsApp Phone Battery');
localStorage.setItem('lastPopupTime', new Date().getTime());
}
// Check if the popup should be shown and display it
if (shouldShowPopup()) {
showPopup();
}