Commit a28956f7 authored by Jen Zajac's avatar Jen Zajac Committed by Robert Lyon

Fix edit page removal of new block

  The dock's close button doesn't have the id in it
  needed to remove new (unsaved) blocks.

  This fix passes the block id in, so the new block
  can be cleaned up when a user changes their mind
  and removes it before saving.

  To test: add a new text block to a page, click the
  X icon in the top left of the dock, and observe
  that the new text block is removed from the page.

  The delete buttons next to each on page item, and
  the cancel button within the dock, should both
  still function as before.

  behatnotneeded

  Bug 1465107

Change-Id: I81f3b43acce9203b8ada9b3f7ac9b6cacb80768c
parent 038b52dd
......@@ -427,13 +427,14 @@
$('#action-dummy').attr('name', 'action_addblocktype_row_' + whereTo['row'] + '_column_' + whereTo['column'] + '_order_' + whereTo['order']);
}
rewriteDeleteButton(blockinstance.find('.deletebutton'));
insertBlockStub(blockinstance, whereTo);
if (data.data.configure) {
showDock($('#configureblock'), true);
addConfigureBlock(blockinstance, data.data.configure, true);
} else {
// if block has has_instance_config() set to false, eg 'comment' block
rewriteDeleteButton(blockinstance.find('.deletebutton'));
blockinstance.find('.deletebutton').focus();
}
},
......@@ -517,7 +518,7 @@
/**
* Rewrites one delete button to be AJAX
*/
function rewriteDeleteButton(button) {
function rewriteDeleteButton(button, blockinstanceId) {
button.off('click');
button.on('click', function(e) {
......@@ -526,8 +527,11 @@
e.preventDefault();
var self = $(this),
pd = {'id': $('#viewid').val(), 'change': 1},
pd = {'id': $('#viewid').val(), 'change': 1};
if ((blockinstanceId === undefined) && self.attr('data-id')) {
blockinstanceId = self.attr('data-id');
}
self.prop('disabled', true);
......@@ -537,7 +541,9 @@
sendjsonrequest(config['wwwroot'] + 'view/blocks.json.php', pd, 'POST', function(data) {
$('#blockinstance_' + blockinstanceId).remove();
if (blockinstanceId !== undefined) {
$('#blockinstance_' + blockinstanceId).remove();
}
if (!$('#configureblock').hasClass('hidden')) {
hideDock();
......@@ -725,7 +731,6 @@
function rewriteCancelButton(button, blockinstanceId) {
button.on('click', function(event) {
event.stopPropagation();
event.preventDefault();
......@@ -1055,7 +1060,6 @@
function addConfigureBlock(oldblock, configblock, removeoncancel) {
hideMediaPlayers();
var temp = $('<div>').html(configblock.html),
......@@ -1078,7 +1082,7 @@
deletebutton.focus();
if (removeoncancel !== undefined) {
rewriteDeleteButton(deletebutton);
rewriteDeleteButton(deletebutton, blockinstanceId);
cancelbutton = $('#cancel_instconf_action_configureblockinstance_id_' + blockinstanceId);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment