d26f03477709098315c6d4c5aac232a3e60c07e7
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Resources / Public / JavaScript / backend.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
14
15 /**
16 * common storage and global object, could later hold more information about the current user etc.
17 */
18 var TYPO3 = TYPO3 || {};
19 TYPO3 = Ext.apply(TYPO3, {
20 // store instances that only should be running once
21 _instances: {},
22 getInstance: function(className) {
23 return TYPO3._instances[className] || false;
24 },
25 addInstance: function(className, instance) {
26 TYPO3._instances[className] = instance;
27 return instance;
28 },
29
30 helpers: {
31 // creates an array by splitting a string into parts, taking a delimiter
32 split: function(str, delim) {
33 var res = [];
34 while (str.indexOf(delim) > 0) {
35 res.push(str.substr(0, str.indexOf(delim)));
36 str = str.substr(str.indexOf(delim) + delim.length);
37 }
38 return res;
39 }
40 }
41 });
42
43 /**
44 * general backend javascript functions
45 */
46
47 Ext.ns('TYPO3.configuration');
48
49 /**
50 * jump the backend to a module
51 */
52 function jump(url, modName, mainModName, pageId) {
53 if (isNaN(pageId)) {
54 pageId = -2;
55 }
56 // clear information about which entry in nav. tree that might have been highlighted.
57 top.fsMod.navFrameHighlightedID = [];
58 top.fsMod.recentIds['web'] = pageId;
59
60 if (top.TYPO3.Backend.NavigationContainer.PageTree) {
61 top.TYPO3.Backend.NavigationContainer.PageTree.refreshTree();
62 }
63
64 top.nextLoadModuleUrl = url;
65 top.TYPO3.ModuleMenu.App.showModule(modName);
66
67 }
68
69 /**
70 * shortcut manager to delegate the action of creating shortcuts to the new
71 * backend.php shortcut menu or the old shortcut frame depending on what is available
72 */
73 var ShortcutManager = {
74
75 /**
76 * central entry point to create a shortcut, delegates the call to correct endpoint
77 * kept for backwards compatibility, use top.TYPO3.ShortcutMenu.createShortcut directly
78 * in the future
79 */
80 createShortcut: function(confirmQuestion, backPath, moduleName, url) {
81 if (console) {
82 console.debug('ShortcutManager.createShortcut is deprecated since TYPO3 CMS 7, use TYPO3.ShortcutMenu directly.');
83 }
84 if (TYPO3.ShortcutMenu !== undefined) {
85 TYPO3.ShortcutMenu.createShortcut(moduleName, url, confirmQuestion);
86 }
87 }
88 }
89
90
91 /**
92 * Function similar to PHPs rawurlencode();
93 */
94 function rawurlencode(str) {
95 var output = escape(str);
96 output = str_replace("*","%2A", output);
97 output = str_replace("+","%2B", output);
98 output = str_replace("/","%2F", output);
99 output = str_replace("@","%40", output);
100 return output;
101 }
102
103 /**
104 * Function to similar to PHPs rawurlencode() which removes TYPO3_SITE_URL;
105 */
106 function rawurlencodeAndRemoveSiteUrl(str) { //
107 var siteUrl = TYPO3.configuration.siteUrl;
108 return rawurlencode(str_replace(siteUrl, "", str));
109 }
110
111 /**
112 * String-replace function
113 */
114 function str_replace(match,replace,string) { //
115 var input = ""+string;
116 var matchStr = ""+match;
117 if (!matchStr) {return string;}
118 var output = "";
119 var pointer=0;
120 var pos = input.indexOf(matchStr);
121 while (pos !== -1) {
122 output+=""+input.substr(pointer, pos-pointer)+replace;
123 pointer=pos+matchStr.length;
124 pos = input.indexOf(match,pos+1);
125 }
126 output+=""+input.substr(pointer);
127 return output;
128 }
129
130
131
132 /**
133 * Launcing information window for records/files (fileref as "table" argument)
134 */
135 function launchView(table, uid, bP) {
136 var thePreviewWindow = "";
137 thePreviewWindow = window.open(TYPO3.settings.ShowItem.moduleUrl + '&table=' + encodeURIComponent(table) + "&uid=" + encodeURIComponent(uid),
138 "ShowItem" + TS.uniqueID,
139 "width=650,height=600,status=0,menubar=0,resizable=0,location=0,directories=0,scrollbars=1,toolbar=0");
140 if (thePreviewWindow && thePreviewWindow.focus) {
141 thePreviewWindow.focus();
142 }
143 }
144
145 /**
146 * Opens plain window with url
147 */
148 function openUrlInWindow(url,windowName) { //
149 regularWindow = window.open(
150 url,
151 windowName,
152 "status=1,menubar=1,resizable=1,location=1,directories=0,scrollbars=1,toolbar=1");
153 regularWindow.focus();
154 return false;
155 }
156
157 /**
158 * Loads a page id for editing in the page edit module:
159 */
160 function loadEditId(id,addGetVars) { //
161 top.fsMod.recentIds.web = id;
162 top.fsMod.navFrameHighlightedID.web = "pages" + id + "_0"; // For highlighting
163
164 if (top.content && top.content.nav_frame && top.content.nav_frame.refresh_nav) {
165 top.content.nav_frame.refresh_nav();
166 }
167 if (TYPO3.configuration.pageModule) {
168 top.goToModule(TYPO3.configuration.pageModule, 0, addGetVars?addGetVars:"");
169 }
170 }
171
172 /**
173 * Returns incoming URL (to a module) unless nextLoadModuleUrl is set. If that is the case nextLoadModuleUrl is returned (and cleared)
174 * Used by the shortcut frame to set a "intermediate URL"
175 */
176 var nextLoadModuleUrl="";
177 function getModuleUrl(inUrl) { //
178 var nMU;
179 if (top.nextLoadModuleUrl) {
180 nMU=top.nextLoadModuleUrl;
181 top.nextLoadModuleUrl="";
182 return nMU;
183 } else {
184 return inUrl;
185 }
186 }
187
188 /**
189 * Print properties of an object
190 */
191 function debugObj(obj,name) { //
192 var acc;
193 for (var i in obj) {
194 if (obj[i]) {
195 acc+=i+": "+obj[i]+"\n";
196 }
197 }
198 alert("Object: "+name+"\n\n"+acc);
199 }
200
201
202
203 // Used by Frameset Modules
204 var currentSubScript = "";
205 var currentSubNavScript = "";
206
207 // Used for tab-panels:
208 var DTM_currentTabs = [];
209
210 // status of WS FE preview
211 var WorkspaceFrontendPreviewEnabled = TYPO3.configuration.workspaceFrontendPreviewEnabled;