Commit 9e34de90 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Watchlist uses sendjsonrequest

parent 5cbf1864
......@@ -59,13 +59,11 @@ if ($stopmonitoring) {
}
catch (Exception $e) {
db_rollback();
$data = array('error' => $e->getMessage);
echo json_encode($data);
json_reply('local', get_string('stopmonitoringfailed', 'activity') . ': ' . $e->getMessage);
}
db_commit();
$data = array('success' => 1, 'count' => $count);
echo json_encode($data);
exit;
$message = $count ? get_string('stopmonitoringsuccess', 'activity') : false;
json_reply(false, array('message' => $message, 'count' => $count));
}
if (!empty($userlist)) {
if ($userlist == 'views') {
......@@ -98,7 +96,7 @@ if (!empty($userlist)) {
foreach ($users as $u) {
$data[] = array('id' => $u->id, 'name' => display_name($u, $USER));
}
json_reply(false, array('users' => $data));
json_reply(false, array('message' => false, 'users' => $data));
}
// normal processing (fetching tablerenderer results)
......
......@@ -38,9 +38,6 @@ $allusersstring = get_string('allusers');
$andchildren = ' * ' . get_string('andchildren', 'activity');
$savefailed = get_string('stopmonitoringfailed', 'activity');
$savesuccess = get_string('stopmonitoringsuccess', 'activity');
$wwwroot = get_config('wwwroot');
$javascript = <<<JAVASCRIPT
......@@ -103,23 +100,13 @@ function stopmonitoring(form) {
pd['stopmonitoring'] = 1;
var d = loadJSONDoc('index.json.php', pd);
d.addCallbacks(function (data) {
if (data.success) {
if (data.count > 0) {
$('messagediv').innerHTML = '$savesuccess';
watchlist.doupdate();
}
}
if (data.error) {
$('messagediv').innerHTML = '$savefailed (' + data.error + ')';
}
},
function () {
$('messagediv').innerHTML = '$savefailed';
sendjsonrequest('index.json.php', pd, 'GET', function (data) {
if (data.count > 0) {
watchlist.doupdate();
}
)
}, function () {
watchlist.doupdate();
});
}
function statusChange() {
......@@ -146,9 +133,7 @@ function statusChange() {
}
else {
var pd = {'userlist': typevalue};
var d = loadJSONDoc('index.json.php', pd);
d.addCallbacks(function (data) {
sendjsonrequest('index.json.php', pd, 'GET', function (data) {
var userSelect = $('user');
var newOptions = new Array()
var opt = OPTION(null, '{$allusersstring}');
......@@ -156,7 +141,7 @@ function statusChange() {
opt.selected = true;
}
newOptions.push(opt);
forEach (data.message.users, function (u) {
forEach (data.users, function (u) {
var opt = OPTION({'value': u.id}, u.name);
if (uservalue == u.id) {
opt.selected = true;
......
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