<?php

class MButton extends MActionControl
{
    public $target = '_self';
    public $type;
    public $image;
    public $onclickdisable;

    public function __construct( $name = '', $value = '', $action = NULL, $image = NULL, $onclickdisable = FALSE )
    {
        parent::__construct( $name, $value );
        $this->action  = $action ? $action : 'submit';
        $this->image   = $image;
        $this->onclickdisable = $onclickdisable;
        $this->setClass('mButton');
    }

    public function setImage( $location )
    {
        $this->image = $location;
    }

    public function generateButton()
    {
        if ( $this->value == '' )
        {
            $this->value = $this->text;
        }

        if (( $this->value == '' ) || ( $this->value == '&nbsp;' ))
        {
            $this->value = 'Enviar';
        }

        $action = $this->action;
        $this->type = ( strtoupper($action) == 'RESET' ) ? 'reset' : 'button';

        // if it has a event registered, it's not necessary calculate $onclick
        if ($this->hasEvent('click'))
        {
            return;
        }

        if ($this->type == 'reset')
        {
            return;
        }

        $onclick = $this->getOnClick($action);

        if ($onclick != '' && (! $this->getAttribute('onclick')))
        {
            $this->addAttribute('onclick', $onclick);
        }
    }

    public function generateInner()
    {
        if ( $this->visible )
        {
            $this->generateButton();
            $this->inner = $this->generateLabel() . $this->getRender('button');
        }
    }
}
?>
