47535a885a4358e795e847c0d6bd6a0589fa87ff
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Resources / Public / JavaScript / ContextMenuActions.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 * Module: TYPO3/CMS/Backend/ContextMenuActions
16 * Click menu actions for db records including tt_content and pages
17 */
18 define(['jquery', 'TYPO3/CMS/Backend/Modal', 'TYPO3/CMS/Backend/Severity'], function ($, Modal, Severity) {
19 /**
20 *
21 * @exports TYPO3/CMS/Backend/ContextMenuActions
22 */
23 var ContextMenuActions = {};
24
25 ContextMenuActions.getReturnUrl = function () {
26 return top.rawurlencode(top.list_frame.document.location.pathname + top.list_frame.document.location.search);
27 };
28
29 ContextMenuActions.editRecord = function (table, uid) {
30 top.TYPO3.Backend.ContentContainer.setUrl(
31 top.TYPO3.settings.FormEngine.moduleUrl + '&edit[' + table + '][' + uid + ']=edit&returnUrl=' + ContextMenuActions.getReturnUrl()
32 );
33 };
34
35 ContextMenuActions.viewRecord = function (table, uid) {
36 var $viewUrl = $(this).data('preview-url');
37 if ($viewUrl) {
38 var previewWin = window.open($viewUrl, 'newTYPO3frontendWindow');
39 previewWin.focus();
40 }
41 };
42
43 ContextMenuActions.openInfoPopUp = function (table, uid) {
44 top.launchView(table, uid);
45 };
46
47 ContextMenuActions.mountAsTreeRoot = function (table, uid) {
48 // see actions.js -> mountAsTreeRoot
49 if (table === 'pages' && typeof top.Ext.getCmp('typo3-pagetree') !== 'undefined') {
50 var node = top.Ext.getCmp('typo3-pagetree-tree').app.getSelected();
51 // var node = top.TYPO3.Backend.NavigationContainer.PageTree.getSelected();
52 if (node === null) {
53 return false;
54 }
55
56 var useNode = {
57 attributes: {
58 nodeData: {
59 id: uid
60 }
61 }
62 };
63 top.TYPO3.Components.PageTree.Actions.mountAsTreeRoot(useNode, node.ownerTree);
64 }
65 };
66
67 ContextMenuActions.newPageWizard = function (table, uid) {
68 top.TYPO3.Backend.ContentContainer.setUrl(
69 top.TYPO3.settings.NewRecord.moduleUrl + '&id=' + uid + '&pagesOnly=1&returnUrl=' + ContextMenuActions.getReturnUrl()
70 );
71 };
72
73 ContextMenuActions.newContentWizard = function (table, uid) {
74 var $wizardUrl = $(this).data('new-wizard-url');
75 if ($wizardUrl) {
76 $wizardUrl += '&returnUrl='+ ContextMenuActions.getReturnUrl();
77 top.TYPO3.Backend.ContentContainer.setUrl($wizardUrl);
78 }
79 };
80
81 ContextMenuActions.newRecord = function (table, uid) {
82 top.TYPO3.Backend.ContentContainer.setUrl(
83 top.TYPO3.settings.FormEngine.moduleUrl + '&edit[' + table + '][-' + uid + ']=new&returnUrl=' + ContextMenuActions.getReturnUrl()
84 );
85 };
86
87 ContextMenuActions.openHistoryPopUp = function (table, uid) {
88 top.TYPO3.Backend.ContentContainer.setUrl(
89 top.TYPO3.settings.RecordHistory.moduleUrl + '&element=' + table + ':' + uid + '&returnUrl=' + ContextMenuActions.getReturnUrl()
90 );
91 };
92
93 ContextMenuActions.openListModule = function (table, uid) {
94 var pageId = table === 'pages' ? uid : $(this).data('page-uid');
95 top.TYPO3.ModuleMenu.App.showModule('web_list', 'id='.pageId);
96 };
97
98 ContextMenuActions.pagesSort = function (table, uid) {
99 var pagesSortUrl = $(this).data('pages-sort-url');
100 if (pagesSortUrl) {
101 top.TYPO3.Backend.ContentContainer.setUrl(pagesSortUrl);
102 }
103 };
104
105 ContextMenuActions.pagesNewMultiple = function (table, uid) {
106 var pagesSortUrl = $(this).data('pages-new-multiple-url');
107 if (pagesSortUrl) {
108 top.TYPO3.Backend.ContentContainer.setUrl(pagesSortUrl);
109 }
110 };
111
112 ContextMenuActions.disableRecord = function (table, uid) {
113 top.TYPO3.Backend.ContentContainer.setUrl(
114 top.TYPO3.settings.RecordCommit.moduleUrl + '&data[' + table + '][' + uid + '][hidden]=1&prErr=1&redirect=' + ContextMenuActions.getReturnUrl()
115 );
116 top.TYPO3.Backend.NavigationContainer.PageTree.refreshTree.defer(500);
117 };
118
119 ContextMenuActions.enableRecord = function (table, uid) {
120 top.TYPO3.Backend.ContentContainer.setUrl(
121 top.TYPO3.settings.RecordCommit.moduleUrl + '&data[' + table + '][' + uid + '][hidden]=0&prErr=1&redirect=' + ContextMenuActions.getReturnUrl()
122 );
123 top.TYPO3.Backend.NavigationContainer.PageTree.refreshTree.defer(500);
124 };
125
126 ContextMenuActions.deleteRecord = function (table, uid) {
127 var $anchorElement = $(this);
128 var $modal = Modal.confirm(
129 $anchorElement.data('title'),
130 $anchorElement.data('message'),
131 Severity.warning, [
132 {
133 text: $(this).data('button-close-text') || TYPO3.lang['button.cancel'] || 'Cancel',
134 active: true,
135 btnClass: 'btn-default',
136 name: 'cancel'
137 },
138 {
139 text: $(this).data('button-ok-text') || TYPO3.lang['button.delete'] || 'Delete',
140 btnClass: 'btn-warning',
141 name: 'delete'
142 }
143 ]);
144
145 $modal.on('button.clicked', function (e) {
146 if (e.target.name === 'delete') {
147 top.TYPO3.Backend.ContentContainer.setUrl(
148 top.TYPO3.settings.RecordCommit.moduleUrl + '&redirect=' + ContextMenuActions.getReturnUrl() + '&cmd[' + table + '][' + uid + '][delete]=1&prErr=1'
149 );
150 if (table === 'pages' && top.TYPO3.Backend.NavigationContainer.PageTree) {
151 top.TYPO3.Backend.NavigationContainer.PageTree.refreshTree.defer(500);
152 }
153 }
154 Modal.dismiss();
155 });
156 };
157
158 ContextMenuActions.copy = function (table, uid) {
159 var url = TYPO3.settings.ajaxUrls['contextmenu_clipboard'];
160 url += '&CB[el][' + table + '%7C' + uid + ']=1'+ '&CB[setCopyMode]=1';
161 $.ajax(url).always(function () {
162 top.TYPO3.Backend.ContentContainer.refresh(true);
163 });
164 };
165
166 ContextMenuActions.clipboardRelease = function (table, uid) {
167 var url = TYPO3.settings.ajaxUrls['contextmenu_clipboard'];
168 url += '&CB[el][' + table + '%7C' + uid + ']=0';
169 $.ajax(url).always(function () {
170 top.TYPO3.Backend.ContentContainer.refresh(true);
171 });
172 };
173
174 ContextMenuActions.cut = function (table, uid) {
175 var url = TYPO3.settings.ajaxUrls['contextmenu_clipboard'];
176 url += '&CB[el][' + table + '%7C' + uid + ']=1'+ '&CB[setCopyMode]=0';
177 $.ajax(url).always(function () {
178 top.TYPO3.Backend.ContentContainer.refresh(true);
179 });
180 };
181
182 /**
183 * Clear cache for given page uid
184 *
185 * @param {string} table pages table
186 * @param {int} uid of the page
187 */
188 ContextMenuActions.clearCache = function (table, uid) {
189 var url = top.TYPO3.settings.WebLayout.moduleUrl;
190 url += '&id=' + uid + '&clear_cache=1';
191 $.ajax(url);
192 };
193
194 /**
195 * Paste db record after another
196 *
197 * @param {string} table any db table except sys_file
198 * @param {int} uid of the record after which record from the cliboard will be pasted
199 */
200 ContextMenuActions.pasteAfter = function (table, uid) {
201 ContextMenuActions.pasteInto.bind($(this))(table, -uid);
202 };
203
204 /**
205 * Paste page into another page
206 *
207 * @param {string} table any db table except sys_file
208 * @param {int} uid of the record after which record from the cliboard will be pasted
209 */
210 ContextMenuActions.pasteInto = function (table, uid) {
211 var $anchorElement = $(this);
212 var title = $anchorElement.data('title');
213 var performPaste = function () {
214 var url = '&CB[paste]=' + table + '%7C' + uid
215 + '&CB[pad]=normal&prErr=1&uPT=1'
216 + '&redirect=' + ContextMenuActions.getReturnUrl();
217
218 top.TYPO3.Backend.ContentContainer.setUrl(
219 top.TYPO3.settings.RecordCommit.moduleUrl + url
220 );
221 if (table === 'pages' && top.TYPO3.Backend.NavigationContainer.PageTree) {
222 top.TYPO3.Backend.NavigationContainer.PageTree.refreshTree.defer(500);
223 }
224 };
225 if (!$anchorElement.data('title')) {
226 performPaste();
227 return;
228 }
229 var $modal = Modal.confirm(
230 $anchorElement.data('title'),
231 $anchorElement.data('message'),
232 Severity.warning, [
233 {
234 text: $(this).data('button-close-text') || TYPO3.lang['button.cancel'] || 'Cancel',
235 active: true,
236 btnClass: 'btn-default',
237 name: 'cancel'
238 },
239 {
240 text: $(this).data('button-ok-text') || TYPO3.lang['button.ok'] || 'OK',
241 btnClass: 'btn-warning',
242 name: 'ok'
243 }
244 ]);
245
246 $modal.on('button.clicked', function (e) {
247 if (e.target.name === 'ok') {
248 performPaste();
249 }
250 Modal.dismiss();
251 });
252
253 };
254
255 return ContextMenuActions;
256 });