|
26 | 26 | removeVote: $('.removevote'), |
27 | 27 | status: $('#status'), |
28 | 28 | successVoted: $('.successvoted'), |
| 29 | + userVoted: $('.user-voted'), |
29 | 30 | votes: $('.votes'), |
30 | 31 | votesList: $('.voteslist'), |
31 | | - voteDown: $('.minivotedown'), |
32 | | - voteUp: $('.minivoteup'), |
| 32 | + voteDown: $('.vote-down'), |
| 33 | + voteUp: $('.vote-up'), |
33 | 34 | voteRemove: $('#vote-remove') |
34 | | - }; |
| 35 | + }, $loadingIndicator; |
35 | 36 |
|
36 | 37 | function voteSuccess(result, $this) { |
37 | 38 | if (typeof result === 'string') { |
38 | 39 | phpbb.alert($this.attr('data-l-err'), $this.attr('data-l-msg') + ' ' + result); |
39 | 40 | } else { |
40 | | - $obj.voteUp.first().html('<span>' + result.votes_up + '</span>'); |
41 | | - $obj.voteDown.first().html('<span>' + result.votes_down + '</span>'); |
| 41 | + $obj.voteUp.find('.vote-count').text(result.votes_up); |
| 42 | + $obj.voteDown.find('.vote-count').text(result.votes_down); |
42 | 43 | $obj.votes.hide().text(function() { |
43 | 44 | return result.points + ' ' + $(this).attr('data-l-msg'); |
44 | 45 | }); |
|
69 | 70 |
|
70 | 71 | var $this = $(this), |
71 | 72 | url = $this.attr('href'), |
72 | | - vote = $this.is('.voteup') ? 1 : 0; |
| 73 | + vote = $this.is($obj.voteUp) ? 1 : 0; |
73 | 74 |
|
74 | | - if ($this.is('.dead')) { |
| 75 | + if ($this.hasClass('vote-disabled')) { |
75 | 76 | return false; |
76 | 77 | } |
77 | 78 |
|
| 79 | + showLoadingIndicator(); |
78 | 80 | $.get(url, {v: vote}, function(data) { |
79 | 81 | voteSuccess(data, $this); |
80 | 82 | resetVoteButtons($this); |
81 | 83 | $obj.voteRemove.show(); |
82 | | - }).fail(voteFailure); |
| 84 | + }).fail(voteFailure).always(hideLoadingIndicator); |
83 | 85 | }); |
84 | 86 |
|
85 | 87 | $obj.votes.on('click', function(e) { |
|
96 | 98 | var $this = $(this), |
97 | 99 | url = $this.attr('href'); |
98 | 100 |
|
99 | | - if ($this.is('.dead')) { |
| 101 | + if ($this.hasClass('vote-disabled')) { |
100 | 102 | return false; |
101 | 103 | } |
102 | 104 |
|
| 105 | + showLoadingIndicator(); |
103 | 106 | $.get(url, function(data) { |
104 | 107 | voteSuccess(data, $this); |
105 | 108 | resetVoteButtons(); |
106 | 109 | $obj.voteRemove.hide(); |
107 | | - }).fail(voteFailure); |
| 110 | + }).fail(voteFailure).always(hideLoadingIndicator); |
108 | 111 | }); |
109 | 112 |
|
110 | 113 | $obj.status.on('change', function() { |
|
118 | 121 | return; |
119 | 122 | } |
120 | 123 |
|
| 124 | + showLoadingIndicator(); |
121 | 125 | $.get($this.attr('data-url'), data, function(res) { |
122 | 126 | if (res) { |
123 | 127 | var anchor = $this.prev('a'), |
|
133 | 137 | $obj.duplicateToggle.toggle(idea_is_duplicate()); |
134 | 138 | $obj.implementedToggle.toggle(idea_is_implemented()); |
135 | 139 | } |
136 | | - }); |
| 140 | + }).always(hideLoadingIndicator); |
137 | 141 | }); |
138 | 142 |
|
139 | 143 | $obj.rfcEdit.on('click', function(e) { |
|
158 | 162 | return; |
159 | 163 | } |
160 | 164 |
|
| 165 | + showLoadingIndicator(); |
161 | 166 | $.get(url, {rfc: value}, function(res) { |
162 | 167 | if (res) { |
163 | 168 | $obj.rfcLink.text(value) |
|
171 | 176 |
|
172 | 177 | $obj.rfcEdit.toggleAddEdit(value); |
173 | 178 | } |
174 | | - }); |
| 179 | + }).always(hideLoadingIndicator); |
175 | 180 | } else if (e.keyCode === keymap.ESC) { |
176 | 181 | e.preventDefault(); |
177 | 182 |
|
|
212 | 217 | value = 'PHPBB3-' + info[1]; |
213 | 218 | } |
214 | 219 |
|
| 220 | + showLoadingIndicator(); |
215 | 221 | $.get(url, {ticket: value && info[1]}, function(res) { |
216 | 222 | if (res) { |
217 | 223 | $obj.ticketLink.text(value) |
|
226 | 232 | $obj.ticketEdit.toggleAddEdit(value); |
227 | 233 | } |
228 | 234 |
|
229 | | - }); |
| 235 | + }).always(hideLoadingIndicator); |
230 | 236 | } else if (e.keyCode === keymap.ESC) { |
231 | 237 | e.preventDefault(); |
232 | 238 |
|
|
262 | 268 | return; |
263 | 269 | } |
264 | 270 |
|
| 271 | + showLoadingIndicator(); |
265 | 272 | $.get(url, {duplicate: Number(value)}, function(res) { |
266 | 273 | if (res) { |
267 | 274 | if (value) { |
|
282 | 289 |
|
283 | 290 | $obj.duplicateEdit.toggleAddEdit(value); |
284 | 291 | } |
285 | | - }); |
| 292 | + }).always(hideLoadingIndicator); |
286 | 293 | } else if (e.keyCode === keymap.ESC) { |
287 | 294 | e.preventDefault(); |
288 | 295 |
|
|
319 | 326 | return; |
320 | 327 | } |
321 | 328 |
|
| 329 | + showLoadingIndicator(); |
322 | 330 | $.get(url, {implemented: value}, function(res) { |
323 | 331 | if (res) { |
324 | 332 | $obj.implementedVersion.text(value); |
|
331 | 339 |
|
332 | 340 | $obj.implementedEdit.toggleAddEdit(value); |
333 | 341 | } |
334 | | - }); |
| 342 | + }).always(hideLoadingIndicator); |
335 | 343 | } else if (e.keyCode === keymap.ESC) { |
336 | 344 | e.preventDefault(); |
337 | 345 |
|
|
347 | 355 | $.fn.toggleAddEdit = function(value) { |
348 | 356 | $(this).text(function() { |
349 | 357 | return value ? $(this).attr('data-l-edit') : $(this).attr('data-l-add'); |
350 | | - }).prepend($('<i class="fa fa-fw"></i>').addClass(function() { |
| 358 | + }).prepend($('<i class="icon fa-fw"></i>').addClass(function() { |
351 | 359 | return value ? 'fa-pencil' : 'fa-plus-circle'; |
352 | 360 | })).show(); |
353 | 361 | }; |
|
399 | 407 | } |
400 | 408 |
|
401 | 409 | function resetVoteButtons($this) { |
402 | | - $obj.voteUp.add($obj.voteDown).removeClass('dead'); |
| 410 | + $obj.voteUp.add($obj.voteDown).removeClass('vote-disabled'); |
| 411 | + $obj.userVoted.hide(); |
| 412 | + |
403 | 413 | if ($this) { |
404 | | - $this.addClass('dead'); |
| 414 | + $this.addClass('vote-disabled').find($obj.userVoted).show(); |
| 415 | + } |
| 416 | + } |
| 417 | + |
| 418 | + function showLoadingIndicator() { |
| 419 | + $loadingIndicator = phpbb.loadingIndicator(); |
| 420 | + } |
| 421 | + |
| 422 | + function hideLoadingIndicator() { |
| 423 | + if ($loadingIndicator && $loadingIndicator.is(':visible')) { |
| 424 | + $loadingIndicator.fadeOut(phpbb.alertTime); |
405 | 425 | } |
406 | 426 | } |
407 | 427 |
|
|
0 commit comments