comparison messages/static/js/tabbed_messages.js @ 581:ee87ea74d46b

For Django 1.4, rearranged project structure for new manage.py.
author Brian Neal <bgneal@gmail.com>
date Sat, 05 May 2012 17:10:48 -0500
parents gpp/messages/static/js/tabbed_messages.js@9f888dbe61ce
children ad69236e8501
comparison
equal deleted inserted replaced
580:c525f3e0b5d0 581:ee87ea74d46b
1 $(document).ready(function() {
2 $tabs = $('#tabs').tabs({
3 selected: initialTab,
4 select: function(event, ui) {
5 $(ui.panel).html('');
6 },
7 load: function(event, ui) {
8 selectedTab = ui;
9 if (ui.index == 1 && receiver && !doReply)
10 {
11 $('#id_receiver').val(receiver);
12 receiver = '';
13 }
14 else if (doReply && ui.index == 1)
15 {
16 doReply = false;
17 var msg = msgCache[$msgDialog.msgId];
18 $('#id_receiver').val(msg.sender);
19 $('#id_subject').val(msg.re_subject);
20 $('#id_message').val(msg.re_content);
21 $('#msg_compose_form').append('<input type="hidden" name="reply_to" value="' +
22 $msgDialog.msgId + '" />');
23 }
24 },
25 ajaxOptions: {
26 error: function(xhr, status, index, anchor) {
27 $(anchor.hash).html(
28 "Oops, we couldn't load this tab. We'll try to fix this as soon as possible.");
29 }
30 }
31 });
32 $msgDialog = $('#msgDialog').dialog({
33 autoOpen: false,
34 width: 460,
35 height: 'auto',
36 maxHeight: false,
37 resizable: false,
38 buttons: [
39 {
40 text: "Reply",
41 click: function() {
42 doReply = true;
43 $(this).dialog('close');
44 $tabs.tabs("select", 1);
45 }
46 },
47 {
48 text: "Close",
49 click: function() {
50 $(this).dialog('close');
51 }
52 }
53 ]
54 });
55 });
56
57 var $tabs = 0;
58 var $msgDialog = 0;
59 var msgCache = {};
60 var doReply = false;
61 var selectedTab = 0;
62
63 function updateUnreadMsgText(n)
64 {
65 var txt = '';
66 if (n == 1) {
67 txt = "1 New Message";
68 }
69 else if (n > 1) {
70 txt = n + " New Messages";
71 }
72 else {
73 txt = "Private Messages";
74 }
75 $('#unread_msg_text').html(txt);
76 }
77
78 function showMsg(link, id) {
79 $msgDialog.msgId = id; // create a msgId attribute on the dialog
80 var msg = msgCache[id];
81
82 // mark as read if necessary
83 var $link = $(link);
84
85 if (username == msg.receiver && $link.hasClass('unread')) {
86 $(link).removeClass('unread');
87
88 // decrement count of unread messages in base template
89 if (unreadMsgCount > 0)
90 {
91 updateUnreadMsgText(--unreadMsgCount);
92 }
93 }
94
95 var s = '<div style="max-height:450px;overflow:auto">' + msg.content + '</div>';
96 $msgDialog.html(s);
97 var title = 'PM From ' + msg.sender + ' To ' + msg.receiver + '<br /> ' + msg.subject;
98 $msgDialog.dialog('option', 'title', title);
99 $msgDialog.dialog('open');
100 }
101
102 function msgShow(link, id) {
103 if (msgCache[id]) {
104 showMsg(link, id);
105 return;
106 }
107 $.ajax({
108 url: '/messages/message/',
109 type: 'POST',
110 data: {
111 msg_id : id
112 },
113 dataType: 'json',
114 success: function (data, textStatus) {
115 msgCache[id] = data;
116 showMsg(link, id);
117 },
118 error: function (xhr, textStatus, ex) {
119 alert('Oops, an error occurred. ' + xhr.statusText + ' - ' +
120 xhr.responseText);
121 }
122 });
123 }
124
125 function submitOptions(form) {
126 $.ajax({
127 url: '/messages/options-tab/',
128 type: 'POST',
129 data: $(form).serialize(),
130 dataType: 'html',
131 success: function (data, textStatus) {
132 $(selectedTab.panel).html(data);
133 },
134 error: function (xhr, textStatus, ex) {
135 alert('Oops, an error occurred. ' + xhr.statusText + ' - ' +
136 xhr.responseText);
137 }
138 });
139 return false;
140 }
141
142 function messageSubmit(form) {
143 $.ajax({
144 url: '/messages/compose-tab/',
145 type: 'POST',
146 data: $(form).serialize(),
147 dataType: 'html',
148 success: function (data, textStatus) {
149 $(selectedTab.panel).html(data);
150 },
151 error: function (xhr, textStatus, ex) {
152 alert('Oops, an error occurred. ' + xhr.statusText + ' - ' +
153 xhr.responseText);
154 }
155 });
156 return false;
157 }
158
159 function tabMasterCheckClick(box, name) {
160 var state = $(box).attr('checked');
161 $('input[name="' + name + '"]').each(function() {
162 this.checked = state;
163 });
164 }
165
166 function bulkMsgAction(form, action) {
167 if (confirm("Really " + action + " checked messages?")) {
168 $.ajax({
169 url: '/messages/bulk/',
170 type: 'POST',
171 data: $(form).serialize(),
172 dataType: 'text',
173 success: function (data, textStatus) {
174 $tabs.tabs("load", selectedTab.index);
175 },
176 error: function (xhr, textStatus, ex) {
177 alert('Oops, an error occurred. ' + xhr.statusText + ' - ' +
178 xhr.responseText);
179 }
180 });
181 }
182 return false;
183 }
184
185 function ajaxPageFetch(link) {
186 $.ajax({
187 url: link.href,
188 type: 'GET',
189 dataType: 'html',
190 success: function (data, textStatus) {
191 $(selectedTab.panel).html(data);
192 },
193 error: function (xhr, textStatus, ex) {
194 alert('Oops, an error occurred. ' + xhr.statusText + ' - ' +
195 xhr.responseText);
196 }
197 });
198 return false;
199 }