comparison gpp/messages/static/js/tabbed_messages.js @ 429:d0f0800eef0c

Making the jquery tabbed version of the messages app the current version and removing the old. Also figured out how to dynamically update the base template's count of unread messages when messages are read.
author Brian Neal <bgneal@gmail.com>
date Tue, 03 May 2011 02:56:58 +0000
parents 77b3b01843b5
children 9df368d9775d
comparison
equal deleted inserted replaced
428:77b3b01843b5 429:d0f0800eef0c
53 var $msgDialog = 0; 53 var $msgDialog = 0;
54 var msgCache = {}; 54 var msgCache = {};
55 var doReply = false; 55 var doReply = false;
56 var selectedTab = 0; 56 var selectedTab = 0;
57 57
58 function updateUnreadMsgText(n)
59 {
60 var txt = '';
61 if (n == 1) {
62 txt = "1 New Message";
63 }
64 else if (n > 1) {
65 txt = n + " New Messages";
66 }
67 else {
68 txt = "Private Messages";
69 }
70 $('#unread_msg_text').html(txt);
71 }
72
58 function showMsg(link, id) { 73 function showMsg(link, id) {
59 $msgDialog.msgId = id; // create a msgId attribute on the dialog 74 $msgDialog.msgId = id; // create a msgId attribute on the dialog
60 var msg = msgCache[id]; 75 var msg = msgCache[id];
61 76
62 // mark as read if necessary 77 // mark as read if necessary
63 if (username == msg.receiver) { 78 var $link = $(link);
79
80 if (username == msg.receiver && $link.hasClass('unread')) {
64 $(link).removeClass('unread'); 81 $(link).removeClass('unread');
82
83 // decrement count of unread messages in base template
84 if (unreadMsgCount > 0)
85 {
86 updateUnreadMsgText(--unreadMsgCount);
87 }
65 } 88 }
66 89
67 $msgDialog.html(msg.content); 90 $msgDialog.html(msg.content);
68 var title = 'PM From ' + msg.sender + ' To ' + msg.receiver + '<br /> ' + msg.subject; 91 var title = 'PM From ' + msg.sender + ' To ' + msg.receiver + '<br /> ' + msg.subject;
69 $msgDialog.dialog('option', 'title', title); 92 $msgDialog.dialog('option', 'title', title);
74 if (msgCache[id]) { 97 if (msgCache[id]) {
75 showMsg(link, id); 98 showMsg(link, id);
76 return; 99 return;
77 } 100 }
78 $.ajax({ 101 $.ajax({
79 url: '/messages/beta/message/', 102 url: '/messages/message/',
80 type: 'POST', 103 type: 'POST',
81 data: { 104 data: {
82 msg_id : id 105 msg_id : id
83 }, 106 },
84 dataType: 'json', 107 dataType: 'json',
93 }); 116 });
94 } 117 }
95 118
96 function submitOptions(form) { 119 function submitOptions(form) {
97 $.ajax({ 120 $.ajax({
98 url: '/messages/beta/options-tab/', 121 url: '/messages/options-tab/',
99 type: 'POST', 122 type: 'POST',
100 data: $(form).serialize(), 123 data: $(form).serialize(),
101 dataType: 'html', 124 dataType: 'html',
102 success: function (data, textStatus) { 125 success: function (data, textStatus) {
103 $(selectedTab.panel).html(data); 126 $(selectedTab.panel).html(data);
110 return false; 133 return false;
111 } 134 }
112 135
113 function messageSubmit(form) { 136 function messageSubmit(form) {
114 $.ajax({ 137 $.ajax({
115 url: '/messages/beta/compose-tab/', 138 url: '/messages/compose-tab/',
116 type: 'POST', 139 type: 'POST',
117 data: $(form).serialize(), 140 data: $(form).serialize(),
118 dataType: 'html', 141 dataType: 'html',
119 success: function (data, textStatus) { 142 success: function (data, textStatus) {
120 $('#ui-tabs-1').html(data); 143 $('#ui-tabs-1').html(data);
135 } 158 }
136 159
137 function bulkMsgAction(form, action) { 160 function bulkMsgAction(form, action) {
138 if (confirm("Really " + action + " checked messages?")) { 161 if (confirm("Really " + action + " checked messages?")) {
139 $.ajax({ 162 $.ajax({
140 url: '/messages/beta/bulk/', 163 url: '/messages/bulk/',
141 type: 'POST', 164 type: 'POST',
142 data: $(form).serialize(), 165 data: $(form).serialize(),
143 dataType: 'text', 166 dataType: 'text',
144 success: function (data, textStatus) { 167 success: function (data, textStatus) {
145 $tabs.tabs("load", selectedTab.index); 168 $tabs.tabs("load", selectedTab.index);