Commit 52770f8b authored by Robert Lyon's avatar Robert Lyon Committed by Aaron Wells
Browse files

Bug 1511536: problem with deleting blocks when edit page first loads



The problem is due to the scope of the blockinstanceId variable being
outside of the click handler function, which inadvertently makes it
into a sort of static variable shared by all of the delete buttons.

So the solution is to use a locally-scoped blockinstanceId button
inside the click handler method.

Change-Id: I3e8ffac31cc869c545e85c5f53c3e710e2e71243
Signed-off-by: default avatarRobert Lyon <robertl@catalyst.net.nz>
Signed-off-by: default avatarAaron Wells <aaronw@catalyst.net.nz>
parent c2b3a178
Loading
Loading
Loading
Loading
+15 −5
Original line number Diff line number Diff line
@@ -531,8 +531,13 @@

    /**
     * Rewrites one delete button to be AJAX
     *
     * @param button: The button to rewrite it for
     * @param pblockinstanceId: If this is being called from the modal popup, we won't be able
     * to retrieve the button's ID. So this optional parameter can supply the button ID directly
     * in that case.
     */
    function rewriteDeleteButton(button, blockinstanceId) {
    function rewriteDeleteButton(button, pblockinstanceId) {
        button.off('click');

        button.on('click', function(e) {
@@ -541,11 +546,17 @@
            e.preventDefault();

            var self = $(this),
                pd = {'id': $('#viewid').val(), 'change': 1};
                pd = {'id': $('#viewid').val(), 'change': 1},
                blockinstanceId;

            if ((blockinstanceId === undefined) && self.attr('data-id')) {
            // If pblockinstanceId wasn't passed, retrieve the id from the button.
            if ((pblockinstanceId === undefined) && self.attr('data-id')) {
                blockinstanceId = self.attr('data-id');
            }
            // If pblockinstanceId was passed, then use that.
            else {
                blockinstanceId = pblockinstanceId;
            }

            self.prop('disabled', true);

@@ -554,8 +565,7 @@
                pd[self.attr('name')] = 1;

                sendjsonrequest(config['wwwroot'] + 'view/blocks.json.php', pd, 'POST', function(data) {

                    if (blockinstanceId !== undefined) {
                    if (blockinstanceId !== undefined && blockinstanceId !== null) {
                        $('#blockinstance_' + blockinstanceId).remove();
                    }

+26 −1
Original line number Diff line number Diff line
@@ -20,6 +20,24 @@ Scenario: Clicking ID's (Bug 1428456)
 And I press "Save"
 Then I should see "Buck Mulligan"

 And I follow "Text"
 And I press "Add"
 And I wait "1" seconds
 And I set the following fields to these values:
 | Block title | The Sun Also Rises |
 | Block content | <p>Robert Cohn was once middleweight boxing champion of Princeton. Do not think that I am very much impressed by that as a boxing title, but it meant a lot to Cohn...</p> |
 And I press "Save"
 Then I should see "Robert Cohn"

 And I follow "Text"
 And I press "Add"
 And I wait "1" seconds
 And I set the following fields to these values:
 | Block title | 1984 |
 | Block content | <p>It was a bright cold day in April, and the clocks were striking thirteen. Winston Smith, his chin nuzzled into his breast in an effort to escape the vile wind...</p> |
 And I press "Save"
 Then I should see "Winston Smith"

 # Checking if we can edit a block
 When I configure the block "About me"
 And I set the following fields to these values:
@@ -27,7 +45,14 @@ Scenario: Clicking ID's (Bug 1428456)
 And I press "Save"
 Then I should see "James Joyce"

 # Checking if we can delete a block
 # Checking that we can delete more than one block (Bug #1511536)
 # We need to leave and return to the page for this
 And I follow "Display page"
 And I follow "Edit this page"
 When I delete the block "The Sun Also Rises"
 Then I should not see "Robert Cohn"
 When I delete the block "1984"
 Then I should not see "Winston Smith"
 When I delete the block "Ulysses"
 Then I should not see "Buck Mulligan"