-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathResetPasswordPanelController.j
63 lines (54 loc) · 1.96 KB
/
ResetPasswordPanelController.j
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
// (c) 2010-2011 by Anton Korenyushkin
@import "RequestPanelController.j"
@implementation ResetPasswordPanelController : RequestPanelController
{
@outlet CPTextField nameOrEmailField;
@outlet CPButton submitButton;
}
- (void)init // public
{
return [super initWithWindowCibName:"ResetPasswordPanel"];
}
- (void)awakeFromCib // private
{
[submitButton setEnabled:NO];
[submitButton setKeyEquivalent:CPCarriageReturnCharacter];
}
- (void)controlTextDidChange:(id)sender // private
{
[submitButton setEnabled:[nameOrEmailField stringValue]];
}
- (@action)submit:(id)sender // private
{
var value = [nameOrEmailField stringValue];
var data = {};
data[value.indexOf("@") == -1 ? "name" : "email"] = value;
[self requestWithMethod:"POST" URL:"/password" data:data];
}
- (void)didReceiveResponse:(JSObject)data // protected
{
[[self window] close];
var panel = [[CPPanel alloc] initWithContentRect:CGRectMake(0, 0, 318, 108) styleMask:CPTitledWindowMask];
var contentView = [panel contentView];
var imageView = [[CPImageView alloc] initWithFrame:CGRectMake(16, 16, 48, 48)];
[imageView setImage:[[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:"Info48.png"]]];
[contentView addSubview:imageView];
var label = [[CPTextField alloc] initWithFrame:CGRectMake(80, 16, 222, 48)];
[label setLineBreakMode:CPLineBreakByWordWrapping];
[label setFont:BoldSystemFont];
[label setStringValue:"An email containing confirmation URL has been sent."];
[contentView addSubview:label];
var button = [[CPButton alloc] initWithFrame:CGRectMake(234, 64, 64, 24)];
[button setTitle:"OK"];
[button setKeyEquivalent:CPCarriageReturnCharacter];
[button setTarget:self];
[button setAction:@selector(stopModal:)];
[contentView addSubview:button];
[CPApp runModalForWindow:panel];
}
- (void)stopModal:(CPButton)sender // private
{
[CPApp stopModal];
[[sender window] close];
}
@end