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