reworked folder selection

hide dropdown if import via context menu
This commit is contained in:
Christoph Haas 2016-06-16 21:37:55 +02:00
parent 2f07db6775
commit e0eb5cf1f0
2 changed files with 84 additions and 38 deletions

View File

@ -2,8 +2,8 @@
/** Disable the import plugin for all clients */ /** Disable the import plugin for all clients */
define('PLUGIN_CONTACTIMPORTER_USER_DEFAULT_ENABLE', false); define('PLUGIN_CONTACTIMPORTER_USER_DEFAULT_ENABLE', false);
/** The default addressbook to import to (default: contact)*/ /** The default addressbook to import to (default: Kontakte or Contacts - depending on your language)*/
define('PLUGIN_CONTACTIMPORTER_DEFAULT', "contact"); define('PLUGIN_CONTACTIMPORTER_DEFAULT', "Kontakte");
/** Tempory path for uploaded files... */ /** Tempory path for uploaded files... */
define('PLUGIN_CONTACTIMPORTER_TMP_UPLOAD', "/var/lib/zarafa-webapp/tmp/"); define('PLUGIN_CONTACTIMPORTER_TMP_UPLOAD', "/var/lib/zarafa-webapp/tmp/");

View File

@ -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 = []; var allFolders = [];
/** var defaultContactFolder = container.getHierarchyStore().getDefaultFolder('contact');
* TODO:
* container.getHierarchyStore() -> 2 stores: inbux und public var inbox = container.getHierarchyStore().getDefaultStore();
* inbox -> substores -> alle folder! 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<folders.length; i++) {
if(folders[i].display_name == name) {
return folders[i];
}
}
return container.getHierarchyStore().getDefaultFolder('contact');
}, },
/** /**
@ -204,42 +277,14 @@ Zarafa.plugins.contactimporter.dialogs.ImportPanel = Ext.extend(Ext.Panel, {
}, },
createSelectBox: function () { createSelectBox: function () {
var defaultFolder = container.getHierarchyStore().getDefaultFolder('contact'); // @type: Zarafa.hierarchy.data.MAPIFolderRecord var myStore = this.getAllContactFolders(true);
var subFolders = defaultFolder.getChildren();
var myStore = [];
/* add all local contact folders */
var i = 0;
myStore.push([defaultFolder.getDefaultFolderKey(), defaultFolder.getDisplayName()]);
for (i = 0; i < subFolders.length; i++) {
/* Store all subfolders */
myStore.push([subFolders[i].getDisplayName(), subFolders[i].getDisplayName(), false]); // 3rd field = isPublicfolder
}
/* add all shared contact folders */
var pubStore = container.getHierarchyStore().getPublicStore();
if (typeof pubStore !== "undefined") {
try {
var pubFolder = pubStore.getDefaultFolder("publicfolders");
var pubSubFolders = pubFolder.getChildren();
for (i = 0; i < pubSubFolders.length; i++) {
if (pubSubFolders[i].isContainerClass("IPF.Contact")) {
myStore.push([pubSubFolders[i].getDisplayName(), pubSubFolders[i].getDisplayName() + " [Shared]", true]); // 3rd field = isPublicfolder
}
}
} catch (e) {
console.log("Error opening the shared folder...");
console.log(e);
}
}
return { return {
xtype : "selectbox", xtype : "selectbox",
ref : 'addressbookSelector', ref : 'addressbookSelector',
editable : false, editable : false,
name : "choosen_addressbook", name : "choosen_addressbook",
value : container.getSettingsModel().get("zarafa/v1/plugins/contactimporter/default_addressbook"), value : Ext.isEmpty(this.folder) ? this.getContactFolderByName(container.getSettingsModel().get("zarafa/v1/plugins/contactimporter/default_addressbook")).entryid : this.folder,
width : 100, width : 100,
fieldLabel : "Select folder", fieldLabel : "Select folder",
store : myStore, store : myStore,
@ -248,6 +293,7 @@ Zarafa.plugins.contactimporter.dialogs.ImportPanel = Ext.extend(Ext.Panel, {
border : false, border : false,
anchor : "100%", anchor : "100%",
scope : this, scope : this,
hidden : Ext.isEmpty(this.folder) ? false : true,
allowBlank : false allowBlank : false
} }
}, },