?? ddview.js
字號:
/*
* Ext JS Library 2.2
* Copyright(c) 2006-2008, Ext JS, LLC.
* licensing@extjs.com
*
* http://extjs.com/license
*/
/* * Software License Agreement (BSD License) * Copyright (c) 2008, Nige "Animal" White * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * Neither the name of the original author nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. *//** * @class Ext.ux.DDView * <p>A DnD-enabled version of {@link Ext.DataView}. Drag/drop is implemented by adding * {@link Ext.data.Record}s to the target DDView. If copying is not being performed, * the original {@link Ext.data.Record} is removed from the source DDView.</p> * @constructor * Create a new DDView * @param {Object} config The configuration properties. */Ext.ux.DDView = function(config) { if (!config.itemSelector) { var tpl = config.tpl; if (this.classRe.test(tpl)) { config.tpl = tpl.replace(this.classRe, 'class=$1x-combo-list-item $2$1'); } else { config.tpl = tpl.replace(this.tagRe, '$1 class="x-combo-list-item" $2'); } config.itemSelector = ".x-combo-list-item"; } Ext.ux.DDView.superclass.constructor.call(this, Ext.apply(config, { border: false }));};Ext.extend(Ext.ux.DDView, Ext.DataView, { /** * @cfg {String/Array} dragGroup The ddgroup name(s) for the View's DragZone (defaults to undefined). */ /** * @cfg {String/Array} dropGroup The ddgroup name(s) for the View's DropZone (defaults to undefined). */ /** * @cfg {Boolean} copy Causes drag operations to copy nodes rather than move (defaults to false). */ /** * @cfg {Boolean} allowCopy Causes ctrl/drag operations to copy nodes rather than move (defaults to false). */ /** * @cfg {String} sortDir Sort direction for the view, 'ASC' or 'DESC' (defaults to 'ASC'). */ sortDir: 'ASC', // private isFormField: true, classRe: /class=(['"])(.*)\1/, tagRe: /(<\w*)(.*?>)/, reset: Ext.emptyFn, clearInvalid: Ext.form.Field.prototype.clearInvalid, // private afterRender: function() { Ext.ux.DDView.superclass.afterRender.call(this); if (this.dragGroup) { this.setDraggable(this.dragGroup.split(",")); } if (this.dropGroup) { this.setDroppable(this.dropGroup.split(",")); } if (this.deletable) { this.setDeletable(); } this.isDirtyFlag = false; this.addEvents( "drop" ); }, // private validate: function() { return true; }, // private destroy: function() { this.purgeListeners(); this.getEl().removeAllListeners(); this.getEl().remove(); if (this.dragZone) { if (this.dragZone.destroy) { this.dragZone.destroy(); } } if (this.dropZone) { if (this.dropZone.destroy) { this.dropZone.destroy(); } } }, /** * Allows this class to be an Ext.form.Field so it can be found using {@link Ext.form.BasicForm#findField}. */ getName: function() { return this.name; }, /** * Loads the View from a JSON string representing the Records to put into the Store. * @param {String} value The JSON string */ setValue: function(v) { if (!this.store) { throw "DDView.setValue(). DDView must be constructed with a valid Store"; } var data = {}; data[this.store.reader.meta.root] = v ? [].concat(v) : []; this.store.proxy = new Ext.data.MemoryProxy(data); this.store.load(); }, /** * Returns the view's data value as a list of ids. * @return {String} A parenthesised list of the ids of the Records in the View, e.g. (1,3,8). */ getValue: function() { var result = '('; this.store.each(function(rec) { result += rec.id + ','; }); return result.substr(0, result.length - 1) + ')'; }, getIds: function() { var i = 0, result = new Array(this.store.getCount()); this.store.each(function(rec) { result[i++] = rec.id; }); return result; }, /** * Returns true if the view's data has changed, else false. * @return {Boolean} */ isDirty: function() { return this.isDirtyFlag; }, /** * Part of the Ext.dd.DropZone interface. If no target node is found, the * whole Element becomes the target, and this causes the drop gesture to append. */ getTargetFromEvent : function(e) { var target = e.getTarget(); while ((target !== null) && (target.parentNode != this.el.dom)) { target = target.parentNode; } if (!target) { target = this.el.dom.lastChild || this.el.dom; } return target; }, /** * Create the drag data which consists of an object which has the property "ddel" as * the drag proxy element. */ getDragData : function(e) { var target = this.findItemFromChild(e.getTarget()); if(target) { if (!this.isSelected(target)) { delete this.ignoreNextClick; this.onItemClick(target, this.indexOf(target), e); this.ignoreNextClick = true; } var dragData = { sourceView: this, viewNodes: [], records: [], copy: this.copy || (this.allowCopy && e.ctrlKey) }; if (this.getSelectionCount() == 1) { var i = this.getSelectedIndexes()[0]; var n = this.getNode(i); dragData.viewNodes.push(dragData.ddel = n); dragData.records.push(this.store.getAt(i)); dragData.repairXY = Ext.fly(n).getXY(); } else { dragData.ddel = document.createElement('div'); dragData.ddel.className = 'multi-proxy'; this.collectSelection(dragData); } return dragData; } return false; }, // override the default repairXY. getRepairXY : function(e){ return this.dragData.repairXY; }, // private collectSelection: function(data) { data.repairXY = Ext.fly(this.getSelectedNodes()[0]).getXY(); if (this.preserveSelectionOrder === true) { Ext.each(this.getSelectedIndexes(), function(i) { var n = this.getNode(i); var dragNode = n.cloneNode(true); dragNode.id = Ext.id(); data.ddel.appendChild(dragNode); data.records.push(this.store.getAt(i)); data.viewNodes.push(n); }, this); } else { var i = 0; this.store.each(function(rec){ if (this.isSelected(i)) { var n = this.getNode(i); var dragNode = n.cloneNode(true); dragNode.id = Ext.id(); data.ddel.appendChild(dragNode); data.records.push(this.store.getAt(i)); data.viewNodes.push(n); } i++; }, this); } }, /** * Specify to which ddGroup items in this DDView may be dragged. * @param {String} ddGroup The DD group name to assign this view to. */ setDraggable: function(ddGroup) { if (ddGroup instanceof Array) { Ext.each(ddGroup, this.setDraggable, this); return; } if (this.dragZone) { this.dragZone.addToGroup(ddGroup); } else { this.dragZone = new Ext.dd.DragZone(this.getEl(), { containerScroll: true, ddGroup: ddGroup }); // Draggability implies selection. DragZone's mousedown selects the element. if (!this.multiSelect) { this.singleSelect = true; } // Wire the DragZone's handlers up to methods in *this* this.dragZone.getDragData = this.getDragData.createDelegate(this); this.dragZone.getRepairXY = this.getRepairXY; this.dragZone.onEndDrag = this.onEndDrag; } }, /** * Specify from which ddGroup this DDView accepts drops. * @param {String} ddGroup The DD group name from which to accept drops. */ setDroppable: function(ddGroup) { if (ddGroup instanceof Array) { Ext.each(ddGroup, this.setDroppable, this); return; } if (this.dropZone) { this.dropZone.addToGroup(ddGroup); } else { this.dropZone = new Ext.dd.DropZone(this.getEl(), { owningView: this, containerScroll: true, ddGroup: ddGroup }); // Wire the DropZone's handlers up to methods in *this* this.dropZone.getTargetFromEvent = this.getTargetFromEvent.createDelegate(this); this.dropZone.onNodeEnter = this.onNodeEnter.createDelegate(this); this.dropZone.onNodeOver = this.onNodeOver.createDelegate(this);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -