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