2011-07-01 12:37:47 +02:00
//var tab = new Tabs(3,'activetab','inactivetab','tab','tabcontent','','','tabpage');
var selectedSuggestion ;
var maxSuggestions = 5 ;
var currentInputField ;
var currentFolderSelectField ;
var currentKeyCode ;
var resultRows ;
var results ;
var keyDownCallback ;
var searchesPending = 0 ;
var resultboxVisible = false ;
var searchActive = false ;
// timer variables
var liveSearchTimer ;
var keyboardTimeout = 500 ;
var fileSelectorWindowTimer ;
var fileSelectorWindowTimeout = 500 ;
// windows
var fileSelectorWindow ;
// special keys needed for navigation
var KEYCODE _TAB = 9 ;
var KEYCODE _ENTER = 13 ;
var KEYCODE _SHIFT = 16 ;
var KEYCODE _ALT = 18 ;
var KEYCODE _ESC = 27 ;
var KEYCODE _LEFT = 37 ;
var KEYCODE _UP = 38 ;
var KEYCODE _RIGHT = 39 ;
var KEYCODE _DOWN = 40 ;
// disabled Keycodes
// quickserach input field
var disabledKeys1 = new Array ( KEYCODE _TAB , KEYCODE _ENTER , KEYCODE _UP , KEYCODE _DOWN ) ;
//var disabledKeys1 = new Array(KEYCODE_ENTER, KEYCODE_UP, KEYCODE_DOWN);
2012-03-22 13:23:11 +01:00
var browserSupportsOnUnloadConfirm = true ;
var do _onunload = false ;
var draftsMayExist = false ;
var justSavedAsDraftManually ; // no value yet, as it should indicate that the message was just saved, before another autosave kicked in
2012-10-31 15:35:13 +01:00
var justClickedSend = false ;
2013-04-24 11:59:09 +02:00
var decodedFolder ;
2011-07-01 12:37:47 +02:00
function initAll ( )
{
if ( egw _getWindowOuterHeight ( ) < 750 )
{
var fm _height = screen . availHeight / 100 * 75 ;
var resizeHeight = fm _height - egw _getWindowOuterHeight ( ) ;
//alert(fm_height+' resize By:0,'+resizeHeight);
if ( fm _height >= 750 ) window . resizeBy ( 0 , resizeHeight ) ;
}
2013-01-24 13:13:36 +01:00
if ( egw _getWindowOuterHeight ( ) > screen . availHeight ) window . resizeBy ( 0 , screen . availHeight - egw _getWindowOuterHeight ( ) ) ;
2013-04-29 13:24:29 +02:00
if ( screen . height > screen . availHeight ) window . moveBy ( 0 , screen . availHeight - screen . height ) ;
2011-07-01 12:37:47 +02:00
//tab.init();
//alert(document.onkeydown);
var titletext = document . getElementById ( 'fm_compose_subject' ) . value ;
if ( titletext . length > 0 ) updateTitle ( titletext ) ;
2012-03-22 13:23:11 +01:00
if ( window . location . search . search ( /&uid=/ ) )
{
for ( var i = 0 ; i < window . location . search . split ( "&" ) . length ; i ++ ) {
if ( window . location . search . split ( "&" ) [ i ] . search ( /uid=/ ) != - 1 )
{
var a = window . location . search . split ( "&" ) [ i ] . replace ( /uid=/ , '' ) ;
if ( a . length > 0 ) { draftsMayExist = true ; /*alert(a+' found');*/ }
}
if ( window . location . search . split ( "&" ) [ i ] . search ( /method=/ ) != - 1 )
{
var b = window . location . search . split ( "&" ) [ i ] . replace ( /method=/ , '' ) ;
if ( b . length > 0 && b == 'importMessageToMergeAndSend' )
{
justSavedAsDraftManually = false ; /*alert(b+' found');*/
do _onunload = true ;
}
}
}
}
if ( $j . browser . webkit ) browserSupportsOnUnloadConfirm = false ; // chrome blocks alert/confirm boxes, but displays (custom) messages on demand before leaving/closing a page
if ( $j . browser . opera ) browserSupportsOnUnloadConfirm = false ; // opera does not support unload or onbeforeunload for security reasons
}
function checkunload ( checkBrowser )
{
if ( typeof checkBrowser != 'undefined' && justSavedAsDraftManually == false )
{
2012-10-31 15:35:13 +01:00
if ( browserSupportsOnUnloadConfirm && do _onunload && justClickedSend == false ) do _onunload = ! confirm ( checkBrowser ) ;
2012-03-22 13:23:11 +01:00
if ( ! browserSupportsOnUnloadConfirm )
{
// window.setTimeout('checkunload();',1000);
// do_onunload = false;
return checkBrowser ;
}
}
2013-06-06 13:56:04 +02:00
if ( do _onunload )
{
xajax _doXMLHTTPsync ( 'felamimail.ajaxfelamimail.removeLastDraftedVersion' , composeID ) ;
// try triggering refresh of draftFolder
if ( typeof window . opener . refreshDraftFolderIfActive == 'function' ) window . opener . refreshDraftFolderIfActive ( ) ;
}
2011-07-01 12:37:47 +02:00
}
2012-03-16 10:59:26 +01:00
function fm _startTimerSaveAsDraft ( _refreshTimeOut ) {
if ( aktiv ) {
window . clearTimeout ( aktiv ) ;
}
if ( _refreshTimeOut > 5000 ) {
aktiv = window . setInterval ( "fm_compose_saveAsDraftBG()" , _refreshTimeOut ) ;
}
}
2012-03-22 13:23:11 +01:00
function fm _compose _saveAsDraftBG ( autoSave )
2012-03-16 10:59:26 +01:00
{
//alert('composing in progress->'+composeID);
2012-03-22 13:23:11 +01:00
if ( typeof autoSave == 'undefined' ) autoSave = true ;
2012-03-16 10:59:26 +01:00
var htmlFlag = document . getElementsByName ( '_is_html' ) [ 0 ] ;
var mimeType = document . getElementById ( 'mimeType' ) ;
2012-10-12 13:47:33 +02:00
var sendButton = document . getElementById ( 'send' ) ;
if ( autoSave ) { sendButton . disabled = sendButton . hidden = true ; }
2012-03-16 10:59:26 +01:00
var currentEditor = htmlFlag . value ;
var currentMode = '' ;
var data = { } ;
if ( currentEditor == 1 )
2012-10-12 13:47:33 +02:00
{
2012-03-16 10:59:26 +01:00
data [ 'mimeType' ] = currentMode = 'html' ;
}
else
{
data [ 'mimeType' ] = currentMode = 'plain' ;
}
var ckeditor = CKEDITOR . instances [ 'body' ] ;
var plaineditor = document . getElementsByName ( 'body' ) [ 0 ] ;
var editorArea = document . getElementById ( 'editorArea' ) ;
data = window . xajax . getFormValues ( 'doit' ) ;
data [ 'body' ] = '' ;
// body
if ( currentMode == 'html' )
{
//Copy the current HTML data and recode it via a XAJAX request
data [ 'body' ] = ckeditor . getData ( ) ;
}
else
{
data [ 'body' ] = plaineditor . value ;
}
//call saveasdraft with xajax_doXMLHTTP, or something equivalent
2012-03-22 13:23:11 +01:00
xajax _doXMLHTTP ( "felamimail.ajaxfelamimail.saveAsDraft" , composeID , data , autoSave ) ;
2012-03-16 10:59:26 +01:00
fm _startTimerSaveAsDraft ( _refreshTimeOut ) ;
2012-03-22 13:23:11 +01:00
if ( autoSave )
{
2012-10-12 13:47:33 +02:00
sendButton . disabled = sendButton . hidden = false ;
2012-03-22 13:23:11 +01:00
draftsMayExist = true ;
do _onunload = true ;
justSavedAsDraftManually = false ;
}
2013-06-06 13:56:04 +02:00
// try triggering refresh of draftFolder
if ( typeof window . opener . refreshDraftFolderIfActive == 'function' ) window . opener . refreshDraftFolderIfActive ( ) ;
2012-03-16 10:59:26 +01:00
}
2011-07-01 12:37:47 +02:00
function addEmail ( to , email )
{
//alert(to+': '+email);
var tableBody = document . getElementById ( 'addressRows' ) ;
var tableRows = tableBody . getElementsByTagName ( 'tr' ) ;
var lastRow = tableRows [ tableRows . length - 1 ] ;
var inputElements = lastRow . getElementsByTagName ( 'input' ) ;
// look for empty fields above to fill in
for ( rowCounter = tableRows . length - 1 ; rowCounter > 0 ; rowCounter -- )
{
var rowBefore = tableRows [ rowCounter - 1 ] ;
var inputBefore = rowBefore . getElementsByTagName ( 'input' ) ;
if ( inputBefore [ 0 ] . value == '' )
{
lastRow = rowBefore ;
inputElements = inputBefore ;
}
else
{
continue ;
}
}
if ( inputElements [ 0 ] . value != '' ) // last row not empty --> create new
{
addAddressRow ( lastRow ) ;
lastRow = tableRows [ tableRows . length - 1 ] ;
inputElements = lastRow . getElementsByTagName ( 'input' ) ;
}
// fill with email and set selectbox
inputElements [ 0 ] . value = email ;
var selectElements = lastRow . getElementsByTagName ( 'select' ) ;
selectElements [ 0 ] . selectedIndex = to == 'cc' ? 1 : ( to == 'bcc' ? 2 : 0 ) ;
// add a new empty last row if there is no empty one at all
lastRow = tableRows [ tableRows . length - 1 ] ;
inputElements = lastRow . getElementsByTagName ( 'input' ) ;
if ( inputElements [ 0 ] . value != '' )
{
addAddressRow ( lastRow ) ;
}
}
function addAddressRow ( _tableRow )
{
// the table body
var tableBody = _tableRow . parentNode ;
// all table rows
var tableRows = tableBody . getElementsByTagName ( 'tr' ) ;
var newTableRow = _tableRow . cloneNode ( true ) ;
var inputElements = newTableRow . getElementsByTagName ( 'input' ) ;
var spanElements = newTableRow . getElementsByTagName ( 'span' ) ;
var tdElements = newTableRow . getElementsByTagName ( 'td' ) ;
//alert(inputElements.length);
inputElements [ 0 ] . value = '' ;
inputElements [ 0 ] . disabled = false ;
inputElements [ 0 ] . style . width = '99%' ;
for ( i = 0 ; i < spanElements . length ; i ++ ) {
if ( spanElements [ i ] . className == 'selectFolder' ) {
spanElements [ i ] . style . display = 'none' ;
}
}
tableBody . appendChild ( newTableRow ) ;
// inputElements[0].focus();
singleRowHeight = _tableRow . clientHeight ;
if ( singleRowHeight == 0 ) singleRowHeight = 20 ;
if ( tableRows . length > 4 ) {
neededHeight = singleRowHeight * 4 ;
} else {
neededHeight = singleRowHeight * tableRows . length ;
}
document . getElementById ( 'addressDIV' ) . style . height = neededHeight + 'px' ;
document . getElementById ( 'addressDIV' ) . scrollTop = document . getElementById ( 'addressTable' ) . clientHeight ;
}
function fm _compose _addAttachmentRow ( _tableRow )
{
// the table body
var tableBody = _tableRow . parentNode ;
// all table rows
var tableRows = tableBody . getElementsByTagName ( 'tr' ) ;
var newTableRow = _tableRow . cloneNode ( true ) ;
var inputElements = newTableRow . getElementsByTagName ( 'input' ) ;
//alert(inputElements.length);
// inputElements[0].value = '';
if ( tableRows . length < 5 ) {
tableBody . appendChild ( newTableRow ) ;
}
// inputElements[0].focus();
singleRowHeight = _tableRow . clientHeight ;
if ( singleRowHeight == 0 ) singleRowHeight = 20 ;
if ( tableRows . length > 4 ) {
neededHeight = singleRowHeight * 4 ;
} else {
neededHeight = singleRowHeight * tableRows . length ;
}
//document.getElementById('addressDIV').style.height = neededHeight+'px';
//document.getElementById('addressDIV').scrollTop = document.getElementById('addressTable').clientHeight;
}
function deleteTableRow ( _imageObject )
{
// the table body
tableBody = document . getElementById ( 'addressRows' ) ;
// all table rows
tableRows = tableBody . getElementsByTagName ( 'tr' ) ;
if ( tableRows . length > 4 ) {
// the row where the clicked image is located
tableRow = _imageObject . parentNode . parentNode ;
// the table body
tableBody = document . getElementById ( 'addressRows' ) ;
tableBody . removeChild ( tableRow ) ;
singleRowHeight = tableRows [ 0 ] . clientHeight ;
2011-08-29 10:45:07 +02:00
if ( singleRowHeight == 0 ) singleRowHeight = 20 ;
2011-07-01 12:37:47 +02:00
if ( tableRows . length > 4 ) {
neededHeight = singleRowHeight * 4 ;
} else {
neededHeight = singleRowHeight * tableRows . length ;
}
document . getElementById ( 'addressDIV' ) . style . height = neededHeight + 'px' ;
} else {
// the row where the clicked image is located
tableRow = _imageObject . parentNode . parentNode ;
var inputElements = tableRow . getElementsByTagName ( 'input' ) ;
inputElements [ 0 ] . value = '' ;
}
}
function getPosLeft ( _node ) {
var left = 0 ;
if ( _node . offsetParent ) {
while ( _node . offsetParent )
{
left += _node . offsetLeft ;
_node = _node . offsetParent ;
}
} else if ( _node . x ) {
left += _node . x ;
}
return left ;
}
function getPosTop ( _node ) {
var top = 0 ;
if ( _node . offsetParent ) {
while ( _node . offsetParent ) {
top += _node . offsetTop ;
if ( _node . parentNode . scrollTop ) {
top -= _node . parentNode . scrollTop
}
_node = _node . offsetParent ;
}
} else if ( _node . y ) {
left += _node . y ;
}
return top ;
}
function hideResultBox ( ) {
var resultBox ;
resultBox = document . getElementById ( 'resultBox' ) ;
resultBox . className = 'resultBoxHidden' ;
//document.title='Search finnished';
resultboxVisible = false ;
}
function initResultBox ( _inputField ) {
//var resultBox;
currentInputField = _inputField ;
//document.title = resultRows.length;
//document.title = "TEST";
//resultBox = document.getElementById("resultBox");
startCapturingEvents ( keypressed ) ;
}
function displayResultBox ( ) {
var top = 0 ;
var left = 0 ;
var width = 0 ;
var resultBox ;
//document.title='Search finnished';
selectedSuggestion = - 1 ;
resultBox = document . getElementById ( 'resultBox' ) ;
if ( searchActive ) {
top = getPosTop ( currentInputField ) + currentInputField . offsetHeight ;
left = getPosLeft ( currentInputField ) ;
width = currentInputField . clientWidth ;
resultBox . style . top = top + 'px' ;
resultBox . style . left = left + 'px' ;
resultBox . style . width = width + 'px' ;
resultBox . scrollTop = 0 ;
resultBox . style . zIndex = 100000 ;
resultBox . className = 'resultBoxVisible' ;
}
resultRows = resultBox . getElementsByTagName ( 'div' ) ;
resultboxVisible = true ;
}
function startCapturingEvents ( _callback ) {
document . onkeydown = keyDown ;
keyDownCallback = _callback ;
// nur fuer NS4
//if (document.layers) {
// document.captureEvents(Event.KEYPRESS);
//}
}
function stopCapturingEvents ( ) {
document . onkeydown = null ;
delete currentKeyCode ;
hideResultBox ( ) ;
}
function keypressed ( keycode , keyvalue ) {
if ( liveSearchTimer ) {
window . clearTimeout ( liveSearchTimer ) ;
}
//_pressed = new Date().getTime();
switch ( keycode ) {
// case KEYCODE_LEFT:
case KEYCODE _UP :
if ( selectedSuggestion > 0 ) {
selectSuggestion ( selectedSuggestion - 1 ) ;
} else {
selectSuggestion ( resultRows . length - 1 ) ;
}
break ;
// case KEYCODE_RIGHT:
case KEYCODE _DOWN :
//document.title='down '+selectedSuggestion;
//if(selectedSuggestion) {
if ( resultboxVisible ) {
//document.title='is selected';
if ( selectedSuggestion < resultRows . length - 1 ) {
selectSuggestion ( selectedSuggestion + 1 ) ;
} else {
selectSuggestion ( 0 ) ;
}
}
break ;
case KEYCODE _ENTER :
if ( resultboxVisible ) {
currentInputField . value = results [ selectedSuggestion ] ;
hideResultBox ( ) ;
}
focusToNextInputField ( ) ;
searchActive = false ;
break ;
case KEYCODE _ESC :
hideResultBox ( ) ;
break ;
case KEYCODE _TAB :
if ( resultboxVisible ) {
if ( selectedSuggestion < resultRows . length - 1 ) {
selectSuggestion ( selectedSuggestion + 1 ) ;
} else {
selectSuggestion ( 0 ) ;
}
} else {
rv = focusToNextInputField ( ) ;
if ( rv == 'fm_compose_subject' )
{
currentKeyCode = 13 ;
//alert(currentKeyCode);
}
}
break ;
case KEYCODE _ALT :
case KEYCODE _SHIFT :
break ;
default :
//_setValue(-1);
liveSearchTimer = window . setTimeout ( 'startLiveSearch()' , keyboardTimeout ) ;
if ( ! currentInputField . parentNode . parentNode . nextSibling ) {
addAddressRow ( currentInputField . parentNode . parentNode ) ;
}
hideResultBox ( ) ;
}
}
function keyDown ( e ) {
var pressedKeyID = document . all ? window . event . keyCode : e . which ;
var pressedKey = String . fromCharCode ( pressedKeyID ) . toLowerCase ( ) ;
currentKeyCode = pressedKeyID ;
if ( keyDownCallback != null ) {
keyDownCallback ( pressedKeyID , pressedKey ) ;
}
}
function startLiveSearch ( ) {
if ( currentInputField . value . length > 2 ) {
fm _blink _currentInputField ( ) ;
searchActive = true ;
//document.title='Search started';
xajax _doXMLHTTP ( "felamimail.ajax_contacts.searchAddress" , currentInputField . value ) ;
}
}
function selectSuggestion ( _selectedSuggestion ) {
selectedSuggestion = _selectedSuggestion ;
for ( i = 0 ; i < resultRows . length ; i ++ ) {
if ( i == _selectedSuggestion ) {
resultRows [ i ] . className = 'activeResultRow' ;
} else {
resultRows [ i ] . className = 'inactiveResultRow' ;
}
}
}
function keycodePressed ( _keyCode ) {
//alert(currentKeyCode +'=='+ _keyCode);
if ( currentKeyCode == _keyCode ) {
return false ;
} else {
return true ;
}
}
function disabledKeyCodes ( _keyCodes ) {
for ( var i = 0 ; i < _keyCodes . length ; ++ i ) {
if ( currentKeyCode == _keyCodes [ i ] ) {
return false ;
}
}
return true ;
}
function updateTitle ( _text ) {
if ( _text . length > 30 ) {
_text = _text . substring ( 0 , 30 ) + '...' ;
}
document . title = _text ;
}
function focusToNextInputField ( ) {
var nextRow ;
if ( nextRow = currentInputField . parentNode . parentNode . nextSibling ) {
if ( nextRow . nodeType == 3 ) {
inputElements = nextRow . nextSibling . getElementsByTagName ( 'input' ) ;
inputElements [ 0 ] . focus ( ) ;
} else {
inputElements = nextRow . getElementsByTagName ( 'input' ) ;
inputElements [ 0 ] . focus ( ) ;
}
return 'addressinput' ;
} else {
document . getElementById ( 'fm_compose_subject' ) . focus ( ) ;
//document.doit.fm_compose_subject.focus();
return 'fm_compose_subject' ;
}
}
function focusToPrevInputField ( ) {
var prevRow ;
if ( prevRow = currentInputField . parentNode . parentNode . previousSibling ) {
if ( prevRow . nodeType == 3 ) {
inputElements = prevRow . previousSibling . getElementsByTagName ( 'input' ) ;
inputElements [ 0 ] . focus ( ) ;
} else {
inputElements = prevRow . getElementsByTagName ( 'input' ) ;
inputElements [ 0 ] . focus ( ) ;
}
} else {
document . getElementById ( 'fm_compose_subject' ) . focus ( ) ;
//document.doit.fm_compose_subject.focus();
}
}
function keyDownSubject ( keycode , keyvalue ) {
}
function startCaptureEventSubjects ( _inputField ) {
_inputField . onkeydown = keyDown ;
keyDownCallback = keyDownSubject ;
}
function fm _compose _selectFolder ( ) {
egw _openWindowCentered ( folderSelectURL , 'fm_compose_selectFolder' , '350' , '500' , window . outerWidth / 2 , window . outerHeight / 2 ) ;
}
function OnLoadingStart ( _nodeID ) {
return true ;
}
function onNodeSelect ( _folderName ) {
opener . fm _compose _setFolderSelectValue ( _folderName ) ;
self . close ( ) ;
}
function fm _compose _changeInputType ( _selectBox ) {
var selectBoxRow = _selectBox . parentNode . parentNode ;
var inputElements = selectBoxRow . getElementsByTagName ( 'input' ) ;
var spanElements = selectBoxRow . getElementsByTagName ( 'span' ) ;
var tdElements = selectBoxRow . getElementsByTagName ( 'td' ) ;
if ( _selectBox . value == 'folder' ) {
inputElements [ 0 ] . value = '' ;
for ( i = 0 ; i < spanElements . length ; i ++ ) {
if ( spanElements [ i ] . className == 'selectFolder' ) {
spanElements [ i ] . style . display = 'inline' ;
}
}
currentFolderSelectField = inputElements [ 0 ] ;
} else {
for ( i = 0 ; i < spanElements . length ; i ++ ) {
if ( spanElements [ i ] . className == 'selectFolder' ) {
spanElements [ i ] . style . display = 'none' ;
}
}
delete currentFolderSelectField ;
}
var tdElements = selectBoxRow . getElementsByTagName ( 'td' ) ;
if ( _selectBox . name == 'signatureID' ) {
var sigBox = document . getElementById ( 'signatureID' ) ;
//alert(sigBox);
// if we find the id, signature is inserted at the top of the message on compose start.
if ( sigBox == null )
{
//alert ("could not find sigBox");
}
else
{
var currSig = document . getElementById ( 'mySigID' ) ;
currentSig = currSig . value ;
// we try to change the signature
fm _compose _changeSignature ( currentSig , _selectBox . value ) ;
}
}
}
function fm _compose _changeSignature ( _oldSig , _signatureID ) {
//alert ("found sigBox");
var htmlFlag = document . getElementsByName ( '_is_html' ) [ 0 ] ;
var currentEditor = htmlFlag . value ;
var content = '' ;
var currentMode = '' ;
if ( _oldSig != _signatureID )
{
if ( currentEditor == 1 )
{
currentMode = 'html' ;
var ckeditor = CKEDITOR . instances [ 'body' ] ;
var content = ckeditor . getData ( ) ;
}
else
{
currentMode = 'plain' ;
var plaineditor = document . getElementsByName ( 'body' ) [ 0 ] ;
content = plaineditor . value ;
}
xajax _doXMLHTTP ( "felamimail.ajaxfelamimail.changeComposeSignature" , composeID , _oldSig , _signatureID , currentMode , content ) ;
document . getElementById ( 'mySigID' ) . value = _signatureID ;
}
}
function fm _compose _setFolderSelectValue ( _folderName ) {
if ( currentFolderSelectField ) {
2013-04-24 11:59:09 +02:00
xajax _doXMLHTTPsync ( "felamimail.ajax_contacts.decodeFolderName" , _folderName ) ;
currentFolderSelectField . value = ( decodedFolder ? decodedFolder : _folderName ) ;
2011-07-01 12:37:47 +02:00
if ( ! currentFolderSelectField . parentNode . parentNode . nextSibling ) {
addAddressRow ( currentFolderSelectField . parentNode . parentNode ) ;
}
var nextSibling = currentFolderSelectField . parentNode . parentNode . nextSibling ;
if ( nextSibling . nodeType == '3' ) {
nextSibling = nextSibling . nextSibling ;
}
nextSibling . getElementsByTagName ( 'input' ) [ 0 ] . focus ( ) ;
}
}
function fm _compose _displayFileSelector ( ) {
fileSelectorWindow = egw _openWindowCentered ( displayFileSelectorURL , 'fm_compose_fileSelector' , '550' , '100' , window . outerWidth / 2 , window . outerHeight / 2 ) ;
if ( fileSelectorWindowTimer ) {
window . clearTimeout ( fileSelectorWindowTimer ) ;
}
fileSelectorWindowTimer = window . setInterval ( 'fm_compose_reloadAttachments()' , fileSelectorWindowTimeout ) ;
}
function fm _compose _displayVfsSelector ( ) {
fileSelectorWindow = egw _openWindowCentered ( displayVfsSelectorURL , 'fm_compose_vfsSelector' , '640' , '580' , window . outerWidth / 2 , window . outerHeight / 2 ) ;
if ( fileSelectorWindowTimer ) {
window . clearTimeout ( fileSelectorWindowTimer ) ;
}
fileSelectorWindowTimer = window . setInterval ( 'fm_compose_reloadAttachments()' , fileSelectorWindowTimeout ) ;
}
function fm _compose _addFile ( ) {
document . getElementById ( 'statusMessage' ) . innerHTML = 'Sending file to server ...' ;
document . getElementById ( 'fileSelectorDIV1' ) . style . display = 'none' ;
document . getElementById ( 'fileSelectorDIV2' ) . style . display = 'inline' ;
document . fileUploadForm . submit ( ) ;
}
function fm _compose _reloadAttachments ( ) {
//searchesPending++;
//document.title=searchesPending;
if ( fileSelectorWindow . closed == true ) {
window . clearTimeout ( fileSelectorWindowTimer ) ;
xajax _doXMLHTTP ( "felamimail.ajaxfelamimail.reloadAttachments" , composeID ) ;
}
}
function fm _compose _deleteAttachmentRow ( _imageNode , _composeID , _attachmentID ) {
_imageNode . parentNode . parentNode . parentNode . parentNode . deleteRow ( _imageNode . parentNode . parentNode . rowIndex ) ;
xajax _doXMLHTTP ( "felamimail.ajaxfelamimail.deleteAttachment" , _composeID , _attachmentID ) ;
}
function fm _compose _selectSuggestionOnClick ( _selectedSuggestion ) {
if ( resultboxVisible ) {
currentInputField . value = results [ _selectedSuggestion ] ;
hideResultBox ( ) ;
}
focusToNextInputField ( ) ;
searchActive = false ;
}
function fm _compose _saveAsDraft ( ) {
document . getElementById ( 'saveAsDraft' ) . value = 1 ;
2012-03-22 13:23:11 +01:00
/ *
// if we submit the form, we do not want to execute the onunload stuff
do _onunload = false ;
2011-07-01 12:37:47 +02:00
document . doit . submit ( ) ;
2012-03-22 13:23:11 +01:00
* /
// we use our new Background function now
fm _compose _saveAsDraftBG ( false ) ;
justSavedAsDraftManually = true ;
2011-07-01 12:37:47 +02:00
}
function fm _compose _printit ( ) {
document . getElementById ( 'printit' ) . value = 1 ;
2012-03-22 13:23:11 +01:00
// if we submit the form, we do not want to execute the onunload stuff
do _onunload = false ;
// ToDo: could be done as fm_compose_saveAsDraftBG() and then reopen it in/as printview
2011-07-01 12:37:47 +02:00
document . doit . submit ( ) ;
2012-03-22 13:23:11 +01:00
2011-07-01 12:37:47 +02:00
}
function fm _blink _currentInputField ( ) {
currentInputField . style . border = "1px solid #666666" ;
window . setTimeout ( "currentInputField.style.border = ''" , 100 ) ;
window . setTimeout ( "currentInputField.style.border = '1px solid #666666'" , 200 ) ;
window . setTimeout ( "currentInputField.style.border = ''" , 450 ) ;
}
function fm _compose _sendEMail ( ) {
var addressTable = document . getElementById ( 'addressRows' ) . rows ;
var addressSet = false ;
2012-10-29 17:22:15 +01:00
var subjectSet = true ;
var doubleCheck = false ;
2012-10-31 15:35:13 +01:00
justClickedSend = true ;
2011-07-01 12:37:47 +02:00
for ( i = 0 ; i < addressTable . length ; i ++ ) {
if ( addressTable . item ( i ) . cells [ 2 ] . firstChild . value != '' ) {
addressSet = true ;
}
}
2012-10-29 17:22:15 +01:00
// check subject
var subject = document . getElementById ( 'fm_compose_subject' ) ;
if ( subject . value == '' ) {
subjectSet = false ;
}
// check to infolog/ to tracker. Only one can be checked.
var toinfolog = document . getElementById ( 'to_infolog' ) ;
var totracker = document . getElementById ( 'to_tracker' ) ;
if ( toinfolog . checked == true && totracker . checked == true )
{
doubleCheck = true ;
}
2011-07-01 12:37:47 +02:00
2012-10-29 17:22:15 +01:00
if ( addressSet == true && subjectSet == true && doubleCheck == false ) {
2012-03-22 13:23:11 +01:00
// if we submit the form, we do not want to execute the onunload stuff
2012-11-28 14:13:19 +01:00
justSavedAsDraftManually = false ;
2012-11-28 14:53:01 +01:00
document . getElementById ( 'saveAsDraft' ) . value = 0 ;
2012-11-28 14:13:19 +01:00
do _onunload = false ;
2011-07-01 12:37:47 +02:00
document . doit . submit ( ) ;
2012-11-28 14:30:00 +01:00
return true ;
2011-07-01 12:37:47 +02:00
} else {
2012-10-31 15:35:13 +01:00
justClickedSend = false ; // since we did not send at all,....
2011-07-01 12:37:47 +02:00
}
}
// Set the state of the HTML/Plain toggles based on the _is_html field value
function fm _set _editor _toggle _states ( )
{
// set the editor toggle based on the state of the editor
var htmlFlag = document . getElementsByName ( '_is_html' ) [ 0 ] ;
var toggles = document . getElementsByName ( '_editorSelect' ) ;
for ( var t = 0 ; t < toggles . length ; t ++ )
{
if ( toggles [ t ] . value == 'html' )
{
toggles [ t ] . checked = ( htmlFlag . value == "1" ) ;
}
else
{
toggles [ t ] . checked = ( htmlFlag . value == "0" ) ;
}
}
}
2011-12-29 12:20:13 +01:00
var scaytStartup ;
2011-07-01 12:37:47 +02:00
// Toggle between the HTML and Plain Text editors
function fm _toggle _editor ( toggler )
{
var selectedEditor = toggler . value ;
// determine the currently displayed editor
var htmlFlag = document . getElementsByName ( '_is_html' ) [ 0 ] ;
var mimeType = document . getElementById ( 'mimeType' ) ;
var currentEditor = htmlFlag . value ;
var currentMode = '' ;
if ( currentEditor == 1 )
{
currentMode = 'html' ;
}
else
{
currentMode = 'plain' ;
}
if ( selectedEditor == currentMode )
{
return ;
}
// do the appropriate conversion
var ckeditor = CKEDITOR . instances [ 'body' ] ;
var plaineditor = document . getElementsByName ( 'body' ) [ 0 ] ;
var editorArea = document . getElementById ( 'editorArea' ) ;
plaineditor . id = "body" ; //This has to be added in order to allow XAJAX to write its content into body
if ( selectedEditor == 'html' )
{
//Hide the old editor
plaineditor . style . display = "none" ;
if ( ckeditor )
{
2011-12-29 12:20:13 +01:00
scaytStartup = ckeditor . config . scayt _autoStartup ;
if ( ckeditor . env . ie ) ckeditor . config . scayt _autoStartup = false ;
ckeditor . config . height = '338px' ; // seems to fit the area
//ckeditor.config.resize_enabled = true;
2011-07-01 12:37:47 +02:00
}
else
{
2011-12-29 12:20:13 +01:00
scaytStartup = ckeditorConfig . scayt _autoStartup ;
if ( CKEDITOR . env . ie ) ckeditorConfig . scayt _autoStartup = false ;
ckeditorConfig . height = "338px" ; // seems to fit the area
//ckeditorConfig.resize_enabled = true;
2011-07-01 12:37:47 +02:00
ckeditor = CKEDITOR . replace ( 'body' , ckeditorConfig ) ;
}
2011-12-29 12:20:13 +01:00
2011-07-01 12:37:47 +02:00
//Copy the current ASCII data and recode it via a XAJAX request
var existingAscii = "<pre>" + plaineditor . value + "</pre>" ;
plaineditor . value = '' ;
xajax _doXMLHTTP ( "felamimail.ajaxfelamimail.toggleEditor" , composeID , existingAscii , 'simple' ) ;
htmlFlag . value = "1" ;
mimeType . value = "html" ;
}
else
{
//Copy the current HTML data and recode it via a XAJAX request
var existingHtml = ckeditor . getData ( ) ;
var ckeditor _span = document . getElementById ( 'cke_body' ) ;
2011-12-29 12:20:13 +01:00
//ckeditor.config.scayt_autoStartup = false;
ckeditor . setData ( ' ' , function ( ) { this . checkDirty ( ) ; } , true ) ;
2011-07-01 12:37:47 +02:00
//Hide the old editor
ckeditor _span . style . display = "none" ;
// we need to destroy the ckeditor, as the/a submit is using the content of the ckeditor instance for content of body
ckeditor . destroy ( ) ;
xajax _doXMLHTTP ( "felamimail.ajaxfelamimail.toggleEditor" , composeID , existingHtml , 'ascii' ) ;
htmlFlag . value = "0" ;
mimeType . value = "text" ;
setupPlainEditor ( plaineditor , editorArea . style . height ) ;
}
showAjaxLoader ( editorArea ) ;
}
function setupPlainEditor ( plaineditor , height )
{
if ( plaineditor )
{
//Do some presets on the new editor
plaineditor . style . width = "99%" ;
plaineditor . style . height = height ;
plaineditor . style . borderWidth = "1px" ;
plaineditor . style . borderStyle = "solid" ;
plaineditor . style . borderColor = "gray" ;
plaineditor . style . margin = "1px" ;
plaineditor . value = '' ;
}
}
function showAjaxLoader ( elem )
{
if ( elem )
{
elem . style . display = "block" ;
elem . style . backgroundImage = "url(phpgwapi/templates/default/images/ajax-loader.gif)" ;
elem . style . backgroundRepeat = "no-repeat" ;
elem . style . backgroundPosition = "center" ;
}
}
function hideAjaxLoader ( elem )
{
if ( elem )
{
elem . style . display = "inline" ;
elem . style . backgroundImage = "" ;
}
}
function showPlainEditor ( _content )
{
var plaineditor = document . getElementsByName ( 'body' ) [ 0 ] ;
//Toggle the plain editor visiblity
plaineditor . style . visibility = "visible" ;
plaineditor . style . display = "block" ;
plaineditor . value = _content ;
2011-12-29 12:20:13 +01:00
plaineditor . focus ( ) ;
2011-07-01 12:37:47 +02:00
hideAjaxLoader ( document . getElementById ( 'editorArea' ) ) ;
}
function showHTMLEditor ( _content )
{
var ckeditor = CKEDITOR . instances [ 'body' ] ;
var ckeditor _span = document . getElementById ( 'cke_body' ) ;
//Set the new content
ckeditor . setData ( _content ) ;
2011-12-29 12:20:13 +01:00
//alert((typeof scaytStartup)+'->'+ scaytStartup);
ckeditor . focus ( ) ;
if ( typeof scaytStartup == boolean ) ckeditor . config . scayt _autoStartup = scaytStartup ;
2011-07-01 12:37:47 +02:00
//Toggle the plain editor visiblity
ckeditor _span . style . display = 'block' ;
hideAjaxLoader ( document . getElementById ( 'editorArea' ) ) ;
}
function removeFCK ( fieldId )
{
/ * v a r c o n f i g E l e m e n t = d o c u m e n t . g e t E l e m e n t B y I d ( f i e l d I d + ' _ _ _ C o n f i g ' ) ;
var frameElement = document . getElementById ( fieldId + '___Frame' ) ; * /
//var textarea = document.forms[this].elements[fieldId];
var editor = CKEDITOR . instances [ fieldId ] ;
//if (editor!=null && configElement && frameElement && configElement.parentNode==textarea.parentNode && frameElement.parentNode==textarea.parentNode && document.removeChild)
if ( editor != null /* && configElement && frameElement && document.removeChild*/ )
{
/ * e d i t o r . U p d a t e L i n k e d F i e l d ( ) ;
configElement . parentNode . removeChild ( configElement ) ;
frameElement . parentNode . removeChild ( frameElement ) ;
//textarea.style.display = '';
delete FCKeditorAPI . Instances [ fieldId ] ;
delete editor ; * /
editor . destroy ( false ) ;
// delete editor;
}
}
function changeIdentity ( SelectedId )
{
// we do the old style (just changing the id, (to be inserted after compose before sending))
// but setSignature may try to initiate a switch of the signature within the email body if conditions match
xajax _doXMLHTTP ( "felamimail.ajaxfelamimail.setComposeSignature" , SelectedId . value ) ;
}
function setSignature ( SelectedId )
{
//alert("IS:"+document.getElementById('mySigID').value);
var sigBox = document . getElementById ( 'mySigID' ) ;
currentSig = sigBox . value ;
for ( i = 0 ; i < document . doit . signatureID . length ; ++ i )
if ( document . doit . signatureID . options [ i ] . value == SelectedId )
{
document . doit . signatureID . options [ i ] . selected = true ;
document . getElementById ( 'mySigID' ) . value = SelectedId ;
}
//else
// document.doit.signatureID.options[i].selected = false;
//alert("Now:"+document.getElementById('mySigID').value);
var sigBox = document . getElementById ( 'signatureID' ) ;
//alert(sigBox);
// if we find the id, signature is inserted at the top of the message on compose start.
// so we try toi switch, ...
if ( sigBox == null )
{
}
else
{
// we try to change the signature
if ( currentSig != SelectedId ) fm _compose _changeSignature ( currentSig , SelectedId ) ;
}
}