aboutsummaryrefslogtreecommitdiff
path: root/public
diff options
context:
space:
mode:
Diffstat (limited to 'public')
-rw-r--r--public/css/hebrewparsetrainer.css4
-rw-r--r--public/js/alerts.js11
-rw-r--r--public/js/moderators.js39
3 files changed, 53 insertions, 1 deletions
diff --git a/public/css/hebrewparsetrainer.css b/public/css/hebrewparsetrainer.css
index 30ef258..6e35fe8 100644
--- a/public/css/hebrewparsetrainer.css
+++ b/public/css/hebrewparsetrainer.css
@@ -37,6 +37,10 @@ body {
vertical-align: middle !important;
}
+.suggestions td.vote-cell {
+ width: 30px;
+}
+
#trainer-404 {
display: none;
padding: 15px;
diff --git a/public/js/alerts.js b/public/js/alerts.js
new file mode 100644
index 0000000..c1763ed
--- /dev/null
+++ b/public/js/alerts.js
@@ -0,0 +1,11 @@
+$.fn.addAlert = function (kind, message) {
+ var box = '<div class="alert alert-' + kind + ' alert-dismissible" role="alert">' +
+ '<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>' +
+ message + '</div>';
+
+ $(this).find('.alerts').append($(box));
+}
+
+$.fn.clearAlerts = function () {
+ $(this).find('.alerts').html('');
+}
diff --git a/public/js/moderators.js b/public/js/moderators.js
index 2b192f8..1a61075 100644
--- a/public/js/moderators.js
+++ b/public/js/moderators.js
@@ -20,10 +20,17 @@ $(document).ready(function(){
var vote = parseInt($(this).data('vote'));
var verbId = $(this).data('verb');
- var container = $(this).parent();
+ var container = $(this).closest('tr');
+
+ var fail = function(msg) {
+ alert('Voting failed with the message: "' + msg + '". Please try again.');
+ }
$.ajax({
url: app_url + 'verb/' + verbId + '/vote/' + vote,
+ error: function(jqxhr, stat, error) {
+ fail(stat);
+ },
success: function(data) {
if (!data.success) {
fail(data.message);
@@ -54,4 +61,34 @@ $(document).ready(function(){
return true;
});
+
+ $('form#suggest').submit(function(){
+ var data = $(this).serialize();
+ var form = $(this);
+
+ form.clearAlerts();
+
+ $.ajax({
+ url: app_url + 'verb/suggest',
+ method: 'post',
+ data: data,
+ error: function(jqxhr, stat, error) {
+ form.addAlert('danger', stat);
+ },
+ success: function(data) {
+ if (!data.success) {
+ form.addAlert('danger', data.message);
+ return;
+ }
+
+ if (data.accepted) {
+ form.addAlert('success', 'The new verb has been <b>accepted immediately</b>.');
+ } else {
+ form.addAlert('success', 'The new verb has been proposed for peer review.');
+ }
+ }
+ });
+
+ return false;
+ });
});