Changeset 802
- Timestamp:
- 01/30/11 18:04:01 (2 years ago)
- Location:
- apps/iphone/my.tel/trunk/Classes
- Files:
-
- 2 modified
-
ProfileRecordsViewController.h (modified) (3 diffs)
-
ProfileRecordsViewController.m (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
apps/iphone/my.tel/trunk/Classes/ProfileRecordsViewController.h
r793 r802 21 21 }; 22 22 23 @interface ProfileRecordsViewController : RecordViewController <HATextViewEditDelegate, UIAlertViewDelegate > {23 @interface ProfileRecordsViewController : RecordViewController <HATextViewEditDelegate, UIAlertViewDelegate, UIActionSheetDelegate> { 24 24 NSDictionary *theProfile; 25 25 NSString *ninfoApiId; 26 26 NSString *ninfoText; 27 28 BOOL showDisabledRecords; 27 NSUInteger selectedRowIndex; 29 28 30 29 IBOutlet UIView *tableHeaderView; … … 45 44 - (void)disableRecordsUsingGlobal:(BOOL)isGlobal; 46 45 - (void)displayDisabledRecords:(BOOL)showDisabled; 46 - (void)triggerOperationsQueueWithJson:(NSDictionary *)parsedJson; 47 47 48 48 - (IBAction)didClickCancel:(id)sender; … … 54 54 @property (nonatomic, retain) NSString *ninfoText; 55 55 56 @property (nonatomic) BOOL showDisabledRecords;57 58 56 @property (nonatomic, retain) IBOutlet UIView *tableHeaderView; 59 57 @property (nonatomic, retain) IBOutlet UITableViewCell *ninfoCell; -
apps/iphone/my.tel/trunk/Classes/ProfileRecordsViewController.m
r794 r802 13 13 #define kNINFOMaxLength 255 // NINFO max length 14 14 15 @interface ProfileRecordsViewController (PrivateMethods) 16 17 - (void)performRecordEnabling:(BOOL)enable usingGlobal:(BOOL)isGlobal; 18 19 @end 20 21 15 22 @implementation ProfileRecordsViewController 16 23 … … 18 25 @synthesize ninfoApiId; 19 26 @synthesize ninfoText; 20 21 @synthesize showDisabledRecords;22 27 23 28 @synthesize tableHeaderView; … … 33 38 34 39 theC.theProfile = aProfile; 35 theC.showDisabledRecords = NO;36 40 [theC _setDidPreload:preload]; 37 41 theC.delegate = aDelegate; … … 189 193 190 194 - (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath { 191 // we only want to allow selection for the profile records when editing 192 if (indexPath.section == kKProfileTableViewSectionRecords) { 193 if (! self.editing) { 194 return nil; 195 } 196 NSDictionary *uiItem = [uiArray objectAtIndex:indexPath.row]; 197 if ([[uiItem valueForKey:@"global"] integerValue] == 1) { 198 // TODO: manage globals 199 NSAssert(FALSE, @"GLOBAL! Must show a question to disable global or cancel"); 200 return nil; 201 } 202 } 195 // override superclass behavior 203 196 return indexPath; 204 197 } … … 217 210 [self.navigationController pushViewController:teC animated:YES]; 218 211 } else if (indexPath.section == kKProfileTableViewSectionRecords) { 212 selectedRowIndex = indexPath.row; 219 213 NSMutableDictionary *uiItem = [[uiArray objectAtIndex:indexPath.row] retain]; 214 NSString *sheetTitle; 220 215 if ([[uiItem valueForKey:@"enabled"] integerValue] == 0) { 221 [uiItem setValue:@"1" forKey:@"enabled"];216 sheetTitle = LocStr(@"Enable record:"); 222 217 } else { 223 [uiItem setValue:@"0" forKey:@"enabled"]; 224 } 218 sheetTitle = LocStr(@"Disable record:"); 219 } 220 221 UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:sheetTitle 222 delegate:self 223 cancelButtonTitle:nil 224 destructiveButtonTitle:nil 225 otherButtonTitles:LocStr(@"in this profile"),LocStr(@"in ALL profiles"),nil]; 226 actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent; 227 [actionSheet showInView:tableView]; 228 [actionSheet release]; 225 229 [uiItem release]; 226 [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];227 230 } else if (indexPath.section == kKProfileTableViewSectionActivate) { 228 231 [self didClickActivate:nil]; … … 240 243 //Toggles the receiver into and out of editing mode. 241 244 [super setEditing:editing animated:animated]; 242 self.showDisabledRecords = editing;243 245 if (editing) { 244 246 [self displayDisabledRecords:YES]; … … 253 255 buttonEditCount = 4; 254 256 self.navigationItem.leftBarButtonItem = nil; 255 [self enableRecordsUsingGlobal:NO]; 256 [self getRecords]; 257 self.navigationItem.rightBarButtonItem.enabled = NO; 258 // Now trigger the whole update cycle, starting with non-global item enabling 259 [self triggerOperationsQueueWithJson:nil]; 257 260 } 258 261 } … … 314 317 } 315 318 316 - (void) updateEditButtonAndDoNothing:(NSDictionary *)parsedJson {319 - (void)triggerOperationsQueueWithJson:(NSDictionary *)parsedJson { 317 320 // hack to ensure: 318 321 // 1- that all enable-disable actions are done in serial order 319 322 // 2- that the user cannot re-edit the table before all is done 320 323 // call enableRecordsUsingGlobal:NO, and all goes from there automatically 324 self.navigationItem.rightBarButtonItem.enabled = NO; 321 325 if (parsedJson) { 322 326 [[MyTelConnect sharedInstance] doNothing:parsedJson]; 323 327 } 324 328 switch (buttonEditCount) { 325 case 4: // This case will be skipped if you start by calling enableRecordsUsingGlobal:NO 329 case 4: // This case should be skipped if you start by calling enableRecordsUsingGlobal:NO 330 buttonEditCount--; 326 331 [self enableRecordsUsingGlobal:NO]; 327 332 break; 328 333 case 3: 334 buttonEditCount--; 329 335 [self enableRecordsUsingGlobal:YES]; 330 336 break; 331 337 case 2: 338 buttonEditCount--; 339 [self disableRecordsUsingGlobal:YES]; 340 break; 341 case 1: 342 buttonEditCount--; 332 343 [self disableRecordsUsingGlobal:NO]; 333 344 break; 334 case 1:335 [self disableRecordsUsingGlobal:YES];336 break;337 345 case 0: 338 self.navigationItem.rightBarButtonItem = self.editButtonItem;346 [self getRecords]; // Necessary to resync the recordsArray 339 347 break; 340 348 default: 341 349 buttonEditCount = 0; 342 self.navigationItem.rightBarButtonItem = self.editButtonItem;350 self.navigationItem.rightBarButtonItem.enabled = YES; 343 351 break; 344 352 } … … 409 417 } 410 418 [self.delegate dataDidChangeInController:self]; 411 [self displayDisabledRecords:self.showDisabledRecords]; 419 [self displayDisabledRecords:self.tableView.editing]; 420 self.navigationItem.rightBarButtonItem.enabled = YES; // could have been disabled by the update queue 412 421 } 413 422 … … 557 566 } 558 567 568 #pragma mark UIActionSheet delegate methods 569 570 - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { 571 if (buttonIndex > 1) 572 return; 573 NSMutableDictionary *uiItem = [[uiArray objectAtIndex:selectedRowIndex] retain]; 574 if (buttonIndex == 0) { 575 // this profile 576 [uiItem setValue:@"0" forKey:@"global"]; 577 } else if (buttonIndex == 1) { 578 // all profiles 579 [uiItem setValue:@"1" forKey:@"global"]; 580 } 581 if ([[uiItem valueForKey:@"enabled"] integerValue] == 0) { 582 [uiItem setValue:@"1" forKey:@"enabled"]; 583 } else { 584 [uiItem setValue:@"0" forKey:@"enabled"]; 585 } 586 [uiItem release]; 587 NSIndexPath *selectedRowPath = [NSIndexPath indexPathForRow:selectedRowIndex inSection:kKProfileTableViewSectionRecords]; 588 [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:selectedRowPath] withRowAnimation:UITableViewRowAnimationFade]; 589 } 590 591 559 592 #pragma mark - 560 593 #pragma mark Data management … … 736 769 737 770 - (void)enableRecordsUsingGlobal:(BOOL)isGlobal { 738 // inputRecords = { 739 // domainName: "cartman.tel", 740 // profiles: [23, 35], 741 // apiIds: [23, 2, 22] 742 // }; 743 // 744 // successResult = { 745 // success: true, 746 // actionMessages: ["records enabled" 747 // "2nd message here", 748 // "3rd message here"] 749 // }; 750 751 buttonEditCount--; 771 [self performRecordEnabling:YES usingGlobal:isGlobal]; 772 } 773 774 - (void)disableRecordsUsingGlobal:(BOOL)isGlobal { 775 [self performRecordEnabling:NO usingGlobal:isGlobal]; 776 } 777 778 - (void)performRecordEnabling:(BOOL)enable usingGlobal:(BOOL)isGlobal { 779 // inputRecords = { 780 // domainName: "cartman.tel", 781 // profiles: [23, 35], 782 // apiIds: [23, 2, 22] 783 // }; 784 // 785 // successResult = { 786 // success: true, 787 // actionMessages: ["records disabled" 788 // "2nd message here", 789 // "3rd message here"] 790 // }; 791 NSString *theAction; 792 if (enable) { 793 theAction = @"enablerecords"; 794 } else { 795 theAction = @"disablerecords"; 796 } 797 752 798 NSMutableArray *apiIdArray = [NSMutableArray arrayWithCapacity:[uiArray count]]; 753 799 for (NSDictionary *theRow in uiArray) { 754 800 if ([[theRow valueForKey:@"global"] integerValue] != isGlobal) { 755 // We don't modify records that are not what we're asking for: either global or profile-specific801 // We don't modify records that are not what we're asking for: either global or profile-specific 756 802 continue; 757 803 } 758 if ([[theRow valueForKey:@"enabled"] integerValue] == 1) {804 if ([[theRow valueForKey:@"enabled"] boolValue] == enable) { 759 805 [apiIdArray addObject:[theRow objectForKey:@"apiId"]]; 760 806 } 761 807 } 762 808 if ([apiIdArray count] == 0) { 763 [self performSelector:@selector( updateEditButtonAndDoNothing:) withObject:nil];809 [self performSelector:@selector(triggerOperationsQueueWithJson:) withObject:nil]; 764 810 return; 765 811 } … … 767 813 Record *conn = [[[Record alloc] init] autorelease]; 768 814 [conn setTheDelegate:self]; 769 [conn setActionSel:@selector( updateEditButtonAndDoNothing:)];770 [conn setConnectionUrl:[conn urlFromAction: @"enablerecords"]];815 [conn setActionSel:@selector(triggerOperationsQueueWithJson:)]; 816 [conn setConnectionUrl:[conn urlFromAction:theAction]]; 771 817 772 818 NSMutableDictionary *requestData = [[NSMutableDictionary dictionaryWithCapacity:3] retain]; … … 779 825 } 780 826 [requestData setObject:profiles forKey:@"profiles"]; 781 827 782 828 [requestData setObject:apiIdArray forKey:@"apiIds"]; 783 829 … … 786 832 [requestData release]; 787 833 } 788 789 - (void)disableRecordsUsingGlobal:(BOOL)isGlobal {790 // inputRecords = {791 // domainName: "cartman.tel",792 // profiles: [23, 35],793 // apiIds: [23, 2, 22]794 // };795 //796 // successResult = {797 // success: true,798 // actionMessages: ["records disabled"799 // "2nd message here",800 // "3rd message here"]801 // };802 803 buttonEditCount--;804 NSMutableArray *apiIdArray = [NSMutableArray arrayWithCapacity:[uiArray count]];805 for (NSDictionary *theRow in uiArray) {806 if ([[theRow valueForKey:@"global"] integerValue] != isGlobal) {807 // We don't modify records that are not what we're asking for: either global or profile-specific808 continue;809 }810 if ([[theRow valueForKey:@"enabled"] integerValue] == 1) {811 [apiIdArray addObject:[theRow objectForKey:@"apiId"]];812 }813 }814 if ([apiIdArray count] == 0) {815 [self performSelector:@selector(updateEditButtonAndDoNothing:) withObject:nil];816 return;817 }818 819 Record *conn = [[[Record alloc] init] autorelease];820 [conn setTheDelegate:self];821 [conn setActionSel:@selector(updateEditButtonAndDoNothing:)];822 [conn setConnectionUrl:[conn urlFromAction:@"disablerecords"]];823 824 NSMutableDictionary *requestData = [[NSMutableDictionary dictionaryWithCapacity:3] retain];825 [requestData setObject:[self.delegate domain] forKey:@"domainName"];826 NSArray *profiles;827 if (isGlobal) {828 profiles = [NSArray arrayWithObject:@"-1"]; // global profile829 } else {830 profiles = [NSArray arrayWithObject:[self.theProfile objectForKey:@"id"]];831 }832 [requestData setObject:profiles forKey:@"profiles"];833 834 [requestData setObject:apiIdArray forKey:@"apiIds"];835 836 [conn setPayload:requestData];837 [conn performLookup:TRUE];838 [requestData release];839 }840 841 834 @end 842 835








