a5a2ea7c376af316cf14708509745dea9e60d93a
1 /***************************************************************
4 * (c) 2010 TYPO3 Tree Team <http://forge.typo3.org/projects/typo3v4-extjstrees>
7 * This script is part of the TYPO3 project. The TYPO3 project is
8 * free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * The GNU General Public License can be found at
14 * http://www.gnu.org/copyleft/gpl.html.
15 * A copy is found in the textfile GPL.txt and important notices to the license
16 * from the author is found in LICENSE.txt distributed with these scripts.
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26 Ext
.namespace('TYPO3.Components.PageTree');
29 * @class TYPO3.Components.PageTree.DeletionDropZone
33 * @namespace TYPO3.Components.PageTree
35 * @author Stefan Galinski <stefan.galinski@gmail.com>
37 TYPO3
.Components
.PageTree
.DeletionDropZone
= Ext
.extend(Ext
.Panel
, {
46 * Hide the drop zone initially
57 commandProvider
: null,
69 * @cfg {TYPO3.Components.PageTree.App}
74 * Removed node had a previous sibling
78 isPreviousSibling
: false,
83 * @type {Ext.tree.TreeNode}
88 * Click Handler for the recovery text
92 textClickHandler
: null,
95 * Amount of drops (used to prevent early hiding of the box)
104 * The "afterrender" event creates the drop zone
109 this.createDropZone();
111 this.getEl().on('mouseout', function(e
) {
112 if (!e
.within(this.getEl(), true)) {
113 this.removeClass(this.id
+ '-activateProxyOver');
114 if (!this.app
.activeTree
.shouldCopyNode
) {
115 this.app
.activeTree
.copyHint
.show();
124 if (this.textClickHandler
) {
132 * Initializes the component
136 initComponent: function() {
137 this.html
= '<p><span id="' + this.id
+ '-icon" class="' +
138 TYPO3
.Components
.PageTree
.Sprites
.TrashCan
+
139 '"> </span><span id="' + this.id
+ '-text">' +
140 TYPO3
.Components
.PageTree
.LLL
.dropToRemove
+ '</span></p>';
142 TYPO3
.Components
.PageTree
.DeletionDropZone
.superclass
.initComponent
.apply(this, arguments
);
147 * Creates the drop zone and it's functionality
151 createDropZone: function() {
152 (new Ext
.dd
.DropZone(this.getEl(), {
153 ddGroup
: this.ddGroup
,
155 notifyOver: function(ddProxy
, e
) {
156 ddProxy
.setDragElPos(e
.xy
[0], e
.xy
[1] - 60);
157 return this.id
+ '-proxyOver';
158 }.createDelegate(this),
160 notifyEnter: function() {
161 this.addClass(this.id
+ '-activateProxyOver');
162 if (!this.app
.activeTree
.shouldCopyNode
) {
163 this.app
.activeTree
.copyHint
.hide();
166 return this.id
+ '-proxyOver';
167 }.createDelegate(this),
169 notifyDrop: function(ddProxy
, e
, n
) {
175 var tree
= node
.ownerTree
;
176 var nodeHasChildNodes
= (node
.hasChildNodes() || node
.isExpandable());
179 if (!top
.TYPO3
.configuration
.inWorkspace
&& !nodeHasChildNodes
) {
180 callback
= this.setRecoverState
.createDelegate(this);
183 if (nodeHasChildNodes
) {
184 node
.ownerTree
.commandProvider
.confirmDelete(node
, tree
, callback
, true);
186 node
.ownerTree
.commandProvider
.deleteNode(node
, tree
, callback
);
188 }.createDelegate(this)
193 * Sets the drop zone into the recovery state
195 * @param {Ext.tree.TreeNode} node
196 * @param {TYPO3.Components.PageTree.Tree} tree
197 * @param {Boolean} succeeded
200 setRecoverState: function(node
, tree
, succeeded
) {
202 this.toOriginState();
208 this.updateIcon(TYPO3
.Components
.PageTree
.Sprites
.TrashCanRestore
);
210 node
.text
+ '<br />' +
211 '<span class="' + this.id
+ '-restore">' +
212 '<span class="' + this.id
+ '-restoreText">' +
213 TYPO3
.Components
.PageTree
.LLL
.dropZoneElementRemoved
+
219 ++this.amountOfDrops
;
221 if (!--this.amountOfDrops
) {
222 this.toOriginState();
224 }).defer(10000, this);
226 this.textClickHandler
= this.restoreNode
.createDelegate(this, [node
, tree
]);
227 Ext
.get(this.id
+ '-text').on('click', this.textClickHandler
);
229 this.isPreviousSibling
= false;
230 this.previousNode
= node
.parentNode
;
231 if (node
.previousSibling
) {
232 this.previousNode
= node
.previousSibling
;
233 this.isPreviousSibling
= true;
238 * Updates the drop zone text label
240 * @param {String} text
241 * @param {Boolean} animate
244 updateText: function(text
, animate
) {
245 animate
= animate
|| false;
247 var elementText
= Ext
.get(this.id
+ '-text');
249 elementText
.animate({opacity
: {to
: 0}}, 1, function(elementText
) {
250 elementText
.update(text
);
251 elementText
.setStyle('opacity', 1);
254 elementText
.update(text
);
259 * Updates the drop zone icon with another sprite icon
261 * @param {String} classes
264 updateIcon: function(classes
) {
265 Ext
.get(this.id
+ '-icon').set({
271 * Resets the drop zone to the initial state
273 * @param {Boolean} hide
276 toOriginState: function(hide
) {
277 if (hide
!== false) {
281 Ext
.get(this.id
+ '-text').un('click', this.textClickHandler
);
282 this.previousNode
= this.textClickHandler
= null;
283 this.isPreviousSibling
= false;
285 if (hide
&& !this.app
.activeTree
.dragZone
.dragging
) {
290 this.updateText(TYPO3
.Components
.PageTree
.LLL
.dropToRemove
, false);
291 this.updateIcon(TYPO3
.Components
.PageTree
.Sprites
.TrashCan
);
295 * Restores the last removed node
297 * @param {Ext.tree.TreeNode} node
298 * @param {TYPO3.Components.PageTree.Tree} tree
301 restoreNode: function(node
, tree
) {
302 if (this.isPreviousSibling
) {
303 this.commandProvider
.restoreNodeAfterDestination(node
, tree
, this.previousNode
);
305 this.commandProvider
.restoreNodeToFirstChildOfDestination(node
, tree
, this.previousNode
);
308 this.updateText(TYPO3
.Components
.PageTree
.LLL
.dropZoneElementRestored
);
311 if (this.textClickHandler
) {
312 this.toOriginState();
314 }).defer(3000, this);
318 // XTYPE Registration
319 Ext
.reg('TYPO3.Components.PageTree.DeletionDropZone', TYPO3
.Components
.PageTree
.DeletionDropZone
);