d868bac3e9580013e88e839b7466c727e9812023
[Packages/TYPO3.CMS.git] / typo3 / sysext / workspaces / Resources / Public / JavaScript / actions.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 Ext.ns('TYPO3.Workspaces');
16
17 TYPO3.Workspaces.Actions = {
18
19 runningMassAction: null,
20 currentSendToMode: 'next',
21
22 checkIntegrity: function(parameters, callbackFunction, callbackArguments) {
23 TYPO3.Workspaces.ExtDirect.checkIntegrity(
24 parameters,
25 function (response) {
26 switch (response.result) {
27 case 'error':
28 top.TYPO3.Dialog.ErrorDialog({
29 minWidth: 400,
30 title: 'Error',
31 msg: '<div class="scope">' + TYPO3.l10n.localize('integrity.hasIssuesDescription') + '</div>'
32 });
33 break;
34 case 'warning':
35 top.TYPO3.Dialog.QuestionDialog({
36 minWidth: 400,
37 title: 'Warning',
38 msg: '<div class="scope">' + TYPO3.l10n.localize('integrity.hasIssuesDescription') + '</div>' +
39 '<div class="question">' + TYPO3.l10n.localize('integrity.hasIssuesQuestion') + '</div>',
40 fn: function(result) {
41 if (result == 'yes') {
42 callbackFunction.call(this, callbackArguments)
43 }
44 }
45 });
46 break;
47 default:
48 callbackFunction.call(this, callbackArguments);
49 }
50 }
51 )
52 },
53
54 triggerMassAction: function(action, language) {
55 switch (action) {
56 case 'publish':
57 case 'swap':
58 this.runningMassAction = TYPO3.Workspaces.ExtDirectMassActions.publishWorkspace;
59 break;
60 case 'discard':
61 this.runningMassAction = TYPO3.Workspaces.ExtDirectMassActions.flushWorkspace;
62 break;
63 }
64
65 // Publishing large amount of changes may require a longer timeout
66 Ext.Ajax.timeout = 3600000;
67
68 this.runMassAction({
69 init: true,
70 total:0,
71 processed:0,
72 language: language,
73 swap: (action == 'swap')
74 });
75 },
76
77 runMassAction: function(parameters) {
78 if (parameters.init) {
79 top.Ext.getCmp('executeMassActionForm').hide();
80 top.Ext.getCmp('executeMassActionProgressBar').show();
81 top.Ext.getCmp('executeMassActionOkButton').disable();
82 }
83
84 var progress = parameters.total > 0 ? parameters.processed / parameters.total : 0;
85 var label = parameters.total > 0 ? parameters.processed + '/' + parameters.total : TYPO3.l10n.localize('runMassAction.init');
86 top.Ext.getCmp('executeMassActionProgressBar').updateProgress(progress, label, true);
87
88 this.runningMassAction(parameters, TYPO3.Workspaces.Actions.runMassActionCallback);
89 },
90
91 runMassActionCallback: function(response) {
92 if (response.error) {
93 top.Ext.getCmp('executeMassActionProgressBar').hide();
94 top.Ext.getCmp('executeMassActionOkButton').hide();
95 top.Ext.getCmp('executeMassActionCancleButton').setText(TYPO3.l10n.localize('close'));
96 top.Ext.getCmp('executeMassActionForm').show();
97 top.Ext.getCmp('executeMassActionForm').update(response.error);
98 TYPO3.Workspaces.Helpers.refreshPageTree();
99 } else {
100 if (response.total > response.processed) {
101 TYPO3.Workspaces.Actions.runMassAction(response);
102 } else {
103 top.Ext.getCmp('executeMassActionProgressBar').hide();
104 top.Ext.getCmp('executeMassActionOkButton').hide();
105 top.Ext.getCmp('executeMassActionCancleButton').setText(TYPO3.l10n.localize('close'));
106 top.Ext.getCmp('executeMassActionForm').show();
107 top.Ext.getCmp('executeMassActionForm').update(TYPO3.l10n.localize('runMassAction.done').replace('%d', response.total));
108 TYPO3.Workspaces.Helpers.refreshPageTree();
109 }
110 }
111 },
112 generateWorkspacePreviewLink: function() {
113 TYPO3.Workspaces.ExtDirectActions.generateWorkspacePreviewLink(TYPO3.settings.Workspaces.id, function(response) {
114 top.TYPO3.Dialog.InformationDialog({
115 title: TYPO3.l10n.localize('previewLink'),
116 msg: String.format('<a href="{0}" target="_blank">{0}</a>', response)
117 });
118 });
119 },
120 swapSingleRecord: function(table, t3ver_oid, orig_uid) {
121 TYPO3.Workspaces.ExtDirectActions.swapSingleRecord(table, t3ver_oid, orig_uid, function(response) {
122 TYPO3.Workspaces.MainStore.load();
123 });
124 },
125 deleteSingleRecord: function(table, uid) {
126 TYPO3.Workspaces.ExtDirectActions.deleteSingleRecord(table, uid, function(response) {
127 TYPO3.Workspaces.Helpers.refreshPageTree();
128 TYPO3.Workspaces.MainStore.load();
129 });
130 },
131 viewSingleRecord: function(table, uid) {
132 TYPO3.Workspaces.ExtDirectActions.viewSingleRecord(table, uid, function(response) {
133 eval(response);
134 });
135 },
136 sendToStageWindow: function(response, selection) {
137 if (Ext.isObject(response.error)) {
138 TYPO3.Workspaces.Actions.handlerResponseOnExecuteAction(response);
139 } else {
140 var dialog = TYPO3.Workspaces.Helpers.getSendToStageWindow({
141 title: response.title,
142 items: response.items,
143 executeHandler: function(event) {
144 var values = top.Ext.getCmp('sendToStageForm').getForm().getValues();
145 affects = response.affects;
146 affects.elements = TYPO3.Workspaces.Helpers.getElementsArrayOfSelection(selection);
147 var parameters = {
148 affects: affects,
149 receipients: TYPO3.Workspaces.Helpers.getElementIdsFromFormValues(values, 'receipients'),
150 additional: values.additional,
151 comments: values.comments
152 };
153
154 TYPO3.Workspaces.Actions.sendToStageExecute(parameters);
155 top.TYPO3.Windows.close('sendToStageWindow');
156 TYPO3.Workspaces.MainStore.reload();
157 TYPO3.Workspaces.Helpers.refreshPageTree();
158 }
159 });
160 }
161 },
162 sendToNextStageWindow: function(table, uid, t3ver_oid) {
163 TYPO3.Workspaces.ExtDirectActions.sendToNextStageWindow(uid, table, t3ver_oid, function(response) {
164 TYPO3.Workspaces.Actions.currentSendToMode = 'next';
165 TYPO3.Workspaces.Actions.sendToStageWindow(response);
166 });
167 },
168 sendToPrevStageWindow: function(table, uid) {
169 TYPO3.Workspaces.ExtDirectActions.sendToPrevStageWindow(uid, table, function(response) {
170 TYPO3.Workspaces.Actions.currentSendToMode = 'prev';
171 TYPO3.Workspaces.Actions.sendToStageWindow(response);
172 });
173 },
174 sendToSpecificStageWindow: function(selection, nextStage) {
175 TYPO3.Workspaces.ExtDirectActions.sendToSpecificStageWindow(nextStage, function(response) {
176 TYPO3.Workspaces.Actions.currentSendToMode = 'specific';
177 TYPO3.Workspaces.Actions.sendToStageWindow(response, selection);
178 });
179 },
180 sendToStageExecute: function (parameters) {
181 switch (TYPO3.Workspaces.Actions.currentSendToMode) {
182 case 'next':
183 TYPO3.Workspaces.ExtDirectActions.sendToNextStageExecute(parameters, TYPO3.Workspaces.Actions.handlerResponseOnExecuteAction);
184 break;
185 case 'prev':
186 TYPO3.Workspaces.ExtDirectActions.sendToPrevStageExecute(parameters, TYPO3.Workspaces.Actions.handlerResponseOnExecuteAction);
187 break;
188 case 'specific':
189 TYPO3.Workspaces.ExtDirectActions.sendToSpecificStageExecute(parameters, TYPO3.Workspaces.Actions.handlerResponseOnExecuteAction);
190 break;
191 }
192
193 },
194 updateColModel: function(colModel) {
195 var dataArray = [];
196 for (var i = 0; i < colModel.config.length; i++) {
197 if (colModel.config[i].dataIndex !== '') {
198 dataArray.push({
199 'position': i,
200 'column': colModel.config[i].dataIndex,
201 'hidden': colModel.config[i].hidden ? 1 : 0
202 });
203 }
204 }
205 TYPO3.Workspaces.ExtDirectActions.saveColumnModel(dataArray);
206 },
207 loadColModel: function(grid) {
208 TYPO3.Workspaces.ExtDirectActions.loadColumnModel(function(response) {
209 var colModel = grid.getColumnModel();
210 for (var field in response) {
211 var colIndex = colModel.getIndexById(field);
212 if (colIndex != -1) {
213 colModel.setHidden(colModel.getIndexById(field), (response[field].hidden == 1 ? true : false));
214 colModel.moveColumn(colModel.getIndexById(field), response[field].position);
215 }
216 }
217 });
218 },
219 handlerResponseOnExecuteAction: function(response) {
220 if (!Ext.isObject(response)) {
221 response = { error: { message: TYPO3.l10n.localize('error.noResponse') }};
222 }
223
224 if (Ext.isObject(response.error)) {
225 var error = response.error;
226 var code = (error.code ? ' #' + error.code : '');
227 top.TYPO3.Dialog.ErrorDialog({ title: 'Error' + code, msg: error.message });
228 }
229 },
230
231 /**
232 * Process "send to next stage" action.
233 *
234 * This method is used in the split frontend preview part.
235 *
236 * @return void
237 *
238 * @author Michael Klapper <development@morphodo.com>
239 */
240 sendPageToNextStage: function () {
241 TYPO3.Workspaces.ExtDirectActions.sendPageToNextStage(TYPO3.settings.Workspaces.id, function (response) {
242 if (Ext.isObject(response.error)) {
243 TYPO3.Workspaces.Actions.handlerResponseOnExecuteAction(response);
244 } else {
245 var dialog = TYPO3.Workspaces.Helpers.getSendToStageWindow({
246 title: TYPO3.l10n.localize('nextStage'),
247 items: response.items.items,
248 executeHandler: function(event) {
249 var values = top.Ext.getCmp('sendToStageForm').getForm().getValues();
250 affects = response.affects;
251 var parameters = {
252 affects: affects,
253 receipients: TYPO3.Workspaces.Helpers.getElementIdsFromFormValues(values, 'receipients'),
254 additional: values.additional,
255 comments: values.comments,
256 stageId: response.stageId
257 };
258 TYPO3.Workspaces.ExtDirectActions.sentCollectionToStage(parameters, function (response) {
259 TYPO3.Workspaces.Actions.handlerResponseOnExecuteAction(response);
260 TYPO3.Workspaces.ExtDirectActions.updateStageChangeButtons(TYPO3.settings.Workspaces.id, TYPO3.Workspaces.Actions.updateStageChangeButtons);
261
262 if (response.refreshLivePanel == true) {
263 Ext.getCmp('livePanel').refresh();
264 Ext.getCmp('livePanel-hbox').refresh();
265 Ext.getCmp('livePanel-vbox').refresh();
266 }
267 });
268 top.TYPO3.Windows.close('sendToStageWindow');
269 }
270 });
271 }
272 });
273 },
274
275 /**
276 * Process "send to previous stage" action.
277 *
278 * This method is used in the split frontend preview part.
279 *
280 * @return void
281 *
282 * @author Michael Klapper <development@morphodo.com>
283 */
284 sendPageToPrevStage: function () {
285 TYPO3.Workspaces.ExtDirectActions.sendPageToPreviousStage(TYPO3.settings.Workspaces.id, function (response) {
286 if (Ext.isObject(response.error)) {
287 TYPO3.Workspaces.Actions.handlerResponseOnExecuteAction(response);
288 } else {
289 var dialog = TYPO3.Workspaces.Helpers.getSendToStageWindow({
290 title: TYPO3.l10n.localize('nextStage'),
291 items: response.items.items,
292 executeHandler: function(event) {
293 var values = top.Ext.getCmp('sendToStageForm').getForm().getValues();
294
295 affects = response.affects;
296 var parameters = {
297 affects: affects,
298 receipients: TYPO3.Workspaces.Helpers.getElementIdsFromFormValues(values, 'receipients'),
299 additional: values.additional,
300 comments: values.comments,
301 stageId: response.stageId
302 };
303 TYPO3.Workspaces.ExtDirectActions.sentCollectionToStage(parameters, function (response) {
304 TYPO3.Workspaces.Actions.handlerResponseOnExecuteAction(response);
305 TYPO3.Workspaces.ExtDirectActions.updateStageChangeButtons(TYPO3.settings.Workspaces.id, TYPO3.Workspaces.Actions.updateStageChangeButtons);
306 });
307 top.TYPO3.Windows.close('sendToStageWindow');
308 }
309 });
310 }
311 });
312 },
313
314 /**
315 * Update the visible state for the buttons "next stage", "prev stage" and "discard".
316 *
317 * This method is used in the split frontend preview part.
318 *
319 * @param object response
320 * @return void
321 *
322 * @author Michael Klapper <development@morphodo.com>
323 */
324 updateStageChangeButtons: function (response) {
325
326 if (Ext.isObject(response.error)) {
327 TYPO3.Workspaces.Actions.handlerResponseOnExecuteAction(response);
328 } else {
329 for (componentId in response) {
330 if (response[componentId].visible) {
331 if (!top.Ext.getCmp(componentId).isVisible()) {
332 top.Ext.getCmp(componentId).show();
333 }
334 top.Ext.getCmp(componentId).setText(response[componentId].text.substr(0, 35));
335 top.Ext.getCmp(componentId).setTooltip(response[componentId].text);
336 } else {
337 if (top.Ext.getCmp(componentId).isVisible()) {
338 top.Ext.getCmp(componentId).hide();
339 }
340 }
341 }
342 // force doLayout on each plugin containing the preview panel
343 Ext.getCmp('preview').plugins.each(function (item, index) {
344 if (Ext.isFunction(item.doLayout)) {
345 item.doLayout();
346 }
347 });
348 }
349 },
350
351 /**
352 * Process the discard all items from current page action.
353 *
354 * This method is used in the split frontend preview part.
355 *
356 * @return void
357 *
358 * @author Michael Klapper <development@morphodo.com>
359 */
360 discardPage: function () {
361 var configuration = {
362 title: TYPO3.l10n.localize('window.discardAll.title'),
363 msg: TYPO3.l10n.localize('window.discardAll.message'),
364 fn: function(result) {
365 if (result == 'yes') {
366 TYPO3.Workspaces.ExtDirectActions.discardStagesFromPage(TYPO3.settings.Workspaces.id, function (response) {
367 TYPO3.Workspaces.Actions.handlerResponseOnExecuteAction(response);
368 TYPO3.Workspaces.ExtDirectActions.updateStageChangeButtons(TYPO3.settings.Workspaces.id, TYPO3.Workspaces.Actions.updateStageChangeButtons);
369 Ext.getCmp('wsPanel').refresh();
370 Ext.getCmp('wsPanel-hbox').refresh();
371 Ext.getCmp('wsPanel-vbox').refresh();
372 });
373 }
374 }
375 };
376
377 top.TYPO3.Dialog.QuestionDialog(configuration);
378 }
379 };