Commit 976d0c6f authored by Penny Leach's avatar Penny Leach
Browse files

reworked the watchlist screen to split out artefacts into another screen

and things not expandey anymore. TODO: deal with recursion when you
stop monitoring...
parent ca3553c6
......@@ -39,15 +39,15 @@ if ($stopmonitoring) {
db_begin();
try {
foreach ($_GET as $k => $v) {
if (preg_match('/^stopview\-(\d+)$/',$k,$m)) {
if (preg_match('/^stopviews\-(\d+)$/',$k,$m)) {
delete_records('usr_watchlist_view', 'usr', $userid, 'view', $m[1]);
$count++;
}
else if (preg_match('/^stopartefact\-(\d+)$/',$k,$m)) {
else if (preg_match('/^stopartefacts\-(\d+)$/',$k,$m)) {
delete_records('usr_watchlist_artefact', 'usr', $userid, 'artefact', $m[1]);
$count++;
}
else if (preg_match('/^stopcommunity\-(\d+)$/',$k,$m)) {
else if (preg_match('/^stopcommunities\-(\d+)$/',$k,$m)) {
delete_records('usr_watchlist_community', 'usr', $userid, 'community', $m[1]);
$count++;
}
......@@ -74,6 +74,9 @@ $offset = param_integer('offset', 0);
$userid = $USER->get('id');
$prefix = get_config('dbprefix');
$count = 0;
$records = array();
if ($type == 'views') {
$count = count_records('usr_watchlist_view', 'usr', $userid);
$sql = 'SELECT v.*, v.title AS name
......@@ -81,11 +84,7 @@ if ($type == 'views') {
JOIN ' . $prefix . 'usr_watchlist_view w ON w.view = v.id
WHERE w.usr = ?
ORDER BY v.mtime DESC';
if ($records = get_records_sql_array($sql, array($userid), $offset, $limit)) {
foreach ($records as &$r) {
// @todo session expandey stuff
}
}
$records = get_records_sql_array($sql, array($userid), $offset, $limit);
}
else if ($type == 'communities') {
$count = count_records('usr_watchlist_community', 'usr', $userid);
......@@ -96,6 +95,15 @@ else if ($type == 'communities') {
ORDER BY c.mtime DESC';
$records = get_records_sql_array($sql, array($userid), $offset, $limit);
}
else if ($type == 'artefacts') {
$count = count_records('usr_watchlist_artefact', 'usr', $userid);
$sql = 'SELECT a.* , a.title AS name
FROM ' . $prefix . 'artefact a
JOIN ' . $prefix . 'usr_watchlist_artefact w ON w.artefact = a.id
WHERE w.usr = ?
ORDER BY a.mtime DESC';
$records = get_records_sql_array($sql, array($userid), $offset, $limit);
}
if (empty($records)) {
$records = array();
......@@ -107,10 +115,6 @@ $activity = array(
'limit' => $limit,
'data' => $records,
'type' => $type,
'minusicon' => theme_get_image_path('minus.png'),
'plusicon' => theme_get_image_path('plus.png'),
'minusalt' => get_string('collapse'),
'plusalt' => get_string('expand'),
);
echo json_encode($activity);
......
......@@ -30,8 +30,9 @@ define('SUBMENUITEM', 'watchlist');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
$viewstring = get_string('viewsandartefacts', 'activity');
$viewstring = get_string('views', 'activity');
$communitystring = get_string('communities', 'activity');
$artefactstring = get_string('artefacts', 'activity');
$monitoredstring = get_string('monitored', 'activity');
$savefailed = get_string('stopmonitoringfailed', 'activity');
......@@ -39,44 +40,19 @@ $savesuccess = get_string('stopmonitoringsuccess', 'activity');
$getartefactsjson = get_config('wwwroot') . 'json/getartefacts.php';
$minusicon = theme_get_image_path('minus.png');
$plusicon = theme_get_image_path('plus.png');
$minusalt = get_string('collapse');
$plusalt = get_string('expand');
$javascript = <<<JAVASCRIPT
var watchlist = new TableRenderer(
'watchlist',
'index.json.php',
[
function(r, d) {
if (r.type == 'community') {
return TD(null, '');
}
if (r.expanded) {
return TD(null, A({'href': '', 'onclick': 'toggleExpand(' + r.id + ', \'view\'); return false;'},
IMG({'src' : '{$minusicon}', 'alt' : '{$minusalt}',
'border': 0, 'id' : 'viewicon-' + r.id})));
}
else {
return TD(null, A({'href': '', 'onclick': 'toggleExpand(' + r.id + ', \'view\'); return false;'},
IMG({'src' : '{$plusicon}', 'alt' : '{$plusalt}',
'border': 0, 'id' : 'viewicon-' + r.id})));
}
},
function(r) {
if (r.url) {
return TD(null,A({'href': r.url}, r.title));
return TD(null,A({'href': r.url}, r.name));
}
return TD(null,r.title);
return TD(null, r.name);
},
function (r) {
if (r.type == 'community') {
return TD(null, INPUT({'type' : 'checkbox', 'class': 'tocheck', 'name': 'stopcommunity-' + r.id}));
}
else {
return TD(null, INPUT({'type' : 'checkbox', 'class': 'tocheck', 'name': 'stopview-' + r.id}));
}
function (r, d) {
return TD(null, INPUT({'type' : 'checkbox', 'class': 'tocheck', 'name': 'stop' + d.type + '-' + r.id}));
}
]
);
......@@ -89,88 +65,10 @@ watchlist.updateOnLoad();
watchlist.rowfunction = function(r, n) { return TR({'id': r.id, 'class': 'view'}); }
function changeTitle(title) {
var titles = { 'views' : '{$viewstring}', 'communities' : '{$communitystring}' };
var titles = { 'views': '{$viewstring}', 'communities': '{$communitystring}', 'artefacts': '{$artefactstring}' };
$('typeheader').innerHTML = '{$monitoredstring} ' + titles[title];
}
function toggleExpand(id, type) {
if ($(type + 'icon-' + id).src == '{$minusicon}') {
$(type + 'icon-' + id).src = '{$plusicon}';
$(type + 'icon-' + id).alt = '{$plusalt}';
removeElement($(type + 'expanded' + id));
return;
}
$(type + 'icon-' + id).src = '{$minusicon}';
$(type + 'icon-' + id).alt = '{$minusalt}';
// the first thing to do is find out if we have children
var url = '{$getartefactsjson}';
var tablename = type + 'table' + id;
var newtable = TABLE({'id': tablename});
var newrow = TR({'class': type, 'id': type + 'expanded' + id}, TD(), TD({'colspan': 2}, newtable));
var tr = $(type + 'icon-' + id).parentNode.parentNode.parentNode;
insertSiblingNodesAfter(tr, newrow);
var newtablelist = new TableRenderer(
tablename,
url,
[
function(r, d) {
if (r.expanded) {
return TD(null, A({'href': '',
'onclick': 'toggleExpand(' + r.id + ', \'artefact\'); return false;'},
IMG({'src' : '{$minusicon}', 'alt' : '{$minusalt}',
'border': 0, 'id' : 'artefacticon-' + r.id})));
}
else {
return TD(null, A({'href': '',
'onclick': 'toggleExpand(' + r.id + ', \'artefact\'); return false;'},
IMG({'src' : '{$plusicon}', 'alt' : '{$plusalt}',
'border': 0, 'id' : 'artefacticon-' + r.id})));
}
},
function(r) {
if (r.url) {
return TD(null,A({'href': r.url}, r.title));
}
return TD(null,r.title);
},
function (r) {
return TD(null, INPUT({'type' : 'checkbox', 'class': 'tocheck', 'name': 'stopartefact-' + r.id}));
}
]
);
newtablelist.statevars.push('view');
if (type == 'artefact') {
newtablelist.statevars.push('artefact');
newtablelist.artefact = id;
newtablelist.view = findViewId(tr);
}
else {
newtablelist.view = id;
}
newtablelist.watchlist = 1;
newtablelist.statevars.push('watchlist');
newtablelist.rowfunction = function(r, n) { return TR({'id': r.id, 'class': 'artefact'}); }
newtablelist.paginate = false;
newtablelist.doupdate();
}
function findViewId(row) {
child = row;
while (typeof(child.parentNode) != 'undefined' && child.parentNode != null) {
parent = child.parentNode;
if (hasElementClass(parent, 'view')) {
if (parent.id.search(/viewexpanded(\d+)/) != -1) {
return parent.id.replace(/viewexpanded/,'');
}
}
child = parent;
}
}
function stopmonitoring(form) {
var c = 'tocheck';
var e = getElementsByTagAndClassName(null,'tocheck',form);
......@@ -206,12 +104,12 @@ function stopmonitoring(form) {
JAVASCRIPT;
$typechange = 'watchlist.doupdate({\'type\':this.options[this.selectedIndex].value}); changeTitle(this.options[this.selectedIndex].value);';
$typechange = 'watchlist.doupdate({\'type\':this.options[this.selectedIndex].value}); changeTitle(this.options[this.selectedIndex].value); $(\'messagediv\').innerHTML = \'\';';
$smarty = smarty(array('tablerenderer'));
$smarty->assign('site_menu', site_menu());
$smarty->assign('typechange', $typechange);
$smarty->assign('typestr', get_string('viewsandartefacts', 'activity'));
$smarty->assign('typestr', get_string('views', 'activity'));
$smarty->assign('selectall', 'toggleChecked(\'tocheck\'); return false;');
$smarty->assign('stopmonitoring', 'stopmonitoring(this); return false;');
$smarty->assign('INLINEJAVASCRIPT', $javascript);
......
......@@ -53,6 +53,8 @@ $string['failedtomarkasread'] = 'Failed to mark your notifications as read';
$string['stopmonitoring'] = 'Stop monitoring';
$string['viewsandartefacts'] = 'Views and artefacts';
$string['views'] = 'Views';
$string['artefacts'] = 'Artefacts';
$string['communities'] = 'Communities';
$string['monitored'] = 'Monitored';
$string['stopmonitoring'] = 'Stop monitoring';
......
......@@ -8,7 +8,8 @@
<form method="post">
{str tag='filter'}:
<select name="type" onChange="{$typechange}">
<option value="views">{str section='activity' tag='viewsandartefacts'}</option>
<option value="views">{str section='activity' tag='views'}</option>
<option value="artefacts">{str section='activity' tag='artefacts'}</option>
<option value="communities">{str section='activity' tag='communities'}</option>
</select>
</form>
......
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