2 * This file is part of the TYPO3 CMS project.
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.
8 * For the full copyright and license information, please read the
9 * LICENSE.txt file that was distributed with this source code.
11 * The TYPO3 project - inspiring people to share!
15 * Module: TYPO3/CMS/Backend/Toolbar/ShortcutMenu
16 * shortcut menu logic to add new shortcut, remove a shortcut
19 define(['jquery', 'TYPO3/CMS/Backend/Modal', 'TYPO3/CMS/Backend/Icons'], function($, Modal
, Icons
) {
24 * @type {{options: {containerSelector: string, toolbarIconSelector: string, toolbarMenuSelector: string, shortcutItemSelector: string, shortcutDeleteSelector: string, shortcutEditSelector: string, shortcutFormTitleSelector: string, shortcutFormGroupSelector: string, shortcutFormSaveSelector: string, shortcutFormCancelSelector: string}}}
25 * @exports TYPO3/CMS/Backend/Toolbar/ShortcutMenu
29 containerSelector
: '#typo3-cms-backend-backend-toolbaritems-shortcuttoolbaritem',
30 toolbarIconSelector
: '.dropdown-toggle span.icon',
31 toolbarMenuSelector
: '.dropdown-menu',
32 shortcutItemSelector
: '.dropdown-menu .shortcut',
33 shortcutDeleteSelector
: '.shortcut-delete',
34 shortcutEditSelector
: '.shortcut-edit',
35 shortcutFormTitleSelector
: 'input[name="shortcut-title"]',
36 shortcutFormGroupSelector
: 'select[name="shortcut-group"]',
37 shortcutFormSaveSelector
: '.shortcut-form-save',
38 shortcutFormCancelSelector
: '.shortcut-form-cancel',
39 shortcutFormSelector
: '.shortcut-form'
44 * build the in-place-editor for a shortcut
46 * @param {Object} $shortcutRecord
48 ShortcutMenu
.editShortcut
= function($shortcutRecord
) {
51 url
: TYPO3
.settings
.ajaxUrls
['shortcut_editform'],
53 shortcutId
: $shortcutRecord
.data('shortcutid'),
54 shortcutGroup
: $shortcutRecord
.data('shortcutgroup')
57 }).done(function(data
) {
58 $shortcutRecord
.html(data
);
63 * Save the data from the in-place-editor for a shortcut
65 * @param {Object} $shortcutRecord
67 ShortcutMenu
.saveShortcutForm
= function($shortcutRecord
) {
69 url
: TYPO3
.settings
.ajaxUrls
['shortcut_saveform'],
71 shortcutId
: $shortcutRecord
.data('shortcutid'),
72 shortcutTitle
: $shortcutRecord
.find(ShortcutMenu
.options
.shortcutFormTitleSelector
).val(),
73 shortcutGroup
: $shortcutRecord
.find(ShortcutMenu
.options
.shortcutFormGroupSelector
).val()
77 }).done(function(data
) {
78 // @todo: we can evaluate here, but what to do? a message?
79 ShortcutMenu
.refreshMenu();
84 * removes an existing short by sending an AJAX call
86 * @param {Object} $shortcutRecord
88 ShortcutMenu
.deleteShortcut
= function($shortcutRecord
) {
89 // @todo: translations
90 Modal
.confirm('Delete bookmark', 'Do you really want to remove this bookmark?')
91 .on('confirm.button.ok', function() {
93 url
: TYPO3
.settings
.ajaxUrls
['shortcut_remove'],
95 shortcutId
: $shortcutRecord
.data('shortcutid')
100 // a reload is used in order to restore the original behaviour
101 // e.g. remove groups that are now empty because the last one in the group
103 ShortcutMenu
.refreshMenu();
105 $(this).trigger('modal-dismiss');
107 .on('confirm.button.cancel', function() {
108 $(this).trigger('modal-dismiss');
113 * makes a call to the backend class to create a new shortcut,
114 * when finished it reloads the menu
116 * @param {String} moduleName
117 * @param {String} url
118 * @param {String} confirmationText
119 * @param {String} motherModule
120 * @param {Object} shortcutButton
121 * @param {String} displayName
123 ShortcutMenu
.createShortcut
= function(moduleName
, url
, confirmationText
, motherModule
, shortcutButton
, displayName
) {
124 if (typeof confirmationText
!== 'undefined') {
125 // @todo: translations
126 Modal
.confirm('Create bookmark', confirmationText
)
127 .on('confirm.button.ok', function() {
128 var $toolbarItemIcon
= $(ShortcutMenu
.options
.toolbarIconSelector
, ShortcutMenu
.options
.containerSelector
),
129 $existingIcon
= $toolbarItemIcon
.clone();
131 Icons
.getIcon('spinner-circle-light', Icons
.sizes
.small
).done(function(spinner
) {
132 $toolbarItemIcon
.replaceWith(spinner
);
136 url
: TYPO3
.settings
.ajaxUrls
['shortcut_create'],
141 motherModName
: motherModule
,
142 displayName
: displayName
146 ShortcutMenu
.refreshMenu();
147 $(ShortcutMenu
.options
.toolbarIconSelector
, ShortcutMenu
.options
.containerSelector
).replaceWith($existingIcon
);
148 if (typeof shortcutButton
=== 'object') {
149 Icons
.getIcon('actions-system-shortcut-active', Icons
.sizes
.small
).done(function(icons
) {
150 $(shortcutButton
).html(icons
['actions-system-shortcut-active']);
152 $(shortcutButton
).addClass('active');
153 $(shortcutButton
).attr('title', null);
154 $(shortcutButton
).attr('onclick', null);
157 $(this).trigger('modal-dismiss');
159 .on('confirm.button.cancel', function() {
160 $(this).trigger('modal-dismiss');
167 * reloads the menu after an update
169 ShortcutMenu
.refreshMenu
= function() {
171 url
: TYPO3
.settings
.ajaxUrls
['shortcut_list'],
174 }).done(function(data
) {
175 $(ShortcutMenu
.options
.toolbarMenuSelector
, ShortcutMenu
.options
.containerSelector
).html(data
);
180 * Registers listeners
182 ShortcutMenu
.initializeEvents
= function() {
183 $(ShortcutMenu
.options
.containerSelector
).on('click', ShortcutMenu
.options
.shortcutDeleteSelector
, function(evt
) {
184 evt
.preventDefault();
185 evt
.stopImmediatePropagation();
186 ShortcutMenu
.deleteShortcut($(this).closest(ShortcutMenu
.options
.shortcutItemSelector
));
187 }).on('click', ShortcutMenu
.options
.shortcutEditSelector
, function(evt
) {
188 evt
.preventDefault();
189 evt
.stopImmediatePropagation();
190 ShortcutMenu
.editShortcut($(this).closest(ShortcutMenu
.options
.shortcutItemSelector
));
191 }).on('click', ShortcutMenu
.options
.shortcutFormSaveSelector
, function(evt
) {
192 ShortcutMenu
.saveShortcutForm($(this).closest(ShortcutMenu
.options
.shortcutItemSelector
));
193 }).on('submit', ShortcutMenu
.options
.shortcutFormSelector
, function(evt
) {
194 evt
.preventDefault();
195 evt
.stopImmediatePropagation();
196 ShortcutMenu
.saveShortcutForm($(this).closest(ShortcutMenu
.options
.shortcutItemSelector
));
197 }).on('click', ShortcutMenu
.options
.shortcutFormCancelSelector
, function() {
198 // re-render the menu on canceling the update of a shortcut
199 ShortcutMenu
.refreshMenu();
203 $(ShortcutMenu
.initializeEvents
);
205 // expose as global object
206 TYPO3
.ShortcutMenu
= ShortcutMenu
;