Commit 65c4e17f authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Changed expected json return object for ajax forms from 'success'

(boolean) to 'error' (see forms wiki)
parent b655aa8a
......@@ -34,11 +34,12 @@ $data['pagename'] = $pagename;
try {
$page = get_record('site_content','name',$pagename);
$data['content'] = $page->content;
$data['success'] = 1;
$data['error'] = false;
$data['message'] = get_string('loadedsitecontent');
}
catch (Exception $e) {
$data['success'] = 0;
$data['errormessage'] = $e->getMessage();
$data['error'] = 'local';
$data['message'] = get_string('failedloadingsitecontent');
}
echo json_encode($data);
......
......@@ -97,7 +97,7 @@ function requestPageText() {
logDebug(get_string('loadingpagecontent', $('pagename').value));
var d = loadJSONDoc('editchangepage.json.php',{'pagename':$('pagename').value});
d.addCallback(function(data) {
if (data.success) {
if (!data.error) {
logDebug(get_string('loadedsuccessfully', $('pagename').value));
setEditorContent(data.content);
originalcontent = getEditorContent();
......
......@@ -38,16 +38,17 @@ $data = new StdClass;
$data->name = $pagename;
$data->content = $pagetext;
$data->mtime = db_format_timestamp(time());
log_debug($USER);
try {
$user = get_record('usr','username',$USER->username);
$data->muser = $user->id;
update_record('site_content',$data,'name');
$result['success'] = 'ok';
$result['error'] = false;
$result['message'] = get_string('savedsuccessfully');
}
catch (Exception $e) {
$result['success'] = 'error';
$result['message'] = $e->getMessage();
$result['error'] = 'local';
$result['message'] = get_string('savefailed');
}
echo json_encode($result);
......
......@@ -14,6 +14,8 @@ function get_string(s) {
return str;
}
function global_error_handler(data) {}
// Appends a status message to the end of elemid
function displayMessage(m, /* optional */ elemid) {
var color = 'red';
......@@ -31,9 +33,9 @@ function displayMessage(m, /* optional */ elemid) {
}
var message = DIV({'style':'color:'+color+';'},m.message);
appendChildNodes(elemid, message);
callLater(2, function() {
removeElement(message);
//fade(message);
});
//callLater(2, function() {
// removeElement(message);
// //fade(message);
//});
}
......@@ -700,12 +700,15 @@ class Form {
$result .= "var d = sendXMLHttpRequest(req,queryString(data));\n";
$result .= 'd.addCallback(function (result) {';
$result .= 'var data = evalJSONRequest(result);';
$result .= "var type = data.success ? 'infomsg' : 'errmsg';\n";
$result .= $this->name . "_message(data.message,type);\n";
$result .= "var errtype = 'global'\n";
$result .= "if (!data.error) { errtype = 'infomsg'; }\n";
$result .= "if (data.error == 'local') { errtype = 'errmsg'; }\n";
$result .= "if (errtype == 'global') { global_error_handler(data); }\n";
$result .= 'else {' . $this->name . "_message(data.message,errtype);\n";
if (!empty($this->successcallback)) {
$result .= $this->successcallback . "();\n";
}
$result .= "});\n";
$result .= "}});\n";
$result .= 'd.addErrback(function() {';
$result .= $this->name . "_message('" . get_string('unknownerror') . "','errmsg');";
$result .= "});\n";
......
Supports Markdown
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