3 <title>The source code</title>
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
7 <body onload="prettyPrint();">
8 <pre class="prettyprint lang-js"><div id="cls-Ext.DataView.LabelEditor"></div>/**
\r
9 * @class Ext.DataView.LabelEditor
\r
10 * @extends Ext.Editor
\r
13 Ext.DataView.LabelEditor = Ext.extend(Ext.Editor, {
\r
16 cls: "x-small-editor",
\r
18 completeOnEnter: true,
\r
20 labelSelector: 'span.x-editable',
\r
22 constructor: function(cfg, field){
\r
23 Ext.DataView.LabelEditor.superclass.constructor.call(this,
\r
24 field || new Ext.form.TextField({
\r
34 init : function(view){
\r
36 view.on('render', this.initEditor, this);
\r
37 this.on('complete', this.onSave, this);
\r
40 initEditor : function(){
\r
43 containerclick: this.doBlur,
\r
46 this.view.getEl().on('mousedown', this.onMouseDown, this, {delegate: this.labelSelector});
\r
55 onMouseDown : function(e, target){
\r
56 if(!e.ctrlKey && !e.shiftKey){
\r
57 var item = this.view.findItemFromChild(target);
\r
59 var record = this.view.store.getAt(this.view.indexOf(item));
\r
60 this.startEdit(target, record.data[this.dataIndex]);
\r
61 this.activeRecord = record;
\r
67 onSave : function(ed, value){
\r
68 this.activeRecord.set(this.dataIndex, value);
\r
73 Ext.DataView.DragSelector = function(cfg){
\r
75 var view, proxy, tracker;
\r
76 var rs, bodyRegion, dragRegion = new Ext.lib.Region(0,0,0,0);
\r
77 var dragSafe = cfg.dragSafe === true;
\r
79 this.init = function(dataView){
\r
81 view.on('render', onRender);
\r
84 function fillRegions(){
\r
86 view.all.each(function(el){
\r
87 rs[rs.length] = el.getRegion();
\r
89 bodyRegion = view.el.getRegion();
\r
92 function cancelClick(){
\r
96 function onBeforeStart(e){
\r
97 return !dragSafe || e.target == view.el.dom;
\r
100 function onStart(e){
\r
101 view.on('containerclick', cancelClick, view, {single:true});
\r
103 proxy = view.el.createChild({cls:'x-view-selector'});
\r
105 if(proxy.dom.parentNode !== view.el.dom){
\r
106 view.el.dom.appendChild(proxy.dom);
\r
108 proxy.setDisplayed('block');
\r
111 view.clearSelections();
\r
114 function onDrag(e){
\r
115 var startXY = tracker.startXY;
\r
116 var xy = tracker.getXY();
\r
118 var x = Math.min(startXY[0], xy[0]);
\r
119 var y = Math.min(startXY[1], xy[1]);
\r
120 var w = Math.abs(startXY[0] - xy[0]);
\r
121 var h = Math.abs(startXY[1] - xy[1]);
\r
123 dragRegion.left = x;
\r
124 dragRegion.top = y;
\r
125 dragRegion.right = x+w;
\r
126 dragRegion.bottom = y+h;
\r
128 dragRegion.constrainTo(bodyRegion);
\r
129 proxy.setRegion(dragRegion);
\r
131 for(var i = 0, len = rs.length; i < len; i++){
\r
132 var r = rs[i], sel = dragRegion.intersect(r);
\r
133 if(sel && !r.selected){
\r
135 view.select(i, true);
\r
136 }else if(!sel && r.selected){
\r
137 r.selected = false;
\r
145 view.un('containerclick', cancelClick, view);
\r
148 proxy.setDisplayed(false);
\r
152 function onRender(view){
\r
153 tracker = new Ext.dd.DragTracker({
\r
154 onBeforeStart: onBeforeStart,
\r
159 tracker.initEl(view.el);
\r