BaseBind

class webix.BaseBind()

Basebind mixin

References

mixins
BindSource(), EventSystem().
helpers
bind(), extend(), log().

Referenced by

components
DataCollection(), DataRecord(), DataValue().
views
baseview().

External references

Official documentation page.

Code

 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
webix.BaseBind = {
    bind:function(target, rule, format){
        if (!this.attachEvent)
            webix.extend(this, webix.EventSystem);

        if (typeof target == 'string')
            target = webix.$$(target);

        if (target._initBindSource) target._initBindSource();
        if (this._initBindSource) this._initBindSource();



        if (!target.getBindData)
            webix.extend(target, webix.BindSource);

        this._bind_ready();

        target.addBind(this._settings.id, rule, format);
        this._bind_source = target._settings.id;

        if (webix.debug_bind)
            webix.log("[bind] "+this.name+"@"+this._settings.id+" <= "+target.name+"@"+target._settings.id);

        var target_id = this._settings.id;
        //FIXME - check for touchable is not the best solution, to detect necessary event
        this._bind_refresh_handler = this.attachEvent(this.touchable?"onAfterRender":"onBindRequest", function(){
            return target.getBindData(target_id);
        });

        if (this.refresh && this.isVisible(this._settings.id))
            this.refresh();
    },
    unbind:function(){
        if (this._bind_source){
            var target = webix.$$(this._bind_source);
            if (target)
                target.removeBind(this._settings.id);
            this.detachEvent(this._bind_refresh_handler);
            this._bind_source = null;
        }
    },
    _bind_ready:function(){
        var config = this._settings;
        if (this.filter){
            var key = config.id;
            this.data._on_sync = webix.bind(function(){
                webix.$$(this._bind_source)._bind_updated[key] = false;
            }, this);
        }

        var old_render = this.render;
        this.render = function(){
            if (this._in_bind_processing) return;

            this._in_bind_processing = true;
            var result = this.callEvent("onBindRequest");
            this._in_bind_processing = false;

            return old_render.apply(this, ((result === false)?arguments:[]));
        };

        if (this.getValue||this.getValues)
            this.save = function(data){
                var source = webix.$$(this._bind_source);
                if (data)
                    source.setBindData(data);
                else {
                    if (this.validate && !this.validate()) return false;
                    var values = this.getValue?this.getValue:this.getValues();
                    source.setBindData(values,this._settings.id);
                    //reset form, so it will be counted as saved
                    if (this.setDirty)
                        this.setDirty(false);
                }
            };

        this._bind_ready = function(){};
    }
};

//bind interface