Code comments

This commit is contained in:
Christoph Haas 2016-06-19 00:16:25 +02:00
parent e0eb5cf1f0
commit 5c98fe9e56
7 changed files with 139 additions and 44 deletions

View File

@ -2,7 +2,7 @@
* ABOUT.js zarafa contact to vcf im/exporter
*
* Author: Christoph Haas <christoph.h@sprinternet.at>
* Copyright (C) 2012-2013 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

View File

@ -54,7 +54,7 @@ Zarafa.plugins.contactimporter.dialogs.ImportContentPanel = Ext.extend(Zarafa.co
{
xtype : 'contactimporter.importcontactpanel',
filename: config.filename,
folder: config.folder
folder : config.folder
}
]
});

View File

@ -29,7 +29,7 @@ Ext.namespace("Zarafa.plugins.contactimporter.dialogs");
/**
* @class Zarafa.plugins.contactimporter.dialogs.ImportPanel
* @extends Ext.form.FormPanel
* @extends Ext.Panel
*/
Zarafa.plugins.contactimporter.dialogs.ImportPanel = Ext.extend(Ext.Panel, {
@ -132,7 +132,12 @@ Zarafa.plugins.contactimporter.dialogs.ImportPanel = Ext.extend(Ext.Panel, {
};
},
getAllContactFolders: function(asDropdownStore) {
/**
* Get all contact folders.
* @param {boolean} asDropdownStore If true, a simple array store will be returned.
* @returns {*}
*/
getAllContactFolders: function (asDropdownStore) {
asDropdownStore = Ext.isEmpty(asDropdownStore) ? false : asDropdownStore;
var allFolders = [];
@ -142,11 +147,11 @@ Zarafa.plugins.contactimporter.dialogs.ImportPanel = Ext.extend(Ext.Panel, {
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++) {
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) {
if (folder.get("container_class") == "IPF.Contact") {
if (asDropdownStore) {
allFolders.push([
folder.get("entryid"),
folder.get("display_name")
@ -163,11 +168,11 @@ Zarafa.plugins.contactimporter.dialogs.ImportPanel = Ext.extend(Ext.Panel, {
}
}
if(!Ext.isEmpty(pub.subStores) && pub.subStores.folders.totalLength > 0) {
for(var j=0; j < pub.subStores.folders.totalLength; j++) {
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) {
if (folder.get("container_class") == "IPF.Contact") {
if (asDropdownStore) {
allFolders.push([
folder.get("entryid"),
folder.get("display_name") + " (Public)"
@ -184,30 +189,40 @@ Zarafa.plugins.contactimporter.dialogs.ImportPanel = Ext.extend(Ext.Panel, {
}
}
if(asDropdownStore) {
if (asDropdownStore) {
return allFolders.sort(this.dynamicSort(1));
} else {
return allFolders;
}
},
dynamicSort: function(property) {
/**
* Dynamic sort function, sorts by property name.
* @param {string|int} property
* @returns {Function}
*/
dynamicSort: function (property) {
var sortOrder = 1;
if(property[0] === "-") {
if (property[0] === "-") {
sortOrder = -1;
property = property.substr(1);
}
return function (a,b) {
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) {
/**
* Return a contact folder element by name.
* @param {string} name
* @returns {*}
*/
getContactFolderByName: function (name) {
var folders = this.getAllContactFolders(false);
for(var i=0; i<folders.length; i++) {
if(folders[i].display_name == name) {
for (var i = 0; i < folders.length; i++) {
if (folders[i].display_name == name) {
return folders[i];
}
}
@ -276,6 +291,10 @@ Zarafa.plugins.contactimporter.dialogs.ImportPanel = Ext.extend(Ext.Panel, {
}
},
/**
* Generate the UI calendar select box.
* @returns {*}
*/
createSelectBox: function () {
var myStore = this.getAllContactFolders(true);
@ -298,6 +317,10 @@ Zarafa.plugins.contactimporter.dialogs.ImportPanel = Ext.extend(Ext.Panel, {
}
},
/**
* Generate the UI upload field.
* @returns {*}
*/
createUploadField: function () {
return {
xtype : "fileuploadfield",
@ -318,6 +341,10 @@ Zarafa.plugins.contactimporter.dialogs.ImportPanel = Ext.extend(Ext.Panel, {
}
},
/**
* Generate the UI submit button.
* @returns {*}
*/
createSubmitButton: function () {
return {
xtype : "button",
@ -333,6 +360,10 @@ Zarafa.plugins.contactimporter.dialogs.ImportPanel = Ext.extend(Ext.Panel, {
}
},
/**
* Generate the UI submit all button.
* @returns {*}
*/
createSubmitAllButton: function () {
return {
xtype : "button",
@ -348,6 +379,10 @@ Zarafa.plugins.contactimporter.dialogs.ImportPanel = Ext.extend(Ext.Panel, {
}
},
/**
* Generate the UI cancel button.
* @returns {*}
*/
createCancelButton: function () {
return {
xtype : "button",
@ -394,6 +429,10 @@ Zarafa.plugins.contactimporter.dialogs.ImportPanel = Ext.extend(Ext.Panel, {
}
},
/**
* Start request to server to parse the given vCard file.
* @param {string} vcfPath
*/
parseContacts: function (vcfPath) {
this.loadMask.show();
@ -412,6 +451,10 @@ Zarafa.plugins.contactimporter.dialogs.ImportPanel = Ext.extend(Ext.Panel, {
);
},
/**
* Callback for the parsing request.
* @param {Object} response
*/
handleParsingResult: function (response) {
this.loadMask.hide();
@ -432,16 +475,25 @@ Zarafa.plugins.contactimporter.dialogs.ImportPanel = Ext.extend(Ext.Panel, {
}
},
/**
* Close the UI dialog.
*/
close: function () {
this.addContactFormPanel.getForm().reset();
this.dialog.close()
},
/**
* Create a request to import all selected contacts.
*/
importCheckedContacts: function () {
var newRecords = this.contactGrid.selModel.getSelections();
this.importContacts(newRecords);
},
/**
* Check all contacts and import them.
*/
importAllContacts: function () {
//receive Records from grid rows
this.contactGrid.selModel.selectAll(); // select all entries
@ -450,8 +502,8 @@ Zarafa.plugins.contactimporter.dialogs.ImportPanel = Ext.extend(Ext.Panel, {
},
/**
* This function stores all given events to the appointmentstore
* @param events
* This function stores all given events to the contact store
* @param {array} contacts
*/
importContacts: function (contacts) {
//receive existing contact store
@ -540,6 +592,10 @@ Zarafa.plugins.contactimporter.dialogs.ImportPanel = Ext.extend(Ext.Panel, {
}
},
/**
* Callback for the import request.
* @param {Object} response
*/
importContactsDone: function (response) {
this.loadMask.hide();
this.dialog.close();

View File

@ -68,6 +68,10 @@ Zarafa.plugins.contactimporter.ImportPlugin = Ext.extend(Zarafa.core.Plugin, {
};
},
/**
* Generates a request to download the selected records as vCard.
* @param {Ext.Button} btn
*/
exportToVCF: function (btn) {
if (btn.records.length == 0) {
return; // skip if no records where given!
@ -96,8 +100,12 @@ Zarafa.plugins.contactimporter.ImportPlugin = Ext.extend(Zarafa.core.Plugin, {
);
},
/**
* Callback for the export request.
* @param {Object} response
*/
downloadVCF: function (response) {
if(response.status == false) {
if (response.status == false) {
Zarafa.common.dialogs.MessageBox.show({
title : dgettext('plugin_files', 'Warning'),
msg : dgettext('plugin_files', response.message),
@ -146,6 +154,7 @@ Zarafa.plugins.contactimporter.ImportPlugin = Ext.extend(Zarafa.core.Plugin, {
/**
* Callback for getAttachmentFileName
* @param {Object} response
*/
gotAttachmentFileName: function (response) {
if (response.status == true) {
@ -162,6 +171,7 @@ Zarafa.plugins.contactimporter.ImportPlugin = Ext.extend(Zarafa.core.Plugin, {
/**
* Clickhandler for the button
* @param {Ext.Button} btn
*/
getAttachmentFileName: function (btn) {
Zarafa.common.dialogs.MessageBox.show({
@ -225,14 +235,13 @@ Zarafa.plugins.contactimporter.ImportPlugin = Ext.extend(Zarafa.core.Plugin, {
/**
* Open the import dialog.
*
* @param {String} filename
*/
openImportDialog: function (filename) {
var componentType = Zarafa.core.data.SharedComponentType['plugins.contactimporter.dialogs.importcontacts'];
var config = {
filename: filename,
modal: true
modal : true
};
Zarafa.core.data.UIFactory.openLayerComponent(componentType, undefined, config);

View File

@ -11,8 +11,7 @@ Zarafa.plugins.contactimporter.ui.ContextMenu = Ext.extend(Zarafa.hierarchy.ui.C
* @constructor
* @param {Object} config Configuration object
*/
constructor : function(config)
{
constructor: function (config) {
config = config || {};
if (config.contextNode) {
@ -23,7 +22,7 @@ Zarafa.plugins.contactimporter.ui.ContextMenu = Ext.extend(Zarafa.hierarchy.ui.C
// add item to menu
var additionalItems = this.createAdditionalContextMenuItems(config);
for(var i=0; i <additionalItems.length; i++) {
for (var i = 0; i < additionalItems.length; i++) {
config.items[0].push(additionalItems[i]);
}
@ -38,15 +37,14 @@ Zarafa.plugins.contactimporter.ui.ContextMenu = Ext.extend(Zarafa.hierarchy.ui.C
*
* Note: All handlers are called within the scope of {@link Zarafa.plugins.contactimporter.ui.ContextMenu HierarchyContextMenu}
*/
createAdditionalContextMenuItems : function(config)
{
createAdditionalContextMenuItems: function (config) {
return [{
xtype: 'menuseparator'
}, {
text : _('Import vCard'),
iconCls : 'icon_contactimporter_import',
handler : this.onContextItemImport,
beforeShow : function(item, record) {
text : _('Import vCard'),
iconCls : 'icon_contactimporter_import',
handler : this.onContextItemImport,
beforeShow: function (item, record) {
var access = record.get('access') & Zarafa.core.mapi.Access.ACCESS_MODIFY;
if (!access || (record.isIPMSubTree() && !record.getMAPIStore().isDefaultStore())) {
item.setDisabled(true);
@ -55,10 +53,10 @@ Zarafa.plugins.contactimporter.ui.ContextMenu = Ext.extend(Zarafa.hierarchy.ui.C
}
}
}, {
text : _('Export vCard'),
iconCls : 'icon_contactimporter_export',
handler : this.onContextItemExport,
beforeShow : function(item, record) {
text : _('Export vCard'),
iconCls : 'icon_contactimporter_export',
handler : this.onContextItemExport,
beforeShow: function (item, record) {
var access = record.get('access') & Zarafa.core.mapi.Access.ACCESS_READ;
if (!access || (record.isIPMSubTree() && !record.getMAPIStore().isDefaultStore())) {
item.setDisabled(true);
@ -85,7 +83,7 @@ Zarafa.plugins.contactimporter.ui.ContextMenu = Ext.extend(Zarafa.hierarchy.ui.C
'export',
{
storeid: this.records.get("store_entryid"),
folder: this.records.get("entryid")
folder : this.records.get("entryid")
},
responseHandler
);
@ -98,15 +96,19 @@ Zarafa.plugins.contactimporter.ui.ContextMenu = Ext.extend(Zarafa.hierarchy.ui.C
onContextItemImport: function () {
var componentType = Zarafa.core.data.SharedComponentType['plugins.contactimporter.dialogs.importcontacts'];
var config = {
modal: true,
modal : true,
folder: this.records.get("entryid")
};
Zarafa.core.data.UIFactory.openLayerComponent(componentType, undefined, config);
},
/**
* Callback for the export request.
* @param {Object} response
*/
downloadVCF: function (response) {
if(response.status == false) {
if (response.status == false) {
Zarafa.common.dialogs.MessageBox.show({
title : dgettext('plugin_files', 'Warning'),
msg : dgettext('plugin_files', response.message),

View File

@ -1,4 +1,5 @@
<?php
/**
* download.php, zarafa contact to vcf im/exporter
*
@ -22,7 +23,10 @@
*/
class DownloadHandler
{
/**
* Download the given vcf file.
* @return bool
*/
public static function doDownload()
{
if (isset($_GET["token"])) {

View File

@ -29,7 +29,7 @@ use JeroenDesloovere\VCard\VCardParser;
class ContactModule extends Module
{
private $DEBUG = true; // enable error_log debugging
private $DEBUG = false; // enable error_log debugging
/**
* @constructor
@ -249,6 +249,12 @@ class ContactModule extends Module
$GLOBALS["bus"]->addData($this->getResponseData());
}
/**
* Get a property from the array.
* @param $props
* @param $propname
* @return string
*/
private function getProp($props, $propname)
{
$p = $this->getProperties();
@ -258,6 +264,12 @@ class ContactModule extends Module
return "";
}
/**
* Export selected contacts to vCard.
* @param $actionType
* @param $actionData
* @return bool
*/
private function exportContacts($actionType, $actionData)
{
// Get store id
@ -290,7 +302,7 @@ class ContactModule extends Module
$store = $GLOBALS["mapisession"]->openMessageStore(hex2bin($storeid));
if ($store) {
// load folder first
if($folder !== false) {
if ($folder !== false) {
$mapifolder = mapi_msgstore_openentry($store, hex2bin($folder));
$table = mapi_folder_getcontentstable($mapifolder);
@ -429,7 +441,7 @@ class ContactModule extends Module
return false;
}
if(count($records) > 0) {
if (count($records) > 0) {
$response['status'] = true;
$response['download_token'] = $token;
$response['filename'] = count($records) . "contacts.vcf";
@ -481,6 +493,12 @@ class ContactModule extends Module
}
}
/**
* Replace String Property Tags
* @param $store
* @param $properties
* @return array
*/
private function replaceStringPropertyTags($store, $properties)
{
$newProperties = array();
@ -1131,6 +1149,12 @@ class ContactModule extends Module
}
}
/**
* Check if string starts with other string.
* @param $haystack
* @param $needle
* @return bool
*/
private function startswith($haystack, $needle)
{
$haystack = str_replace("type=", "", $haystack); // remove type from string