672b91606e024fccb3ace1e0b853cf18ff424454
[Packages/TYPO3.CMS.git] / typo3 / sysext / pagetree / components / pagetree / javascript / tree.js
1 /***************************************************************
2 * Copyright notice
3 *
4 * (c) 2010 TYPO3 Tree Team <http://forge.typo3.org/projects/typo3v4-extjstrees>
5 * All rights reserved
6 *
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.
12 *
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.
17 *
18 *
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.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27 /**
28 * TYPO3 Page Tree Panel
29 */
30
31 Ext.namespace('TYPO3.Components.PageTree');
32
33 TYPO3.Components.PageTree.Tree = Ext.extend(Ext.tree.TreePanel, {
34 id: 'typo3-pagetree-tree',
35 border: false,
36
37 enableDD: true,
38 dragConfig: {
39 ddGroup: 'TreeDD'
40 },
41
42 t3ContextNode: null,
43 t3ContextInfo: {
44 inCopyMode: false,
45 inCutMode: false
46 },
47
48 rootVisible: false,
49 pageTree: null,
50 contextMenuConfiguration: null,
51
52 initComponent: function() {
53 this.contextMenu = new TYPO3.Components.PageTree.ContextMenu({});
54
55 this.root = new Ext.tree.AsyncTreeNode({
56 expanded: true,
57 id: 'root'
58 });
59
60 this.loader = new Ext.tree.TreeLoader({
61 directFn: this.pageTree.dataProvider.getNextTreeLevel,
62 paramOrder: 'attributes',
63
64 baseAttrs: {
65 uiProvider: 't3'
66 },
67
68 uiProviders: {
69 t3: TYPO3.Components.PageTree.PageTreeUI,
70 rootNodeProvider: Ext.tree.TreeNodeUI
71 },
72
73 createNode: function(attr) {
74 if (attr.id == 0) {
75 attr.id = 'siteRootNode';
76 }
77
78 return Ext.tree.TreeLoader.prototype.createNode.call(this, attr);
79 },
80
81 listeners: {
82 beforeload: function(treeLoader, node) {
83 treeLoader.baseParams.attributes = node.attributes;
84 },
85
86 load: {
87 scope: this,
88 fn: function(treeLoader, node) {
89 this.restoreState(node.getPath());
90 }
91 }
92 }
93 });
94
95 TYPO3.Components.PageTree.Tree.superclass.initComponent.apply(this, arguments);
96 },
97
98 // shows the context menu and creates it if it's not already done
99 openContextMenu: function(node, event) {
100 node.select();
101
102 var attributes = { t3ContextInfo: node.ownerTree.t3ContextInfo };
103 attributes = Ext.apply(node.attributes.nodeData, attributes);
104
105 this.pageTree.contextMenuDataProvider.getActionsForNodeArray(
106 attributes,
107 function(result) {
108 var contextMenu = node.getOwnerTree().contextMenu;
109 contextMenu.removeAll();
110
111 var numberOfElementsInside = contextMenu.fillWithMenuItems(node, this.pageTree, result);
112 if (numberOfElementsInside > 0) {
113 contextMenu.showAt(event.getXY());
114 }
115 },
116 this
117 );
118 },
119
120 refreshTree: function() {
121 this.getLoader().load(this.root);
122 },
123
124 refreshNode: function(node) {
125 this.getLoader().load(node);
126 },
127
128 listeners: {
129 // this event triggers the context menu
130 contextmenu: {
131 scope: this,
132 fn: function(node, event) {
133 node.getOwnerTree().openContextMenu(node, event);
134 }
135 },
136
137 // calls a given single click callback for the tree
138 click: {
139 fn: function(node, event) {
140 if (this.clicksRegistered === 2) {
141 this.clicksRegistered = 0;
142 event.stopEvent();
143 return false;
144 }
145
146 this.clicksRegistered = 0;
147 this.pageTree.commandProvider.singleClick(node);
148 },
149 delay: 400
150 },
151
152 // needed or the label edit will never work
153 beforedblclick: {
154 fn: function() {
155 return false;
156 }
157 },
158
159 beforeclick: {
160 fn: function(node, event) {
161 if (!this.clicksRegistered && this.getSelectionModel().isSelected(node)) {
162 node.fireEvent('click', node, event);
163 ++this.clicksRegistered;
164 return false;
165 }
166 ++this.clicksRegistered;
167 }
168 }
169 }
170 });
171
172 // XTYPE Registration
173 Ext.reg('TYPO3.Components.PageTree.Tree', TYPO3.Components.PageTree.Tree);