-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSignupPanelController.j
More file actions
83 lines (72 loc) · 2.5 KB
/
SignupPanelController.j
File metadata and controls
83 lines (72 loc) · 2.5 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
// (c) 2010-2011 by Anton Korenyushkin
@import "RequestPanelController.j"
@implementation SignupPanelController : RequestPanelController
{
id target @accessors;
SEL action @accessors;
@outlet CPTextField nameLabel;
@outlet CPTextField nameField;
@outlet CPTextField emailLabel;
@outlet CPTextField emailField;
@outlet CPTextField passwordLabel;
@outlet CPTextField passwordField;
@outlet CPTextField confirmLabel;
@outlet CPTextField confirmField;
@outlet CPButton signupButton;
}
- (id)init // public
{
return [super initWithWindowCibName:"SignupPanel"];
}
- (void)awakeFromCib // private
{
[nameLabel, emailLabel, passwordLabel, confirmLabel].forEach(
function (label) { [label setAlignment:CPRightTextAlignment]; });
[passwordField setSecure:YES];
[confirmField setSecure:YES];
[signupButton setEnabled:NO];
[signupButton setKeyEquivalent:CPCarriageReturnCharacter];
}
- (void)controlTextDidChange:(id)sender // private
{
[signupButton setEnabled:([nameField stringValue] &&
[emailField stringValue] &&
[passwordField stringValue] &&
[confirmField stringValue])];
}
- (@action)submit:(id)sender // private
{
var password = [passwordField stringValue];
if ([confirmField stringValue] == password) {
var data = {name: [nameField stringValue], email: [emailField stringValue], password: password};
[self requestWithMethod:"POST" URL:"/signup" data:data context:data];
} else {
[[[Alert alloc] initWithMessage:"The passwords don't match."
comment:"Please retype the password twice."
target:self
action:@selector(didEndMatchErrorSheet)]
showSheetForWindow:[self window]];
}
}
- (void)didEndMatchErrorSheet // private
{
[passwordField setStringValue:""];
[confirmField setStringValue:""];
[signupButton setEnabled:NO];
[[self window] makeFirstResponder:passwordField];
}
- (void)didEndRequestErrorSheet:(Alert)sender // protected
{
[[self window] makeFirstResponder:[sender message].indexOf("email") == -1 ? nameField : emailField];
}
- (void)didReceiveResponse:(JSObject)data withContext:context // protected
{
objj_msgSend(target, action);
[DATA setUsername:context.name];
[DATA setEmail:context.email];
}
- (void)windowWillClose:(id)sender // private
{
target = action = nil;
}
@end