From c4d11cd91617f8905ce909c3ef70d2c764b64a7f Mon Sep 17 00:00:00 2001 From: Jean Raby Date: Thu, 5 Jul 2012 21:16:02 +0000 Subject: [PATCH] * UI/WebServerResources/generic.js (openGenericWindow): New method that opens a simple new window. * UI/WebServerResources/ContactsUI.js (onMenuRawContact): New callback to show the vCard content from the menu. * UI/WebServerResources/ContactsUI.js (onContactMenuPrepareVisibility): Enable the export and raw functions only on vcards contacts. * UI/Templates/ContactsUI/UIxContactFoldersView.wox: New contextual menu item: Show vCard content * UI/Contacts/UIxContactFolderActions.m (rawAction): New method that returns the raw contact data for all the contact uids provided Monotone-Parent: f03db6cb5531dddabab4e8678d856fe593d3745d Monotone-Revision: e853157abbabf35bc95273da8bc10b2d3b142627 Monotone-Author: jraby@inverse.ca Monotone-Date: 2012-07-05T21:16:02 --- ChangeLog | 15 ++++++ UI/Contacts/English.lproj/Localizable.strings | 1 + UI/Contacts/French.lproj/Localizable.strings | 1 + UI/Contacts/UIxContactFolderActions.m | 46 +++++++++++++++++++ UI/Contacts/product.plist | 5 ++ .../ContactsUI/UIxContactFoldersView.wox | 1 + UI/WebServerResources/ContactsUI.js | 29 +++++++++++- UI/WebServerResources/generic.js | 36 +++++++++++++++ 8 files changed, 133 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index cc323bdde..cce164c33 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,20 @@ 2012-07-05 Jean Raby + * UI/WebServerResources/generic.js (openGenericWindow): + New method that opens a simple new window. + + * UI/WebServerResources/ContactsUI.js (onMenuRawContact): + New callback to show the vCard content from the menu. + + * UI/WebServerResources/ContactsUI.js (onContactMenuPrepareVisibility): + Enable the export and raw functions only on vcards contacts. + + * UI/Templates/ContactsUI/UIxContactFoldersView.wox: + New contextual menu item: Show vCard content + + * UI/Contacts/UIxContactFolderActions.m (rawAction): + New method that returns the raw contact data for all the contact uids provided + * UI/Contacts/UIxContactView.m (secondaryEmail): function renamed to secondaryEmails. It now returns all addresses instead of the first one found in the vcard. diff --git a/UI/Contacts/English.lproj/Localizable.strings b/UI/Contacts/English.lproj/Localizable.strings index 341bb39d0..539f2b41d 100644 --- a/UI/Contacts/English.lproj/Localizable.strings +++ b/UI/Contacts/English.lproj/Localizable.strings @@ -195,6 +195,7 @@ "Lists can't be moved or copied." = "Lists can't be moved or copied."; "Export" = "Export"; "Export Address Book..." = "Export Address Book..."; +"Show vCard content" = "Show vCard content"; "Import Cards" = "Import Cards"; "Select a vCard or LDIF file." = "Select a vCard or LDIF file."; "Upload" = "Upload"; diff --git a/UI/Contacts/French.lproj/Localizable.strings b/UI/Contacts/French.lproj/Localizable.strings index 255ee0c08..5efce3d8e 100644 --- a/UI/Contacts/French.lproj/Localizable.strings +++ b/UI/Contacts/French.lproj/Localizable.strings @@ -195,6 +195,7 @@ "Lists can't be moved or copied." = "Les listes ne peuvent pas être déplacées ou copiées."; "Export" = "Exporter"; "Export Address Book..." = "Exporter le carnet d'adresses..."; +"Show vCard content" = "Afficher le contenu vCard"; "Import Cards" = "Importer des contacts"; "Select a vCard or LDIF file." = "Sélectionner un fichier. LDIF ou vCard."; "Upload" = "Ajouter"; diff --git a/UI/Contacts/UIxContactFolderActions.m b/UI/Contacts/UIxContactFolderActions.m index 8adbcaa2b..4d2f6cccb 100644 --- a/UI/Contacts/UIxContactFolderActions.m +++ b/UI/Contacts/UIxContactFolderActions.m @@ -287,5 +287,51 @@ return rc; } +- (id ) rawAction +{ + WORequest *request; + WOResponse *response; + NSArray *contactsId; + NSEnumerator *uids; + NSString *uid; + id currentChild; + SOGoContactGCSFolder *sourceFolder; + NSMutableString *content; + + content = [NSMutableString string]; + request = [context request]; + response = [context response]; + sourceFolder = [self clientObject]; + contactsId = [request formValuesForKey: @"uid"]; + + if ((uids = [contactsId objectEnumerator])) + { + while ((uid = [uids nextObject])) + { + currentChild = [sourceFolder lookupName: uid + inContext: [self context] + acquire: NO]; + if([currentChild isKindOfClass: [NSException class]]) + continue; + [content appendFormat: [currentChild contentAsString]]; + [content appendString: @"\n"]; + } + } + + if (![content length]) + { + response = [self responseWithStatus: 404 + andString: @"Contact does not exist"]; + } + else + { + [response setHeader: @"text/plain; charset=utf-8" + forKey: @"content-type"]; + [response appendContentString: content]; + } + + return response; +} + @end /* UIxContactsListView */ diff --git a/UI/Contacts/product.plist b/UI/Contacts/product.plist index 8aadf26a2..6ee56d387 100644 --- a/UI/Contacts/product.plist +++ b/UI/Contacts/product.plist @@ -99,6 +99,11 @@ actionClass = "UIxContactFolderActions"; actionName = "export"; }; + raw = { + protectedBy = "View"; + actionClass = "UIxContactFolderActions"; + actionName = "raw"; + }; exportFolder = { protectedBy = "View"; actionClass = "UIxContactFolderActions"; diff --git a/UI/Templates/ContactsUI/UIxContactFoldersView.wox b/UI/Templates/ContactsUI/UIxContactFoldersView.wox index 5918e9dae..716fa06e9 100644 --- a/UI/Templates/ContactsUI/UIxContactFoldersView.wox +++ b/UI/Templates/ContactsUI/UIxContactFoldersView.wox @@ -84,6 +84,7 @@
  • +
  • diff --git a/UI/WebServerResources/ContactsUI.js b/UI/WebServerResources/ContactsUI.js index f836a7166..5b9d8d33f 100644 --- a/UI/WebServerResources/ContactsUI.js +++ b/UI/WebServerResources/ContactsUI.js @@ -290,6 +290,20 @@ function onMenuExportContact (event) { } } +function onMenuRawContact (event) { + var selectedFolders = $("contactFolders").getSelectedNodes(); + var canExport = (selectedFolders[0].getAttribute("owner") != "nobody"); + if (canExport) { + var selectedFolderId = $(selectedFolders[0]).readAttribute("id"); + var contactIds = document.menuTarget.collect(function(row) { + return row.readAttribute("id"); + }); + var url = ApplicationBaseURL + selectedFolderId + "/raw" + + "?uid=" + contactIds.join("&uid="); + openGenericWindow(url); + } +} + function actionContactCallback(http) { if (http.readyState == 4) if (isHttpStatus204(http.status)) { @@ -1176,6 +1190,19 @@ function onContactMenuPrepareVisibility() { deleteOption.removeClassName("disabled"); moveOption.removeClassName("disabled"); } + + var exportOption = elements[10]; + var rawOption = elements[11]; + if ($(selectedFolder).getAttribute("owner") == "nobody") { + // public folders (ldap) cannot export or show raw contacts + exportOption.addClassName("disabled"); + rawOption.addClassName("disabled"); + } + else { + exportOption.removeClassName("disabled"); + rawOption.removeClassName("disabled"); + } + return true; } @@ -1197,7 +1224,7 @@ getMenus = function() { onMenuWriteToContact, onMenuAIMContact, "-", onMenuDeleteContact, "-", "moveContactMenu", "copyContactMenu", - onMenuExportContact); + onMenuExportContact, onMenuRawContact); menus["searchMenu"] = new Array(setSearchCriteria, setSearchCriteria); var contactFoldersMenu = $("contactFoldersMenu"); diff --git a/UI/WebServerResources/generic.js b/UI/WebServerResources/generic.js index 4e8ccc642..7653e03fa 100644 --- a/UI/WebServerResources/generic.js +++ b/UI/WebServerResources/generic.js @@ -206,6 +206,42 @@ function openUserFolderSelector(callback, type) { } } +function openGenericWindow(url, wId) { + var div = $("popupFrame"); + if (div) { + if (!div.hasClassName("small")) + div.addClassName("small"); + var iframe = div.down("iframe"); + iframe.src = url; + if (!wId) + wId = "genericFrame"; + iframe.id = wId;; + var bgDiv = $("bgFrameDiv"); + if (bgDiv) { + bgDiv.show(); + } + else { + bgDiv = createElement("div", "bgFrameDiv"); + document.body.appendChild(bgDiv); + } + div.show(); + + return div; + } + else { + if (!wId) + wId = "_blank"; + else + wId = sanitizeWindowName(wId); + + var w = window.open(url, wId, + "width=550,height=650,resizable=1,scrollbars=1,location=0"); + w.focus(); + + return w; + } +} + function openContactWindow(url, wId) { var div = $("popupFrame"); if (div) {