//
//  SendMessageViewController.m
//  k-observer-iphone
//
//  Created by vvv ооо on 31.08.12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "SendMessageViewController.h"
#import "AppDelegate.h"


extern AppDelegate* appDelegate;

@interface SendMessageViewController ()

@end

@implementation SendMessageViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

-(void)viewDidAppear:(BOOL)animated
{
    UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithTitle:@"Отправить" style:UIBarButtonItemStylePlain target:self action:@selector(SendMessage)];
    
    
    self.navigationItem.rightBarButtonItem = anotherButton;
}

-(void)viewDidDisappear:(BOOL)animated
{
    
    self.navigationItem.rightBarButtonItem = nil;
}

-(void)SendMessage
{
    
    self.navigationItem.rightBarButtonItem = nil;
    [appDelegate.navController popViewControllerAnimated:true];
    
    NSString* ns_msg = ((UITextView*)[self.view viewWithTag:1]).text;
    
    if (![ns_msg isEqualToString:@""])
    {

        [appDelegate.observerClient SendMessage:ns_msg];
        
        [((UITextView*)[self.view viewWithTag:1]) setText:@""];
    }
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
