/** * ImportPanel.js zarafa contact to vcf im/exporter * * Author: Christoph Haas * Copyright (C) 2012-2016 Christoph Haas * * 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. * * 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. */ Ext.namespace("Zarafa.plugins.contactimporter.dialogs"); /** * @class Zarafa.plugins.contactimporter.dialogs.ImportPanel * @extends Ext.form.FormPanel */ Zarafa.plugins.contactimporter.dialogs.ImportPanel = Ext.extend(Ext.Panel, { /* path to vcf file on server... */ vcffile: null, /* The store for the selection grid */ store : null, /* selected folder */ folder : null, /** * @constructor * @param {object} config */ constructor: function (config) { config = config || {}; var self = this; if (!Ext.isEmpty(config.filename)) { this.vcffile = config.filename; } if (!Ext.isEmpty(config.folder)) { this.folder = config.folder; } // 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'} ] }); Ext.apply(config, { xtype : 'contactimporter.importpanel', ref : "importcontactpanel", layout : { type : 'form', align: 'stretch' }, anchor : '100%', bodyStyle: 'background-color: inherit;', defaults : { border : true, bodyStyle: 'background-color: inherit; padding: 3px 0px 3px 0px; border-style: none none solid none;' }, items : [ this.createSelectBox(), this.initForm(), this.createGrid() ], buttons : [ this.createSubmitAllButton(), this.createSubmitButton(), this.createCancelButton() ], listeners: { afterrender: function (cmp) { this.loadMask = new Ext.LoadMask(this.getEl(), {msg: 'Loading...'}); if (this.vcffile != null) { // if we have got the filename from an attachment this.parseContacts(this.vcffile); } }, scope : this } }); 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 */ initForm: function () { return { xtype : 'form', ref : 'addContactFormPanel', layout : 'column', fileUpload: true, autoWidth : true, autoHeight: true, border : false, bodyStyle : 'padding: 5px;', defaults : { anchor : '95%', border : false, bodyStyle: 'padding: 5px;' }, items : [this.createUploadField()] }; }, getAllContactFolders: function(asDropdownStore) { asDropdownStore = Ext.isEmpty(asDropdownStore) ? false : asDropdownStore; var allFolders = []; 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