prepa_odoo.js 24.5 KB
Newer Older
Administrator committed
1 2 3
var to_fill_box = $('#to_fill'),
    with_errors_box = $('#with_errors'),
    coops = {'to_fill': [],
4 5 6 7
        'with_errors': [],
        'waiting_validation_employee':[],
        'waiting_validation_member':[],
        'done':[]},
Administrator committed
8
    validation_next_steps = {'to_fill': 'waiting_validation_employee',
9 10
        'waiting_validation_employee': 'waiting_validation_member',
        'waiting_validation_member': 'done'},
Administrator committed
11 12 13 14 15 16 17 18 19 20 21 22 23

    dashboard = $('#dashboard'),

    coop_validation_form = $('#coop_validation_form'),
    warning_slide = $('#warning_slide'),
    warning_msg = $('#new_warning_form textarea[name="message"]'),
    waiting_validation_employee_div = $('#waiting_validation_employee'),
    waiting_validation_member_div = $('#waiting_validation_member'),
    done_div = $('#done'),
    form_delete = $('#form_delete'),
    problem_delete = $('#problem_delete'),
    vform = $('#coop_validation_form');

24 25 26 27 28 29 30 31 32 33
// date validation
Date.prototype.isValid = function () {

    // If the date object is invalid it
    // will return 'NaN' on getTime()
    // and NaN is never equal to itself.
    return this.getTime() === this.getTime();
};


Administrator committed
34
sync.on('change', function (info) {
35 36 37 38
    // handle change
    if (info.direction == 'pull') {
        retrieve_all_coops();
    }
Administrator committed
39 40 41 42 43
}).on('paused', function (err) {
    // replication paused (e.g. replication up to date, user went offline)
    if (err) {
        online = false;
    }
44 45 46 47 48
})
    .on('active', function () {
    // replicate resumed (e.g. new changes replicating, user went back online)
        online = true;
    })
Damien Moulard committed
49
    .on('denied', function () {
50 51
    // a document failed to replicate (e.g. due to permissions)
    })
Damien Moulard committed
52
    .on('complete', function () {
53 54 55 56 57 58 59
    // handle complete
    })
    .on('error', function (err) {
    // handle error
        console.log('erreur sync');
        console.log(err);
    });
Administrator committed
60 61


62 63 64 65
function home() {
    coop_page.hide();
    warning_slide.hide();
    dashboard.show();
Administrator committed
66 67 68
}

function is_in_coops(mail) {
69 70 71 72 73 74 75 76 77 78 79
    var answer = false;

    for (key in coops) {
        $.each(coops[key], function(i, e) {
            if (e._id == mail) {
                answer = true;
            }
        });
    }

    return answer;
Administrator committed
80 81 82 83
}

// Store/update coop data in couchdb
function store_current_coop_data(callback) {
84
    dbc.put(current_coop, function(err, result) {
Administrator committed
85
        if (!err) {
86 87
            current_coop._rev = result.rev;
            if (callback) callback(err);
Administrator committed
88 89 90
        } else {
            console.log(err);
            if (err.name == 'conflict') {
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
                dbc.get(current_coop._id, {'latest': true})
                    .then(function(retrieved_coop) {
                        if (current_coop.errors) {
                            var err_msg = current_coop.errors;

                            if (retrieved_coop.errors && retrieved_coop.errors != err_msg) {
                                err_msg += ' ' + retrieved_coop.errors;
                                current_coop.errors = err_msg;
                            }

                        }
                        current_coop._rev = retrieved_coop._rev;
                        console.log('Enregistrement redemandé');
                        store_current_coop_data(callback);
                    });
Administrator committed
106 107
            }
        }
108
    });
Administrator committed
109 110 111 112
}

// Remove old document if id (email) changed before applying changes
function put_current_coop_in_buffer_db(callback) {
113 114 115
    var can_continue = true;

    if (typeof current_coop._old_id != "undefined") {
Damien Moulard committed
116
        dbc.remove(current_coop._old_id, current_coop._rev, function(err) {
117 118 119 120 121 122 123 124 125 126 127 128
            if (err) {
                console.log(err); can_continue = false;
            }
        });
        delete current_coop._rev;
        delete current_coop._old_id;
    }
    if (can_continue == true) {
        store_current_coop_data(callback);
    } else {
        alert('Problème de sauvegarde des modifications');
    }
Administrator committed
129 130
}

131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
function process_new_warning(event) {
    event.preventDefault();
    var msg = warning_msg.val();

    openModal();
    if (msg.length > 0) {
        current_coop.errors = msg;
        store_current_coop_data(function() {
            retrieve_all_coops();
            closeModal();
            home();
            display_msg_box('Enregistrement signalement problème terminé.', 'success');
        });
    } else {
        closeModal();
        alert('Le message est vide !');
    }
Administrator committed
148 149 150 151
}

// Set current coop to previous validation state
function previous_validation_state() {
152 153 154 155 156 157
    for (var key in validation_next_steps) {
        if (current_coop.validation_state == validation_next_steps[key]) {
            current_coop.validation_state = key;
            store_current_coop_data();
            break;
        }
Administrator committed
158 159 160 161
    }
}

function submit_full_coop_form() {
162 163 164 165 166
    let form = $('#coop_validation_form');
    var form_data = new FormData(form.get(0)),
        m_barcode = form.find('[name="m_barcode"]'),
        sex = $('#sex'),
        has_empty_values = false;
Administrator committed
167

168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
    for (var pair of form_data.entries()) {
        let val = pair[1],
            key = pair[0];

        if ($('input[name="' + key +'"]').get(0)
            .hasAttribute('required') && val.length == 0) {
            has_empty_values = true;
        }
    }

    if (has_empty_values == true) {
        closeModal();
        alert('Vous devez remplir tous les champs pour valider.');
        // If form not submitted, set back coop current validation_state
        previous_validation_state();
    } else {
        form_data.set(
            'firstname',
            vform.find('input[name="firstname"]').val()
                .toFormatedFirstName()
        );
        form_data.set(
            'lastname',
            vform.find('input[name="lastname"]').val()
                .toFormatedLastName()
        );
        form_data.set('odoo_id', current_coop.odoo_id);

        form_data.set('shift_template', JSON.stringify(current_coop.shift_template));
        //Fields beeing disabled : force value
        form_data.set('shares_nb', vform.find('input[name="shares_nb"]').val());
        form_data.set('shares_euros', vform.find('input[name="shares_euros"]').val());
        form_data.set('checks_nb', vform.find('input[name="checks_nb"]').val());
        form_data.set('payment_meaning', vform.find('input[name="payment_meaning"]').val());
        if (m_barcode.length > 0) {
            form_data.set('m_barcode', m_barcode.val());
        }
205 206 207
        if (sex.length > 0) {
            form_data.set('sex', $('input[name="sex"]:checked').val());
        }
208 209
        post_form(
            '/members/coop_validated_data', form_data,
Damien Moulard committed
210
            function(err) {
211 212 213 214 215 216 217
                if (!err) {
                    setTimeout(after_save, 1500);
                } else {
                    console.log(err);
                }
            }
        );
Administrator committed
218 219 220 221
    }
}

function odoo_create_coop() {
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
    var current_coop_copy = current_coop;

    current_coop_copy.shift_template = JSON.stringify(current_coop.shift_template);
    $.post({url : '/members/create_from_buffered_data/',
        headers: { "X-CSRFToken": getCookie("csrftoken") },
        data : current_coop_copy,
        dataType :'json'
    })
        .done(function(rData) {
            if (rData.odoo_id && ! isNaN(rData.odoo_id)) {
                after_save();
            } else {
                alert('Erreur pendant l\'enregistrement Odoo');
            }
        })
        .fail(function() {
            after_save(1);
        });
Administrator committed
240 241 242 243 244
}

// Save the current coop details from form values
// Then do callback function
function save_current_coop(callback) {
245 246 247
    //_id obligatoire !
    let form = coop_validation_form,
        _id = form.find('[name="email"]').val(),
248 249
        m_barcode = form.find('[name="m_barcode"]'),
        sex = form.find('[name="sex"]');
250 251

    if (current_coop != null && _id.length > 0) {
Administrator committed
252
    //Birthdate verification
253 254 255
        let birthdate = form.find('[name="birthdate"]').val()
            .trim();
        var birthdate_error = false,
256 257
            m_barcode_error = false,
            sex_error = false;
258 259

        if (/([0-9]{2})\/([0-9]{2})\/([0-9]{4})/.exec(birthdate)) {
260
            try {
261
                var jj = RegExp.$1,
262 263
                    mm = RegExp.$2,
                    aaaa = RegExp.$3;
264

265 266
                let tmp_date = aaaa + "-" + mm + "-" + jj;
                // try to create a date object
267

268 269 270
                date_test = new Date(tmp_date);
                // if date is invalid a correction is apply in date object. Check it
                // january start at 0, so we add + 1 for the month
271
                if ((date_test.getDate() !== parseInt(jj)) || ((date_test.getMonth()+1) !== parseInt(mm)) || (date_test.getFullYear() !== parseInt(aaaa)) || !date_test.isValid()) {
272 273
                    birthdate_error = true;
                }
274
            } catch (Exception) {
275 276
                birthdate_error = true;
            }
277

278 279 280
        } else {
            birthdate_error = true;
        }
Administrator committed
281

282 283


284 285
        let street2_input = form.find('[name="street2"]'),
            phone_input = form.find('[name="phone"]');
Administrator committed
286

287 288 289 290 291 292 293
        current_coop.firstname = form.find('[name="firstname"]').val()
            .toFormatedFirstName();
        current_coop.lastname = form.find('[name="lastname"]').val()
            .toFormatedLastName();
        if (current_coop._id != _id) {
            current_coop._old_id = current_coop._id;
        }
Administrator committed
294

295 296 297
        current_coop._id = _id;
        current_coop.birthdate = birthdate;
        current_coop.address = form.find('[name="address"]').val();
298 299 300 301 302

        if (sex.length > 0) {
            current_coop.sex = $('input[name="sex"]:checked').val();
            if (typeof current_coop.sex == "undefined") sex_error = true;
        }
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320
        if (street2_input.length > 0) {
            current_coop.street2 = street2_input.val();
        }
        current_coop.city = form.find('[name="city"]').val();
        current_coop.zip = form.find('[name="zip"]').val();
        current_coop.country = form.find('[name="country"]').val();
        current_coop.mobile = form.find('[name="mobile"]').val();
        if (phone_input.length > 0) {
            current_coop.phone = phone_input.val();
        }
        current_coop.shares_nb = form.find('[name="shares_nb"]').val();
        current_coop.shares_euros = form.find('[name="shares_euros"]').val();
        current_coop.checks_nb = form.find('[name="checks_nb"]').val();
        current_coop.payment_meaning = form.find('[name="payment_meaning"]').val();
        if (m_barcode.length > 0) {
            current_coop.m_barcode = m_barcode.val();
            if (!isValidEAN13(current_coop.m_barcode)) m_barcode_error = true;
        }
321
        if ((birthdate_error == true || m_barcode_error == true || sex_error == true) && callback) {
322 323 324 325 326 327 328 329
            put_current_coop_in_buffer_db();
            closeModal();
            var msg = '';

            if (birthdate_error == true)
                msg += "La date de naissance ne semble pas correcte (jj/mm/aaaa)\n";
            if (m_barcode_error == true)
                msg += "Le code-barre n'est pas valide\n";
330 331
            if (sex_error == true)
                msg += "Une option concernant le sexe doit être cochée\n";
332 333 334 335 336 337 338
            alert(msg);
        } else {
            // Send coop to next step
            if (callback) current_coop.validation_state = validation_next_steps[current_coop.validation_state];
            //if not were are in the case of problem warning (no validation step change)
            put_current_coop_in_buffer_db(callback);
        }
Administrator committed
339 340 341 342
    }
}

// After save, get coops again and reset page
343 344 345
function after_save(err) {
    closeModal();
    if (!err) {
Administrator committed
346
    // put_current_coop_in_buffer_db(retrieve_all_coops);
347 348 349 350 351
        retrieve_all_coops();
        home();
    } else {
        alert('Une erreur est survenue pendant l\'enregistrement');
    }
Administrator committed
352 353 354
}

// Validate & store sensitive data from form, check for errors, then do relevant action according to process state
355 356 357 358 359 360 361 362 363 364 365 366
function process_validation_form(event) {
    event.preventDefault();
    //Shares nb and euros are consistent ?
    var shares_nb = parseInt($('[name="shares_nb"]').val(), 10);
    var shares_euros = parseInt($('[name="shares_euros"]').val(), 10);
    var is_valid = true;

    if (!isNaN(shares_nb) && !isNaN(shares_euros)) {
        if (shares_euros != 10*shares_nb) {
            is_valid = false;
            alert('Le nombre de parts et le montant en euros ne correspondent pas !');
        }
Administrator committed
367 368
    }

369
    if (current_coop.payment_meaning == "ch" && current_coop.checks_nb < 1) {
Administrator committed
370
        is_valid = false;
371
        alert('Le nombre de chèques doit être supérieur à 0 !');
Administrator committed
372 373
    }

374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399
    // Save checks details
    var total = 0;

    if (current_coop.validation_state == 'waiting_validation_employee' && current_coop.payment_meaning == "ch" && current_coop.checks_nb > 1) {
        var checks = [];

        for (var i = 1; i <= current_coop.checks_nb; i++) {
            var check_value = parseInt($('[name="check_' + i + '"]').val());

            if (check_value == 0) {
                is_valid = false;
                alert('Un chèque ne peut pas avoir une valeur à 0 !');
            } else {
                checks.push(check_value);
                total += check_value;
            }
        }

        if (total != $('[name="shares_euros"]').val()) {
            if (is_valid) {
                is_valid = false;
                alert('La somme des chèques ne correspond pas au montant de la cotisation !');
            }
        } else {
            current_coop.checks = JSON.stringify(checks);
        }
Administrator committed
400
    }
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416

    if (is_time_to('save_form_in_odoo')) {
        if (is_valid == true) {
            openModal();

            if (current_coop.validation_state == "to_fill") {
                save_current_coop(after_save); // First step, coop info only saved in couchdb
            } else if (current_coop.validation_state == 'waiting_validation_employee') {
                save_current_coop(odoo_create_coop); // Second step, coop is created in odoo
            } else if (current_coop.validation_state == 'waiting_validation_member') {
                save_current_coop(submit_full_coop_form);
            }
        } else {
            alert('Formulaire non valide.');
            closeModal();
        }
Administrator committed
417
    } else {
418
        closeModal();
Administrator committed
419 420 421
    }
}

422 423 424 425 426 427
function process_signaler_click() {
    var coop_msg = '';

    if (current_coop.coop_msg) {
        coop_msg = 'Message coop : ' + current_coop.coop_msg;
    } else {
Administrator committed
428
    //save cuuren_coop with already given data
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452
        save_current_coop();
    }

    dashboard.hide();
    coop_page.hide();
    // Connected user can delete a coop if errors exist
    if (!coop_is_connected() || (typeof (current_coop.errors) == "undefined" && typeof (current_coop.coop_msg) == "undefined")) {
        form_delete.hide();
        problem_delete.hide();
    } else if (coop_is_connected()) {
        if (typeof (current_coop.errors) != "undefined" || typeof (current_coop.coop_msg) != "undefined")
            form_delete.show();
        problem_delete.show();
    }

    warning_slide.find('[name="firstname"]').val(current_coop.firstname);
    warning_slide.find('[name="lastname"]').val(current_coop.lastname);
    //warning_slide.find('[name="barcode_base"]').val(current_coop.barcode_base);
    warning_slide.find('[name="message"]').val(current_coop.errors || '');
    warning_slide.find('p.coop_msg').html(coop_msg);
    if (current_coop.odoo_state && current_coop.odoo_state == 'done') {
        form_delete.show();
    }
    warning_slide.show();
Administrator committed
453 454 455
}

// Select the coop being udpated
456 457 458 459 460 461
function set_current_coop(clicked, callback) {
    var id = clicked.id;
    var type = clicked.validation_state;
    var coops_set = null;
    //coop_form is always empty, in order to remove all previous data, which could be associated to another coop.

462 463
    coop_validation_form.find(':input').not('[type="radio"]')
        .val('');
464 465 466 467 468 469 470 471 472 473 474 475
    if (type == 'to_fill') {
        coops_set = coops.to_fill;
    } else if (type == 'with_errors') {
        coops_set = coops.with_errors;
    } else if (type == 'waiting_validation_employee') {
        coops_set = coops.waiting_validation_employee;
    } else if (type == 'waiting_validation_member') {
        coops_set = coops.waiting_validation_member;
    } else if (type == 'done') {
        coops_set = coops.done;
    } else {
        coops_set = coops.to_fill;
Administrator committed
476
    }
477 478 479 480 481 482 483 484 485 486
    if (coops_set != null) {
        if (type != 'done') {
            dashboard.hide();
        }
        for (i in coops_set) {
            if (coops_set[i]._id == id) {
                current_coop = coops_set[i];
                callback();
            }
        }
Administrator committed
487 488 489 490 491
    }
}

// Archive a member record: delete from temp db
function coop_form_delete() {
492
    try {
Administrator committed
493
    //Call django method (instead of pouchdb call)
494 495 496 497 498 499 500 501 502 503 504 505
        post_form(
            '/members/remove_data_from_couchdb',
            {email: current_coop._id},
            function(err, result) {
                if (!err) {
                    if (typeof(result.msg) != "undefined") {
                        alert(result.msg);
                    } else if (result.action === null) {
                        display_msg_box('Données supprimées.');
                        current_coop = null;
                        closeModal();
                        home();
Administrator committed
506
                    }
507 508 509 510 511 512
                }
            }
        );
    } catch (e) {
        console.log(e);
    }
Administrator committed
513 514 515
}

function coop_problem_delete() {
516 517 518 519 520 521 522
    delete current_coop.errors;
    delete current_coop.coop_msg;
    store_current_coop_data(function() {
        retrieve_all_coops();
        closeModal();
        home();
    });
Administrator committed
523 524
}

525
function open_coop_form(e) {
526 527 528
    try {
        if (e) {
            var clicked = $(this);
529

530 531 532
            coop_target = {};
            coop_target.id = clicked.data('id');
            coop_target.validation_state = clicked.closest('div.main').attr('id');
533
        } else {
534
            return display_current_coop_form();
535
        }
536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552

        set_current_coop(coop_target, function() {
            if (coop_target.validation_state == 'to_fill') {
                display_current_coop_form();
            } else if ((coop_target.validation_state == 'waiting_validation_employee' || coop_target.validation_state == 'waiting_validation_member') && coop_is_connected()) {
                display_current_coop_form();
            } else if (coop_target.validation_state == 'done') {
                ask_for_deletion();
            } else {
                process_signaler_click();
            }
        });
    } catch (err) {
        error = {msg: err.name + ' : ' + err.message, ctx: 'open_coop_form'};
        console.error(error);
        report_JS_error(error, 'prepa-odoo');
    }
Damien Moulard committed
553 554

    return null;
Administrator committed
555 556 557
}

function ask_for_deletion() {
558 559 560 561
    var msg = 'Voulez-vous archiver ';

    msg += current_coop.firstname + ' ' + current_coop.lastname + ' ?';
    openModal(msg, coop_form_delete, 'Oui');
Administrator committed
562 563 564
}

function ask_for_problem_deletion() {
565 566 567
    var msg = 'Voulez-vous enlever ' + current_coop.firstname + ' ' + current_coop.lastname + ' des coops à problème ?';

    openModal(msg, coop_problem_delete, 'Oui');
Administrator committed
568
}
569
function add_coop_to_box(box, coop) {
570 571
    try {
        var info = coop.firstname + ' ' + coop.lastname;
572

573 574 575
        if (coop.odoo_state && coop.odoo_state == 'done') {
            info = coop.barcode_base + ' - ' + info;
        }
576

577 578 579 580 581 582 583 584 585 586 587
        info = $('<span/>').text(info);
        var cbox = $('<div/>').addClass('coop')
            .attr('data-id', coop._id)
            .append(info);
        // Only connected user can do these actions

        if ([
            "waiting_validation_employee",
            "waiting_validation_member",
            "done"
        ].indexOf(coop.validation_state) > -1
Administrator committed
588
      && !coop_is_connected()) {
589 590 591 592 593 594 595
            cbox.addClass('coop_no_select');
        }
        box.append(cbox);
    } catch (e) {
        err = {msg: e.name + ' : ' + e.message, ctx: 'add_coop_to_box'};
        console.error(err);
        report_JS_error(err, 'prepa-odoo');
596
    }
Administrator committed
597 598 599 600
}

//Called after having retrieved all coops
function dispatch_coops_in_boxes() {
601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623
    try {
        $('div.coop').off('click', open_coop_form);
        to_fill_box.html('');
        with_errors_box.html('');
        waiting_validation_employee_div.find('.elts').html('');
        waiting_validation_member_div.find('.elts').html('');
        done_div.find('.elts').html('');

        $.each(coops.to_fill, function(i, e) {
            add_coop_to_box(to_fill_box, e);
        });
        $.each(coops.with_errors, function(i, e) {
            add_coop_to_box(with_errors_box, e);
        });
        $.each(coops.waiting_validation_employee, function(i, e) {
            add_coop_to_box(waiting_validation_employee_div.find('.elts'), e);
        });
        $.each(coops.waiting_validation_member, function(i, e) {
            add_coop_to_box(waiting_validation_member_div.find('.elts'), e);
        });
        $.each(coops.done, function(i, e) {
            add_coop_to_box(done_div.find('.elts'), e);
        });
624

625 626 627 628 629 630 631
        $('div.coop').on('click', open_coop_form);
        $('div.coop_no_select').off('click', open_coop_form);
    } catch (e) {
        err = {msg: e.name + ' : ' + e.message, ctx: 'dispatch_coops_in_boxes'};
        console.error(err);
        report_JS_error(err, 'prepa-odoo');
    }
Administrator committed
632 633
}

634 635 636 637 638 639 640 641 642 643 644 645 646 647
function handle_legacy_states(rows) {
    $.each(rows, function(i, e) {
        if (typeof (e.doc.validation_state) == "undefined") {
            if (typeof (e.doc.odoo_state) !== "undefined" && e.doc.odoo_state == 'done') {
                rows[i].doc.validation_state = 'done';
            } else if (typeof (e.doc.odoo_id) == "undefined" && typeof (e.doc.birthdate) != "undefined") {
                rows[i].doc.validation_state = 'waiting_validation_employee';
            } else if (typeof (e.doc.odoo_id) !== "undefined") {
                rows[i].doc.validation_state = 'waiting_validation_member';
            } else {
                rows[i].doc.validation_state = 'to_fill';
            }
        }
    });
Administrator committed
648

649
    return rows;
Administrator committed
650 651 652 653
}

// first function called when loading page
function retrieve_all_coops() {
654 655 656 657
    try {
        dbc.allDocs({include_docs: true, descending: true}, function(err, resp) {
            if (err) {
                return console.log(err);
658
            }
659 660 661 662 663 664 665 666 667 668 669 670 671 672
            coops = {'to_fill': [], 'with_errors': [], 'waiting_validation_employee':[], 'waiting_validation_member':[], 'done':[]};
            $.each(handle_legacy_states(resp.rows), function(i, e) {
                if (e.doc.firstname) {
                    if (e.doc.errors) {
                        coops.with_errors.push(e.doc);
                    } else if (e.doc.validation_state == "to_fill") {
                        coops.to_fill.push(e.doc);
                    } else if (e.doc.validation_state == "waiting_validation_employee") {
                        coops.waiting_validation_employee.push(e.doc);
                    } else if (e.doc.validation_state == "waiting_validation_member") {
                        coops.waiting_validation_member.push(e.doc);
                    } else if (e.doc.validation_state == "done") {
                        coops.done.push(e.doc);
                    }
Administrator committed
673

674 675 676 677
                    if (e.doc.coop_msg) {
                        coops.with_errors.push(e.doc);
                    }
                }
678

679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696
            });

            coops['to_fill'].sort(function(a, b) {
                return a.barcode_base - b.barcode_base;
            });
            coops['with_errors'].sort(function(a, b) {
                return a.barcode_base - b.barcode_base;
            });
            coops['waiting_validation_employee'].sort(function(a, b) {
                return a.barcode_base - b.barcode_base;
            });
            coops['waiting_validation_member'].sort(function(a, b) {
                return a.odoo_id - b.odoo_id;
            });
            coops['done'].sort(function(a, b) {
                return b.timestamp - a.timestamp;
            });
            dispatch_coops_in_boxes();
Damien Moulard committed
697 698

            return null;
699
        });
700 701 702 703 704
    } catch (err) {
        error = {msg: err.name + ' : ' + err.message, ctx: 'retrieve_all_coops'};
        console.log(error);
        report_JS_error(error, 'prepa-odoo');
    }
Administrator committed
705 706 707
}

$(document).ready(function() {
708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728
    retrieve_all_coops();

    coop_validation_form.submit(process_validation_form);
    coop_validation_form.find('[name="signaler"]').click(process_signaler_click);
    $('#new_warning_form').submit(process_new_warning);

    $('.next_step button').click(function() {
        var clicked = $(this);

        if (clicked.data('action') == 'coop_form') {
            warning_slide.hide();
            open_coop_form();
        } else if (clicked.data('action') == 'form_delete') {
            ask_for_deletion();
        } else if (clicked.data('action') == 'problem_delete') {
            ask_for_problem_deletion();
        } else {
            current_coop = null;
            home();
        }
    });
Administrator committed
729 730

});