ContextMenuActions.ts 10.3 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
/*
 * This file is part of the TYPO3 CMS project.
 *
 * It is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License, either version 2
 * of the License, or any later version.
 *
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
 *
 * The TYPO3 project - inspiring people to share!
 */

14
import {SeverityEnum} from './Enum/Severity';
15
16
17
import * as $ from 'jquery';
import InfoWindow = require('./InfoWindow');
import Modal = require('./Modal');
18
import ModuleMenu = require('./ModuleMenu');
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import Viewport = require('./Viewport');

/**
 * @exports TYPO3/CMS/Backend/ContextMenuActions
 */
class ContextMenuActions {
  /**
   * @returns {string}
   */
  public static getReturnUrl(): string {
    return top.rawurlencode(top.list_frame.document.location.pathname + top.list_frame.document.location.search);
  }

  /**
   * @param {string} table
   * @param {number} uid
   */
  public static editRecord(table: string, uid: number): void {
37
38
39
40
41
42
43
44
    let overrideVals = '',
      pageLanguageId = $(this).data('pages-language-uid');

    if (pageLanguageId) {
      // Disallow manual adjustment of the language field for pages
      overrideVals = '&overrideVals[pages][sys_language_uid]=' + pageLanguageId;
    }

45
    Viewport.ContentContainer.setUrl(
46
47
48
      top.TYPO3.settings.FormEngine.moduleUrl
        + '&edit[' + table + '][' + uid + ']=edit'
        + overrideVals
49
        + '&returnUrl=' + ContextMenuActions.getReturnUrl(),
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
    );
  }

  /**
   * @param {string} table
   * @param {number} uid
   */
  public static viewRecord(table: string, uid: number): void {
    const $viewUrl = $(this).data('preview-url');
    if ($viewUrl) {
      const previewWin = window.open($viewUrl, 'newTYPO3frontendWindow');
      previewWin.focus();
    }
  }

  /**
   * @param {string} table
   * @param {number} uid
   */
  public static openInfoPopUp(table: string, uid: number): void {
    InfoWindow.showItem(table, uid);
  }

  /**
   * @param {string} table
   * @param {number} uid
   */
  public static mountAsTreeRoot(table: string, uid: number): void {
    if (table === 'pages') {
      Viewport.NavigationContainer.PageTree.setTemporaryMountPoint(uid);
    }
  }

  /**
   * @param {string} table
   * @param {number} uid
   */
  public static newPageWizard(table: string, uid: number): void {
    Viewport.ContentContainer.setUrl(
89
      top.TYPO3.settings.NewRecord.moduleUrl + '&id=' + uid + '&pagesOnly=1&returnUrl=' + ContextMenuActions.getReturnUrl(),
90
91
92
93
94
95
96
97
    );
  }

  /**
   * @param {string} table
   * @param {number} uid
   */
  public static newContentWizard(table: string, uid: number): void {
98
99
    const $me = $(this);
    let $wizardUrl = $me.data('new-wizard-url');
100
101
    if ($wizardUrl) {
      $wizardUrl += '&returnUrl=' + ContextMenuActions.getReturnUrl();
102
103
104
105
106
      Modal.advanced({
        title: $me.data('title'),
        type: Modal.types.ajax,
        size: Modal.sizes.medium,
        content: $wizardUrl,
107
        severity: SeverityEnum.notice,
108
      });
109
110
111
112
113
114
115
116
117
    }
  }

  /**
   * @param {string} table
   * @param {number} uid
   */
  public static newRecord(table: string, uid: number): void {
    Viewport.ContentContainer.setUrl(
118
      top.TYPO3.settings.FormEngine.moduleUrl + '&edit[' + table + '][-' + uid + ']=new&returnUrl=' + ContextMenuActions.getReturnUrl(),
119
120
121
122
123
124
125
126
127
    );
  }

  /**
   * @param {string} table
   * @param {number} uid
   */
  public static openHistoryPopUp(table: string, uid: number): void {
    Viewport.ContentContainer.setUrl(
128
      top.TYPO3.settings.RecordHistory.moduleUrl + '&element=' + table + ':' + uid + '&returnUrl=' + ContextMenuActions.getReturnUrl(),
129
130
131
132
133
134
135
136
137
    );
  }

  /**
   * @param {string} table
   * @param {number} uid
   */
  public static openListModule(table: string, uid: number): void {
    const pageId = table === 'pages' ? uid : $(this).data('page-uid');
138
    ModuleMenu.App.showModule('web_list', 'id=' + pageId);
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
  }

  /**
   * @param {string} table
   * @param {number} uid
   */
  public static pagesSort(table: string, uid: number): void {
    const pagesSortUrl = $(this).data('pages-sort-url');
    if (pagesSortUrl) {
      Viewport.ContentContainer.setUrl(pagesSortUrl);
    }
  }

  /**
   * @param {string} table
   * @param {number} uid
   */
  public static pagesNewMultiple(table: string, uid: number): void {
    const pagesSortUrl = $(this).data('pages-new-multiple-url');
    if (pagesSortUrl) {
      Viewport.ContentContainer.setUrl(pagesSortUrl);
    }
  }

  /**
   * @param {string} table
   * @param {number} uid
   */
  public static disableRecord(table: string, uid: number): void {
    Viewport.ContentContainer.setUrl(
      top.TYPO3.settings.RecordCommit.moduleUrl
      + '&data[' + table + '][' + uid + '][hidden]=1'
171
      + '&redirect=' + ContextMenuActions.getReturnUrl(),
172
173
174
175
176
177
178
179
180
181
182
183
184
    ).done((): void => {
      Viewport.NavigationContainer.PageTree.refreshTree();
    });
  }

  /**
   * @param {string} table
   * @param {number} uid
   */
  public static enableRecord(table: string, uid: number): void {
    Viewport.ContentContainer.setUrl(
      top.TYPO3.settings.RecordCommit.moduleUrl
      + '&data[' + table + '][' + uid + '][hidden]=0'
185
      + '&redirect=' + ContextMenuActions.getReturnUrl(),
186
187
188
189
190
191
192
193
194
195
196
197
198
199
    ).done((): void => {
      Viewport.NavigationContainer.PageTree.refreshTree();
    });
  }

  /**
   * @param {string} table
   * @param {number} uid
   */
  public static deleteRecord(table: string, uid: number): void {
    const $anchorElement = $(this);
    const $modal = Modal.confirm(
      $anchorElement.data('title'),
      $anchorElement.data('message'),
200
      SeverityEnum.warning, [
201
202
203
204
        {
          text: $(this).data('button-close-text') || TYPO3.lang['button.cancel'] || 'Cancel',
          active: true,
          btnClass: 'btn-default',
205
          name: 'cancel',
206
207
208
209
        },
        {
          text: $(this).data('button-ok-text') || TYPO3.lang['button.delete'] || 'Delete',
          btnClass: 'btn-warning',
210
211
          name: 'delete',
        },
212
213
214
215
      ]);

    $modal.on('button.clicked', (e: JQueryEventObject): void => {
      if (e.target.getAttribute('name') === 'delete') {
216
217
218
219
220
221
222
223
224
225
226
        const targetUrl = top.TYPO3.settings.RecordCommit.moduleUrl
          + '&cmd[' + table + '][' + uid + '][delete]=1';

        $.ajax({
          url: targetUrl,
          success: (): void => {
            if (table === 'pages' && Viewport.NavigationContainer.PageTree) {
              if (uid === top.fsMod.recentIds.web) {
                let node = Viewport.NavigationContainer.PageTree.instance.nodes[0];
                Viewport.NavigationContainer.PageTree.selectNode(node);
              }
227

228
229
230
              Viewport.NavigationContainer.PageTree.refreshTree();
            }
          },
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
        });
      }
      Modal.dismiss();
    });
  }

  /**
   * @param {string} table
   * @param {number} uid
   */
  public static copy(table: string, uid: number): void {
    const url = TYPO3.settings.ajaxUrls.contextmenu_clipboard
      + '&CB[el][' + table + '%7C' + uid + ']=1'
      + '&CB[setCopyMode]=1';

    $.ajax(url).always((): void => {
      ContextMenuActions.triggerRefresh(Viewport.ContentContainer.get().location.href);
    });
  }

  /**
   * @param {string} table
   * @param {number} uid
   */
  public static clipboardRelease(table: string, uid: number): void {
    const url = TYPO3.settings.ajaxUrls.contextmenu_clipboard
      + '&CB[el][' + table + '%7C' + uid + ']=0';

    $.ajax(url).always((): void => {
      ContextMenuActions.triggerRefresh(Viewport.ContentContainer.get().location.href);
    });
  }

  /**
   * @param {string} table
   * @param {number} uid
   */
  public static cut(table: string, uid: number): void {
    const url = TYPO3.settings.ajaxUrls.contextmenu_clipboard
      + '&CB[el][' + table + '%7C' + uid + ']=1'
      + '&CB[setCopyMode]=0';

    $.ajax(url).always((): void => {
      ContextMenuActions.triggerRefresh(Viewport.ContentContainer.get().location.href);
    });
  }

  /**
   * @param {string} iframeUrl
   */
  public static triggerRefresh(iframeUrl: string): void {
    if (iframeUrl.indexOf('record%2Fedit') === -1) {
      Viewport.ContentContainer.refresh(true);
    }
  }

  /**
   * Clear cache for given page uid
   *
   * @param {string} table pages table
   * @param {number} uid uid of the page
   */
  public static clearCache(table: string, uid: number): void {
    const url = top.TYPO3.settings.WebLayout.moduleUrl
      + '&id=' + uid + '&clear_cache=1';
    $.ajax(url);
  }

  /**
   * Paste db record after another
   *
   * @param {string} table any db table except sys_file
   * @param {number} uid uid of the record after which record from the cliboard will be pasted
   */
  public static pasteAfter(table: string, uid: number): void {
    ContextMenuActions.pasteInto.bind($(this))(table, -uid);
  }

  /**
   * Paste page into another page
   *
   * @param {string} table any db table except sys_file
   * @param {number} uid uid of the record after which record from the cliboard will be pasted
   */
  public static pasteInto(table: string, uid: number): void {
    const $anchorElement = $(this);
    const performPaste = (): void => {
      const url = '&CB[paste]=' + table + '%7C' + uid
        + '&CB[pad]=normal'
        + '&redirect=' + ContextMenuActions.getReturnUrl();

      Viewport.ContentContainer.setUrl(
323
        top.TYPO3.settings.RecordCommit.moduleUrl + url,
324
325
326
327
328
329
330
331
332
333
334
335
336
      ).done((): void => {
        if (table === 'pages' && Viewport.NavigationContainer.PageTree) {
          Viewport.NavigationContainer.PageTree.refreshTree();
        }
      });
    };
    if (!$anchorElement.data('title')) {
      performPaste();
      return;
    }
    const $modal = Modal.confirm(
      $anchorElement.data('title'),
      $anchorElement.data('message'),
337
      SeverityEnum.warning, [
338
339
340
341
        {
          text: $(this).data('button-close-text') || TYPO3.lang['button.cancel'] || 'Cancel',
          active: true,
          btnClass: 'btn-default',
342
          name: 'cancel',
343
344
345
346
        },
        {
          text: $(this).data('button-ok-text') || TYPO3.lang['button.ok'] || 'OK',
          btnClass: 'btn-warning',
347
348
          name: 'ok',
        },
349
350
351
352
353
354
355
356
357
358
359
360
      ]);

    $modal.on('button.clicked', (e: JQueryEventObject): void => {
      if (e.target.getAttribute('name') === 'ok') {
        performPaste();
      }
      Modal.dismiss();
    });
  }
}

export = ContextMenuActions;