Skip to content

Commit

Permalink
Issue #161: Polish the modal edit refresh.
Browse files Browse the repository at this point in the history
Fixes #161.
  • Loading branch information
laryn committed Aug 15, 2023
1 parent 6f191fe commit 2c9997e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
18 changes: 14 additions & 4 deletions js/paragraphs_modal_admin.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
(function($, Backdrop) {
Backdrop.ajax.prototype.commands.paragraphs_modal_admin_message_hide = function(ajax, response, status) {
$('.paragraphs-modal-admin-message').delay(1000).fadeOut(800);
//alert(response.value1);
(function ($, Backdrop) {
Backdrop.ajax.prototype.commands.paragraphs_modal_admin_message_hide = function (ajax, response, status) {
$('.paragraphs-modal-admin-message').delay(1000).fadeOut(800, function () {
$(this).remove();
});
}

Backdrop.ajax.prototype.commands.paragraphs_modal_admin_refresh = function (ajax, response, status) {
$(response.selector).addClass('paragraphs-item-stale');
$('.paragraphs-item-stale').removeClass(response.selector);
$('.paragraphs-item-stale').after(response.new_element);
$(response.selector).addClass('paragraphs-item-modal-admin');
$(response.selector).prepend($('.paragraphs-item-stale > .dropbutton-wrapper'));
$('.paragraphs-item-stale').remove();
}
})(jQuery, Backdrop);
16 changes: 10 additions & 6 deletions paragraphs.admin.inc
Original file line number Diff line number Diff line change
Expand Up @@ -486,12 +486,16 @@ function paragraphs_modal_admin_save_close($form, &$form_state) {

// Refresh display of Paragraph that was edited.
if (is_object($form_state['build_info']['args'][0]) && !empty($form_state['build_info']['args'][0]->item_id)) {
$item_id = $form_state['build_info']['args'][0]->item_id;
$selector = '.paragraphs-item-' . $form_state['build_info']['args'][0]->item_id;
$revision_id = $form_state['build_info']['args'][0]->revision_id;
$fresh_paragraph = paragraphs_item_revision_load($revision_id)->view();
$new_element = '<div class=\'messages status paragraphs-modal-admin-message\'>' . t('Paragraph !type has been updated.', array('!type' => $bundle->name)) . '</div>';
$new_element .= backdrop_render($fresh_paragraph['paragraphs_item']);
$commands['#commands'][] = ajax_command_html('.paragraphs-item-' . $item_id . ' .content', $new_element);
$new_element .= backdrop_render($fresh_paragraph);
$commands['#commands'][] = array(
'command' => 'paragraphs_modal_admin_refresh',
'selector' => $selector,
'new_element' => $new_element,
);
$commands['#commands'][] = array(
'command' => 'paragraphs_modal_admin_message_hide',
);
Expand Down Expand Up @@ -849,7 +853,7 @@ function paragraphs_modal_admin_add_form($form, &$form_state, $mode, $paragraphs
// Create the new paragraph item and set the host entity + position.
$new_paragraph = entity_create('paragraphs_item', array(
'bundle' => $paragraphs_bundle->bundle,
'field_name' => $field_name
'field_name' => $field_name,
));
$new_paragraph->setHostEntity($host_entity_type, $host_entity, $host_entity->langcode, FALSE);
$new_paragraph->position = $new_paragraph_position;
Expand Down Expand Up @@ -921,8 +925,8 @@ function paragraphs_modal_admin_add_form_submit($form, &$form_state) {
$new_paragraph = array(
array(
'value' => $paragraphs_item->item_id,
'revision_id' => $paragraphs_item->revision_id
)
'revision_id' => $paragraphs_item->revision_id,
),
);

// Load the paragraphs field from the host entity and insert the new paragraph item in the correct position.
Expand Down

0 comments on commit 2c9997e

Please sign in to comment.