subscription_common.js 5.06 KB
Newer Older
1
//used in prepa-odoo and validation_coop
Administrator committed
2 3 4
var coop_page = $('#coop_page');

function show_checks_nb() {
5 6 7 8
    $('#coop_validation_form').find('[name="checks_nb"]')
        .show();
    $('#coop_validation_form').find('[id="checks_nb_label"]')
        .show();
Administrator committed
9 10 11
}

function hide_checks_nb() {
12 13 14 15 16 17
    $('#coop_validation_form').find('[name="checks_nb"]')
        .hide();
    $('#coop_validation_form').find('[name="checks_nb"]')
        .val(0);
    $('#coop_validation_form').find('[id="checks_nb_label"]')
        .hide();
Administrator committed
18 19 20
}

function open_shift_choice() {
21 22 23
    schoice_view.show();
    coop_page.hide();
    retrieve_and_draw_shift_tempates();
Administrator committed
24 25 26
}

function display_current_coop_form() {
27 28 29 30
    let form = $('#coop_validation_form'),
        chgt_shift_btn = $('#change_shift_template');
    var ftop_shift = $('#choosen_shift [name="ftop"]'),
        m_barcode = form.find('[name="m_barcode"]'),
31 32
        sex = $('#sex'),
        job = $('#job');
33 34 35
    let street2_input = form.find('[name="street2"]'),
        phone_input = form.find('[name="phone"]');

Etienne Freiss committed
36 37 38 39 40 41 42 43 44
    if (current_coop.parent_name) {
        $('#associated_member').show();
        if (current_coop.parent_id)
            $('#associated_member_name').text(current_coop.parent_name);
        else $('#associated_member_name').text(current_coop.parent_name + " ATTENTION à faire manuellement");
    } else {
        $('#associated_member').hide();
    }

45 46 47 48 49 50 51 52 53
    chgt_shift_btn.hide();
    chgt_shift_btn.off('click', open_shift_choice);
    form.find('[name="firstname"]').val(current_coop.firstname);
    form.find('[name="lastname"]').val(current_coop.lastname);

    if (m_barcode.length > 0 && typeof current_coop.m_barcode != "undefined") {
        m_barcode.val(current_coop.m_barcode);
    }
    if (sex.length > 0 && typeof current_coop.sex != "undefined") {
54
        $('input[name="sex"][value="' + current_coop.sex + '"]').prop('checked', true);
55
    }
56 57 58
    if (job.length > 0) {
        form.find('[name="job"]').val(current_coop.function);
    }
59 60 61
    // form.find('[name="barcode_base"]').val(current_coop.barcode_base);
    form.find('[name="email"]').val(current_coop._id);
    if (current_coop.shift_template &&
62 63
        current_coop.shift_template.data.type == 2 &&
        typeof manage_ftop != "undefined" && manage_ftop == true) {
64 65 66
        $('#choosen_shift input').hide();
        ftop_shift.val('Volant');
        ftop_shift.show();
Administrator committed
67

68
    } else {
69
        // Bien laisser dans cet ordre
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
        $('#choosen_shift input').show();
        ftop_shift.hide();

    }

    form.find('[name="birthdate"]').val(current_coop.birthdate || '');
    form.find('[name="address"]').val(current_coop.address || '');
    form.find('[name="city"]').val(current_coop.city || '');
    form.find('[name="zip"]').val(current_coop.zip || '');
    form.find('[name="country"]').val(current_coop.country || 'France');
    form.find('[name="mobile"]').val(current_coop.mobile || '');
    form.find('[name="shares_nb"]').val(current_coop.shares_nb || '');
    form.find('[name="shares_euros"]').val(current_coop.shares_euros || '');
    form.find('[name="payment_meaning"]').val(current_coop.payment_meaning || '');
    form.find('[name="checks_nb"]').val(current_coop.checks_nb || 0);
    if (street2_input.length > 0) {
        street2_input.val(current_coop.street2 || '');
Administrator committed
87
    }
88 89
    if (phone_input.length > 0) {
        phone_input.val(current_coop.phone || '');
Administrator committed
90
    }
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
    // Checks
    form.find('[name="checks_nb"]').hide();
    form.find('[id="checks_nb_label"]').hide();
    $('#checks').hide();
    var check_details = $('#checks').find('.check_details');

    $(check_details).html('');
    // Display checks number if paid by checks
    if (current_coop.payment_meaning == "ch") {
        show_checks_nb();

        // Display check details if in payment validation step and more than 1 check
        if (current_coop.validation_state == "waiting_validation_employee" && current_coop.checks_nb > 1) {
            $('#checks').show();

            for (var i = 1; i <= current_coop.checks_nb; i++) {
107
                $(check_details).append('<p>Chèque #' + i + ' : <input type="text" name="check_' + i + '" class="b_green check_item" required/> € </p>');
108 109
            }
        }
Administrator committed
110 111
    }

112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
    if (current_coop.shift_template) {
        var st = current_coop.shift_template.data;

        form.find('[name="week"]').val(weeks_name[st.week]);
        form.find('[name="day"]').val(st.day);
        form.find('[name="hour"]').val(st.begin);
        var place = st.place;

        if (place == mag_place_string) {
            place = 'Magasin';
        } else if (place == office_place_string) {
            place = 'Bureau';
        }
        form.find('[name="place"]').val(place);
    }
Administrator committed
127

128
    let show_change_shift = current_coop.validation_state === 'waiting_validation_employee';
129 130 131 132 133
    if (show_change_shift == true) {
        chgt_shift_btn.show();
        chgt_shift_btn.on('click', open_shift_choice);
    }

134
    if (typeof (coop_page) != "undefined") {
135 136
        coop_page.show();
    }
Administrator committed
137 138
}

139
$('#payment_meaning').change(function () {
140 141 142 143 144
    if ($(this).val() == 'ch') {
        show_checks_nb();
    } else {
        hide_checks_nb();
    }
Administrator committed
145
});