portfolio/src/main/webapp/script.js
/**
 * Fetch login status of the user, and toggle the display of the comment form 
 * and login instructions (in div with id=login-logout-instructions) accordngly.
 * Note that only logged in users will be able to see the comment form. Users
 * will be prompted to login or logout accordingly.
 * @returns none
 */
Fetch login status of the user, and toggle the display of the comment form
and login instructions (in div with id=login-logout-instructions) accordngly.
Note that only logged in users will be able to see the comment form. Users
will be prompted to login or logout accordingly.
@returns none
Fetch login status of the user and toggle the display of the comment form and login instructions ( in div with id = login - logout - instructions ) accordngly . Note that only logged in users will be able to see the comment form . Users will be prompted to login or logout accordingly . @returns none
function toggleCommentForm() {
  const request = new Request('/login-status', {'method': 'GET'});
  fetch(request).then(response => response.json()).then((loginStatus) => {
    let commentForm = document.getElementById('comment-form');
    if (loginStatus.loggedIn === 'true') {
      commentForm.style.display = 'block';
      let logoutInstructions = '<p class="body-text">Logout <a href=' + loginStatus.logoutUrl + '>here</a></p>';
      document.getElementById('login-logout-instructions').innerHTML = logoutInstructions;
    } else {
      commentForm.style.display = 'none';
      let loginInstructions = '<p class="body-text">Login <a href=' + loginStatus.loginUrl + '>here</a> to add comments.</p>';
      document.getElementById('login-logout-instructions').innerHTML = loginInstructions;
    }
  });
}
function toggleCommentForm ( ) { const request = new Request ( '/login-status' , { 'method' : 'GET' } ) ; fetch ( request ) . then ( response => response . json ( ) ) . then ( ( loginStatus ) => { let commentForm = document . getElementById ( 'comment-form' ) ; if ( loginStatus . loggedIn === 'true' ) { commentForm . style . display = 'block' ; let logoutInstructions = '<p class="body-text">Logout <a href=' + loginStatus . logoutUrl + '>here</a></p>' ; document . getElementById ( 'login-logout-instructions' ) . innerHTML = logoutInstructions ; } else { commentForm . style . display = 'none' ; let loginInstructions = '<p class="body-text">Login <a href=' + loginStatus . loginUrl + '>here</a> to add comments.</p>' ; document . getElementById ( 'login-logout-instructions' ) . innerHTML = loginInstructions ; } } ) ; }
Fetch login status of the user, and toggle the display of the comment form
 and login instructions (in div with id=login-logout-instructions) accordngly.
Fetch login status of the user and toggle the display of the comment form and login instructions ( in div with id = login - logout - instructions ) accordngly .
// Show the comments form  // Show logout link // Hide comments form  // Show login link