-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathISAccountView.j
121 lines (91 loc) · 4.5 KB
/
ISAccountView.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
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
117
118
119
120
121
/*
* AppController.j
* GithubIssues
*
* Created by Randy Luecke on April 14, 2011.
* Copyright 2011, RCLConcepts, LLC All rights reserved.
*/
/*!
The account view shows the login status of the user
*/
var octocatImage = nil;
@implementation ISAccountView : CPView
{
@outlet CPImageView avatarView;
@outlet CPTextField accountNameField;
@outlet CPTextField loggedInAsField;
@outlet CPButton loginButton;
@outlet CPPopUpButton detailsButton;
}
- (void)awakeFromCib
{
var buttonPattern = [CPColor colorWithPatternImage:resourcesImage("loginbutton.png", 58, 21)],
buttonPatternActive = [CPColor colorWithPatternImage:resourcesImage("loginbutton-active.png", 58, 21)];
octocatImage = resourcesImage("octocat32.png", 32, 32);
[loginButton setValue:buttonPattern forThemeAttribute:"bezel-color" inState:CPThemeStateNormal];
[loginButton setValue:buttonPatternActive forThemeAttribute:"bezel-color" inState:CPThemeStateHighlighted];
[loginButton setValue:[CPColor colorWithRed:218/255 green:225/255 blue:229/255 alpha:1.0] forThemeAttribute:@"text-color" inState:CPThemeStateNormal];
[loginButton setValue:[CPColor colorWithRed:0 green:0 blue:0 alpha:.35] forThemeAttribute:@"text-shadow-color" inState:CPThemeStateNormal];
[loginButton setValue:CGSizeMake(0,-1) forThemeAttribute:@"text-shadow-offset" inState:CPThemeStateNormal];
// FIX ME: it'd be nice to get NIB2Cib to do this for us...
[loginButton setFrameSize:CGSizeMake(58, 21)];
[loginButton setTitle:"Login"];
[accountNameField setValue:[CPColor colorWithRed:1 green:1 blue:1 alpha:.3] forThemeAttribute:@"text-shadow-color" inState:CPThemeStateNormal];
[accountNameField setValue:CGSizeMake(0,1) forThemeAttribute:@"text-shadow-offset" inState:CPThemeStateNormal];
// In order to add a proper shadow we need to make the frame 1px taller
var size = [accountNameField frameSize];
size.height += 1;
[accountNameField setFrameSize:size];
[loggedInAsField setValue:[CPColor colorWithRed:1 green:1 blue:1 alpha:.3] forThemeAttribute:@"text-shadow-color" inState:CPThemeStateNormal];
[loggedInAsField setValue:CGSizeMake(0,1) forThemeAttribute:@"text-shadow-offset" inState:CPThemeStateNormal];
var size = [loggedInAsField frameSize];
size.height += 2;
[loggedInAsField setFrameSize:size];
[avatarView setBackgroundColor:[CPColor colorWithPatternImage:resourcesImage("userViewImageBackground-large.png", 44, 44)]];
[[CPNotificationCenter defaultCenter] addObserver:self
selector:@selector(loginStatusDidChange:)
name:CPUserSessionManagerStatusDidChangeNotification
object:nil];
[detailsButton setFrameSize:CGSizeMake(10,10)];
[detailsButton setValue:[CPColor colorWithPatternImage:resourcesImage("FIXME_arrowdown.png", 10, 10)] forThemeAttribute:"bezel-color"];
[self loginStatusDidChange:nil];
}
- (@action)addOwnRepos:(id)sender
{
var controller = [ISGithubAPIController sharedController];
[controller loadAllReposForUser:[controller username] callback:function(aRepo, aRequest){
[[[CPApp delegate] reposController] addRepository:aRepo select:NO];
}];
}
- (@action)toggleLogin:(id)sender
{
[[ISGithubAPIController sharedController] toggleAuthentication:sender];
}
- (void)loginStatusDidChange:(CPNotification)aNote
{
var githubController = [ISGithubAPIController sharedController],
isLoggedIn = [githubController isAuthenticated];
if (isLoggedIn)
{
[loggedInAsField setStringValue:"Logged in as"];
[accountNameField setStringValue:[githubController username]];
[accountNameField sizeToFit];
[avatarView setImage:[githubController userThumbnailImage]];
[loginButton setTitle:"Logout"];
var frame = [accountNameField frame];
[detailsButton setFrameOrigin:CGPointMake(CGRectGetMaxX(frame) + 2, CGRectGetMinY(frame) + 2)];
[detailsButton setHidden:NO];
var defaults = [CPUserDefaults standardUserDefaults];
[defaults setObject:[githubController username] forKey:"username"];
[defaults setObject:[githubController password] forKey:"password"];
}
else
{
[detailsButton setHidden:YES];
[loggedInAsField setStringValue:"Not logged in"];
[accountNameField setStringValue:""];
[avatarView setImage:octocatImage];
[loginButton setTitle:"Login"];
}
}
@end