<?php

namespace Modules\Partners\Corporates\ContactPersons;


class View_Utils_FormFilters extends \App\Mvc\View_Utils_FormAbstract
{

	/**
	 * Creates the form for corporates filter
	 * @see \App\Mvc\View_Utils_FormAbstract::getForm()
	 */
	public function getForm()
	{
		$fieldsValues = $this->values['listingParams']->getFilters();

		$CFG = \Engine\Loader_Cfg::getInstance()->getGlobal();
		$_LANG = \Engine\Loader_Lang::getInstance()->getAll();

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

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

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

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

		$role = new \Engine\Form\Input\Select($this->lang['index']['filters']['role'], "filters[role]", $fieldsValues['role']);
		$role->showDefaultOption();
		$list = [];
		foreach ($CFG['contactPersonsRolesList'] as  $roleStr) {
			$list[$roleStr] = $_LANG['generalData']['contactPersonsRoles'][$roleStr];
		}
		$role->setPossibleValues($list);
		//$role->setTooltip($this->lang['index']['tooltips']['role']);
		$form->addElement($role);

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

	}

}