src/static/js/admin-programs.js
// Populate data on the programs page
Populate data on the programs page
Populate data on the programs page
async function populatePrograms() {
  const programsURL = "/api/adminPrograms";
  let programs = null;
  try {
    programs = await fetchJSON(programsURL);
  } catch (err) {
    showError("Failed to update programs");
  }
  if (programs) {
    hideError();
    clearElement("programs");
    for (const program of programs) {
      const newItem = createProgramRow(program);
      appendTo("programs", newItem);
    }
    const newProgramButton = newElement("button")
      .addClass("btn btn-primary")
      .attr({
        type: "button",
      })
      .text("New Program")
      .click(() => {
        createProgram("");
      });
    const newProgramButtonDiv = newElement("div")
      .addClass("row mt-3")
      .append(newProgramButton);
    appendTo("programs", newProgramButtonDiv);
  }
}
async function populatePrograms ( ) { const programsURL = "/api/adminPrograms" ; let programs = null ; try { programs = await fetchJSON ( programsURL ) ; } catch ( err ) { showError ( "Failed to update programs" ) ; } if ( programs ) { hideError ( ) ; clearElement ( "programs" ) ; for ( const program of programs ) { const newItem = createProgramRow ( program ) ; appendTo ( "programs" , newItem ) ; } const newProgramButton = newElement ( "button" ) . addClass ( "btn btn-primary" ) . attr ( { type : "button" , } ) . text ( "New Program" ) . click ( ( ) => { createProgram ( "" ) ; } ) ; const newProgramButtonDiv = newElement ( "div" ) . addClass ( "row mt-3" ) . append ( newProgramButton ) ; appendTo ( "programs" , newProgramButtonDiv ) ; } }
Populate data on the programs page
Populate data on the programs page