2013-05-20 23:09:51 +02:00
|
|
|
/**
|
|
|
|
* ImportPanel.js zarafa contact to vcf im/exporter
|
|
|
|
*
|
|
|
|
* Author: Christoph Haas <christoph.h@sprinternet.at>
|
2016-06-13 22:59:05 +02:00
|
|
|
* Copyright (C) 2012-2016 Christoph Haas
|
2013-05-20 23:09:51 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2016-06-13 22:59:05 +02:00
|
|
|
*
|
2013-05-20 23:09:51 +02:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ImportPanel
|
|
|
|
*
|
|
|
|
* The main Panel of the contactimporter plugin.
|
|
|
|
*/
|
2016-06-13 22:59:05 +02:00
|
|
|
Ext.namespace("Zarafa.plugins.contactimporter.dialogs");
|
2013-05-20 23:09:51 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @class Zarafa.plugins.contactimporter.dialogs.ImportPanel
|
2016-06-19 00:16:25 +02:00
|
|
|
* @extends Ext.Panel
|
2013-05-20 23:09:51 +02:00
|
|
|
*/
|
|
|
|
Zarafa.plugins.contactimporter.dialogs.ImportPanel = Ext.extend(Ext.Panel, {
|
|
|
|
|
|
|
|
/* path to vcf file on server... */
|
|
|
|
vcffile: null,
|
2016-06-13 22:59:05 +02:00
|
|
|
|
2013-05-20 23:09:51 +02:00
|
|
|
/* The store for the selection grid */
|
2016-06-13 22:59:05 +02:00
|
|
|
store : null,
|
2013-05-20 23:09:51 +02:00
|
|
|
|
2016-06-14 00:57:00 +02:00
|
|
|
/* selected folder */
|
|
|
|
folder : null,
|
|
|
|
|
2013-05-20 23:09:51 +02:00
|
|
|
/**
|
|
|
|
* @constructor
|
|
|
|
* @param {object} config
|
|
|
|
*/
|
2016-06-13 22:59:05 +02:00
|
|
|
constructor: function (config) {
|
2013-05-20 23:09:51 +02:00
|
|
|
config = config || {};
|
|
|
|
var self = this;
|
2016-06-13 22:59:05 +02:00
|
|
|
|
|
|
|
if (!Ext.isEmpty(config.filename)) {
|
2013-05-20 23:09:51 +02:00
|
|
|
this.vcffile = config.filename;
|
|
|
|
}
|
2016-06-13 22:59:05 +02:00
|
|
|
|
2016-06-14 00:57:00 +02:00
|
|
|
if (!Ext.isEmpty(config.folder)) {
|
|
|
|
this.folder = config.folder;
|
|
|
|
}
|
|
|
|
|
2013-05-20 23:09:51 +02:00
|
|
|
// create the data store
|
|
|
|
// we only display the firstname, lastname, homephone and primary email address in our grid
|
|
|
|
this.store = new Ext.data.ArrayStore({
|
|
|
|
fields: [
|
|
|
|
{name: 'display_name'},
|
|
|
|
{name: 'given_name'},
|
|
|
|
{name: 'surname'},
|
|
|
|
{name: 'company_name'},
|
|
|
|
{name: 'record'}
|
|
|
|
]
|
|
|
|
});
|
2016-06-13 22:59:05 +02:00
|
|
|
|
2013-05-20 23:09:51 +02:00
|
|
|
Ext.apply(config, {
|
2016-06-13 22:59:05 +02:00
|
|
|
xtype : 'contactimporter.importpanel',
|
|
|
|
ref : "importcontactpanel",
|
|
|
|
layout : {
|
|
|
|
type : 'form',
|
|
|
|
align: 'stretch'
|
2013-05-20 23:09:51 +02:00
|
|
|
},
|
2016-06-13 22:59:05 +02:00
|
|
|
anchor : '100%',
|
|
|
|
bodyStyle: 'background-color: inherit;',
|
|
|
|
defaults : {
|
|
|
|
border : true,
|
|
|
|
bodyStyle: 'background-color: inherit; padding: 3px 0px 3px 0px; border-style: none none solid none;'
|
2013-05-20 23:09:51 +02:00
|
|
|
},
|
2016-06-13 22:59:05 +02:00
|
|
|
items : [
|
2013-05-20 23:09:51 +02:00
|
|
|
this.createSelectBox(),
|
|
|
|
this.initForm(),
|
|
|
|
this.createGrid()
|
|
|
|
],
|
2016-06-13 22:59:05 +02:00
|
|
|
buttons : [
|
2013-05-20 23:09:51 +02:00
|
|
|
this.createSubmitAllButton(),
|
|
|
|
this.createSubmitButton(),
|
|
|
|
this.createCancelButton()
|
2016-06-13 22:59:05 +02:00
|
|
|
],
|
2013-05-20 23:09:51 +02:00
|
|
|
listeners: {
|
|
|
|
afterrender: function (cmp) {
|
2016-06-13 22:59:05 +02:00
|
|
|
this.loadMask = new Ext.LoadMask(this.getEl(), {msg: 'Loading...'});
|
|
|
|
|
|
|
|
if (this.vcffile != null) { // if we have got the filename from an attachment
|
2013-05-20 23:09:51 +02:00
|
|
|
this.parseContacts(this.vcffile);
|
|
|
|
}
|
|
|
|
},
|
2016-06-13 22:59:05 +02:00
|
|
|
scope : this
|
2013-05-20 23:09:51 +02:00
|
|
|
}
|
|
|
|
});
|
2016-06-13 22:59:05 +02:00
|
|
|
|
2013-05-20 23:09:51 +02:00
|
|
|
Zarafa.plugins.contactimporter.dialogs.ImportPanel.superclass.constructor.call(this, config);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Init embedded form, this is the form that is
|
|
|
|
* posted and contains the attachments
|
|
|
|
* @private
|
|
|
|
*/
|
2016-06-13 22:59:05 +02:00
|
|
|
initForm: function () {
|
2013-05-20 23:09:51 +02:00
|
|
|
return {
|
2016-06-13 22:59:05 +02:00
|
|
|
xtype : 'form',
|
|
|
|
ref : 'addContactFormPanel',
|
|
|
|
layout : 'column',
|
2013-05-20 23:09:51 +02:00
|
|
|
fileUpload: true,
|
2016-06-13 22:59:05 +02:00
|
|
|
autoWidth : true,
|
2013-05-20 23:09:51 +02:00
|
|
|
autoHeight: true,
|
2016-06-13 22:59:05 +02:00
|
|
|
border : false,
|
|
|
|
bodyStyle : 'padding: 5px;',
|
|
|
|
defaults : {
|
|
|
|
anchor : '95%',
|
|
|
|
border : false,
|
2013-05-20 23:09:51 +02:00
|
|
|
bodyStyle: 'padding: 5px;'
|
|
|
|
},
|
2016-06-13 22:59:05 +02:00
|
|
|
items : [this.createUploadField()]
|
2013-05-20 23:09:51 +02:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2016-06-19 00:16:25 +02:00
|
|
|
/**
|
|
|
|
* Get all contact folders.
|
|
|
|
* @param {boolean} asDropdownStore If true, a simple array store will be returned.
|
|
|
|
* @returns {*}
|
|
|
|
*/
|
|
|
|
getAllContactFolders: function (asDropdownStore) {
|
2016-06-16 21:37:55 +02:00
|
|
|
asDropdownStore = Ext.isEmpty(asDropdownStore) ? false : asDropdownStore;
|
|
|
|
|
2016-06-14 01:18:00 +02:00
|
|
|
var allFolders = [];
|
|
|
|
|
2016-06-16 21:37:55 +02:00
|
|
|
var defaultContactFolder = container.getHierarchyStore().getDefaultFolder('contact');
|
|
|
|
|
|
|
|
var inbox = container.getHierarchyStore().getDefaultStore();
|
|
|
|
var pub = container.getHierarchyStore().getPublicStore();
|
|
|
|
|
2016-06-19 00:16:25 +02:00
|
|
|
if (!Ext.isEmpty(inbox.subStores) && inbox.subStores.folders.totalLength > 0) {
|
|
|
|
for (var i = 0; i < inbox.subStores.folders.totalLength; i++) {
|
2016-06-16 21:37:55 +02:00
|
|
|
var folder = inbox.subStores.folders.getAt(i);
|
2016-06-19 00:16:25 +02:00
|
|
|
if (folder.get("container_class") == "IPF.Contact") {
|
|
|
|
if (asDropdownStore) {
|
2016-06-16 21:37:55 +02:00
|
|
|
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
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-19 00:16:25 +02:00
|
|
|
if (!Ext.isEmpty(pub.subStores) && pub.subStores.folders.totalLength > 0) {
|
|
|
|
for (var j = 0; j < pub.subStores.folders.totalLength; j++) {
|
2016-06-16 21:37:55 +02:00
|
|
|
var folder = pub.subStores.folders.getAt(j);
|
2016-06-19 00:16:25 +02:00
|
|
|
if (folder.get("container_class") == "IPF.Contact") {
|
|
|
|
if (asDropdownStore) {
|
2016-06-16 21:37:55 +02:00
|
|
|
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
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-19 00:16:25 +02:00
|
|
|
if (asDropdownStore) {
|
2016-06-16 21:37:55 +02:00
|
|
|
return allFolders.sort(this.dynamicSort(1));
|
|
|
|
} else {
|
|
|
|
return allFolders;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-06-19 00:16:25 +02:00
|
|
|
/**
|
|
|
|
* Dynamic sort function, sorts by property name.
|
|
|
|
* @param {string|int} property
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
dynamicSort: function (property) {
|
2016-06-16 21:37:55 +02:00
|
|
|
var sortOrder = 1;
|
2016-06-19 00:16:25 +02:00
|
|
|
if (property[0] === "-") {
|
2016-06-16 21:37:55 +02:00
|
|
|
sortOrder = -1;
|
|
|
|
property = property.substr(1);
|
|
|
|
}
|
2016-06-19 00:16:25 +02:00
|
|
|
return function (a, b) {
|
2016-06-16 21:37:55 +02:00
|
|
|
var result = (a[property].toLowerCase() < b[property].toLowerCase()) ? -1 : (a[property].toLowerCase() > b[property].toLowerCase()) ? 1 : 0;
|
|
|
|
return result * sortOrder;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-06-19 00:16:25 +02:00
|
|
|
/**
|
|
|
|
* Return a contact folder element by name.
|
|
|
|
* @param {string} name
|
|
|
|
* @returns {*}
|
|
|
|
*/
|
|
|
|
getContactFolderByName: function (name) {
|
2016-06-16 21:37:55 +02:00
|
|
|
var folders = this.getAllContactFolders(false);
|
|
|
|
|
2016-06-19 00:16:25 +02:00
|
|
|
for (var i = 0; i < folders.length; i++) {
|
|
|
|
if (folders[i].display_name == name) {
|
2016-06-16 21:37:55 +02:00
|
|
|
return folders[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return container.getHierarchyStore().getDefaultFolder('contact');
|
2016-06-14 01:18:00 +02:00
|
|
|
},
|
|
|
|
|
2016-06-19 00:22:30 +02:00
|
|
|
/**
|
|
|
|
* 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');
|
|
|
|
},
|
|
|
|
|
2013-05-20 23:09:51 +02:00
|
|
|
/**
|
|
|
|
* Reloads the data of the grid
|
|
|
|
* @private
|
|
|
|
*/
|
2016-06-13 22:59:05 +02:00
|
|
|
reloadGridStore: function (contactdata) {
|
2013-05-20 23:09:51 +02:00
|
|
|
var parsedData = [];
|
2016-06-13 22:59:05 +02:00
|
|
|
|
|
|
|
if (contactdata) {
|
2013-05-20 23:09:51 +02:00
|
|
|
parsedData = new Array(contactdata.contacts.length);
|
|
|
|
var i = 0;
|
2016-06-13 22:59:05 +02:00
|
|
|
for (i = 0; i < contactdata.contacts.length; i++) {
|
|
|
|
|
2016-06-13 10:18:47 +02:00
|
|
|
parsedData[i] = [
|
2013-05-20 23:09:51 +02:00
|
|
|
contactdata.contacts[i]["display_name"],
|
|
|
|
contactdata.contacts[i]["given_name"],
|
|
|
|
contactdata.contacts[i]["surname"],
|
|
|
|
contactdata.contacts[i]["company_name"],
|
|
|
|
contactdata.contacts[i]
|
2016-06-13 10:18:47 +02:00
|
|
|
];
|
2013-05-20 23:09:51 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.store.loadData(parsedData, false);
|
|
|
|
},
|
2016-06-13 22:59:05 +02:00
|
|
|
|
2013-05-20 23:09:51 +02:00
|
|
|
/**
|
|
|
|
* Init embedded form, this is the form that is
|
|
|
|
* posted and contains the attachments
|
|
|
|
* @private
|
|
|
|
*/
|
2016-06-13 22:59:05 +02:00
|
|
|
createGrid: function () {
|
2013-05-20 23:09:51 +02:00
|
|
|
return {
|
2016-06-13 22:59:05 +02:00
|
|
|
xtype : 'grid',
|
|
|
|
ref : 'contactGrid',
|
2013-05-20 23:09:51 +02:00
|
|
|
columnWidth: 1.0,
|
2016-06-13 22:59:05 +02:00
|
|
|
store : this.store,
|
|
|
|
width : '100%',
|
|
|
|
height : 300,
|
|
|
|
title : 'Select contacts to import',
|
|
|
|
frame : false,
|
|
|
|
viewConfig : {
|
|
|
|
forceFit: true
|
2013-05-20 23:09:51 +02:00
|
|
|
},
|
2016-06-13 22:59:05 +02:00
|
|
|
colModel : new Ext.grid.ColumnModel({
|
2013-05-20 23:09:51 +02:00
|
|
|
defaults: {
|
2016-06-13 22:59:05 +02:00
|
|
|
width : 300,
|
2013-05-20 23:09:51 +02:00
|
|
|
sortable: true
|
|
|
|
},
|
2016-06-13 22:59:05 +02:00
|
|
|
columns : [
|
2013-05-20 23:09:51 +02:00
|
|
|
{id: 'Displayname', header: 'Displayname', width: 350, sortable: true, dataIndex: 'display_name'},
|
|
|
|
{header: 'Firstname', width: 200, sortable: true, dataIndex: 'given_name'},
|
|
|
|
{header: 'Lastname', width: 200, sortable: true, dataIndex: 'surname'},
|
|
|
|
{header: 'Company', sortable: true, dataIndex: 'company_name'}
|
|
|
|
]
|
|
|
|
}),
|
2016-06-13 22:59:05 +02:00
|
|
|
sm : new Ext.grid.RowSelectionModel({multiSelect: true})
|
2013-05-20 23:09:51 +02:00
|
|
|
}
|
|
|
|
},
|
2016-06-13 22:59:05 +02:00
|
|
|
|
2016-06-19 00:16:25 +02:00
|
|
|
/**
|
|
|
|
* Generate the UI calendar select box.
|
|
|
|
* @returns {*}
|
|
|
|
*/
|
2016-06-13 22:59:05 +02:00
|
|
|
createSelectBox: function () {
|
2016-06-16 21:37:55 +02:00
|
|
|
var myStore = this.getAllContactFolders(true);
|
2016-06-13 22:59:05 +02:00
|
|
|
|
2013-05-20 23:09:51 +02:00
|
|
|
return {
|
2016-06-13 22:59:05 +02:00
|
|
|
xtype : "selectbox",
|
|
|
|
ref : 'addressbookSelector',
|
|
|
|
editable : false,
|
|
|
|
name : "choosen_addressbook",
|
2016-06-16 21:37:55 +02:00
|
|
|
value : Ext.isEmpty(this.folder) ? this.getContactFolderByName(container.getSettingsModel().get("zarafa/v1/plugins/contactimporter/default_addressbook")).entryid : this.folder,
|
2016-06-13 22:59:05 +02:00
|
|
|
width : 100,
|
2016-06-14 00:57:00 +02:00
|
|
|
fieldLabel : "Select folder",
|
2016-06-13 22:59:05 +02:00
|
|
|
store : myStore,
|
|
|
|
mode : 'local',
|
2013-05-20 23:09:51 +02:00
|
|
|
labelSeperator: ":",
|
2016-06-13 22:59:05 +02:00
|
|
|
border : false,
|
|
|
|
anchor : "100%",
|
|
|
|
scope : this,
|
2016-06-16 21:37:55 +02:00
|
|
|
hidden : Ext.isEmpty(this.folder) ? false : true,
|
2016-06-13 22:59:05 +02:00
|
|
|
allowBlank : false
|
2013-05-20 23:09:51 +02:00
|
|
|
}
|
|
|
|
},
|
2016-06-13 22:59:05 +02:00
|
|
|
|
2016-06-19 00:16:25 +02:00
|
|
|
/**
|
|
|
|
* Generate the UI upload field.
|
|
|
|
* @returns {*}
|
|
|
|
*/
|
2016-06-13 22:59:05 +02:00
|
|
|
createUploadField: function () {
|
2013-05-20 23:09:51 +02:00
|
|
|
return {
|
2016-06-13 22:59:05 +02:00
|
|
|
xtype : "fileuploadfield",
|
|
|
|
ref : 'contactfileuploadfield',
|
2013-05-20 23:09:51 +02:00
|
|
|
columnWidth: 1.0,
|
2016-06-13 22:59:05 +02:00
|
|
|
id : 'form-file',
|
|
|
|
name : 'vcfdata',
|
|
|
|
emptyText : 'Select an .vcf addressbook',
|
|
|
|
border : false,
|
|
|
|
anchor : "100%",
|
2016-06-14 00:57:00 +02:00
|
|
|
height : "30",
|
2016-06-13 22:59:05 +02:00
|
|
|
scope : this,
|
|
|
|
allowBlank : false,
|
|
|
|
listeners : {
|
2013-05-20 23:09:51 +02:00
|
|
|
'fileselected': this.onFileSelected,
|
2016-06-13 22:59:05 +02:00
|
|
|
scope : this
|
2013-05-20 23:09:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2016-06-13 22:59:05 +02:00
|
|
|
|
2016-06-19 00:16:25 +02:00
|
|
|
/**
|
|
|
|
* Generate the UI submit button.
|
|
|
|
* @returns {*}
|
|
|
|
*/
|
2016-06-13 22:59:05 +02:00
|
|
|
createSubmitButton: function () {
|
2013-05-20 23:09:51 +02:00
|
|
|
return {
|
2016-06-13 22:59:05 +02:00
|
|
|
xtype : "button",
|
|
|
|
ref : "../submitButton",
|
|
|
|
disabled : true,
|
|
|
|
width : 100,
|
|
|
|
border : false,
|
|
|
|
text : _("Import"),
|
|
|
|
anchor : "100%",
|
|
|
|
handler : this.importCheckedContacts,
|
|
|
|
scope : this,
|
2013-05-20 23:09:51 +02:00
|
|
|
allowBlank: false
|
|
|
|
}
|
|
|
|
},
|
2016-06-13 22:59:05 +02:00
|
|
|
|
2016-06-19 00:16:25 +02:00
|
|
|
/**
|
|
|
|
* Generate the UI submit all button.
|
|
|
|
* @returns {*}
|
|
|
|
*/
|
2016-06-13 22:59:05 +02:00
|
|
|
createSubmitAllButton: function () {
|
2013-05-20 23:09:51 +02:00
|
|
|
return {
|
2016-06-13 22:59:05 +02:00
|
|
|
xtype : "button",
|
|
|
|
ref : "../submitAllButton",
|
|
|
|
disabled : true,
|
|
|
|
width : 100,
|
|
|
|
border : false,
|
|
|
|
text : _("Import All"),
|
|
|
|
anchor : "100%",
|
|
|
|
handler : this.importAllContacts,
|
|
|
|
scope : this,
|
2013-05-20 23:09:51 +02:00
|
|
|
allowBlank: false
|
|
|
|
}
|
|
|
|
},
|
2016-06-13 22:59:05 +02:00
|
|
|
|
2016-06-19 00:16:25 +02:00
|
|
|
/**
|
|
|
|
* Generate the UI cancel button.
|
|
|
|
* @returns {*}
|
|
|
|
*/
|
2016-06-13 22:59:05 +02:00
|
|
|
createCancelButton: function () {
|
2013-05-20 23:09:51 +02:00
|
|
|
return {
|
2016-06-13 22:59:05 +02:00
|
|
|
xtype : "button",
|
|
|
|
width : 100,
|
|
|
|
border : false,
|
|
|
|
text : _("Cancel"),
|
|
|
|
anchor : "100%",
|
|
|
|
handler : this.close,
|
|
|
|
scope : this,
|
2013-05-20 23:09:51 +02:00
|
|
|
allowBlank: false
|
|
|
|
}
|
|
|
|
},
|
2016-06-13 22:59:05 +02:00
|
|
|
|
2013-05-20 23:09:51 +02:00
|
|
|
/**
|
|
|
|
* This is called when a file has been seleceted in the file dialog
|
|
|
|
* in the {@link Ext.ux.form.FileUploadField} and the dialog is closed
|
|
|
|
* @param {Ext.ux.form.FileUploadField} uploadField being added a file to
|
|
|
|
*/
|
2016-06-13 22:59:05 +02:00
|
|
|
onFileSelected: function (uploadField) {
|
2013-05-20 23:09:51 +02:00
|
|
|
var form = this.addContactFormPanel.getForm();
|
|
|
|
|
|
|
|
if (form.isValid()) {
|
|
|
|
form.submit({
|
|
|
|
waitMsg: 'Uploading and parsing contacts...',
|
2016-06-13 22:59:05 +02:00
|
|
|
url : 'plugins/contactimporter/php/upload.php',
|
|
|
|
failure: function (file, action) {
|
2013-05-20 23:09:51 +02:00
|
|
|
this.submitButton.disable();
|
|
|
|
this.submitAllButton.disable();
|
|
|
|
Zarafa.common.dialogs.MessageBox.show({
|
2016-06-13 22:59:05 +02:00
|
|
|
title : _('Error'),
|
|
|
|
msg : _(action.result.error),
|
|
|
|
icon : Zarafa.common.dialogs.MessageBox.ERROR,
|
|
|
|
buttons: Zarafa.common.dialogs.MessageBox.OK
|
2013-05-20 23:09:51 +02:00
|
|
|
});
|
|
|
|
},
|
2016-06-13 22:59:05 +02:00
|
|
|
success: function (file, action) {
|
2013-05-20 23:09:51 +02:00
|
|
|
uploadField.reset();
|
|
|
|
this.vcffile = action.result.vcf_file;
|
2016-06-13 22:59:05 +02:00
|
|
|
|
2013-05-20 23:09:51 +02:00
|
|
|
this.parseContacts(this.vcffile);
|
|
|
|
},
|
2016-06-13 22:59:05 +02:00
|
|
|
scope : this
|
2013-05-20 23:09:51 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2016-06-13 22:59:05 +02:00
|
|
|
|
2016-06-19 00:16:25 +02:00
|
|
|
/**
|
|
|
|
* Start request to server to parse the given vCard file.
|
|
|
|
* @param {string} vcfPath
|
|
|
|
*/
|
2013-05-20 23:09:51 +02:00
|
|
|
parseContacts: function (vcfPath) {
|
|
|
|
this.loadMask.show();
|
2016-06-13 22:59:05 +02:00
|
|
|
|
2013-05-20 23:09:51 +02:00
|
|
|
// call export function here!
|
|
|
|
var responseHandler = new Zarafa.plugins.contactimporter.data.ResponseHandler({
|
|
|
|
successCallback: this.handleParsingResult.createDelegate(this)
|
|
|
|
});
|
2016-06-13 22:59:05 +02:00
|
|
|
|
2013-05-20 23:09:51 +02:00
|
|
|
container.getRequest().singleRequest(
|
|
|
|
'contactmodule',
|
2013-06-24 22:21:09 +02:00
|
|
|
'load',
|
2013-05-20 23:09:51 +02:00
|
|
|
{
|
|
|
|
vcf_filepath: vcfPath
|
|
|
|
},
|
|
|
|
responseHandler
|
|
|
|
);
|
|
|
|
},
|
2016-06-13 22:59:05 +02:00
|
|
|
|
2016-06-19 00:16:25 +02:00
|
|
|
/**
|
|
|
|
* Callback for the parsing request.
|
|
|
|
* @param {Object} response
|
|
|
|
*/
|
2016-06-13 22:59:05 +02:00
|
|
|
handleParsingResult: function (response) {
|
2013-05-20 23:09:51 +02:00
|
|
|
this.loadMask.hide();
|
2016-06-13 22:59:05 +02:00
|
|
|
|
|
|
|
if (response["status"] == true) {
|
2013-05-20 23:09:51 +02:00
|
|
|
this.submitButton.enable();
|
|
|
|
this.submitAllButton.enable();
|
2016-06-13 22:59:05 +02:00
|
|
|
|
2013-05-20 23:09:51 +02:00
|
|
|
this.reloadGridStore(response.parsed);
|
|
|
|
} else {
|
|
|
|
this.submitButton.disable();
|
|
|
|
this.submitAllButton.disable();
|
|
|
|
Zarafa.common.dialogs.MessageBox.show({
|
2016-06-13 22:59:05 +02:00
|
|
|
title : _('Parser Error'),
|
|
|
|
msg : _(response["message"]),
|
|
|
|
icon : Zarafa.common.dialogs.MessageBox.ERROR,
|
|
|
|
buttons: Zarafa.common.dialogs.MessageBox.OK
|
2013-05-20 23:09:51 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-06-19 00:16:25 +02:00
|
|
|
/**
|
|
|
|
* Close the UI dialog.
|
|
|
|
*/
|
2013-05-20 23:09:51 +02:00
|
|
|
close: function () {
|
|
|
|
this.addContactFormPanel.getForm().reset();
|
|
|
|
this.dialog.close()
|
|
|
|
},
|
|
|
|
|
2016-06-19 00:16:25 +02:00
|
|
|
/**
|
|
|
|
* Create a request to import all selected contacts.
|
|
|
|
*/
|
2013-05-20 23:09:51 +02:00
|
|
|
importCheckedContacts: function () {
|
|
|
|
var newRecords = this.contactGrid.selModel.getSelections();
|
|
|
|
this.importContacts(newRecords);
|
2016-06-13 22:59:05 +02:00
|
|
|
},
|
2013-05-20 23:09:51 +02:00
|
|
|
|
2016-06-19 00:16:25 +02:00
|
|
|
/**
|
|
|
|
* Check all contacts and import them.
|
|
|
|
*/
|
2013-05-20 23:09:51 +02:00
|
|
|
importAllContacts: function () {
|
|
|
|
//receive Records from grid rows
|
|
|
|
this.contactGrid.selModel.selectAll(); // select all entries
|
|
|
|
var newRecords = this.contactGrid.selModel.getSelections();
|
|
|
|
this.importContacts(newRecords);
|
2016-06-13 22:59:05 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2016-06-19 00:16:25 +02:00
|
|
|
* This function stores all given events to the contact store
|
|
|
|
* @param {array} contacts
|
2013-05-20 23:09:51 +02:00
|
|
|
*/
|
|
|
|
importContacts: function (contacts) {
|
|
|
|
//receive existing contact store
|
|
|
|
var folderValue = this.addressbookSelector.getValue();
|
|
|
|
|
2016-06-13 22:59:05 +02:00
|
|
|
if (folderValue == undefined) { // no addressbook choosen
|
2013-05-20 23:09:51 +02:00
|
|
|
Zarafa.common.dialogs.MessageBox.show({
|
2016-06-13 22:59:05 +02:00
|
|
|
title : _('Error'),
|
|
|
|
msg : _('You have to choose an addressbook!'),
|
|
|
|
icon : Zarafa.common.dialogs.MessageBox.ERROR,
|
|
|
|
buttons: Zarafa.common.dialogs.MessageBox.OK
|
2013-05-20 23:09:51 +02:00
|
|
|
});
|
|
|
|
} else {
|
2016-06-13 22:59:05 +02:00
|
|
|
if (this.contactGrid.selModel.getCount() < 1) {
|
2013-05-20 23:09:51 +02:00
|
|
|
Zarafa.common.dialogs.MessageBox.show({
|
2016-06-13 22:59:05 +02:00
|
|
|
title : _('Error'),
|
|
|
|
msg : _('You have to choose at least one contact to import!'),
|
|
|
|
icon : Zarafa.common.dialogs.MessageBox.ERROR,
|
|
|
|
buttons: Zarafa.common.dialogs.MessageBox.OK
|
2013-05-20 23:09:51 +02:00
|
|
|
});
|
|
|
|
} else {
|
2016-06-19 00:22:30 +02:00
|
|
|
var contactFolder = this.getContactFolderByEntryid(folderValue);
|
2016-06-13 22:59:05 +02:00
|
|
|
|
2016-06-19 00:22:30 +02:00
|
|
|
this.loadMask.show();
|
|
|
|
var uids = [];
|
2013-05-20 23:09:51 +02:00
|
|
|
|
2016-06-19 00:22:30 +02:00
|
|
|
//receive Records from grid rows
|
|
|
|
Ext.each(contacts, function (newRecord) {
|
|
|
|
uids.push(newRecord.data.record.internal_fields.contact_uid);
|
|
|
|
}, this);
|
2016-06-13 22:59:05 +02:00
|
|
|
|
2016-06-19 00:22:30 +02:00
|
|
|
var responseHandler = new Zarafa.plugins.contactimporter.data.ResponseHandler({
|
|
|
|
successCallback: this.importContactsDone.createDelegate(this)
|
|
|
|
});
|
2016-06-13 22:59:05 +02:00
|
|
|
|
2016-06-19 00:22:30 +02:00
|
|
|
container.getRequest().singleRequest(
|
|
|
|
'contactmodule',
|
|
|
|
'import',
|
|
|
|
{
|
|
|
|
storeid : contactFolder.store_entryid,
|
|
|
|
folderid : contactFolder.entryid,
|
|
|
|
uids : uids,
|
|
|
|
vcf_filepath: this.vcffile
|
|
|
|
},
|
|
|
|
responseHandler
|
|
|
|
);
|
2013-05-20 23:09:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2016-06-13 22:59:05 +02:00
|
|
|
|
2016-06-19 00:16:25 +02:00
|
|
|
/**
|
|
|
|
* Callback for the import request.
|
|
|
|
* @param {Object} response
|
|
|
|
*/
|
2016-06-13 22:59:05 +02:00
|
|
|
importContactsDone: function (response) {
|
2013-06-24 22:21:09 +02:00
|
|
|
this.loadMask.hide();
|
|
|
|
this.dialog.close();
|
2016-06-13 22:59:05 +02:00
|
|
|
if (response.status == true) {
|
2013-06-24 22:21:09 +02:00
|
|
|
container.getNotifier().notify('info', 'Imported', 'Imported ' + response.count + ' contacts. Please reload your addressbook!');
|
|
|
|
} else {
|
|
|
|
Zarafa.common.dialogs.MessageBox.show({
|
2016-06-13 22:59:05 +02:00
|
|
|
title : _('Error'),
|
|
|
|
msg : _('Import failed: ') + response.message,
|
|
|
|
icon : Zarafa.common.dialogs.MessageBox.ERROR,
|
|
|
|
buttons: Zarafa.common.dialogs.MessageBox.OK
|
2013-05-20 23:09:51 +02:00
|
|
|
});
|
2013-06-24 22:21:09 +02:00
|
|
|
}
|
2013-05-20 23:09:51 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Ext.reg('contactimporter.importcontactpanel', Zarafa.plugins.contactimporter.dialogs.ImportPanel);
|