forked from mozilla/kitsune
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored Report Abuse to eliminate duplication.
- Loading branch information
Showing
6 changed files
with
88 additions
and
225 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Report abuse UI. | ||
*/ | ||
|
||
(function($) { | ||
|
||
"use strict"; | ||
|
||
k.ReportAbuse = { | ||
init: function(options) { | ||
options = $.extend({ | ||
selector: 'form.report input[type="submit"]' | ||
}, options); | ||
|
||
// Click handler | ||
$(options.selector).click(function(ev){ | ||
ev.preventDefault(); | ||
var $form = $(this).closest('form'); | ||
$('div.report-post-box').remove(); | ||
|
||
// Build up the HTML for the kbox popup | ||
var html = '<section class="report-post-box">' + | ||
'<ul class="wrap"></ul></section>', | ||
$html = $(html), | ||
$ul = $html.find('ul'), | ||
kbox = new KBox($html, { | ||
title: gettext('Report this post'), | ||
position: 'none', | ||
container: $form, | ||
closeOnOutClick: true | ||
}); | ||
$form.find('select option').each(function(){ | ||
var $this = $(this), | ||
$li = $('<li><a href="#"></a></li>'), | ||
$a = $li.find('a'); | ||
$a.attr('data-val', $this.attr('value')).text($this.text()); | ||
$ul.append($li); | ||
}); | ||
$ul.append('<li><input type="text" class="text" ' + | ||
'name="modal-other"/></li>'); | ||
|
||
// Selection click handlers | ||
$html.find('ul a').click(function(ev){ | ||
ev.preventDefault(); | ||
$form.find('select').val($(this).data('val')); | ||
var other = $html.find('input[name="modal-other"]').val(); | ||
$form.find('input[name="other"]').val(other); | ||
$.ajax({ | ||
url: $form.attr('action'), | ||
type: 'POST', | ||
data: $form.serialize(), | ||
dataType: 'json', | ||
success: function(data) { | ||
var $msg = $('<div class="msg"></div>'); | ||
$msg.text(data.message); | ||
$html.find('ul').replaceWith($msg); | ||
}, | ||
error: function() { | ||
var message = gettext("There was an error."), | ||
$msg = $('<div class="msg"></div>'); | ||
$msg.text(data.message); | ||
$html.find('ul').replaceWith($msg); | ||
} | ||
}); | ||
|
||
return false; | ||
}); | ||
|
||
kbox.open(); | ||
}); | ||
} | ||
}; | ||
|
||
$(document).ready(k.ReportAbuse.init); | ||
|
||
})(jQuery); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters