download whole contact folders
This commit is contained in:
		| @@ -63,12 +63,18 @@ Zarafa.plugins.contactimporter.ImportPlugin = Ext.extend(Zarafa.core.Plugin, { | ||||
| 	 */ | ||||
| 	createImportButton: function () { | ||||
| 		var button = { | ||||
| 			xtype            : 'button', | ||||
| 			text             : _('Import Contacts'), | ||||
| 			iconCls          : 'icon_contactimporter_button', | ||||
| 			xtype: 'panel', | ||||
| 			cls: 'zarafa-ciplg-container', | ||||
| 			layout: 'fit', | ||||
| 			navigationContext: container.getContextByName('contact'), | ||||
| 			handler          : this.onImportButtonClick, | ||||
| 			scope            : this | ||||
| 			items: [{ | ||||
| 				xtype            : 'button', | ||||
| 				text             : _('Import Contacts'), | ||||
| 				iconCls          : 'icon_contactimporter_button', | ||||
| 				cls: 'zarafa-ciplg-button', | ||||
| 				handler          : this.onImportButtonClick, | ||||
| 				scope            : this | ||||
| 			}] | ||||
| 		}; | ||||
|  | ||||
| 		return button; | ||||
| @@ -119,19 +125,28 @@ Zarafa.plugins.contactimporter.ImportPlugin = Ext.extend(Zarafa.core.Plugin, { | ||||
| 	}, | ||||
|  | ||||
| 	downloadVCF: function (response) { | ||||
| 		var downloadFrame = Ext.getBody().createChild({ | ||||
| 			tag: 'iframe', | ||||
| 			cls: 'x-hidden' | ||||
| 		}); | ||||
| 		if(response.status == false) { | ||||
| 			Zarafa.common.dialogs.MessageBox.show({ | ||||
| 				title  : dgettext('plugin_files', 'Warning'), | ||||
| 				msg    : dgettext('plugin_files', response.message), | ||||
| 				icon   : Zarafa.common.dialogs.MessageBox.WARNING, | ||||
| 				buttons: Zarafa.common.dialogs.MessageBox.OK | ||||
| 			}); | ||||
| 		} else { | ||||
| 			var downloadFrame = Ext.getBody().createChild({ | ||||
| 				tag: 'iframe', | ||||
| 				cls: 'x-hidden' | ||||
| 			}); | ||||
|  | ||||
| 		var url = document.URL; | ||||
| 		var link = url.substring(0, url.lastIndexOf('/') + 1); | ||||
| 			var url = document.URL; | ||||
| 			var link = url.substring(0, url.lastIndexOf('/') + 1); | ||||
|  | ||||
| 		link += "index.php?sessionid=" + container.getUser().getSessionId() + "&load=custom&name=download_vcf"; | ||||
| 		link = Ext.urlAppend(link, "token=" + encodeURIComponent(response.download_token)); | ||||
| 		link = Ext.urlAppend(link, "filename=" + encodeURIComponent(response.filename)); | ||||
| 			link += "index.php?sessionid=" + container.getUser().getSessionId() + "&load=custom&name=download_vcf"; | ||||
| 			link = Ext.urlAppend(link, "token=" + encodeURIComponent(response.download_token)); | ||||
| 			link = Ext.urlAppend(link, "filename=" + encodeURIComponent(response.filename)); | ||||
|  | ||||
| 		downloadFrame.dom.contentWindow.location = link; | ||||
| 			downloadFrame.dom.contentWindow.location = link; | ||||
| 		} | ||||
| 	}, | ||||
|  | ||||
| 	/** | ||||
| @@ -271,6 +286,13 @@ Zarafa.plugins.contactimporter.ImportPlugin = Ext.extend(Zarafa.core.Plugin, { | ||||
| 			case Zarafa.core.data.SharedComponentType['plugins.contactimporter.dialogs.importcontacts']: | ||||
| 				bid = 1; | ||||
| 				break; | ||||
| 			case Zarafa.core.data.SharedComponentType['common.contextmenu']: | ||||
| 				if (record instanceof Zarafa.core.data.MAPIRecord) { | ||||
| 					if (record.get('object_type') == Zarafa.core.mapi.ObjectType.MAPI_FOLDER) { | ||||
| 						bid = 2; | ||||
| 					} | ||||
| 				} | ||||
| 				break; | ||||
| 		} | ||||
| 		return bid; | ||||
| 	}, | ||||
| @@ -288,6 +310,9 @@ Zarafa.plugins.contactimporter.ImportPlugin = Ext.extend(Zarafa.core.Plugin, { | ||||
| 			case Zarafa.core.data.SharedComponentType['plugins.contactimporter.dialogs.importcontacts']: | ||||
| 				component = Zarafa.plugins.contactimporter.dialogs.ImportContentPanel; | ||||
| 				break; | ||||
| 			case Zarafa.core.data.SharedComponentType['common.contextmenu']: | ||||
| 				component = Zarafa.plugins.contactimporter.ui.ContextMenu; | ||||
| 				break; | ||||
| 		} | ||||
|  | ||||
| 		return component; | ||||
|   | ||||
							
								
								
									
										108
									
								
								js/ui/ContextMenu.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										108
									
								
								js/ui/ContextMenu.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,108 @@ | ||||
| Ext.namespace('Zarafa.plugins.contactimporter.ui'); | ||||
|  | ||||
| /** | ||||
|  * @class Zarafa.plugins.contactimporter.ui.ContextMenu | ||||
|  * @extends Zarafa.hierarchy.ui.ContextMenu | ||||
|  * @xtype contactimporter.hierarchycontextmenu | ||||
|  */ | ||||
| Zarafa.plugins.contactimporter.ui.ContextMenu = Ext.extend(Zarafa.hierarchy.ui.ContextMenu, { | ||||
|  | ||||
| 	/** | ||||
| 	 * @constructor | ||||
| 	 * @param {Object} config Configuration object | ||||
| 	 */ | ||||
| 	constructor : function(config) | ||||
| 	{ | ||||
| 		config = config || {}; | ||||
|  | ||||
| 		if (config.contextNode) { | ||||
| 			config.contextTree = config.contextNode.getOwnerTree(); | ||||
| 		} | ||||
|  | ||||
| 		Zarafa.plugins.contactimporter.ui.ContextMenu.superclass.constructor.call(this, config); | ||||
|  | ||||
| 		// add item to menu | ||||
| 		var additionalItems = this.createAdditionalContextMenuItems(config); | ||||
| 		for(var i=0; i <additionalItems.length; i++) { | ||||
| 			config.items[0].push(additionalItems[i]); | ||||
| 		} | ||||
|  | ||||
| 		Zarafa.plugins.contactimporter.ui.ContextMenu.superclass.constructor.call(this, config); // redo ... otherwise menu does not get published | ||||
| 	}, | ||||
|  | ||||
| 	/** | ||||
| 	 * Create the Action context menu items. | ||||
| 	 * @param {Object} config Configuration object for the {@link Zarafa.plugins.contactimporter.ui.ContextMenu ContextMenu} | ||||
| 	 * @return {Zarafa.core.ui.menu.ConditionalItem[]} The list of Action context menu items | ||||
| 	 * @private | ||||
| 	 * | ||||
| 	 * Note: All handlers are called within the scope of {@link Zarafa.plugins.contactimporter.ui.ContextMenu HierarchyContextMenu} | ||||
| 	 */ | ||||
| 	createAdditionalContextMenuItems : function(config) | ||||
| 	{ | ||||
| 		return [{ | ||||
| 			xtype: 'menuseparator' | ||||
| 		}, { | ||||
| 			text : _('Export VCF'), | ||||
| 			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); | ||||
| 				} else { | ||||
| 					item.setDisabled(false); | ||||
| 				} | ||||
| 			} | ||||
| 		}]; | ||||
| 	}, | ||||
|  | ||||
| 	/** | ||||
| 	 * Fires on selecting 'Open' menu option from {@link Zarafa.hierarchy.ui.ContextMenu ContextMenu} | ||||
| 	 * @private | ||||
| 	 */ | ||||
| 	onContextItemExport: function () { | ||||
| 		var responseHandler = new Zarafa.plugins.contactimporter.data.ResponseHandler({ | ||||
| 			successCallback: this.downloadVCF, | ||||
| 			scope          : this | ||||
| 		}); | ||||
|  | ||||
| 		// request attachment preperation | ||||
| 		container.getRequest().singleRequest( | ||||
| 			'contactmodule', | ||||
| 			'export', | ||||
| 			{ | ||||
| 				storeid: this.records.get("store_entryid"), | ||||
| 				folder: this.records.get("entryid") | ||||
| 			}, | ||||
| 			responseHandler | ||||
| 		); | ||||
| 	}, | ||||
|  | ||||
| 	downloadVCF: function (response) { | ||||
| 		if(response.status == false) { | ||||
| 			Zarafa.common.dialogs.MessageBox.show({ | ||||
| 				title  : dgettext('plugin_files', 'Warning'), | ||||
| 				msg    : dgettext('plugin_files', response.message), | ||||
| 				icon   : Zarafa.common.dialogs.MessageBox.WARNING, | ||||
| 				buttons: Zarafa.common.dialogs.MessageBox.OK | ||||
| 			}); | ||||
| 		} else { | ||||
| 			var downloadFrame = Ext.getBody().createChild({ | ||||
| 				tag: 'iframe', | ||||
| 				cls: 'x-hidden' | ||||
| 			}); | ||||
|  | ||||
| 			var url = document.URL; | ||||
| 			var link = url.substring(0, url.lastIndexOf('/') + 1); | ||||
|  | ||||
| 			link += "index.php?sessionid=" + container.getUser().getSessionId() + "&load=custom&name=download_vcf"; | ||||
| 			link = Ext.urlAppend(link, "token=" + encodeURIComponent(response.download_token)); | ||||
| 			link = Ext.urlAppend(link, "filename=" + encodeURIComponent(response.filename)); | ||||
|  | ||||
| 			downloadFrame.dom.contentWindow.location = link; | ||||
| 		} | ||||
| 	} | ||||
| }); | ||||
|  | ||||
| Ext.reg('contactimporter.hierarchycontextmenu', Zarafa.plugins.contactimporter.ui.ContextMenu); | ||||
| @@ -28,6 +28,7 @@ | ||||
| 					<clientfile load="source">js/data/ResponseHandler.js</clientfile> | ||||
| 					<clientfile load="source">js/dialogs/ImportContentPanel.js</clientfile> | ||||
| 					<clientfile load="source">js/dialogs/ImportPanel.js</clientfile> | ||||
| 					<clientfile load="source">js/ui/ContextMenu.js</clientfile> | ||||
| 				</client> | ||||
| 				<resources> | ||||
| 					<resourcefile load="release">resources/css/contactimporter.css</resourcefile> | ||||
|   | ||||
| @@ -272,6 +272,12 @@ class ContactModule extends Module | ||||
| 			$records = $actionData["records"]; | ||||
| 		} | ||||
|  | ||||
| 		// Get folders | ||||
| 		$folder = false; | ||||
| 		if (isset($actionData["folder"])) { | ||||
| 			$folder = $actionData["folder"]; | ||||
| 		} | ||||
|  | ||||
| 		$response = array(); | ||||
| 		$error = false; | ||||
| 		$error_msg = ""; | ||||
| @@ -283,6 +289,17 @@ class ContactModule extends Module | ||||
|  | ||||
| 		$store = $GLOBALS["mapisession"]->openMessageStore(hex2bin($storeid)); | ||||
| 		if ($store) { | ||||
| 			// load folder first | ||||
| 			if($folder !== false) { | ||||
| 				$mapifolder = mapi_msgstore_openentry($store, hex2bin($folder)); | ||||
|  | ||||
| 				$table = mapi_folder_getcontentstable($mapifolder); | ||||
| 				$list = mapi_table_queryallrows($table, array(PR_ENTRYID)); | ||||
|  | ||||
| 				foreach ($list as $item) { | ||||
| 					$records[] = bin2hex($item[PR_ENTRYID]); | ||||
| 				} | ||||
| 			} | ||||
| 			for ($index = 0, $count = count($records); $index < $count; $index++) { | ||||
| 				// define vcard | ||||
| 				$vcard = new VCard(); | ||||
| @@ -412,9 +429,14 @@ class ContactModule extends Module | ||||
| 			return false; | ||||
| 		} | ||||
|  | ||||
| 		$response['status'] = true; | ||||
| 		$response['download_token'] = $token; | ||||
| 		$response['filename'] = count($records) . "contacts.vcf"; | ||||
| 		if(count($records) > 0) { | ||||
| 			$response['status'] = true; | ||||
| 			$response['download_token'] = $token; | ||||
| 			$response['filename'] = count($records) . "contacts.vcf"; | ||||
| 		} else { | ||||
| 			$response['status'] = false; | ||||
| 			$response['message'] = "No contacts found. Export skipped!"; | ||||
| 		} | ||||
|  | ||||
| 		$this->addActionData($actionType, $response); | ||||
| 		$GLOBALS["bus"]->addData($this->getResponseData()); | ||||
|   | ||||
| @@ -10,3 +10,15 @@ | ||||
|     background-repeat: no-repeat; | ||||
|     background-position: center; | ||||
| } | ||||
|  | ||||
| .zarafa-ciplg-container { | ||||
|     width: 100%; | ||||
|     height: 30px; | ||||
| } | ||||
|  | ||||
| .zarafa-ciplg-button.x-btn-small { | ||||
|     width: 80%; | ||||
|     height: 25px; | ||||
|     margin-left: auto; | ||||
|     margin-right: auto; | ||||
| } | ||||
		Reference in New Issue
	
	Block a user