<?php
namespace Modules\Orders\MiceProjects;

class View_Utils_FormAdmin extends \App\Mvc\View_Utils_FormAbstract
{
	public function getForm()
	{
		// load cfg
		$cfg=\Entity\MiceProject::loadCFG();

		// create the form
		$form =\Engine\Form\General::create();
		$fieldset = \Engine\Form\Container\Fieldset::create($this->lang['insert']['general']);
		$form->addContainer($fieldset);

		// project name
		$name = new \Engine\Form\Input\Text($this->lang['insert']['name'], 'name', $this->values['name']);
		$name->importFromConfig($cfg['name']);
		$form->addElement($name);

		// project code
		$code = new \Engine\Form\Input\Text($this->lang['insert']['code'], 'code', $this->values['code']);
		$code->importFromConfig($cfg['code']);
		$form->addElement($code);

		// corporate
		$corporate = new \App\Form\Input\Autocomplete_Corporate($this->lang['insert']['corporate'], 'corporate', $this->values['corporate']['id']);
		$corporate->importFromConfig($cfg['idCorporate']);
		$corporate->addEvent('onChange', "FormField.setValue(null, 'Engine/Form/Input/Autocomplete', null, 'contactPerson', {
			displayValue: '',
			value: ''});");
		$form->addElement($corporate);

		// contact person
		$contactPerson = new \App\Form\Input\Autocomplete_ContactPersonCorporate($this->lang['insert']['contact_person'], 'contactPerson', $this->values['contactPerson']);
		$contactPerson->importFromConfig($cfg['idContactPerson']);
		$contactPerson->setFilters('idCompany', $corporate);
		$form->addElement($contactPerson);

		// project type
		$type = new \App\Form\Input\Autocomplete_MiceProjectType($this->lang['insert']['type'], 'idType', $this->values['idType']);
		$type->importFromConfig($cfg['idType']);
		$form->addElement($type);

		// interval
		$interval = new \Engine\Form\Input\DateInterval($this->lang['insert']['interval'], 'interval', $this->values['interval']);
		$interval->setMandatory($cfg['startDate']['mandatory']);
		$form->addElement($interval);

		// location
		$location = new \App\Form\Input\Autocomplete_CountryCity($this->lang['insert']['location'], 'location', $this->values['location']);
		$location->setMandatory($cfg['countryCode']['mandatory']);
		$form->addElement($location);

		// email
		$email = new \Engine\Form\Input\Text($this->lang['insert']['email'], 'email', $this->values['email']);
		$email->importFromConfig($cfg['email']);
		$email->setTooltip($this->lang['insert']['emailTooltip']);
		$form->addElement($email);

		// responsible
		$responsibleUser = new \App\Form\Input\Autocomplete_User($this->lang['insert']['responsibleUser'], 'idResponsibleUser', $this->values['idResponsibleUser']);
		$responsibleUser->importFromConfig($cfg['idResponsibleUser']);
		$form->addElement($responsibleUser);

		// comments
		$comments = new \Engine\Form\Input\Textarea($this->lang['insert']['comments'], 'comments', $this->values['comments']);
		$comments->importFromConfig($cfg['comments']);
		$form->addElement($comments);

		// remarks
		$remarks = new \App\Form\Input\Remarks($this->lang['insert']['remarks'], 'remarks', $this->values['remarks']);
		$remarks->importFromConfig($cfg['remarks']);
		$remarks->setRemarksType('miceProject');
		$form->addElement($remarks);

		$form->addElement(new \Engine\Form\Input\Hidden('', $this->submitButtonName, 1));
		return $form;
	}
}