diff --git a/openbis-ipad/Research/BisMac.xcodeproj/project.xcworkspace/xcuserdata/cramakri.xcuserdatad/UserInterfaceState.xcuserstate b/openbis-ipad/Research/BisMac.xcodeproj/project.xcworkspace/xcuserdata/cramakri.xcuserdatad/UserInterfaceState.xcuserstate index 7a3bda6222d85296cdf753a04be35e1a629d71ee..b549e23db89b6885c527fda5192ac62d0fcd435f 100644 Binary files a/openbis-ipad/Research/BisMac.xcodeproj/project.xcworkspace/xcuserdata/cramakri.xcuserdatad/UserInterfaceState.xcuserstate and b/openbis-ipad/Research/BisMac.xcodeproj/project.xcworkspace/xcuserdata/cramakri.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/openbis-ipad/openBIS/openBIS.xcodeproj/project.xcworkspace/xcuserdata/cramakri.xcuserdatad/UserInterfaceState.xcuserstate b/openbis-ipad/openBIS/openBIS.xcodeproj/project.xcworkspace/xcuserdata/cramakri.xcuserdatad/UserInterfaceState.xcuserstate index 99d8724ab18848a46d614032880a807db93933c2..6d6ace0d8cc8ffcbee221045c425e8d26b3b1adf 100644 Binary files a/openbis-ipad/openBIS/openBIS.xcodeproj/project.xcworkspace/xcuserdata/cramakri.xcuserdatad/UserInterfaceState.xcuserstate and b/openbis-ipad/openBIS/openBIS.xcodeproj/project.xcworkspace/xcuserdata/cramakri.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/openbis-ipad/openBIS/openBIS/CISDOBAppDelegate.m b/openbis-ipad/openBIS/openBIS/CISDOBAppDelegate.m index 79ff27a2c609b082b7b3cd2db3a5ad93e0a264d5..70bec49017e143d79bb2a28690a1a136889820ce 100644 --- a/openbis-ipad/openBIS/openBIS/CISDOBAppDelegate.m +++ b/openbis-ipad/openBIS/openBIS/CISDOBAppDelegate.m @@ -30,6 +30,7 @@ #import "CISDOBDetailViewController.h" #import "CISDOBLoginViewController.h" #import "CISDOBAuthenticationChallengeConfirmationDialog.h" +#import "CISDOBIpadEntity.h" @implementation CISDOBAppDelegate @@ -103,7 +104,7 @@ UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController; UINavigationController *navigationController = [splitViewController.viewControllers lastObject]; splitViewController.delegate = (id)navigationController.topViewController; - [self detailsViewController].appDelegate = self; + [self detailViewController].appDelegate = self; [self masterViewController].openBisModel = self.rootOpenBisModel; } else { @@ -125,7 +126,7 @@ return controller; } -- (CISDOBDetailViewController *)detailsViewController +- (CISDOBDetailViewController *)detailViewController { UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController; return (CISDOBDetailViewController *)[[splitViewController.viewControllers lastObject] topViewController]; @@ -141,7 +142,7 @@ [controller didConnectServiceManager: self.serviceManager]; }; call.fail = ^(NSError *error) { - [[self detailsViewController] performSegueWithIdentifier: @"ShowLoginDialog" sender: self]; + [[self detailViewController] performSegueWithIdentifier: @"ShowLoginDialog" sender: self]; }; [call start]; } @@ -244,10 +245,14 @@ if (!_serviceManager) return NO; } + // Use a weak reference to self in blocks to avoid retain cycles __weak CISDOBAppDelegate *weakSelf = self; _serviceManager.authenticationChallengeBlock = ^(CISDOBAsyncCall *call, NSURLAuthenticationChallenge *challenge) { [weakSelf presetDialogForCall: call challenge: challenge]; }; + _serviceManager.mocSaveBlock = ^(CISDOBIpadServiceManager *serviceManager, NSArray *deletedEntityPermIds) { + [weakSelf serviceManager: serviceManager willSaveDeletingEntities: deletedEntityPermIds]; + }; return YES; } @@ -285,6 +290,30 @@ _challengeDialog = nil; } +#pragma mark - MOC Save Handling +- (void)serviceManager:(CISDOBIpadServiceManager *)serviceManager willSaveDeletingEntities:(NSArray *)deletedEntityPermIds +{ + // Nothing to do if nothing was deleted + if ([deletedEntityPermIds count] < 1) return; + + // Check if any of the deleted entities are currently open, if so, return to the root view to avoid any problems caused by looking at zombie entities + BOOL returnToRoot = NO; + NSSet *permIdSet = [NSSet setWithArray: deletedEntityPermIds]; + CISDOBOpenBisModel *model; + for (model = [self detailViewController].openBisModel; model != nil; model = model.parentModel) { + if ([permIdSet containsObject: model.selectedObject.permId]) { + returnToRoot = YES; + break; + } + } + + if (returnToRoot) { + UINavigationController *navigationController = self.masterViewController.navigationController; + [navigationController popToRootViewControllerAnimated: YES]; + self.detailViewController.openBisModel = self.rootOpenBisModel; + [self.detailViewController selectionDidChange]; + } +} #pragma mark - Application's Documents directory diff --git a/openbis-ipad/openBIS/openBIS/CISDOBDetailViewController.m b/openbis-ipad/openBIS/openBIS/CISDOBDetailViewController.m index 128d6126db494fa5ab9b54e0452885771e1131fc..84077a677979c2468e8aca8f3df4ef44c5ca8904 100644 --- a/openbis-ipad/openBIS/openBIS/CISDOBDetailViewController.m +++ b/openbis-ipad/openBIS/openBIS/CISDOBDetailViewController.m @@ -46,6 +46,8 @@ #pragma mark - Managing the detail item - (void)requestServerSync { + if (!self.detailItem) return; + // Ask the server to synchronize the detail object and nofiy me when the complete data is available SuccessBlock success = ^(id result) { [self configureView]; [self requestImage]; }; [self.openBisModel syncSelectedObjectForDetailOnSuccess: success]; @@ -109,9 +111,16 @@ - (void)configureView { - // The detail item is now up-to-date. Update the user interface. - if (!self.detailItem) return; + if (!self.detailItem) { + self.title = @""; + self.summaryHeaderLabel.text = @""; + self.summaryLabel.text = @""; + self.identifierLabel.text = @""; + [self.propertiesTableView reloadData]; + return; + } + // The detail item is now up-to-date. Update the user interface. self.title = self.detailItem.summaryHeader; self.summaryHeaderLabel.text = self.detailItem.summaryHeader; self.summaryLabel.text = self.detailItem.summary; @@ -179,6 +188,11 @@ #pragma mark - Table View (Properties) - (NSDictionary *)propertiesAtIndexPath:(NSIndexPath *)indexPath { + if (!self.detailItem) { + return [NSDictionary dictionaryWithObjectsAndKeys: + @"label", @"", + @"value", @"", nil]; + } NSDictionary *properties = [self.detailItem.properties objectAtIndex: [indexPath indexAtPosition: 1]]; return properties; } diff --git a/openbis-ipad/openBIS/openBIS/CISDOBOpenBisModel.h b/openbis-ipad/openBIS/openBIS/CISDOBOpenBisModel.h index 78d0d66fcc24833d71e4ec2b2d053609c48c6d97..01d983d1b8eeb8a8880e876db3e3e3921eb3effd 100644 --- a/openbis-ipad/openBIS/openBIS/CISDOBOpenBisModel.h +++ b/openbis-ipad/openBIS/openBIS/CISDOBOpenBisModel.h @@ -39,6 +39,7 @@ @property (weak, nonatomic) CISDOBOpenBisModel *parentModel; @property (readonly) CISDOBIpadServiceManager *serviceManager; +@property (strong, nonatomic) CISDOBIpadEntity *selectedObject; // Initialize - (id)initWithParentModel:(CISDOBOpenBisModel *)parentModel; //!< The designated initializer @@ -50,8 +51,6 @@ - (CISDOBIpadEntity *)objectAtIndexPath:(NSIndexPath *)indexPath; // Selection -@property (strong, nonatomic) CISDOBIpadEntity *selectedObject; - //! Select the object and return it - (CISDOBIpadEntity *)selectObjectAtIndexPath:(NSIndexPath *)indexPath;