bgneal@425: $(document).ready(function() { bgneal@693: bgneal@693: // allow HTML in title for 1.10 bgneal@693: $.widget("ui.dialog", $.extend({}, $.ui.dialog.prototype, { bgneal@693: _title: function(title) { bgneal@693: if (!this.options.title ) { bgneal@693: title.html(" "); bgneal@693: } else { bgneal@693: title.html(this.options.title); bgneal@693: } bgneal@693: } bgneal@693: })); bgneal@693: bgneal@425: $tabs = $('#tabs').tabs({ bgneal@698: active: initialTab, bgneal@698: activate: function(event, ui) { bgneal@425: $(ui.panel).html(''); bgneal@425: }, bgneal@425: load: function(event, ui) { bgneal@425: selectedTab = ui; bgneal@711: bgneal@711: if (ui.tab.index() == 1 && receiver && !doReply) bgneal@711: { bgneal@711: $('#id_receiver').val(receiver); bgneal@711: receiver = ''; bgneal@711: } bgneal@711: else if (doReply && ui.tab.index() == 1) bgneal@425: { bgneal@425: doReply = false; bgneal@425: var msg = msgCache[$msgDialog.msgId]; bgneal@425: $('#id_receiver').val(msg.sender); bgneal@425: $('#id_subject').val(msg.re_subject); bgneal@425: $('#id_message').val(msg.re_content); bgneal@430: $('#msg_compose_form').append(''); bgneal@425: } bgneal@425: }, bgneal@698: beforeLoad: function(event, ui) { bgneal@698: ui.jqXHR.error(function(xhr, status, index, anchor) { bgneal@425: $(anchor.hash).html( bgneal@425: "Oops, we couldn't load this tab. We'll try to fix this as soon as possible."); bgneal@698: }); bgneal@425: } bgneal@425: }); bgneal@425: $msgDialog = $('#msgDialog').dialog({ bgneal@425: autoOpen: false, bgneal@425: width: 460, bgneal@481: height: 'auto', bgneal@481: maxHeight: false, bgneal@481: resizable: false, bgneal@425: buttons: [ bgneal@425: { bgneal@425: text: "Reply", bgneal@425: click: function() { bgneal@425: doReply = true; bgneal@425: $(this).dialog('close'); bgneal@698: $tabs.tabs("option", "active", 1); bgneal@425: } bgneal@425: }, bgneal@425: { bgneal@425: text: "Close", bgneal@425: click: function() { bgneal@425: $(this).dialog('close'); bgneal@425: } bgneal@425: } bgneal@425: ] bgneal@425: }); bgneal@425: }); bgneal@425: bgneal@425: var $tabs = 0; bgneal@425: var $msgDialog = 0; bgneal@425: var msgCache = {}; bgneal@425: var doReply = false; bgneal@425: var selectedTab = 0; bgneal@425: bgneal@429: function updateUnreadMsgText(n) bgneal@429: { bgneal@429: var txt = ''; bgneal@429: if (n == 1) { bgneal@429: txt = "1 New Message"; bgneal@429: } bgneal@429: else if (n > 1) { bgneal@429: txt = n + " New Messages"; bgneal@429: } bgneal@429: else { bgneal@429: txt = "Private Messages"; bgneal@429: } bgneal@429: $('#unread_msg_text').html(txt); bgneal@429: } bgneal@429: bgneal@425: function showMsg(link, id) { bgneal@425: $msgDialog.msgId = id; // create a msgId attribute on the dialog bgneal@425: var msg = msgCache[id]; bgneal@425: bgneal@425: // mark as read if necessary bgneal@429: var $link = $(link); bgneal@429: bgneal@429: if (username == msg.receiver && $link.hasClass('unread')) { bgneal@425: $(link).removeClass('unread'); bgneal@429: bgneal@429: // decrement count of unread messages in base template bgneal@429: if (unreadMsgCount > 0) bgneal@429: { bgneal@429: updateUnreadMsgText(--unreadMsgCount); bgneal@429: } bgneal@425: } bgneal@425: bgneal@481: var s = '
' + msg.content + '
'; bgneal@481: $msgDialog.html(s); bgneal@693: var title = 'PM From ' + msg.sender + ' To ' + msg.receiver + '
' + msg.subject; bgneal@425: $msgDialog.dialog('option', 'title', title); bgneal@425: $msgDialog.dialog('open'); bgneal@425: } bgneal@425: bgneal@425: function msgShow(link, id) { bgneal@425: if (msgCache[id]) { bgneal@425: showMsg(link, id); bgneal@425: return; bgneal@425: } bgneal@425: $.ajax({ bgneal@429: url: '/messages/message/', bgneal@425: type: 'POST', bgneal@425: data: { bgneal@425: msg_id : id bgneal@425: }, bgneal@425: dataType: 'json', bgneal@425: success: function (data, textStatus) { bgneal@425: msgCache[id] = data; bgneal@425: showMsg(link, id); bgneal@425: }, bgneal@425: error: function (xhr, textStatus, ex) { bgneal@425: alert('Oops, an error occurred. ' + xhr.statusText + ' - ' + bgneal@425: xhr.responseText); bgneal@425: } bgneal@425: }); bgneal@425: } bgneal@425: bgneal@425: function submitOptions(form) { bgneal@425: $.ajax({ bgneal@429: url: '/messages/options-tab/', bgneal@425: type: 'POST', bgneal@425: data: $(form).serialize(), bgneal@425: dataType: 'html', bgneal@425: success: function (data, textStatus) { bgneal@425: $(selectedTab.panel).html(data); bgneal@425: }, bgneal@425: error: function (xhr, textStatus, ex) { bgneal@425: alert('Oops, an error occurred. ' + xhr.statusText + ' - ' + bgneal@425: xhr.responseText); bgneal@425: } bgneal@425: }); bgneal@425: return false; bgneal@425: } bgneal@425: bgneal@425: function messageSubmit(form) { bgneal@425: $.ajax({ bgneal@429: url: '/messages/compose-tab/', bgneal@425: type: 'POST', bgneal@425: data: $(form).serialize(), bgneal@425: dataType: 'html', bgneal@425: success: function (data, textStatus) { bgneal@430: $(selectedTab.panel).html(data); bgneal@425: }, bgneal@425: error: function (xhr, textStatus, ex) { bgneal@425: alert('Oops, an error occurred. ' + xhr.statusText + ' - ' + bgneal@425: xhr.responseText); bgneal@425: } bgneal@425: }); bgneal@425: return false; bgneal@425: } bgneal@425: bgneal@425: function tabMasterCheckClick(box, name) { bgneal@425: var state = $(box).attr('checked'); bgneal@425: $('input[name="' + name + '"]').each(function() { bgneal@425: this.checked = state; bgneal@425: }); bgneal@425: } bgneal@425: bgneal@425: function bulkMsgAction(form, action) { bgneal@425: if (confirm("Really " + action + " checked messages?")) { bgneal@425: $.ajax({ bgneal@429: url: '/messages/bulk/', bgneal@425: type: 'POST', bgneal@425: data: $(form).serialize(), bgneal@425: dataType: 'text', bgneal@425: success: function (data, textStatus) { bgneal@698: $tabs.tabs("load", selectedTab.tab.index()); bgneal@425: }, bgneal@425: error: function (xhr, textStatus, ex) { bgneal@425: alert('Oops, an error occurred. ' + xhr.statusText + ' - ' + bgneal@425: xhr.responseText); bgneal@425: } bgneal@425: }); bgneal@425: } bgneal@425: return false; bgneal@425: } bgneal@425: bgneal@425: function ajaxPageFetch(link) { bgneal@425: $.ajax({ bgneal@425: url: link.href, bgneal@425: type: 'GET', bgneal@425: dataType: 'html', bgneal@425: success: function (data, textStatus) { bgneal@425: $(selectedTab.panel).html(data); bgneal@425: }, bgneal@425: error: function (xhr, textStatus, ex) { bgneal@425: alert('Oops, an error occurred. ' + xhr.statusText + ' - ' + bgneal@425: xhr.responseText); bgneal@425: } bgneal@425: }); bgneal@425: return false; bgneal@425: }