def7f5fe072609fb1ba9e1bdd223ca66620774c3
[Packages/TYPO3.CMS.git] / typo3 / sysext / filelist / 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/Filelist/ContextMenuActions
16 *
17 * JavaScript to handle filelist actions from context menu
18 * @exports TYPO3/CMS/Filelist/ContextMenuActions
19 */
20 define(['jquery', 'TYPO3/CMS/Backend/Modal', 'TYPO3/CMS/Backend/Severity'], function ($, Modal, Severity) {
21 'use strict';
22
23 /**
24 * @exports TYPO3/CMS/Filelist/ContextMenuActions
25 */
26 var ContextMenuActions = {};
27 ContextMenuActions.getReturnUrl = function () {
28 return top.rawurlencode(top.list_frame.document.location.pathname + top.list_frame.document.location.search);
29 };
30
31 ContextMenuActions.renameFile = function (table, uid) {
32 top.TYPO3.Backend.ContentContainer.setUrl(
33 top.TYPO3.settings.FileRename.moduleUrl + '&target=' + top.rawurlencode(uid) + '&returnUrl=' + ContextMenuActions.getReturnUrl()
34 );
35 };
36
37 ContextMenuActions.editFile = function (table, uid) {
38 top.TYPO3.Backend.ContentContainer.setUrl(
39 top.TYPO3.settings.FileEdit.moduleUrl + '&target=' + top.rawurlencode(uid) + '&returnUrl=' + ContextMenuActions.getReturnUrl()
40 );
41 };
42
43 ContextMenuActions.editFileStorage = function (table, uid) {
44 top.TYPO3.Backend.ContentContainer.setUrl(
45 top.TYPO3.settings.FormEngine.moduleUrl + '&edit[sys_file_storage][' + top.rawurlencode(uid) + ']=edit&returnUrl=' + ContextMenuActions.getReturnUrl()
46 );
47 };
48
49 ContextMenuActions.openInfoPopUp = function (table, uid) {
50 if (table === 'sys_file_storage') {
51 top.launchView(table, uid);
52 } else {
53 //files and folders
54 top.launchView('_FILE', uid);
55 }
56 };
57
58 ContextMenuActions.uploadFile = function (table, uid) {
59 top.TYPO3.Backend.ContentContainer.setUrl(
60 top.TYPO3.settings.FileUpload.moduleUrl + '&target=' + top.rawurlencode(uid) + '&returnUrl=' + ContextMenuActions.getReturnUrl()
61 );
62 };
63
64 ContextMenuActions.createFile = function (table, uid) {
65 top.TYPO3.Backend.ContentContainer.setUrl(
66 top.TYPO3.settings.FileCreate.moduleUrl + '&target=' + top.rawurlencode(uid) + '&returnUrl=' + ContextMenuActions.getReturnUrl()
67 );
68 };
69
70 ContextMenuActions.deleteFile = function (table, uid) {
71 var $anchorElement = $(this);
72 var performDelete = function () {
73 top.TYPO3.Backend.ContentContainer.setUrl(
74 top.TYPO3.settings.FileCommit.moduleUrl + '&data[delete][0][data]=' + top.rawurlencode(uid) + '&data[delete][0][redirect]=' + ContextMenuActions.getReturnUrl()
75 );
76 };
77 if (!$anchorElement.data('title')) {
78 performDelete();
79 return;
80 }
81
82 var $modal = Modal.confirm(
83 $anchorElement.data('title'),
84 $anchorElement.data('message'),
85 Severity.warning, [
86 {
87 text: $(this).data('button-close-text') || TYPO3.lang['button.cancel'] || 'Cancel',
88 active: true,
89 btnClass: 'btn-default',
90 name: 'cancel'
91 },
92 {
93 text: $(this).data('button-ok-text') || TYPO3.lang['button.delete'] || 'Delete',
94 btnClass: 'btn-warning',
95 name: 'delete'
96 }
97 ]);
98
99 $modal.on('button.clicked', function (e) {
100 if (e.target.name === 'delete') {
101 performDelete();
102 }
103 Modal.dismiss();
104 });
105 };
106
107 ContextMenuActions.copyFile = function (table, uid) {
108 var shortMD5 = top.MD5(uid).substring(0, 10);
109 var url = TYPO3.settings.ajaxUrls['contextmenu_clipboard'];
110 url += '&CB[el][_FILE%7C' + shortMD5 + ']=' + top.rawurlencode(uid) + '&CB[setCopyMode]=1';
111 $.ajax(url).always(function () {
112 top.TYPO3.Backend.ContentContainer.refresh(true);
113 });
114 };
115
116 ContextMenuActions.copyReleaseFile = function (table, uid) {
117 var shortMD5 = top.MD5(uid).substring(0, 10);
118 var url = TYPO3.settings.ajaxUrls['contextmenu_clipboard'];
119 url += '&CB[el][_FILE%7C' + shortMD5 + ']=0&CB[setCopyMode]=1';
120 $.ajax(url).always(function () {
121 top.TYPO3.Backend.ContentContainer.refresh(true);
122 });
123 };
124
125 ContextMenuActions.cutFile = function (table, uid) {
126 var shortMD5 = top.MD5(uid).substring(0, 10);
127 var url = TYPO3.settings.ajaxUrls['contextmenu_clipboard'];
128 url += '&CB[el][_FILE%7C' + shortMD5 + ']=' + top.rawurlencode(uid);
129 $.ajax(url).always(function () {
130 top.TYPO3.Backend.ContentContainer.refresh(true);
131 });
132 };
133
134 ContextMenuActions.cutReleaseFile = function (table, uid) {
135 var shortMD5 = top.MD5(uid).substring(0, 10);
136 var url = TYPO3.settings.ajaxUrls['contextmenu_clipboard'];
137 url += '&CB[el][_FILE%7C' + shortMD5 + ']=0';
138 $.ajax(url).always(function () {
139 top.TYPO3.Backend.ContentContainer.refresh(true);
140 });
141 };
142
143 ContextMenuActions.pasteFileInto = function (table, uid) {
144 var $anchorElement = $(this);
145 var title = $anchorElement.data('title');
146 var performPaste = function () {
147 top.TYPO3.Backend.ContentContainer.setUrl(
148 top.TYPO3.settings.FileCommit.moduleUrl + '&prErr=1&uPT=1&CB[paste]=FILE|' + top.rawurlencode(uid) + '&CB[pad]=normal&redirect=' + ContextMenuActions.getReturnUrl()
149 );
150 };
151 if (!$anchorElement.data('title')) {
152 performPaste();
153 return;
154 }
155 var $modal = Modal.confirm(
156 $anchorElement.data('title'),
157 $anchorElement.data('message'),
158 Severity.warning, [
159 {
160 text: $(this).data('button-close-text') || TYPO3.lang['button.cancel'] || 'Cancel',
161 active: true,
162 btnClass: 'btn-default',
163 name: 'cancel'
164 },
165 {
166 text: $(this).data('button-ok-text') || TYPO3.lang['button.ok'] || 'OK',
167 btnClass: 'btn-warning',
168 name: 'ok'
169 }
170 ]);
171
172 $modal.on('button.clicked', function (e) {
173 if (e.target.name === 'ok') {
174 performPaste();
175 }
176 Modal.dismiss();
177 });
178 };
179
180
181
182 ContextMenuActions.dropInto = function (table, uid, mode) {
183 var target = $(this).data('drop-target');
184 top.TYPO3.Backend.ContentContainer.setUrl(
185 top.TYPO3.settings.FileCommit.moduleUrl
186 + '&file['+ mode + '][0][data]=' + top.rawurlencode(uid)
187 + '&file['+ mode + '][0][target]=' + top.rawurlencode(target)
188 + '&redirect=' + ContextMenuActions.getReturnUrl()
189 + '&prErr=1'
190 );
191 };
192 ContextMenuActions.dropMoveInto = function (table, uid) {
193 ContextMenuActions.dropInto.bind($(this))(table, uid, 'move');
194 };
195 ContextMenuActions.dropCopyInto = function (table, uid) {
196 ContextMenuActions.dropInto.bind($(this))(table, uid, 'copy');
197 };
198 return ContextMenuActions;
199 });