9b13f0457d0f8b2e02026d3e88a4f488419976c7
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Resources / Public / JavaScript / extjs / components / pagetree / javascript / treeeditor.js
1 /*
2 * This file is part of the TYPO3 CMS project.
3 *
4 * It is free software; you can redistribute it and/or modify it under
5 * the terms of the GNU General Public License, either version 2
6 * of the License, or any later version.
7 *
8 * For the full copyright and license information, please read the
9 * LICENSE.txt file that was distributed with this source code.
10 *
11 * The TYPO3 project - inspiring people to share!
12 */
13 Ext.namespace('TYPO3.Components.PageTree');
14
15 /**
16 * @class TYPO3.Components.PageTree.TreeEditor
17 *
18 * Custom Tree Editor implementation to enable different source fields for the
19 * editable label.
20 *
21 * @namespace TYPO3.Components.PageTree
22 * @extends Ext.tree.TreeEditor
23 * @author Stefan Galinski <stefan.galinski@gmail.com>
24 */
25 TYPO3.Components.PageTree.TreeEditor = Ext.extend(Ext.tree.TreeEditor, {
26 /**
27 * Don't send any save events if the value wasn't changed
28 *
29 * @type {Boolean}
30 */
31 ignoreNoChange: false,
32
33 /**
34 * Edit delay
35 *
36 * @type {int}
37 */
38 editDelay: 0,
39
40 /**
41 * Indicates if an underlying shadow should be shown
42 *
43 * @type {Boolean}
44 */
45 shadow: false,
46
47 /**
48 * Listeners
49 *
50 * Handles the synchronization between the edited label and the shown label.
51 */
52 listeners: {
53 beforecomplete: function(node) {
54 this.updatedValue = this.getValue();
55 if (this.updatedValue === '') {
56 this.cancelEdit();
57 return false;
58 }
59 this.setValue(this.editNode.attributes.prefix + Ext.util.Format.htmlEncode(this.updatedValue) + this.editNode.attributes.suffix);
60 },
61
62 complete: {
63 fn: function(node, newValue, oldValue) {
64 if (newValue === oldValue) {
65 this.fireEvent('canceledit', this);
66 return false;
67 }
68
69 this.editNode.getOwnerTree().commandProvider.saveTitle(node, this.updatedValue, oldValue, this);
70 }
71 },
72
73 startEdit: {
74 fn: function(element, value) {
75 this.field.selectText();
76 }
77 },
78
79 canceledit: function() {
80 var tree = this.editNode.getOwnerTree();
81 if (tree.currentSelectedNode) {
82 tree.currentSelectedNode.select();
83 }
84 }
85 },
86
87 /**
88 * Updates the edit node
89 *
90 * @param {Ext.tree.TreeNode} node
91 * @param {String} editableText
92 * @param {String} updatedNode
93 * @return {void}
94 */
95 updateNodeText: function(node, editableText, updatedNode) {
96 this.editNode.setText(this.editNode.attributes.prefix + updatedNode + this.editNode.attributes.suffix);
97 this.editNode.attributes.editableText = editableText;
98 },
99
100 /**
101 * Overridden method to set another editable text than the node text attribute
102 *
103 * @param {Ext.tree.TreeNode} node
104 * @return {Boolean}
105 */
106 triggerEdit: function(node) {
107 this.completeEdit();
108 if (node.attributes.editable !== false) {
109 this.editNode = node;
110 if (this.tree.autoScroll) {
111 Ext.fly(node.ui.getEl()).scrollIntoView(this.tree.body);
112 }
113
114 var value = node.text || '';
115 if (!Ext.isGecko && Ext.isEmpty(node.text)) {
116 node.setText(' ');
117 }
118
119 // TYPO3 MODIFICATION to use another attribute
120 value = node.attributes.editableText;
121
122 this.autoEditTimer = this.startEdit.defer(this.editDelay, this, [node.ui.textNode, value]);
123 return false;
124 }
125 }
126 });
127
128 // XTYPE Registration
129 Ext.reg('TYPO3.Components.PageTree.TreeEditor', TYPO3.Components.PageTree.TreeEditor);