Redisplay of modal causes modal to not respond to input

12 views
Skip to first unread message

scott

unread,
Oct 24, 2009, 4:46:02 PM10/24/09
to Cappuccino & Objective-J Development List
I am creating a Login Modal Dialog. I used the CPAlert as a
template. I need to check the username and password and if it is not
correct I need to redisplay the Login modal with a message stating
that the username and/or password is incorrect.

When I redisplay the modal it appears with the message but it no
longer accepts user input.

I deployed the application at http://oringecompany.com/desktop/index.html

Here is the code:

/*
* AppController.j
* Oringe Application
*
* Created by Scott Lewis on October 24, 2009.
* Copyright 2009, Oringe Company All rights reserved.
*/

@import <Foundation/CPObject.j>
@import "OCLoginDialog.j"


@implementation AppController : CPObject
{
var theWindow;
}

- (void)applicationDidFinishLaunching:(CPNotification)aNotification
{
theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero()
styleMask:CPBorderlessBridgeWindowMask], contentView = [theWindow
contentView];
[theWindow setDelegate:self];

[contentView setBackgroundColor:[CPColor darkGrayColor]];

var loginDialog = [[OCLoginDialog alloc]
initWithLogoImageFileName:@"Resources/oringe_hard_hat_logo.png"];
[loginDialog setDelegate:self];
[loginDialog setErrorMessageDisplayed:NO];
[loginDialog runModal];

[theWindow orderFront:self];

// Uncomment the following line to turn on the standard menu bar.
//[CPMenu setMenuBarVisible:YES];
}


-(void)windowDidResize:(CPNotification)notification
{
[loginDialog center];
}


- (void)login:(id)sender
{
//Testing
}

-(void)loginDidEnd:(OCLoginDialog)theDialog
{
var loginDialog1 = [[OCLoginDialog alloc]
initWithLogoImageFileName:@"Resources/oringe_hard_hat_logo.png"];
[loginDialog1 setErrorMessageDisplayed:YES];
[loginDialog1 runModal];

}

@end



/*
* OCLoginDialog.j
*
*
* Created by Scott Lewis.
* Copyright 2009, Oringe Company.
*
*/

@import <Foundation/CPObject.j>
@import <Foundation/CPString.j>

@import <AppKit/CPApplication.j>
@import <AppKit/CPButton.j>
@import <AppKit/CPColor.j>
@import <AppKit/CPFont.j>
@import <AppKit/CPImage.j>
@import <AppKit/CPImageView.j>
@import <AppKit/CPPanel.j>
@import <AppKit/CPTextField.j>


/*!
@ingroup ockit

OCLoginDialog is an login dialog that can be displayed modally to
present the
user with a username and password.

The dialog is displayed modally by calling \c -runModal and once
the user has
dismissed the dialog, a message will be sent to the login dialog's
delegate (if set), informing
it that the login button was clicked (see delegate methods).

@delegate -(void)loginDidEnd:(OCLoginDialog)theDialog returnCode:
(int)returnCode;
Called when the user dismisses the dialog by clicking the button.
@param theDialog the login dialog that the user dismissed
*/
@implementation OCLoginDialog : CPObject
{
CPPanel _loginPanel;
CPTextField _usernameTextField;
CPTextField _passwordTextField;
CPTextField _forgotCredsLabel;
CPTextField _invalidCredsMessageLabel;
CPImageView _logoImageView;
CPString _windowTitle;
CPString _buttonTitle;
CPString _imageFileName;
CPButton _button;
BOOL _errorMessageDisplayed;
id _delegate;
}

+ (void)initialize
{
if (self != OCLoginDialog)
return;

//var bundle = [CPBundle bundleForClass:[self class]];

}

/*!
Initializes a \c OCLoginDialog with the default title and logo
image.
*/
- (id)initWithLogoImageFileName:(CPString)theFileName
{
self = [super init];

if (self)
{

_loginPanel = [[CPPanel alloc] initWithContentRect:CGRectMake
(0.0, 0.0, 400.0, 155.0) styleMask:CPHUDBackgroundWindowMask];
//_loginPanel = [[CPPanel alloc] initWithContentRect:CGRectMake
(0.0, 0.0, 400.0, 155.0) styleMask:CPBorderlessWindowMask];
[_loginPanel setFloatingPanel:YES];
[_loginPanel center];

var logoImage = [[CPImage alloc]
initWithContentsOfFile:theFileName];
_logoImageView = [[CPImageView alloc] initWithFrame:CGRectMake
(20.0, 30.0, 117, 100)];
[_logoImageView setImage:logoImage];
[[_loginPanel contentView] addSubview:_logoImageView];

_usernameTextField = [[CPTextField alloc]
initWithFrame:CGRectMake(157.0, 25.0, 220.0, 80.0)];
[_usernameTextField setAlignment:CPJustifiedTextAlignment];
[_usernameTextField setEditable:YES];
[_usernameTextField setBezeled:YES];
//[_usernameTextField setBezelStyle:CPTextFieldRoundedBezel];
[_usernameTextField setTextFieldBackgroundColor:[CPColor
whiteColor]];
[_usernameTextField setPlaceholderString:@"User Name"];
[_usernameTextField setTextColor:[CPColor grayColor]];
[_usernameTextField setFont:[CPFont boldSystemFontOfSize:16.0]];
[_usernameTextField sizeToFit];
[_usernameTextField setAutoresizingMask:CPViewMinXMargin |
CPViewMaxXMargin | CPViewMinYMargin | CPViewMaxYMargin];
[[_loginPanel contentView] addSubview:_usernameTextField];


_passwordTextField = [[CPTextField alloc] initWithFrame:CGRectMake
(157.0, 62.0, 220.0, 80.0)];
[_passwordTextField setEditable:YES];
[_passwordTextField setBezeled:YES];
[_passwordTextField setSecure:YES];
//[passwordTextField setBezelStyle:CPTextFieldRoundedBezel];
[_passwordTextField setTextFieldBackgroundColor:[CPColor
whiteColor]];
[_passwordTextField setPlaceholderString:@"Password"];
[_passwordTextField setTextColor:[CPColor grayColor]];
[_passwordTextField setFont:[CPFont boldSystemFontOfSize:16.0]];
[_passwordTextField sizeToFit];
[_passwordTextField setAutoresizingMask:CPViewMinXMargin |
CPViewMaxXMargin | CPViewMinYMargin | CPViewMaxYMargin];
[[_loginPanel contentView] addSubview:_passwordTextField];

_button = [[CPButton alloc] initWithFrame:CGRectMake(295.0, 105.0,
80.0, 24.0)];
[_button setTarget:self];
[_button setTag:0];
[_button setAction:@selector(_notifyDelegate:)];
[_button setFrameSize:CGSizeMake([_button frame].size.width,
24.0)];
[_button setBezelStyle:CPHUDBezelStyle];
//[_button setBezelStyle:CPRoundRectBezelStyle];
[[_loginPanel contentView] addSubview:_button];

_forgotCredsLabel = [[CPTextField alloc] initWithFrame:CGRectMake
(157.0, 110.0, 120.0, 20.0)];
[_forgotCredsLabel setEditable:NO];
[_forgotCredsLabel setBezeled:NO];
[_forgotCredsLabel setSecure:NO];
[_forgotCredsLabel setStringValue:@"Forgot Password"];
[_forgotCredsLabel setTextColor:[CPColor blueColor]];
[_forgotCredsLabel setFont:[CPFont boldSystemFontOfSize:12.0]];
[[_loginPanel contentView] addSubview:_forgotCredsLabel];

_invalidCredsMessageLabel = [[CPTextField alloc]
initWithFrame:CGRectMake(30.0, 0.0, 350.0, 20.0)];
[_invalidCredsMessageLabel setEditable:NO];
[_invalidCredsMessageLabel setBezeled:NO];
[_invalidCredsMessageLabel setSecure:NO];
[_invalidCredsMessageLabel setStringValue:@"User Name and/or
Password is invalid please try again."];
[_invalidCredsMessageLabel setTextColor:[CPColor redColor]];
[_invalidCredsMessageLabel setFont:[CPFont boldSystemFontOfSize:
12.0]];
//[_invalidCredsMessageLabel setHidden:YES];
[[_loginPanel contentView] addSubview:_invalidCredsMessageLabel];

}

return self;
}

/*!
Sets the window's title. If this is not defined, a default title
based on your warning level will be used.
@param aTitle the title to use in place of the default. Set to nil
to use default.
*/
- (void)center
{
[_loginPanel center];
}

/*!
Sets the window's title. If this is not defined, a default title
based on your warning level will be used.
@param aTitle the title to use in place of the default. Set to nil
to use default.
*/
- (void)setTitle:(CPString)aTitle
{
_windowTitle = aTitle;
}

/*!
Gets the window's title.
*/
- (CPString)title
{
return _windowTitle;
}

/*!
Sets the window's title. If this is not defined, a default title
based on your warning level will be used.
@param aTitle the title to use in place of the default. Set to nil
to use default.
*/
- (void)setButtonTitle:(CPString)aTitle
{
_buttonTitle = aTitle;
}

/*!
Gets the window's title.
*/
- (CPString)buttonTitle
{
return _buttonTitle;
}

/*!
Sets the window's image. If this is not defined, a default title
based on your warning level will be used.
@param aFileName the file name to use in place of the default. Set
to nil to use default.
*/
- (void)setImageFileName:(CPString)aFileName
{
_imageFileName = aFileName;
}

/*!
Gets the window's image.
*/
- (CPString)imageFileName
{
return _imageFileName;
}

_errorMessageDisplayed

/*!

@param shouldDisplayErrorMessage .
*/
- (void)setErrorMessageDisplayed:(BOOL)shouldDisplayErrorMessage
{
_errorMessageDisplayed = shouldDisplayErrorMessage;
}

/*!

*/
- (BOOL)isErrorMessageDisplayed
{
return _errorMessageDisplayed;
}



/*!
Sets the receiver’s delegate.
@param delegate - Delegate for the alert. nil removes the
delegate.
*/
- (void)setDelegate:(id)delegate
{
_delegate = delegate;
}

/*!
Gets the receiver's delegate.
*/
- (void)delegate
{
return _delegate;
}

/*!
Displays the \c OCLoginDialog as a modal dialog. The user will not
be
able to interact with any other controls until the dialog is
dismissed
by clicking on the button.
*/
- (void)runModal
{
var theTitle = @"Enter your User Name and Password";
var theImageFileName = @"Resources/oringe_hard_hat_logo.png";
var theButtonTitle = @"Login";

[_loginPanel setTitle:_windowTitle ? _windowTitle : theTitle];
[_button setTitle:_buttonTitle ? _buttonTitle : theButtonTitle];
[_invalidCredsMessageLabel setHidden:!_errorMessageDisplayed];

[CPApp runModalForWindow:_loginPanel];
}

/* @ignore */
- (void)_notifyDelegate:(id)button
{
if (_delegate && [_delegate respondsToSelector:@selector
(loginDidEnd:)])
[_delegate loginDidEnd:self];

[CPApp abortModal];
[_loginPanel close];
}

@end


Reply all
Reply to author
Forward
0 new messages