Commit 73fcb0c4 authored by Richard Mansfield's avatar Richard Mansfield
Browse files
parents 5ee7fe59 f967bc0e
......@@ -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);
......
......@@ -393,7 +393,7 @@ MochiKit.Base.update(MochiKit.Color.Color, {
var d = MochiKit.DOM;
var cls = MochiKit.Color.Color;
for (elem = d.getElement(elem); elem; elem = elem.parentNode) {
var actualColor = MochiKit.Style.computedStyle.apply(d, arguments);
var actualColor = MochiKit.Style.getStyle.apply(d, arguments);
if (!actualColor) {
continue;
}
......
......@@ -110,6 +110,7 @@ MochiKit.DOM.EXPORT = [
"emitHTML",
"scrapeText",
"isParent",
"getFirstParentByTagAndClassName",
"makeClipping",
"undoClipping",
"makePositioned",
......@@ -122,7 +123,7 @@ MochiKit.DOM.EXPORT_OK = [
];
MochiKit.DOM.DEPRECATED = [
['computedStyle', 'MochiKit.Style.computedStyle', '1.4'],
['computedStyle', 'MochiKit.Style.getStyle', '1.4'],
/** @id MochiKit.DOM.elementDimensions */
['elementDimensions', 'MochiKit.Style.getElementDimensions', '1.4'],
/** @id MochiKit.DOM.elementPosition */
......@@ -1038,6 +1039,43 @@ MochiKit.Base.update(MochiKit.DOM, {
}
},
/** @id MochiKit.DOM.getFirstParentByTagAndClassName */
getFirstParentByTagAndClassName: function (elem, tagName, className) {
var self = MochiKit.DOM;
elem = self.getElement(elem);
if (typeof(tagName) == 'undefined' || tagName === null) {
tagName = '*';
} else {
tagName = tagName.toUpperCase();
}
if (typeof(className) == 'undefined' || className === null) {
className = null;
}
var classList = '';
var curTagName = '';
while (elem && elem.tagName) {
elem = elem.parentNode;
if (tagName == '*' && className === null) {
return elem;
}
classList = elem.className.split(' ');
curTagName = elem.tagName.toUpperCase();
if (className === null && tagName == curTagName) {
return elem;
} else if (className !== null) {
for (var i = 0; i < classList.length; i++) {
if (tagName == '*' && classList[i] == className) {
return elem;
} else if (tagName == curTagName && classList[i] == className) {
return elem;
}
}
}
}
return elem;
},
/** @id MochiKit.DOM.isParent */
isParent: function (child, element) {
if (!child.parentNode || child == element) {
......
......@@ -415,7 +415,7 @@ MochiKit.DragAndDrop.Draggable.prototype = {
/** @id MochiKit.DragAndDrop.starteffect */
starteffect: function (innerelement) {
this._savedOpacity = MochiKit.Style.getOpacity(innerelement) || 1.0;
this._savedOpacity = MochiKit.Style.getStyle(innerelement, 'opacity') || 1.0;
new v.Opacity(innerelement, {duration:0.2, from:this._savedOpacity, to:0.7});
},
/** @id MochiKit.DragAndDrop.reverteffect */
......
......@@ -66,12 +66,19 @@ MochiKit.Base.update(MochiKit.Signal.Event.prototype, {
var str = '{event(): ' + repr(this.event()) +
', src(): ' + repr(this.src()) +
', type(): ' + repr(this.type()) +
', target(): ' + repr(this.target()) +
', modifier(): ' + '{alt: ' + repr(this.modifier().alt) +
', target(): ' + repr(this.target());
if (this.type() &&
this.type().indexOf('key') === 0 ||
this.type().indexOf('mouse') === 0 ||
this.type().indexOf('click') != -1 ||
this.type() == 'contextmenu') {
str += ', modifier(): ' + '{alt: ' + repr(this.modifier().alt) +
', ctrl: ' + repr(this.modifier().ctrl) +
', meta: ' + repr(this.modifier().meta) +
', shift: ' + repr(this.modifier().shift) +
', any: ' + repr(this.modifier().any) + '}';
}
if (this.type() && this.type().indexOf('key') === 0) {
str += ', key(): {code: ' + repr(this.key().code) +
......@@ -344,7 +351,7 @@ MochiKit.Base.update(MochiKit.Signal.Event.prototype, {
- Safari doesn't fire any click events on a right
click:
http://bugzilla.opendarwin.org/show_bug.cgi?id=6595
http://bugs.webkit.org/show_bug.cgi?id=6595
- Firefox fires the event, and sets ctrlKey = true
......
......@@ -50,11 +50,9 @@ MochiKit.Style.toString = function () {
MochiKit.Style.EXPORT_OK = [];
MochiKit.Style.EXPORT = [
'setOpacity',
'getOpacity',
'setStyle',
'getStyle', // temporary
'computedStyle',
'setOpacity',
'getStyle',
'getElementDimensions',
'elementDimensions', // deprecated
'setElementDimensions',
......@@ -115,62 +113,38 @@ MochiKit.Style.Coordinates.prototype.toString = function () {
MochiKit.Base.update(MochiKit.Style, {
/** @id MochiKit.Style.computedStyle */
computedStyle: function (elem, cssProperty) {
/** @id MochiKit.Style.getStyle */
getStyle: function (elem, style) {
var dom = MochiKit.DOM;
var d = dom._document;
elem = dom.getElement(elem);
cssProperty = MochiKit.Base.camelize(cssProperty);
style = MochiKit.Base.camelize(style);
if (!elem || elem == d) {
return undefined;
}
/* from YUI 0.10.0 */
if (cssProperty == 'opacity' && elem.filters) { // IE opacity
try {
return elem.filters.item('DXImageTransform.Microsoft.Alpha'
).opacity / 100;
} catch(e) {
try {
return elem.filters.item('alpha').opacity / 100;
} catch(e) {}
if (style == 'opacity' && elem.filters) {
var opacity;
if (opacity = (MochiKit.Style.getStyle(elem, 'filter') || '').match(/alpha\(opacity=(.*)\)/)) {
if (opacity[1]) {
return parseFloat(opacity[1]) / 100;
}
}
return 1.0;
}
if (elem.currentStyle) {
return elem.currentStyle[cssProperty];
}
if (typeof(d.defaultView) == 'undefined') {
return undefined;
}
if (d.defaultView === null) {
return undefined;
}
var style = d.defaultView.getComputedStyle(elem, null);
if (typeof(style) == 'undefined' || style === null) {
return undefined;
}
var selectorCase = cssProperty.replace(/([A-Z])/g, '-$1'
).toLowerCase(); // from dojo.style.toSelectorCase
return style.getPropertyValue(selectorCase);
},
/** @id MochiKit.Style.getStyle */
getStyle: function (elem, style) {
elem = MochiKit.DOM.getElement(elem);
var value = elem.style[MochiKit.Base.camelize(style)];
var value = elem.style[style];
if (!value) {
if (document.defaultView && document.defaultView.getComputedStyle) {
var css = document.defaultView.getComputedStyle(elem, null);
if (d.defaultView && d.defaultView.getComputedStyle) {
var css = d.defaultView.getComputedStyle(elem, null);
value = css ? css.getPropertyValue(style) : null;
} else if (elem.currentStyle) {
value = elem.currentStyle[MochiKit.Base.camelize(style)];
value = elem.currentStyle[style];
}
}
if (style == 'opacity') {
value = parseFloat(value);
}
if (/Opera/.test(navigator.userAgent) && (MochiKit.Base.find(['left', 'top', 'right', 'bottom'], style) != -1)) {
if (MochiKit.Style.getStyle(elem, 'position') == 'static') {
......@@ -185,42 +159,33 @@ MochiKit.Base.update(MochiKit.Style, {
setStyle: function (elem, style) {
elem = MochiKit.DOM.getElement(elem);
for (name in style) {
elem.style[MochiKit.Base.camelize(name)] = style[name];
}
},
/** @id MochiKit.Style.getOpacity */
getOpacity: function (elem) {
var opacity;
if (opacity = MochiKit.Style.getStyle(elem, 'opacity')) {
return parseFloat(opacity);
}
if (opacity = (MochiKit.Style.getStyle(elem, 'filter') || '').match(/alpha\(opacity=(.*)\)/)) {
if (opacity[1]) {
return parseFloat(opacity[1]) / 100;
if (name == 'opacity') {
MochiKit.Style.setOpacity(elem, style[name]);
} else {
elem.style[MochiKit.Base.camelize(name)] = style[name];
}
}
return 1.0;
},
/** @id MochiKit.Style.setOpacity */
setOpacity: function(elem, o) {
setOpacity: function (elem, o) {
elem = MochiKit.DOM.getElement(elem);
var self = MochiKit.Style;
if (o == 1) {
var toSet = /Gecko/.test(navigator.userAgent) && !(/Konqueror|Safari|KHTML/.test(navigator.userAgent));
self.setStyle(elem, {opacity: toSet ? 0.999999 : 1.0});
elem.style[name] = toSet ? 0.999999 : 1.0;
if (/MSIE/.test(navigator.userAgent)) {
self.setStyle(elem, {filter:
self.getStyle(elem, 'filter').replace(/alpha\([^\)]*\)/gi, '')});
elem.style['filter'] =
self.getStyle(elem, 'filter').replace(/alpha\([^\)]*\)/gi, '');
}
} else {
if (o < 0.00001) {
o = 0;
}
self.setStyle(elem, {opacity: o});
elem.style[name] = o;
if (/MSIE/.test(navigator.userAgent)) {
self.setStyle(elem,
{filter: self.getStyle(elem, 'filter').replace(/alpha\([^\)]*\)/gi, '') + 'alpha(opacity=' + o * 100 + ')' });
elem.style['filter'] =
self.getStyle(elem, 'filter').replace(/alpha\([^\)]*\)/gi, '') + 'alpha(opacity=' + o * 100 + ')';
}
}
},
......@@ -242,7 +207,7 @@ MochiKit.Base.update(MochiKit.Style, {
if (!elem ||
(!(elem.x && elem.y) &&
(!elem.parentNode == null ||
self.computedStyle(elem, 'display') == 'none'))) {
self.getStyle(elem, 'display') == 'none'))) {
return undefined;
}
......@@ -301,7 +266,7 @@ MochiKit.Base.update(MochiKit.Style, {
if ((typeof(opera) != 'undefined' &&
parseFloat(opera.version()) < 9) ||
(ua.indexOf('safari') != -1 &&
self.computedStyle(elem, 'position') == 'absolute')) {
self.getStyle(elem, 'position') == 'absolute')) {
c.x -= b.offsetLeft;
c.y -= b.offsetTop;
......@@ -368,7 +333,7 @@ MochiKit.Base.update(MochiKit.Style, {
if (!elem) {
return undefined;
}
var disp = self.computedStyle(elem, 'display');
var disp = self.getStyle(elem, 'display');
// display can be empty/undefined on WebKit/KHTML
if (disp != 'none' && disp != '' && typeof(disp) != 'undefined') {
return new self.Dimensions(elem.offsetWidth || 0,
......
......@@ -815,7 +815,7 @@ MochiKit.Base.update(MochiKit.Visual.Opacity.prototype, {
s.setStyle(this.element, {zoom: 1});
}
options = b.update({
from: s.getOpacity(this.element) || 0.0,
from: s.getStyle(this.element, 'opacity') || 0.0,
to: 1.0
}, options || {});
this.start(options);
......@@ -823,11 +823,11 @@ MochiKit.Base.update(MochiKit.Visual.Opacity.prototype, {
/** @id MochiKit.Visual.Opacity.prototype.update */
update: function (position) {
MochiKit.Style.setOpacity(this.element, position);
MochiKit.Style.setStyle(this.element, {'opacity': position});
}
});
/** @id MochiKit.Visual.Opacity.prototype.Move */
/** @id MochiKit.Visual.Move.prototype */
MochiKit.Visual.Move = function (element, options) {
var cls = arguments.callee;
if (!(this instanceof cls)) {
......@@ -1176,16 +1176,16 @@ MochiKit.Visual.fade = function (element, /* optional */ options) {
***/
var s = MochiKit.Style;
var oldOpacity = MochiKit.DOM.getElement(element).style.opacity || '';
var oldOpacity = s.getStyle(element, 'opacity');
options = MochiKit.Base.update({
from: s.getOpacity(element) || 1.0,
from: s.getStyle(element, 'opacity') || 1.0,
to: 0.0,
afterFinishInternal: function (effect) {
if (effect.options.to !== 0) {
return;
}
s.hideElement(effect.element);
s.setStyle(effect.element, {opacity: oldOpacity});
s.setStyle(effect.element, {'opacity': oldOpacity});
}
}, options || {});
return new MochiKit.Visual.Opacity(element, options);
......@@ -1204,14 +1204,14 @@ MochiKit.Visual.appear = function (element, /* optional */ options) {
var v = MochiKit.Visual;
options = MochiKit.Base.update({
from: (s.getStyle(element, 'display') == 'none' ? 0.0 :
s.getOpacity(element) || 0.0),
s.getStyle(element, 'opacity') || 0.0),
to: 1.0,
// force Safari to render floated elements properly
afterFinishInternal: function (effect) {
v.forceRerendering(effect.element);
},
beforeSetupInternal: function (effect) {
s.setOpacity(effect.element, effect.options.from);
s.setStyle(effect.element, {'opacity': effect.options.from});
s.showElement(effect.element);
}
}, options || {});
......@@ -1229,12 +1229,12 @@ MochiKit.Visual.puff = function (element, /* optional */ options) {
var v = MochiKit.Visual;
element = MochiKit.DOM.getElement(element);
var oldStyle = {
opacity: element.style.opacity || '',
position: s.getStyle(element, 'position'),
top: element.style.top,
left: element.style.left,
width: element.style.width,
height: element.style.height
height: element.style.height,
opacity: s.getStyle(element, 'opacity')
};
options = MochiKit.Base.update({
beforeSetupInternal: function (effect) {
......@@ -1316,7 +1316,7 @@ MochiKit.Visual.switchOff = function (element, /* optional */ options) {
***/
var d = MochiKit.DOM;
<