<?php
namespace ModulesAbstract\Admin\Access;

abstract class View_Index extends \App\Mvc\View_Popup_FormAbstract
{
	/**
	 * {@inheritDoc}
	 * @see \App\Mvc\View_Popup_GeneralAbstract::getTemplatePath()
	 */
	public function getTemplatePath()
	{
		return __DIR__."/_tpl/index.tpl";
	}

	/**
	 * {@inheritDoc}
	 * @see \App\Mvc\View_Popup_FormAbstract::render_getForm()
	 */
	protected function render_getForm($formValues)
	{

		// check if the formClassName was set
		if (!$this->formClassName) {
			throw new \Exception('You did not set the `formClassName` class attribute for the class `'.get_called_class().'`.');
		}

		// the current ns
		$namespace=getClassNamespace(get_called_class());

		$className="\\{$namespace}\\{$this->formClassName}";
		$formMngObj = new $className($this->controller);

		if ($formValues!==null) {
			$formMngObj->setValues($formValues);
		}

		$formMngObj->setCurrentAccess($this->input['currentAccess']);

		// force the submit button name
		if ($this->input['formSubmitButtonName']) {
			$formMngObj->setSubmitButtonName($this->input['formSubmitButtonName']);
		}

		$form = $formMngObj->getForm();

		if ($formValues && $this->input['formSubmitButtonName'] && !$formValues[$this->input['formSubmitButtonName']]) {
			// all forms should have the focus set on the first input
			$form->setFocus(true);
		}

		return $form;
	}
}