Вход Регистрация
Файл: public/js/ips.messenger.js
Строк: 608
<?php
/************************************************/
/* IPB3 Javascript                                */
/* -------------------------------------------- */
/* ips.messenger.js - Messenger code            */
/* (c) IPS, Inc 2008                            */
/* -------------------------------------------- */
/* Author: Rikki Tissier                        */
/************************************************/

var _msg window.IPBoard;

_msg.prototype.messenger = {
    
folderTemplate'',
    
inviteInitfalse,
    
disabled0,
    
editShown0,
    
    
/*------------------------------*/
    /* Constructor                     */
    
init: function()
    {
        
Debug.write("Initializing ips.messenger.js");
        
        
document.observe("dom:loaded", function(){
            
ipb.messenger.initEvents();
        });
    },
    
    
/* ------------------------------ */
    /**
     * Initialize the events necessary for this module
    */
    
initEvents: function()
    {
        if( $(
'add_folder') )
        {
            $(
'add_folder').observe'click'ipb.messenger.addFolder );
        }
        
        if( $(
'edit_folders') )
        {
            $(
'edit_folders').observe'click'ipb.messenger.toggleEdit );
            
            
ipb.delegate.register('.f_empty'ipb.messenger.emptyFolder );
            
ipb.delegate.register('.f_delete'ipb.messenger.deleteFolder );
        }
        
        if( $(
'msg_checkall') )
        {
            $(
'msg_checkall').observe('click'ipb.messenger.checkAllMsgs );
        }
        
        
ipb.delegate.register('.msg_check'ipb.messenger.checkSingleBox );
        
        
/*$$('.msg_check').each( function(checkbox){
            $(checkbox).observe('click', ipb.messenger.checkSingleBox );
        } );*/
        
        
if( $('folder_moderation') )
        {
            $(
'folder_moderation').observe('click'ipb.messenger.goMultiFile );
        }
        
        
// Autocomplete stuff
        
ipb.messenger.acURL ipb.vars['base_url'] + 'app=core&module=ajax&section=findnames&do=get-member-names&secure_key=' ipb.vars['secure_hash'] + '&name=';
        
        if( $(
'entered_name') )
        {
            
ipb.messenger.autoComplete = new ipb.Autocomplete( $('entered_name'), { multiboxfalseurlipb.messenger.acURLtemplates: { wrapipb.templates['autocomplete_wrap'], itemipb.templates['autocomplete_item'] } } );
        }
        
        if( $(
'more_members') ){
            
ipb.messenger.autoCompleteMore = new ipb.Autocomplete( $('more_members'), { multiboxtrueurlipb.messenger.acURLtemplates: { wrapipb.templates['autocomplete_wrap'], itemipb.templates['autocomplete_item'] } } );
        }
        
        if( $(
'add_participants') ){
            $(
'add_participants').observe('click'ipb.messenger.loadInvites);
        }
        
        
ipb.delegate.register('.email_convo'ipb.messenger.emailConversation);
    
        
// Delegate for delete post
        
ipb.delegate.register('.delete_post'ipb.messenger.deleteReply);
        
        
// Messenger disabled?
        
if ( ipb.messenger.disabled )
        {
            new 
ipb.Popup'pmdisabled', { type'modal',
                                                         
initial: $('pmDisabled').innerHTML,
                                                         
stemtrue,
                                                         
hideAtStartfalse,
                                                         
modaltrue,
                                                         
modalOpacity0.8,
                                                         
hideClosetrue,
                                                         
w'450px' });
        }
    },
    
    
/* ------------------------------ */
    /**
     * Empty a conversation
     * 
     * @param    {event}        e        The event
     * @return    {boolean}
    */
    
emailConversation: function(eelem)
    {
        if( 
Object.isUndefinedelem ) ){ return; }
        
Event.stop(e);        
        
        
// Get id
        
        
id elem.id.replace'email_convo_''' );
        
        
Debug.write"Sending topic ID: " id );
        
        if( ! 
id )
        {
            return 
false;
        }
        
        
// OK, empty
        
url '&app=members&module=ajax&secure_key=' ipb.vars['secure_hash'] + '&section=messenger&do=archiveConversation&memberID='+ipb.vars['member_id']+'&topicID=' id;
        
        new 
Ajax.Request(     ipb.vars['base_url'] + url,
                            {
                                
method'post',
                                
parameters: { method'all' },
                                
evalJSON'force',
                                
onSuccess: function(t)
                                {
                                    if( 
Object.isUndefinedt.responseJSON ) )
                                    {
                                        
alertipb.lang['error_occured'] );
                                        return;
                                    }
                                    
                                    if ( 
t.responseJSON['error'] )
                                    {
                                        
alertt.responseJSON['error'] );
                                        return;
                                    }
                                    
                                    if ( 
t.responseJSON['msg'] )
                                    {
                                        
ipb.global.showInlineNotificationt.responseJSON['msg'].toString() );
                                    }
                                }
                            }
                        );
                        
        return 
true;
    },

    
/* ------------------------------ */
    /**
     * Shows the popup for adding more participants
    */
    
loadInvites: function(e)
    {
        
Event.stop(e);
        
        $(
'invite_more_default').hide();
        $(
'invite_more_dialogue').setStyle( { display'block' });
        
        if ( ! 
ipb.messenger.inviteInit )
        {
            $(
'invite_more_dialogue').innerHTML = $('invite_more_dialogue').innerHTML.gsub(/[x]/, ipb.messenger.nameText );
            $(
'invite_more_cancel').observe'click'ipb.messenger.closeInvites );
            
ipb.messenger.autoCompleteInvite = new ipb.Autocomplete( $('invite_more_autocomplete'), { multiboxtrueurlipb.messenger.acURLtemplates: { wrapipb.templates['autocomplete_wrap'], itemipb.templates['autocomplete_item'] } } );
            
            
ipb.messenger.inviteInit true;
        }
    },
    
    
/* ------------------------------ */
    /**
     * Closes invites
    */
    
closeInvites: function(e)
    {
        
Event.stop(e);
        
        $(
'invite_more_default').show();
        $(
'invite_more_dialogue').hide();
    },
    
    
/* ------------------------------ */
    /**
     * Checks all messages
     * 
     * @param    {event}        e        The event
    */
    
checkAllMsgs: function(e)
    {
        
toCheck $F('msg_checkall');
        
        $$(
'.msg_check').each( function(elem){
            if( 
toCheck != null )
            {
                
elem.checked true;
            }
            else
            {
                
elem.checked false;
            }
        });
    },
    
    
/* ------------------------------ */
    /**
     * Monitors single checkbox and updates "check all" box appropriately
     * 
     * @param    {event}        e        The event
    */
    
checkSingleBox: function(eelem)
    {
        var 
totalBoxes        0;
        var 
totalChecked    0;
        
        $$(
'.msg_check').each( function(checkbox){
            
totalBoxes++;
            
            if( 
checkbox.checked == true )
            {
                
totalChecked++;
            }
        } );
        
        if( 
totalBoxes == totalChecked )
        {
            $(
'msg_checkall').checked    true;
        }
        else
        {
            $(
'msg_checkall').checked    false;
        }
    },
    
    
/* ------------------------------ */
    /**
     * Empty a folder
     * 
     * @param    {event}        e        The event
     * @return    {boolean}
    */
    
emptyFolder: function(eelem)
    {
        if( 
Object.isUndefinedelem ) ){ return; }
        
Event.stop(e);        
        
        
// Get folder id
        //elem = Event.findElement( e, 'li');
        
id elem.id.replace('f_''');
        
id elem.id.replace('empty_''');
        
        if( !
confirmipb.lang['confirm_empty'] ) )
        {
            return 
false;
        }
        
        
// OK, empty
        
url '&app=members&module=ajax&secure_key=' ipb.vars['secure_hash'] + '&section=messenger&do=emptyFolder&memberID='+ipb.vars['member_id']+'&folderID=' id;
        
        new 
Ajax.Request(     ipb.vars['base_url'] + url,
                            {
                                
method'post',
                                
parameters: { method'all' },
                                
evalJSON'force',
                                
onSuccess: function(t)
                                {
                                    if( 
Object.isUndefinedt.responseJSON ) )
                                    {
                                        
alertipb.lang['error_occured'] );
                                        return;
                                    }
                                    
                                    if( 
t.responseJSON['error'] && t.responseJSON['error'] != 'nothingToRemove')
                                    {
                                        
alertt.responseJSON['error'] );
                                        return;
                                    }
                                    
                                    
// Reset count
                                    
if( $('f_' id).select('.total')[0] )
                                    {
                                        $(
'f_' id).select('.total')[0].update('0');
                                        
//new Effect.Highlight( $('f_' + id) );
                                        
ipb.global.showInlineNotificationipb.lang['folder_emptied'] );
                                    }
                                    
                                    if( !
Object.isUndefinedipb.messenger.curFolder ) && ipb.messenger.curFolder == id )
                                    {
                                        
window.refresh();
                                    }
                                }
                            }
                        );
                        
        return 
true;
    },
    
    
/* ------------------------------ */
    /**
     * Delete a folder
     * 
     * @param    {event}        e        The event
     * @return    {boolean}
    */
    
deleteFolder: function(eelem)
    {
        if( 
Object.isUndefinedelem ) ){ return; }
        
        
//elem = Event.findElement( e, 'li' );
        
id elem.id.replace('f_''');
        
id elem.id.replace('delete_''');
        
        if( 
elem.hasClassName('protected') )
        {
            
alertipb.lang['cant_delete_folder'] );
            return 
false;
        }
        
        if( !
confirmipb.lang['confirm_delete'] ) )
        {
            return 
false;
        }
        
        
// Remove it
        
url '&app=members&module=ajax&secure_key=' ipb.vars['secure_hash'] + '&section=messenger&do=removeFolder&memberID='+ipb.vars['member_id']+'&folderID=' id;
        
        new 
Ajax.Request(    ipb.vars['base_url'] + url,
                            {
                                
method'post',
                                
evalJSON'force',
                                
onSuccess: function(t)
                                {
                                    if( 
Object.isUndefinedt.responseJSON ) )
                                    {
                                        
alertipb.lang['error_occured'] );
                                        return;
                                    }
                                    
                                    if( 
t.responseJSON['error'] )
                                    {
                                        switch( 
t.responseJSON['error'] )
                                        {
                                            case 
'cannotDeleteUndeletable':
                                                
alertipb.lang['cant_delete_folder'] );
                                                break;
                                            default:
                                                
alertt.responseJSON['error'] );
                                                break;
                                        }
                                    }
                                    
                                    new 
Effect.BlindUp( $('f_' id ), {duration0.3afterFinish: function(elem){ 
                                        $(
'f_' id).remove();
                                    } } );
                                    
                                    if( !
Object.isUndefinedipb.messenger.curFolder ) && ipb.messenger.curFolder == id )
                                    {
                                        
window.refresh();
                                    }
                                }
                            }
                        );
                        
        return 
true;
        
    },
    
    
/* ------------------------------ */
    /**
     * Toggles the edit folder options on/off
     * 
     * @param    {event}        e        The event
    */
    
toggleEdit: function(e)
    {
        if( 
ipb.messenger.editShown )
        {
            $(
'edit_folders').update( $('edit_folders').innerHTML.replace( /(.+?)> (.+?)</a>/i"$1> " ipb.lang['messenger_edit'] + "</a>" ) );
            
            $(
'folder_list').select('.edit_folders').each( function(elem){
                new 
Effect.Fadeelem, { duration0.4 } );
            });
            
            $(
'folder_list').select('.total').each( function(elem){
                new 
Effect.Appearelem, { duration0.4 } );
            });
            
            
// Check for any folder renames
            
$('folder_list').select('a[rel="folder_name"]').each( function( elem ){
                var 
parent = $( elem ).up('.folder');
                if( !$( 
parent ) ){ return; }
                if( $( 
parent ).hasClassName('protected') ){ return; }
                                
                if( $( $(
parent).id '_rename') ){
                    $( $(
parent).id '_rename').remove();
                }
                
                if( $( $(
parent).id '_save' ) ){
                    $( $(
parent).id '_save').remove();
                }
                
                $( 
elem ).show();                
            });
            
            
ipb.messenger.editShown 0;
        }
        else
        {
            $(
'edit_folders').update( $('edit_folders').innerHTML.replace( /(.+?)> (.+?)</a>/i"$1> " ipb.lang['messenger_cancel'] + "</a>" ) );
            
            $(
'folder_list').select('.total').each( function(elem){
                new 
Effect.Fadeelem, { duration0.4 } );
            });
            
            $(
'folder_list').select('.edit_folders').each( function(elem){
                new 
Effect.Appearelem, { duration0.4 } );
            });
            
            
// Set up folder renaming
            
$('folder_list').select('a[rel="folder_name"]').each( function( elem ){
                var 
parent = $( elem ).up('.folder');
                if( !$( 
parent ) ){ return; }
                if( $( 
parent ).hasClassName('protected') ){ return; }
                
                
// Create new textbox
                
var textbox = new Element('input', { type'text''class''input_text'value: $( elem ).innerHTMLsize'10'id: $(parent).id '_rename' });
                var 
submit = new Element('input', { type'submit''class''input_submit add_folder'valueipb.lang['save_folder'], id: $(parent).id '_save'});
                
                $( 
elem ).insert( { beforesubmit } );
                $( 
submit ).insert( { beforetextbox } );
                $( 
elem ).hide();
                
                $( 
submit ).observe'click'ipb.messenger.saveFolderName.bindAsEventListenerthis, $( parent ).id ) );
                $( 
textbox ).observe'keypress'ipb.messenger.checkNameSubmit.bindAsEventListenerthis, $( parent ).id ) );
            });
            
            
ipb.messenger.editShown 1;
        }
        
        
Event.stop(e);
    },
    
    
checkNameSubmit: function(eid)
    {
        if( 
e.which == Event.KEY_RETURN )
        {
            
ipb.messenger.saveFolderName(eid);
        }
    },
    
    
saveFolderName: function(eid)
    {
        
// find text box
        
if( !$( id '_rename') ){ return; }
        
        
// Check for value
        
if( $Fid '_rename' ).blank() ){
            
alertipb.lang['must_enter_name'] );
            return;
        }
        
        var 
folderID id.replace('f_''');
        var 
folderName $Fid '_rename' );
        
        
// Send
        
new Ajax.Requestipb.vars['base_url'] + 'app=members&module=ajax&section=messenger&do=renameFolder&secure_key=' ipb.vars['secure_hash'] + '&folderID=' folderID '&memberID=' ipb.vars['member_id'],
                            {
                                
method'post',
                                
parameters: {
                                    
namefolderName.encodeParam()
                                },
                                
evalJSON'force',
                                
onSuccess: function(t){
                                    if( 
Object.isUndefinedt.responseJSON ) )
                                    {
                                        
alertipb.lang['error_occured'] );
                                        return;
                                    }
                                    
                                    if( 
t.responseJSON['error'] )
                                    {
                                        switch( 
t.responseJSON['error'] )
                                        {
                                            case 
'noSuchFolder':
                                                
alertipb.lang['folder_not_found'] );
                                            break;
                                            case 
'cannotDeleteUndeletable':
                                                
alertipb.lang['folder_protected'] );
                                            break;
                                            default:
                                                
alertipb.lang['error_occured'] + ": " t.responseJSON['error'] );
                                            break;
                                        }
                                        
                                        return;
                                    }
                                    
                                    
// It was a success, so remove text boxes
                                    
$( id ).select('a[rel="folder_name"]')[0].updatet.responseJSON['name'] ).show();
                                    
                                    if( $( 
id '_rename' ) ){
                                        $( 
id '_rename' ).remove();
                                    }
                                    
                                    if( $( 
id '_save' ) ){
                                        $( 
id '_save' ).remove();
                                    }
                                }
                            }
                        );
    },
    
    
/* ------------------------------ */
    /**
     * Shows the textbox for adding a folder
     * 
     * @param    {event}        e        The event
    */
    
addFolder: function(e)
    {
        
Debug.write("Adding folder");
        
rand Math.ceilMath.random() * 10000 );
        
        
// Create text box
        
_textbox = new Element'input', { 'type''text''size'16'class''input_text''id''fa_text_' rand } );
        
_li = new Element'li', { 'class''new_folder''id''fa_li_' rand } ).hide();
        
_submit = new Element'input', { 'type''submit''value''+''class''input_submit add_folder''id''fa_submit_' rand } );
        
        
_li.insert_textbox ).insert(  _submit );
        $(
'folders').insert_li );
        
        
// Add events
        
_textbox.observe('keypress'ipb.messenger.checkForAddSubmit).setStyle('width: 70%');
        
_submit.observe('click'ipb.messenger.doNewFolder);
        
        new 
Effect.BlindDown_li, { duration0.3 } );
        
        
Event.stop(e);
    },
    
    
/* ------------------------------ */
    /**
     * Listens for an enter keypress in textbox
     * 
     * @param    {event}        e        The event
    */
    
checkForAddSubmit: function(e)
    {
        if( 
e.which == Event.KEY_RETURN )
        {
            
ipb.messenger.doNewFolder(e);
        }
    },
    
    
/**
    * Delete PM
    *
    * @param    {event}        e        Event
    * @param    {int}        tid        The topic ID to delete
    */
    
deletePM: function ( etid )
    {
        
Event.stop(e);

        if ( 
confirmipb.lang['delete_pm_confirm'] ) !== true )
        {
            
Event.stop(e);
            return 
false;
        }
        
        
window.location ipb.vars['base_url'] + 'app=members&module=messaging&section=view&do=deleteConversation&topicID=' tid '&authKey=' ipb.vars['secure_hash'];
    },
    
    
/* ------------------------------ */
    /**
     * Deletes a reply in a PM
     * 
     * @param    {event}        e        The event
     * @param    {element}    elem    The element in question
    */
    
deleteReply: function(eelem)
    {
        if( ! 
confirmipb.lang['delete_reply_confirm'] ) )
        {
            
Event.stop(e);
            return 
false;
        }        
    },
    
    
/**
    * Go Multi File
    * Processes many messages
    *
    * @param    {event}        e    The event
    */
    
goMultiFile: function(e)
    {
        
/* Confirm if we chose delete */
        
var method = $('pm_multifile').options[ $('pm_multifile').selectedIndex ].value;
        
        if ( 
method == 'delete' )
        {
            if ( !
confirmipb.lang['delete_pm_many_confirm'] ) )
            {
                
Event.stop(e);
                return 
false;
            }
            
            $(
'msgFolderForm').action += '&method=delete';
        }
        else if ( 
method == 'markread' )
        {
            $(
'msgFolderForm').action += '&method=markread';
        }
        else if ( 
method == 'markunread' )
        {
            $(
'msgFolderForm').action += '&method=markunread';
        }
        else if ( 
method == 'notifyon' )
        {
            $(
'msgFolderForm').action += '&method=notifyon';
        }
        else if ( 
method == 'notifyoff' )
        {
            $(
'msgFolderForm').action += '&method=notifyoff';
        }
        else
        {
            var 
id method.replace'move_''' );
            
            $(
'msgFolderForm').action += '&method=move&folderID=' id;
            $(
'pm_multifile').options[ $('pm_multifile').selectedIndex ].value 'move';
        }
        
        $(
'msgFolderForm').submit();
    },
    
    
/* ------------------------------ */
    /**
     * Processes an add folder request
     * 
     * @param    {event}        e        The event
    */
    
doNewFolder: function(e)
    {
        
elem Event.findElement(e'li');
        
// Find ID
        
addID elem.id.replace("fa_li_"'');
        
        if( 
$F('fa_text_' addID).blank() )
        {
            
alertipb.lang['invalid_folder_name'] );
            return;
        }
        
        new 
Ajax.Requestipb.vars['base_url'] + '&app=members&module=ajax&secure_key=' ipb.vars['secure_hash'] + '&section=messenger&do=addFolder&memberID='ipb.vars['member_id'],
                         {     
method'post',
                            
parameters: { 'name' $F('fa_text_' addID).encodeParam() },
                            
evalJSON'force',
                             
onSuccess: function (t)
                            {                
                                if( 
Object.isUndefinedt.responseJSON ) )
                                {
                                    
alertipb.lang['error_occured'] );
                                    return;
                                }
                                
                                if( 
t.responseJSON['error'] )
                                {
                                    if( 
t.responseJSON['error'] == 'invalidName' )
                                    {
                                        
alertipb.lang['invalid_folder_name'] );
                                    }
                                    else if( 
t.responseJSON['error'] == 'tooManyFolders' )
                                    {
                                        
alertipb.lang['reached_max_folders'] );
                                    }
                                    else
                                    {
                                        
alertt.responseJSON['error'] );
                                    }
                                    
                                    return;
                                }
                                
                                
_temp ipb.messenger.folderTemplate;
                                
                                
_temp _temp.gsub(/[id]/, t.responseJSON['newID']);
                                
_temp _temp.gsub(/[name]/, $F('fa_text_' addID).escapeHTML());
                                
_temp _temp.gsub(/[total]/, 0);
                                
                                
                                $(
'fa_li_' addID).insert( { before_temp } );
                                $(
'f_' t.responseJSON['newID']).hide();
                                
                                
Effect.toggle( $('f_' t.responseJSON['newID']), 'blind', {duration0.4});
                                
Effect.toggle( $('fa_li_' addID ), 'blind', {duration0.4} );
                                
                                $(
'f_' t.responseJSON['newID']).select('.f_empty')[0].observe('click'ipb.messenger.emptyFolder );
                                $(
'f_' t.responseJSON['newID']).select('.f_delete')[0].observe('click'ipb.messenger.deleteFolder );
                                
                                if( 
ipb.messenger.editShown ){
                                    var 
elem = $('f_' t.responseJSON['newID']).select("a[rel='folder_name']")[0];
                                    var 
parent = $( elem ).up('.folder');
                                    if( !$( 
parent ) ){ return; }
                                    if( $( 
parent ).hasClassName('protected') ){ return; }
                                    
                                    
// Create new textbox
                                    
var textbox = new Element('input', { type'text''class''input_text'value: $( elem ).innerHTMLsize'10'id: $(parent).id '_rename' });
                                    var 
submit = new Element('input', { type'submit''class''input_submit add_folder'valueipb.lang['save_folder'], id: $(parent).id '_save'});
                                    
                                    $(
parent).select(".total")[0].hide();
                                    $(
parent).select(".edit_folders")[0].show();

                                    $( 
elem ).insert( { beforesubmit } );
                                    $( 
submit ).insert( { beforetextbox } );
                                    $( 
elem ).hide();

                                    $( 
submit ).observe'click'ipb.messenger.saveFolderName.bindAsEventListenerthis, $( parent ).id ) );
                                    $( 
textbox ).observe'keypress'ipb.messenger.checkNameSubmit.bindAsEventListenerthis, $( parent ).id ) );

                                }
                            }
                        }
                    );
                                
        
    }
};

ipb.messenger.init();
?>
Онлайн: 1
Реклама