annotate gpp/messages/static/js/tabbed_messages.js @ 428:77b3b01843b5

Gave the beta private messages a 'compose to' view. Tweaked the color of the tables to match the jquery ui theme.
author Brian Neal <bgneal@gmail.com>
date Sun, 01 May 2011 02:11:48 +0000
parents 76ba9478ebbd
children d0f0800eef0c
rev   line source
bgneal@425 1 $(document).ready(function() {
bgneal@425 2 $tabs = $('#tabs').tabs({
bgneal@425 3 selected: initialTab,
bgneal@425 4 select: function(event, ui) {
bgneal@425 5 $(ui.panel).html('');
bgneal@425 6 },
bgneal@425 7 load: function(event, ui) {
bgneal@425 8 selectedTab = ui;
bgneal@428 9 if (ui.index == 1 && receiver && !doReply)
bgneal@428 10 {
bgneal@428 11 $('#id_receiver').val(receiver);
bgneal@428 12 receiver = '';
bgneal@428 13 }
bgneal@428 14 else if (doReply && ui.index == 1)
bgneal@425 15 {
bgneal@425 16 doReply = false;
bgneal@425 17 var msg = msgCache[$msgDialog.msgId];
bgneal@425 18 $('#id_receiver').val(msg.sender);
bgneal@425 19 $('#id_subject').val(msg.re_subject);
bgneal@425 20 $('#id_message').val(msg.re_content);
bgneal@425 21 }
bgneal@425 22 },
bgneal@425 23 ajaxOptions: {
bgneal@425 24 error: function(xhr, status, index, anchor) {
bgneal@425 25 $(anchor.hash).html(
bgneal@425 26 "Oops, we couldn't load this tab. We'll try to fix this as soon as possible.");
bgneal@425 27 }
bgneal@425 28 }
bgneal@425 29 });
bgneal@425 30 $msgDialog = $('#msgDialog').dialog({
bgneal@425 31 autoOpen: false,
bgneal@425 32 width: 460,
bgneal@425 33 buttons: [
bgneal@425 34 {
bgneal@425 35 text: "Reply",
bgneal@425 36 click: function() {
bgneal@425 37 doReply = true;
bgneal@425 38 $(this).dialog('close');
bgneal@425 39 $tabs.tabs("select", 1);
bgneal@425 40 }
bgneal@425 41 },
bgneal@425 42 {
bgneal@425 43 text: "Close",
bgneal@425 44 click: function() {
bgneal@425 45 $(this).dialog('close');
bgneal@425 46 }
bgneal@425 47 }
bgneal@425 48 ]
bgneal@425 49 });
bgneal@425 50 });
bgneal@425 51
bgneal@425 52 var $tabs = 0;
bgneal@425 53 var $msgDialog = 0;
bgneal@425 54 var msgCache = {};
bgneal@425 55 var doReply = false;
bgneal@425 56 var selectedTab = 0;
bgneal@425 57
bgneal@425 58 function showMsg(link, id) {
bgneal@425 59 $msgDialog.msgId = id; // create a msgId attribute on the dialog
bgneal@425 60 var msg = msgCache[id];
bgneal@425 61
bgneal@425 62 // mark as read if necessary
bgneal@425 63 if (username == msg.receiver) {
bgneal@425 64 $(link).removeClass('unread');
bgneal@425 65 }
bgneal@425 66
bgneal@425 67 $msgDialog.html(msg.content);
bgneal@425 68 var title = 'PM From ' + msg.sender + ' To ' + msg.receiver + '<br /> ' + msg.subject;
bgneal@425 69 $msgDialog.dialog('option', 'title', title);
bgneal@425 70 $msgDialog.dialog('open');
bgneal@425 71 }
bgneal@425 72
bgneal@425 73 function msgShow(link, id) {
bgneal@425 74 if (msgCache[id]) {
bgneal@425 75 showMsg(link, id);
bgneal@425 76 return;
bgneal@425 77 }
bgneal@425 78 $.ajax({
bgneal@425 79 url: '/messages/beta/message/',
bgneal@425 80 type: 'POST',
bgneal@425 81 data: {
bgneal@425 82 msg_id : id
bgneal@425 83 },
bgneal@425 84 dataType: 'json',
bgneal@425 85 success: function (data, textStatus) {
bgneal@425 86 msgCache[id] = data;
bgneal@425 87 showMsg(link, id);
bgneal@425 88 },
bgneal@425 89 error: function (xhr, textStatus, ex) {
bgneal@425 90 alert('Oops, an error occurred. ' + xhr.statusText + ' - ' +
bgneal@425 91 xhr.responseText);
bgneal@425 92 }
bgneal@425 93 });
bgneal@425 94 }
bgneal@425 95
bgneal@425 96 function submitOptions(form) {
bgneal@425 97 $.ajax({
bgneal@425 98 url: '/messages/beta/options-tab/',
bgneal@425 99 type: 'POST',
bgneal@425 100 data: $(form).serialize(),
bgneal@425 101 dataType: 'html',
bgneal@425 102 success: function (data, textStatus) {
bgneal@425 103 $(selectedTab.panel).html(data);
bgneal@425 104 },
bgneal@425 105 error: function (xhr, textStatus, ex) {
bgneal@425 106 alert('Oops, an error occurred. ' + xhr.statusText + ' - ' +
bgneal@425 107 xhr.responseText);
bgneal@425 108 }
bgneal@425 109 });
bgneal@425 110 return false;
bgneal@425 111 }
bgneal@425 112
bgneal@425 113 function messageSubmit(form) {
bgneal@425 114 $.ajax({
bgneal@425 115 url: '/messages/beta/compose-tab/',
bgneal@425 116 type: 'POST',
bgneal@425 117 data: $(form).serialize(),
bgneal@425 118 dataType: 'html',
bgneal@425 119 success: function (data, textStatus) {
bgneal@425 120 $('#ui-tabs-1').html(data);
bgneal@425 121 },
bgneal@425 122 error: function (xhr, textStatus, ex) {
bgneal@425 123 alert('Oops, an error occurred. ' + xhr.statusText + ' - ' +
bgneal@425 124 xhr.responseText);
bgneal@425 125 }
bgneal@425 126 });
bgneal@425 127 return false;
bgneal@425 128 }
bgneal@425 129
bgneal@425 130 function tabMasterCheckClick(box, name) {
bgneal@425 131 var state = $(box).attr('checked');
bgneal@425 132 $('input[name="' + name + '"]').each(function() {
bgneal@425 133 this.checked = state;
bgneal@425 134 });
bgneal@425 135 }
bgneal@425 136
bgneal@425 137 function bulkMsgAction(form, action) {
bgneal@425 138 if (confirm("Really " + action + " checked messages?")) {
bgneal@425 139 $.ajax({
bgneal@425 140 url: '/messages/beta/bulk/',
bgneal@425 141 type: 'POST',
bgneal@425 142 data: $(form).serialize(),
bgneal@425 143 dataType: 'text',
bgneal@425 144 success: function (data, textStatus) {
bgneal@425 145 $tabs.tabs("load", selectedTab.index);
bgneal@425 146 },
bgneal@425 147 error: function (xhr, textStatus, ex) {
bgneal@425 148 alert('Oops, an error occurred. ' + xhr.statusText + ' - ' +
bgneal@425 149 xhr.responseText);
bgneal@425 150 }
bgneal@425 151 });
bgneal@425 152 }
bgneal@425 153 return false;
bgneal@425 154 }
bgneal@425 155
bgneal@425 156 function ajaxPageFetch(link) {
bgneal@425 157 $.ajax({
bgneal@425 158 url: link.href,
bgneal@425 159 type: 'GET',
bgneal@425 160 dataType: 'html',
bgneal@425 161 success: function (data, textStatus) {
bgneal@425 162 $(selectedTab.panel).html(data);
bgneal@425 163 },
bgneal@425 164 error: function (xhr, textStatus, ex) {
bgneal@425 165 alert('Oops, an error occurred. ' + xhr.statusText + ' - ' +
bgneal@425 166 xhr.responseText);
bgneal@425 167 }
bgneal@425 168 });
bgneal@425 169 return false;
bgneal@425 170 }