Better thread watcher list update on un/watch.

This commit is contained in:
Nicolas Stepien 2011-05-04 01:52:04 +02:00
parent 6584da2a68
commit fa2ebec87a
2 changed files with 38 additions and 11 deletions

View File

@ -1496,6 +1496,28 @@
}
return _results;
},
list: function(watched) {
var board, div, id, props, _results;
div = $('#watcher > div:not(.move)');
while (div) {
$.remove(div);
div = $('#watcher > div:not(.move)');
}
_results = [];
for (board in watched) {
_results.push((function() {
var _ref, _results;
_ref = watched[board];
_results = [];
for (id in _ref) {
props = _ref[id];
_results.push(watcher.addLink(props, $('#watcher')));
}
return _results;
})());
}
return _results;
},
addLink: function(props, dialog) {
var div, link, x;
dialog || (dialog = $('#watcher'));
@ -1529,17 +1551,15 @@
}
},
unwatch: function(board, id) {
var div, favicon, href, input, watched;
href = "/" + board + "/res/" + id;
div = $("#watcher a[href=\"" + href + "\"]").parentNode;
$.remove(div);
var favicon, input, watched;
if (input = $("input[name=\"" + id + "\"]")) {
favicon = input.previousSibling;
favicon.src = Favicon.empty;
}
watched = $.getValue('watched', {});
delete watched[board][id];
return $.setValue('watched', watched);
$.setValue('watched', watched);
return watcher.list(watched);
},
watch: function(thread) {
var favicon, id, props, tc, watched, _name;
@ -1558,7 +1578,7 @@
watched[_name = g.BOARD] || (watched[_name] = {});
watched[g.BOARD][id] = props;
$.setValue('watched', watched);
return watcher.addLink(props);
return watcher.list(watched);
}
};
anonymize = {

View File

@ -1184,6 +1184,15 @@ watcher =
$.bind favicon, 'click', watcher.cb.toggle
$.before input, favicon
list: (watched) ->
div = $ '#watcher > div:not(.move)'
while div
$.remove div
div = $ '#watcher > div:not(.move)'
for board of watched
for id, props of watched[board]
watcher.addLink props, $ '#watcher'
addLink: (props, dialog) ->
dialog or= $ '#watcher'
div = $.el 'div'
@ -1212,10 +1221,6 @@ watcher =
watcher.unwatch g.BOARD, id
unwatch: (board, id) ->
href = "/#{board}/res/#{id}"
div = $("#watcher a[href=\"#{href}\"]").parentNode
$.remove div
if input = $ "input[name=\"#{id}\"]"
favicon = input.previousSibling
favicon.src = Favicon.empty
@ -1224,6 +1229,8 @@ watcher =
delete watched[board][id]
$.setValue 'watched', watched
watcher.list watched
watch: (thread) ->
favicon = $ 'img.favicon', thread
return if favicon.src is Favicon.default
@ -1240,7 +1247,7 @@ watcher =
watched[g.BOARD][id] = props
$.setValue 'watched', watched
watcher.addLink props
watcher.list watched
anonymize =
init: ->