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

Commit

Permalink
fix(278): restore support for _delete field
Browse files Browse the repository at this point in the history
  • Loading branch information
srascar committed Jul 16, 2021
1 parent d6f0e27 commit 528bbea
Showing 1 changed file with 35 additions and 26 deletions.
61 changes: 35 additions & 26 deletions src/Resources/public/js/fragmentList.jquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@
if (!$frag.hasClass('is-tmp')) {
// Hide form block
$form.hide();
// Check the hidden field that marks deletion
$cb.prop('checked', true).attr('checked', true);
this.moveSelectedFragmentOutsideOfForm(id, $frag, $form);

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

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

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

resetRemovedElement.append(cancelIcon);
resetRemovedElement.append(' <i>' + fragmentTitle + '</i>');
Expand All @@ -247,31 +251,36 @@
/**
* This method cancels the fragment deletion.
*
* @param {event} e
* @param {Plugin} plugin
*/
cancelFragmentDeletion: function (e) {
e.preventDefault();
e.stopPropagation();

var $target = $(e.currentTarget),
$frag = $target.closest('[data-fragment]'),
id = $frag.data('fragId');

// Get the deleted fragment by id.
var canceledFragment = $('div#deleted-fragments');

// Get the fragment list.
var fragment = $('ul.fragmentList').find('[data-frag-id="' + id + '"]');

// Get forms.
var forms = $("[id~=field_widget_" + id.slice(0, -2) + "]");

// Reset clear and append the fragments list element.
fragment.empty();
fragment.append(canceledFragment.find('[data-frag-id="' + id + '"]').children());

// Move the deleted form to the original place.
forms.append(canceledFragment.find('[data-fragment-form="' + id + '"]'));
cancelFragmentDeletion: function (plugin) {
return function (e) {
e.preventDefault();
e.stopPropagation();

var $target = $(e.currentTarget),
$frag = $target.closest('[data-fragment]'),
id = $frag.data('fragId'),
$form = plugin.getFormByFragmentId(id),
$cb = $form.find(plugin.options.formRemoveName)
;

// Get the deleted fragment by id.
var canceledFragment = $('div#deleted-fragments');

// Get the fragment list.
var fragment = $('ul.fragmentList').find('[data-frag-id="' + id + '"]');

// Get forms.
var forms = $("[id~=field_widget_" + id.slice(0, -2) + "]");

// Reset clear and append the fragments list element.
fragment.empty();
fragment.append(canceledFragment.find('[data-frag-id="' + id + '"]').children());

// Uncheck the _delete field
$cb.prop('checked', false).attr('checked', false);
};
},

/**
Expand Down

0 comments on commit 528bbea

Please sign in to comment.