comparison gpp/messages/static/js/tabbed_messages.js @ 425:76ba9478ebbd

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