initialize: function() {

        this.model = new Contact;

        BackboneValidation.bind(this, {
            valid: function (view, attr, selector) {
                var el = view.$('[name="' + attr + '"]'),
                    container = el.closest('.mui-textfield');
                el.removeClass('mui--is-invalid');
                container.find('.error-reason').remove();
            },
            invalid: function (view, attr, error, selector) {
                var el = view.$el.find('[name="' + attr + '"]'),
                    container = el.closest('.mui-textfield');
                el.addClass('mui--is-invalid');
                container.find('.error-reason').remove();
                container.append('<span class="error-reason" style="color: red">'+error+'</span>');
            }
        });

        Toast.options = {
            "positionClass": "toast-bottom-right",
            "preventDuplicates": true
        }
    },
    },
    childViewEvents: {
        'finish': 'onFinish',
    },
    initialize: function(){
        this.payment_conditions_options = Radio.channel('config').request(
            'get:options', 'payment_conditions'
        );
        this.lookupDefault();

        var channel = Radio.channel('facade');
        this.listenTo(channel, 'bind:validation', this.bindValidation);
        this.listenTo(channel, 'unbind:validation', this.unbindValidation);
    },
    bindValidation(){
        Validation.bind(this);
    },
    unbindValidation(){
        Validation.unbind(this);
    },
    showErrors(model, errors){
        this.$el.addClass('error');
    },
    hideErrors(model){
        this.$el.removeClass('error');
    },
    onFinish(field_name, value){
        if (field_name == 'predefined_conditions'){
            var condition_object = this.getCondition(value);

            this.model.set('predefined_conditions', value);
        Validation.unbind(this.view);
    },
    onSyncSuccess(datas, status, result){
        var channel = Radio.channel("message");
        channel.trigger('success:backbone', result);
        Validation.unbind(this.view);
        console.log("Trigger success:sync from FormBehavior");
        this.view.triggerMethod('success:sync');
    },
    syncServer(datas, bound){
        var bound = bound || false;
        var datas = datas || this.view.model.toJSON();

        if (!bound){
            Validation.bind(this.view, {
                attributes(view){return _.keys(datas)}
            });
        }

        if (this.view.model.isValid(_.keys(datas))){
            let request;
            if (! this.view.model.get('id')){
                request = this.addSubmit(datas);
            } else {
                request = this.editSubmit(datas);
            }
            console.log(request);
            request.done(this.onSyncSuccess.bind(this)
                        ).fail(this.onSyncError.bind(this)
                              );
        }