Import code cleanup

This commit is contained in:
Christoph Haas 2016-06-19 00:22:30 +02:00
parent 5c98fe9e56
commit b61e6c7392
1 changed files with 38 additions and 59 deletions

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,68 +542,31 @@ 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") { this.loadMask.show();
var subFolders = contactFolder.getChildren(); var uids = [];
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()) { //receive Records from grid rows
Zarafa.common.dialogs.MessageBox.show({ Ext.each(contacts, function (newRecord) {
title : _('Error'), uids.push(newRecord.data.record.internal_fields.contact_uid);
msg : _('Selected addressbook does not exist!'), }, this);
icon : Zarafa.common.dialogs.MessageBox.ERROR,
buttons: Zarafa.common.dialogs.MessageBox.OK
});
addressbookexist = false;
}
}
if (addressbookexist) { var responseHandler = new Zarafa.plugins.contactimporter.data.ResponseHandler({
this.loadMask.show(); successCallback: this.importContactsDone.createDelegate(this)
var uids = []; });
var store_entryid = "";
//receive Records from grid rows container.getRequest().singleRequest(
Ext.each(contacts, function (newRecord) { 'contactmodule',
uids.push(newRecord.data.record.internal_fields.contact_uid); 'import',
}, this); {
store_entryid = contactFolder.get('store_entryid'); storeid : contactFolder.store_entryid,
folderid : contactFolder.entryid,
var responseHandler = new Zarafa.plugins.contactimporter.data.ResponseHandler({ uids : uids,
successCallback: this.importContactsDone.createDelegate(this) vcf_filepath: this.vcffile
}); },
responseHandler
container.getRequest().singleRequest( );
'contactmodule',
'import',
{
storeid : contactFolder.get("store_entryid"),
folderid : contactFolder.get("entryid"),
uids : uids,
vcf_filepath: this.vcffile
},
responseHandler
);
}
} }
} }
}, },