<?php
namespace Modules\Orders\OrdersList;

class View_Utils_FormBulkUpdate extends \App\Mvc\View_Utils_FormAbstract
{

	/**
	 * Creates the form for insert/update.
	 * @see \App\Mvc\View_Utils_FormAbstract::getForm()
	 */
	public function getForm()
	{

		$form = \Engine\Form\General::create();

		// resp user update fieldset
		$fieldset = \Engine\Form\Container\Fieldset::create($this->lang['bulkUpdate']['fieldset']['changeRespUser']);
		$form->addContainer($fieldset);

		$fldRespUserReset = new \Engine\Form\Input\Select($this->lang['bulkUpdate']['formFields']['action'], 'respUserAction', $this->values['respUserAction']);
		$fldRespUserReset->setPossibleValues( ['update' => $this->lang['bulkUpdate']['actionValues']['update']] );
		$fldRespUserReset->setDefaultOptionText($this->lang['bulkUpdate']['actionValues']['default']);
		$fldRespUserReset->showDefaultOption(true);
		$fieldset->addElement($fldRespUserReset);

		// user autocomplete
		$user = new \App\Form\Input\Autocomplete_User($this->lang['bulkUpdate']['formFields']['respUser'], 'idUser' , $this->values['idUser']);
		$user->setMandatory();
		$fieldset->addElement($user);

		$fldRespUserReset->setControlledElements( ['update'=>[$user]] );

		// MICE project
		$fieldsetMice = new \Engine\Form\Container\Fieldset($this->lang['bulkUpdate']['fieldset']['changeMiceProject']);
		$form->addContainer($fieldsetMice);

		$fldMiceReset = new \Engine\Form\Input\Select($this->lang['bulkUpdate']['formFields']['action'], 'miceProjectAction', $this->values['miceProjectAction']); // TODO: vezi lang!
		$fldMiceReset->setPossibleValues([
				'update'	=>	$this->lang['bulkUpdate']['actionValues']['update'],
				'delete'	=>	$this->lang['bulkUpdate']['actionValues']['delete'],
		]);
		$fldMiceReset->showDefaultOption(true);
		$fldMiceReset->setDefaultOptionText($this->lang['bulkUpdate']['actionValues']['default']);
		$fieldsetMice->addElement($fldMiceReset);

		$fldMiceUpdate = new \App\Form\Input\Autocomplete_MiceProject($this->lang['bulkUpdate']['formFields']['idMiceProject'], 'idMiceProject', $this->values['idMiceProject']);
		$fldMiceUpdate->setMandatory();
		$fieldsetMice->addElement($fldMiceUpdate);
		$fldMiceReset->setControlledElements(['update'=>[$fldMiceUpdate]]);

		// Order type
		$fieldset = new \Engine\Form\Container\Fieldset($this->lang['bulkUpdate']['fieldset']['changeOrderType']);
		$form->addContainer($fieldset);

		$fldOrderTypeReset = new \Engine\Form\Input\Select($this->lang['bulkUpdate']['formFields']['action'], 'orderTypeAction', $this->values['orderTypeAction']); // TODO: lang
		$fldOrderTypeReset->setPossibleValues([
			'update'	=>	$this->lang['bulkUpdate']['actionValues']['update'],
			'delete'	=>	$this->lang['bulkUpdate']['actionValues']['delete'],
		]);
		$fldOrderTypeReset->showDefaultOption(true);
		$fldOrderTypeReset->setDefaultOptionText($this->lang['bulkUpdate']['actionValues']['default']);
		$fieldset->addElement($fldOrderTypeReset);

		$fldOrderTypeUpdate = new \App\Form\Input\Select_OrderType($this->lang['bulkUpdate']['formFields']['orderType'], 'orderType', $this->values['orderType']);
		$fldOrderTypeUpdate->setMandatory();
		$fldOrderTypeUpdate->showDefaultOption();
		$fieldset->addElement($fldOrderTypeUpdate);
		$fldOrderTypeReset->setControlledElements(['update'=>[$fldOrderTypeUpdate]]);

		// Service type
		$fieldset = new \Engine\Form\Container\Fieldset($this->lang['bulkUpdate']['fieldset']['changeServiceType']);
		$form->addContainer($fieldset);

		$fldServiceTypeReset = new \Engine\Form\Input\Select($this->lang['bulkUpdate']['formFields']['action'], 'serviceTypeAction', $this->values['serviceTypeAction']); // TODO: langs
		$fldServiceTypeReset->setPossibleValues([
			'update'	=>	$this->lang['bulkUpdate']['actionValues']['update'],
			'delete'	=>	$this->lang['bulkUpdate']['actionValues']['delete'],
		]);
		$fldServiceTypeReset->showDefaultOption(true);
		$fldServiceTypeReset->setDefaultOptionText($this->lang['bulkUpdate']['actionValues']['default']);
		$fieldset->addElement($fldServiceTypeReset);

		$fldServiceTypeUpdate = new \App\Form\Input\Select_OrderServicesType($this->lang['bulkUpdate']['formFields']['serviceType'], 'serviceType', $this->values['serviceType']);
		$fldServiceTypeUpdate->setMandatory();
		$fldServiceTypeUpdate->showDefaultOption();
		$fieldset->addElement($fldServiceTypeUpdate);
		$fldServiceTypeReset->setControlledElements(['update'=>[$fldServiceTypeUpdate]]);

		// Flag
		$fieldset = new \Engine\Form\Container\Fieldset($this->lang['bulkUpdate']['fieldset']['changeFlag']);
		$form->addContainer($fieldset);

		$fldFlagReset = new \Engine\Form\Input\Select($this->lang['bulkUpdate']['formFields']['action'], 'flagAction', $this->values['flagAction']);
		$fldFlagReset->setPossibleValues([
			'update'	=>	$this->lang['bulkUpdate']['actionValues']['update'],
			'delete'	=>	$this->lang['bulkUpdate']['actionValues']['delete'],
		]);
		$fldFlagReset->showDefaultOption(true);
		$fldFlagReset->setDefaultOptionText($this->lang['bulkUpdate']['actionValues']['default']);
		$fieldset->addElement($fldFlagReset);

		$fldFlagUpdate = new \App\Form\Input\OrderFlag($this->lang['bulkUpdate']['formFields']['flag'], 'flag', $this->values['flag']);
		$fldFlagUpdate->setMandatory();
		if (!\App\UserAccess\CurrentUserAccessFast::getInstance()->getAccessOptionValue('Modules/Orders/Details/OrderFlag')) {
			$fldFlagUpdate->setDisabled();
		}
		$fieldset->addElement($fldFlagUpdate);
		$fldFlagReset->setControlledElements(['update'=>[$fldFlagUpdate]]);

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

		return $form;
	}

}