77079c3269a36c039d78d978da82dd9e9bf8c59b
[Packages/TYPO3.CMS.git] / t3lib / js / extjs / components / pagetree / javascript / treeeditor.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 Ext.namespace('TYPO3.Components.PageTree');
27
28 /**
29 * @class TYPO3.Components.PageTree.TreeEditor
30 *
31 * Custom Tree Editor implementation to enable different source fields for the
32 * editable label.
33 *
34 * @namespace TYPO3.Components.PageTree
35 * @extends Ext.tree.TreeEditor
36 * @author Stefan Galinski <stefan.galinski@gmail.com>
37 */
38 TYPO3.Components.PageTree.TreeEditor = Ext.extend(Ext.tree.TreeEditor, {
39 /**
40 * Don't send any save events if the value wasn't changed
41 *
42 * @type {Boolean}
43 */
44 ignoreNoChange: true,
45
46 /**
47 * Edit delay
48 *
49 * @type {int}
50 */
51 editDelay: 250,
52
53 /**
54 * Indicates if an underlying shadow should be shown
55 *
56 * @type {Boolean}
57 */
58 shadow: false,
59
60 /**
61 * Listeners
62 *
63 * Handles the synchronization between the edited label and the shown label.
64 */
65 listeners: {
66 beforecomplete: function(node) {
67 this.updatedValue = this.getValue();
68 if (this.updatedValue === '') {
69 this.cancelEdit();
70 return false;
71 }
72 this.setValue(this.editNode.attributes.prefix + Ext.util.Format.htmlEncode(this.updatedValue) + this.editNode.attributes.suffix);
73 },
74
75 complete: {
76 fn: function(node, newValue, oldValue) {
77 this.editNode.ownerTree.commandProvider.saveTitle(node, this.updatedValue, oldValue, this);
78 }
79 }
80 },
81
82 /**
83 * Updates the edit node
84 *
85 * @param {Ext.tree.TreeNode} node
86 * @param {String} editableText
87 * @param {String} updatedNode
88 * @return {void}
89 */
90 updateNodeText: function(node, editableText, updatedNode) {
91 this.editNode.setText(this.editNode.attributes.prefix + updatedNode + this.editNode.attributes.suffix);
92 this.editNode.attributes.editableText = editableText;
93 },
94
95 /**
96 * Overridden method to set another editable text than the node text attribute
97 *
98 * @param {Ext.tree.TreeNode} node
99 * @return {Boolean}
100 */
101 triggerEdit: function(node) {
102 this.completeEdit();
103 if (node.attributes.editable !== false) {
104 this.editNode = node;
105 if (this.tree.autoScroll) {
106 Ext.fly(node.ui.getEl()).scrollIntoView(this.tree.body);
107 }
108
109 var value = node.text || '';
110 if (!Ext.isGecko && Ext.isEmpty(node.text)) {
111 node.setText(' ');
112 }
113
114 // TYPO3 MODIFICATION to use another attribute
115 value = node.attributes.editableText;
116
117 this.autoEditTimer = this.startEdit.defer(this.editDelay, this, [node.ui.textNode, value]);
118 return false;
119 }
120 }
121 });
122
123 // XTYPE Registration
124 Ext.reg('TYPO3.Components.PageTree.TreeEditor', TYPO3.Components.PageTree.TreeEditor);