diff --git a/config.php b/config.php index f64d22f..ac536fc 100644 --- a/config.php +++ b/config.php @@ -2,8 +2,8 @@ /** Disable the import plugin for all clients */ define('PLUGIN_CONTACTIMPORTER_USER_DEFAULT_ENABLE', false); -/** The default addressbook to import to (default: contact)*/ -define('PLUGIN_CONTACTIMPORTER_DEFAULT', "contact"); +/** The default addressbook to import to (default: Kontakte or Contacts - depending on your language)*/ +define('PLUGIN_CONTACTIMPORTER_DEFAULT', "Kontakte"); /** Tempory path for uploaded files... */ define('PLUGIN_CONTACTIMPORTER_TMP_UPLOAD', "/var/lib/zarafa-webapp/tmp/"); diff --git a/js/dialogs/ImportPanel.js b/js/dialogs/ImportPanel.js index caf6a0e..c8083a2 100644 --- a/js/dialogs/ImportPanel.js +++ b/js/dialogs/ImportPanel.js @@ -132,14 +132,87 @@ Zarafa.plugins.contactimporter.dialogs.ImportPanel = Ext.extend(Ext.Panel, { }; }, - getAllContactFolders: function() { + getAllContactFolders: function(asDropdownStore) { + asDropdownStore = Ext.isEmpty(asDropdownStore) ? false : asDropdownStore; + var allFolders = []; - /** - * TODO: - * container.getHierarchyStore() -> 2 stores: inbux und public - * inbox -> substores -> alle folder! - */ + var defaultContactFolder = container.getHierarchyStore().getDefaultFolder('contact'); + + var inbox = container.getHierarchyStore().getDefaultStore(); + var pub = container.getHierarchyStore().getPublicStore(); + + if(!Ext.isEmpty(inbox.subStores) && inbox.subStores.folders.totalLength > 0) { + for(var i=0; i < inbox.subStores.folders.totalLength; i++) { + var folder = inbox.subStores.folders.getAt(i); + if(folder.get("container_class") == "IPF.Contact") { + if(asDropdownStore) { + allFolders.push([ + folder.get("entryid"), + folder.get("display_name") + ]); + } else { + allFolders.push({ + display_name : folder.get("display_name"), + entryid : folder.get("entryid"), + store_entryid: folder.get("store_entryid"), + is_public : false + }); + } + } + } + } + + if(!Ext.isEmpty(pub.subStores) && pub.subStores.folders.totalLength > 0) { + for(var j=0; j < pub.subStores.folders.totalLength; j++) { + var folder = pub.subStores.folders.getAt(j); + if(folder.get("container_class") == "IPF.Contact") { + if(asDropdownStore) { + allFolders.push([ + folder.get("entryid"), + folder.get("display_name") + " (Public)" + ]); + } else { + allFolders.push({ + display_name : folder.get("display_name"), + entryid : folder.get("entryid"), + store_entryid: folder.get("store_entryid"), + is_public : true + }); + } + } + } + } + + if(asDropdownStore) { + return allFolders.sort(this.dynamicSort(1)); + } else { + return allFolders; + } + }, + + dynamicSort: function(property) { + var sortOrder = 1; + if(property[0] === "-") { + sortOrder = -1; + property = property.substr(1); + } + return function (a,b) { + var result = (a[property].toLowerCase() < b[property].toLowerCase()) ? -1 : (a[property].toLowerCase() > b[property].toLowerCase()) ? 1 : 0; + return result * sortOrder; + } + }, + + getContactFolderByName: function(name) { + var folders = this.getAllContactFolders(false); + + for(var i=0; i