diff --git a/ChangeLog b/ChangeLog index db7664943..3faecab72 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,17 @@ 2010-11-01 Wolfgang Sourdeau + * UI/WebServerResources/ContactsUI.js: (resetCategoriesMenu) + (onCategoriesMenuPrepareVisibility, onCategoriesMenuItemClick) + (setCategoryOnNode, unsetCategoryOnNode): new methods designed to + handle the handling of categories directly from the contacts list. + + * SoObjects/Contacts/SOGoContactGCSFolder.m (+initialize): we now + return the "c_categories" field too. + + * UI/Contacts/UIxContactActions.m: new class module implementing + actions on contacts. + (-setCategoryAction, -unsetCategoryAction): new actions. + * UI/WebServerResources/generic.js (triggerAjaxRequest): invoke the request callback only when set on the http object. diff --git a/SoObjects/Contacts/SOGoContactGCSFolder.m b/SoObjects/Contacts/SOGoContactGCSFolder.m index b176e4da6..7279064e9 100644 --- a/SoObjects/Contacts/SOGoContactGCSFolder.m +++ b/SoObjects/Contacts/SOGoContactGCSFolder.m @@ -62,6 +62,7 @@ static NSArray *folderListingFields = nil; @"c_cn", @"c_givenname", @"c_sn", @"c_screenname", @"c_o", @"c_mail", @"c_telephonenumber", + @"c_categories", @"c_component", nil]; } diff --git a/UI/Contacts/GNUmakefile b/UI/Contacts/GNUmakefile index ec7177f8c..90c97a79d 100644 --- a/UI/Contacts/GNUmakefile +++ b/UI/Contacts/GNUmakefile @@ -15,6 +15,7 @@ ContactsUI_OBJC_FILES = \ \ ContactsUIProduct.m \ UIxContactsFilterPanel.m \ + UIxContactActions.m \ UIxContactView.m \ UIxContactEditor.m \ UIxListView.m \ diff --git a/UI/Contacts/UIxContactActions.m b/UI/Contacts/UIxContactActions.m new file mode 100644 index 000000000..03f5f6a07 --- /dev/null +++ b/UI/Contacts/UIxContactActions.m @@ -0,0 +1,131 @@ +/* UIxContactActions.m - this file is part of SOGo + * + * Copyright (C) 2010 Inverse inc. + * + * Author: Wolfgang Sourdeau + * + * This file is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This file 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#import +#import + +#import +#import + +#import + +#import + +#import + +@interface NGVCard (SOGoActionCategory) + +- (BOOL) addOrRemove: (BOOL) set + category: (NSString *) newCategory; + +@end + +@implementation NGVCard (SOGoActionCategory) + +- (BOOL) addOrRemove: (BOOL) set + category: (NSString *) category +{ + NSMutableArray *categories; + BOOL modified; + NSUInteger idx; + + modified = NO; + + categories = [[self categories] mutableCopy]; + [categories autorelease]; + if (set) + { + if (![categories containsObject: category]) + { + [categories addObject: category]; + modified = YES; + } + } + else + { + idx = [categories indexOfObject: category]; + if (idx != NSNotFound) + { + [categories removeObjectAtIndex: idx]; + modified = YES; + } + } + + if (modified) + [self setCategories: categories]; + + return modified; +} + +@end + +@interface UIxContactActions : WODirectAction + +- (WOResponse *) setCategoryAction; +- (WOResponse *) unsetCategoryAction; + +@end + +@implementation UIxContactActions + +- (WOResponse *) _setOrUnsetCategoryAction: (BOOL) set +{ + SOGoContactGCSEntry *contact; + NSString *category; + WORequest *rq; + WOResponse *response; + NGVCard *card; + + rq = [context request]; + category = [rq formValueForKey: @"category"]; + if ([category length] > 0) + { + contact = [self clientObject]; + if (![contact isNew]) + { + card = [contact vCard]; + if ([card addOrRemove: set category: category]) + [contact save]; + response = [self responseWith204]; + } + else + response = [self responseWithStatus: 404 + andString: @"Contact does not exist"]; + } + else + response = [self responseWithStatus: 403 + andString: @"Missing 'category' parameter"]; + + return response; +} + +- (WOResponse *) setCategoryAction +{ + return [self _setOrUnsetCategoryAction: YES]; +} + +- (WOResponse *) unsetCategoryAction +{ + return [self _setOrUnsetCategoryAction: NO]; +} + +@end diff --git a/UI/Contacts/product.plist b/UI/Contacts/product.plist index 945c9a136..2136af2bf 100644 --- a/UI/Contacts/product.plist +++ b/UI/Contacts/product.plist @@ -184,6 +184,16 @@ pageName = "UIxContactEditor"; actionName = "write"; }; + setCategory = { + protectedBy = "Change Images And Files"; + actionClass = "UIxContactActions"; + actionName = "setCategory"; + }; + unsetCategory = { + protectedBy = "Change Images And Files"; + actionClass = "UIxContactActions"; + actionName = "unsetCategory"; + }; }; }; diff --git a/UI/Templates/ContactsUI/UIxContactFoldersView.wox b/UI/Templates/ContactsUI/UIxContactFoldersView.wox index 318d811cd..2bd9210cc 100644 --- a/UI/Templates/ContactsUI/UIxContactFoldersView.wox +++ b/UI/Templates/ContactsUI/UIxContactFoldersView.wox @@ -7,6 +7,7 @@ xmlns:uix="OGo:uix" xmlns:label="OGo:label" xmlns:rsrc="OGo:url" + const:userDefaultsKeys="SOGoContactsCategories" className="UIxPageFrame" title="name" var:popup="isPopup"> @@ -72,6 +73,7 @@