Commit 154c2894 authored by Robert Lyon's avatar Robert Lyon

Bug 1865095: Config modal error message display

We need to be able to display the error when the json_reply() used is
the mahara.php one and not the pieform.php one - for non form related
error replies

Change-Id: I9a1407fc484afc8ef1aef69a2ce01f592c2c6ee7
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent 8aad351a
......@@ -353,7 +353,7 @@ function sendjsonrequest(url, data, method, successcallback, errorcallback, quie
}
if (error) {
errorcallback();
errorcallback(data);
}
else {
try {
......@@ -375,7 +375,7 @@ function sendjsonrequest(url, data, method, successcallback, errorcallback, quie
displayMessage(get_string('unknownerror'), 'error');
}
errorcallback();
errorcallback(null);
processingStop();
});
}
......
......@@ -199,64 +199,64 @@
};
pd['action_changeblockinstance_id_' + blockid + '_new_' + isnew + '_blocktype_' + option + '_title_' + title] = true;
sendjsonrequest(config['wwwroot'] + 'view/blocks.json.php', pd, 'POST', function(data) {
if (data.data.returnCode == 1) {
console.log('error: ' + data.data.message);
}
else {
console.log('success: ' + data.data.message);
// Update block on page to be of new type
var newdata = {};
newdata.blockid = data.data.blockid;
newdata.viewid = data.data.viewid;
newdata.data = {};
newdata.data.html = data.data.display.html;
newdata.data.javascript = data.data.display.javascript;
var blockinstance = ViewManager.replaceConfigureBlock(newdata);
if (data.data.configure) {
// The new block has configuration so update config modal to have new config form
if (data.data.isnew) {
addConfigureBlock(blockinstance, data.data.configure, true);
}
else {
// wire up the cancel button on chosen blocktype form to revert the block back to placeholder block
addConfigureBlock(blockinstance, data.data.configure);
var blockinstanceId = blockinstance.attr('data-id');
var cancelbutton = jQuery('#cancel_instconf_action_configureblockinstance_id_' + blockinstanceId);
cancelbutton.off('click');
cancelbutton.on('click',function(e) {
e.stopPropagation();
e.preventDefault();
var revpd = {
'id': $('#viewid').val(),
'change': 1,
'blocktype': 'placeholder',
};
revpd['action_revertblockinstance_id_' + data.data.blockid + '_title_' + data.data.oldtitle] = true;
sendjsonrequest(config['wwwroot'] + 'view/blocks.json.php', revpd, 'POST', function(revdata) {
if (data.data.returnCode == 1) {
console.log('error: ' + revdata.data.message);
}
else {
console.log('success: ' + revdata.data.message);
var revnewdata = {};
revnewdata.blockid = revdata.data.blockid;
revnewdata.viewid = revdata.data.viewid;
revnewdata.data = {};
revnewdata.data.html = revdata.data.display.html;
revnewdata.data.javascript = revdata.data.display.javascript;
var blockinstance = ViewManager.replaceConfigureBlock(revnewdata);
var configbutton = jQuery('.view-container button[name="action_configureblockinstance_id_' + revdata.data.blockid + '"]');
onModalCancel(e, configbutton);
}
});
});
}
// Update block on page to be of new type
var newdata = {};
newdata.blockid = data.data.blockid;
newdata.viewid = data.data.viewid;
newdata.data = {};
newdata.data.html = data.data.display.html;
newdata.data.javascript = data.data.display.javascript;
var blockinstance = ViewManager.replaceConfigureBlock(newdata);
if (data.data.configure) {
// The new block has configuration so update config modal to have new config form
if (data.data.isnew) {
addConfigureBlock(blockinstance, data.data.configure, true);
}
else {
// No configure form so we just need to close the modal
hideDock();
// wire up the cancel button on chosen blocktype form to revert the block back to placeholder block
addConfigureBlock(blockinstance, data.data.configure);
var blockinstanceId = blockinstance.attr('data-id');
var cancelbutton = jQuery('#cancel_instconf_action_configureblockinstance_id_' + blockinstanceId);
cancelbutton.off('click');
cancelbutton.on('click',function(e) {
e.stopPropagation();
e.preventDefault();
var revpd = {
'id': $('#viewid').val(),
'change': 1,
'blocktype': 'placeholder',
};
revpd['action_revertblockinstance_id_' + data.data.blockid + '_title_' + data.data.oldtitle] = true;
sendjsonrequest(config['wwwroot'] + 'view/blocks.json.php', revpd, 'POST', function(revdata) {
console.log('success: ' + revdata.data.message);
var revnewdata = {};
revnewdata.blockid = revdata.data.blockid;
revnewdata.viewid = revdata.data.viewid;
revnewdata.data = {};
revnewdata.data.html = revdata.data.display.html;
revnewdata.data.javascript = revdata.data.display.javascript;
var blockinstance = ViewManager.replaceConfigureBlock(revnewdata);
var configbutton = jQuery('.view-container button[name="action_configureblockinstance_id_' + revdata.data.blockid + '"]');
onModalCancel(e, configbutton);
},
function (revdata) {
if (revdata.message) {
console.log('error: ' + revdata.message);
}
});
});
}
}
else {
// No configure form so we just need to close the modal
hideDock();
}
},
function (data) {
if (data.message && data.placement) {
$('#' + data.placement).find('.alert').remove();
$('#' + data.placement).prepend('<div class="alert alert-danger">' + data.message + '</div>');
}
});
});
});
......
......@@ -80,7 +80,7 @@ $string['blockconfigdatacalledfromset'] = 'Configdata should not be set directly
$string['invaliddirection'] = 'Invalid direction %s.';
$string['onlyoneprofileviewallowed'] = 'You are only allowed one profile page.';
$string['cannotputblocktypeintoview'] = 'Cannot put %s block types into this page';
$string['onlyoneblocktypeperview'] = 'Cannot put more than one %s block type into a page.';
$string['onlyoneblocktypeperview'] = 'Cannot put more than one "%s" block type into a page.';
$string['errorat'] = ' at ';
// if you change these next two , be sure to change them in libroot/errors.php
......
......@@ -2348,7 +2348,8 @@ class View {
$count = count_records_select('block_instance', '"view" = ? AND blocktype = ?',
array($this->id, $values['blocktype']));
if ($count > 0) {
throw new UserException(get_string('onlyoneblocktypeperview', 'error', $values['blocktype']));
$blocktitle = call_static_method(generate_class_name('blocktype', $values['blocktype']), 'get_title', $this);
throw new UserException(get_string('onlyoneblocktypeperview', 'error', $blocktitle));
}
}
......@@ -2465,7 +2466,8 @@ class View {
$count = count_records_select('block_instance', '"view" = ? AND blocktype = ?',
array($this->id, $values['blocktype']));
if ($count > 0) {
throw new UserException(get_string('onlyoneblocktypeperview', 'error', $values['blocktype']));
$blocktitle = call_static_method(generate_class_name('blocktype', $values['blocktype']), 'get_title', $this);
throw new UserException(get_string('onlyoneblocktypeperview', 'error', $blocktitle));
}
}
......
......@@ -32,7 +32,7 @@ if ($change) {
json_reply(false, $returndata);
}
catch (Exception $e) {
json_reply(true, $e->getMessage());
json_reply(true, array('message' => $e->getMessage(), 'placement' => 'placeholderlist'));
}
}
// else we're just reading data...
......
......@@ -49,4 +49,4 @@ Feature: Site admin includes special blocks for the "Profile" site template and
And I should see "Wall" in the "Content types" property
And I click on "Wall" in the "Content types" property
And I press "Save"
Then I should see "Cannot put more than one wall block type into a page."
Then I should see "Cannot put more than one \"Wall\" block type into a page."
......@@ -146,6 +146,8 @@ Scenario: Editing Education and Employment info
Then I should see "Address: 150 Willis St"
# Test whether Education history shows address
When I follow "Machine Learning - Creation 2.1 (Masters of Philosophy) at University College"
And I wait "1" seconds
And I scroll to the base of id "bottom-pane"
Then I should see "Address: 23a O'Dell Boulevard"
# Test whether a qualification with just start date and title also shows address
When I scroll to the base of id "bottom-pane"
......@@ -176,6 +178,7 @@ Scenario: Adding Achievements
| addcertification_description | Designed for testers holding the ISTQB® Foundation Certificate, this extension course provides an understanding of the fundamentals of testing in Agile projects. |
And I scroll to the base of id "addcertification"
And I attach the file "Image2.png" to "Attach file"
And I wait "1" seconds
And I press "Save"
And I scroll to the id "main-nav"
And I should see "Saved successfully"
......
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