Changeset 623
- Timestamp:
- 01/11/10 10:26:27 (2 months ago)
- Location:
- apps/iphone/my.tel/trunk/Classes
- Files:
-
- 3 modified
-
GroupFriendsController.m (modified) (1 diff)
-
GroupsViewController.h (modified) (2 diffs)
-
GroupsViewController.m (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
apps/iphone/my.tel/trunk/Classes/GroupFriendsController.m
r593 r623 56 56 57 57 - (void)deleteGroup { 58 Group *conn = [[[Group alloc] init] autorelease]; 59 [conn setTheDelegate:self]; 60 [conn setActionSel:@selector(groupDeletedWithJson:)]; 61 [conn setConnectionUrl:[conn urlFromAction:@"deletegroup"]]; 62 63 NSMutableDictionary *requestData = [[NSMutableDictionary dictionaryWithCapacity:2] retain]; 64 [requestData setObject:[self.delegate domain] forKey:@"domainName"]; 65 [requestData setObject:[theGroup objectForKey:@"id"] forKey:@"groupId"]; 66 67 [conn setPayload:requestData]; 68 NSDictionary *parsedJson = [conn performLookup:FALSE]; 69 [requestData release]; 70 if ([[parsedJson valueForKey:@"success"] integerValue] == 1) { 71 [self.delegate dataDidChangeInController:self]; 72 [self.navigationController popViewControllerAnimated:YES]; 73 } else { 74 [Group throwJsonErrorAlert:parsedJson]; 75 } 58 [self.delegate objectWillGetDeletedInController:self]; 59 [self.navigationController popViewControllerAnimated:YES]; 76 60 } 77 61 -
apps/iphone/my.tel/trunk/Classes/GroupsViewController.h
r593 r623 16 16 <UITableViewDelegate, UITableViewDataSource, UIAlertViewDelegate, TelControllerDelegate> { 17 17 NSMutableArray *groupsArray; // retrieved raw JSON data (also used as the datasource array) 18 NSUInteger currentGroupIndex; // groupsArray index of the group being edited or viewed 18 19 id <TelControllerDelegate> delegate; 19 20 @private … … 26 27 - (void)listGroups; 27 28 - (void)createGroup:(NSString *)aGroupName; 28 29 - (void)deleteGroupAtIndex:(NSUInteger)index; 29 30 30 31 - (IBAction)didClickAdd:(id)sender; -
apps/iphone/my.tel/trunk/Classes/GroupsViewController.m
r593 r623 43 43 - (void)viewDidLoad { 44 44 [super viewDidLoad]; 45 self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd 46 target:self 47 action:@selector(didClickAdd:)] 48 autorelease]; 45 self.navigationItem.rightBarButtonItem = [self editButtonItem]; 46 // disable editing until we've loaded the data 47 self.navigationItem.rightBarButtonItem.enabled = NO; 49 48 self.title = @"Privacy Groups"; 50 49 } … … 88 87 - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView 89 88 editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { 89 NSDictionary *sGroup = [groupsArray objectAtIndex:indexPath.row]; 90 if ([[sGroup valueForKey:@"allFriends"] integerValue] == 1) { 91 return UITableViewCellEditingStyleNone; 92 } 90 93 return UITableViewCellEditingStyleDelete; 91 94 } 92 95 93 96 - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { 94 // Don't allow deleting here, do it in the navigation pane of the individual group 95 return FALSE; 97 // Disable swipe-to-delete: don't allow row edit if table not in edit mode 98 return (tableView.editing); 99 } 100 101 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle 102 forRowAtIndexPath:(NSIndexPath *)indexPath { 103 if (editingStyle == UITableViewCellEditingStyleDelete) { 104 [self deleteGroupAtIndex:indexPath.row]; 105 } 96 106 } 97 107 … … 119 129 cell.textLabel.text = [sGroup valueForKey:@"name"]; 120 130 } 131 [cell.textLabel setNeedsDisplay]; 121 132 return cell; 122 133 } 123 134 124 135 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 136 [tableView deselectRowAtIndexPath:indexPath animated:YES]; 137 currentGroupIndex = indexPath.row; 125 138 GroupFriendsController *newController = [GroupFriendsController 126 139 controllerForGroup:[groupsArray objectAtIndex:indexPath.row] delegate:self]; 127 [tableView deselectRowAtIndexPath:indexPath animated:YES];128 140 [[self navigationController] pushViewController:newController animated:YES]; 129 141 } 142 143 - (void)setEditing:(BOOL)editing animated:(BOOL)animated { 144 [super setEditing:editing animated:animated]; 145 if (editing) { 146 self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd 147 target:self 148 action:@selector(didClickAdd:)] autorelease]; 149 } else { 150 self.navigationItem.leftBarButtonItem = nil; 151 } 152 } 153 130 154 131 155 #pragma mark ------ UI Methods and JSON delegates … … 141 165 alert.uiStringField.text = @""; 142 166 [alert show]; 167 } 168 169 - (void)deleteGroupAtIndex:(NSUInteger)index { 170 NSDictionary *aGroup = [groupsArray objectAtIndex:index]; 171 if (!aGroup) { 172 return; 173 } 174 [aGroup retain]; 175 Group *conn = [[[Group alloc] init] autorelease]; 176 [conn setTheDelegate:self]; 177 [conn setActionSel:@selector(groupDeletedWithJson:)]; 178 [conn setConnectionUrl:[conn urlFromAction:@"deletegroup"]]; 179 180 NSMutableDictionary *requestData = [[NSMutableDictionary dictionaryWithCapacity:2] retain]; 181 [requestData setObject:[self.delegate domain] forKey:@"domainName"]; 182 [requestData setObject:[aGroup objectForKey:@"id"] forKey:@"groupId"]; 183 184 [conn setPayload:requestData]; 185 NSDictionary *parsedJson = [conn performLookup:FALSE]; 186 [requestData release]; 187 if ([[parsedJson valueForKey:@"success"] integerValue] == 0) { 188 [Group throwJsonErrorAlert:parsedJson]; 189 } else { 190 [self.groupsArray removeObjectAtIndex:index]; 191 NSIndexPath *deleteIndexPath = [NSIndexPath indexPathForRow:index inSection:0]; 192 [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:deleteIndexPath] withRowAnimation:UITableViewRowAnimationFade]; 193 } 143 194 } 144 195 … … 169 220 [self.delegate dataDidChangeInController:self]; 170 221 [self.tableView reloadData]; 222 self.navigationItem.rightBarButtonItem.enabled = YES; 171 223 } else { 172 224 [self.tableView reloadData]; … … 186 238 // request the domain from the calling controller 187 239 return [self.delegate domain]; 240 } 241 242 - (void)objectWillGetDeletedInController:(UIViewController *)controller { 243 if ([controller isMemberOfClass:[GroupFriendsController class]]) { 244 [self deleteGroupAtIndex:currentGroupIndex]; 245 } 188 246 } 189 247








