src/web/static/js/main.js
/** Event handler for clicking the save button. Send the form date to the server */
Event handler for clicking the save button. Send the form date to the server
Event handler for clicking the save button . Send the form date to the server
async function save() {
  try {
    const dayContainers = Array.from(document.querySelectorAll(".day-container"));
    const dayData = Object.fromEntries(dayContainers.map(dayContainer => {
      const day = dayContainer.id.split('-')[2];
      return [day, getDataForDay(day)];
    }));
    const res = await fetch(UPDATE_URL, {
      method: 'POST',
      body: JSON.stringify(dayData),
      headers: {
        'Content-Type': 'application/json'
      },
    });
    if (!res.ok) throw new Error(`Request failed: Status ${ res.status } ${ res.statusText }`);
    showToast('save-success');
  } catch (e) {
    error(e);
  }
}
async function save ( ) { try { const dayContainers = Array . from ( document . querySelectorAll ( ".day-container" ) ) ; const dayData = Object . fromEntries ( dayContainers . map ( dayContainer => { const day = dayContainer . id . split ( '-' ) [ 2 ] ; return [ day , getDataForDay ( day ) ] ; } ) ) ; const res = await fetch ( UPDATE_URL , { method : 'POST' , body : JSON . stringify ( dayData ) , headers : { 'Content-Type' : 'application/json' } , } ) ; if ( ! res . ok ) throw new Error ( ` ${ res . status } ${ res . statusText } ` ) ; showToast ( 'save-success' ) ; } catch ( e ) { error ( e ) ; } }
Event handler for clicking the save button.
Event handler for clicking the save button .
// There is an input group contained in a div .day-container #day-container-{{ day }} for each weekday // find the form data for each day