Created
March 11, 2011 03:37
-
-
Save jamesbrink/865411 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* AppController.j | |
* Cloud-MD | |
* | |
* Created by You on March 8, 2011. | |
* Copyright 2011, Your Company All rights reserved. | |
*/ | |
@import <Foundation/CPObject.j> | |
@implementation AppController : CPObject | |
{ | |
CPWindow theWindow; //this "outlet" is connected automatically by the Cib | |
CPTextField LoginUserName; | |
CPSecureTextField LoginPassword; | |
CPTextField LoginError; | |
} | |
- (void)applicationDidFinishLaunching:(CPNotification)aNotification | |
{ | |
// This is called when the application is done loading. | |
} | |
- (void)awakeFromCib | |
{ | |
// This is called when the cib is done loading. | |
// You can implement this method on any object instantiated from a Cib. | |
// It's a useful hook for setting up current UI values, and other things. | |
// In this case, we want the window from Cib to become our full browser window | |
[theWindow setFullBridge:YES]; | |
} | |
- (void)doLogin:(id)sender | |
{ | |
var UserSession = { | |
"user_session" : { | |
"login" : [LoginUserName objectValue], | |
"password" : [LoginPassword objectValue], | |
"remember_me" : false | |
} | |
}; | |
var request = [[CPURLRequest alloc] initWithURL:[CPURL URLWithString: @"/user_sessions"]]; | |
[request setHTTPMethod:@"POST"]; | |
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; | |
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"]; | |
[request setHTTPBody:[CPString JSONFromObject:UserSession]]; | |
response = [CPURLConnection connectionWithRequest:request delegate:self]; | |
} | |
- (void)connection:(CPURLConnection) connection didReceiveData:(CPString)data | |
{ | |
result = CPJSObjectCreateWithJSON(data); | |
alert(result.success); | |
} | |
- (void)connection:(CPURLConnection)connection didFailWithError:(CPString)error | |
{ | |
alert("Error"); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment