app/static/scripts/globalScripts.js
// process select values for creation of relationship entry
process select values for creation of relationship entry
process select values for creation of relationship entry
function add_relationship() {
            var type = document.getElementById('select_new_relative_type');
            var adding_person = document.getElementById('select_new_relative');
            var label_element = document.getElementById('add_relative_current_id');
            var current_person_id = label_element.getAttribute('var');
            var current_person_obj = person_from_id(current_person_id);
            var relation_entry = {};
            switch(type.value) {
                case 'a': 
                    relation_entry.relation_type = 0;
                    relation_entry.person_a_id = parseInt(adding_person.value);
                    relation_entry.person_b_id = parseInt(current_person_id);
                    break;
                case 'b': 
                    relation_entry.relation_type = 0;
                    relation_entry.person_a_id = parseInt(current_person_id);
                    relation_entry.person_b_id = parseInt(adding_person.value);
                    break;
                case 'c': 
                    relation_entry.relation_type = 1;
                    relation_entry.person_a_id = parseInt(current_person_id);
                    relation_entry.person_b_id = parseInt(adding_person.value);
                    break;
            }
            console.log(relation_entry);
            RELATION_ARRAY.push(relation_entry);
            create_relationship(relation_entry);
            let json_string = JSON.stringify(relation_entry);
            var ajax_request = new XMLHttpRequest();
            ajax_request.open("POST", "/add_relationship");
            ajax_request.setRequestHeader("Content-Type", "application/json"); 
            ajax_request.send(json_string);
            ajax_request.onload = function() {  
                var profile_arrays = document.getElementsByClassName('profile_array');
                for( let elem of profile_arrays) {
                    switch(elem.id) {
                        case 'profile_parents':
                            for( let child of elem.children) {
                                child.remove();
                            }
                            array_to_element(current_person_obj.parents, elem);
                            break;
                        case 'profile_children':
                            for( let child of elem.children) {
                                child.remove();
                            }
                            array_to_element(current_person_obj.children, elem);
                            break;
                        case 'profile_siblings':
                            for( let child of elem.children) {
                                child.remove();
                            }
                            array_to_element(current_person_obj.siblings, elem);
                            break;
                    }
                }
                update_tree();
            };
        }
function add_relationship ( ) { var type = document . getElementById ( 'select_new_relative_type' ) ; var adding_person = document . getElementById ( 'select_new_relative' ) ; var label_element = document . getElementById ( 'add_relative_current_id' ) ; var current_person_id = label_element . getAttribute ( 'var' ) ; var current_person_obj = person_from_id ( current_person_id ) ; var relation_entry = { } ; switch ( type . value ) { case 'a' : relation_entry . relation_type = 0 ; relation_entry . person_a_id = parseInt ( adding_person . value ) ; relation_entry . person_b_id = parseInt ( current_person_id ) ; break ; case 'b' : relation_entry . relation_type = 0 ; relation_entry . person_a_id = parseInt ( current_person_id ) ; relation_entry . person_b_id = parseInt ( adding_person . value ) ; break ; case 'c' : relation_entry . relation_type = 1 ; relation_entry . person_a_id = parseInt ( current_person_id ) ; relation_entry . person_b_id = parseInt ( adding_person . value ) ; break ; } console . log ( relation_entry ) ; RELATION_ARRAY . push ( relation_entry ) ; create_relationship ( relation_entry ) ; let json_string = JSON . stringify ( relation_entry ) ; var ajax_request = new XMLHttpRequest ( ) ; ajax_request . open ( "POST" , "/add_relationship" ) ; ajax_request . setRequestHeader ( "Content-Type" , "application/json" ) ; ajax_request . send ( json_string ) ; ajax_request . onload = function ( ) { var profile_arrays = document . getElementsByClassName ( 'profile_array' ) ; for ( let elem of profile_arrays ) { switch ( elem . id ) { case 'profile_parents' : for ( let child of elem . children ) { child . remove ( ) ; } array_to_element ( current_person_obj . parents , elem ) ; break ; case 'profile_children' : for ( let child of elem . children ) { child . remove ( ) ; } array_to_element ( current_person_obj . children , elem ) ; break ; case 'profile_siblings' : for ( let child of elem . children ) { child . remove ( ) ; } array_to_element ( current_person_obj . siblings , elem ) ; break ; } } update_tree ( ) ; } ; }
process select values for creation of relationship entry
process select values for creation of relationship entry
// the added person is the parent // the added person is the child // the persons are siblings, doesn't matter // post section // important for flask interpretation // this is from the response // add to profile view //remove what's there // use person object //remove what's there // use person object //remove what's there // use person object