annotate messages/static/js/tabbed_messages.js @ 698:efb525863a75

jQuery UI Tabs were changed quite a bit, which broke private messages. Here is a fix. Upgrade notes are found here: http://jqueryui.com/upgrade-guide/1.9/#tabs
author Brian Neal <bgneal@gmail.com>
date Mon, 09 Sep 2013 20:30:13 -0500
parents ad69236e8501
children c09ed90c891b
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@698 15 active: initialTab,
bgneal@698 16 activate: 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@698 21 if (doReply && ui.tab.index() == 1)
bgneal@425 22 {
bgneal@425 23 doReply = false;
bgneal@425 24 var msg = msgCache[$msgDialog.msgId];
bgneal@425 25 $('#id_receiver').val(msg.sender);
bgneal@425 26 $('#id_subject').val(msg.re_subject);
bgneal@425 27 $('#id_message').val(msg.re_content);
bgneal@430 28 $('#msg_compose_form').append('<input type="hidden" name="reply_to" value="' +
bgneal@430 29 $msgDialog.msgId + '" />');
bgneal@425 30 }
bgneal@425 31 },
bgneal@698 32 beforeLoad: function(event, ui) {
bgneal@698 33 ui.jqXHR.error(function(xhr, status, index, anchor) {
bgneal@425 34 $(anchor.hash).html(
bgneal@425 35 "Oops, we couldn't load this tab. We'll try to fix this as soon as possible.");
bgneal@698 36 });
bgneal@425 37 }
bgneal@425 38 });
bgneal@425 39 $msgDialog = $('#msgDialog').dialog({
bgneal@425 40 autoOpen: false,
bgneal@425 41 width: 460,
bgneal@481 42 height: 'auto',
bgneal@481 43 maxHeight: false,
bgneal@481 44 resizable: false,
bgneal@425 45 buttons: [
bgneal@425 46 {
bgneal@425 47 text: "Reply",
bgneal@425 48 click: function() {
bgneal@425 49 doReply = true;
bgneal@425 50 $(this).dialog('close');
bgneal@698 51 $tabs.tabs("option", "active", 1);
bgneal@425 52 }
bgneal@425 53 },
bgneal@425 54 {
bgneal@425 55 text: "Close",
bgneal@425 56 click: function() {
bgneal@425 57 $(this).dialog('close');
bgneal@425 58 }
bgneal@425 59 }
bgneal@425 60 ]
bgneal@425 61 });
bgneal@425 62 });
bgneal@425 63
bgneal@425 64 var $tabs = 0;
bgneal@425 65 var $msgDialog = 0;
bgneal@425 66 var msgCache = {};
bgneal@425 67 var doReply = false;
bgneal@425 68 var selectedTab = 0;
bgneal@425 69
bgneal@429 70 function updateUnreadMsgText(n)
bgneal@429 71 {
bgneal@429 72 var txt = '';
bgneal@429 73 if (n == 1) {
bgneal@429 74 txt = "1 New Message";
bgneal@429 75 }
bgneal@429 76 else if (n > 1) {
bgneal@429 77 txt = n + " New Messages";
bgneal@429 78 }
bgneal@429 79 else {
bgneal@429 80 txt = "Private Messages";
bgneal@429 81 }
bgneal@429 82 $('#unread_msg_text').html(txt);
bgneal@429 83 }
bgneal@429 84
bgneal@425 85 function showMsg(link, id) {
bgneal@425 86 $msgDialog.msgId = id; // create a msgId attribute on the dialog
bgneal@425 87 var msg = msgCache[id];
bgneal@425 88
bgneal@425 89 // mark as read if necessary
bgneal@429 90 var $link = $(link);
bgneal@429 91
bgneal@429 92 if (username == msg.receiver && $link.hasClass('unread')) {
bgneal@425 93 $(link).removeClass('unread');
bgneal@429 94
bgneal@429 95 // decrement count of unread messages in base template
bgneal@429 96 if (unreadMsgCount > 0)
bgneal@429 97 {
bgneal@429 98 updateUnreadMsgText(--unreadMsgCount);
bgneal@429 99 }
bgneal@425 100 }
bgneal@425 101
bgneal@481 102 var s = '<div style="max-height:450px;overflow:auto">' + msg.content + '</div>';
bgneal@481 103 $msgDialog.html(s);
bgneal@693 104 var title = 'PM From ' + msg.sender + ' To ' + msg.receiver + '<br />' + msg.subject;
bgneal@425 105 $msgDialog.dialog('option', 'title', title);
bgneal@425 106 $msgDialog.dialog('open');
bgneal@425 107 }
bgneal@425 108
bgneal@425 109 function msgShow(link, id) {
bgneal@425 110 if (msgCache[id]) {
bgneal@425 111 showMsg(link, id);
bgneal@425 112 return;
bgneal@425 113 }
bgneal@425 114 $.ajax({
bgneal@429 115 url: '/messages/message/',
bgneal@425 116 type: 'POST',
bgneal@425 117 data: {
bgneal@425 118 msg_id : id
bgneal@425 119 },
bgneal@425 120 dataType: 'json',
bgneal@425 121 success: function (data, textStatus) {
bgneal@425 122 msgCache[id] = data;
bgneal@425 123 showMsg(link, id);
bgneal@425 124 },
bgneal@425 125 error: function (xhr, textStatus, ex) {
bgneal@425 126 alert('Oops, an error occurred. ' + xhr.statusText + ' - ' +
bgneal@425 127 xhr.responseText);
bgneal@425 128 }
bgneal@425 129 });
bgneal@425 130 }
bgneal@425 131
bgneal@425 132 function submitOptions(form) {
bgneal@425 133 $.ajax({
bgneal@429 134 url: '/messages/options-tab/',
bgneal@425 135 type: 'POST',
bgneal@425 136 data: $(form).serialize(),
bgneal@425 137 dataType: 'html',
bgneal@425 138 success: function (data, textStatus) {
bgneal@425 139 $(selectedTab.panel).html(data);
bgneal@425 140 },
bgneal@425 141 error: function (xhr, textStatus, ex) {
bgneal@425 142 alert('Oops, an error occurred. ' + xhr.statusText + ' - ' +
bgneal@425 143 xhr.responseText);
bgneal@425 144 }
bgneal@425 145 });
bgneal@425 146 return false;
bgneal@425 147 }
bgneal@425 148
bgneal@425 149 function messageSubmit(form) {
bgneal@425 150 $.ajax({
bgneal@429 151 url: '/messages/compose-tab/',
bgneal@425 152 type: 'POST',
bgneal@425 153 data: $(form).serialize(),
bgneal@425 154 dataType: 'html',
bgneal@425 155 success: function (data, textStatus) {
bgneal@430 156 $(selectedTab.panel).html(data);
bgneal@425 157 },
bgneal@425 158 error: function (xhr, textStatus, ex) {
bgneal@425 159 alert('Oops, an error occurred. ' + xhr.statusText + ' - ' +
bgneal@425 160 xhr.responseText);
bgneal@425 161 }
bgneal@425 162 });
bgneal@425 163 return false;
bgneal@425 164 }
bgneal@425 165
bgneal@425 166 function tabMasterCheckClick(box, name) {
bgneal@425 167 var state = $(box).attr('checked');
bgneal@425 168 $('input[name="' + name + '"]').each(function() {
bgneal@425 169 this.checked = state;
bgneal@425 170 });
bgneal@425 171 }
bgneal@425 172
bgneal@425 173 function bulkMsgAction(form, action) {
bgneal@425 174 if (confirm("Really " + action + " checked messages?")) {
bgneal@425 175 $.ajax({
bgneal@429 176 url: '/messages/bulk/',
bgneal@425 177 type: 'POST',
bgneal@425 178 data: $(form).serialize(),
bgneal@425 179 dataType: 'text',
bgneal@425 180 success: function (data, textStatus) {
bgneal@698 181 $tabs.tabs("load", selectedTab.tab.index());
bgneal@425 182 },
bgneal@425 183 error: function (xhr, textStatus, ex) {
bgneal@425 184 alert('Oops, an error occurred. ' + xhr.statusText + ' - ' +
bgneal@425 185 xhr.responseText);
bgneal@425 186 }
bgneal@425 187 });
bgneal@425 188 }
bgneal@425 189 return false;
bgneal@425 190 }
bgneal@425 191
bgneal@425 192 function ajaxPageFetch(link) {
bgneal@425 193 $.ajax({
bgneal@425 194 url: link.href,
bgneal@425 195 type: 'GET',
bgneal@425 196 dataType: 'html',
bgneal@425 197 success: function (data, textStatus) {
bgneal@425 198 $(selectedTab.panel).html(data);
bgneal@425 199 },
bgneal@425 200 error: function (xhr, textStatus, ex) {
bgneal@425 201 alert('Oops, an error occurred. ' + xhr.statusText + ' - ' +
bgneal@425 202 xhr.responseText);
bgneal@425 203 }
bgneal@425 204 });
bgneal@425 205 return false;
bgneal@425 206 }