[BUGFIX] Update tslint.json and fix build
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Resources / Private / TypeScript / ContextMenuActions.ts
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 import {SeverityEnum} from './Enum/Severity';
15 import * as $ from 'jquery';
16 import InfoWindow = require('./InfoWindow');
17 import Modal = require('./Modal');
18 import ModuleMenu = require('./ModuleMenu');
19 import Viewport = require('./Viewport');
20
21 /**
22 * @exports TYPO3/CMS/Backend/ContextMenuActions
23 */
24 class ContextMenuActions {
25 /**
26 * @returns {string}
27 */
28 public static getReturnUrl(): string {
29 return top.rawurlencode(top.list_frame.document.location.pathname + top.list_frame.document.location.search);
30 }
31
32 /**
33 * @param {string} table
34 * @param {number} uid
35 */
36 public static editRecord(table: string, uid: number): void {
37 let overrideVals = '',
38 pageLanguageId = $(this).data('pages-language-uid');
39
40 if (pageLanguageId) {
41 // Disallow manual adjustment of the language field for pages
42 overrideVals = '&overrideVals[pages][sys_language_uid]=' + pageLanguageId;
43 }
44
45 Viewport.ContentContainer.setUrl(
46 top.TYPO3.settings.FormEngine.moduleUrl
47 + '&edit[' + table + '][' + uid + ']=edit'
48 + overrideVals
49 + '&returnUrl=' + ContextMenuActions.getReturnUrl(),
50 );
51 }
52
53 /**
54 * @param {string} table
55 * @param {number} uid
56 */
57 public static viewRecord(table: string, uid: number): void {
58 const $viewUrl = $(this).data('preview-url');
59 if ($viewUrl) {
60 const previewWin = window.open($viewUrl, 'newTYPO3frontendWindow');
61 previewWin.focus();
62 }
63 }
64
65 /**
66 * @param {string} table
67 * @param {number} uid
68 */
69 public static openInfoPopUp(table: string, uid: number): void {
70 InfoWindow.showItem(table, uid);
71 }
72
73 /**
74 * @param {string} table
75 * @param {number} uid
76 */
77 public static mountAsTreeRoot(table: string, uid: number): void {
78 if (table === 'pages') {
79 Viewport.NavigationContainer.PageTree.setTemporaryMountPoint(uid);
80 }
81 }
82
83 /**
84 * @param {string} table
85 * @param {number} uid
86 */
87 public static newPageWizard(table: string, uid: number): void {
88 Viewport.ContentContainer.setUrl(
89 top.TYPO3.settings.NewRecord.moduleUrl + '&id=' + uid + '&pagesOnly=1&returnUrl=' + ContextMenuActions.getReturnUrl(),
90 );
91 }
92
93 /**
94 * @param {string} table
95 * @param {number} uid
96 */
97 public static newContentWizard(table: string, uid: number): void {
98 const $me = $(this);
99 let $wizardUrl = $me.data('new-wizard-url');
100 if ($wizardUrl) {
101 $wizardUrl += '&returnUrl=' + ContextMenuActions.getReturnUrl();
102 Modal.advanced({
103 title: $me.data('title'),
104 type: Modal.types.ajax,
105 size: Modal.sizes.medium,
106 content: $wizardUrl,
107 severity: SeverityEnum.notice,
108 });
109 }
110 }
111
112 /**
113 * @param {string} table
114 * @param {number} uid
115 */
116 public static newRecord(table: string, uid: number): void {
117 Viewport.ContentContainer.setUrl(
118 top.TYPO3.settings.FormEngine.moduleUrl + '&edit[' + table + '][-' + uid + ']=new&returnUrl=' + ContextMenuActions.getReturnUrl(),
119 );
120 }
121
122 /**
123 * @param {string} table
124 * @param {number} uid
125 */
126 public static openHistoryPopUp(table: string, uid: number): void {
127 Viewport.ContentContainer.setUrl(
128 top.TYPO3.settings.RecordHistory.moduleUrl + '&element=' + table + ':' + uid + '&returnUrl=' + ContextMenuActions.getReturnUrl(),
129 );
130 }
131
132 /**
133 * @param {string} table
134 * @param {number} uid
135 */
136 public static openListModule(table: string, uid: number): void {
137 const pageId = table === 'pages' ? uid : $(this).data('page-uid');
138 ModuleMenu.App.showModule('web_list', 'id=' + pageId);
139 }
140
141 /**
142 * @param {string} table
143 * @param {number} uid
144 */
145 public static pagesSort(table: string, uid: number): void {
146 const pagesSortUrl = $(this).data('pages-sort-url');
147 if (pagesSortUrl) {
148 Viewport.ContentContainer.setUrl(pagesSortUrl);
149 }
150 }
151
152 /**
153 * @param {string} table
154 * @param {number} uid
155 */
156 public static pagesNewMultiple(table: string, uid: number): void {
157 const pagesSortUrl = $(this).data('pages-new-multiple-url');
158 if (pagesSortUrl) {
159 Viewport.ContentContainer.setUrl(pagesSortUrl);
160 }
161 }
162
163 /**
164 * @param {string} table
165 * @param {number} uid
166 */
167 public static disableRecord(table: string, uid: number): void {
168 Viewport.ContentContainer.setUrl(
169 top.TYPO3.settings.RecordCommit.moduleUrl
170 + '&data[' + table + '][' + uid + '][hidden]=1'
171 + '&redirect=' + ContextMenuActions.getReturnUrl(),
172 ).done((): void => {
173 Viewport.NavigationContainer.PageTree.refreshTree();
174 });
175 }
176
177 /**
178 * @param {string} table
179 * @param {number} uid
180 */
181 public static enableRecord(table: string, uid: number): void {
182 Viewport.ContentContainer.setUrl(
183 top.TYPO3.settings.RecordCommit.moduleUrl
184 + '&data[' + table + '][' + uid + '][hidden]=0'
185 + '&redirect=' + ContextMenuActions.getReturnUrl(),
186 ).done((): void => {
187 Viewport.NavigationContainer.PageTree.refreshTree();
188 });
189 }
190
191 /**
192 * @param {string} table
193 * @param {number} uid
194 */
195 public static deleteRecord(table: string, uid: number): void {
196 const $anchorElement = $(this);
197 const $modal = Modal.confirm(
198 $anchorElement.data('title'),
199 $anchorElement.data('message'),
200 SeverityEnum.warning, [
201 {
202 text: $(this).data('button-close-text') || TYPO3.lang['button.cancel'] || 'Cancel',
203 active: true,
204 btnClass: 'btn-default',
205 name: 'cancel',
206 },
207 {
208 text: $(this).data('button-ok-text') || TYPO3.lang['button.delete'] || 'Delete',
209 btnClass: 'btn-warning',
210 name: 'delete',
211 },
212 ]);
213
214 $modal.on('button.clicked', (e: JQueryEventObject): void => {
215 if (e.target.getAttribute('name') === 'delete') {
216 Viewport.ContentContainer.setUrl(
217 top.TYPO3.settings.RecordCommit.moduleUrl
218 + '&redirect=' + ContextMenuActions.getReturnUrl()
219 + '&cmd[' + table + '][' + uid + '][delete]=1',
220 ).done((): void => {
221 if (table === 'pages' && Viewport.NavigationContainer.PageTree) {
222 if (uid === top.fsMod.recentIds.web) {
223 let node = Viewport.NavigationContainer.PageTree.instance.nodes[0];
224 Viewport.NavigationContainer.PageTree.selectNode(node);
225 }
226
227 Viewport.NavigationContainer.PageTree.refreshTree();
228 }
229 });
230 }
231 Modal.dismiss();
232 });
233 }
234
235 /**
236 * @param {string} table
237 * @param {number} uid
238 */
239 public static copy(table: string, uid: number): void {
240 const url = TYPO3.settings.ajaxUrls.contextmenu_clipboard
241 + '&CB[el][' + table + '%7C' + uid + ']=1'
242 + '&CB[setCopyMode]=1';
243
244 $.ajax(url).always((): void => {
245 ContextMenuActions.triggerRefresh(Viewport.ContentContainer.get().location.href);
246 });
247 }
248
249 /**
250 * @param {string} table
251 * @param {number} uid
252 */
253 public static clipboardRelease(table: string, uid: number): void {
254 const url = TYPO3.settings.ajaxUrls.contextmenu_clipboard
255 + '&CB[el][' + table + '%7C' + uid + ']=0';
256
257 $.ajax(url).always((): void => {
258 ContextMenuActions.triggerRefresh(Viewport.ContentContainer.get().location.href);
259 });
260 }
261
262 /**
263 * @param {string} table
264 * @param {number} uid
265 */
266 public static cut(table: string, uid: number): void {
267 const url = TYPO3.settings.ajaxUrls.contextmenu_clipboard
268 + '&CB[el][' + table + '%7C' + uid + ']=1'
269 + '&CB[setCopyMode]=0';
270
271 $.ajax(url).always((): void => {
272 ContextMenuActions.triggerRefresh(Viewport.ContentContainer.get().location.href);
273 });
274 }
275
276 /**
277 * @param {string} iframeUrl
278 */
279 public static triggerRefresh(iframeUrl: string): void {
280 if (iframeUrl.indexOf('record%2Fedit') === -1) {
281 Viewport.ContentContainer.refresh(true);
282 }
283 }
284
285 /**
286 * Clear cache for given page uid
287 *
288 * @param {string} table pages table
289 * @param {number} uid uid of the page
290 */
291 public static clearCache(table: string, uid: number): void {
292 const url = top.TYPO3.settings.WebLayout.moduleUrl
293 + '&id=' + uid + '&clear_cache=1';
294 $.ajax(url);
295 }
296
297 /**
298 * Paste db record after another
299 *
300 * @param {string} table any db table except sys_file
301 * @param {number} uid uid of the record after which record from the cliboard will be pasted
302 */
303 public static pasteAfter(table: string, uid: number): void {
304 ContextMenuActions.pasteInto.bind($(this))(table, -uid);
305 }
306
307 /**
308 * Paste page into another page
309 *
310 * @param {string} table any db table except sys_file
311 * @param {number} uid uid of the record after which record from the cliboard will be pasted
312 */
313 public static pasteInto(table: string, uid: number): void {
314 const $anchorElement = $(this);
315 const performPaste = (): void => {
316 const url = '&CB[paste]=' + table + '%7C' + uid
317 + '&CB[pad]=normal'
318 + '&redirect=' + ContextMenuActions.getReturnUrl();
319
320 Viewport.ContentContainer.setUrl(
321 top.TYPO3.settings.RecordCommit.moduleUrl + url,
322 ).done((): void => {
323 if (table === 'pages' && Viewport.NavigationContainer.PageTree) {
324 Viewport.NavigationContainer.PageTree.refreshTree();
325 }
326 });
327 };
328 if (!$anchorElement.data('title')) {
329 performPaste();
330 return;
331 }
332 const $modal = Modal.confirm(
333 $anchorElement.data('title'),
334 $anchorElement.data('message'),
335 SeverityEnum.warning, [
336 {
337 text: $(this).data('button-close-text') || TYPO3.lang['button.cancel'] || 'Cancel',
338 active: true,
339 btnClass: 'btn-default',
340 name: 'cancel',
341 },
342 {
343 text: $(this).data('button-ok-text') || TYPO3.lang['button.ok'] || 'OK',
344 btnClass: 'btn-warning',
345 name: 'ok',
346 },
347 ]);
348
349 $modal.on('button.clicked', (e: JQueryEventObject): void => {
350 if (e.target.getAttribute('name') === 'ok') {
351 performPaste();
352 }
353 Modal.dismiss();
354 });
355 }
356 }
357
358 export = ContextMenuActions;