source: trunk/web/addons/job_monarch/lib/extjs-30/examples/ux/Portal.js @ 625

Last change on this file since 625 was 625, checked in by ramonb, 15 years ago

lib/extjs-30:

  • new ExtJS 3.0
File size: 5.8 KB
Line 
1/*!
2 * Ext JS Library 3.0.0
3 * Copyright(c) 2006-2009 Ext JS, LLC
4 * licensing@extjs.com
5 * http://www.extjs.com/license
6 */
7Ext.ux.Portal = Ext.extend(Ext.Panel, {
8    layout : 'column',
9    autoScroll : true,
10    cls : 'x-portal',
11    defaultType : 'portalcolumn',
12   
13    initComponent : function(){
14        Ext.ux.Portal.superclass.initComponent.call(this);
15        this.addEvents({
16            validatedrop:true,
17            beforedragover:true,
18            dragover:true,
19            beforedrop:true,
20            drop:true
21        });
22    },
23
24    initEvents : function(){
25        Ext.ux.Portal.superclass.initEvents.call(this);
26        this.dd = new Ext.ux.Portal.DropZone(this, this.dropConfig);
27    },
28   
29    beforeDestroy : function() {
30        if(this.dd){
31            this.dd.unreg();
32        }
33        Ext.ux.Portal.superclass.beforeDestroy.call(this);
34    }
35});
36
37Ext.reg('portal', Ext.ux.Portal);
38
39
40Ext.ux.Portal.DropZone = function(portal, cfg){
41    this.portal = portal;
42    Ext.dd.ScrollManager.register(portal.body);
43    Ext.ux.Portal.DropZone.superclass.constructor.call(this, portal.bwrap.dom, cfg);
44    portal.body.ddScrollConfig = this.ddScrollConfig;
45};
46
47Ext.extend(Ext.ux.Portal.DropZone, Ext.dd.DropTarget, {
48    ddScrollConfig : {
49        vthresh: 50,
50        hthresh: -1,
51        animate: true,
52        increment: 200
53    },
54
55    createEvent : function(dd, e, data, col, c, pos){
56        return {
57            portal: this.portal,
58            panel: data.panel,
59            columnIndex: col,
60            column: c,
61            position: pos,
62            data: data,
63            source: dd,
64            rawEvent: e,
65            status: this.dropAllowed
66        };
67    },
68
69    notifyOver : function(dd, e, data){
70        var xy = e.getXY(), portal = this.portal, px = dd.proxy;
71
72        // case column widths
73        if(!this.grid){
74            this.grid = this.getGrid();
75        }
76
77        // handle case scroll where scrollbars appear during drag
78        var cw = portal.body.dom.clientWidth;
79        if(!this.lastCW){
80            this.lastCW = cw;
81        }else if(this.lastCW != cw){
82            this.lastCW = cw;
83            portal.doLayout();
84            this.grid = this.getGrid();
85        }
86
87        // determine column
88        var col = 0, xs = this.grid.columnX, cmatch = false;
89        for(var len = xs.length; col < len; col++){
90            if(xy[0] < (xs[col].x + xs[col].w)){
91                cmatch = true;
92                break;
93            }
94        }
95        // no match, fix last index
96        if(!cmatch){
97            col--;
98        }
99
100        // find insert position
101        var p, match = false, pos = 0,
102            c = portal.items.itemAt(col),
103            items = c.items.items, overSelf = false;
104
105        for(var len = items.length; pos < len; pos++){
106            p = items[pos];
107            var h = p.el.getHeight();
108            if(h === 0){
109                overSelf = true;
110            }
111            else if((p.el.getY()+(h/2)) > xy[1]){
112                match = true;
113                break;
114            }
115        }
116
117        pos = (match && p ? pos : c.items.getCount()) + (overSelf ? -1 : 0);
118        var overEvent = this.createEvent(dd, e, data, col, c, pos);
119
120        if(portal.fireEvent('validatedrop', overEvent) !== false &&
121           portal.fireEvent('beforedragover', overEvent) !== false){
122
123            // make sure proxy width is fluid
124            px.getProxy().setWidth('auto');
125
126            if(p){
127                px.moveProxy(p.el.dom.parentNode, match ? p.el.dom : null);
128            }else{
129                px.moveProxy(c.el.dom, null);
130            }
131
132            this.lastPos = {c: c, col: col, p: overSelf || (match && p) ? pos : false};
133            this.scrollPos = portal.body.getScroll();
134
135            portal.fireEvent('dragover', overEvent);
136
137            return overEvent.status;
138        }else{
139            return overEvent.status;
140        }
141
142    },
143
144    notifyOut : function(){
145        delete this.grid;
146    },
147
148    notifyDrop : function(dd, e, data){
149        delete this.grid;
150        if(!this.lastPos){
151            return;
152        }
153        var c = this.lastPos.c, col = this.lastPos.col, pos = this.lastPos.p;
154
155        var dropEvent = this.createEvent(dd, e, data, col, c,
156            pos !== false ? pos : c.items.getCount());
157
158        if(this.portal.fireEvent('validatedrop', dropEvent) !== false &&
159           this.portal.fireEvent('beforedrop', dropEvent) !== false){
160
161            dd.proxy.getProxy().remove();
162            dd.panel.el.dom.parentNode.removeChild(dd.panel.el.dom);
163           
164            if(pos !== false){
165                if(c == dd.panel.ownerCt && (c.items.items.indexOf(dd.panel) <= pos)){
166                    pos++;
167                }
168                c.insert(pos, dd.panel);
169            }else{
170                c.add(dd.panel);
171            }
172           
173            c.doLayout();
174
175            this.portal.fireEvent('drop', dropEvent);
176
177            // scroll position is lost on drop, fix it
178            var st = this.scrollPos.top;
179            if(st){
180                var d = this.portal.body.dom;
181                setTimeout(function(){
182                    d.scrollTop = st;
183                }, 10);
184            }
185
186        }
187        delete this.lastPos;
188    },
189
190    // internal cache of body and column coords
191    getGrid : function(){
192        var box = this.portal.bwrap.getBox();
193        box.columnX = [];
194        this.portal.items.each(function(c){
195             box.columnX.push({x: c.el.getX(), w: c.el.getWidth()});
196        });
197        return box;
198    },
199
200    // unregister the dropzone from ScrollManager
201    unreg: function() {
202        //Ext.dd.ScrollManager.unregister(this.portal.body);
203        Ext.ux.Portal.DropZone.superclass.unreg.call(this);
204    }
205});
Note: See TracBrowser for help on using the repository browser.