pscript.onload_Messages = function() { var p = new PageHeader($i('message_header'),'Messages'); pscript.msg_struct = new Message(); } pscript.onshow_Messages = function() { pscript.msg_struct.show_inbox(); } function Message(){ if(!this.mytabs) this.make_body(); } Message.prototype.make_body = function() { var me = this; this.mytabs = new TabbedPage($i('inbox_tabs')); $y(this.mytabs.body_area, {padding:'16px'}) me.make_inbox(); me.make_compose(); me.make_sent(); this.mytabs.tabs['Inbox'].show(); } Message.prototype.make_inbox = function() { var me = this; //inbox tab me.mytabs.add_tab('Inbox', function() { me.inbox_lst.generate_unread_lst(); me.inbox_lst.msg_li.run(); me.cur_inbox_list = me.inbox_lst.msg_li; // for refresh }); if(!this.inbox_lst) this.inbox_lst = new MessageList(me.mytabs.tabs['Inbox'].tab_body, 'inbox msg'); this.inbox_lst.msg_li.get_query = function() { //me.checked_msg_lst = []; me.all_msg = {}; this.query = repl("select distinct t1.name, t1.last_updated_on, t1.last_updated_by, t1.subject, t3.first_name, t3.file_list, t1.message_date, t1.owner, t1.message, t1.previous_updated_by from `tabMail` t1, `tabMail Participant Details` t2, `tabProfile` t3 where t1.is_main_thread='Yes' and t2.participant_name='%(user)s' and (t2.delete_status is NULL or t2.delete_status = 'No') and t1.name = t2.parent and ((t1.last_updated_by = t3.name and t1.last_updated_by!='%(user)s') or (t1.previous_updated_by = t3.name and t1.previous_updated_by!='%(user)s')) order by t1.modified desc", {'user':user}); this.query_max = repl("select distinct count(t1.name) from `tabMail` t1, `tabMail Participant Details` t2, `tabProfile` t3 where t1.is_main_thread='Yes' and t2.participant_name='%(user)s' and (t2.delete_status is NULL or t2.delete_status = 'No') and t1.name = t2.parent and ((t1.last_updated_by = t3.name and t1.last_updated_by!='%(user)s') or (t1.previous_updated_by = t3.name and t1.previous_updated_by!='%(user)s')) order by t1.modified desc", {'user':user}); } this.inbox_lst.generate_unread_lst(); this.inbox_lst.msg_li.run(); this.inbox_lst.msg_li.onrun = function(){ me.inbox_lst.show_if_no_msg(me.inbox_lst.msg_li); } } Message.prototype.make_compose = function() { var me = this; me.mytabs.add_tab('Compose', function() { if(!pscript.compose_msg_obj){ pscript.compose_msg_obj = new MessageThread(me.mytabs.tabs['Compose'].tab_body, me.mytabs.tabs['Inbox'], me.inbox_lst.lst_wrapper, 'My Inbox'); //pscript.compose_msg_obj.show_msg(0, me.mytabs.tabs['Compose'].tab_body, me.mytabs.tabs['Inbox'], me.inbox_lst.lst_wrapper, 'My Inbox', me.mytabs.tabs['Sent'], me.sent_lst.lst_wrapper); } pscript.compose_msg_obj.show_msg(0, me.mytabs.tabs['Compose'].tab_body, me.mytabs.tabs['Inbox'], me.inbox_lst.lst_wrapper, 'My Inbox', me.mytabs.tabs['Sent'], me.sent_lst.lst_wrapper); this.cur_inbox_list = null; }); } Message.prototype.make_sent = function() { var me = this; // sent msg tab me.mytabs.add_tab('Sent', function() { me.sent_lst.msg_li.run(); me.cur_inbox_list = me.sent_lst.msg_li; // for refresh }); if(!this.sent_lst) this.sent_lst = new MessageList(me.mytabs.tabs['Sent'].tab_body, 'sent msg'); this.sent_lst.msg_li.get_query = function() { //me.checked_msg_lst = []; me.all_msg = {}; this.query = repl("select distinct t1.name, t1.last_updated_on, t1.last_updated_by, t1.subject, t3.first_name, t3.file_list, t1.message_date, t1.owner, t1.message from `tabMail` t1, `tabProfile` t3, `tabMail Participant Details` t2 where t1.is_main_thread='Yes' and t1.last_updated_by='%(user)s' and t1.last_updated_by = t3.name and t2.participant_name = '%(user)s' and (t2.delete_status is NULL or t2.delete_status = 'No') and t2.parent = t1.name order by t1.modified desc", {'user':user}); this.query_max = repl("select distinct count(t1.name) from `tabMail` t1, `tabProfile` t3, `tabMail Participant Details` t2 where t1.is_main_thread='Yes' and t1.last_updated_by='%(user)s' and t1.last_updated_by = t3.name and t2.participant_name = '%(user)s' and (t2.delete_status is NULL or t2.delete_status = 'No') and t2.parent = t1.name order by t1.modified desc", {'user':user}); } this.sent_lst.msg_li.run(); this.sent_lst.msg_li.onrun = function(){ me.sent_lst.show_if_no_msg(me.sent_lst.msg_li); } } Message.prototype.show_inbox = function(){ var me = this; if(me.inbox_lst){ me.inbox_lst.msg_li.run(); } me.mytabs.tabs['Inbox'].show(); } MessageList = function(parent_tab, req_frm) { this.checked_msg_lst = []; this.unread_msg_lst = []; this.all_msg = {}; this.parent_tab = parent_tab; this.req_frm = req_frm; this.make(); } MessageList.prototype.make = function(){ var me = this; this.lst_wrapper = $a(me.parent_tab, 'div'); //toolbar this.toolbar_area = $a(this.lst_wrapper, 'div', '', {paddingTop:'12px'}); this.create_toolbar(); //no inbox msg div this.no_lst_wrapper = $a(me.parent_tab, 'div', '', {padding:'8px',backgroundColor:'#FFE4AA'}); $dh(this.no_lst_wrapper); //view inbox msg div this.view_msg_wrapper = $a(me.parent_tab, 'div'); this.msg_li = new Listing("Recent Messages",1); this.msg_li.colwidths = ['90%']; this.msg_li.opts.no_border = 1; this.msg_li.opts.show_empty_tab = 0; this.msg_li.opts.no_border = 1; this.msg_li.show_cell = function(cell,ri,ci,d) { if(ri % 2)$y(cell,{backgroundColor:'#E1E3DE'}); if(ci ==0){ this.msg_lst = new MessagePreview(cell, me.req_frm, d[ri][0], d[ri][1], d[ri][2], d[ri][3], d[ri][4], d[ri][5], d[ri][6], d[ri][7], d[ri][8], d[ri][9], me.lst_wrapper, me.view_msg_wrapper, me.unread_msg_lst, me.all_msg); } } this.msg_li.make(this.lst_wrapper); $dh(this.msg_li.btn_area); } MessageList.prototype.create_toolbar = function(){ var me = this; this.toolbar_tbl = make_table(me.toolbar_area, 1, 2, '100%', ['85%', '15%']); this.select_all_lnk = $a($td(this.toolbar_tbl, 0, 0), 'span', 'link_type'); this.select_all_lnk.innerHTML = 'Select All'; $dh(this.select_all_lnk); this.unselect_all_lnk = $a($td(this.toolbar_tbl, 0, 0), 'span', 'link_type'); this.unselect_all_lnk.innerHTML = 'Unselect All'; $dh(this.unselect_all_lnk); this.select_all_lnk.onclick = function(){ $ds(me.unselect_all_lnk); $dh(me.select_all_lnk); for(m in me.all_msg){ me.all_msg[m].checked = true; } } this.unselect_all_lnk.onclick = function(){ $ds(me.select_all_lnk); $dh(me.unselect_all_lnk); for(m in me.all_msg){ me.all_msg[m].checked = false; } } this.delete_selected_btn = $a($td(this.toolbar_tbl, 0, 1), 'button', 'button', {align:'right'}); this.delete_selected_btn.innerHTML = 'Delete Selected'; $dh(this.delete_selected_btn); this.delete_selected_btn.onclick = function(){ me.checked_msg_lst = []; for(m in me.all_msg){ if(me.all_msg[m].checked == true) me.checked_msg_lst.push(m); } me.delete_selected(); } } MessageList.prototype.show_if_no_msg = function(lst_data){ var me = this; $dh(me.view_msg_wrapper); if(!lst_data.has_data()){ $ds(me.no_lst_wrapper); $dh(me.lst_wrapper); if(me.req_frm == 'inbox msg'){ me.no_lst_wrapper.innerHTML = "You have no messages in your Inbox."; } else if(me.req_frm == 'sent msg'){ me.no_lst_wrapper.innerHTML = "You have no messages in your Sent messages list."; } } else { $dh(me.no_lst_wrapper); $ds(me.lst_wrapper); $dh(me.no_lst_wrapper); $ds(me.lst_wrapper); $dh(this.unselect_all_lnk); $ds(this.select_all_lnk); $ds(this.delete_selected_btn); } } MessageList.prototype.generate_unread_lst = function(){ var me = this; var msg_callback = function(r, rt){ if(r.message.ur_lst){ me.unread_msg_lst = r.message.ur_lst; } } $c('runserverobj', {doctype:'Message Control',method:'get_unread_msg_lst',arg:user}, msg_callback); } MessageList.prototype.delete_selected = function(){ var me = this; if(me.checked_msg_lst.length >= 1) me.msg_li.msg_lst.delete_msg(me.checked_msg_lst); else msgprint("error:Please select the message to delete"); } function MessagePreview(parent, req_frm, msg_id, last_updated_on, last_updated_by, subject, first_name, profile_pic, msg_date, msg_owner, message, previous_updated_by, lst_wrapper, view_msg_wrapper, unread_msg_lst, all_msg_dict) { this.create_structure(parent); if(req_frm) this.req_frm = req_frm; this.msg_id = msg_id; this.subject = subject; this.message = message; this.msg_date = msg_date; this.msg_owner = msg_owner; this.first_name = first_name; this.lst_wrapper = lst_wrapper; this.view_msg_wrapper = view_msg_wrapper; if(profile_pic) this.profile_pic = profile_pic; if(last_updated_on) this.last_updated_on = last_updated_on; if(last_updated_by) this.last_updated_by = last_updated_by; if(previous_updated_by) this.previous_updated_by = previous_updated_by; this.unread_msg_lst = unread_msg_lst; this.all_msg = all_msg_dict; this.show_msg_sender(); this.show_msg_subject(); this.show_delete_lnk(); } MessagePreview.prototype.create_structure = function(parent){ this.wrapper = $a(parent,'div'); this.t = make_table(this.wrapper, 1, 4, '100%', ['5%','10%','80%','5%']); } MessagePreview.prototype.show_msg_sender = function(){ var me = this; // checkbox var chk_box = $a($td(this.t, 0, 0),'div'); if(isIE) { chk_box.innerHTML = ''; // IE fix this.inp = chk_box.childNodes[0]; } else { this.inp = $a(chk_box, 'input'); this.inp.type = 'checkbox'; } this.inp.onclick = function() { for(m in me.all_msg){ if(m == me.msg_id) me.all_msg[m].checked = me.inp.checked; } } me.all_msg[me.msg_id] = this.inp; //sender or receiver // photo if(this.profile_pic) { var img = $a($td(this.t, 0, 1),'img'); var img_src = this.profile_pic.split(NEWLINE)[0].split(',')[0] img.src = repl('cgi-bin/getfile.cgi?name=%(fn)s&thumbnail=32',{fn:img_src}) } //name var div = $a($td(this.t, 0, 1),'div'); div.innerHTML = this.first_name; } MessagePreview.prototype.show_msg_subject = function() { var me = this; // message var div1 = $a($td(this.t, 0, 2),'div', '', {paddingBottom:'4px'}); var sp = $a(div1,'span','link_type', {fontSize:'12px'}); sp.innerHTML = 'Sub : ' +me.subject; var div = $a($td(this.t, 0, 2),'div', 'comment',{paddingBottom:'8px'}); div.innerHTML = 'created by: ' + me.msg_owner +' | created on: ' + dateutil.str_to_user(me.msg_date)+ ' | last updated on: ' + dateutil.str_to_user(me.last_updated_on); if (me.req_frm == 'inbox msg' && inList(me.unread_msg_lst, me.msg_id)) { $y(sp,{fontWeight:'bold',color:'Black'}); $y(div,{fontWeight:'bold',color:'Black'}); } sp.style.cursor = 'pointer'; sp.msg_id = me.msg_id; sp.req_frm = me.req_frm; sp.onclick = function() { $dh(me.lst_wrapper); if(this.req_frm == 'inbox msg'){ if(!pscript.inbox_msg_obj){ pscript.inbox_msg_obj = new MessageThread(me.view_msg_wrapper, pscript.msg_struct.mytabs.tabs['Inbox'], me.lst_wrapper, 'My Inbox'); } pscript.inbox_msg_obj.show_msg(this.msg_id, me.view_msg_wrapper, pscript.msg_struct.mytabs.tabs['Inbox'], me.lst_wrapper, 'My Inbox', pscript.msg_struct.mytabs.tabs['Sent'], me.lst_wrapper); //mark for already read if (this.req_frm == 'inbox msg' && inList(me.unread_msg_lst,this.msg_id)) { me.mark_as_read(this.msg_id); } } else if(this.req_frm == 'sent msg'){ if(!pscript.sent_msg_obj){ pscript.sent_msg_obj = new MessageThread(me.view_msg_wrapper, pscript.msg_struct.mytabs.tabs['Sent'], me.lst_wrapper, 'My Inbox'); } pscript.sent_msg_obj.show_msg(this.msg_id, me.view_msg_wrapper, pscript.msg_struct.mytabs.tabs['Sent'], me.lst_wrapper, 'My Inbox', pscript.msg_struct.mytabs.tabs['Sent'], me.lst_wrapper); } } } MessagePreview.prototype.mark_as_read = function(msg_id){ this.msg_id = msg_id; var me = this; args = {'user' : user, 'msg':this.msg_id,'read':'Yes'} $c_obj('Message Control','read_unread_message',docstring(args),function(r,rt){ me.remove_element(me.unread_msg_lst, me.msg_id); }); } MessagePreview.prototype.delete_msg = function(msg_nm_lst){ this.msg_nm_lst = msg_nm_lst; var me = this; var delete_msg_dialog; set_delete_msg_dialog = function() { delete_msg_dialog = new Dialog(400, 200, 'Delete Message'); delete_msg_dialog.make_body([ ['HTML', 'Message', '