bcb82b4bbeda277d633896b8937ba40433bc1639
[Packages/TYPO3.CMS.git] / typo3 / sysext / workspaces / Resources / Public / JavaScript / toolbar.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 Ext.ns('TYPO3.Workspaces');
15
16 TYPO3.Workspaces.Toolbar = {};
17
18 TYPO3.Workspaces.Toolbar.search = new Ext.app.SearchField({
19 store: TYPO3.Workspaces.MainStore,
20 trigger1Class : 't3-icon t3-icon-actions t3-icon-actions-input t3-icon-input-clear t3-tceforms-input-clearer',
21 trigger2Class : 't3-icon t3-icon-actions t3-icon-actions-system t3-icon-system-tree-search-open',
22 width: 200
23 });
24
25 TYPO3.Workspaces.Toolbar.selectActionStore = new Ext.data.DirectStore({
26 storeId : 'stagesService',
27 root : 'data',
28 totalProperty : 'total',
29 idProperty : 'uid',
30 fields : [
31 {name : 'uid'},
32 {name : 'title'}
33 ],
34 listeners : {
35 load : function(store, records) {
36 if (records.length == 0) {
37 TYPO3.Workspaces.Toolbar.selectStateActionCombo.hide();
38 } else {
39 TYPO3.Workspaces.Toolbar.selectStateActionCombo.show();
40 TYPO3.Workspaces.WorkspaceGrid.colModel.setHidden(0, false);
41 }
42 }
43 }
44 });
45
46 TYPO3.Workspaces.Toolbar.selectStateActionCombo = new Ext.form.ComboBox({
47 width: 150,
48 listWidth: 350,
49 lazyRender: true,
50 valueField: 'uid',
51 displayField: 'title',
52 mode: 'local',
53 emptyText: TYPO3.l10n.localize('chooseAction'),
54 selectOnFocus: true,
55 disabled : true,
56 hidden : true, // we hide it by default and show it in case there are any actions available
57 triggerAction: 'all',
58 editable: false,
59 forceSelection: true,
60 store: TYPO3.Workspaces.Toolbar.selectActionStore,
61 listeners: {
62 'select' : function () {
63 var selection = TYPO3.Workspaces.WorkspaceGrid.getSelectionModel().getSelections();
64 var nextStage = this.getValue();
65
66 // Use integrity check since "publish execute" stage is effective
67 if (nextStage == -20) {
68 var parameters = {
69 type: 'selection',
70 selection: TYPO3.Workspaces.Helpers.getElementsArrayOfSelectionForIntegrityCheck(selection)
71 };
72
73 TYPO3.Workspaces.Actions.checkIntegrity(parameters, function() {
74 TYPO3.Workspaces.Actions.sendToSpecificStageWindow(selection, nextStage);
75 });
76 } else {
77 TYPO3.Workspaces.Actions.sendToSpecificStageWindow(selection, nextStage);
78 }
79 }
80 }
81 });
82
83 TYPO3.Workspaces.Toolbar.selectMassActionStore = new Ext.data.DirectStore({
84 storeId : 'stagesService',
85 root : 'data',
86 totalProperty : 'total',
87 idProperty : 'action',
88 fields : [
89 {name : 'action'},
90 {name : 'title'}
91 ],
92 listeners : {
93 load : function(store, records) {
94 if (records.length == 0 || TYPO3.settings.Workspaces.singleView === '1') {
95 TYPO3.Workspaces.Toolbar.selectionActionCombo.hide();
96 TYPO3.Workspaces.Toolbar.selectStateMassActionCombo.hide();
97 } else {
98 TYPO3.Workspaces.Toolbar.selectionActionCombo.show();
99 TYPO3.Workspaces.Toolbar.selectStateMassActionCombo.show();
100 }
101 }
102 }
103 });
104
105 TYPO3.Workspaces.Toolbar.selectionActionCombo = new Ext.form.ComboBox({
106 width: 150,
107 lazyRender: true,
108 valueField: 'action',
109 displayField: 'title',
110 mode: 'local',
111 emptyText: 'choose selection action',
112 selectOnFocus: true,
113 triggerAction: 'all',
114 editable: false,
115 disabled : true, // disabled per default, enabled if selections are done in the grid
116 hidden : true, // hidden per default, shown if actions are available
117 forceSelection: true,
118 store: TYPO3.Workspaces.Toolbar.selectMassActionStore,
119 listeners: {
120 'select' : function(combo, record) {
121 var label;
122 var checkIntegrity = false;
123 var selection = TYPO3.Workspaces.Helpers.getElementsArrayOfSelectionForIntegrityCheck(
124 TYPO3.Workspaces.WorkspaceGrid.getSelectionModel().getSelections()
125 );
126
127 switch (record.data.action) {
128 case 'publish':
129 label = TYPO3.l10n.localize('tooltip.publishSelected');
130 checkIntegrity = true;
131 break;
132 case 'swap':
133 label = TYPO3.l10n.localize('tooltip.swapSelected');
134 checkIntegrity = true;
135 break;
136 case 'discard':
137 label = TYPO3.l10n.localize('tooltip.discardSelected');
138 break;
139 }
140
141 top.TYPO3.Windows.close('executeSelectionActionWindow');
142
143 var configuration = {
144 id: 'executeSelectionActionWindow',
145 title: TYPO3.l10n.localize('window.selectionAction.title'),
146 items: [
147 {
148 xtype: 'form',
149 id: 'executeSelectionActionForm',
150 width: '100%',
151 html: label,
152 bodyStyle: 'padding: 5px 5px 3px 5px; border-width: 0; margin-bottom: 7px;'
153 }
154 ],
155 buttons: [
156 {
157 id: 'executeSelectionActionOkButton',
158 data: { action: record.data.action, selection: selection },
159 scope: this,
160 text: TYPO3.l10n.localize('ok'),
161 disabled:false,
162 handler: function(event) {
163 top.Ext.getCmp('executeSelectionActionForm').update('Working...');
164 top.Ext.getCmp('executeSelectionActionOkButton').disable();
165 TYPO3.Workspaces.ExtDirectActions.executeSelectionAction(event.data, function(response) {
166 top.Ext.getCmp('executeSelectionActionOkButton').hide();
167 top.Ext.getCmp('executeSelectionActionCancelButton').setText(TYPO3.lang.close);
168 if (response.error) {
169 top.Ext.getCmp('executeSelectionActionForm').update('<strong>' + TYPO3.l10n.localize('status.error') + ':</strong> ' + response.error);
170 } else {
171 top.Ext.getCmp('executeSelectionActionForm').update(TYPO3.l10n.localize('runMassAction.done').replace('%d', response.total));
172 top.TYPO3.Backend.NavigationContainer.PageTree.refreshTree();
173 }
174 });
175 }
176 },
177 {
178 id: 'executeSelectionActionCancelButton',
179 scope: this,
180 text: TYPO3.l10n.localize('cancel'),
181 handler: function() {
182 top.TYPO3.Windows.close('executeSelectionActionWindow');
183 top.TYPO3.ModuleMenu.App.reloadFrames();
184 }
185 }
186 ]
187 };
188
189 if (checkIntegrity) {
190 var parameters = {
191 type: 'selection',
192 selection: selection
193 };
194
195 TYPO3.Workspaces.Actions.checkIntegrity(parameters, function() {
196 top.TYPO3.Windows.showWindow(configuration);
197 });
198 } else {
199 top.TYPO3.Windows.showWindow(configuration);
200 }
201 }
202 }
203 });
204
205 TYPO3.Workspaces.Toolbar.selectStateMassActionCombo = new Ext.form.ComboBox({
206 width: 150,
207 lazyRender: true,
208 valueField: 'action',
209 displayField: 'title',
210 mode: 'local',
211 emptyText: TYPO3.l10n.localize('chooseMassAction'),
212 selectOnFocus: true,
213 triggerAction: 'all',
214 editable: false,
215 hidden : true, // we hide it by default and show it in case there are any actions available
216 forceSelection: true,
217 store: TYPO3.Workspaces.Toolbar.selectMassActionStore,
218 listeners: {
219 'select' : function (combo, record) {
220 var label = '';
221 var affectWholeWorkspaceWarning = TYPO3.l10n.localize('tooltip.affectWholeWorkspace');
222 var language = TYPO3.Workspaces.MainStore.baseParams.language;
223 var checkIntegrity = false;
224
225 switch (record.data.action) {
226 case 'publish':
227 label = TYPO3.l10n.localize('tooltip.publishAll');
228 checkIntegrity = true;
229 break;
230 case 'swap':
231 label = TYPO3.l10n.localize('tooltip.swapAll');
232 checkIntegrity = true;
233 break;
234 case 'discard':
235 label = TYPO3.l10n.localize('tooltip.discardAll');
236 break;
237 }
238 top.TYPO3.Windows.close('executeMassActionWindow');
239
240 var configuration = {
241 id: 'executeMassActionWindow',
242 title: TYPO3.l10n.localize('window.massAction.title'),
243 items: [
244 {
245 xtype: 'form',
246 id: 'executeMassActionForm',
247 width: '100%',
248 html: label + '<br /><br />' + affectWholeWorkspaceWarning,
249 bodyStyle: 'padding: 5px 5px 3px 5px; border-width: 0; margin-bottom: 7px;'
250 },
251 {
252 xtype: 'progress',
253 id: 'executeMassActionProgressBar',
254 autoWidth: true,
255 autoHeight: true,
256 hidden: true,
257 value: 0
258 }
259 ],
260 buttons: [
261 {
262 id: 'executeMassActionOkButton',
263 data: record.data,
264 scope: this,
265 text: TYPO3.l10n.localize('ok'),
266 disabled:false,
267 handler: function(event) {
268 TYPO3.Workspaces.Actions.triggerMassAction(
269 event.data.action,
270 language
271 );
272 }
273 },
274 {
275 id: 'executeMassActionCancleButton',
276 scope: this,
277 text: TYPO3.l10n.localize('cancel'),
278 handler: function() {
279 top.TYPO3.Windows.close('executeMassActionWindow');
280 // if clicks during action - this also interrupts the running process -- not the nices way but efficient
281 top.TYPO3.ModuleMenu.App.reloadFrames();
282 }
283 }
284 ]
285 };
286
287 if (checkIntegrity && language != 'all') {
288 var parameters = {
289 type: 'all',
290 language: language
291 };
292 TYPO3.Workspaces.Actions.checkIntegrity(parameters, function() {
293 top.TYPO3.Windows.showWindow(configuration);
294 });
295 } else {
296 top.TYPO3.Windows.showWindow(configuration);
297 }
298 }
299 }
300 });
301
302 TYPO3.Workspaces.Toolbar.Pager = new Ext.PagingToolbar({
303 store : TYPO3.Workspaces.MainStore,
304 pageSize : 30,
305 displayInfo: false,
306 plugins : [ TYPO3.Workspaces.Configuration.GridFilters ]
307 });
308
309 /****************************************************
310 * Depth menu
311 ****************************************************/
312 TYPO3.Workspaces.Toolbar.depthFilter = new Ext.form.ComboBox({
313 width: 150,
314 lazyRender: true,
315 valueField: 'depth',
316 displayField: 'label',
317 id: 'depthSelector',
318 mode: 'local',
319 emptyText: TYPO3.l10n.localize('depth'),
320 selectOnFocus: true,
321 triggerAction: 'all',
322 editable: false,
323 forceSelection: true,
324 hidden: (TYPO3.settings.Workspaces.singleView === '1'),
325 store: new Ext.data.SimpleStore({
326 autoLoad: true,
327 fields: ['depth','label'],
328 data : [
329 ['0', TYPO3.l10n.localize('depth_0')],
330 ['1', TYPO3.l10n.localize('depth_1')],
331 ['2', TYPO3.l10n.localize('depth_2')],
332 ['3', TYPO3.l10n.localize('depth_3')],
333 ['4', TYPO3.l10n.localize('depth_4')],
334 ['999', TYPO3.l10n.localize('depth_infi')]
335 ]
336 }),
337 value: 999,
338 listeners: {
339 'select': {
340 fn: function(cmp, rec, index) {
341 var depth = rec.get('depth');
342 TYPO3.Workspaces.MainStore.setBaseParam('depth', depth);
343 TYPO3.Workspaces.MainStore.load({
344 params: {
345 wsId: 0
346 }
347 });
348 }
349 }
350 }
351 });
352
353 TYPO3.Workspaces.Toolbar.LanguageSelector = new Ext.form.ComboBox({
354 width: 150,
355 listWidth: 350,
356 lazyRender: true,
357 valueField: 'uid',
358 displayField: 'title',
359 mode: 'local',
360 emptyText: TYPO3.l10n.localize('language.selectLanguage'),
361 selectOnFocus: true,
362 triggerAction: 'all',
363 editable: false,
364 forceSelection: true,
365 tpl: '<tpl for="."><div class="x-combo-list-item"><span class="{cls}">&nbsp;</span> {title}</div></tpl>',
366 store: new Ext.data.DirectStore({
367 storeId: 'languages',
368 root: 'data',
369 totalProperty: 'total',
370 idProperty: 'uid',
371 fields: [
372 {name : 'uid'},
373 {name : 'title'},
374 {name : 'cls'}
375 ],
376 listeners: {
377 load: function() {
378 TYPO3.Workspaces.Toolbar.LanguageSelector.setValue(TYPO3.settings.Workspaces.language);
379 }
380 }
381 }),
382 listeners: {
383 select: function (comboBox, record, index) {
384 TYPO3.Workspaces.ExtDirectActions.saveLanguageSelection(this.getValue());
385 TYPO3.Workspaces.MainStore.setBaseParam('language', this.getValue());
386 TYPO3.Workspaces.MainStore.load();
387 }
388 }
389 });
390
391 TYPO3.Workspaces.Toolbar.FullTopToolbar = [
392 TYPO3.Workspaces.Toolbar.depthFilter,
393 '-',
394 TYPO3.Workspaces.Toolbar.LanguageSelector,
395 {xtype: 'tbfill'},
396 TYPO3.Workspaces.Toolbar.search
397 ];
398
399 TYPO3.Workspaces.Toolbar.FullBottomBar = [
400 (TYPO3.settings.Workspaces.isLiveWorkspace == true || TYPO3.settings.Workspaces.allView) ? {hidden: true} : TYPO3.Workspaces.Toolbar.selectStateActionCombo,
401 (TYPO3.settings.Workspaces.isLiveWorkspace == true || TYPO3.settings.Workspaces.allView) ? {hidden: true} : '-',
402 (TYPO3.settings.Workspaces.isLiveWorkspace == true || TYPO3.settings.Workspaces.allView) ? {hidden: true} : TYPO3.Workspaces.Toolbar.selectionActionCombo,
403 (TYPO3.settings.Workspaces.isLiveWorkspace == true || TYPO3.settings.Workspaces.allView) ? {hidden: true} : '-',
404 (TYPO3.settings.Workspaces.isLiveWorkspace == true || TYPO3.settings.Workspaces.allView) ? {hidden: true} : TYPO3.Workspaces.Toolbar.selectStateMassActionCombo,
405 {xtype: 'tbfill'},
406 TYPO3.Workspaces.Toolbar.Pager
407 ];