17
17
var lp_client = new Y.lp.client.Launchpad();
20
* XXX: rvb 2011-08-01 bug=796669: At present this module it is
21
* function-passing spaghetti. The duct-tape is getting frayed.
22
* It ought to be recomposed as widgets or something a bit more objecty so
23
* it can be unit tested without having to set-up the world each time.
20
27
* Setup the expandable rows for each difference.
22
29
* @method setup_expandable_rows
24
31
namespace.setup_expandable_rows = function() {
26
var blacklist_handler = function(e, dsd_link, source_name) {
33
var blacklist_handler = function(e, dsd_link, source_name,
34
latest_comment_container,
35
add_comment_placeholder) {
27
36
// We only want to select the new radio if the update is
29
38
e.preventDefault();
30
39
var blacklist_options_container = this.ancestor('div');
32
// Disable all the inputs
40
blacklist_comment_overlay(
41
e, dsd_link, source_name, latest_comment_container,
42
add_comment_placeholder, blacklist_options_container);
45
var blacklist_comment_overlay = function(e, dsd_link, source_name,
46
latest_comment_container,
47
add_comment_placeholder,
48
blacklist_options_container) {
49
var comment_form = Y.Node.create("<form />")
50
.appendChild(Y.Node.create("<textarea />")
51
.set("name", "comment")
56
var submit_button = Y.Node.create(
57
'<button type="submit" class="lazr-pos lazr-btn" />')
59
var cancel_button = Y.Node.create(
60
'<button type="button" class="lazr-neg lazr-btn" />')
61
.set("text", "Cancel");
63
var submit_callback = function(data) {
66
if (data.comment !== undefined) {
67
comment = data.comment[0];
69
blacklist_submit_handler(
70
e, dsd_link, source_name, comment, latest_comment_container,
71
add_comment_placeholder, blacklist_options_container);
74
var origin = blacklist_options_container.one('.blacklist-options');
75
var overlay = new Y.lazr.FormOverlay({
77
/* Align the centre of the overlay with the centre of the
78
node containing the blacklist options. */
81
Y.WidgetPositionAlign.CC,
82
Y.WidgetPositionAlign.CC
85
headerContent: "<h2>Add an optional comment</h2>",
86
form_content: comment_form,
87
form_submit_button: submit_button,
88
form_cancel_button: cancel_button,
89
form_submit_callback: submit_callback,
95
var blacklist_submit_handler = function(e, dsd_link, source_name,
96
comment, latest_comment_container,
97
add_comment_placeholder,
98
blacklist_options_container) {
99
// Disable all the inputs.
33
100
blacklist_options_container.all('input').set('disabled', 'disabled');
34
101
e.target.prepend('<img src="/@@/spinner" />');
81
152
* @param blacklist_options {Node} The node containing the blacklist
83
154
* @param source_name {string} The name of the source to update.
155
* @param dsd_link {string} The uri for the distroseriesdifference object.
156
* @param latest_comment_container {Node} The node containing the last
158
* @param add_comment_placeholder {Node} The node containing the "add
85
161
var setup_blacklist_options = function(
86
blacklist_options, source_name, dsd_link) {
162
blacklist_options, source_name, dsd_link, latest_comment_container,
163
add_comment_placeholder) {
87
164
Y.on('click', blacklist_handler, blacklist_options.all('input'),
88
blacklist_options, dsd_link, source_name);
165
blacklist_options, dsd_link, source_name,
166
latest_comment_container, add_comment_placeholder);
121
* Handle the add comment event.
198
* This method adds a comment in the UI. It appends a comment to the
199
* list of comments and updates the latest comments slot.
201
* @param comment_entry {Comment} A comment as returns by the api.
202
* @param add_comment_placeholder {Node} The node that contains the
203
* relevant comment fields.
204
* @param latest_comment_placeholder {Node} The node that contains the
207
var add_comment = function(comment_entry, add_comment_placeholder,
208
latest_comment_placeholder) {
209
// Grab the XHTML representation of the comment
210
// and prepend it to the list of comments.
213
success: function(comment_html) {
214
var comment_node = Y.Node.create(comment_html);
215
add_comment_placeholder.insert(comment_node, 'before');
216
var reveal = Y.lazr.effects.slide_out(comment_node);
217
reveal.on("end", function() {
218
Y.lp.anim.green_flash(
219
{node: comment_node}).run();
224
accept: Y.lp.client.XHTML
226
lp_client.get(comment_entry.get('self_link'), config);
227
update_latest_comment(comment_entry, latest_comment_placeholder);
231
* Handle the add comment event triggered by the 'add comment' form.
123
233
* This method adds a comment via the API and update the UI.
125
235
* @param comment_form {Node} The node that contains the relevant comment
237
* @param latest_comment_placeholder {Node} The node that contains the
127
239
* @param api_uri {string} The uri for the distroseriesdifference to which
128
* the comment is to be added.
130
* @param cb_success {function}
131
* Called when a comment has successfully been added. (Deferreds would
132
* be awesome right about now.)
240
* the comment is to be added.
241
* @param cb_success {function} Called when a comment has successfully
242
* been added. (Deferreds would be awesome right about now.)
134
244
var add_comment_handler = function(
135
245
comment_form, latest_comment_placeholder, api_uri, cb_success) {
146
256
var success_handler = function(comment_entry) {
147
// Grab the XHTML representation of the comment
148
// and prepend it to the list of comments.
151
success: function(comment_html) {
152
var comment_node = Y.Node.create(comment_html);
153
comment_form.insert(comment_node, 'before');
154
var reveal = Y.lazr.effects.slide_out(comment_node);
155
reveal.on("end", function() {
156
Y.lp.anim.green_flash(
157
{node: comment_node}).run();
162
accept: Y.lp.client.XHTML
164
lp_client.get(comment_entry.get('self_link'), config);
258
comment_entry, comment_form, latest_comment_placeholder);
165
259
comment_form.one('textarea').set('value', '');
166
update_latest_comment(comment_entry, latest_comment_placeholder);
169
262
var failure_handler = function(id, response) {
294
387
parent_distro_name,
295
388
parent_series_name
390
var latest_comment_container =
391
args.master_container.one('td.latest-comment-fragment');
392
// The add comment slot is only available when the user has the
393
// right to add comments.
394
var add_comment_placeholder =
395
args.container.one('div.add-comment-placeholder');
396
if (add_comment_placeholder !== null) {
398
add_comment_placeholder,
399
latest_comment_container,
297
402
// The blacklist slot with a class 'blacklist-options' is only
298
403
// available when the user has the right to blacklist.
299
404
var blacklist_slot = args.container.one('div.blacklist-options');
300
405
if (blacklist_slot !== null) {
301
setup_blacklist_options(blacklist_slot, source_name, api_uri);
406
setup_blacklist_options(
407
blacklist_slot, source_name, api_uri,
408
latest_comment_container,
409
add_comment_placeholder);
303
411
// If the user has not the right to blacklist, we disable
304
412
// the blacklist slot.
308
416
disabled_blacklist_slot
309
417
.all('input').set('disabled', 'disabled');
311
// The add comment slot is only available when the user has the
312
// right to add comments.
313
var add_comment_placeholder =
314
args.container.one('div.add-comment-placeholder');
315
if (add_comment_placeholder !== null) {
317
add_comment_placeholder,
318
args.master_container.one('td.latest-comment-fragment'),
321
419
// Set-up diffs and the means to request them.
322
420
namespace.setup_packages_diff_states(args.container, api_uri);