8235600d53c779201df0283b459bb630e17807a4
[Packages/TYPO3.CMS.git] / typo3 / sysext / workspaces / Resources / Public / JavaScript / actions.js
1 /***************************************************************
2 * Copyright notice
3 *
4 * (c) 2010 Workspaces Team (http://forge.typo3.org/projects/show/typo3v4-workspaces)
5 * All rights reserved
6 *
7 * This script is part of the TYPO3 project. The TYPO3 project is
8 * free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * The GNU General Public License can be found at
14 * http://www.gnu.org/copyleft/gpl.html.
15 * A copy is found in the textfile GPL.txt and important notices to the license
16 * from the author is found in LICENSE.txt distributed with these scripts.
17 *
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27
28 Ext.ns('TYPO3.Workspaces');
29
30 TYPO3.Workspaces.Actions = {
31
32 runningMassAction: null,
33 currentSendToMode: 'next',
34 triggerMassAction: function(action) {
35
36 switch (action) {
37 case 'publish':
38 case 'swap':
39 this.runningMassAction = TYPO3.Workspaces.ExtDirectMassActions.publishWorkspace;
40 break;
41 case 'discard':
42 this.runningMassAction = TYPO3.Workspaces.ExtDirectMassActions.flushWorkspace;
43 break;
44 }
45
46 this.runMassAction({
47 init: true,
48 total:0,
49 processed:0,
50 swap: (action == 'swap')
51 });
52 },
53
54 runMassAction: function(parameters) {
55 if (parameters.init) {
56 top.Ext.getCmp('executeMassActionForm').hide();
57 top.Ext.getCmp('executeMassActionProgressBar').show();
58 top.Ext.getCmp('executeMassActionOkButton').disable();
59 }
60
61 var progress = parameters.total > 0 ? parameters.processed / parameters.total : 0;
62 var label = parameters.total > 0 ? parameters.processed + '/' + parameters.total : TYPO3.l10n.localize('runMassAction.init');
63 top.Ext.getCmp('executeMassActionProgressBar').updateProgress(progress, label, true);
64
65 this.runningMassAction(parameters, TYPO3.Workspaces.Actions.runMassActionCallback);
66 },
67
68 runMassActionCallback: function(response) {
69 if (response.error) {
70 top.Ext.getCmp('executeMassActionProgressBar').hide();
71 top.Ext.getCmp('executeMassActionOkButton').hide();
72 top.Ext.getCmp('executeMassActionCancleButton').setText(TYPO3.l10n.localize('close'));
73 top.Ext.getCmp('executeMassActionForm').show();
74 top.Ext.getCmp('executeMassActionForm').update(response.error);
75 } else {
76 if (response.total > response.processed) {
77 TYPO3.Workspaces.Actions.runMassAction(response);
78 } else {
79 top.Ext.getCmp('executeMassActionProgressBar').hide();
80 top.Ext.getCmp('executeMassActionOkButton').hide();
81 top.Ext.getCmp('executeMassActionCancleButton').setText(TYPO3.l10n.localize('close'));
82 top.Ext.getCmp('executeMassActionForm').show();
83 top.Ext.getCmp('executeMassActionForm').update(TYPO3.l10n.localize('runMassAction.done').replace('%d', response.total));
84 top.TYPO3.Backend.NavigationContainer.PageTree.refreshTree();
85 }
86 }
87 },
88 generateWorkspacePreviewLink: function() {
89 TYPO3.Workspaces.ExtDirectActions.generateWorkspacePreviewLink(TYPO3.settings.Workspaces.id, function(response) {
90 top.TYPO3.Dialog.InformationDialog({
91 title: TYPO3.l10n.localize('previewLink'),
92 msg: String.format('<a href="{0}" target="_blank">{0}</a>', response)
93 });
94 });
95 },
96 swapSingleRecord: function(table, t3ver_oid, orig_uid) {
97 TYPO3.Workspaces.ExtDirectActions.swapSingleRecord(table, t3ver_oid, orig_uid, function(response) {
98 TYPO3.Workspaces.MainStore.load();
99 });
100 },
101 deleteSingleRecord: function(table, uid) {
102 TYPO3.Workspaces.ExtDirectActions.deleteSingleRecord(table, uid, function(response) {
103 TYPO3.Workspaces.MainStore.load();
104 });
105 },
106 viewSingleRecord: function(table, uid) {
107 TYPO3.Workspaces.ExtDirectActions.viewSingleRecord(table, uid, function(response) {
108 eval(response);
109 });
110 },
111 sendToStageWindow: function(response, selection) {
112 if (Ext.isObject(response.error)) {
113 TYPO3.Workspaces.Actions.handlerResponseOnExecuteAction(response);
114 } else {
115 var dialog = TYPO3.Workspaces.Helpers.getSendToStageWindow({
116 title: response.title,
117 items: response.items,
118 executeHandler: function(event) {
119 var values = top.Ext.getCmp('sendToStageForm').getForm().getValues();
120 affects = response.affects;
121 affects.elements = TYPO3.Workspaces.Helpers.getElementsArrayOfSelection(selection);
122 var parameters = {
123 affects: affects,
124 receipients: TYPO3.Workspaces.Helpers.getElementIdsFromFormValues(values, 'receipients'),
125 additional: values.additional,
126 comments: values.comments
127 };
128
129 TYPO3.Workspaces.Actions.sendToStageExecute(parameters);
130 top.TYPO3.Windows.close('sendToStageWindow');
131 TYPO3.Workspaces.MainStore.reload();
132 top.TYPO3.Backend.NavigationContainer.PageTree.refreshTree();
133 }
134 });
135 }
136 },
137 sendToNextStageWindow: function(table, uid, t3ver_oid) {
138 TYPO3.Workspaces.ExtDirectActions.sendToNextStageWindow(uid, table, t3ver_oid, function(response) {
139 TYPO3.Workspaces.Actions.currentSendToMode = 'next';
140 TYPO3.Workspaces.Actions.sendToStageWindow(response);
141 });
142 },
143 sendToPrevStageWindow: function(table, uid) {
144 TYPO3.Workspaces.ExtDirectActions.sendToPrevStageWindow(uid, table, function(response) {
145 TYPO3.Workspaces.Actions.currentSendToMode = 'prev';
146 TYPO3.Workspaces.Actions.sendToStageWindow(response);
147 });
148 },
149 sendToSpecificStageWindow: function(selection, nextStage) {
150 TYPO3.Workspaces.ExtDirectActions.sendToSpecificStageWindow(nextStage, function(response) {
151 TYPO3.Workspaces.Actions.currentSendToMode = 'specific';
152 TYPO3.Workspaces.Actions.sendToStageWindow(response, selection);
153 });
154 },
155 sendToStageExecute: function (parameters) {
156 switch (TYPO3.Workspaces.Actions.currentSendToMode) {
157 case 'next':
158 TYPO3.Workspaces.ExtDirectActions.sendToNextStageExecute(parameters, TYPO3.Workspaces.Actions.handlerResponseOnExecuteAction);
159 break;
160 case 'prev':
161 TYPO3.Workspaces.ExtDirectActions.sendToPrevStageExecute(parameters, TYPO3.Workspaces.Actions.handlerResponseOnExecuteAction);
162 break;
163 case 'specific':
164 TYPO3.Workspaces.ExtDirectActions.sendToSpecificStageExecute(parameters, TYPO3.Workspaces.Actions.handlerResponseOnExecuteAction);
165 break;
166 }
167
168 },
169 updateColModel: function(colModel) {
170 var dataArray = [];
171 for (var i = 0; i < colModel.config.length; i++) {
172 if (colModel.config[i].dataIndex !== '') {
173 dataArray.push({
174 'position': i,
175 'column': colModel.config[i].dataIndex,
176 'hidden': colModel.config[i].hidden ? 1 : 0
177 });
178 }
179 }
180 TYPO3.Workspaces.ExtDirectActions.saveColumnModel(dataArray);
181 },
182 loadColModel: function(grid) {
183 TYPO3.Workspaces.ExtDirectActions.loadColumnModel(function(response) {
184 var colModel = grid.getColumnModel();
185 for (var field in response) {
186 var colIndex = colModel.getIndexById(field);
187 if (colIndex != -1) {
188 colModel.setHidden(colModel.getIndexById(field), (response[field].hidden == 1 ? true : false));
189 colModel.moveColumn(colModel.getIndexById(field), response[field].position);
190 }
191 }
192 });
193 },
194 handlerResponseOnExecuteAction: function(response) {
195 if (!Ext.isObject(response)) {
196 response = { error: { message: TYPO3.l10n.localize('error.noResponse') }};
197 }
198
199 if (Ext.isObject(response.error)) {
200 var error = response.error;
201 var code = (error.code ? ' #' + error.code : '');
202 top.TYPO3.Dialog.ErrorDialog({ title: 'Error' + code, msg: error.message });
203 }
204 },
205
206 /**
207 * Process "send to next stage" action.
208 *
209 * This method is used in the split frontend preview part.
210 *
211 * @return void
212 *
213 * @author Michael Klapper <development@morphodo.com>
214 */
215 sendPageToNextStage: function () {
216 TYPO3.Workspaces.ExtDirectActions.sendPageToNextStage(TYPO3.settings.Workspaces.id, function (response) {
217 if (Ext.isObject(response.error)) {
218 TYPO3.Workspaces.Actions.handlerResponseOnExecuteAction(response);
219 } else {
220 var dialog = TYPO3.Workspaces.Helpers.getSendToStageWindow({
221 title: TYPO3.l10n.localize('nextStage'),
222 items: response.items.items,
223 executeHandler: function(event) {
224 var values = top.Ext.getCmp('sendToStageForm').getForm().getValues();
225 affects = response.affects;
226 var parameters = {
227 affects: affects,
228 receipients: TYPO3.Workspaces.Helpers.getElementIdsFromFormValues(values, 'receipients'),
229 additional: values.additional,
230 comments: values.comments,
231 stageId: response.stageId
232 };
233 TYPO3.Workspaces.ExtDirectActions.sentCollectionToStage(parameters, function (response) {
234 TYPO3.Workspaces.Actions.handlerResponseOnExecuteAction(response);
235 TYPO3.Workspaces.ExtDirectActions.updateStageChangeButtons(TYPO3.settings.Workspaces.id, TYPO3.Workspaces.Actions.updateStageChangeButtons);
236
237 if (response.refreshLivePanel == true) {
238 Ext.getCmp('livePanel').refresh();
239 Ext.getCmp('livePanel-hbox').refresh();
240 Ext.getCmp('livePanel-vbox').refresh();
241 }
242 });
243 top.TYPO3.Windows.close('sendToStageWindow');
244 }
245 });
246 }
247 });
248 },
249
250 /**
251 * Process "send to previous stage" action.
252 *
253 * This method is used in the split frontend preview part.
254 *
255 * @return void
256 *
257 * @author Michael Klapper <development@morphodo.com>
258 */
259 sendPageToPrevStage: function () {
260 TYPO3.Workspaces.ExtDirectActions.sendPageToPreviousStage(TYPO3.settings.Workspaces.id, function (response) {
261 if (Ext.isObject(response.error)) {
262 TYPO3.Workspaces.Actions.handlerResponseOnExecuteAction(response);
263 } else {
264 var dialog = TYPO3.Workspaces.Helpers.getSendToStageWindow({
265 title: TYPO3.l10n.localize('nextStage'),
266 items: response.items.items,
267 executeHandler: function(event) {
268 var values = top.Ext.getCmp('sendToStageForm').getForm().getValues();
269
270 affects = response.affects;
271 var parameters = {
272 affects: affects,
273 receipients: TYPO3.Workspaces.Helpers.getElementIdsFromFormValues(values, 'receipients'),
274 additional: values.additional,
275 comments: values.comments,
276 stageId: response.stageId
277 };
278 TYPO3.Workspaces.ExtDirectActions.sentCollectionToStage(parameters, function (response) {
279 TYPO3.Workspaces.Actions.handlerResponseOnExecuteAction(response);
280 TYPO3.Workspaces.ExtDirectActions.updateStageChangeButtons(TYPO3.settings.Workspaces.id, TYPO3.Workspaces.Actions.updateStageChangeButtons);
281 });
282 top.TYPO3.Windows.close('sendToStageWindow');
283 }
284 });
285 }
286 });
287 },
288
289 /**
290 * Update the visible state for the buttons "next stage", "prev stage" and "discard".
291 *
292 * This method is used in the split frontend preview part.
293 *
294 * @param object response
295 * @return void
296 *
297 * @author Michael Klapper <development@morphodo.com>
298 */
299 updateStageChangeButtons: function (response) {
300
301 if (Ext.isObject(response.error)) {
302 TYPO3.Workspaces.Actions.handlerResponseOnExecuteAction(response);
303 } else {
304 for (componentId in response) {
305 if (response[componentId].visible) {
306 if (!top.Ext.getCmp(componentId).isVisible()) {
307 top.Ext.getCmp(componentId).show();
308 }
309 top.Ext.getCmp(componentId).setText(response[componentId].text);
310 } else {
311 if (top.Ext.getCmp(componentId).isVisible()) {
312 top.Ext.getCmp(componentId).hide();
313 }
314 }
315 }
316 // force doLayout on each plugin containing the preview panel
317 Ext.getCmp('preview').plugins.each(function (item, index) {
318 if (Ext.isFunction(item.doLayout)) {
319 item.doLayout();
320 }
321 });
322 }
323 },
324
325 /**
326 * Process the discard all items from current page action.
327 *
328 * This method is used in the split frontend preview part.
329 *
330 * @return void
331 *
332 * @author Michael Klapper <development@morphodo.com>
333 */
334 discardPage: function () {
335 var configuration = {
336 title: TYPO3.l10n.localize('window.discardAll.title'),
337 msg: TYPO3.l10n.localize('window.discardAll.message'),
338 fn: function(result) {
339 if (result == 'yes') {
340 TYPO3.Workspaces.ExtDirectActions.discardStagesFromPage(TYPO3.settings.Workspaces.id, function (response) {
341 TYPO3.Workspaces.Actions.handlerResponseOnExecuteAction(response);
342 TYPO3.Workspaces.ExtDirectActions.updateStageChangeButtons(TYPO3.settings.Workspaces.id, TYPO3.Workspaces.Actions.updateStageChangeButtons);
343 Ext.getCmp('wsPanel').refresh();
344 Ext.getCmp('wsPanel-hbox').refresh();
345 Ext.getCmp('wsPanel-vbox').refresh();
346 });
347 }
348 }
349 };
350
351 top.TYPO3.Dialog.QuestionDialog(configuration);
352 }
353 };