From b97bf2b25fbc8614ac73cb95470da9b6fac61a76 Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Fri, 5 Sep 2014 22:34:25 -0400 Subject: [PATCH] JSON'ed [UIxParentFolderActions createFolder] --- UI/Common/UIxParentFolderActions.m | 40 +++++++++++++++++++----------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/UI/Common/UIxParentFolderActions.m b/UI/Common/UIxParentFolderActions.m index 3021687d2..24c0e26af 100644 --- a/UI/Common/UIxParentFolderActions.m +++ b/UI/Common/UIxParentFolderActions.m @@ -1,8 +1,6 @@ /* UIxParentFolderActions.m - this file is part of SOGo * - * Copyright (C) 2007 Inverse inc. - * - * Author: Wolfgang Sourdeau + * Copyright (C) 2007-2014 Inverse inc. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -27,9 +25,13 @@ #import #import -#import #import +#import +#import + +#import + #import "UIxParentFolderActions.h" @implementation UIxParentFolderActions @@ -38,8 +40,13 @@ { WOResponse *response; NSString *name, *nameInContainer; + NSDictionary *params, *data; + WORequest *request; - name = [[context request] formValueForKey: @"name"]; + request = [context request]; + params = [[request contentAsString] objectFromJSONString]; + + name = [params objectForKey: @"name"]; nameInContainer = nil; if ([name length] > 0) @@ -50,19 +57,24 @@ nameInContainer: &nameInContainer]; if (!response) { - response = [self responseWithStatus: 201]; - [response setHeader: @"text/plain; charset=us-ascii" - forKey: @"content-type"]; - [response appendContentString: nameInContainer]; - } + data = [NSDictionary dictionaryWithObjectsAndKeys: nameInContainer, @"id", nil]; + response = [self responseWithStatus: 201 + andString: [data jsonRepresentation]]; + } } else - response = [NSException exceptionWithHTTPStatus: 409 - reason: @"That name already exists"]; + { + data = [NSDictionary dictionaryWithObjectsAndKeys: @"That name already exists", @"error", nil]; + response = [self responseWithStatus: 409 + andString: [data jsonRepresentation]]; + } } else - response = [NSException exceptionWithHTTPStatus: 400 - reason: @"The name is missing"]; + { + data = [NSDictionary dictionaryWithObjectsAndKeys: @"The name is missing", @"error", nil]; + response = [self responseWithStatus: 400 + andString: [data jsonRepresentation]]; + } return response; }