<?php
/**
 * Dictionary form
 *
 * @author Moises Heberle [moises@solis.coop.br]
 *
 * @version $Id$
 *
 * \b Maintainers \n
 * Eduardo Bonfandini [eduardo@solis.coop.br]
 * Jamiel Spezia [jamiel@solis.coop.br]
 * Luiz Gregory Filho [luiz@solis.coop.br]
 * Moises Heberle [moises@solis.coop.br]
 * Sandro Roberto Weisheimer [sandrow@solis.coop.br]
 *
 * @since
 * Class created on 03/12/2008
 *
 * \b Organization: \n
 * SOLIS - Cooperativa de Solucoes Livres \n
 * The Gnuteca3 Development Team
 *
 * \b CopyLeft: \n
 * CopyLeft (L) 2008 SOLIS - Cooperativa de Solucoes Livres \n
 *
 * \b License: \n
 * Licensed under GPL (for further details read the COPYING file or http://www.gnu.org/copyleft/gpl.html )
 *
 * \b History: \n
 * See history in SVN repository: http://gnuteca.solis.coop.br
 */
class FrmDictionary extends GnutecaForm
{


    public function __construct()
    {
        $this->function = MIOLO::_REQUEST('function');

        if ( ($this->function == 'search') || ($this->function == '') )
        {
            $this->setAllFunctions('Dictionary', array('description'));
        }
        else
        {
            $this->setAllFunctions('Dictionary', array('description'), 'dictionaryId', array('description', 'readOnly'));
        }

         parent::__construct();
    }


    public function createFields()
    {
        if ( $this->function == 'update' )
        {
            $dictionaryId = new MTextField('dictionaryId', null, _M('Code', $this->module), FIELD_ID_SIZE);
            $this->setFocus('description');
            $dictionaryId->setReadOnly(TRUE);
            $fields[] = $dictionaryId;
            $validators[] = new MRequiredValidator('dictionaryId');
        }

        if ( ( $this->function == 'search' ) || ( $this->function == '' ) )
        {
           	$this->setFocus('dictionaryIdS');
            $dictionaryIdS = new MTextField('dictionaryIdS', null, _M('Code', $this->module), FIELD_ID_SIZE);
            $fields[] = $dictionaryIdS;
            $fields[] = new MTextField('tags', null, _M('tags', $this->module), FIELD_DESCRIPTION_SIZE);
        }
        $fields[] = new MTextField('description', NULL, _M('Description', $this->module), FIELD_ID_SIZE);

        if ( ( $this->function == 'insert' ) || ( $this->function == 'update' ) )
        {
           	$this->setFocus('description');
            $fields[] = new MMultiLineField('tags', null, _M('Tags', $this->module), null, FIELD_MULTILINE_ROWS_SIZE, FIELD_MULTILINE_COLS_SIZE);
            $validators[] = new MRequiredValidator('tags');
            $validators[] = new MRequiredValidator('description');
        }


        $lbl = new MLabel(_M('Read only', $this->module) . ':');
        $lbl->setWidth(FIELD_LABEL_SIZE);

        if ($this->function == 'insert')
        {
            $isRestrictedValue = 'f';
        }

        $readOnly = new MRadioButtonGroup('readOnly', null, GnutecaUtils::listYesNo(1), $isRestrictedValue, null, MRadioButtonGroup::LAYOUT_HORIZONTAL);
        $fields[] = new MHContainer('hctReadOnly', array($lbl, $readOnly));

        $this->setFields($fields);
        $this->setValidators($validators);
    }
}
?>
