| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php
- namespace ThurData\Servers\KerioEmail\Core\UI\Widget\Forms\AjaxFields;
- use ThurData\Servers\KerioEmail\Core\UI\Interfaces\AjaxElementInterface;
- use ThurData\Servers\KerioEmail\Core\UI\ResponseTemplates;
- /**
- * Select field controler
- *
- * @autor ThurData <info@thurdata.ch>
- */
- class Select extends \ThurData\Servers\KerioEmail\Core\UI\Widget\Forms\Fields\Select implements AjaxElementInterface
- {
- use \ThurData\Servers\KerioEmail\Core\UI\Traits\HideByDefaultIfNoData;
- protected $id = 'ajaxSelect';
- protected $name = 'ajaxSelect';
- protected $vueComponent = true;
- protected $defaultVueComponentName = 'mg-ajax-select';
-
- /**
- * a list of fields id's, fi those fields are changed the select will reload its content
- * @var type array
- */
- protected $reloadOnChangeFields = [];
- /**
- * do not overwrite this function
- * @return type \ThurData\Servers\KerioEmail\Core\UI\ResponseTemplates\RawDataJsonResponse
- */
- public function returnAjaxData()
- {
- $this->prepareAjaxData();
-
- $returnData = [
- 'options' => $this->getAvailableValues(),
- 'selected' => $this->getValue(),
- 'additionalData' => $this->data['additionalData']
- ];
- return (new ResponseTemplates\RawDataJsonResponse($returnData))->setCallBackFunction($this->callBackFunction);
- }
- /**
- * overwrite this function, use setSelectedValue && setAvailableValues functions
- */
- public function prepareAjaxData()
- {
- $this->setAvailableValues([
- ['key' => '1', 'value' => 'value1'],
- ['key' => '2', 'value' => 'value2']
- ]);
- // '2' for single, ['1', '2'] for multiple
- $this->setSelectedValue('2');
- }
- public function initContent()
- {
-
- }
- public function addReloadOnChangeField($fieldId = null)
- {
- if (is_string($fieldId) && $fieldId !== '')
- {
- $this->reloadOnChangeFields[] = $fieldId;
- }
- return $this;
- }
- public function getReloadOnChangeFields()
- {
- return $this->reloadOnChangeFields;
- }
- public function wrappReloadIdsToString()
- {
- $str = '';
- foreach ($this->reloadOnChangeFields as $key => $value)
- {
- $str .= (string)$key . " : '" . $value . "'" . ($key === end(array_keys($this->reloadOnChangeFields)) ? ' ' : ', ');
- }
- return $str;
- }
- }
|