Import completed

Monotone-Parent: 3ea392b157dc9573c7f8219aa7296cf845c3b081
Monotone-Revision: 80ad9ff70fe3d4130d99bbd2590349b71c85b9f3

Monotone-Author: crobert@inverse.ca
Monotone-Date: 2009-09-03T14:18:13
Monotone-Branch: ca.inverse.sogo
maint-2.0.2
C Robert 2009-09-03 14:18:13 +00:00
parent eff69827cc
commit 110bfdcb4e
19 changed files with 238 additions and 40 deletions

View File

@ -1,3 +1,7 @@
2009-09-03 Cyril Robert <crobert@inverse.ca>
* UI/Contacts/UIxContactsListView.m: Added ldif / vcard import
2009-09-02 Cyril Robert <crobert@inverse.ca>
* UI/Contacts/UIxContactsListView.m (exportAction): Added to support export.

View File

@ -180,3 +180,6 @@
"Lists can't be moved or copied." = "Lists can't be moved or copied.";
"Export" = "Export";
"Import cards" = "Import cards";
"Select file..." = "Select file...";
"Upload" = "Upload";

View File

@ -180,3 +180,6 @@
"Lists can't be moved or copied." = "Lists can't be moved or copied.";
"Export" = "Export";
"Import cards" = "Import cards";
"Select file..." = "Select file...";
"Upload" = "Upload";

View File

@ -180,3 +180,6 @@
"Lists can't be moved or copied." = "Lists can't be moved or copied.";
"Export" = "Export";
"Import cards" = "Import cards";
"Select file..." = "Select file...";
"Upload" = "Upload";

View File

@ -180,3 +180,6 @@
"Lists can't be moved or copied." = "Lists can't be moved or copied.";
"Export" = "Export";
"Import cards" = "Import cards";
"Select file..." = "Select file...";
"Upload" = "Upload";

View File

@ -180,3 +180,6 @@
"Lists can't be moved or copied." = "Les listes ne peuvent pas être déplacées ou copiées.";
"Export" = "Exporter";
"Import cards" = "Importer des contacts";
"Select file..." = "Sélectionner un fichier...";
"Upload" = "Ajouter";

View File

@ -180,3 +180,6 @@
"Lists can't be moved or copied." = "Lists can't be moved or copied.";
"Export" = "Export";
"Import cards" = "Import cards";
"Select file..." = "Select file...";
"Upload" = "Upload";

View File

@ -180,3 +180,6 @@
"Lists can't be moved or copied." = "Lists can't be moved or copied.";
"Export" = "Export";
"Import cards" = "Import cards";
"Select file..." = "Select file...";
"Upload" = "Upload";

View File

@ -180,3 +180,6 @@
"Lists can't be moved or copied." = "Lists can't be moved or copied.";
"Export" = "Export";
"Import cards" = "Import cards";
"Select file..." = "Select file...";
"Upload" = "Upload";

View File

@ -165,3 +165,6 @@
"Lists can't be moved or copied." = "Lists can't be moved or copied.";
"Export" = "Export";
"Import cards" = "Import cards";
"Select file..." = "Select file...";
"Upload" = "Upload";

View File

@ -180,3 +180,6 @@
"Lists can't be moved or copied." = "Lists can't be moved or copied.";
"Export" = "Export";
"Import cards" = "Import cards";
"Select file..." = "Select file...";
"Upload" = "Upload";

View File

@ -35,6 +35,10 @@
NSArray *contactInfos;
}
- (void) importLdifData: (NSString *) ldifData;
- (void) importVcardData: (NSString *) vcardData;
- (void) importVcard: (NGVCard *) card;
@end
#endif /* __UIxContactsListView_H__ */

View File

@ -27,6 +27,7 @@
#import <NGObjWeb/NSException+HTTP.h>
#import <NGObjWeb/WOContext.h>
#import <NGObjWeb/WOResponse.h>
#import <NGObjWeb/WORequest.h>
#import <NGExtensions/NSString+misc.h>
#import <NGExtensions/NSNull+misc.h>
@ -37,7 +38,10 @@
#import <NGCards/NGVCard.h>
#import <NGCards/NGVList.h>
#import <SoObjects/Contacts/SOGoContactGCSEntry.h>
#import <SoObjects/Contacts/SOGoContactLDIFEntry.h>
#import <SoObjects/Contacts/SOGoContactGCSList.h>
#import <SoObjects/Contacts/SOGoContactGCSFolder.h>
#import <GDLContentStore/GCSFolder.h>
#import "UIxContactsListView.h"
@ -192,7 +196,7 @@
NSEnumerator *uids;
NSString *uid;
id currentChild;
id sourceFolder;
SOGoContactGCSFolder *sourceFolder;
NSMutableString *content;
content = [NSMutableString string];
@ -223,5 +227,109 @@
return response;
}
- (id <WOActionResults>) importAction
{
WORequest *request;
NSData *data;
NSString *fileContent;
request = [context request];
data = (NSData *)[request formValueForKey: @"contactsFile"];
fileContent = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
[fileContent autorelease];
if (fileContent && [fileContent length])
{
if ([fileContent hasPrefix: @"dn:"])
[self importLdifData: fileContent];
else
[self importVcardData: fileContent];
}
return [self redirectToLocation: @"../view"];
}
- (void) importLdifData: (NSString *) ldifData
{
SOGoContactGCSFolder *folder;
NSString *key, *value;
NSArray *ldifContacts, *lines, *components;
NSMutableDictionary *entry;
NGVCard *vCard;
NSString *uid;
int i,j,count,linesCount;
folder = [self clientObject];
ldifContacts = [ldifData componentsSeparatedByString: @"\ndn"];
count = [ldifContacts count];
for (i = 0; i < count; i++)
{
SOGoContactLDIFEntry *ldifEntry;
entry = [NSMutableDictionary dictionary];
lines = [[ldifContacts objectAtIndex: i]
componentsSeparatedByString: @"\n"];
linesCount = [lines count];
for (j = 0; j < linesCount; j++)
{
components = [[lines objectAtIndex: j]
componentsSeparatedByString: @": "];
if ([components count] == 2)
{
key = [components objectAtIndex: 0];
value = [components objectAtIndex: 1];
if ([key length] == 0)
key = @"dn";
[entry setObject: value forKey: key];
}
else
{
break;
}
}
uid = [folder globallyUniqueObjectId];
ldifEntry = [SOGoContactLDIFEntry contactEntryWithName: uid
withLDIFEntry: entry
inContainer: folder];
if (ldifEntry)
{
vCard = [ldifEntry vCard];
[self importVcard: vCard];
}
}
}
- (void) importVcardData: (NSString *) vcardData
{
NGVCard *card;
card = [NGVCard parseSingleFromSource: vcardData];
[self importVcard: card];
}
- (void) importVcard: (NGVCard *) card
{
NSString *uid, *name;
SOGoContactGCSFolder *folder;
NSException *ex;
if (card)
{
folder = [self clientObject];
uid = [folder globallyUniqueObjectId];
name = [NSString stringWithFormat: @"%@.vcf", uid];
[card setUid: uid];
ex = [[folder ocsFolder] writeContent: [card versitString]
toName: name
baseVersion: 0];
if (ex)
NSLog (@"write failed: %@", ex);
}
}
@end /* UIxContactsListView */

View File

@ -164,3 +164,6 @@
"Lists can't be moved or copied." = "Lists can't be moved or copied.";
"Export" = "Export";
"Import cards" = "Import cards";
"Select file..." = "Select file...";
"Upload" = "Upload";

View File

@ -103,6 +103,11 @@
pageName = "UIxContactsListView";
actionName = "export";
};
import = {
protectedBy = "View";
pageName = "UIxContactsListView";
actionName = "import";
};
userRights = {
protectedBy = "ReadAcls";
pageName = "UIxContactsUserRightsEditor";

View File

@ -25,6 +25,19 @@
</var:if>
</style>
<div id="uploadDialog" style="display: none" class="dialog left">
<div>
<h3><var:string label:value="Select file..."/></h3>
<form name="uploadForm" id="uploadForm" method="post"
enctype="multipart/form-data"
onsubmit="return validateUploadForm()">
<p><input type="file" name="contactsFile" id="contactsFile" /></p>
<p><input class="button" type="submit" const:id="uploadSubmit" label:value="Upload"/>
<input class="button" type="button" const:id="uploadCancel" label:value="Cancel"/></p>
</form>
</div>
</div>
<div class="menu" id="contactFoldersMenu">
<ul>
<li><var:string label:value="Properties" /></li>
@ -32,6 +45,7 @@
<li><var:string label:value="New Card" /></li>
<li><var:string label:value="New List" /></li>
<li><!-- separator --></li>
<li><var:string label:value="Import cards" /></li>
<li><var:string label:value="Delete" /></li>
<li><!-- separator --></li>
<li><var:string label:value="Sharing..." /></li>

View File

@ -655,6 +655,35 @@ function onFolderUnsubscribeCB(folderId) {
onFolderSelectionChange();
}
function onAddressBookImport(event) {
var node = $("contactFolders").getSelectedNodes().first();
var folderId = node.getAttribute("id");
var url = ApplicationBaseURL + folderId + "/import";
$("uploadForm").action = url;
$("uploadCancel").onclick = hideContactsImport;
$("contactsFile").value = "";
var cellPosition = node.cumulativeOffset();
var cellDimensions = node.getDimensions();
var left = cellDimensions['width'] - 20;
var top = cellPosition[1];
var div = $("uploadDialog");
div.style.top = top + "px";
div.style.left = left + "px";
div.style.display = "block";
}
function hideContactsImport () {
$("uploadDialog").style.display = "none";
}
function validateUploadForm () {
rc = false;
if ($("contactsFile").value.length)
rc = true;
return rc;
}
function onAddressBookRemove(event) {
var selector = $("contactFolders");
var nodes = selector.getSelectedNodes();
@ -986,7 +1015,8 @@ function onContactMenuPrepareVisibility() {
function getMenus() {
var menus = {};
menus["contactFoldersMenu"] = new Array(onAddressBookModify, "-", newContact,
null, "-", onAddressBookRemove, "-",
null, "-", onAddressBookImport,
onAddressBookRemove, "-",
onMenuSharing);
menus["contactMenu"] = new Array(onMenuEditContact, "-",
onMenuWriteToContact, onMenuAIMContact,

View File

@ -291,44 +291,6 @@ TABLE#eventsList TH
TABLE#eventsList TH
{ white-space: pre; }
DIV#uploadDialog
{ border-width: 1px;
width: 260px;
height: 118px;
}
DIV.dialog
{ position: absolute;
top: 100px;
left: 75px;
z-index: 50; }
DIV.dialog DIV
{ border: 1px solid #444;
/*height: 100px;*/
background-color: #fff;
padding: 5px; }
DIV.dialog.left
{ background-image: url("dialog-left.png");
background-repeat: no-repeat;
background-position: top left; }
DIV.dialog.left DIV
{ border-left: 0;
margin-left: 19px;
text-align: left; }
DIV.dialog.right
{ background-image: url("dialog-right.png");
background-repeat: no-repeat;
background-position: top right; }
DIV.dialog.right DIV
{ border-right: 0;
margin-right: 19px;
text-align: right; }
DIV#eventDialog
{ width: 200px; }
DIV#eventDialog H1,

View File

@ -782,3 +782,41 @@ DIV.resize-handle
background-color: #f0f0f0 !important;
color: #000000 !important;
}
DIV#uploadDialog
{ border-width: 1px;
width: 260px;
height: 118px;
}
DIV.dialog
{ position: absolute;
top: 100px;
left: 75px;
z-index: 50; }
DIV.dialog DIV
{ border: 1px solid #444;
/*height: 100px;*/
background-color: #fff;
padding: 5px; }
DIV.dialog.left
{ background-image: url("dialog-left.png");
background-repeat: no-repeat;
background-position: top left; }
DIV.dialog.left DIV
{ border-left: 0;
margin-left: 19px;
text-align: left; }
DIV.dialog.right
{ background-image: url("dialog-right.png");
background-repeat: no-repeat;
background-position: top right; }
DIV.dialog.right DIV
{ border-right: 0;
margin-right: 19px;
text-align: right; }