92
* Toggle the spinner and enable/disable comment fields.
94
* @param comment_form {Node} The node that contains the relevant
97
var toggle_comment_in_progress = function(comment_form) {
98
var spinner = comment_form.one('img');
99
if (Y.Lang.isNull(spinner)) {
100
comment_form.one('div.widget-bd').append(
101
'<img src="/@@/spinner" />');
102
comment_form.all('textarea,button').set(
103
'disabled', 'disabled');
105
comment_form.one('img').remove();
106
comment_form.all('textarea,button').set(
112
92
* Handle the add comment event.
114
94
* This method adds a comment via the API and update the UI.
118
98
* @param api_uri {string} The uri for the distroseriesdifference to which
119
99
* the comment is to be added.
101
* @param cb_success {function}
102
* Called when a comment has successfully been added. (Deferreds would
103
* be awesome right about now.)
121
var add_comment_handler = function(comment_form, api_uri) {
123
var comment_text = comment_form.one('textarea').get('value');
125
toggle_comment_in_progress(comment_form);
105
var add_comment_handler = function(comment_form, api_uri, cb_success) {
107
var comment_area = comment_form.one('textarea');
108
var comment_text = comment_area.get('value');
110
// Treat empty comments as mistakes.
111
if (Y.Lang.trim(comment_text).length == 0) {
112
Y.lazr.anim.red_flash({node: comment_area}).run();
127
116
var success_handler = function(comment_entry) {
128
117
// Grab the XHTML representation of the comment
132
121
success: function(comment_html) {
133
comment_node = Y.Node.create(comment_html);
122
var comment_node = Y.Node.create(comment_html);
134
123
comment_form.insert(comment_node, 'before');
135
var anim = Y.lazr.anim.green_flash({
124
var reveal = Y.lazr.effects.slide_out(comment_node);
125
reveal.on("end", function() {
126
Y.lazr.anim.green_flash(
127
{node: comment_node}).run();
141
132
accept: Y.lp.client.XHTML
143
134
lp_client.get(comment_entry.get('self_link'), config);
144
135
comment_form.one('textarea').set('value', '');
145
toggle_comment_in_progress(comment_form);
147
138
var failure_handler = function(id, response) {
148
139
// Re-enable field with red flash.
149
toggle_comment_in_progress(comment_form);
150
var anim = Y.lazr.anim.red_flash({
140
Y.lazr.anim.red_flash({node: comment_form}).run();
158
145
success: success_handler,
159
failure: failure_handler
146
failure: failure_handler,
149
comment_form.one('div.widget-bd')
150
.append('<img src="/@@/spinner" />');
151
// Disable the textarea and button.
152
comment_form.all('textarea,button')
153
.setAttribute('disabled', 'disabled');
156
// Remove the spinner.
157
comment_form.all('img').remove();
159
comment_form.all('textarea,button')
160
.removeAttribute('disabled');
162
164
comment: comment_text
165
167
lp_client.named_post(api_uri, 'addComment', config);
189
191
// The comment area should slide in when the 'Add comment'
190
192
// action is clicked.
192
placeholder.one('a.widget-hd').on('click', function(e) {
195
slide = Y.lazr.effects.slide_out(
193
var slide_anim = null;
194
var slide = function(direction) {
195
// Slide out if direction is true, slide in if direction
196
// is false, otherwise do the opposite of what's being
197
// animated right now.
198
if (slide_anim === null) {
199
slide_anim = Y.lazr.effects.slide_out(
196
200
placeholder.one('div.widget-bd'));
198
slide.set('reverse', !slide.get('reverse'));
201
if (Y.Lang.isBoolean(direction)) {
202
slide_anim.set("reverse", !direction);
206
if (Y.Lang.isBoolean(direction)) {
207
slide_anim.set("reverse", !direction);
210
slide_anim.set('reverse', !slide_anim.get('reverse'));
216
var slide_out = function() { slide(false); };
218
placeholder.one('a.widget-hd').on(
219
'click', function(e) { e.preventDefault(); slide(); });
204
221
placeholder.one('button').on('click', function(e) {
205
222
e.preventDefault();
206
add_comment_handler(placeholder, api_uri);
223
add_comment_handler(placeholder, api_uri, slide_out);