1
/* Copyright 2011 Canonical Ltd. This software is licensed under the
2
* GNU Affero General Public License version 3 (see the file LICENSE).
4
* @namespace Y.lp.comments.hide
5
* @requires dom, node, lazr.anim, lp.client
7
YUI.add('lp.comments.hide', function(Y) {
8
var namespace = Y.namespace('lp.comments.hide');
10
var hidden_class = "adminHiddenComment";
11
var hide_text = "Hide comment";
12
var unhide_text = "Unhide comment";
14
function update_comment(link, comment) {
15
var text = link.get('text').trim();
16
if (text === hide_text) {
17
comment.removeClass(hidden_class);
18
link.set('text', unhide_text);
20
comment.addClass(hidden_class);
21
link.set('text', hide_text);
25
function set_visibility(parameters, callbacks) {
26
// comment_context must be setup on pages using this js, and is the
27
// context for a comment (e.g. bug).
28
var comment_context = LP.cache.comment_context;
29
var lp_client = new Y.lp.client.Launchpad();
32
success: callbacks.success,
33
failure: callbacks.failure
35
parameters: parameters
38
comment_context.self_link, 'setCommentVisibility', config);
41
function toggle_hidden(link) {
42
var comment = link.get('parentNode').get('parentNode');
43
var visible = comment.hasClass('adminHiddenComment');
44
var comment_number = parseInt(
45
link.get('id').replace('mark-spam-', ''), 10);
48
comment_number: comment_number
50
set_visibility(parameters, {
51
// We use red flash on failure so admins know it didn't work.
52
// There's no green flash on success, b/c the change in bg
53
// color provides an immediate visual cue.
54
success: function () {
55
update_comment(link, comment);
56
comment.toggleClass(hidden_class);
58
failure: function () {
59
Y.lazr.anim.red_flash({node:comment});
63
namespace.toggle_hidden = toggle_hidden;
65
function setup_hide_controls() {
66
Y.on('click', function(e) {
68
namespace.toggle_hidden(this);
71
namespace.setup_hide_controls = setup_hide_controls;
72
}, "0.1", {"requires": ["dom", "node", "lazr.anim", "lp.client"]});