]> err.no Git - scalable-opengroupware.org/blobdiff - SOGo/UI/MailerUI/UIxMailView.m
implemented trashing
[scalable-opengroupware.org] / SOGo / UI / MailerUI / UIxMailView.m
index ffe89b1101fde8bbeefeddf2116c3320dbcd9ea0..59b40bfe3ed93280efa6544b24150b26b34342cc 100644 (file)
   return s;
 }
 
+/* expunge / delete setup and permissions */
+
+- (BOOL)showMarkDeletedButton {
+  if (![[self clientObject] isDeletionAllowed])
+    return NO;
+  
+  return NO; // TODO: make configurable in profile
+}
+
+- (BOOL)showTrashButton {
+  if (![[self clientObject] isDeletionAllowed])
+    return NO;
+  // TODO: should also check for Trash write access (or add -isTrashingAllowed)
+  
+  return YES; // TODO: make configurable in profile
+}
+
 /* links (DUP to UIxMailPartViewer!) */
 
 - (NSString *)linkToEnvelopeAddress:(NGImap4EnvelopeAddress *)_address {
 
 - (id)deleteAction {
   NSException *ex;
-
+  
   if (![self isDeletableClientObject]) {
     return [NSException exceptionWithHTTPStatus:400 /* Bad Request */
                         reason:@"method cannot be invoked on "
   }
   
   if ((ex = [[self clientObject] delete]) != nil) {
-    // TODO: improve error handling
     id url;
     
-    [self debugWithFormat:@"failed to delete: %@", ex];
-    
     url = [[ex reason] stringByEscapingURL];
     url = [@"view?error=" stringByAppendingString:url];
     return [self redirectToLocation:url];
   return [self redirectToParentFolder];
 }
 
+- (id)trashAction {
+  NSException *ex;
+  
+  if ([self isInvokedBySafeMethod]) {
+    // TODO: fix UI to use POST for unsafe actions
+    [self logWithFormat:@"WARNING: method is invoked using safe HTTP method!"];
+  }
+  
+  if ((ex = [[self clientObject] trashInContext:[self context]]) != nil) {
+    id url;
+    
+    url = [[ex reason] stringByEscapingURL];
+    url = [@"view?error=" stringByAppendingString:url];
+    return [self redirectToLocation:url];
+  }
+  
+  if (![self isInlineViewer]) {
+    // if everything is ok, close the window (send a JS closing the Window)
+    id page;
+    
+    page = [self pageWithName:@"UIxMailWindowCloser"];
+    [page takeValue:@"YES" forKey:@"refreshOpener"];
+    return page;
+  }
+  
+  return [self redirectToParentFolder];
+}
+
 - (id)getMailAction {
   // TODO: we might want to flush the caches?
   return [self redirectToLocation:@"view"];