@ -343,8 +343,15 @@ function rcube_webmail()
this . enable _command ( 'add' , this . env . identities _level < 2 ) ;
this . enable _command ( 'add' , this . env . identities _level < 2 ) ;
this . enable _command ( 'save' , 'delete' , 'edit' , 'toggle-editor' , true ) ;
this . enable _command ( 'save' , 'delete' , 'edit' , 'toggle-editor' , true ) ;
}
}
else if ( this . env . action == 'folders' )
else if ( this . env . action == 'folders' ) {
this . enable _command ( 'subscribe' , 'unsubscribe' , 'create-folder' , 'rename-folder' , 'delete-folder' , 'enable-threading' , 'disable-threading' , true ) ;
this . enable _command ( 'subscribe' , 'unsubscribe' , 'create-folder' , 'rename-folder' , true ) ;
}
else if ( this . env . action == 'edit-folder' && this . gui _objects . editform ) {
this . enable _command ( 'save' , 'folder-size' , true ) ;
parent . rcmail . env . messagecount = this . env . messagecount ;
parent . rcmail . enable _command ( 'purge' , this . env . messagecount ) ;
$ ( "input[type='text']" ) . first ( ) . select ( ) ;
}
if ( this . gui _objects . identitieslist ) {
if ( this . gui _objects . identitieslist ) {
this . identity _list = new rcube _list _widget ( this . gui _objects . identitieslist , { multiselect : false , draggable : false , keyboard : false } ) ;
this . identity _list = new rcube _list _widget ( this . gui _objects . identitieslist , { multiselect : false , draggable : false , keyboard : false } ) ;
@ -1125,7 +1132,7 @@ function rcube_webmail()
else if ( delay )
else if ( delay )
window . setTimeout ( function ( ) { rcmail . reload ( ) ; } , delay ) ;
window . setTimeout ( function ( ) { rcmail . reload ( ) ; } , delay ) ;
else if ( window . location )
else if ( window . location )
location . href = this . env . comm _path ;
location . href = this . env . comm _path + ( this . env . action ? '&_action=' + this . env . action : '' ) ;
} ;
} ;
// Add variable to GET string, replace old value if exists
// Add variable to GET string, replace old value if exists
@ -1534,7 +1541,7 @@ function rcube_webmail()
if ( this . task == 'mail' )
if ( this . task == 'mail' )
allow = ( this . env . mailboxes [ id ] && this . env . mailboxes [ id ] . id != this . env . mailbox && ! this . env . mailboxes [ id ] . virtual ) ;
allow = ( this . env . mailboxes [ id ] && this . env . mailboxes [ id ] . id != this . env . mailbox && ! this . env . mailboxes [ id ] . virtual ) ;
else if ( this . task == 'settings' )
else if ( this . task == 'settings' )
allow = ( id != this . env . folder ) ;
allow = ( id != this . env . mailbox ) ;
else if ( this . task == 'addressbook' ) {
else if ( this . task == 'addressbook' ) {
if ( id != this . env . source && this . env . contactfolders [ id ] ) {
if ( id != this . env . source && this . env . contactfolders [ id ] ) {
if ( this . env . contactfolders [ id ] . type == 'group' ) {
if ( this . env . contactfolders [ id ] . type == 'group' ) {
@ -2735,24 +2742,23 @@ function rcube_webmail()
this . expunge _mailbox = function ( mbox )
this . expunge _mailbox = function ( mbox )
{
{
var lock = false ;
var lock = false ,
var add _url = '' ;
url = '_mbox=' + urlencode ( mbox ) ;
// lock interface if it's the active mailbox
// lock interface if it's the active mailbox
if ( mbox == this . env . mailbox ) {
if ( mbox == this . env . mailbox ) {
lock = this . set _busy ( true , 'loading' ) ;
lock = this . set _busy ( true , 'loading' ) ;
add_ url = '&_reload=1' ;
url + = '&_reload=1' ;
}
}
// send request to server
// send request to server
var url = '_mbox=' + urlencode ( mbox ) ;
this . http _post ( 'expunge' , url , lock ) ;
this . http _post ( 'expunge' , url + add _url , lock ) ;
} ;
} ;
this . purge _mailbox = function ( mbox )
this . purge _mailbox = function ( mbox )
{
{
var lock = false ;
var lock = false ,
var add _url = '' ;
url = '_mbox=' + urlencode ( mbox ) ;
if ( ! confirm ( this . get _label ( 'purgefolderconfirm' ) ) )
if ( ! confirm ( this . get _label ( 'purgefolderconfirm' ) ) )
return false ;
return false ;
@ -2760,13 +2766,11 @@ function rcube_webmail()
// lock interface if it's the active mailbox
// lock interface if it's the active mailbox
if ( mbox == this . env . mailbox ) {
if ( mbox == this . env . mailbox ) {
lock = this . set _busy ( true , 'loading' ) ;
lock = this . set _busy ( true , 'loading' ) ;
add_ url = '&_reload=1' ;
url + = '&_reload=1' ;
}
}
// send request to server
// send request to server
var url = '_mbox=' + urlencode ( mbox ) ;
this . http _post ( 'purge' , url , lock ) ;
this . http _post ( 'purge' , url + add _url , lock ) ;
return true ;
} ;
} ;
// test if purge command is allowed
// test if purge command is allowed
@ -3980,16 +3984,12 @@ function rcube_webmail()
this . init _subscription _list = function ( )
this . init _subscription _list = function ( )
{
{
var p = this ;
var p = this ;
this . subscription _list = new rcube _list _widget ( this . gui _objects . subscriptionlist , { multiselect : false , draggable : true , keyboard : false , toggleselect : true } ) ;
this . subscription _list = new rcube _list _widget ( this . gui _objects . subscriptionlist ,
{ multiselect : false , draggable : true , keyboard : false , toggleselect : true } ) ;
this . subscription _list . addEventListener ( 'select' , function ( o ) { p . subscription _select ( o ) ; } ) ;
this . subscription _list . addEventListener ( 'select' , function ( o ) { p . subscription _select ( o ) ; } ) ;
this . subscription _list . addEventListener ( 'dragstart' , function ( o ) { p . drag _active = true ; } ) ;
this . subscription _list . addEventListener ( 'dragstart' , function ( o ) { p . drag _active = true ; } ) ;
this . subscription _list . addEventListener ( 'dragend' , function ( o ) { p . subscription _move _folder ( o ) ; } ) ;
this . subscription _list . addEventListener ( 'dragend' , function ( o ) { p . subscription _move _folder ( o ) ; } ) ;
this . subscription _list . row _init = function ( row ) {
this . subscription _list . row _init = function ( row ) {
var anchors = row . obj . getElementsByTagName ( 'a' ) ;
if ( anchors [ 0 ] )
anchors [ 0 ] . onclick = function ( ) { p . command ( 'rename-folder' , row . id ) ; return false ; } ;
if ( anchors [ 1 ] )
anchors [ 1 ] . onclick = function ( ) { p . command ( 'delete-folder' , row . id ) ; return false ; } ;
row . obj . onmouseover = function ( ) { p . focus _subscription ( row . id ) ; } ;
row . obj . onmouseover = function ( ) { p . focus _subscription ( row . id ) ; } ;
row . obj . onmouseout = function ( ) { p . unfocus _subscription ( row . id ) ; } ;
row . obj . onmouseout = function ( ) { p . unfocus _subscription ( row . id ) ; } ;
} ;
} ;
@ -4066,18 +4066,18 @@ function rcube_webmail()
delim = RegExp . escape ( this . env . delimiter ) ,
delim = RegExp . escape ( this . env . delimiter ) ,
reg = RegExp ( '[' + delim + ']?[^' + delim + ']+$' ) ;
reg = RegExp ( '[' + delim + ']?[^' + delim + ']+$' ) ;
if ( this . drag _active && this . env . folder && ( row = document . getElementById ( id ) ) )
if ( this . drag _active && this . env . mailbox && ( row = document . getElementById ( id ) ) )
if ( this . env . subscriptionrows [ id ] &&
if ( this . env . subscriptionrows [ id ] &&
( folder = this . env . subscriptionrows [ id ] [ 0 ] ) ) {
( folder = this . env . subscriptionrows [ id ] [ 0 ] ) ) {
if ( this . check _droptarget ( folder ) &&
if ( this . check _droptarget ( folder ) &&
! this . env . subscriptionrows [ this . get _folder _row _id ( this . env . folder ) ] [ 2 ] &&
! this . env . subscriptionrows [ this . get _folder _row _id ( this . env . mailbox ) ] [ 2 ] &&
( folder != this . env . folder . replace ( reg , '' ) ) &&
( folder != this . env . mailbox . replace ( reg , '' ) ) &&
( ! folder . match ( new RegExp ( '^' + RegExp . escape ( this . env . folder + this . env . delimiter ) ) ) ) ) {
( ! folder . match ( new RegExp ( '^' + RegExp . escape ( this . env . mailbox + this . env . delimiter ) ) ) ) ) {
this . set _env ( 'dstfolder' , folder ) ;
this . set _env ( 'dstfolder' , folder ) ;
$ ( row ) . addClass ( 'droptarget' ) ;
$ ( row ) . addClass ( 'droptarget' ) ;
}
}
}
}
else if ( this . env . folder . match ( new RegExp ( delim ) ) ) {
else if ( this . env . mailbox . match ( new RegExp ( delim ) ) ) {
this . set _env ( 'dstfolder' , this . env . delimiter ) ;
this . set _env ( 'dstfolder' , this . env . delimiter ) ;
$ ( this . subscription _list . frame ) . addClass ( 'droptarget' ) ;
$ ( this . subscription _list . frame ) . addClass ( 'droptarget' ) ;
}
}
@ -4097,15 +4097,19 @@ function rcube_webmail()
this . subscription _select = function ( list )
this . subscription _select = function ( list )
{
{
var id , folder ;
var id , folder ;
if ( ( id = list . get _single _selection ( ) ) &&
this . env . subscriptionrows [ 'rcmrow' + id ] &&
( folder = this . env . subscriptionrows [ 'rcmrow' + id ] [ 0 ] ) )
this . set _env ( 'folder' , folder ) ;
else
this . set _env ( 'folder' , null ) ;
if ( this . gui _objects . createfolderhint )
if ( list && ( id = list . get _single _selection ( ) ) &&
$ ( this . gui _objects . createfolderhint ) . html ( this . env . folder ? this . get _label ( 'addsubfolderhint' ) : '' ) ;
( folder = this . env . subscriptionrows [ 'rcmrow' + id ] )
) {
this . set _env ( 'mailbox' , folder [ 0 ] ) ;
this . show _folder ( folder [ 0 ] ) ;
this . enable _command ( 'delete-folder' , ! folder [ 2 ] ) ;
}
else {
this . env . mailbox = null ;
this . show _contentframe ( false ) ;
this . enable _command ( 'delete-folder' , 'purge' , false ) ;
}
} ;
} ;
this . subscription _move _folder = function ( list )
this . subscription _move _folder = function ( list )
@ -4113,129 +4117,35 @@ function rcube_webmail()
var delim = RegExp . escape ( this . env . delimiter ) ,
var delim = RegExp . escape ( this . env . delimiter ) ,
reg = RegExp ( '[' + delim + ']?[^' + delim + ']+$' ) ;
reg = RegExp ( '[' + delim + ']?[^' + delim + ']+$' ) ;
if ( this . env . folder && this . env . dstfolder && ( this . env . dstfolder != this . env . folder ) &&
if ( this . env . mailbox && this . env . dstfolder && ( this . env . dstfolder != this . env . mailbox ) &&
( this . env . dstfolder != this . env . folder . replace ( reg , '' ) ) ) {
( this . env . dstfolder != this . env . mailbox . replace ( reg , '' ) )
var reg = new RegExp ( '[^' + delim + ']*[' + delim + ']' , 'g' ) ;
) {
var basename = this . env . folder . replace ( reg , '' ) ;
reg = new RegExp ( '[^' + delim + ']*[' + delim + ']' , 'g' ) ;
var newname = this . env . dstfolder == this . env . delimiter ? basename : this . env . dstfolder + this . env . delimiter + basename ;
var lock = this . set _busy ( true , 'foldermoving' ) ,
basename = this . env . mailbox . replace ( reg , '' ) ,
newname = this . env . dstfolder == this . env . delimiter ? basename : this . env . dstfolder + this . env . delimiter + basename ;
var lock = this . set _busy ( true , 'foldermoving' ) ;
this . http _post ( 'rename-folder' , '_folder_oldname=' + urlencode ( this . env . mailbox ) + '&_folder_newname=' + urlencode ( newname ) , lock ) ;
this . http _post ( 'rename-folder' , '_folder_oldname=' + urlencode ( this . env . folder ) + '&_folder_newname=' + urlencode ( newname ) , lock ) ;
}
}
this . drag _active = false ;
this . drag _active = false ;
this . unfocus _subscription ( this . get _folder _row _id ( this . env . dstfolder ) ) ;
this . unfocus _subscription ( this . get _folder _row _id ( this . env . dstfolder ) ) ;
} ;
} ;
// tell server to create and subscribe a new mailbox
// tell server to create and subscribe a new mailbox
this . create _folder = function ( name )
this . create _folder = function ( )
{
{
if ( this . edit _folder )
this . show _folder ( '' , this . env . mailbox ) ;
this . reset _folder _rename ( ) ;
var form ;
if ( ( form = this . gui _objects . editform ) && form . elements [ '_folder_name' ] ) {
name = form . elements [ '_folder_name' ] . value ;
if ( name . indexOf ( this . env . delimiter ) >= 0 ) {
alert ( this . get _label ( 'forbiddencharacter' ) + ' (' + this . env . delimiter + ')' ) ;
return false ;
}
if ( this . env . folder && name != '' )
name = this . env . folder + this . env . delimiter + name ;
var lock = this . set _busy ( true , 'foldercreating' ) ;
this . http _post ( 'create-folder' , '_name=' + urlencode ( name ) , lock ) ;
}
else if ( form . elements [ '_folder_name' ] )
form . elements [ '_folder_name' ] . focus ( ) ;
} ;
// start renaming the mailbox name.
// this will replace the name string with an input field
this . rename _folder = function ( id )
{
var temp , row , form ;
// reset current renaming
if ( temp = this . edit _folder ) {
this . reset _folder _rename ( ) ;
if ( temp == id )
return ;
}
if ( id && this . env . subscriptionrows [ id ] && ( row = document . getElementById ( id ) ) ) {
var delim = RegExp . escape ( this . env . delimiter ) ,
reg = new RegExp ( '.*[' + delim + ']' ) ;
this . name _input = document . createElement ( 'input' ) ;
this . name _input . type = 'text' ;
this . name _input . value = this . env . subscriptionrows [ id ] [ 0 ] . replace ( reg , '' ) ;
reg = new RegExp ( '[' + delim + ']?[^' + delim + ']+$' ) ;
this . name _input . _ _parent = this . env . subscriptionrows [ id ] [ 0 ] . replace ( reg , '' ) ;
this . name _input . onkeydown = function ( e ) { rcmail . name _input _keydown ( e ) ; } ;
row . cells [ 0 ] . replaceChild ( this . name _input , row . cells [ 0 ] . firstChild ) ;
this . edit _folder = id ;
this . name _input . select ( ) ;
if ( form = this . gui _objects . editform )
form . onsubmit = function ( ) { return false ; } ;
}
} ;
// remove the input field and write the current mailbox name to the table cell
this . reset _folder _rename = function ( )
{
var cell = this . name _input ? this . name _input . parentNode : null ;
if ( cell && this . edit _folder && this . env . subscriptionrows [ this . edit _folder ] )
$ ( cell ) . html ( this . env . subscriptionrows [ this . edit _folder ] [ 1 ] ) ;
this . edit _folder = null ;
} ;
// handler for keyboard events on the input field
this . name _input _keydown = function ( e )
{
var key = rcube _event . get _keycode ( e ) ;
// enter
if ( key == 13 ) {
var newname = this . name _input ? this . name _input . value : null ;
if ( this . edit _folder && newname ) {
if ( newname . indexOf ( this . env . delimiter ) >= 0 ) {
alert ( this . get _label ( 'forbiddencharacter' ) + ' (' + this . env . delimiter + ')' ) ;
return false ;
}
if ( this . name _input . _ _parent )
newname = this . name _input . _ _parent + this . env . delimiter + newname ;
var lock = this . set _busy ( true , 'folderrenaming' ) ;
this . http _post ( 'rename-folder' , '_folder_oldname=' + urlencode ( this . env . subscriptionrows [ this . edit _folder ] [ 0 ] ) + '&_folder_newname=' + urlencode ( newname ) , lock ) ;
}
}
// escape
else if ( key == 27 )
this . reset _folder _rename ( ) ;
} ;
} ;
// delete a specific mailbox with all its messages
// delete a specific mailbox with all its messages
this . delete _folder = function ( id )
this . delete _folder = function ( name )
{
{
var folder = this . env . subscriptionrows [ id ] [ 0 ] ;
var id = this . get _folder _row _id ( name ? name : this . env . mailbox ) ,
folder = this . env . subscriptionrows [ id ] [ 0 ] ;
if ( this . edit _folder )
this . reset _folder _rename ( ) ;
if ( folder && confirm ( this . get _label ( 'deletefolderconfirm' ) ) ) {
if ( folder && confirm ( this . get _label ( 'deletefolderconfirm' ) ) ) {
var lock = this . set _busy ( true , 'folderdeleting' ) ;
var lock = this . set _busy ( true , 'folderdeleting' ) ;
this . http _post ( 'delete-folder' , '_mboxes=' + urlencode ( folder ) , lock ) ;
this . http _post ( 'delete-folder' , '_mbox=' + urlencode ( folder ) , lock ) ;
this . set _env ( 'folder' , null ) ;
$ ( this . gui _objects . createfolderhint ) . html ( '' ) ;
}
}
} ;
} ;
@ -4292,18 +4202,8 @@ function rcube_webmail()
// set messages count to zero
// set messages count to zero
row . cells [ 1 ] . innerHTML = '*' ;
row . cells [ 1 ] . innerHTML = '*' ;
// update subscription /threading checkboxes
// update subscription checkbox
$ ( 'input[name="_subscribed[]"]' , row ) . val ( name ) . attr ( 'checked' , true ) ;
$ ( 'input[name="_subscribed[]"]' , row ) . val ( name ) . attr ( 'checked' , true ) ;
$ ( 'input[name="_threaded[]"]' , row ) . val ( name ) . attr ( 'checked' , false ) ;
var elem ;
// add new folder to rename-folder list and clear input field
if ( form = this . gui _objects . editform ) {
if ( elem = form . elements [ '_folder_oldname' ] )
elem . options [ elem . options . length ] = new Option ( name , name ) ;
if ( elem = form . elements [ '_folder_name' ] )
elem . value = '' ;
}
}
}
this . init _subscription _list ( ) ;
this . init _subscription _list ( ) ;
@ -4317,72 +4217,37 @@ function rcube_webmail()
// replace an existing table row with a new folder line
// replace an existing table row with a new folder line
this . replace _folder _row = function ( oldfolder , newfolder , display _name , before )
this . replace _folder _row = function ( oldfolder , newfolder , display _name , before )
{
{
var form , elm ,
var id = this . get _folder _row _id ( oldfolder ) ,
id = this . get _folder _row _id ( oldfolder ) ,
row = document . getElementById ( id ) ;
row = document . getElementById ( id ) ;
// replace an existing table row (if found)
// replace an existing table row (if found)
this . add _folder _row ( newfolder , display _name , row , before ) ;
this . add _folder _row ( newfolder , display _name , row , before ) ;
// rename folder in rename-folder dropdown
if ( ( form = this . gui _objects . editform ) && ( elm = form . elements [ '_folder_oldname' ] ) ) {
for ( var i = 0 ; i < elm . options . length ; i ++ ) {
if ( elm . options [ i ] . value == oldfolder ) {
elm . options [ i ] . text = display _name ;
elm . options [ i ] . value = newfolder ;
break ;
}
}
form . elements [ '_folder_newname' ] . value = '' ;
}
} ;
} ;
// remove the table row of a specific mailbox from the table
// remove the table row of a specific mailbox from the table
// (the row will not be removed, just hidden)
// (the row will not be removed, just hidden)
this . remove _folder _row = function ( folder )
this . remove _folder _row = function ( folder )
{
{
var form, elm , row, id = this . get _folder _row _id ( folder ) ;
var row , id = this . get _folder _row _id ( folder ) ;
if ( id && ( row = document . getElementById ( id ) ) )
if ( id && ( row = document . getElementById ( id ) ) )
row . style . display = 'none' ;
row . style . display = 'none' ;
// remove folder from rename-folder list
if ( ( form = this . gui _objects . editform ) && ( elm = form . elements [ '_folder_oldname' ] ) ) {
for ( var i = 0 ; i < elm . options . length ; i ++ ) {
if ( elm . options [ i ] . value == folder ) {
elm . options [ i ] = null ;
break ;
}
}
}
if ( form && ( elm = form . elements [ '_folder_newname' ] ) )
elm . value = '' ;
} ;
} ;
this . subscribe = function ( folder )
this . subscribe = function ( folder )
{
{
if ( folder )
if ( folder ) {
this . http _post ( 'subscribe' , '_mbox=' + urlencode ( folder ) ) ;
var lock = this . display _message ( 'foldersubscribing' , 'loading' ) ;
this . http _post ( 'subscribe' , '_mbox=' + urlencode ( folder ) , lock ) ;
}
} ;
} ;
this . unsubscribe = function ( folder )
this . unsubscribe = function ( folder )
{
{
if ( folder )
if ( folder ) {
this . http _post ( 'unsubscribe' , '_mbox=' + urlencode ( folder ) ) ;
var lock = this . display _message ( 'folderunsubscribing' , 'loading' ) ;
} ;
this . http _post ( 'unsubscribe' , '_mbox=' + urlencode ( folder ) , lock ) ;
}
this . enable _threading = function ( folder )
{
if ( folder )
this . http _post ( 'enable-threading' , '_mbox=' + urlencode ( folder ) ) ;
} ;
this . disable _threading = function ( folder )
{
if ( folder )
this . http _post ( 'disable-threading' , '_mbox=' + urlencode ( folder ) ) ;
} ;
} ;
// helper method to find a specific mailbox row ID
// helper method to find a specific mailbox row ID
@ -4401,7 +4266,7 @@ function rcube_webmail()
var cell , td ,
var cell , td ,
new _row = document . createElement ( 'tr' ) ;
new _row = document . createElement ( 'tr' ) ;
for ( var n = 0 ; n < row . cells . length ; n ++ ) {
for ( var n = 0 ; n < row . cells . length ; n ++ ) {
cell = row . cells [ n ] ;
cell = row . cells [ n ] ;
td = document . createElement ( 'td' ) ;
td = document . createElement ( 'td' ) ;
@ -4417,6 +4282,42 @@ function rcube_webmail()
return new _row ;
return new _row ;
} ;
} ;
// when user select a folder in manager
this . show _folder = function ( folder , path , force )
{
var target = window ,
url = '&_action=edit-folder&_mbox=' + urlencode ( folder ) ;
if ( path )
url += '&_path=' + urlencode ( path ) ;
if ( this . env . contentframe && window . frames && window . frames [ this . env . contentframe ] ) {
target = window . frames [ this . env . contentframe ] ;
url += '&_framed=1' ;
}
if ( String ( target . location . href ) . indexOf ( url ) >= 0 && ! force ) {
this . show _contentframe ( true ) ;
}
else {
if ( ! this . env . frame _lock ) {
( parent . rcmail ? parent . rcmail : this ) . env . frame _lock = this . set _busy ( true , 'loading' ) ;
}
target . location . href = this . env . comm _path + url ;
}
} ;
this . folder _size = function ( folder )
{
var lock = this . set _busy ( true , 'loading' ) ;
this . http _post ( 'folder-size' , '_mbox=' + urlencode ( folder ) , lock ) ;
} ;
this . folder _size _update = function ( size )
{
$ ( '#folder-size' ) . replaceWith ( size ) ;
} ;
/*********************************************************/
/*********************************************************/
/********* GUI functionality *********/
/********* GUI functionality *********/