members-space-home.js 6.39 KB
Newer Older
1 2
var calendar = null;

3 4
function init_my_shifts_tile() {
    if (incoming_shifts.length === 0) {
François committed
5
        $("#home_tile_my_services #home_incoming_services").text("Aucun service à venir...");
6
    } else {
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
        
        if (partner_data.comite === "True") {
            let message = $('#comite_my_shifs_message').clone()
            message.find('[data-type="nb_of_shifs_state"] [data-type="shifts_nb"]').text(partner_data.final_ftop_point)
            if (Math.abs(partner_data.final_ftop_point) > 1) {
                message.find('[data-type="nb_of_shifs_state"] [data-type="service_txt"]').text("services")
            }
            // let's get next ftop shift (incoming_shifts is ordered)
            if (incoming_shifts.length > 0) {
                const next_shift = incoming_shifts[0]
                let ns_date = new Date(next_shift.date_begin)
                const date_options = {dateStyle: "short"}
                message.find('[data-type="next_ftop_shift_date"]').text(ns_date.toLocaleDateString('fr-FR', date_options))
            }
            
            $("#home_tile_my_services .tile_content").html(message)
        } else {
            $("#home_tile_my_services #home_incoming_services").empty();
            let cpt = 0;

            for (shift of incoming_shifts) {
                if (cpt === 3) {
                    break;
                } else {
                    let shift_line_template = prepare_shift_line_template(shift.date_begin);

                    $("#home_tile_my_services #home_incoming_services").append(shift_line_template.html());

                    cpt++;
                }
37 38 39 40 41
            }
        }
    }
}

42 43 44
function process_asked_shift_template_change(shift_t_id) {
    var s_data = shift_templates[shift_t_id].data;
    var shift_name = get_shift_name(s_data);
Damien Moulard committed
45
    let msg = 'Inscription au créneau ' + shift_name;
46 47 48 49

    openModal(
        msg,
        function() {
50
            setTimeout(openModal, 300); // to show something happened , work in process
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
            let data = {
                partner_id: parseInt(partner_data.partner_id, 10),
                shift_type: 1, //force to standard
                shift_template_id: shift_t_id,
                unsubscribe_first: true
            };

            $.ajax({
                type: 'POST',
                url: '/members/shift_subscription',
                data: JSON.stringify(data),
                dataType:"json",
                traditional: true,
                contentType: "application/json; charset=utf-8",
                success: function(data) {
                    stdata = data.shift_template;
                    partner_data.regular_shift_name = stdata.name;
                    partner_data.shift_type = "standard";
                    init_my_info_data();
70
                    location.reload();
71 72 73 74 75 76
                },
                error: function(err_data) {
                    if (
                        err_data.status == 409
                        && typeof (err_data.responseJSON) != "undefined"
                    ) {
77 78 79 80
                        let modal_template = $("#modal_generic_error_change_shift_template");
                        modal_template.find(".modal_generic_error_change_shift_template_text").text(
                                err_data.responseJSON.message
                        );
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
                        closeModal();
                        openModal(
                            modal_template.html(),
                            () => {},
                            "Compris !",
                            true,
                            false
                        );
                    } else {
                        err = {
                            msg: "erreur serveur lors de l'inscription du membre au créneau",
                            ctx: 'members_space.shift_subscrition'
                        };
                        report_JS_error(err, 'members_space');
                        closeModal();

                        $.notify("Une erreur est survenue lors de l'inscription au créneau.", {
                            globalPosition:"top right",
                            className: "error"
                        });
                    }
                }
            });
Damien Moulard committed
104

105 106 107 108 109
        },
        'Valider',
        true, // modal closes after validation
        true,
        edit_shift_template_registration // on cancel , reload calendar
110 111 112
    );
}

Damien Moulard committed
113
function edit_shift_template_registration() {
114
    const calendar_params = {external: true, without_modal: true, shift_listener: true};
115 116 117 118 119 120 121
    if (calendar == null) calendar = $('#modal-calendar-choice').clone();
    if ($('#modal-calendar-choice').html().length > 0) {
        $('#modal-calendar-choice').empty();

    }
    calendar.find('.oddeven_selector').empty();
    displayMsg(calendar.html());
Damien Moulard committed
122 123
    $('#week_types').find('input')
        .change(() => {
124
            filter_weeks(calendar_params);
Damien Moulard committed
125
        });
126
    retrieve_and_draw_shift_tempates(calendar_params);
Damien Moulard committed
127

128 129 130

}

131
function init_home() {
Damien Moulard committed
132
    $("#go_to_shifts_calendar").on("click", () => {
133 134 135 136 137
        goto('echange-de-services');
    });
    $("#home_go_to_shift_history").on("click", () => {
        goto('mes-services');
    });
Damien Moulard committed
138 139 140
    $("#see_more_info_link").on('click', (e) => {
        e.preventDefault();
        goto('mes-infos');
Damien Moulard committed
141
    });
Etienne Freiss committed
142 143 144 145 146
    // $("#go_to_forms").prop("href", "forms_link");
    $("#go_to_forms").on('click', (e) => {
        e.preventDefault();
        goto('faq');
    });
François committed
147

148
    $(".member_shift_name_area").on("click", ".fa-edit", (e) => {
Damien Moulard committed
149 150
        $('#week_types').find('input')
            .change(filter_weeks);
151 152 153 154
        e.preventDefault();
        edit_shift_template_registration();
    });

155 156 157 158 159 160 161 162 163 164 165 166
    if (partner_data.is_in_association === false) {
        $("#home .member_associated_partner_area").hide();
    } else {
        if (partner_data.is_associated_people === "True") {
            $(".member_associated_partner").text(partner_data.parent_name);
        } else if (partner_data.associated_partner_id !== "False") {
            $(".member_associated_partner").text(partner_data.associated_partner_name);
        }
    }

    // TODO vérif tile my info avec données binomes + rattrapage et délai

Damien Moulard committed
167 168
    // Init my info tile
    init_my_info_data();
François committed
169

170 171 172
    if (incoming_shifts !== null) {
        init_my_shifts_tile();
    } else {
173
        load_partner_shifts(partner_data.concerned_partner_id)
174 175
            .then(init_my_shifts_tile);
    }
Félicie committed
176 177
    
    display_messages_for_service_exchange_24h_before();
178
}