src/public/js/edit_profile.js
/**
 * Populates the user's profile fields with their current information.
 *
 * @returns {Promise<void>}
 */
Populates the user's profile fields with their current information.
@returns {Promise}
Populates the user ' s profile fields with their current information . @returns { Promise }
async function populateFields() {
    check_for_errors();
    let user_data = await fetch("/profile");
    user_data = await user_data.json();
    user_data = user_data.data;
    console.log(user_data);
    countries = await getCountries();
    populateSelect("country", countries);
    schools = await getSchools();
    populateSelect("school", schools);
    clubs = await getClubs();
    let club_ids = [];
    for(let x = 0; x < user_data.clubs.length; x++)
    {
        club_ids.push(user_data.clubs[x].id);
    }
    populateSelect("clubs", clubs);
    let $select = $('#clubs').selectize({
        plugins: ['remove_button'],
        maxItems: null
    });
    let selectize = $select[0].selectize;
    selectize.setValue(club_ids);
    document.getElementById("first_name").value = user_data.first_name;
    document.getElementById("last_name").value = user_data.last_name;
    document.getElementById("email").value = user_data.email;
    document.getElementById('bio').innerText = user_data.bio;
    tinymce.get("bio").setContent(user_data.bio);
    document.getElementById("minor").value = user_data.minor;
    document.getElementById("country").value = user_data.country_id;
    document.getElementById("school").value = user_data.school_id;
    await countrySelectionChange('country', 'state');
    await schoolSelectionChange('school', 'major');
    document.getElementById("state").value = user_data.state_id;
    document.getElementById("major").value = user_data.major_id;
    document.getElementById("profile_image").src = "/profile_pictures/" + user_data.picture;
    document.getElementById("grad_date").value = moment(user_data.grad_date).add(1,'days').format('YYYY-MM-DD');
}
async function populateFields ( ) { check_for_errors ( ) ; let user_data = await fetch ( "/profile" ) ; user_data = await user_data . json ( ) ; user_data = user_data . data ; console . log ( user_data ) ; countries = await getCountries ( ) ; populateSelect ( "country" , countries ) ; schools = await getSchools ( ) ; populateSelect ( "school" , schools ) ; clubs = await getClubs ( ) ; let club_ids = [ ] ; for ( let x = 0 ; x < user_data . clubs . length ; x ++ ) { club_ids . push ( user_data . clubs [ x ] . id ) ; } populateSelect ( "clubs" , clubs ) ; let $select = $ ( '#clubs' ) . selectize ( { plugins : [ 'remove_button' ] , maxItems : null } ) ; let selectize = $select [ 0 ] . selectize ; selectize . setValue ( club_ids ) ; document . getElementById ( "first_name" ) . value = user_data . first_name ; document . getElementById ( "last_name" ) . value = user_data . last_name ; document . getElementById ( "email" ) . value = user_data . email ; document . getElementById ( 'bio' ) . innerText = user_data . bio ; tinymce . get ( "bio" ) . setContent ( user_data . bio ) ; document . getElementById ( "minor" ) . value = user_data . minor ; document . getElementById ( "country" ) . value = user_data . country_id ; document . getElementById ( "school" ) . value = user_data . school_id ; await countrySelectionChange ( 'country' , 'state' ) ; await schoolSelectionChange ( 'school' , 'major' ) ; document . getElementById ( "state" ) . value = user_data . state_id ; document . getElementById ( "major" ) . value = user_data . major_id ; document . getElementById ( "profile_image" ) . src = "/profile_pictures/" + user_data . picture ; document . getElementById ( "grad_date" ) . value = moment ( user_data . grad_date ) . add ( 1 , 'days' ) . format ( 'YYYY-MM-DD' ) ; }
Populates the user's profile fields with their current information.
Populates the user ' s profile fields with their current information .
// Instantiates the multiple select plugin for the club input