c1d7146e0a7eab6d1daaa90148a1d3bfbdc059b5
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Resources / Public / JavaScript / LayoutModule / Paste.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/Backend/LayoutModule/Paste
16 * this JS code does the paste logic for the Layout module (Web => Page)
17 * based on jQuery UI
18 */
19 define(['jquery',
20 'TYPO3/CMS/Backend/LayoutModule/DragDrop',
21 'TYPO3/CMS/Backend/Modal',
22 'TYPO3/CMS/Backend/Severity'
23 ], function($, DragDrop, Modal, Severity) {
24 'use strict';
25
26 /**
27 *
28 * @type {{}}
29 * @exports TYPO3/CMS/Backend/LayoutModule/Paste
30 */
31 var Paste = {
32 openedPopupWindow: []
33 };
34
35 /**
36 * initializes paste icons for all content elements on the page
37 */
38 Paste.initialize = function() {
39 if ($('.t3js-page-columns').length) {
40 Paste.activatePasteIcons();
41 }
42 };
43
44 /**
45 * activates the paste into / paste after icons outside of the context menus
46 */
47 Paste.activatePasteIcons = function() {
48 $('.t3-page-ce-wrapper-new-ce').each(function() {
49 if (!$(this).find('.t3js-toggle-new-content-element-wizard').length) {
50 return true;
51 }
52 $('.t3js-page-lang-column .t3-page-ce > .t3-page-ce').removeClass('t3js-page-ce');
53 if (top.pasteAfterLinkTemplate && top.pasteIntoLinkTemplate) {
54 var parent = $(this).parent();
55 if (parent.data('page')) {
56 $(this).append(top.pasteIntoLinkTemplate);
57 } else {
58 $(this).append(top.pasteAfterLinkTemplate);
59 }
60 $(this).find('.t3js-paste').on('click', function(evt) {
61 evt.preventDefault();
62 Paste.activatePasteModal($(this));
63 });
64 }
65 });
66 }
67
68 /**
69 * generates the paste into / paste after modal
70 */
71 Paste.activatePasteModal = function(element) {
72 var $element = $(element);
73 var url = $element.data('url') || null;
74 var title = (TYPO3.lang['paste.modal.title.paste'] || 'Paste record') + ': "' + $element.data('title') + '"';
75 var severity = (typeof top.TYPO3.Severity[$element.data('severity')] !== 'undefined') ? top.TYPO3.Severity[$element.data('severity')] : top.TYPO3.Severity.info;
76 if ($element.hasClass('t3js-paste-copy')) {
77 var content = TYPO3.lang['paste.modal.pastecopy'] || 'Do you want to copy the record to this position?';
78 var buttons = [
79 {
80 text: TYPO3.lang['paste.modal.button.cancel'] || 'Cancel',
81 active: true,
82 btnClass: 'btn-default',
83 trigger: function() {
84 Modal.currentModal.trigger('modal-dismiss');
85 }
86 },
87 {
88 text: TYPO3.lang['paste.modal.button.pastecopy'] || 'Copy',
89 btnClass: 'btn-' + Severity.getCssClass(severity),
90 trigger: function() {
91 Modal.currentModal.trigger('modal-dismiss');
92 DragDrop.onDrop($element.data('content'), $element, null);
93 }
94 }
95 ];
96 } else {
97 var content = TYPO3.lang['paste.modal.paste'] || 'Do you want to move the record to this position?';
98 var buttons = [
99 {
100 text: TYPO3.lang['paste.modal.button.cancel'] || 'Cancel',
101 active: true,
102 btnClass: 'btn-default',
103 trigger: function() {
104 Modal.currentModal.trigger('modal-dismiss');
105 }
106 },
107 {
108 text: TYPO3.lang['paste.modal.button.paste'] || 'Move',
109 btnClass: 'btn-' + Severity.getCssClass(severity),
110 trigger: function() {
111 Modal.currentModal.trigger('modal-dismiss');
112 DragDrop.onDrop($element.data('content'), $element, null);
113 }
114 }
115 ];
116 }
117 if (url !== null) {
118 var separator = (url.indexOf('?') > -1) ? '&' : '?';
119 var params = $.param({data: $element.data()});
120 Modal.loadUrl(title, severity, buttons, url + separator + params);
121 } else {
122 Modal.show(title, content, severity, buttons);
123 }
124 }
125
126 $(Paste.initialize);
127 return Paste;
128 });