Import code cleanup

This commit is contained in:
Christoph Haas 2016-06-19 00:22:30 +02:00
parent 5c98fe9e56
commit b61e6c7392

View File

@ -230,6 +230,23 @@ Zarafa.plugins.contactimporter.dialogs.ImportPanel = Ext.extend(Ext.Panel, {
return container.getHierarchyStore().getDefaultFolder('contact'); return container.getHierarchyStore().getDefaultFolder('contact');
}, },
/**
* Return a contact folder element by entryid.
* @param {string} entryid
* @returns {*}
*/
getContactFolderByEntryid: function (entryid) {
var folders = this.getAllContactFolders(false);
for (var i = 0; i < folders.length; i++) {
if (folders[i].entryid == entryid) {
return folders[i];
}
}
return container.getHierarchyStore().getDefaultFolder('contact');
},
/** /**
* Reloads the data of the grid * Reloads the data of the grid
* @private * @private
@ -517,7 +534,6 @@ Zarafa.plugins.contactimporter.dialogs.ImportPanel = Ext.extend(Ext.Panel, {
buttons: Zarafa.common.dialogs.MessageBox.OK buttons: Zarafa.common.dialogs.MessageBox.OK
}); });
} else { } else {
var addressbookexist = true;
if (this.contactGrid.selModel.getCount() < 1) { if (this.contactGrid.selModel.getCount() < 1) {
Zarafa.common.dialogs.MessageBox.show({ Zarafa.common.dialogs.MessageBox.show({
title : _('Error'), title : _('Error'),
@ -526,50 +542,15 @@ Zarafa.plugins.contactimporter.dialogs.ImportPanel = Ext.extend(Ext.Panel, {
buttons: Zarafa.common.dialogs.MessageBox.OK buttons: Zarafa.common.dialogs.MessageBox.OK
}); });
} else { } else {
var contactStore = new Zarafa.contact.ContactStore(); var contactFolder = this.getContactFolderByEntryid(folderValue);
var contactFolder = container.getHierarchyStore().getDefaultFolder('contact');
var pubStore = container.getHierarchyStore().getPublicStore();
var pubFolder = pubStore.getDefaultFolder("publicfolders");
var pubSubFolders = pubFolder.getChildren();
if (folderValue != "contact") {
var subFolders = contactFolder.getChildren();
var i = 0;
for (i = 0; i < pubSubFolders.length; i++) {
if (pubSubFolders[i].isContainerClass("IPF.Contact")) {
subFolders.push(pubSubFolders[i]);
}
}
for (i = 0; i < subFolders.length; i++) {
// look up right folder
// TODO: improve!!
if (subFolders[i].getDisplayName() == folderValue) {
contactFolder = subFolders[i];
break;
}
}
if (contactFolder.isDefaultFolder()) {
Zarafa.common.dialogs.MessageBox.show({
title : _('Error'),
msg : _('Selected addressbook does not exist!'),
icon : Zarafa.common.dialogs.MessageBox.ERROR,
buttons: Zarafa.common.dialogs.MessageBox.OK
});
addressbookexist = false;
}
}
if (addressbookexist) {
this.loadMask.show(); this.loadMask.show();
var uids = []; var uids = [];
var store_entryid = "";
//receive Records from grid rows //receive Records from grid rows
Ext.each(contacts, function (newRecord) { Ext.each(contacts, function (newRecord) {
uids.push(newRecord.data.record.internal_fields.contact_uid); uids.push(newRecord.data.record.internal_fields.contact_uid);
}, this); }, this);
store_entryid = contactFolder.get('store_entryid');
var responseHandler = new Zarafa.plugins.contactimporter.data.ResponseHandler({ var responseHandler = new Zarafa.plugins.contactimporter.data.ResponseHandler({
successCallback: this.importContactsDone.createDelegate(this) successCallback: this.importContactsDone.createDelegate(this)
@ -579,15 +560,13 @@ Zarafa.plugins.contactimporter.dialogs.ImportPanel = Ext.extend(Ext.Panel, {
'contactmodule', 'contactmodule',
'import', 'import',
{ {
storeid : contactFolder.get("store_entryid"), storeid : contactFolder.store_entryid,
folderid : contactFolder.get("entryid"), folderid : contactFolder.entryid,
uids : uids, uids : uids,
vcf_filepath: this.vcffile vcf_filepath: this.vcffile
}, },
responseHandler responseHandler
); );
}
} }
} }
}, },