<?php
namespace Modules\Orders\MiceProjects;

class View_Utils_FormFilters extends \App\Mvc\View_Utils_FormAbstract
{
	/**
	 * Creates the form for document series filters.
	 * @see \App\Mvc\View_Utils_FormAbstract::getForm()
	 */
	public function getForm()
	{
		$fieldsValues = $this->values['listingParams']->getFilters();

		$form=\Engine\Form\Filters::create();
		$form->setColumns(3);

		// name
		$name = new \Engine\Form\Input\Text($this->lang['index']['filters']['name'], 'filters[name]', $fieldsValues['name']);
		$form->addElement($name);

		// type
		$type = new \App\Form\Input\Autocomplete_MiceProjectType($this->lang['index']['filters']['type'], 'filters[type]', $fieldsValues['type']['id']);
		$form->addElement($type);

		// status
		$status = new \Engine\Form\Input\Select($this->lang['index']['filters']['status'], 'filters[status]', $fieldsValues['status']);
		$status->setPossibleValues([
			'all'=> 	'-',
			'open'=> 	$this->lang['index']['filters']['status_open'],
			'closed'=> 	$this->lang['index']['filters']['status_closed'],
		]);
		$form->addElement($status);

		// location
		$location = new \App\Form\Input\Autocomplete_CountryCity($this->lang['index']['filters']['location'], 'filters[location]', $fieldsValues['location']);
		$form->addElement($location);

		// period
		$period = new \Engine\Form\Input\DateInterval($this->lang['index']['filters']['period'], 'filters[period]', $fieldsValues['period']);
		$form->addElement($period);

		// corporation
		$corporation = new \App\Form\Input\Autocomplete_Corporate($this->lang['index']['filters']['corporation'], 'filters[corporation]', $fieldsValues['corporation']['id']);
		$form->addElement($corporation);

		// responsible user
		$responsibleUser = new \App\Form\Input\Autocomplete_User($this->lang['index']['filters']['responsibleUser'], 'filters[responsibleUser]', $fieldsValues['responsibleUser']);
		$form->addElement($responsibleUser);

		// project ID
		$projectId = new \Engine\Form\Input\Text($this->lang['index']['filters']['projectId'], 'filters[projectId]', $fieldsValues['projectId']);
		$form->addElement($projectId);

		// project Code
		$projectCode = new \Engine\Form\Input\Text($this->lang['index']['filters']['projectCode'], 'filters[projectCode]', $fieldsValues['projectCode']);
		$form->addElement($projectCode);

		$form->setJsCallback('MVC.listing.installedHandlers["listing"].reloadAndResetListing');
		$form->loadMissingDefaultValues($this->values['listingParams']->getDefaultFilters());
		return $form;
	}
}