2011-06-08 09:07:15 +00:00
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 = '<input type="checkbox" style="border: 0px">' ; // 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' , '<div class = "comment">Are you sure, you want to delete message(s) ?</div>' ] ,
[ 'HTML' , 'Response' , '<div class = "comment" id="delete_msg_dialog_response"></div>' ] ,
[ 'HTML' , 'Delete Msg' , '<div></div>' ]
] ) ;
var delete _msg _btn1 = $a ( $i ( delete _msg _dialog . widgets [ 'Delete Msg' ] ) , 'button' , 'button' ) ;
delete _msg _btn1 . innerHTML = 'Yes' ;
delete _msg _btn1 . onclick = function ( ) { delete _msg _dialog . add ( ) ; }
var delete _msg _btn2 = $a ( $i ( delete _msg _dialog . widgets [ 'Delete Msg' ] ) , 'button' , 'button' ) ;
delete _msg _btn2 . innerHTML = 'No' ;
$y ( delete _msg _btn2 , { marginLeft : '4px' } ) ;
delete _msg _btn2 . onclick = function ( ) { delete _msg _dialog . hide ( ) ; }
delete _msg _dialog . onshow = function ( ) {
$i ( 'delete_msg_dialog_response' ) . innerHTML = '' ;
}
delete _msg _dialog . add = function ( ) {
// sending...
$i ( 'delete_msg_dialog_response' ) . innerHTML = 'Processing...' ;
var m _arg = user + '~~' + this . msg _nm _lst ;
var call _back = function ( r , rt ) {
if ( r . message == 'true' ) {
$i ( 'delete_msg_dialog_response' ) . innerHTML = 'Message Deleted' ;
delete _msg _dialog . hide ( ) ;
for ( m = 0 ; m < me . msg _nm _lst . length ; m ++ ) {
if ( inList ( me . unread _msg _lst , me . msg _nm _lst [ m ] ) )
me . remove _element ( me . unread _msg _lst , me . msg _nm _lst [ m ] ) ;
}
pscript . msg _struct . inbox _lst . msg _li . run ( ) ;
pscript . msg _struct . sent _lst . msg _li . run ( ) ;
}
}
$c ( 'runserverobj' , { doctype : 'Message Control' , method : 'delete_message' , arg : m _arg } , call _back ) ;
}
}
if ( ! delete _msg _dialog ) {
set _delete _msg _dialog ( ) ;
}
delete _msg _dialog . msg _nm _lst = this . msg _nm _lst ;
delete _msg _dialog . show ( ) ;
}
MessagePreview . prototype . remove _element = function ( arrayName , arrayElement ) {
for ( var i = 0 ; i < arrayName . length ; i ++ )
{
if ( arrayName [ i ] == arrayElement )
arrayName . splice ( i , 1 ) ;
}
}
MessagePreview . prototype . show _delete _lnk = function ( ) {
var me = this ;
var div = $a ( $td ( this . t , 0 , 3 ) , 'span' , 'link_type' ) ;
div . innerHTML = 'Delete' ;
div . msg _id = me . msg _id ;
div . onclick = function ( ) {
me . delete _msg ( me . msg _id ) ;
}
}
MessagePart = function ( parent ) {
var me = this ;
this . parent = parent ;
this . inputs = { } ;
me . make _header ( ) ;
me . make _reply ( ) ;
me . make _post ( ) ;
}
MessagePart . prototype . make = function ( label , ele , comment ) {
var me = this ;
var div = $a ( this . parent , 'div' , '' , { marginBottom : '12px' } ) ;
var t = make _table ( div , 2 , 1 , '70%' , [ '100%' ] ) ;
if ( ele == 'button' ) {
var element = $a ( $td ( t , 0 , 0 ) , 'button' ) ;
element . innerHTML = label ;
}
else {
var element = $a ( $td ( t , 1 , 0 ) , ele ) ;
// large fonts for inputs
if ( in _list ( [ 'input' , 'textarea' ] , ele . toLowerCase ( ) ) ) {
$y ( element , { fontSize : '14px' , width : '100%' } )
}
$td ( t , 0 , 0 ) . innerHTML = label ;
}
if ( comment ) {
var div2 = $a ( div , 'div' , '' , { fontSize : '11px' , color : '#888' , marginTop : '2px' } ) ;
div2 . innerHTML = comment ;
}
element . wrapper = div ;
if ( label ) me . inputs [ label ] = element ;
return element ;
}
MessagePart . prototype . make _header = function ( ) {
var me = this ;
this . back _link _div = $a ( me . make ( '' , 'div' ) , 'span' , 'link_type' , { paddingTop : '12px' } ) ;
this . back _link _div . innerHTML = 'Back to List' ;
me . make ( 'To' , 'textarea' , 'Enter Email Ids separated by commas (,)' ) ;
$y ( me . inputs [ 'To' ] , { overflow : 'auto' , height : '50px' } ) ;
me . make ( 'Subject' , 'input' ) ;
}
MessagePart . prototype . make _reply = function ( ) {
var me = this ;
this . inputs . Thread = $a ( this . parent , 'div' , '' , { margin : '16px 0px' } )
}
MessagePart . prototype . make _post = function ( ) {
var me = this ;
me . make ( 'Message' , 'textarea' ) ;
$y ( me . inputs [ 'Message' ] , { height : '240px' } ) ;
// send + cancel
var d = $a ( this . parent , 'div' ) ;
me . inputs . Send = $btn ( d , 'Send' ) ;
me . inputs . Reply = $a ( d , 'Reply' )
}
MessagePart . prototype . add _header _values = function ( to _list , subject ) {
var me = this ;
//thread_participants
me . inputs [ 'To' ] . value = to _list . join ( ',' ) ;
me . inputs [ 'To' ] . disabled = true ;
// subject
me . inputs [ 'Subject' ] . value = subject ;
me . inputs [ 'Subject' ] . disabled = true ;
}
MessagePart . prototype . add _reply _thread = function ( thread ) {
var me = this ;
// prev messages
var t = me . inputs [ 'Thread' ] ;
t . innerHTML = '' ; // clear previous threads
var w = $a ( t , 'div' , '' , { width : '70%' } ) ;
var tab = make _table ( w , thread . length , 2 , '100%' , [ '20%' , '80%' ] , { padding : '8px 0px' , borderBottom : '1px solid #AAA' } ) ;
for ( i = 0 ; i < thread . length ; i ++ ) {
// ---- photo ----
if ( thread [ i ] [ 6 ] ) {
var img = $a ( $td ( tab , i , 0 ) , 'img' ) ;
var img _src = thread [ i ] [ 6 ] . split ( NEWLINE ) [ 0 ] . split ( ',' ) [ 0 ] ;
img . src = repl ( 'cgi-bin/getfile.cgi?name=%(fn)s&thumbnail=32' , { fn : img _src } ) ;
}
// ---- sender name ----
var d = $a ( $td ( tab , i , 0 ) , 'div' , '' , { fontSize : '11px' } ) ;
d . innerHTML = thread [ i ] [ 5 ] ;
//----- date ----
var d = $a ( $td ( tab , i , 1 ) , 'div' , 'comment' , { marginLeft : '8px' , color : '#888' , fontSize : '11px' } ) ;
d . innerHTML = dateutil . str _to _user ( thread [ i ] [ 3 ] ) ;
//------ message ------
var d = $a ( $td ( tab , i , 1 ) , 'div' , 'comment' , { fontSize : '14px' , marginLeft : '8px' } ) ;
d . innerHTML = replace _newlines ( thread [ i ] [ 1 ] ) ;
$y ( $td ( tab , i , 1 ) , { paddingBottom : '8px' } ) ;
}
}
//++++++++++++++++++++++++ Message ++++++++++++++++++++++++
MessageThread = function ( parent , view _list _tab , view _list _div , req _frm ) {
var me = this ;
this . wrapper = $a ( parent , 'div' ) ;
if ( ! this . msg _parts ) this . make ( view _list _tab , view _list _div , req _frm ) ;
}
MessageThread . prototype . add _autosuggest = function ( ) {
var me = this ;
// ---- add auto suggest ----
var opts = { script : '' , json : true , maxresults : 10 , timeout : 10000 , delay : 250 , maxentries : 500 , cache : false } ;
2011-09-08 13:37:14 +00:00
wn . require ( 'lib/js/legacy/widgets/autosuggest.js' ) ;
2011-06-08 09:07:15 +00:00
var as = new AutoSuggest ( me . msg _parts . inputs [ 'To' ] , opts ) ;
as . custom _select = function ( txt , sel ) {
// ---- add to the last comma ----
var r = '' ;
var tl = txt . split ( ',' ) ;
for ( var i = 0 ; i < tl . length - 1 ; i ++ ) r = r + tl [ i ] + ',' ;
r = r + ( r ? ' ' : '' ) + sel + ',' ;
if ( r [ r . length - 1 ] == NEWLINE ) { r = substr ( 0 , r . length - 1 ) ; }
return r ;
}
// ---- override server call ----
as . doAjaxRequest = function ( txt ) {
var pointer = as ; var q = '' ;
// ---- get last few letters typed ----
var last _txt = txt . split ( ',' ) ;
last _txt = last _txt [ last _txt . length - 1 ] ;
// ---- show options ----
var call _back = function ( r , rt ) {
as . aSug = [ ] ;
var jsondata = r . message ;
for ( var i = 0 ; i < jsondata . results . length ; i ++ ) {
as . aSug . push ( { 'id' : jsondata . results [ i ] . id , 'value' : jsondata . results [ i ] . value , 'info' : jsondata . results [ i ] . info } ) ;
}
as . idAs = "as_for_to_message" ;
//old create list
as . createList ( as . aSug ) ;
}
$c _obj ( 'Message Control' , 'get_to_list' , ( last _txt ? last _txt : '%' ) , call _back ) ;
return ;
}
}
MessageThread . prototype . make = function ( view _list _tab , view _list _div , req _frm ) {
var me = this ;
me . view _list _tab = view _list _tab ;
me . view _list _div = view _list _div ;
me . req _frm = req _frm ;
this . msg _parts = new MessagePart ( me . wrapper ) ;
this . msg _parts . back _link _div . onclick = function ( ) {
me . hide ( ) ;
if ( me . in _compose ) {
if ( me . req _frm == 'My Inbox' ) { me . view _list _tab . show ( ) ; $ds ( me . view _list _div ) ; }
}
}
// autosuggest
me . add _autosuggest ( ) ;
}
MessageThread . prototype . set _inbox _editor = function ( editor ) {
pscript . inbox _text _editor _set = 1 ;
}
MessageThread . prototype . view _existing _msg = function ( args ) {
var me = this ;
$c _obj ( 'Message Control' , 'get_thread_details' , docstring ( args ) ,
function ( r , rt ) {
var tl = r . message . tl ;
var to _list = r . message . to _list ;
//to and subject
me . msg _parts . add _header _values ( to _list , tl [ 0 ] [ 0 ] ) ;
//reply thread
me . msg _parts . add _reply _thread ( tl ) ;
//post area
if ( me . inbox _editor && pscript . inbox _text _editor _set == 1 ) {
me . inbox _editor . editor . setContent ( '' ) ;
}
else {
me . msg _parts . inputs [ 'Message' ] . value = '' ;
}
me . show _as ( true ) ;
}
) ;
}
MessageThread . prototype . view _blank _form = function ( ) {
var me = this ;
$ds ( me . msg _parts . inputs [ 'To' ] . wrapper ) ;
me . msg _parts . inputs [ 'To' ] . disabled = false ;
me . msg _parts . inputs [ 'To' ] . value = '' ;
me . msg _parts . inputs [ 'Subject' ] . disabled = false ;
me . msg _parts . inputs [ 'Subject' ] . value = '' ;
me . msg _parts . inputs [ 'Thread' ] . innerHTML = '' ;
if ( me . inbox _editor && pscript . inbox _text _editor _set == 1 ) {
me . inbox _editor . editor . setContent ( '' ) ;
}
else {
me . msg _parts . inputs [ 'Message' ] . value = '' ;
}
me . show _as ( false ) ;
}
// msg_id = mesage id,
// parent = div/tab from where msg will be shown,
// view_list_tab = name of tab in which list will be viewed,
// view_list_div = name of div in which list will be viewed,
// req_frm = my inbox / group / event,
// show_on_send_tab = tab to be viewed on sending/replying to msg,
// show_on_send_div = div to be viewed on sending/replying to msg,
// receiver_lst = list of msg receiver
MessageThread . prototype . show _msg = function ( msg _id , parent , view _list _tab , view _list _div , req _frm , show _on _send _tab , show _on _send _div , receiver _lst ) {
var me = this ;
// set tinymce editor
if ( ! me . inbox _editor ) {
pscript . inbox _text _editor _set = 0 ;
var theme _adv _btn1 = "fontselect,fontsizeselect,formatselect,indicime,indicimehelp,emotions" ;
var theme _adv _btn2 = "bold,italic,underline,|,undo,redo,|,code,forecolor,backcolor,link,unlink,hr,|,sub,sup,|,charmap" ;
var theme _adv _btn3 = "" ;
me . inbox _editor = new TextAreaEditor ( me . msg _parts . inputs [ "Message" ] , null , me . set _inbox _editor , theme _adv _btn1 , theme _adv _btn2 , theme _adv _btn3 , '300px' ) ;
}
me . req _frm = req _frm ;
me . receiver _lst = receiver _lst ;
me . parent = parent ;
me . view _list _tab = view _list _tab ;
me . view _list _div = view _list _div ;
me . show _on _send _tab = show _on _send _tab ;
me . show _on _send _div = show _on _send _div ;
me . msg _parts . inputs [ 'Send' ] . btn _click = 0 ;
me . msg _parts . inputs [ 'Reply' ] . btn _click = 0 ;
if ( msg _id ) {
this . cur _message _id = msg _id ;
var args = { 'user_name' : user , 'cur_msg_id' : this . cur _message _id } ;
me . view _existing _msg ( args ) ;
}
else {
this . cur _message _id = null ;
me . view _blank _form ( ) ;
}
$ds ( me . parent ) ;
// reply or send btn
me . msg _parts . inputs [ 'Send' ] . onclick = function ( ) {
if ( ! this . btn _click ) {
this . btn _click = 1 ;
me . send ( me . req _frm , me . receiver _lst , me . show _on _send _tab , me . show _on _send _div ) ;
}
}
me . msg _parts . inputs [ 'Reply' ] . onclick = me . msg _parts . inputs [ 'Send' ] . onclick ;
}
MessageThread . prototype . hide = function ( ) {
var me = this ;
$dh ( me . wrapper ) ;
$ds ( me . view _list _div ) ;
me . display = 0 ;
}
MessageThread . prototype . show _as = function ( reply ) {
var me = this ;
if ( ! reply ) {
$dh ( me . msg _parts . inputs [ 'Thread' ] . wrapper ) ;
$dh ( me . msg _parts . inputs [ 'Reply' ] ) ;
$ds ( me . msg _parts . inputs [ 'Send' ] ) ;
me . in _compose = 1 ;
}
else {
$ds ( me . msg _parts . inputs [ 'Thread' ] . wrapper ) ;
$ds ( me . msg _parts . inputs [ 'Reply' ] ) ;
$dh ( me . msg _parts . inputs [ 'Send' ] ) ;
$dh ( me . view _list _div ) ;
me . in _compose = 1 ;
}
$ds ( me . wrapper ) ;
me . display = 1 ;
}
MessageThread . prototype . send _msg = function ( arg ) {
var me = this ;
var args = arg ;
var send _call _back = function ( r , rt ) {
//var me = this;
if ( r . message == 'true' ) {
me . msg _parts . inputs [ 'To' ] . value = '' ;
me . msg _parts . inputs [ 'Subject' ] . value = '' ;
me . msg _parts . inputs [ 'Thread' ] . innerHTML = '' ;
if ( me . inbox _editor && pscript . inbox _text _editor _set == 1 ) {
me . inbox _editor . editor . setContent ( '' ) ;
}
else {
me . msg _parts . inputs [ 'Message' ] . value = '' ;
}
if ( me . req _frm == 'My Inbox' ) {
pscript . msg _struct . sent _lst . msg _li . run ( ) ;
me . show _on _send _tab . show ( ) ;
$ds ( me . show _on _send _div ) ;
$dh ( me . parent ) ;
}
}
}
if ( me . cur _message _id == null ) {
$c _obj ( 'Message Control' , 'send_message' , docstring ( args ) , send _call _back ) ;
}
else {
$c _obj ( 'Message Control' , 'send_reply' , docstring ( args ) , send _call _back ) ;
}
}
MessageThread . prototype . send = function ( req _frm , receiver _lst , show _on _send _tab , show _on _send _div ) {
var me = this ;
me . req _frm = req _frm ;
me . show _on _send _tab = show _on _send _tab ;
me . show _on _send _div = show _on _send _div ;
var args = { 'user_name' : user } ;
if ( me . inbox _editor && pscript . inbox _text _editor _set == 1 ) {
args . message = me . inbox _editor . editor . getContent ( ) ;
}
else {
args . message = me . msg _parts . inputs [ 'Message' ] . value ;
}
if ( me . cur _message _id == null ) {
args . subject = me . msg _parts . inputs [ 'Subject' ] . value ;
args . to _list = me . msg _parts . inputs [ 'To' ] . value ;
if ( ! args . to _list ) { msgprint ( 'error:Must enter "To:"' ) ; }
else if ( ! args . subject ) { msgprint ( 'error:Must enter "Subject"' ) ; }
else me . send _msg ( args ) ;
}
else {
var subj = me . msg _parts . inputs [ 'Subject' ] . value ;
if ( ! subj . substr ( 0 , 3 ) . toLowerCase ( ) == 're:' )
subj = 'Re: ' + subj ;
args . subject = subj ;
args . message _id = me . cur _message _id ;
me . send _msg ( args ) ;
}
}
MessageThread . prototype . delete _msg = function ( req _frm , parent , view _list _tab , view _list _div ) {
var me = this ;
var msg _lst = [ ] ;
var delete _message _dialog ;
me . parent = parent ;
if ( me . cur _message _id )
msg _lst . push ( me . cur _message _id ) ;
if ( msg _lst . length >= 1 ) {
function set _delete _message _dialog ( ) {
delete _message _dialog = new Dialog ( 400 , 400 , 'Delete Message' ) ;
delete _message _dialog . make _body ( [
[ 'HTML' , 'Message' , '<div class = "comment">Are you sure, you want to delete this message ?</div>' ] ,
[ 'HTML' , 'Response' , '<div class = "comment" id="delete_message_dialog_response"></div>' ] ,
[ 'HTML' , 'Delete Message' , '<div id="delete_message_btn" style ="height:25px;"></div>' ]
] ) ;
var delete _message _btn1 = $a ( $i ( 'delete_message_btn' ) , 'button' , 'button' ) ;
delete _message _btn1 . innerHTML = 'Yes' ;
delete _message _btn1 . onclick = function ( ) { delete _message _dialog . add ( ) ; }
var delete _message _btn2 = $a ( $i ( 'delete_message_btn' ) , 'button' , 'button' ) ;
delete _message _btn2 . innerHTML = 'No' ;
$y ( delete _message _btn2 , { marginLeft : '4px' } ) ;
delete _message _btn2 . onclick = function ( ) { delete _message _dialog . hide ( ) ; }
delete _message _dialog . onshow = function ( ) {
$i ( 'delete_message_dialog_response' ) . innerHTML = '' ;
}
delete _message _dialog . add = function ( ) {
if ( this . req _frm == 'My Inbox' ) {
var args = user + '~~' + this . msg _lst ;
$c _obj ( 'Message Control' , 'delete_message' , args , function ( r , rt ) {
if ( r . message == 'true' ) {
me . hide ( ) ;
me . view _list _tab . show ( ) ;
$ds ( me . view _list _div ) ;
delete _message _dialog . hide ( ) ;
}
} ) ;
}
}
}
if ( ! delete _message _dialog )
set _delete _message _dialog ( ) ;
delete _message _dialog . req _frm = req _frm ;
delete _message _dialog . msg _lst = msg _lst ;
delete _message _dialog . view _list _tab = view _list _tab ;
delete _message _dialog . view _list _div = view _list _div ;
delete _message _dialog . show ( ) ;
}
}
// ---------------- editor---------------------
var editor _count = 0 ;
function TextAreaEditor ( txt , parent , callback , theme _advanced _btn1 , theme _advanced _btn2 , theme _advanced _btn3 , editor _ht ) {
this . txt = txt ;
this . parent = parent ;
this . callback = callback ;
if ( theme _advanced _btn1 ) this . theme _advanced _btn1 = theme _advanced _btn1 ;
if ( theme _advanced _btn2 ) this . theme _advanced _btn2 = theme _advanced _btn2 ;
if ( theme _advanced _btn3 ) this . theme _advanced _btn3 = theme _advanced _btn3 ;
if ( editor _ht ) this . editor _ht = editor _ht ;
// load tinyMCE library
this . load _tiny _mce _library ( ) ;
}
TextAreaEditor . prototype . load _tiny _mce _library = function ( ) {
var me = this ;
if ( ! tinymce _loaded ) {
tinymce _loaded = 1 ;
tinyMCE _GZ . init (
{
themes : "advanced" ,
plugins : "style,table,inlinepopups,indicime,emotions" ,
languages : "en" ,
disk _cache : true
} , function ( ) { me . setup _text _area ( ) } ) ;
}
else {
me . setup _text _area ( ) ;
}
}
TextAreaEditor . prototype . setup _text _area = function ( ) {
var me = this ;
if ( ! me . txt ) {
me . txt = $a ( me . parent , 'textarea' ) ;
}
editor _count ++ ;
me . id = 'editor_text_' + editor _count ;
me . txt . setAttribute ( 'id' , me . id ) ;
tinyMCE . init ( {
theme : "advanced" ,
mode : "exact" ,
elements : me . id ,
plugins : "table,style,inlinepopups,indicime,emotions" ,
theme _advanced _toolbar _location : "top" ,
theme _advanced _statusbar _location : "bottom" ,
extended _valid _elements : "div[id|dir|class|align|style]" ,
// w/h
width : '100%' ,
height : me . editor _ht ? me . editor _ht : '50px' ,
// buttons
//theme_advanced_buttons1 :"bold,italic,underline,strikethrough,blockquote,forecolor,backcolor,bullist,numlist,|,undo,redo,|,image,code,indicime,indicimehelp,emotions",
theme _advanced _buttons1 : me . theme _advanced _btn1 ? me . theme _advanced _btn1 : "bold,italic,underline,forecolor,backcolor,|,undo,redo,|,link,unlink,indicime,indicimehelp,emotions" ,
theme _advanced _buttons2 : me . theme _advanced _btn2 ? me . theme _advanced _btn2 : "" ,
theme _advanced _buttons3 : me . theme _advanced _btn3 ? me . theme _advanced _btn3 : "" ,
// callback function with editor instance.
init _instance _callback : "editor_init_callback"
} ) ;
editor _init _callback = function ( inst ) {
me . editor = tinyMCE . get ( me . id ) ;
me . editor . focus ( ) ;
if ( me . callback ) {
me . callback ( me . editor ) ;
}
}
}