root/apps/iphone/my.tel/trunk/Classes/DomainViewController.m
@
657
| Revision 651, 24.1 kB (checked in by henri, 3 years ago) |
|---|
| Line | |
|---|---|
| 1 | // |
| 2 | // DomainViewController.m |
| 3 | // My.tel |
| 4 | // |
| 5 | // Created by Henri Asseily on 10/12/09. |
| 6 | // Copyright 2009 Telnic Ltd. All rights reserved. |
| 7 | // |
| 8 | |
| 9 | #import "DomainViewController.h" |
| 10 | |
| 11 | #define kDDSMaxLength 255 // DDS max length |
| 12 | |
| 13 | @interface DomainViewController (PrivateMethods) |
| 14 | - (NSInteger)sectionForIndex:(NSInteger)sectionIndex; |
| 15 | @end |
| 16 | |
| 17 | |
| 18 | @implementation DomainViewController |
| 19 | |
| 20 | @synthesize domain; |
| 21 | @synthesize ddsTitle; |
| 22 | @synthesize subdomainsArray; |
| 23 | @synthesize recordVC, keywordVC, locationVC, profileVC, groupVC; |
| 24 | |
| 25 | + (DomainViewController *)controllerForDomain:(NSString *)aDomain { |
| 26 | if (!aDomain) return nil; |
| 27 | DomainViewController *theC = [[[DomainViewController alloc] initWithStyle:UITableViewStyleGrouped] autorelease]; |
| 28 | theC.title = theC.domain = aDomain; |
| 29 | theC.ddsTitle = nil; |
| 30 | theC.subdomainsArray = [NSMutableArray arrayWithCapacity:10]; |
| 31 | [theC getSubFolderList]; |
| 32 | return theC; |
| 33 | } |
| 34 | |
| 35 | /* |
| 36 | - (id)initWithStyle:(UITableViewStyle)style { |
| 37 | // Override initWithStyle: if you create the controller programmatically and want to perform customization |
| 38 | // that is not appropriate for viewDidLoad. |
| 39 | if (self = [super initWithStyle:style]) { |
| 40 | } |
| 41 | return self; |
| 42 | } |
| 43 | */ |
| 44 | |
| 45 | - (void)viewDidLoad { |
| 46 | [super viewDidLoad]; |
| 47 | self.navigationItem.rightBarButtonItem = [self editButtonItem]; |
| 48 | self.tableView.allowsSelectionDuringEditing = YES; |
| 49 | [self getDisplayString]; |
| 50 | self.recordVC = [RecordViewController controllerWithDelegate:self preload:YES]; |
| 51 | self.keywordVC = [KeywordViewController controllerWithDelegate:self preload:YES]; |
| 52 | self.locationVC = [LocationViewController controllerWithDelegate:self preload:YES]; |
| 53 | self.profileVC = [ProfileViewController controllerWithDelegate:self preload:YES]; |
| 54 | self.groupVC = [GroupsViewController controllerWithDelegate:self preload:YES]; |
| 55 | } |
| 56 | |
| 57 | /* |
| 58 | - (void)viewWillAppear:(BOOL)animated { |
| 59 | [super viewWillAppear:animated]; |
| 60 | } |
| 61 | */ |
| 62 | |
| 63 | - (void)viewDidAppear:(BOOL)animated { |
| 64 | [super viewDidAppear:animated]; |
| 65 | } |
| 66 | |
| 67 | /* |
| 68 | - (void)viewWillDisappear:(BOOL)animated { |
| 69 | [super viewWillDisappear:animated]; |
| 70 | } |
| 71 | */ |
| 72 | /* |
| 73 | - (void)viewDidDisappear:(BOOL)animated { |
| 74 | [super viewDidDisappear:animated]; |
| 75 | } |
| 76 | */ |
| 77 | |
| 78 | /* |
| 79 | // Override to allow orientations other than the default portrait orientation. |
| 80 | - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { |
| 81 | // Return YES for supported orientations |
| 82 | return (interfaceOrientation == UIInterfaceOrientationPortrait); |
| 83 | } |
| 84 | */ |
| 85 | |
| 86 | - (void)didReceiveMemoryWarning { |
| 87 | // Releases the view if it doesn't have a superview. |
| 88 | [super didReceiveMemoryWarning]; |
| 89 | |
| 90 | // Release any cached data, images, etc that aren't in use. |
| 91 | } |
| 92 | |
| 93 | - (void)viewDidUnload { |
| 94 | self.ddsTitle = nil; |
| 95 | self.recordVC = nil; |
| 96 | self.keywordVC = nil; |
| 97 | self.locationVC = nil; |
| 98 | self.profileVC = nil; |
| 99 | self.groupVC = nil; |
| 100 | } |
| 101 | |
| 102 | #pragma mark - |
| 103 | #pragma mark Table view methods |
| 104 | |
| 105 | - (NSInteger)sectionForIndex:(NSInteger)sectionIndex { |
| 106 | // maps the proper section index based on editing mode |
| 107 | switch (sectionIndex) { |
| 108 | case kKDomainTableViewSectionTitle: |
| 109 | return (self.editing ? -1 : 0); |
| 110 | break; |
| 111 | case kKDomainTableViewSectionInfo: |
| 112 | return (self.editing ? -1 : 1); |
| 113 | break; |
| 114 | case kKDomainTableViewSectionFolders: |
| 115 | return (self.editing ? 1 : 2); |
| 116 | break; |
| 117 | case kKDomainTableViewSectionAddFolder: |
| 118 | return (self.editing ? 0 : -1); |
| 119 | break; |
| 120 | case kKDomainTableViewSectionsCount: |
| 121 | return (self.editing ? 2 : 3); |
| 122 | break; |
| 123 | default: |
| 124 | break; |
| 125 | } |
| 126 | return -1; |
| 127 | } |
| 128 | |
| 129 | - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { |
| 130 | return [self sectionForIndex:kKDomainTableViewSectionsCount]; |
| 131 | } |
| 132 | |
| 133 | // Customize the number of rows in the table view. |
| 134 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
| 135 | if (section == [self sectionForIndex:kKDomainTableViewSectionTitle]) |
| 136 | return (self.editing ? 0 : 1); |
| 137 | if (section == [self sectionForIndex:kKDomainTableViewSectionFolders]) |
| 138 | return [self.subdomainsArray count]; |
| 139 | if (section == [self sectionForIndex:kKDomainTableViewSectionInfo]) |
| 140 | // profiles, contacts, keywords, location, advanced |
| 141 | return (self.editing ? 0 : 5); |
| 142 | if (section == [self sectionForIndex:kKDomainTableViewSectionAddFolder]) |
| 143 | return (self.editing ? 1 : 0); |
| 144 | return 0; |
| 145 | } |
| 146 | |
| 147 | - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { |
| 148 | if (section == [self sectionForIndex:kKDomainTableViewSectionFolders]) |
| 149 | return @"Subfolders"; |
| 150 | if (section == [self sectionForIndex:kKDomainTableViewSectionInfo]) |
| 151 | return @"Information"; |
| 152 | return nil; |
| 153 | } |
| 154 | |
| 155 | // Customize the appearance of table view cells. |
| 156 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
| 157 | |
| 158 | static NSString *TitleCellIdentifier = @"TitleCell"; |
| 159 | static NSString *FoldersCellIdentifier = @"FoldersCell"; |
| 160 | static NSString *AddFolderCellIdentifier = @"AddFolderCell"; |
| 161 | static NSString *InfoCellIdentifier = @"InfoCell"; |
| 162 | |
| 163 | UITableViewCell *cell = nil; |
| 164 | |
| 165 | if (indexPath.section == [self sectionForIndex:kKDomainTableViewSectionTitle]) { |
| 166 | cell = [tableView dequeueReusableCellWithIdentifier:TitleCellIdentifier]; |
| 167 | if (cell == nil) { |
| 168 | cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 |
| 169 | reuseIdentifier:TitleCellIdentifier] autorelease]; |
| 170 | cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; |
| 171 | cell.textLabel.text = @"Display Title"; |
| 172 | } |
| 173 | if (self.ddsTitle != nil) { |
| 174 | cell.detailTextLabel.text = self.ddsTitle; |
| 175 | } |
| 176 | } else if (indexPath.section == [self sectionForIndex:kKDomainTableViewSectionFolders]) { |
| 177 | cell = [tableView dequeueReusableCellWithIdentifier:FoldersCellIdentifier]; |
| 178 | if (cell == nil) { |
| 179 | cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault |
| 180 | reuseIdentifier:FoldersCellIdentifier] autorelease]; |
| 181 | cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; |
| 182 | cell.editingAccessoryType = UITableViewCellAccessoryNone; |
| 183 | } |
| 184 | NSString *subDom = [[self.subdomainsArray objectAtIndex:indexPath.row] valueForKey:@"name"]; |
| 185 | // remove the postfix domain title from the subdomain, including the "." delimiter |
| 186 | // For offline testing usage, make sure we don't go over the index length |
| 187 | if ([subDom length] > [self.title length]) { |
| 188 | cell.textLabel.text = [subDom substringToIndex:([subDom length] - [self.title length] - 1)]; |
| 189 | } else { |
| 190 | cell.textLabel.text = subDom; |
| 191 | } |
| 192 | } else if (indexPath.section == [self sectionForIndex:kKDomainTableViewSectionInfo]) { |
| 193 | // profiles, contacts, keywords, location, profiles |
| 194 | // TODO: Add "Advanced" row for SMTP and other stuff |
| 195 | cell = [tableView dequeueReusableCellWithIdentifier:InfoCellIdentifier]; |
| 196 | if (cell == nil) { |
| 197 | cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 |
| 198 | reuseIdentifier:InfoCellIdentifier] autorelease]; |
| 199 | cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; |
| 200 | } |
| 201 | switch (indexPath.row) { |
| 202 | case 0: |
| 203 | cell.textLabel.text = @"Contact Items"; |
| 204 | break; |
| 205 | case 1: |
| 206 | cell.textLabel.text = @"Keywords"; |
| 207 | break; |
| 208 | case 2: |
| 209 | cell.textLabel.text = @"Location"; |
| 210 | break; |
| 211 | case 3: |
| 212 | cell.textLabel.text = @"Profiles"; |
| 213 | break; |
| 214 | case 4: |
| 215 | cell.textLabel.text = @"Privacy Groups"; |
| 216 | break; |
| 217 | default: |
| 218 | break; |
| 219 | } |
| 220 | } else if (indexPath.section == [self sectionForIndex:kKDomainTableViewSectionAddFolder]) { |
| 221 | cell = [tableView dequeueReusableCellWithIdentifier:AddFolderCellIdentifier]; |
| 222 | if (cell == nil) { |
| 223 | cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault |
| 224 | reuseIdentifier:AddFolderCellIdentifier] autorelease]; |
| 225 | cell.accessoryType = cell.editingAccessoryType = UITableViewCellAccessoryNone; |
| 226 | cell.textLabel.text = @"Add new folder"; |
| 227 | cell.textLabel.textColor = [UIColor blueColor]; |
| 228 | cell.textLabel.textAlignment = UITextAlignmentCenter; |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | return cell; |
| 233 | } |
| 234 | |
| 235 | //- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
| 236 | // // Don't allow selection of folders when in editing mode |
| 237 | // if (self.editing && (indexPath.section == [self sectionForIndex:kKDomainTableViewSectionFolders])) { |
| 238 | // return nil; |
| 239 | // } |
| 240 | // return indexPath; |
| 241 | //} |
| 242 | |
| 243 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
| 244 | [tableView deselectRowAtIndexPath:indexPath animated:YES]; |
| 245 | |
| 246 | if (indexPath.section == [self sectionForIndex:kKDomainTableViewSectionTitle]) { |
| 247 | NSString *ddsEditTitle = @"Display Title"; |
| 248 | NSString *ddsPrompt = @"More descriptive name for your domain"; |
| 249 | |
| 250 | HATextViewEditController *teC = [HATextViewEditController controllerWithDelegate:self |
| 251 | title:ddsEditTitle |
| 252 | prompt:ddsPrompt]; |
| 253 | teC.textContent = self.ddsTitle; |
| 254 | teC.maxCharSize = kDDSMaxLength; |
| 255 | teC.returnKeyType = UIReturnKeyDone; |
| 256 | [self.navigationController pushViewController:teC animated:YES]; |
| 257 | } else if (indexPath.section == [self sectionForIndex:kKDomainTableViewSectionFolders]) { |
| 258 | if (self.editing) { |
| 259 | // disallowed |
| 260 | return; |
| 261 | } |
| 262 | NSString *selectedSubDomain = [tableView cellForRowAtIndexPath:indexPath].textLabel.text; |
| 263 | NSString *fqdn = [NSString stringWithFormat:@"%@.%@", selectedSubDomain, self.domain]; |
| 264 | DomainViewController *newC = [DomainViewController controllerForDomain:fqdn]; |
| 265 | [self.navigationController pushViewController:newC animated:YES]; |
| 266 | } else if (indexPath.section == [self sectionForIndex:kKDomainTableViewSectionInfo]) { |
| 267 | switch (indexPath.row) { |
| 268 | case 0: //"Contacts"; |
| 269 | [self.navigationController pushViewController:self.recordVC animated:YES]; |
| 270 | break; |
| 271 | case 1: //"Keywords"; |
| 272 | [self.navigationController pushViewController:self.keywordVC animated:YES]; |
| 273 | break; |
| 274 | case 2: //"Location"; |
| 275 | [self.navigationController pushViewController:self.locationVC animated:YES]; |
| 276 | break; |
| 277 | case 3: //"Profiles"; |
| 278 | [self.navigationController pushViewController:self.profileVC animated:YES]; |
| 279 | break; |
| 280 | case 4: //"Privacy Groups"; |
| 281 | [self.navigationController pushViewController:self.groupVC animated:YES]; |
| 282 | break; |
| 283 | default: |
| 284 | break; |
| 285 | } |
| 286 | } else if (indexPath.section == [self sectionForIndex:kKDomainTableViewSectionAddFolder]) { |
| 287 | [tableView.dataSource tableView:tableView |
| 288 | commitEditingStyle:UITableViewCellEditingStyleInsert forRowAtIndexPath:indexPath]; |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | - (void)setEditing:(BOOL)editing animated:(BOOL)animated { |
| 293 | [super setEditing:editing animated:animated]; |
| 294 | UITableView *tv = self.tableView; |
| 295 | [tv beginUpdates]; |
| 296 | NSMutableIndexSet *sectionsToInsert = [[[NSMutableIndexSet alloc] init] autorelease]; |
| 297 | NSMutableIndexSet *sectionsToDelete = [[[NSMutableIndexSet alloc] init] autorelease]; |
| 298 | if (editing) { |
| 299 | [sectionsToDelete addIndex:0]; // kKDomainTableViewSectionTitle |
| 300 | [sectionsToDelete addIndex:1]; // kKDomainTableViewSectionInfo |
| 301 | [sectionsToInsert addIndex:0]; // kKDomainTableViewSectionAddFolder |
| 302 | } else { |
| 303 | [sectionsToDelete addIndex:0]; // kKDomainTableViewSectionAddFolder |
| 304 | [sectionsToInsert addIndex:0]; // kKDomainTableViewSectionTitle |
| 305 | [sectionsToInsert addIndex:1]; // kKDomainTableViewSectionInfo |
| 306 | } |
| 307 | [tv deleteSections:sectionsToDelete withRowAnimation:UITableViewRowAnimationFade]; |
| 308 | [tv insertSections:sectionsToInsert withRowAnimation:UITableViewRowAnimationFade]; |
| 309 | [tv endUpdates]; |
| 310 | } |
| 311 | |
| 312 | - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { |
| 313 | if (self.editing && (indexPath.section == [self sectionForIndex:kKDomainTableViewSectionFolders])) { |
| 314 | return UITableViewCellEditingStyleDelete; |
| 315 | } |
| 316 | return UITableViewCellEditingStyleNone; |
| 317 | } |
| 318 | |
| 319 | |
| 320 | - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { |
| 321 | if (indexPath.section == [self sectionForIndex:kKDomainTableViewSectionFolders]) { |
| 322 | return YES; |
| 323 | } |
| 324 | return NO; |
| 325 | } |
| 326 | |
| 327 | |
| 328 | - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { |
| 329 | // Edit the tableview (only the folders are supported for editing at this point) |
| 330 | |
| 331 | if (editingStyle == UITableViewCellEditingStyleDelete) { |
| 332 | // Delete the row from the data source |
| 333 | if (indexPath.section == [self sectionForIndex:kKDomainTableViewSectionFolders]) { |
| 334 | AlertRenameView *alert = [[AlertRenameView alloc] initWithTitle:@"Confirm Deletion" |
| 335 | message:@"All information contained in this folder will be permanently deleted!" |
| 336 | delegate:self |
| 337 | cancelButtonTitle:@"Cancel" |
| 338 | otherButtonTitles:@"Delete", nil]; |
| 339 | alert.alertId = [NSNumber numberWithInt:kKDomainTableViewAlertDelete]; |
| 340 | alert.refObject = indexPath; |
| 341 | ((UITextField *)alert.uiStringField).hidden = YES; |
| 342 | [alert show]; |
| 343 | [alert release]; |
| 344 | } |
| 345 | } else if (editingStyle == UITableViewCellEditingStyleInsert) { |
| 346 | if (indexPath.section == [self sectionForIndex:kKDomainTableViewSectionAddFolder]) { |
| 347 | AlertRenameView *alert = [[AlertRenameView alloc] initWithTitle:@"New Folder Name" |
| 348 | message:@"\n\n" |
| 349 | delegate:self |
| 350 | cancelButtonTitle:@"Cancel" |
| 351 | otherButtonTitles:@"OK", nil]; |
| 352 | alert.alertId = [NSNumber numberWithInt:kKDomainTableViewAlertAdd]; |
| 353 | alert.uiStringField.text = @""; |
| 354 | [alert show]; |
| 355 | [alert release]; |
| 356 | } |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | |
| 361 | /* |
| 362 | // Override to support rearranging the table view. |
| 363 | - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath { |
| 364 | } |
| 365 | */ |
| 366 | |
| 367 | |
| 368 | - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { |
| 369 | return NO; |
| 370 | } |
| 371 | |
| 372 | - (void)dealloc { |
| 373 | [subdomainsArray release]; |
| 374 | [super dealloc]; |
| 375 | } |
| 376 | |
| 377 | #pragma mark - |
| 378 | #pragma mark Data Methods |
| 379 | |
| 380 | - (void)updateFoldersSectionWithJson:(NSDictionary *)parsedJson { |
| 381 | #ifdef DEBUG |
| 382 | NSLog(@"%@", [parsedJson descriptionInStringsFileFormat]); |
| 383 | #endif |
| 384 | |
| 385 | [subdomainsArray removeAllObjects]; |
| 386 | if ([[parsedJson valueForKey:@"success"] integerValue] == 1) { |
| 387 | [subdomainsArray setArray:(NSArray *)[parsedJson valueForKey:@"folderList"]]; |
| 388 | } else { |
| 389 | [Subdomain throwJsonErrorAlert:parsedJson]; |
| 390 | } |
| 391 | NSIndexSet *iSet = [NSIndexSet indexSetWithIndex:[self sectionForIndex:kKDomainTableViewSectionFolders]]; |
| 392 | [self.tableView reloadSections:iSet withRowAnimation:UITableViewRowAnimationTop]; |
| 393 | |
| 394 | } |
| 395 | |
| 396 | - (void)updateDisplayStringWithJson:(NSDictionary *)parsedJson { |
| 397 | #ifdef DEBUG |
| 398 | NSLog(@"%@", [parsedJson descriptionInStringsFileFormat]); |
| 399 | #endif |
| 400 | if ([[parsedJson valueForKey:@"success"] integerValue] == 1) { |
| 401 | self.ddsTitle = [parsedJson valueForKey:@"displayString"]; |
| 402 | if (self.ddsTitle == (NSString *)[NSNull null]) self.ddsTitle = nil; |
| 403 | } else { |
| 404 | [Subdomain throwJsonErrorAlert:parsedJson]; |
| 405 | } |
| 406 | NSIndexSet *iSet = [NSIndexSet indexSetWithIndex:[self sectionForIndex:kKDomainTableViewSectionTitle]]; |
| 407 | [self.tableView reloadSections:iSet withRowAnimation:UITableViewRowAnimationFade]; |
| 408 | } |
| 409 | |
| 410 | - (void)getSubFolderList { |
| 411 | // input = { |
| 412 | // domainName: "tel", /** gets a list of all folders */ |
| 413 | // recursive: true |
| 414 | // }; |
| 415 | // |
| 416 | // successResult = { |
| 417 | // success: true, |
| 418 | // folderList: [{id: 12, name: "cartman.tel", soConnection: "Active"}, |
| 419 | // {id: 23, name: "stan.cartman.tel", soConnection: "Uninitialised"}, |
| 420 | // {id: 14, name: "henry.tel", soConnection: "Incomplete"}], |
| 421 | // actionMessages: ["request successful", |
| 422 | // |
| 423 | // |
| 424 | // "2nd message here", |
| 425 | // "3rd message here"] |
| 426 | // }; |
| 427 | Subdomain *conn = [[[Subdomain alloc] init] autorelease]; |
| 428 | [conn setTheDelegate:self]; |
| 429 | [conn setActionSel:@selector(updateFoldersSectionWithJson:)]; |
| 430 | [conn setConnectionUrl:[conn urlFromAction:@"getsubfolderlist"]]; |
| 431 | |
| 432 | NSMutableDictionary *requestData = [[NSMutableDictionary dictionaryWithCapacity:1] retain]; |
| 433 | [requestData setObject:self.title forKey:@"domainName"]; |
| 434 | [requestData setObject:@"false" forKey:@"recursive"]; |
| 435 | |
| 436 | [conn setPayload:requestData]; |
| 437 | [conn performLookup:TRUE]; |
| 438 | [requestData release]; |
| 439 | |
| 440 | } |
| 441 | |
| 442 | - (void)storeFolder:(NSString *)aFolderName { |
| 443 | // inputFolder = { |
| 444 | // domainName: "stan.cartman.tel" |
| 445 | // }; |
| 446 | // |
| 447 | // successResult = { |
| 448 | // success: true, |
| 449 | // domainId: 25, |
| 450 | // actionMessages: ["folder added", |
| 451 | // "2nd message here", |
| 452 | // "3rd message here"] |
| 453 | // }; |
| 454 | |
| 455 | if (!aFolderName) { |
| 456 | return; |
| 457 | } |
| 458 | [aFolderName retain]; |
| 459 | Subdomain *conn = [[[Subdomain alloc] init] autorelease]; |
| 460 | [conn setTheDelegate:self]; |
| 461 | [conn setActionSel:@selector(doNothing:)]; |
| 462 | [conn setConnectionUrl:[conn urlFromAction:@"storefolder"]]; |
| 463 | |
| 464 | NSMutableDictionary *requestData = [[NSMutableDictionary dictionaryWithCapacity:3] retain]; |
| 465 | [requestData setObject:aFolderName forKey:@"domainName"]; |
| 466 | |
| 467 | [conn setPayload:requestData]; |
| 468 | NSDictionary *parsedJson = [conn performLookup:FALSE]; |
| 469 | [requestData release]; |
| 470 | if ([[parsedJson valueForKey:@"success"] integerValue] == 0) { |
| 471 | [Subdomain throwJsonErrorAlert:parsedJson]; |
| 472 | } else { |
| 473 | NSDictionary *newSub = [NSDictionary dictionaryWithObjectsAndKeys:[parsedJson valueForKey:@"domainId"], @"id", |
| 474 | aFolderName, @"name", |
| 475 | @"Uninitialised", @"soConnection", |
| 476 | nil]; |
| 477 | [self.subdomainsArray addObject:newSub]; |
| 478 | } |
| 479 | [aFolderName release]; |
| 480 | return; |
| 481 | } |
| 482 | |
| 483 | - (void)renameFolder:(NSDictionary *)aSub withString:(NSString *)newFolderName { |
| 484 | // inputFolder = { |
| 485 | // domainName: "stan.cartman.tel" |
| 486 | // newDomainName: "john.cartman.tel" |
| 487 | // }; |
| 488 | // |
| 489 | // successResult = { |
| 490 | // success: true, |
| 491 | // actionMessages: ["folder renamed", |
| 492 | // "2nd message here", |
| 493 | // "3rd message here"] |
| 494 | // }; |
| 495 | |
| 496 | if ((!aSub) || (!newFolderName)) { |
| 497 | return; |
| 498 | } |
| 499 | [newFolderName retain]; |
| 500 | Subdomain *conn = [[[Subdomain alloc] init] autorelease]; |
| 501 | [conn setTheDelegate:self]; |
| 502 | [conn setActionSel:@selector(doNothing:)]; |
| 503 | [conn setConnectionUrl:[conn urlFromAction:@"renamefolder"]]; |
| 504 | |
| 505 | NSMutableDictionary *requestData = [[NSMutableDictionary dictionaryWithCapacity:3] retain]; |
| 506 | [requestData setObject:[aSub objectForKey:@"name"] forKey:@"domainName"]; |
| 507 | [requestData setObject:newFolderName forKey:@"newDomainName"]; |
| 508 | |
| 509 | [conn setPayload:requestData]; |
| 510 | NSDictionary *parsedJson = [conn performLookup:FALSE]; |
| 511 | [requestData release]; |
| 512 | if ([[parsedJson valueForKey:@"success"] integerValue] == 0) { |
| 513 | [Subdomain throwJsonErrorAlert:parsedJson]; |
| 514 | } else { |
| 515 | NSMutableDictionary *newSub = [NSMutableDictionary dictionaryWithDictionary:aSub]; |
| 516 | [newSub setObject:newFolderName forKey:@"domainName"]; |
| 517 | [self.subdomainsArray replaceObjectAtIndex:[self.subdomainsArray indexOfObject:aSub] withObject:newSub]; |
| 518 | } |
| 519 | [newFolderName release]; |
| 520 | return; |
| 521 | } |
| 522 | |
| 523 | - (void)deleteFolder:(NSDictionary *)aSub atIndex:(NSIndexPath *)indexPath{ |
| 524 | // inputFolder = { |
| 525 | // domainName: "test.cartman.tel" |
| 526 | // }; |
| 527 | // |
| 528 | // successResult = { |
| 529 | // success: true, |
| 530 | // actionMessages: ["folder deleted" |
| 531 | // "2nd message here", |
| 532 | // "3rd message here"] |
| 533 | // }; |
| 534 | |
| 535 | if (!aSub) { |
| 536 | return; |
| 537 | } |
| 538 | [aSub retain]; |
| 539 | Subdomain *conn = [[[Subdomain alloc] init] autorelease]; |
| 540 | [conn setTheDelegate:[MyTelConnect sharedInstance]]; |
| 541 | [conn setActionSel:@selector(doNothing:)]; |
| 542 | [conn setConnectionUrl:[conn urlFromAction:@"deletefolder"]]; |
| 543 | |
| 544 | NSMutableDictionary *requestData = [[NSMutableDictionary dictionaryWithCapacity:1] retain]; |
| 545 | [requestData setObject:[aSub objectForKey:@"name"] forKey:@"domainName"]; |
| 546 | |
| 547 | [conn setPayload:requestData]; |
| 548 | NSDictionary *parsedJson = [conn performLookup:FALSE]; |
| 549 | [requestData release]; |
| 550 | if ([[parsedJson valueForKey:@"success"] integerValue] == 0) { |
| 551 | [Subdomain throwJsonErrorAlert:parsedJson]; |
| 552 | } else { |
| 553 | [self.subdomainsArray removeObjectAtIndex:indexPath.row]; |
| 554 | [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; |
| 555 | } |
| 556 | [aSub release]; |
| 557 | } |
| 558 | |
| 559 | - (void)getDisplayString { |
| 560 | // inputFolder = { |
| 561 | // domainName: "stan.cartman.tel" |
| 562 | // }; |
| 563 | // |
| 564 | // successResult = { |
| 565 | // success: true, |
| 566 | // displayString: "Stan's domain", |
| 567 | // actionMessages: ["domain display string retrieved", |
| 568 | // "2nd message here", |
| 569 | // "3rd message here"] |
| 570 | // }; |
| 571 | // |
| 572 | Subdomain *conn = [[[Subdomain alloc] init] autorelease]; |
| 573 | [conn setTheDelegate:self]; |
| 574 | [conn setActionSel:@selector(updateDisplayStringWithJson:)]; |
| 575 | [conn setConnectionUrl:[conn urlFromAction:@"getdisplaystring"]]; |
| 576 | |
| 577 | NSMutableDictionary *requestData = [[NSMutableDictionary dictionaryWithCapacity:1] retain]; |
| 578 | [requestData setObject:self.domain forKey:@"domainName"]; |
| 579 | |
| 580 | [conn setPayload:requestData]; |
| 581 | [conn performLookup:TRUE]; |
| 582 | [requestData release]; |
| 583 | } |
| 584 | |
| 585 | |
| 586 | - (void)setDisplayString:(NSString *)aDisplayString { |
| 587 | // inputFolder = { |
| 588 | // domainName: "stan.cartman.tel", |
| 589 | // displayString: "Stan Cartman: My domain" |
| 590 | // }; |
| 591 | // |
| 592 | // successResult = { |
| 593 | // success: true, |
| 594 | // actionMessages: ["domain display string set", |
| 595 | // "2nd message here", |
| 596 | // "3rd message here"] |
| 597 | // }; |
| 598 | |
| 599 | Subdomain *conn = [[[Subdomain alloc] init] autorelease]; |
| 600 | [conn setTheDelegate:self]; |
| 601 | [conn setActionSel:@selector(getDisplayString)]; |
| 602 | [conn setConnectionUrl:[conn urlFromAction:@"setdisplaystring"]]; |
| 603 | |
| 604 | NSMutableDictionary *requestData = [[NSMutableDictionary dictionaryWithCapacity:2] retain]; |
| 605 | [requestData setObject:self.domain forKey:@"domainName"]; |
| 606 | [requestData setObject:aDisplayString forKey:@"displayString"]; |
| 607 | |
| 608 | [conn setPayload:requestData]; |
| 609 | [conn performLookup:TRUE]; |
| 610 | [requestData release]; |
| 611 | } |
| 612 | |
| 613 | #pragma mark - |
| 614 | #pragma mark HATextViewEditDelegate Methods |
| 615 | |
| 616 | - (void)didChangeContentOfTextView:(UITextView *)textView { |
| 617 | self.ddsTitle = textView.text; |
| 618 | [self setDisplayString:self.ddsTitle]; |
| 619 | } |
| 620 | |
| 621 | - (void)didDismissTextView:(UITextView *)textView { |
| 622 | } |
| 623 | |
| 624 | #pragma mark - |
| 625 | #pragma mark TelControllerDelegate Methods |
| 626 | |
| 627 | - (void)dataDidChangeInController:(UIViewController *)controller { |
| 628 | UITableViewCell *theCell = nil; |
| 629 | if ([controller isMemberOfClass:[RecordViewController class]]) { |
| 630 | NSIndexPath *thePath = [NSIndexPath indexPathForRow:0 inSection:[self sectionForIndex:kKDomainTableViewSectionInfo]]; |
| 631 | theCell = [self.tableView cellForRowAtIndexPath:thePath]; |
| 632 | theCell.detailTextLabel.text = [NSString stringWithFormat:@"(%d)", [((RecordViewController *)controller).recordsArray count]]; |
| 633 | } else if ([controller isMemberOfClass:[KeywordViewController class]]) { |
| 634 | NSIndexPath *thePath = [NSIndexPath indexPathForRow:1 inSection:[self sectionForIndex:kKDomainTableViewSectionInfo]]; |
| 635 | theCell = [self.tableView cellForRowAtIndexPath:thePath]; |
| 636 | theCell.detailTextLabel.text = [NSString stringWithFormat:@"(%d)", [((KeywordViewController *)controller).keywordsArray count]]; |
| 637 | } else if ([controller isMemberOfClass:[LocationViewController class]]) { |
| 638 | // TODO: get reverse geoloc |
| 639 | NSIndexPath *thePath = [NSIndexPath indexPathForRow:2 inSection:[self sectionForIndex:kKDomainTableViewSectionInfo]]; |
| 640 | theCell = [self.tableView cellForRowAtIndexPath:thePath]; |
| 641 | if (((LocationViewController *)controller).markerTel) { |
| 642 | theCell.detailTextLabel.text = @"â"; |
| 643 | theCell.detailTextLabel.textColor = [UIColor greenColor]; |
| 644 | } else { |
| 645 | theCell.detailTextLabel.text = @"â"; |
| 646 | theCell.detailTextLabel.textColor = [UIColor redColor]; |
| 647 | } |
| 648 | } else if ([controller isMemberOfClass:[ProfileViewController class]]) { |
| 649 | NSIndexPath *thePath = [NSIndexPath indexPathForRow:3 inSection:[self sectionForIndex:kKDomainTableViewSectionInfo]]; |
| 650 | theCell = [self.tableView cellForRowAtIndexPath:thePath]; |
| 651 | theCell.detailTextLabel.text = [NSString stringWithFormat:@"(%d)", [((ProfileViewController *)controller).profilesArray count]]; |
| 652 | } else if ([controller isMemberOfClass:[GroupsViewController class]]) { |
| 653 | NSIndexPath *thePath = [NSIndexPath indexPathForRow:4 inSection:[self sectionForIndex:kKDomainTableViewSectionInfo]]; |
| 654 | theCell = [self.tableView cellForRowAtIndexPath:thePath]; |
| 655 | theCell.detailTextLabel.text = [NSString stringWithFormat:@"(%d)", [((GroupsViewController *)controller).groupsArray count]]; |
| 656 | } |
| 657 | if (theCell != nil) { |
| 658 | [theCell setNeedsLayout]; |
| 659 | [theCell setNeedsDisplay]; |
| 660 | } |
| 661 | } |
| 662 | |
| 663 | #pragma mark - |
| 664 | #pragma mark AlertRenameView delegate methods |
| 665 | |
| 666 | - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { |
| 667 | AlertRenameView *aV = (AlertRenameView *)alertView; |
| 668 | switch ([aV.alertId integerValue]) { |
| 669 | case kKDomainTableViewAlertAdd: |
| 670 | if (buttonIndex == aV.cancelButtonIndex) { |
| 671 | // Cancel |
| 672 | } else if ([aV.uiStringField.text length] == 0) { |
| 673 | // Cancel |
| 674 | } else { |
| 675 | NSString *newFolder = [aV.uiStringField.text stringByAppendingFormat:@".%@", self.title]; |
| 676 | [self storeFolder:[newFolder lowercaseString]]; |
| 677 | [self.tableView reloadData]; |
| 678 | } |
| 679 | break; |
| 680 | |
| 681 | case kKDomainTableViewAlertDelete: |
| 682 | if (buttonIndex == aV.cancelButtonIndex) { |
| 683 | // Cancel |
| 684 | } else { |
| 685 | if (aV.refObject) { |
| 686 | NSIndexPath *indexPath = (NSIndexPath *)aV.refObject; |
| 687 | NSDictionary *aSub = [self.subdomainsArray objectAtIndex:indexPath.row]; |
| 688 | [self deleteFolder:aSub atIndex:indexPath]; |
| 689 | } |
| 690 | } |
| 691 | break; |
| 692 | |
| 693 | default: |
| 694 | break; |
| 695 | } |
| 696 | return; |
| 697 | } |
| 698 | |
| 699 | @end |
| 700 |
Note: See TracBrowser
for help on using the browser.








