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 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
|
<html>
<head>
<title>The source code</title>
<link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../resources/prettify/prettify.js"></script>
</head>
<body onload="prettyPrint();">
<pre class="prettyprint lang-js"><div id="cls-Ext.DataView.LabelEditor"></div>/**
* @class Ext.DataView.LabelEditor
* @extends Ext.Editor
*
*/
Ext.DataView.LabelEditor = Ext.extend(Ext.Editor, {
alignment: "tl-tl",
hideEl : false,
cls: "x-small-editor",
shim: false,
completeOnEnter: true,
cancelOnEsc: true,
labelSelector: 'span.x-editable',
constructor: function(cfg, field){
Ext.DataView.LabelEditor.superclass.constructor.call(this,
field || new Ext.form.TextField({
allowBlank: false,
growMin:90,
growMax:240,
grow:true,
selectOnFocus:true
}), cfg
);
},
init : function(view){
this.view = view;
view.on('render', this.initEditor, this);
this.on('complete', this.onSave, this);
},
initEditor : function(){
this.view.on({
scope: this,
containerclick: this.doBlur,
click: this.doBlur
});
this.view.getEl().on('mousedown', this.onMouseDown, this, {delegate: this.labelSelector});
},
doBlur: function(){
if(this.editing){
this.field.blur();
}
},
onMouseDown : function(e, target){
if(!e.ctrlKey && !e.shiftKey){
var item = this.view.findItemFromChild(target);
e.stopEvent();
var record = this.view.store.getAt(this.view.indexOf(item));
this.startEdit(target, record.data[this.dataIndex]);
this.activeRecord = record;
}else{
e.preventDefault();
}
},
onSave : function(ed, value){
this.activeRecord.set(this.dataIndex, value);
}
});
Ext.DataView.DragSelector = function(cfg){
cfg = cfg || {};
var view, proxy, tracker;
var rs, bodyRegion, dragRegion = new Ext.lib.Region(0,0,0,0);
var dragSafe = cfg.dragSafe === true;
this.init = function(dataView){
view = dataView;
view.on('render', onRender);
};
function fillRegions(){
rs = [];
view.all.each(function(el){
rs[rs.length] = el.getRegion();
});
bodyRegion = view.el.getRegion();
}
function cancelClick(){
return false;
}
function onBeforeStart(e){
return !dragSafe || e.target == view.el.dom;
}
function onStart(e){
view.on('containerclick', cancelClick, view, {single:true});
if(!proxy){
proxy = view.el.createChild({cls:'x-view-selector'});
}else{
if(proxy.dom.parentNode !== view.el.dom){
view.el.dom.appendChild(proxy.dom);
}
proxy.setDisplayed('block');
}
fillRegions();
view.clearSelections();
}
function onDrag(e){
var startXY = tracker.startXY;
var xy = tracker.getXY();
var x = Math.min(startXY[0], xy[0]);
var y = Math.min(startXY[1], xy[1]);
var w = Math.abs(startXY[0] - xy[0]);
var h = Math.abs(startXY[1] - xy[1]);
dragRegion.left = x;
dragRegion.top = y;
dragRegion.right = x+w;
dragRegion.bottom = y+h;
dragRegion.constrainTo(bodyRegion);
proxy.setRegion(dragRegion);
for(var i = 0, len = rs.length; i < len; i++){
var r = rs[i], sel = dragRegion.intersect(r);
if(sel && !r.selected){
r.selected = true;
view.select(i, true);
}else if(!sel && r.selected){
r.selected = false;
view.deselect(i);
}
}
}
function onEnd(e){
if (!Ext.isIE) {
view.un('containerclick', cancelClick, view);
}
if(proxy){
proxy.setDisplayed(false);
}
}
function onRender(view){
tracker = new Ext.dd.DragTracker({
onBeforeStart: onBeforeStart,
onStart: onStart,
onDrag: onDrag,
onEnd: onEnd
});
tracker.initEl(view.el);
}
};</pre>
</body>
</html>
|