members-space-my-info.js 5.58 KB
Newer Older
1
function init_my_info() {
Damien Moulard committed
2 3 4 5
    init_my_info_data();

    $(".member_email").text(partner_data.email);

6
    if (partner_data.is_in_association === false) {
7
        $("#attached_info_area").hide();
Damien Moulard committed
8
    }
9 10

    if (partner_data.is_associated_people === "True") {
11
        $(".attached_partner_name").text(partner_data.parent_name);
12 13
    } else if (partner_data.associated_partner_id !== "False") {
        $(".attached_partner_name").text(partner_data.associated_partner_name);
14 15
    }

Etienne Freiss committed
16
    $(".member_address").empty();
17
    if (partner_data.street !== "" && partner_data.street !== "False") {
Damien Moulard committed
18 19
        $(".member_address")
            .append(partner_data.street + "<br/>");
20
        if (partner_data.street2 !== "" && partner_data.street2 !== "False") {
Damien Moulard committed
21 22 23 24 25 26 27 28 29
            $(".member_address")
                .append(partner_data.street2 + "<br/>");
        }
        $(".member_address")
            .append(partner_data.zip + " " + partner_data.city);
    } else {
        $(".member_address_line").hide();
    }

Etienne Freiss committed
30
    $(".member_mobile").empty();
31
    if (partner_data.mobile !== "" && partner_data.mobile !== "False" && partner_data.mobile !== false && partner_data.mobile !== null) {
Damien Moulard committed
32
        $(".member_mobile")
33 34
            .append(partner_data.mobile)
            .show();
Damien Moulard committed
35
    } else {
36
        $(".member_mobile").hide();
Damien Moulard committed
37
    }
Etienne Freiss committed
38

Etienne Freiss committed
39
    $(".member_phone").empty();
Damien Moulard committed
40
    if (partner_data.phone !== "" && partner_data.phone !== "False" && partner_data.phone !== false && partner_data.phone !== null) {
Damien Moulard committed
41
        $(".member_phone")
42 43
            .append(partner_data.phone)
            .show();
Damien Moulard committed
44
    } else {
45 46 47 48
        $(".member_phone").hide();
    }

    if ($(".member_mobile").text() === "" && $(".member_phone").text() === "") {
Damien Moulard committed
49 50
        $(".member_phone_line").hide();
    }
Etienne Freiss committed
51

52 53 54 55 56 57 58 59 60 61 62 63 64
    $(".member_job").empty();
    if (partner_data.function !== "" && partner_data.function !== "False" && partner_data.function !== false && partner_data.function !== null) {
        $(".member_job")
            .append(partner_data.function)
            .show();
    } else {
        $(".member_job").hide();
    }

    if ($(".member_job").text() === "") {
        $(".member_job_line").hide();
    }

Etienne Freiss committed
65 66
    $('#edit_address').off('click')
        .on('click', () => {
Félicie committed
67
            $("#street_form").val(partner_data.street.replace(/&#39;/g, "'"));
Etienne Freiss committed
68
            // $("#street2_form").val(partner_data.street2);
Félicie committed
69 70
            $("#zip_form").val(partner_data.zip.replace(/&#39;/g, "'"));
            $("#city_form").val(partner_data.city.replace(/&#39;/g, "'"));
Etienne Freiss committed
71 72 73 74 75 76 77 78 79 80 81 82 83
            $('#edit_address_value').hide();
            $('#edit_address_form').show();
        });
    $('#cancel_edit_address').
        on('click', () => {
            $('#edit_address_form').hide();
            $('#edit_address_value').show();
        });
    $('#save_edit_address').off('click')
        .on('click', () => {
            data= [];
            data['street']= $("#street_form").val();
            // data['street2']= $("#street2_form").val();
84
            data['zip']= $("#zip_form").val();
Etienne Freiss committed
85 86 87 88 89 90 91
            data['city']= $("#city_form").val();

            saveInfo(data, 'address');
        });

    $('#edit_phone').off('click')
        .on('click', () => {
92 93
            if (partner_data.phone === "False") partner_data.phone = "";
            if (partner_data.mobile === "False") partner_data.mobile = "";
Etienne Freiss committed
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
            $("#phone_form").val(partner_data.phone);
            $("#mobile_form").val(partner_data.mobile);
            $('#edit_phone_value').hide();
            $('#edit_phone_form').show();
        });
    $('#cancel_edit_phone').off('click')
        .on('click', () => {
            $('#edit_phone_form').hide();
            $('#edit_phone_value').show();
        });
    $('#save_edit_phone').off('click')
        .on('click', () => {
            data =[];
            data['phone']= $("#phone_form").val();
            data['mobile']= $("#mobile_form").val();
            saveInfo(data, 'phone');
        });
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
    $('#edit_job').off('click')
        .on('click', () => {
            if (partner_data.function === "False") partner_data.function = "";
            $("#job_form").val(partner_data.function);
            $('#edit_job_value').hide();
            $('#edit_job_form').show();
        });
    $('#cancel_edit_job').off('click')
        .on('click', () => {
            $('#edit_job_form').hide();
            $('#edit_job_value').show();
        });
    $('#save_edit_job').off('click')
        .on('click', () => {
            console.log('ici');
            data =[];
            data['function']= $("#job_form").val();
            saveInfo(data, 'function');
        });
Etienne Freiss committed
130 131 132

}

Etienne Freiss committed
133
function saveInfo(data, field) {
Etienne Freiss committed
134 135
    tData = '&idPartner=' + partner_data.partner_id
    + '&shift_type=' + partner_data.shift_type
Etienne Freiss committed
136 137
    + '&verif_token=' + partner_data.verif_token;
    for (d in data) {
Etienne Freiss committed
138 139 140 141 142 143 144 145 146 147
        tData+="&"+d+"="+data[d];
    }

    tUrl = '/members/save_partner_info';
    $.ajax({
        type: 'POST',
        url: tUrl,
        dataType:"json",
        data: tData,
        timeout: 3000,
Etienne Freiss committed
148 149 150
        success: function() {
            for (d in data) {
                partner_data[d]=data[d];
Etienne Freiss committed
151 152
            }
            init_my_info();
Etienne Freiss committed
153
            if (field == 'address') {
Etienne Freiss committed
154 155 156
                $('#edit_address_form').hide();
                $('#edit_address_value').show();
            }
Etienne Freiss committed
157
            if (field == 'phone') {
Etienne Freiss committed
158 159 160
                $('#edit_phone_form').hide();
                $('#edit_phone_value').show();
            }
161 162 163 164
            if (field == 'function') {
                $('#edit_job_form').hide();
                $('#edit_job_value').show();
            }
Etienne Freiss committed
165 166
        },
        error: function(error) {
Etienne Freiss committed
167
            console.log(error);
Etienne Freiss committed
168 169
        }
    });
Félicie committed
170
}