Settings

class webix.Settings()

Settings mixin

References

helpers
ajax(), extend().

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
webix.Settings={
    $init:function(){
        /*
            property can be accessed as this.config.some
            in same time for inner call it have sense to use _settings
            because it will be minified in final version
        */
        this._settings = this.config= {};
    },
    define:function(property, value){
        if (typeof property == "object")
            return this._parseSeetingColl(property);
        return this._define(property, value);
    },
    _define:function(property,value){
        //method with name {prop}_setter will be used as property setter
        //setter is optional
        var setter = this[property+"_setter"];
        return (this._settings[property]=setter?setter.call(this,value,property):value);
    },
    //process configuration object
    _parseSeetingColl:function(coll){
        if (coll){
            for (var a in coll)                //for each setting
                this._define(a,coll[a]);        //set value through config
        }
    },
    //helper for object initialization
    _parseSettings:function(obj,initial){
        //initial - set of default values
        var settings = {};
        if (initial)
            settings = webix.extend(settings,initial);

        //code below will copy all properties over default one
        if (typeof obj == "object" && !obj.tagName)
            webix.extend(settings,obj, true);
        //call config for each setting
        this._parseSeetingColl(settings);
    },
    _mergeSettings:function(config, defaults){
        for (var key in defaults)
            switch(typeof config[key]){
                case "object":
                    config[key] = this._mergeSettings((config[key]||{}), defaults[key]);
                    break;
                case "undefined":
                    config[key] = defaults[key];
                    break;
                default:    //do nothing
                    break;
            }
        return config;
    }
};
/*
    ajax operations

    can be used for direct loading as
        webix.ajax(ulr, callback)
    or
        webix.ajax().getItem(url)
        webix.ajax().post(url)

*/