CreateGroupViewController.m
3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//
// CreateGroupViewController.m
// LifeLog
//
// Created by nvtu on 8/19/17.
// Copyright © 2017 PhongNV. All rights reserved.
//
#import "CreateGroupViewController.h"
#import "ServerAPI.h"
@interface CreateGroupViewController ()
@end
@implementation CreateGroupViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark IBAction
- (IBAction)clickBack:(UIButton *)sender {
[self.navigationController popViewControllerAnimated:true];
}
- (IBAction)clickCreateGroup:(AutoTransButton *)sender {
NSString *name = self.textName.text;
NSString *goal = self.textGoal.text;
if(name.length == 0) {
[Utilities showErrorMessage:@"Fill name of group!" withViewController:self];
return;
}
else if(name.length >= 255) {
[Utilities showErrorMessage:@"Name of group is too long!" withViewController:self];
return;
}
else if(goal.length == 0) {
[Utilities showErrorMessage:@"Fill information for goal of group" withViewController:self];
return;
}
if(self.switchWalk.on && [self.textGoalWalk.text intValue] == 0) {
[Utilities showErrorMessage:@"Add goal for walk mode" withViewController:self];
return;
}
if(self.switchBike.on && [self.textGoalBike.text intValue] == 0) {
[Utilities showErrorMessage:@"Add goal for bike mode" withViewController:self];
return;
}
if(self.switchRun.on && [self.textGoalRun.text intValue] == 0) {
[Utilities showErrorMessage:@"Add goal for run mode" withViewController:self];
return;
}
GroupObject *object = [[GroupObject alloc] init];
object.name = name;
object.goal = goal;
object.walkMode = self.switchWalk.on;
object.runMode = self.switchRun.on;
object.bikeMode = self.switchBike.on;
object.stepMode = self.switchStep.on;
object.gymMode = self.switchGym.on;
object.beginMode = self.switchBegin.on;
object.walkGoal = [self.textGoalWalk.text intValue];
object.bikeGoal = [self.textGoalBike.text intValue];
object.runGoal = [self.textGoalRun.text intValue];
NSLog(@"%@", object.name);
NSLog(@"%@", object.goal);
NSLog(@"%d", object.walkGoal);
NSLog(@"%d", object.bikeGoal);
NSLog(@"%d", object.runGoal);
NSLog(@"%d", object.walkMode);
NSLog(@"%d", object.runMode);
NSLog(@"%d", object.bikeMode);
NSLog(@"%d", object.stepMode);
NSLog(@"%d", object.gymMode);
NSLog(@"%d", object.beginMode);
NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken];
MBProgressHUD *hudView = [MBProgressHUD showHUDAddedTo:self.view animated:true];
[[ServerAPI server] requestCreateGroup:token withGroup:object CompletionHandler:^(GroupObject * group, NSError * error) {
CreateGroupViewController __weak *weakSelf = self;
if(error == nil) {
dispatch_async(dispatch_get_main_queue(), ^{
if(weakSelf.createGroupSuccess != nil) {
[hudView hideAnimated:true];
[weakSelf clickBack:nil];
weakSelf.createGroupSuccess(object);
}
});
}
else {
dispatch_async(dispatch_get_main_queue(), ^{
[hudView hideAnimated:true];
NSString *message = [error.userInfo objectForKey:@"message"];
[Utilities showErrorMessage:message withViewController:weakSelf];
});
}
}];
}
#pragma mark UITextView Delegate
-(BOOL) textFieldShouldReturn:(UITextField *)textField {
[self.view endEditing:true];
return true;
}
@end