backend.js 1.49 KB
Newer Older
1 2 3 4 5 6 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 37 38 39 40 41 42 43 44 45 46 47 48 49 50
odoo.define('lacagette_membership.backend', function(require){
    "use strict";

    var core = require('web.core');
    var FormView = require('web.FormView');
    var Model = require('web.DataModel');
    var framework = require('web.framework');
    var _t = core._t;
    var partner_id = null;
    var last_call = 0;

    FormView.include({

        load_record: function() {
          var self = this;
          return this._super.apply(this, arguments)
            .then(function() {
              partner_id = self.get_fields_values().id;

            });
        }
    });


    $(document).on('change', '#coop_state_selection', function(){
        var d = new Date()
        var elapsed_since_last_call = d.getTime() - last_call
        let new_state = $(this).val()
        if (elapsed_since_last_call > 5000) {
            last_call = d.getTime()
            let fields = {id: partner_id, state: new_state}
            framework.blockUI();
            new Model('res.partner').call('set_special_state',[fields]).then(function(rData){
                window.location.reload()
            },function(err,event){
                event.preventDefault();
                var error_body = _t('Your Internet connection is probably down.');
                if (err.data) {
                    var except = err.data;
                    error_body = except.arguments && except.arguments[0] || except.message || error_body;
                }
               alert(error_body)
            });
        }
        
    });



});