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