rework of nodeIDs; to provide unfolding of profile nodes, change profile on-click, change folder on already opened nodes of other profiles, inital refresh

This commit is contained in:
Klaus Leithoff 2013-02-20 16:27:10 +00:00
parent 9205c30a45
commit 91f9e29c49
2 changed files with 111 additions and 54 deletions

View File

@ -26,6 +26,20 @@ class mail_ui
'TestConnection' => True, 'TestConnection' => True,
); );
/**
* current icServerID
*
* @var int
*/
static $icServerID;
/**
* delimiter - used to separate profileID from foldertreestructure, and separate keyinformation in rowids
*
* @var string
*/
static $delimiter = '::';
/** /**
* instance of mail_bo * instance of mail_bo
* *
@ -48,20 +62,19 @@ class mail_ui
//$icServerID =& egw_cache::getSession('mail','activeProfileID'); //$icServerID =& egw_cache::getSession('mail','activeProfileID');
if (isset($GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID']) && !empty($GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID'])) if (isset($GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID']) && !empty($GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID']))
{ {
$icServerID = (int)$GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID']; self::$icServerID = (int)$GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID'];
} }
if ($connectionReset) if ($connectionReset)
{ {
error_log(__METHOD__.__LINE__.' Connection Reset triggered:'.$connectionReset.' for Profile with ID:'.$icServerID); error_log(__METHOD__.__LINE__.' Connection Reset triggered:'.$connectionReset.' for Profile with ID:'.self::$icServerID);
emailadmin_bo::unsetCachedObjects($icServerID); emailadmin_bo::unsetCachedObjects(self::$icServerID);
} }
$this->mail_bo = mail_bo::getInstance(false,$icServerID); $this->mail_bo = mail_bo::getInstance(false,$icServerID);
error_log(__METHOD__.__LINE__.' Fetched IC Server:'.$icServerID.'/'.$this->mail_bo->profileID.':'.function_backtrace()); error_log(__METHOD__.__LINE__.' Fetched IC Server:'.self::$icServerID.'/'.$this->mail_bo->profileID.':'.function_backtrace());
// no icServer Object: something failed big time // no icServer Object: something failed big time
if (!isset($this->mail_bo->icServer)) exit; // ToDo: Exception or the dialog for setting up a server config if (!isset($this->mail_bo->icServer)) exit; // ToDo: Exception or the dialog for setting up a server config
if (!($this->mail_bo->icServer->_connected == 1)) $this->mail_bo->openConnection($icServerID); if (!($this->mail_bo->icServer->_connected == 1)) $this->mail_bo->openConnection(self::$icServerID);
} }
/** /**
@ -69,22 +82,23 @@ class mail_ui
* *
* @param int $icServerID * @param int $icServerID
*/ */
function changeProfile($icServerID) function changeProfile($_icServerID)
{ {
error_log(__METHOD__.__LINE__.'->'.$icServerID); self::$icServerID = $_icServerID;
emailadmin_bo::unsetCachedObjects($icServerID); error_log(__METHOD__.__LINE__.'->'.self::$icServerID);
$this->mail_bo = mail_bo::getInstance(false,$icServerID); emailadmin_bo::unsetCachedObjects(self::$icServerID);
error_log(__METHOD__.__LINE__.' Fetched IC Server:'.$icServerID.'/'.$this->mail_bo->profileID.':'.function_backtrace()); $this->mail_bo = mail_bo::getInstance(false,self::$icServerID);
error_log(__METHOD__.__LINE__.' Fetched IC Server:'.self::$icServerID.'/'.$this->mail_bo->profileID.':'.function_backtrace());
// no icServer Object: something failed big time // no icServer Object: something failed big time
if (!isset($this->mail_bo->icServer)) exit; // ToDo: Exception or the dialog for setting up a server config if (!isset($this->mail_bo->icServer)) exit; // ToDo: Exception or the dialog for setting up a server config
/*if (!($this->mail_bo->icServer->_connected == 1))*/ $this->mail_bo->openConnection($icServerID); /*if (!($this->mail_bo->icServer->_connected == 1))*/ $this->mail_bo->openConnection(self::$icServerID);
// save session varchar // save session varchar
$oldicServerID =& egw_cache::getSession('mail','activeProfileID'); $oldicServerID =& egw_cache::getSession('mail','activeProfileID');
$oldicServerID = $icServerID; $oldicServerID = self::$icServerID;
// save pref // save pref
$GLOBALS['egw']->preferences->add('mail','ActiveProfileID',$icServerID,'user'); $GLOBALS['egw']->preferences->add('mail','ActiveProfileID',self::$icServerID,'user');
$GLOBALS['egw']->preferences->save_repository(true); $GLOBALS['egw']->preferences->save_repository(true);
$GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID'] = $icServerID; $GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID'] = self::$icServerID;
} }
/** /**
@ -149,18 +163,17 @@ class mail_ui
$content['nm']['foldertree'] = '/INBOX/sub'; $content['nm']['foldertree'] = '/INBOX/sub';
*/ */
$del = $this->mail_bo->getHierarchyDelimiter(false);
$sel_options['nm']['foldertree'] = $this->getFolderTree(false); $sel_options['nm']['foldertree'] = $this->getFolderTree(false);
$sessionFolder = $this->mail_bo->sessionData['maibox']; $sessionFolder = $this->mail_bo->sessionData['maibox'];
if ($this->mail_bo->folderExists($sessionFolder)) if ($this->mail_bo->folderExists($sessionFolder))
{ {
$content['nm']['selectedFolder'] = $this->mail_bo->profileID.$del.$this->mail_bo->sessionData['maibox']; $content['nm']['selectedFolder'] = $this->mail_bo->profileID.self::$delimiter.$this->mail_bo->sessionData['maibox'];
} }
if (!isset($content['nm']['foldertree'])) $content['nm']['foldertree'] = $this->mail_bo->profileID.$del.'INBOX'; if (!isset($content['nm']['foldertree'])) $content['nm']['foldertree'] = $this->mail_bo->profileID.self::$delimiter.'INBOX';
if (!isset($content['nm']['selectedFolder'])) $content['nm']['selectedFolder'] = $this->mail_bo->profileID.$del.'INBOX'; if (!isset($content['nm']['selectedFolder'])) $content['nm']['selectedFolder'] = $this->mail_bo->profileID.self::$delimiter.'INBOX';
$content['nm']['foldertree'] = $content['nm']['selectedFolder']; $content['nm']['foldertree'] = $content['nm']['selectedFolder'];
$sel_options['cat_id'] = array(1=>'none'); $sel_options['cat_id'] = array(1=>'none');
if (!isset($content['nm']['cat_id'])) $content['nm']['cat_id'] = 'All'; if (!isset($content['nm']['cat_id'])) $content['nm']['cat_id'] = 'All';
@ -347,13 +360,14 @@ class mail_ui
* *
* We currently load all folders of a given profile, tree can also load parts of a tree. * We currently load all folders of a given profile, tree can also load parts of a tree.
* *
* @param string $_GET[selected] if of node whos children are requested * @param string $_GET[id] if of node whos children are requested
*/ */
public function ajax_foldertree() public function ajax_foldertree()
{ {
list($profileId) = explode(':', $_GET['selected']); $nodeID = $_GET['id'];
//error_log(__METHOD__.__LINE__.'->'.array2string($_REQUEST));
$data = $this->getFolderTree(false, $profileId); //error_log(__METHOD__.__LINE__.'->'.array2string($_GET));
$data = $this->getFolderTree(false, $nodeID);
header('Content-Type: application/json; charset=utf-8'); header('Content-Type: application/json; charset=utf-8');
echo json_encode($data); echo json_encode($data);
@ -363,6 +377,7 @@ class mail_ui
/** /**
* getFolderTree, get folders from server and prepare the folder tree * getFolderTree, get folders from server and prepare the folder tree
* @param bool $_fetchCounters, wether to fetch extended information on folders * @param bool $_fetchCounters, wether to fetch extended information on folders
* @param string $_nodeID, nodeID to fetch and return
* @return array something like that: array('id'=>0, * @return array something like that: array('id'=>0,
* 'item'=>array( * 'item'=>array(
* 'text'=>'INBOX', * 'text'=>'INBOX',
@ -372,11 +387,19 @@ class mail_ui
* ) * )
* ); * );
*/ */
function getFolderTree($_fetchCounters=false, $_profileID=null) function getFolderTree($_fetchCounters=false, $_nodeID=null)
{ {
if ($_profileID && $_profileID != $this->mail_bo->profileID) if ($_nodeID)
{ {
$this->changeProfile($_profileID); list($_profileID,$_folderName) = explode(self::$delimiter,$_nodeID,2);
if (is_numeric($_profileID))
{
if ($_profileID && $_profileID != $this->mail_bo->profileID)
{
error_log(__METHOD__.__LINE__.' change Profile to ->'.$_profileID);
$this->changeProfile($_profileID);
}
}
} }
$folderObjects = $this->mail_bo->getFolderObjects(true,false,true); $folderObjects = $this->mail_bo->getFolderObjects(true,false,true);
$trashFolder = $this->mail_bo->getTrashFolder(); $trashFolder = $this->mail_bo->getTrashFolder();
@ -389,7 +412,6 @@ class mail_ui
if (isset($draftFolder) && $draftFolder != 'none') $userDefinedFunctionFolders['Drafts'] = $draftFolder; if (isset($draftFolder) && $draftFolder != 'none') $userDefinedFunctionFolders['Drafts'] = $draftFolder;
if (isset($templateFolder) && $templateFolder != 'none') $userDefinedFunctionFolders['Templates'] = $templateFolder; if (isset($templateFolder) && $templateFolder != 'none') $userDefinedFunctionFolders['Templates'] = $templateFolder;
$out = array('id' => 0); $out = array('id' => 0);
$del = $this->mail_bo->getHierarchyDelimiter(false);
if($this->mail_bo->mailPreferences->userDefinedAccounts) $allAccountData = $this->mail_bo->bopreferences->getAllAccountData($this->mail_bo->mailPreferences); if($this->mail_bo->mailPreferences->userDefinedAccounts) $allAccountData = $this->mail_bo->bopreferences->getAllAccountData($this->mail_bo->mailPreferences);
if ($allAccountData) { if ($allAccountData) {
foreach ($allAccountData as $tmpkey => $accountData) foreach ($allAccountData as $tmpkey => $accountData)
@ -398,7 +420,7 @@ class mail_ui
$icServer =& $accountData['icServer']; $icServer =& $accountData['icServer'];
//_debug_array($identity); //_debug_array($identity);
//_debug_array($icServer); //_debug_array($icServer);
//if ($icServer->ImapServerId<>6) continue; if ($_profileID && $icServer->ImapServerId<>$_profileID) continue;
//error_log(__METHOD__.__LINE__.' Userdefined Profiles ImapServerId:'.$icServer->ImapServerId); //error_log(__METHOD__.__LINE__.' Userdefined Profiles ImapServerId:'.$icServer->ImapServerId);
if (empty($icServer->host)) continue; if (empty($icServer->host)) continue;
$identities[$icServer->ImapServerId]=$identity->realName.' '.$identity->organization.' &lt;'.$identity->emailAddress.'&gt;'; $identities[$icServer->ImapServerId]=$identity->realName.' '.$identity->organization.' &lt;'.$identity->emailAddress.'&gt;';
@ -412,7 +434,7 @@ class mail_ui
'child'=> 1, 'child'=> 1,
'parent' => '' 'parent' => ''
); );
$this->setOutStructure($oA,$out,$del); $this->setOutStructure($oA,$out,self::$delimiter);
} }
} }
@ -429,7 +451,7 @@ class mail_ui
// the rest of the array is the name of the parent // the rest of the array is the name of the parent
$parentName = implode((array)$folderParts,$obj->delimiter); $parentName = implode((array)$folderParts,$obj->delimiter);
$parentName = $this->mail_bo->profileID.$obj->delimiter.$parentName; $parentName = $this->mail_bo->profileID.self::$delimiter.$parentName;
$oA =array('text'=> $obj->shortDisplayName, 'tooltip'=> $obj->displayName); $oA =array('text'=> $obj->shortDisplayName, 'tooltip'=> $obj->displayName);
array_unshift($fFP,$this->mail_bo->profileID); array_unshift($fFP,$this->mail_bo->profileID);
$oA['path'] = $fFP; $oA['path'] = $fFP;
@ -457,7 +479,7 @@ class mail_ui
$oA['im1'] = "folderOpen.gif"; $oA['im1'] = "folderOpen.gif";
$oA['im2'] = "MailFolderClosed.png"; // has Children $oA['im2'] = "MailFolderClosed.png"; // has Children
} }
$path = $this->mail_bo->profileID.$obj->delimiter.$key; //$obj->folderName; //$obj->delimiter $path = $this->mail_bo->profileID.self::$delimiter.$key; //$obj->folderName; //$obj->delimiter
$oA['id'] = $path; // ID holds the PATH $oA['id'] = $path; // ID holds the PATH
if (stripos(array2string($fS['attributes']),'\noselect')!== false) if (stripos(array2string($fS['attributes']),'\noselect')!== false)
{ {
@ -474,10 +496,34 @@ class mail_ui
$this->setOutStructure($oA,$out,$obj->delimiter); $this->setOutStructure($oA,$out,$obj->delimiter);
$c++; $c++;
} }
if ($_nodeID)
{
$node = self::findNode($out,$_nodeID);
error_log(__METHOD__.__LINE__.array2string($node));
return $node;
}
return ($c?$out:array('id'=>0, 'item'=>array('text'=>'INBOX','tooltip'=>'INBOX'.' '.lang('(not connected)'),'im0'=>'kfm_home.png'))); return ($c?$out:array('id'=>0, 'item'=>array('text'=>'INBOX','tooltip'=>'INBOX'.' '.lang('(not connected)'),'im0'=>'kfm_home.png')));
} }
/**
* findNode - helper function to return only a branch of the tree
*
* @param array &$out, out array (to be processed)
* @param string $_nodeID, node to search for
* @param boolean $childElements=true return node itself, or only its child items
* @return array structured subtree
*/
static function findNode($_out, $_nodeID, $childElements = false)
{
foreach($_out['item'] as $node)
{
if ($node['id']==$_nodeID)
{
return ($childElements?$node['item']:$node);
}
}
}
/** /**
* setOutStructure - helper function to transform the folderObjectList to dhtmlXTreeObject requirements * setOutStructure - helper function to transform the folderObjectList to dhtmlXTreeObject requirements
* *
@ -497,10 +543,21 @@ class mail_ui
$parents = array(); $parents = array();
foreach($components as $component) foreach($components as $component)
{ {
$parent = implode($del, $parents); if (count($parents)>1)
if ($parent) $parent .= $del; {
$helper = array_slice($parents,1,null,true);
$parent = $parents[0].self::$delimiter.implode($del, $helper);
if ($parent) $parent .= $del;
}
else
{
$parent = implode(self::$delimiter, $parents);
if ($parent) $parent .= self::$delimiter;
}
if (!is_array($insert) || !isset($insert['item'])) if (!is_array($insert) || !isset($insert['item']))
{ {
//break;
throw new egw_exception_assertion_failed(__METHOD__.':'.__LINE__." id=$data[id]: Parent '$parent' '$component' not found! out=".array2string($out)); throw new egw_exception_assertion_failed(__METHOD__.':'.__LINE__." id=$data[id]: Parent '$parent' '$component' not found! out=".array2string($out));
} }
foreach($insert['item'] as &$item) foreach($insert['item'] as &$item)
@ -878,12 +935,15 @@ $starttime = microtime(true);
$sRToFetch = null; $sRToFetch = null;
$_folderName=$query['selectedFolder']; $_folderName=$query['selectedFolder'];
$del = $this->mail_bo->getHierarchyDelimiter(false); list($_profileID,$folderName) = explode(self::$delimiter,$_folderName,2);
$splitFolder = explode($del,$_folderName); if (is_numeric($_profileID))
if (is_numeric($splitFolder[0]))
{ {
array_shift($splitFolder); if ($_profileID && $_profileID != $this->mail_bo->profileID)
$_folderName = implode($del,$splitFolder); {
error_log(__METHOD__.__LINE__.' change Profile to ->'.$_profileID);
$this->changeProfile($_profileID);
}
$_folderName = $folderName;
} }
//save selected Folder to sessionData (mailbox)->currentFolder //save selected Folder to sessionData (mailbox)->currentFolder
if (isset($query['selectedFolder'])) $this->mail_bo->sessionData['maibox']=$_folderName; if (isset($query['selectedFolder'])) $this->mail_bo->sessionData['maibox']=$_folderName;
@ -983,7 +1043,7 @@ error_log(__METHOD__.__LINE__.' SelectedFolder:'.$query['selectedFolder'].' Star
*/ */
function createRowID($_folderName, $message_uid) function createRowID($_folderName, $message_uid)
{ {
return trim($GLOBALS['egw_info']['user']['account_id']).'::'.$this->mail_bo->profileID.'::'.base64_encode($_folderName).'::'.$message_uid; return trim($GLOBALS['egw_info']['user']['account_id']).self::$delimiter.$this->mail_bo->profileID.self::$delimiter.base64_encode($_folderName).self::$delimiter.$message_uid;
} }
/** /**
@ -994,7 +1054,7 @@ error_log(__METHOD__.__LINE__.' SelectedFolder:'.$query['selectedFolder'].' Star
*/ */
function splitRowID($_rowID) function splitRowID($_rowID)
{ {
$res = explode('::',$_rowID); $res = explode(self::$delimiter,$_rowID);
// as a rowID is perceeded by app::, we ignore the first part // as a rowID is perceeded by app::, we ignore the first part
return array('accountID'=>$res[1], 'profileID'=>$res[2], 'folder'=>base64_decode($res[3]), 'msgUID'=>$res[4]); return array('accountID'=>$res[1], 'profileID'=>$res[2], 'folder'=>base64_decode($res[3]), 'msgUID'=>$res[4]);
} }
@ -1324,12 +1384,10 @@ error_log(__METHOD__.__LINE__.' SelectedFolder:'.$query['selectedFolder'].' Star
$oA = array(); $oA = array();
foreach ($_folder as $_folderName) foreach ($_folder as $_folderName)
{ {
$splitFolder = explode($del,$_folderName); list($profileID,$folderName) = explode(self::$delimiter,$_folderName,2);
if (is_numeric($splitFolder[0])) if (is_numeric($profileID))
{ {
$fPID = array_shift($splitFolder); if ($profileID != $this->mail_bo->profileID) continue; // only current connection
if ($fPID != $this->mail_bo->profileID) continue; // only current connection
$folderName = implode($del,$splitFolder);
if ($folderName) if ($folderName)
{ {
$fS = $this->mail_bo->getFolderStatus($folderName,false); $fS = $this->mail_bo->getFolderStatus($folderName,false);
@ -1358,6 +1416,8 @@ error_log(__METHOD__.__LINE__.' SelectedFolder:'.$query['selectedFolder'].' Star
*/ */
function ajax_changeProfile($icServerID) function ajax_changeProfile($icServerID)
{ {
if ($icServerID && $icServerID != $this->mail_bo->profileID)
error_log(__METHOD__.__LINE__.' change Profile to ->'.$icServerID);
$this->changeProfile($icServerID); $this->changeProfile($icServerID);
$response = egw_json_response::get(); $response = egw_json_response::get();
$response->call('egw_refresh',lang('changed profile'),'mail'); $response->call('egw_refresh',lang('changed profile'),'mail');

View File

@ -9,8 +9,10 @@
*/ */
var mail_doTimedRefresh; var mail_doTimedRefresh;
var mail_refreshTimeOut = 1000*10; // initial call var mail_refreshTimeOut = 1000*60*3; // initial call
mail_startTimerFolderStatusUpdate(mail_refreshTimeOut); mail_startTimerFolderStatusUpdate(mail_refreshTimeOut);
//inital call of refresh folderstatus
window.setTimeout('mail_refreshFolderStatus()',1000);
/** /**
* mail_startTimerFolderStatusUpdate, timer functions, if the counter changes for the current folder * mail_startTimerFolderStatusUpdate, timer functions, if the counter changes for the current folder
@ -27,15 +29,9 @@ function mail_startTimerFolderStatusUpdate(_refreshTimeOut) {
if(mail_doTimedRefresh) { if(mail_doTimedRefresh) {
window.clearTimeout(mail_doTimedRefresh); window.clearTimeout(mail_doTimedRefresh);
} }
if(_refreshTimeOut > 9999) {//we do not set _refreshTimeOut's less than 10 seconds (our initial call) if(_refreshTimeOut > 9999) {//we do not set _refreshTimeOut's less than 10 seconds
mail_doTimedRefresh = window.setInterval("mail_refreshFolderStatus()", _refreshTimeOut); mail_doTimedRefresh = window.setInterval("mail_refreshFolderStatus()", _refreshTimeOut);
} }
// initial call done -> now set the timeout to the timeout defined by pref
if(_refreshTimeOut == 10000)
{
var minutes = egw.preference('refreshTime','mail');
mail_refreshTimeOut = _refreshTimeOut= 1000*60*(minutes?minutes:3); // either the prefs or 3 Minutes
}
} }
/** /**
@ -242,6 +238,7 @@ function mail_changeFolder(folder,_widget) {
myMsg = (displayname?displayname:folder)+' '+egw.lang('selected'); myMsg = (displayname?displayname:folder)+' '+egw.lang('selected');
app_refresh(myMsg, 'mail'); app_refresh(myMsg, 'mail');
} }
//mail_refreshMessageGrid();
mail_refreshFolderStatus(folder,'forced'); mail_refreshFolderStatus(folder,'forced');
mail_startTimerFolderStatusUpdate(mail_refreshTimeOut); mail_startTimerFolderStatusUpdate(mail_refreshTimeOut);
} }