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

Remove ' + bgneal@1166: '

' + bgneal@1166: '
'; bgneal@312: myDiv.prepend(html); bgneal@312: $('#' + id + ' a').click(function() { bgneal@312: myDiv.remove(); bgneal@312: relabelAttachLink(); bgneal@312: return false; bgneal@312: }); bgneal@312: }, bgneal@312: error: function (xhr, textStatus, ex) { bgneal@673: alert('Oops, an error occurred. ' + xhr.statusText + ' - ' + bgneal@312: xhr.responseText); bgneal@312: button.removeAttr('disabled'); bgneal@312: } bgneal@312: }); bgneal@312: }); bgneal@312: bgneal@312: if (vid == 0) bgneal@312: { bgneal@312: $('#video-0').after('Attach another video'); bgneal@312: $('#attach-another').click(function() { bgneal@312: addVideo(); bgneal@312: relabelAttachLink(); bgneal@312: return false; bgneal@312: }); bgneal@312: } bgneal@312: ++vid; bgneal@312: } bgneal@312: bgneal@312: initAttachments(); bgneal@673: bgneal@673: var topicTitle = $('#id_name'); bgneal@673: var topicSearchButton = $('#search_topics'); bgneal@673: var searchBusy = $('#search-busy-icon'); bgneal@673: topicSearchButton.click(function () { bgneal@673: var text = $.trim(topicTitle.val()); bgneal@673: if (!text) return; bgneal@673: bgneal@673: $(this).attr('disabled', 'disabled'); bgneal@673: $('#quick-search-results').remove(); bgneal@673: searchBusy.toggle(); bgneal@673: bgneal@673: $.ajax({ bgneal@673: url: '/search/ajax/', bgneal@673: type: 'GET', bgneal@673: data: { bgneal@673: q : text, bgneal@673: models : 'forums.topic' bgneal@673: }, bgneal@673: traditional: true, bgneal@673: dataType: 'html', bgneal@673: success: function (data, textStatus) { bgneal@673: topicSearchButton.removeAttr('disabled'); bgneal@673: searchBusy.hide(); bgneal@673: searchBusy.after(data); bgneal@673: $('#hide-search-results').click(function() { bgneal@673: var results = $('#quick-search-results'); bgneal@673: results.fadeOut(1500, function() { results.remove(); }); bgneal@673: }); bgneal@673: }, bgneal@673: error: function (xhr, textStatus, ex) { bgneal@673: topicSearchButton.removeAttr('disabled'); bgneal@673: searchBusy.hide(); bgneal@673: alert('Oops, an error occurred. ' + xhr.statusText + ' - ' + bgneal@673: xhr.responseText); bgneal@673: } bgneal@673: }); bgneal@673: return false; bgneal@673: }); bgneal@312: });