From 15b26b8b2af028ea30dc34f78ed5c6f3fcb0d547 Mon Sep 17 00:00:00 2001
From: Camil Staps
Date: Mon, 5 Sep 2016 23:43:35 +0200
Subject: Suggest new verbs
---
public/css/hebrewparsetrainer.css | 4 ++++
public/js/alerts.js | 11 +++++++++++
public/js/moderators.js | 39 ++++++++++++++++++++++++++++++++++++++-
3 files changed, 53 insertions(+), 1 deletion(-)
create mode 100644 public/js/alerts.js
(limited to 'public')
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 = '
' +
+ '' +
+ message + '
';
+
+ $(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 accepted immediately.');
+ } else {
+ form.addAlert('success', 'The new verb has been proposed for peer review.');
+ }
+ }
+ });
+
+ return false;
+ });
});
--
cgit v1.2.3