bgneal@89: $(document).ready(function() { bgneal@89: var postText = $('#id_body'); bgneal@89: var postButton = $('#forums-reply-post'); bgneal@89: postButton.click(function () { bgneal@89: var text = $.trim(postText.val()); bgneal@89: $(this).attr('disabled', 'disabled').val('Posting reply...'); bgneal@285: bgneal@285: var attachments = new Array() bgneal@285: $('#attachment div input').each(function(index) { bgneal@285: attachments[index] = $(this).val(); bgneal@285: }); bgneal@285: bgneal@89: $.ajax({ bgneal@89: url: '/forums/quick-reply/', bgneal@89: type: 'POST', bgneal@89: data: { bgneal@285: body : postText.val(), bgneal@285: topic_id : $('#id_topic_id').val(), bgneal@285: attachment : attachments bgneal@89: }, bgneal@285: traditional: true, bgneal@89: dataType: 'html', bgneal@89: success: function (data, textStatus) { bgneal@89: postText.val(''); bgneal@89: $('#forum-topic tr:last').after(data); bgneal@89: var lastTr = $('#forum-topic tr:last'); bgneal@89: lastTr.hide(); bgneal@89: lastTr.fadeIn(3000); bgneal@89: postButton.removeAttr('disabled').val('Submit Reply'); bgneal@285: initAttachments(); bgneal@89: }, bgneal@89: error: function (xhr, textStatus, ex) { bgneal@108: alert('Oops, an error occurred. ' + xhr.statusText + ' - ' + bgneal@108: xhr.responseText); bgneal@89: postButton.removeAttr('disabled').val('Submit Reply'); bgneal@285: initAttachments(); bgneal@89: } bgneal@89: }); bgneal@89: return false; bgneal@89: }); bgneal@98: $('a.post-flag').click(function () { bgneal@98: var id = this.id; bgneal@107: if (id.match(/fp-(\d+)/)) { bgneal@98: id = RegExp.$1; bgneal@98: if (confirm('Only flag a post if you feel it is spam, abuse, violates site rules, ' + bgneal@98: 'or is not appropriate. ' + bgneal@98: 'A moderator will be notified and will review the post. ' + bgneal@98: 'Are you sure you want to flag this post?')) { bgneal@99: $.ajax({ bgneal@99: url: '/forums/flag-post/', bgneal@99: type: 'POST', bgneal@99: data: {id: id}, bgneal@99: dataType: 'text', bgneal@99: success: function (response, textStatus) { bgneal@99: alert(response); bgneal@99: }, bgneal@99: error: function (xhr, textStatus, ex) { bgneal@99: alert('Oops, an error occurred: ' + xhr.statusText + ' - ' + xhr.responseText); bgneal@99: } bgneal@99: }); bgneal@98: } bgneal@98: } bgneal@98: return false; bgneal@98: }); bgneal@107: $('a.post-delete').click(function () { bgneal@107: var id = this.id; bgneal@107: if (id.match(/dp-(\d+)/)) { bgneal@107: id = RegExp.$1; bgneal@107: if (confirm('Are you sure you want to delete this post?')) { bgneal@107: $.ajax({ bgneal@107: url: '/forums/delete-post/', bgneal@107: type: 'POST', bgneal@107: data: {id: id}, bgneal@107: dataType: 'text', bgneal@107: success: function (response, textStatus) { bgneal@107: alert(response); bgneal@107: $('#post-' + id).fadeOut(3000); bgneal@107: }, bgneal@107: error: function (xhr, textStatus, ex) { bgneal@107: alert('Oops, an error occurred: ' + xhr.statusText + ' - ' + xhr.responseText); bgneal@107: } bgneal@107: }); bgneal@107: } bgneal@107: } bgneal@107: return false; bgneal@107: }); bgneal@109: $('#forum-mod-del-topic').click(function () { bgneal@109: return confirm('Are you sure you want to delete this topic?\n' + bgneal@109: 'WARNING: all posts will be lost.'); bgneal@109: }); bgneal@285: bgneal@285: var vid = 0; bgneal@285: var vidDiv = $('#attachment'); bgneal@285: bgneal@285: function clearAttachments() bgneal@285: { bgneal@285: $('#attachment div').remove(); bgneal@285: $('#attach-another').remove(); bgneal@285: } bgneal@285: bgneal@286: function processEmbeds(data, textStatus) bgneal@286: { bgneal@286: vidDiv.find('img').remove(); bgneal@286: $.each(data, function(index, value) { bgneal@286: var html = '
' + value.html + bgneal@286: '' + bgneal@286: 'Remove ' + bgneal@286: 'Remove' + bgneal@286: ''; bgneal@286: '
'; bgneal@286: vidDiv.append(html); bgneal@286: $('#video-' + index + ' a').click(function() { bgneal@286: $('#video-' + index).remove(); bgneal@286: relabelAttachLink(); bgneal@286: return false; bgneal@286: }); bgneal@286: }); bgneal@286: vid = data.length; bgneal@286: $('#video-' + (vid-1)).after('Attach another video'); bgneal@286: $('#attach-another').click(function() { bgneal@286: addVideo(); bgneal@286: relabelAttachLink(); bgneal@286: return false; bgneal@286: }); bgneal@286: } bgneal@286: bgneal@285: function initAttachments() bgneal@285: { bgneal@285: clearAttachments(); bgneal@285: bgneal@286: var post_input = $('#id_post_id'); bgneal@286: var attachments = $("#forums_post_form input:hidden[name='attachment']"); bgneal@285: if (post_input.length == 1) bgneal@285: { bgneal@285: post_id = post_input.val(); bgneal@286: vidDiv.prepend('Busy'); bgneal@285: $.ajax({ bgneal@285: url: '/forums/fetch_attachments/', bgneal@285: type: 'GET', bgneal@285: data: { bgneal@285: pid : post_id bgneal@285: }, bgneal@285: dataType: 'json', bgneal@286: success: processEmbeds, bgneal@286: error: function (xhr, textStatus, ex) { bgneal@286: vidDiv.find('img').remove(); bgneal@286: alert('Oops, an error occurred. ' + xhr.statusText + ' - ' + bgneal@286: xhr.responseText); bgneal@286: } bgneal@286: }); bgneal@286: } bgneal@286: else if (attachments.length > 0) bgneal@286: { bgneal@286: vidDiv.prepend('Busy'); bgneal@286: var embeds = new Array(); bgneal@286: attachments.each(function(index) { bgneal@286: embeds[index] = $(this).val(); bgneal@286: }); bgneal@286: attachments.remove(); bgneal@286: $.ajax({ bgneal@286: url: '/oembed/fetch_saved/', bgneal@286: type: 'GET', bgneal@286: data: { bgneal@286: embeds: embeds bgneal@285: }, bgneal@286: traditional: true, bgneal@286: dataType: 'json', bgneal@286: success: processEmbeds, bgneal@285: error: function (xhr, textStatus, ex) { bgneal@286: vidDiv.find('img').remove(); bgneal@285: alert('Oops, an error occurred. ' + xhr.statusText + ' - ' + bgneal@285: xhr.responseText); bgneal@285: } bgneal@285: }); bgneal@285: } bgneal@285: else bgneal@285: { bgneal@285: vid = 0; bgneal@285: var s = '
' + bgneal@285: 'Add ' + bgneal@285: 'Attach Video
'; bgneal@285: vidDiv.prepend(s); bgneal@285: $('#attachment a').click(function () { bgneal@285: $('#init-add').remove(); bgneal@285: addVideo(); bgneal@285: return false; bgneal@285: }); bgneal@285: } bgneal@285: } bgneal@285: bgneal@285: function relabelAttachLink() bgneal@285: { bgneal@285: var another = $('#attach-another'); bgneal@285: var n = $('#attachment div').length; bgneal@285: if (n == 0) bgneal@285: { bgneal@285: another.html("Attach a video"); bgneal@285: } bgneal@285: else bgneal@285: { bgneal@285: another.html("Attach another video"); bgneal@285: } bgneal@285: } bgneal@285: bgneal@285: function addVideo() bgneal@285: { bgneal@285: var id = "video-" + vid; bgneal@285: bgneal@285: var fakeForm = '
' + bgneal@285: 'Attach ' + bgneal@285: ' ' + bgneal@285: 'Remove
'; bgneal@285: bgneal@285: var n = $('#attachment div').length; bgneal@285: bgneal@285: var another = $('#attach-another'); bgneal@285: if (n == 0) bgneal@285: { bgneal@285: if (another.length > 0) bgneal@285: { bgneal@285: another.before(fakeForm); bgneal@285: } bgneal@285: else bgneal@285: { bgneal@285: vidDiv.append(fakeForm); bgneal@285: } bgneal@285: } bgneal@285: else bgneal@285: { bgneal@285: $('#attachment div:last').after(fakeForm); bgneal@285: } bgneal@285: bgneal@285: $('#' + id + ' a').click(function() { bgneal@285: $('#' + id).remove(); bgneal@285: relabelAttachLink(); bgneal@285: return false; bgneal@285: }); bgneal@285: bgneal@285: var vidText = $('#' + id + ' input'); bgneal@285: bgneal@285: $('#' + id + ' button').click(function() { bgneal@286: var button = $(this); bgneal@286: button.attr('disabled', 'disabled'); bgneal@285: $.ajax({ bgneal@285: url: '/oembed/fetch/', bgneal@285: type: 'POST', bgneal@285: data: { bgneal@285: q : vidText.val() bgneal@285: }, bgneal@285: dataType: 'json', bgneal@285: success: function (data, textStatus) { bgneal@285: $('#' + id + " .r").remove(); bgneal@285: var myDiv = $('#' + id); bgneal@285: var html = '' + bgneal@285: 'Remove ' + bgneal@285: 'Remove' + bgneal@285: ''; bgneal@285: myDiv.prepend(html); bgneal@285: myDiv.prepend(data.embed); bgneal@285: $('#' + id + ' a').click(function() { bgneal@285: myDiv.remove(); bgneal@285: relabelAttachLink(); bgneal@285: return false; bgneal@285: }); bgneal@285: }, bgneal@285: error: function (xhr, textStatus, ex) { bgneal@285: alert('Oops, an error occurred. ' + xhr.statusText + ' - ' + bgneal@285: xhr.responseText); bgneal@286: button.removeAttr('disabled'); bgneal@285: } bgneal@285: }); bgneal@285: }); bgneal@285: bgneal@285: if (vid == 0) bgneal@285: { bgneal@285: $('#video-0').after('Attach another video'); bgneal@285: $('#attach-another').click(function() { bgneal@285: addVideo(); bgneal@285: relabelAttachLink(); bgneal@285: return false; bgneal@285: }); bgneal@285: } bgneal@285: ++vid; bgneal@285: } bgneal@285: bgneal@285: initAttachments(); bgneal@89: });