DragOrder

class webix.DragOrder()

Dragorder mixin

References

helpers
delay(), scrollSize().

Referenced by

mixins
DragItem().

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
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
webix.DragOrder={
    _do_not_drag_selection:true,
    $drag:function(s,e){
        var html = webix.DragItem.$drag.call(this,s,e);
        if (html){
            var context = webix.DragControl.getContext();
            if (this.getBranchIndex)
                this._drag_order_stored_left = this._drag_order_complex?((this.getItem(context.start).$level) * 16):0;
            if (!context.fragile)
                this.addCss(context.start, "webix_transparent");
        }
        return html;
    },
    _getDragItemPos: function(pos,e){
        return webix.DragItem._getDragItemPos(pos,e);
    },
    $dragPos:function(pos,e, node){
        var box = webix.html.offset(this.$view);
        var left = box.x + (this._drag_order_complex?( 1+this._drag_order_stored_left):1);
        var top = pos.y;
        var config = this._settings;
        var xdrag = (config.layout == "x");

        if (xdrag){
            top = box.y + (this._drag_order_complex?( + box.height - webix.ui.scrollSize - 1):1);
            left = pos.x;
        }

        node.style.display = 'none';

        var html = document.elementFromPoint(left, top);

        if (html != this._last_sort_dnd_node){
            var view = webix.$$(html);
            //this type of dnd is limited to the self
            if (view && view == this){
                var id = this.locate(html, true);
                var start_id = webix.DragControl.getContext().start;
                this._auto_scroll_force = true;
                if (id){

                    if (id != this._last_sort_dnd_node){
                        if (id != start_id){
                            var details, index;

                            if (this.getBranchIndex){
                                details = { parent:this.getParentId(id) };
                                index = this.getBranchIndex(id);
                            } else {
                                details = {};
                                index = this.getIndexById(id);
                            }

                            if (this.callEvent("onBeforeDropOrder",[start_id, index, e, details])){
                                this.move(start_id, index, this, details);
                                this._last_sort_dnd_node = id;
                            }
                        }
                        webix.DragControl._last = this._contentobj;
                    }
                }
                else {
                    id = "$webix-last";
                    if (this._last_sort_dnd_node != id){
                        if (!this.callEvent("onBeforeDropOrder",[start_id, -1, e, { parent: 0} ])) return;
                        this._last_sort_dnd_node  = id;
                    }
                }
            }
        }

        node.style.display = 'block';


        if (xdrag){
            pos.y = box.y;
            pos.x = pos.x-18;

            if (pos.x < box.x)
                pos.x = box.x;
            else {
                var max = box.x + this.$view.offsetWidth - 60;
                if (pos.x > max)
                    pos.x = max;
            }
        } else {
            box.y += this._header_height;
            pos.x = this._drag_order_stored_left||box.x;
            pos.y = pos.y-18;

            if (pos.y < box.y)
                pos.y = box.y;
            else {
                var max = box.y + this.$view.offsetHeight - 60;
                if (pos.y > max)
                    pos.y = max;
            }
        }

        if (this._auto_scroll_delay)
            this._auto_scroll_delay = window.clearTimeout(this._auto_scroll_delay);

        this._auto_scroll_delay = webix.delay(this._auto_scroll, this, [webix.html.pos(e), this.locate(e) || null],250);

        //prevent normal dnd landing checking
        webix.DragControl._skip = true;
    },
    $dragIn:function(){
        return false;
    },
    $drop:function(s,t,e){
        if (this._auto_scroll_delay){
            this._auto_scroll_force = null;
            this._auto_scroll_delay = window.clearTimeout(this._auto_scroll_delay);
        }

        var context = webix.DragControl.getContext();
        var id = context.start;
        this.removeCss(id, "webix_transparent");

        var index = this.getIndexById(id);
        this.callEvent("onAfterDropOrder",[id, index , e]);
        if (context.fragile)
            this.refresh();
    }
};