bgneal@425: $(document).ready(function() { bgneal@425: $tabs = $('#tabs').tabs({ bgneal@425: selected: initialTab, bgneal@425: select: function(event, ui) { bgneal@425: $(ui.panel).html(''); bgneal@425: }, bgneal@425: load: function(event, ui) { bgneal@425: selectedTab = ui; bgneal@425: if (doReply && ui.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@425: } bgneal@425: }, bgneal@425: ajaxOptions: { bgneal@425: 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@425: } bgneal@425: } bgneal@425: }); bgneal@425: $msgDialog = $('#msgDialog').dialog({ bgneal@425: autoOpen: false, bgneal@425: width: 460, bgneal@425: buttons: [ bgneal@425: { bgneal@425: text: "Reply", bgneal@425: click: function() { bgneal@425: doReply = true; bgneal@425: $(this).dialog('close'); bgneal@425: $tabs.tabs("select", 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@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@425: if (username == msg.receiver) { bgneal@425: $(link).removeClass('unread'); bgneal@425: } bgneal@425: bgneal@425: $msgDialog.html(msg.content); bgneal@425: 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@425: url: '/messages/beta/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@425: url: '/messages/beta/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@425: url: '/messages/beta/compose-tab/', bgneal@425: type: 'POST', bgneal@425: data: $(form).serialize(), bgneal@425: dataType: 'html', bgneal@425: success: function (data, textStatus) { bgneal@425: $('#ui-tabs-1').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@425: url: '/messages/beta/bulk/', bgneal@425: type: 'POST', bgneal@425: data: $(form).serialize(), bgneal@425: dataType: 'text', bgneal@425: success: function (data, textStatus) { bgneal@425: $tabs.tabs("load", selectedTab.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: }