|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Ext.namespace('Tine.Felamimail'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Tine.Felamimail.FilterPanel = Ext.extend(Tine.widgets.persistentfilter.PickerPanel, { |
|
filterModel: 'Felamimail_Model_MessageFilter' |
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Tine.Felamimail.TreePanel = function(config) { |
|
Ext.apply(this, config); |
|
|
|
this.addEvents( |
|
|
|
|
|
|
|
|
|
|
|
'containeradd', |
|
|
|
|
|
|
|
|
|
|
|
'containerdelete', |
|
|
|
|
|
|
|
|
|
|
|
'containerrename' |
|
); |
|
|
|
Tine.Felamimail.TreePanel.superclass.constructor.call(this); |
|
}; |
|
|
|
Ext.extend(Tine.Felamimail.TreePanel, Ext.tree.TreePanel, { |
|
|
|
|
|
|
|
|
|
|
|
app: null, |
|
|
|
|
|
|
|
|
|
|
|
accountStore: null, |
|
|
|
|
|
|
|
|
|
folderStore: null, |
|
|
|
|
|
|
|
|
|
containerName: 'Folder', |
|
|
|
|
|
|
|
|
|
|
|
rootVisible: false, |
|
|
|
|
|
|
|
|
|
enableDrop: true, |
|
ddGroup: 'mailToTreeDDGroup', |
|
|
|
|
|
|
|
|
|
border: false, |
|
recordClass: Tine.Felamimail.Model.Account, |
|
filterMode: 'filterToolbar', |
|
|
|
|
|
|
|
|
|
selectContainerPath: Ext.emptyFn, |
|
|
|
|
|
|
|
|
|
|
|
initComponent: function() { |
|
|
|
this.folderStore = Tine.Tinebase.appMgr.get('Felamimail').getFolderStore(); |
|
|
|
|
|
this.loader = new Tine.Felamimail.TreeLoader({ |
|
folderStore: this.folderStore, |
|
app: this.app |
|
}); |
|
|
|
|
|
this.root = new Ext.tree.TreeNode({ |
|
text: 'default', |
|
draggable: false, |
|
allowDrop: false, |
|
expanded: true, |
|
leaf: false, |
|
id: 'root' |
|
}); |
|
|
|
|
|
this.initAccounts(); |
|
|
|
|
|
this.dropConfig = { |
|
ddGroup: this.ddGroup || 'TreeDD', |
|
appendOnly: this.ddAppendOnly === true, |
|
notifyEnter : function() {this.isDropSensitive = true;}.createDelegate(this), |
|
notifyOut : function() {this.isDropSensitive = false;}.createDelegate(this), |
|
onNodeOver : function(n, dd, e, data) { |
|
var node = n.node; |
|
|
|
|
|
if(!this.expandProcId && node.attributes.allowDrop && node.hasChildNodes() && !node.isExpanded()){ |
|
this.queueExpand(node); |
|
} else if (! node.attributes.allowDrop) { |
|
this.cancelExpand(); |
|
} |
|
return node.attributes.allowDrop ? 'tinebase-tree-drop-move' : false; |
|
}, |
|
isValidDropPoint: function(n, dd, e, data){ |
|
return n.node.attributes.allowDrop; |
|
} |
|
}; |
|
|
|
|
|
this.selModel = new Ext.tree.MultiSelectionModel({}); |
|
|
|
|
|
var initCtxMenu = Tine.Felamimail.setTreeContextMenus.createDelegate(this); |
|
initCtxMenu(); |
|
|
|
|
|
this.on('beforeclick', this.onBeforeClick, this); |
|
this.on('click', this.onClick, this); |
|
this.on('contextmenu', this.onContextMenu, this); |
|
this.on('beforenodedrop', this.onBeforenodedrop, this); |
|
this.on('append', this.onAppend, this); |
|
this.on('containeradd', this.onFolderAdd, this); |
|
this.on('containerrename', this.onFolderRename, this); |
|
this.on('containerdelete', this.onFolderDelete, this); |
|
this.selModel.on('selectionchange', this.onSelectionChange, this); |
|
this.folderStore.on('update', this.onUpdateFolderStore, this); |
|
|
|
|
|
Tine.Felamimail.TreePanel.superclass.initComponent.call(this); |
|
}, |
|
|
|
|
|
|
|
|
|
|
|
initAccounts: function() { |
|
this.accountStore = this.app.getAccountStore(); |
|
this.accountStore.each(this.addAccount, this); |
|
this.accountStore.on('update', this.onAccountUpdate, this); |
|
}, |
|
|
|
|
|
|
|
|
|
initToolTips: function() { |
|
this.folderTip = new Ext.ToolTip({ |
|
target: this.getEl(), |
|
delegate: 'a.x-tree-node-anchor', |
|
renderTo: document.body, |
|
listeners: {beforeshow: this.updateFolderTip.createDelegate(this)} |
|
}); |
|
|
|
this.folderProgressTip = new Ext.ToolTip({ |
|
target: this.getEl(), |
|
delegate: '.felamimail-node-statusbox-progress', |
|
renderTo: document.body, |
|
listeners: {beforeshow: this.updateProgressTip.createDelegate(this)} |
|
}); |
|
|
|
this.folderUnreadTip = new Ext.ToolTip({ |
|
target: this.getEl(), |
|
delegate: '.felamimail-node-statusbox-unread', |
|
renderTo: document.body, |
|
listeners: {beforeshow: this.updateUnreadTip.createDelegate(this)} |
|
}); |
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
onSelectionChange: function(sm, nodes) { |
|
if (this.filterMode == 'gridFilter' && this.filterPlugin) { |
|
this.filterPlugin.onFilterChange(); |
|
} |
|
if (this.filterMode == 'filterToolbar' && this.filterPlugin) { |
|
|
|
|
|
var ftb = this.filterPlugin.getGridPanel().filterToolbar; |
|
|
|
ftb = ftb.activeFilterPanel ? ftb.activeFilterPanel : ftb; |
|
|
|
if (! ftb.rendered) { |
|
this.onSelectionChange.defer(150, this, [sm, nodes]); |
|
return; |
|
} |
|
|
|
|
|
ftb.supressEvents = true; |
|
ftb.filterStore.each(function(filter) { |
|
var field = filter.get('field'); |
|
if (field === 'path') { |
|
ftb.deleteFilter(filter); |
|
} |
|
}, this); |
|
ftb.supressEvents = false; |
|
|
|
|
|
var filter = this.getFilterPlugin().getFilter(); |
|
ftb.addFilter(new ftb.record(filter)); |
|
|
|
ftb.onFiltertrigger(); |
|
|
|
|
|
sm.suspendEvents(); |
|
Ext.each(nodes, function(node) { |
|
sm.select(node, Ext.EventObject, true); |
|
}, this); |
|
sm.resumeEvents(); |
|
} |
|
}, |
|
|
|
onFilterChange: Tine.widgets.container.TreePanel.prototype.onFilterChange, |
|
|
|
|
|
|
|
|
|
|
|
getFilterPlugin: function() { |
|
if (!this.filterPlugin) { |
|
this.filterPlugin = new Tine.widgets.tree.FilterPlugin({ |
|
treePanel: this, |
|
field: 'path', |
|
nodeAttributeField: 'path', |
|
singleNodeOperator: 'in' |
|
}); |
|
} |
|
|
|
return this.filterPlugin; |
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getTreePath: function(path) { |
|
return '/root' + path; |
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
afterRender: function() { |
|
Tine.Felamimail.TreePanel.superclass.afterRender.call(this); |
|
this.initToolTips(); |
|
this.selectInbox(); |
|
|
|
if (this.filterMode == 'filterToolbar' && this.filterPlugin) { |
|
this.filterPlugin.getGridPanel().filterToolbar.on('change', this.onFilterChange, this); |
|
} |
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
selectInbox: function(account) { |
|
var accountId = (account) ? account.id : Tine.Felamimail.registry.get('preferences').get('defaultEmailAccount'); |
|
|
|
this.expandPath('/root/' + accountId + '/', null, function(success, parentNode) { |
|
Ext.each(parentNode.childNodes, function(node) { |
|
if (Ext.util.Format.lowercase(node.attributes.localname) == 'inbox') { |
|
node.select(); |
|
return false; |
|
} |
|
}, this); |
|
}); |
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
onAccountUpdate: function(store, record, action) { |
|
if (action === Ext.data.Record.EDIT) { |
|
this.updateAccountStatus(record); |
|
} |
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
onAppend: function(tree, node, appendedNode, index) { |
|
appendedNode.ui.render = appendedNode.ui.render.createSequence(function() { |
|
var app = Tine.Tinebase.appMgr.get('Felamimail'), |
|
folder = app.getFolderStore().getById(appendedNode.id); |
|
|
|
if (folder) { |
|
app.getMainScreen().getTreePanel().addStatusboxesToNodeUi(this); |
|
app.getMainScreen().getTreePanel().updateFolderStatus(folder); |
|
} |
|
}, appendedNode.ui); |
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
addStatusboxesToNodeUi: function(nodeUi) { |
|
Ext.DomHelper.insertAfter(nodeUi.elNode.lastChild, {tag: 'span', 'class': 'felamimail-node-statusbox', cn:[ |
|
{'tag': 'img', 'src': Ext.BLANK_IMAGE_URL, 'class': 'felamimail-node-statusbox-progress'}, |
|
{'tag': 'span', 'class': 'felamimail-node-statusbox-unread'} |
|
]}); |
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
onBeforeClick: function(node) { |
|
if (this.accountStore.getById(node.id) || ! this.app.getFolderStore().getById(node.id).get('is_selectable')) { |
|
return false; |
|
} |
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
onClick: function(node) { |
|
if (node.expandable) { |
|
node.expand(); |
|
} |
|
|
|
if (node.id && node.id != '/' && node.attributes.globalname != '') { |
|
var folder = this.app.getFolderStore().getById(node.id); |
|
this.app.checkMailsDelayedTask.delay(0); |
|
} |
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
onContextMenu: function(node, event) { |
|
this.ctxNode = node; |
|
|
|
var folder = this.app.getFolderStore().getById(node.id), |
|
account = folder ? this.accountStore.getById(folder.get('account_id')) : |
|
this.accountStore.getById(node.id); |
|
|
|
if (! folder) { |
|
|
|
if (account.get('ns_personal') !== 'default') { |
|
this.contextMenuAccount.items.each(function(item) { |
|
|
|
if (item.iconCls == 'action_add') { |
|
item.setDisabled(account.get('ns_personal') != ''); |
|
} |
|
|
|
if (item.iconCls == 'action_email_replyAll' || item.iconCls == 'action_email_forward') { |
|
item.setDisabled(account.get('sieve_hostname') == null || account.get('sieve_hostname') == ''); |
|
} |
|
}); |
|
|
|
this.contextMenuAccount.showAt(event.getXY()); |
|
} |
|
} else { |
|
if (folder.get('globalname') === account.get('trash_folder') || folder.get('localname').match(/junk/i)) { |
|
this.contextMenuTrash.showAt(event.getXY()); |
|
} else if (! folder.get('is_selectable')){ |
|
this.unselectableFolder.showAt(event.getXY()); |
|
} else if (folder.get('system_folder')) { |
|
this.contextMenuSystemFolder.showAt(event.getXY()); |
|
} else { |
|
this.contextMenuUserFolder.showAt(event.getXY()); |
|
} |
|
} |
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
onBeforenodedrop: function(dropEvent) { |
|
var targetFolderId = dropEvent.target.attributes.folder_id, |
|
targetFolder = this.app.getFolderStore().getById(targetFolderId); |
|
|
|
this.app.getMainScreen().getCenterPanel().moveSelectedMessages(targetFolder, false); |
|
return true; |
|
}, |
|
|
|
|
|
|
|
|
|
onDestroy: function() { |
|
this.folderStore.un('update', this.onUpdateFolderStore, this); |
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
onUpdateFolderStore: function(store, record, operation) { |
|
if (operation === Ext.data.Record.EDIT) { |
|
this.updateFolderStatus(record); |
|
} |
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
onFolderAdd: function(folderData) { |
|
var recordData = Ext.copyTo({}, folderData, Tine.Felamimail.Model.Folder.getFieldNames()); |
|
var newRecord = Tine.Felamimail.folderBackend.recordReader({responseText: Ext.util.JSON.encode(recordData)}); |
|
|
|
Tine.log.debug('Added new folder:' + newRecord.get('globalname')); |
|
|
|
this.folderStore.add([newRecord]); |
|
this.initNewFolderNode(newRecord); |
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
initNewFolderNode: function(newRecord) { |
|
|
|
var appendedNode = this.getNodeById(newRecord.id); |
|
|
|
if (! appendedNode) { |
|
|
|
var parentId = newRecord.get('parent_path').split('/').pop(), |
|
parentNode = this.getNodeById(parentId); |
|
parentNode.reload(function() { |
|
this.initNewFolderNode(newRecord); |
|
}, this); |
|
return; |
|
} |
|
|
|
appendedNode.attributes.path = newRecord.get('path'); |
|
appendedNode.attributes.parent_path = newRecord.get('parent_path'); |
|
|
|
|
|
this.addStatusboxesToNodeUi(appendedNode.ui); |
|
this.updateFolderStatus(newRecord); |
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
onFolderRename: function(folderData) { |
|
var record = this.folderStore.getById(folderData.id); |
|
record.set('globalname', folderData.globalname); |
|
record.set('localname', folderData.localname); |
|
|
|
Tine.log.debug('Renamed folder:' + record.get('globalname')); |
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
onFolderDelete: function(folderData) { |
|
|
|
if (folderData.record && folderData.record.modelName === 'Account') { |
|
this.accountStore.remove(this.accountStore.getById(folderData.id)); |
|
} |
|
|
|
this.folderStore.remove(this.folderStore.getById(folderData.id)); |
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getElsParentsNodeId: function(el) { |
|
return Ext.fly(el, '_treeEvents').up('div[class^=x-tree-node-el]').getAttribute('tree-node-id', 'ext'); |
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
updateAccountStatus: function(account) { |
|
var imapStatus = account.get('imap_status'), |
|
node = this.getNodeById(account.id), |
|
ui = node ? node.getUI() : null, |
|
nodeEl = ui ? ui.getEl() : null; |
|
|
|
Tine.log.info('Account ' + account.get('name') + ' updated with imap_status: ' + imapStatus); |
|
if (node && node.ui.rendered) { |
|
var statusEl = Ext.get(Ext.DomQuery.selectNode('span[class=felamimail-node-accountfailure]', nodeEl)); |
|
if (! statusEl) { |
|
|
|
statusEl = Ext.DomHelper.insertAfter(ui.elNode.lastChild, {'tag': 'span', 'class': 'felamimail-node-accountfailure'}, true); |
|
statusEl.on('click', function() { |
|
Tine.Felamimail.folderBackend.handleRequestException(account.getLastIMAPException()); |
|
}, this); |
|
} |
|
|
|
statusEl.setVisible(imapStatus === 'failure'); |
|
} |
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
updateFolderStatus: function(folder) { |
|
var unreadcount = folder.get('cache_unreadcount'), |
|
progress = Math.round(folder.get('cache_job_actions_done') / folder.get('cache_job_actions_est') * 10) * 10, |
|
node = this.getNodeById(folder.id), |
|
ui = node ? node.getUI() : null, |
|
nodeEl = ui ? ui.getEl() : null, |
|
cacheStatus = folder.get('cache_status'), |
|
lastCacheStatus = folder.modified ? folder.modified.cache_status : null, |
|
isSelected = folder.isCurrentSelection(); |
|
|
|
this.setUnreadClass(folder.id); |
|
|
|
if (node && node.ui.rendered) { |
|
var domNode = Ext.DomQuery.selectNode('span[class=felamimail-node-statusbox-unread]', nodeEl); |
|
if (domNode) { |
|
|
|
|
|
Ext.fly(domNode).update(unreadcount).setVisible(unreadcount > 0); |
|
|
|
|
|
var progressEl = Ext.get(Ext.DomQuery.selectNode('img[class^=felamimail-node-statusbox-progress]', nodeEl)); |
|
progressEl.removeClass(['felamimail-node-statusbox-progress-pie', 'felamimail-node-statusbox-progress-loading']); |
|
if (! Ext.isNumber(progress)) { |
|
progressEl.setStyle('background-position', 0 + 'px'); |
|
progressEl.addClass('felamimail-node-statusbox-progress-loading'); |
|
} else { |
|
progressEl.setStyle('background-position', progress + '%'); |
|
progressEl.addClass('felamimail-node-statusbox-progress-pie'); |
|
} |
|
progressEl.setVisible(isSelected && cacheStatus !== 'complete' && cacheStatus !== 'disconnect' && progress !== 100 && lastCacheStatus !== 'complete'); |
|
} |
|
} |
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setUnreadClass: function(folderId) { |
|
var folder = this.app.getFolderStore().getById(folderId), |
|
node = this.getNodeById(folderId), |
|
isUnread = folder.get('cache_unreadcount') > 0, |
|
hasUnreadChildren = folder.get('unread_children').length > 0; |
|
|
|
if (node && node.ui.rendered) { |
|
var ui = node.getUI(); |
|
ui[(isUnread || hasUnreadChildren) ? 'addClass' : 'removeClass']('felamimail-node-unread'); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
updateFolderTip: function(tip) { |
|
var folderId = this.getElsParentsNodeId(tip.triggerElement), |
|
folder = this.app.getFolderStore().getById(folderId), |
|
account = this.accountStore.getById(folderId); |
|
|
|
if (folder && !this.isDropSensitive) { |
|
var info = [ |
|
'<table>', |
|
'<tr>', |
|
'<td>', this.app.i18n._('Total Messages:'), '</td>', |
|
'<td>', folder.get('cache_totalcount'), '</td>', |
|
'</tr>', |
|
'<tr>', |
|
'<td>', this.app.i18n._('Unread Messages:'), '</td>', |
|
'<td>', folder.get('cache_unreadcount'), '</td>', |
|
'</tr>', |
|
'<tr>', |
|
'<td>', this.app.i18n._('Name on Server:'), '</td>', |
|
'<td>', folder.get('globalname'), '</td>', |
|
'</tr>', |
|
'<tr>', |
|
'<td>', this.app.i18n._('Last update:'), '</td>', |
|
'<td>', Tine.Tinebase.common.dateTimeRenderer(folder.get('client_access_time')), '</td>', |
|
'</tr>', |
|
'</table>' |
|
]; |
|
tip.body.dom.innerHTML = info.join(''); |
|
} else { |
|
return false; |
|
} |
|
}, |
|
|
|
|
|
|
|
|
|
|
|
updateProgressTip: function(tip) { |
|
var folderId = this.getElsParentsNodeId(tip.triggerElement), |
|
folder = this.app.getFolderStore().getById(folderId), |
|
progress = Math.round(folder.get('cache_job_actions_done') / folder.get('cache_job_actions_est') * 100); |
|
if (! this.isDropSensitive) { |
|
tip.body.dom.innerHTML = String.format(this.app.i18n._('Fetching messages... ({0} done)'), progress + '%'); |
|
} else { |
|
return false; |
|
} |
|
}, |
|
|
|
|
|
|
|
|
|
|
|
updateUnreadTip: function(tip) { |
|
var folderId = this.getElsParentsNodeId(tip.triggerElement), |
|
folder = this.app.getFolderStore().getById(folderId), |
|
count = folder.get('cache_unreadcount'); |
|
|
|
if (! this.isDropSensitive) { |
|
tip.body.dom.innerHTML = String.format(this.app.i18n.ngettext('{0} unread message', '{0} unread messages', count), count); |
|
} else { |
|
return false; |
|
} |
|
}, |
|
|
|
|
|
|
|
|
|
decrementCurrentUnreadCount: function() { |
|
var store = Tine.Tinebase.appMgr.get('Felamimail').getFolderStore(), |
|
node = this.getSelectionModel().getSelectedNode(), |
|
folder = node ? store.getById(node.id) : null; |
|
|
|
if (folder) { |
|
folder.set('cache_unreadcount', parseInt(folder.get('cache_unreadcount'), 10) -1); |
|
folder.commit(); |
|
} |
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
addAccount: function(record) { |
|
|
|
var node = new Ext.tree.AsyncTreeNode({ |
|
id: record.data.id, |
|
path: '/' + record.data.id, |
|
record: record, |
|
globalname: '', |
|
draggable: false, |
|
allowDrop: false, |
|
expanded: false, |
|
text: Ext.util.Format.htmlEncode(record.get('name')), |
|
|
|
|
|
|
|
qtip: Ext.util.Format.htmlEncode(record.get('host')), |
|
leaf: false, |
|
cls: 'felamimail-node-account', |
|
delimiter: record.get('delimiter'), |
|
ns_personal: record.get('ns_personal'), |
|
account_id: record.data.id, |
|
listeners: { |
|
scope: this, |
|
load: function(node) { |
|
var account = this.accountStore.getById(node.id); |
|
this.updateAccountStatus(account); |
|
} |
|
} |
|
}); |
|
|
|
|
|
this.suspendEvents(); |
|
this.root.appendChild(node); |
|
this.resumeEvents(); |
|
}, |
|
|
|
|
|
|
|
|
|
|
|
getActiveAccount: function() { |
|
var result = null; |
|
var node = this.getSelectionModel().getSelectedNode(); |
|
if (node) { |
|
var accountId = node.attributes.account_id; |
|
result = this.accountStore.getById(accountId); |
|
} |
|
|
|
return result; |
|
} |
|
}); |
|
|