X-Git-Url: https://git.openstreetmap.org./osqa.git/blobdiff_plain/c579fa70d5febab89dcb5b3811ed8d926127bff1..0fa0566b62e7ac7fe389821e48bba5507758c4df:/forum/skins/default/media/js/osqa.main.js
diff --git a/forum/skins/default/media/js/osqa.main.js b/forum/skins/default/media/js/osqa.main.js
index 2de5ecf..993407b 100644
--- a/forum/skins/default/media/js/osqa.main.js
+++ b/forum/skins/default/media/js/osqa.main.js
@@ -1,3 +1,29 @@
+/**
+ * We do not want the CSRF protection enabled for the AJAX post requests, it causes only trouble.
+ * Get the csrftoken cookie and pass it to the X-CSRFToken HTTP request property.
+ */
+$('html').ajaxSend(function(event, xhr, settings) {
+ function getCookie(name) {
+ var cookieValue = null;
+ if (document.cookie && document.cookie != '') {
+ var cookies = document.cookie.split(';');
+ for (var i = 0; i < cookies.length; i++) {
+ var cookie = jQuery.trim(cookies[i]);
+ // Does this cookie string begin with the name we want?
+ if (cookie.substring(0, name.length + 1) == (name + '=')) {
+ cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
+ break;
+ }
+ }
+ }
+ return cookieValue;
+ }
+ if (!(/^http:.*/.test(settings.url) || /^https:.*/.test(settings.url))) {
+ // Only send the token to relative URLs i.e. locally.
+ xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));
+ }
+});
+
var response_commands = {
refresh_page: function() {
window.location.reload(true)
@@ -75,7 +101,7 @@ var response_commands = {
alert('ok');
},
- insert_comment: function(post_id, comment_id, comment, username, profile_url, delete_url, edit_url, convert_url) {
+ insert_comment: function(post_id, comment_id, comment, username, profile_url, delete_url, edit_url, convert_url, can_convert) {
var $container = $('#comments-container-' + post_id);
var skeleton = $('#new-comment-skeleton-' + post_id).html().toString();
@@ -89,6 +115,11 @@ var response_commands = {
$container.append(skeleton);
+ // Show the convert comment to answer tool only if the current comment can be converted
+ if (can_convert == true) {
+ $('#comment-' + comment_id + '-convert').show();
+ }
+
$('#comment-' + comment_id).slideDown('slow');
},
@@ -128,7 +159,6 @@ var response_commands = {
},
copy_url: function(url) {
- $.copy(url);
}
}
@@ -150,11 +180,17 @@ function show_dialog (extern) {
yes_callback: default_close_function,
no_text: messages.cancel,
show_no: false,
- close_on_clickoutside: false
+ close_on_clickoutside: false,
+ copy: false
}
$.extend(options, extern);
+ var copy_id = '';
+ if (options.copy) {
+ copy_id = ' id="copy_clip_button"'
+ }
+
if (options.event != undefined) {
options.pos = {x: options.event.pageX, y: options.event.pageY};
}
@@ -166,8 +202,7 @@ function show_dialog (extern) {
html += '';
}
- html += ''
- + '';
+ html += '' + '';
$dialog = $(html);
$('body').append($dialog);
@@ -273,7 +308,12 @@ function load_prompt(evt, el, url) {
process_ajax_response(data, evt);
}, 'json');
},
- show_no: true
+ show_no: true,
+ copy: false
+ }
+
+ if (el.hasClass('copy')) {
+ $.extend(doptions, { yes_text : 'Copy', copy: true});
}
if (!el.is('.centered')) {
@@ -532,7 +572,7 @@ $(function() {
}
start_command();
- $.post($form.attr('action'), post_data, function(data) {
+ $.post($form.attr('action'), $form.serialize(), function(data) {
process_ajax_response(data, evt, function(error) {
if (!error) {
cleanup_form();