<?php
/**
 * Form for comment under the blog item.
 *
 * @package koubel homepage
 * @author Miroslav Kubelik (koubel@volny.cz)
 * @copyright Copyright (c) 2007-2009 Miroslav Kubelik
 * @license http://opensource.org/licenses/gpl-license.php GNU GPL
 */

/**
 * Form for comment under the blog item.
 *
 * @package koubel homepage
 * @author Miroslav Kubelik (koubel@volny.cz)
 * @copyright Copyright (c) 2007-2009 Miroslav Kubelik
 * @license http://opensource.org/licenses/gpl-license.php GNU GPL
 */
class Blog_Form_Comment extends Zend_Form
{
    /**
     * Init the form elements.
     */
    public function init()
    {
        $username = new Zend_Form_Element_Text("username");
        $username->addFilter('StringTrim')
            ->setLabel('Name (Required)')
            ->setAttrib('size',30)
            ->setRequired(true);

        $email = new Zend_Form_Element_Text("email");
        $email->addFilter('StringTrim')
            ->setRequired(true)
            ->setLabel('Email (Required)')
            ->setAttrib('size',30)
            ->addValidator(new Zend_Validate_EmailAddress());

        $www = new Zend_Form_Element_Text("www");
        $www->addFilter('StringTrim')
            ->setLabel('www')
            ->setAttrib('size',30)
            ->addValidator(new MKLib_UrlValid());

        $message = new Zend_Form_Element_Textarea("message",
            array(
                'label'=>'message',
                'style'=>'width:500px',
                'rows'=>10,
                'cols'=>40
            )
        );
        $message->addFilter('StringTrim')
            ->setRequired(true)
            ->setLabel('Your comment (allowed tags <a href>,<pre>)');

        $antiSpam = new Zend_Form_Element_Text("homepage");
        $antiSpam->setRequired(true)
            ->addValidator(new Zend_Validate_Identical('NejsemSpammer'));

        $formAction = new Zend_Form_Element_Hidden('formAction');
        $formAction->setValue('addCommentDb');

        $submit = new Zend_Form_Element_Submit('submitB',array('class'=>'dialogButton'));
        $submit->setLabel('Submit');

        $reset = new Zend_Form_Element_Reset('resetB',array('class'=>'dialogButton'));
        $reset->setLabel('Reset');

        $preview = new Zend_Form_Element_Button('preview',array('class'=>'dialogButton'));
        $preview->setAttrib('onclick','commentPreview(); return false;')
            ->setValue("Preview")
            ->setLabel('Preview');
        
        $this->addElement($username)
            ->addElement($email)
            ->addElement($www)
            ->addElement($message)
            ->addElement($antiSpam)
            ->addElement($formAction)
            ->addElement($submit)
            ->addElement($reset)
            ->addElement($preview);

        $this->addDisplayGroup(
            array('username', 'email','www','message','homepage','formAction','submitB','resetB','preview')
            ,'commentGroup'
            ,array("legend"=>"Add comment","class"=>'dialog')
        );

        $this->setDisplayGroupDecorators(array(
            'FormElements',
            'Fieldset'
        ));

        $this->setDecorators(array(
            'FormElements',
            'Form'
        ));

        $this->setElementDecorators(array(
            'ViewHelper','Errors',
            array('HtmlTag', array('tag' => 'div','class'=>'formElement')),
            array('Label')
        ));

        $antiSpam->clearDecorators();
        $antiSpam->addDecorator('ViewScript',array('viewScript'=>'antiSpamInput.phtml'));
        $antiSpam->addDecorator('Errors');

        $formAction->clearDecorators();
        $formAction->addDecorator('ViewHelper');

        $submit->clearDecorators();
        $submit->addDecorator('ViewHelper');

        $reset->clearDecorators();
        $reset->addDecorator('ViewHelper');

        $preview->clearDecorators();
        $preview->addDecorator('ViewHelper',array('helper'=>'FormButtonType'));
    }
}