Skip to content
This repository was archived by the owner on Jul 22, 2022. It is now read-only.

Commit 6b664a8

Browse files
authored
fix(278): restore support for _delete field (#280)
1 parent 42f1802 commit 6b664a8

File tree

1 file changed

+35
-26
lines changed

1 file changed

+35
-26
lines changed

src/Resources/public/js/fragmentList.jquery.js

+35-26
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@
190190
if (!$frag.hasClass('is-tmp')) {
191191
// Hide form block
192192
$form.hide();
193+
// Check the hidden field that marks deletion
194+
$cb.prop('checked', true).attr('checked', true);
193195
this.moveSelectedFragmentOutsideOfForm(id, $frag, $form);
194196

195197
// Remove a new fragment (not already saved)
@@ -223,15 +225,17 @@
223225
var divElement = $('<div>')[0];
224226
divElement.setAttribute('id', id);
225227
fragmentElement.clone().appendTo(divElement);
226-
divElement.append(formElement[0]);
228+
// Hide the form instead of removing it
229+
formElement.hide();
227230

228231
// Generate the elements who contains the fragment title and the cancel button.
229232
var resetRemovedElement = $('<span>');
230233
var fragmentTitle = fragmentElement.find('.fragment__title').text();
231234

232235
var cancelIcon = $('<i>');
233236
cancelIcon.attr('class', 'fa fa-repeat');
234-
cancelIcon.on('click', this.cancelFragmentDeletion);
237+
// Forward the current context to the callback function
238+
cancelIcon.on('click', this.cancelFragmentDeletion(this));
235239

236240
resetRemovedElement.append(cancelIcon);
237241
resetRemovedElement.append(' <i>' + fragmentTitle + '</i>');
@@ -247,31 +251,36 @@
247251
/**
248252
* This method cancels the fragment deletion.
249253
*
250-
* @param {event} e
254+
* @param {Plugin} plugin
251255
*/
252-
cancelFragmentDeletion: function (e) {
253-
e.preventDefault();
254-
e.stopPropagation();
255-
256-
var $target = $(e.currentTarget),
257-
$frag = $target.closest('[data-fragment]'),
258-
id = $frag.data('fragId');
259-
260-
// Get the deleted fragment by id.
261-
var canceledFragment = $('div#deleted-fragments');
262-
263-
// Get the fragment list.
264-
var fragment = $('ul.fragmentList').find('[data-frag-id="' + id + '"]');
265-
266-
// Get forms.
267-
var forms = $("[id~=field_widget_" + id.slice(0, -2) + "]");
268-
269-
// Reset clear and append the fragments list element.
270-
fragment.empty();
271-
fragment.append(canceledFragment.find('[data-frag-id="' + id + '"]').children());
272-
273-
// Move the deleted form to the original place.
274-
forms.append(canceledFragment.find('[data-fragment-form="' + id + '"]'));
256+
cancelFragmentDeletion: function (plugin) {
257+
return function (e) {
258+
e.preventDefault();
259+
e.stopPropagation();
260+
261+
var $target = $(e.currentTarget),
262+
$frag = $target.closest('[data-fragment]'),
263+
id = $frag.data('fragId'),
264+
$form = plugin.getFormByFragmentId(id),
265+
$cb = $form.find(plugin.options.formRemoveName)
266+
;
267+
268+
// Get the deleted fragment by id.
269+
var canceledFragment = $('div#deleted-fragments');
270+
271+
// Get the fragment list.
272+
var fragment = $('ul.fragmentList').find('[data-frag-id="' + id + '"]');
273+
274+
// Get forms.
275+
var forms = $("[id~=field_widget_" + id.slice(0, -2) + "]");
276+
277+
// Reset clear and append the fragments list element.
278+
fragment.empty();
279+
fragment.append(canceledFragment.find('[data-frag-id="' + id + '"]').children());
280+
281+
// Uncheck the _delete field
282+
$cb.prop('checked', false).attr('checked', false);
283+
};
275284
},
276285

277286
/**

0 commit comments

Comments
 (0)