annotate messages/static/js/tabbed_messages.js @ 693:ad69236e8501

For issue #52, update many 3rd party Javascript libraries. Updated to jquery 1.10.2, jquery ui 1.10.3. This broke a lot of stuff. - Found a newer version of the jquery cycle all plugin (3.0.3). - Updated JPlayer to 2.4.0. - Updated to MarkItUp 1.1.14. This also required me to add multiline attributes set to true on various buttons in the markdown set. - As per a stackoverflow post, added some code to get multiline titles in a jQuery UI dialog. They removed that functionality but allow you to put it back. Tweaked the MarkItUp preview CSS to show blockquotes in italic. Did not update TinyMCE at this time. I'm not using the JQuery version and this version appears to work ok for now. What I should do is make a repo for MarkItUp and do a vendor branch thing so I don't have to futz around diffing directories to figure out if I'll lose changes when I update.
author Brian Neal <bgneal@gmail.com>
date Wed, 04 Sep 2013 19:55:20 -0500
parents ee87ea74d46b
children efb525863a75
rev   line source
bgneal@425 1 $(document).ready(function() {
bgneal@693 2
bgneal@693 3 // allow HTML in title for 1.10
bgneal@693 4 $.widget("ui.dialog", $.extend({}, $.ui.dialog.prototype, {
bgneal@693 5 _title: function(title) {
bgneal@693 6 if (!this.options.title ) {
bgneal@693 7 title.html("&#160;");
bgneal@693 8 } else {
bgneal@693 9 title.html(this.options.title);
bgneal@693 10 }
bgneal@693 11 }
bgneal@693 12 }));
bgneal@693 13
bgneal@425 14 $tabs = $('#tabs').tabs({
bgneal@425 15 selected: initialTab,
bgneal@425 16 select: function(event, ui) {
bgneal@425 17 $(ui.panel).html('');
bgneal@425 18 },
bgneal@425 19 load: function(event, ui) {
bgneal@425 20 selectedTab = ui;
bgneal@428 21 if (ui.index == 1 && receiver && !doReply)
bgneal@428 22 {
bgneal@428 23 $('#id_receiver').val(receiver);
bgneal@428 24 receiver = '';
bgneal@428 25 }
bgneal@428 26 else if (doReply && ui.index == 1)
bgneal@425 27 {
bgneal@425 28 doReply = false;
bgneal@425 29 var msg = msgCache[$msgDialog.msgId];
bgneal@425 30 $('#id_receiver').val(msg.sender);
bgneal@425 31 $('#id_subject').val(msg.re_subject);
bgneal@425 32 $('#id_message').val(msg.re_content);
bgneal@430 33 $('#msg_compose_form').append('<input type="hidden" name="reply_to" value="' +
bgneal@430 34 $msgDialog.msgId + '" />');
bgneal@425 35 }
bgneal@425 36 },
bgneal@425 37 ajaxOptions: {
bgneal@425 38 error: function(xhr, status, index, anchor) {
bgneal@425 39 $(anchor.hash).html(
bgneal@425 40 "Oops, we couldn't load this tab. We'll try to fix this as soon as possible.");
bgneal@425 41 }
bgneal@425 42 }
bgneal@425 43 });
bgneal@425 44 $msgDialog = $('#msgDialog').dialog({
bgneal@425 45 autoOpen: false,
bgneal@425 46 width: 460,
bgneal@481 47 height: 'auto',
bgneal@481 48 maxHeight: false,
bgneal@481 49 resizable: false,
bgneal@425 50 buttons: [
bgneal@425 51 {
bgneal@425 52 text: "Reply",
bgneal@425 53 click: function() {
bgneal@425 54 doReply = true;
bgneal@425 55 $(this).dialog('close');
bgneal@425 56 $tabs.tabs("select", 1);
bgneal@425 57 }
bgneal@425 58 },
bgneal@425 59 {
bgneal@425 60 text: "Close",
bgneal@425 61 click: function() {
bgneal@425 62 $(this).dialog('close');
bgneal@425 63 }
bgneal@425 64 }
bgneal@425 65 ]
bgneal@425 66 });
bgneal@425 67 });
bgneal@425 68
bgneal@425 69 var $tabs = 0;
bgneal@425 70 var $msgDialog = 0;
bgneal@425 71 var msgCache = {};
bgneal@425 72 var doReply = false;
bgneal@425 73 var selectedTab = 0;
bgneal@425 74
bgneal@429 75 function updateUnreadMsgText(n)
bgneal@429 76 {
bgneal@429 77 var txt = '';
bgneal@429 78 if (n == 1) {
bgneal@429 79 txt = "1 New Message";
bgneal@429 80 }
bgneal@429 81 else if (n > 1) {
bgneal@429 82 txt = n + " New Messages";
bgneal@429 83 }
bgneal@429 84 else {
bgneal@429 85 txt = "Private Messages";
bgneal@429 86 }
bgneal@429 87 $('#unread_msg_text').html(txt);
bgneal@429 88 }
bgneal@429 89
bgneal@425 90 function showMsg(link, id) {
bgneal@425 91 $msgDialog.msgId = id; // create a msgId attribute on the dialog
bgneal@425 92 var msg = msgCache[id];
bgneal@425 93
bgneal@425 94 // mark as read if necessary
bgneal@429 95 var $link = $(link);
bgneal@429 96
bgneal@429 97 if (username == msg.receiver && $link.hasClass('unread')) {
bgneal@425 98 $(link).removeClass('unread');
bgneal@429 99
bgneal@429 100 // decrement count of unread messages in base template
bgneal@429 101 if (unreadMsgCount > 0)
bgneal@429 102 {
bgneal@429 103 updateUnreadMsgText(--unreadMsgCount);
bgneal@429 104 }
bgneal@425 105 }
bgneal@425 106
bgneal@481 107 var s = '<div style="max-height:450px;overflow:auto">' + msg.content + '</div>';
bgneal@481 108 $msgDialog.html(s);
bgneal@693 109 var title = 'PM From ' + msg.sender + ' To ' + msg.receiver + '<br />' + msg.subject;
bgneal@425 110 $msgDialog.dialog('option', 'title', title);
bgneal@425 111 $msgDialog.dialog('open');
bgneal@425 112 }
bgneal@425 113
bgneal@425 114 function msgShow(link, id) {
bgneal@425 115 if (msgCache[id]) {
bgneal@425 116 showMsg(link, id);
bgneal@425 117 return;
bgneal@425 118 }
bgneal@425 119 $.ajax({
bgneal@429 120 url: '/messages/message/',
bgneal@425 121 type: 'POST',
bgneal@425 122 data: {
bgneal@425 123 msg_id : id
bgneal@425 124 },
bgneal@425 125 dataType: 'json',
bgneal@425 126 success: function (data, textStatus) {
bgneal@425 127 msgCache[id] = data;
bgneal@425 128 showMsg(link, id);
bgneal@425 129 },
bgneal@425 130 error: function (xhr, textStatus, ex) {
bgneal@425 131 alert('Oops, an error occurred. ' + xhr.statusText + ' - ' +
bgneal@425 132 xhr.responseText);
bgneal@425 133 }
bgneal@425 134 });
bgneal@425 135 }
bgneal@425 136
bgneal@425 137 function submitOptions(form) {
bgneal@425 138 $.ajax({
bgneal@429 139 url: '/messages/options-tab/',
bgneal@425 140 type: 'POST',
bgneal@425 141 data: $(form).serialize(),
bgneal@425 142 dataType: 'html',
bgneal@425 143 success: function (data, textStatus) {
bgneal@425 144 $(selectedTab.panel).html(data);
bgneal@425 145 },
bgneal@425 146 error: function (xhr, textStatus, ex) {
bgneal@425 147 alert('Oops, an error occurred. ' + xhr.statusText + ' - ' +
bgneal@425 148 xhr.responseText);
bgneal@425 149 }
bgneal@425 150 });
bgneal@425 151 return false;
bgneal@425 152 }
bgneal@425 153
bgneal@425 154 function messageSubmit(form) {
bgneal@425 155 $.ajax({
bgneal@429 156 url: '/messages/compose-tab/',
bgneal@425 157 type: 'POST',
bgneal@425 158 data: $(form).serialize(),
bgneal@425 159 dataType: 'html',
bgneal@425 160 success: function (data, textStatus) {
bgneal@430 161 $(selectedTab.panel).html(data);
bgneal@425 162 },
bgneal@425 163 error: function (xhr, textStatus, ex) {
bgneal@425 164 alert('Oops, an error occurred. ' + xhr.statusText + ' - ' +
bgneal@425 165 xhr.responseText);
bgneal@425 166 }
bgneal@425 167 });
bgneal@425 168 return false;
bgneal@425 169 }
bgneal@425 170
bgneal@425 171 function tabMasterCheckClick(box, name) {
bgneal@425 172 var state = $(box).attr('checked');
bgneal@425 173 $('input[name="' + name + '"]').each(function() {
bgneal@425 174 this.checked = state;
bgneal@425 175 });
bgneal@425 176 }
bgneal@425 177
bgneal@425 178 function bulkMsgAction(form, action) {
bgneal@425 179 if (confirm("Really " + action + " checked messages?")) {
bgneal@425 180 $.ajax({
bgneal@429 181 url: '/messages/bulk/',
bgneal@425 182 type: 'POST',
bgneal@425 183 data: $(form).serialize(),
bgneal@425 184 dataType: 'text',
bgneal@425 185 success: function (data, textStatus) {
bgneal@425 186 $tabs.tabs("load", selectedTab.index);
bgneal@425 187 },
bgneal@425 188 error: function (xhr, textStatus, ex) {
bgneal@425 189 alert('Oops, an error occurred. ' + xhr.statusText + ' - ' +
bgneal@425 190 xhr.responseText);
bgneal@425 191 }
bgneal@425 192 });
bgneal@425 193 }
bgneal@425 194 return false;
bgneal@425 195 }
bgneal@425 196
bgneal@425 197 function ajaxPageFetch(link) {
bgneal@425 198 $.ajax({
bgneal@425 199 url: link.href,
bgneal@425 200 type: 'GET',
bgneal@425 201 dataType: 'html',
bgneal@425 202 success: function (data, textStatus) {
bgneal@425 203 $(selectedTab.panel).html(data);
bgneal@425 204 },
bgneal@425 205 error: function (xhr, textStatus, ex) {
bgneal@425 206 alert('Oops, an error occurred. ' + xhr.statusText + ' - ' +
bgneal@425 207 xhr.responseText);
bgneal@425 208 }
bgneal@425 209 });
bgneal@425 210 return false;
bgneal@425 211 }