| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280 |
- <?php defined('BX_DOL') or die('hack attempt');
- /**
- * Copyright (c) UNA, Inc - https://una.io
- * MIT License - https://opensource.org/licenses/MIT
- * @defgroup Tasks Tasks
- * @ingroup UnaModules
- *
- * @{
- */
- class BxTasksGridPreValues extends BxBaseModGeneralGrid
- {
- protected $_iContextPid;
- protected $_sList;
- protected $_aListInfo;
- public function __construct ($aOptions, $oTemplate = false)
- {
- $this->_sModule = 'bx_tasks';
- parent::__construct ($aOptions, $oTemplate);
- $this->_aConfirmMessages = [
- 'delete' => _t('_bx_tasks_grid_action_confirm_pv_delete')
- ];
- if(($sFfName = 'profile_id') && ($iValue = bx_get($sFfName)) !== false)
- $this->setContextPid($iValue);
-
- if(($sFfName = 'list') && ($sValue = bx_get($sFfName)) !== false)
- $this->setList($sValue);
- }
- public function setContextPid($iContextPid)
- {
- $this->_iContextPid = (int)$iContextPid;
- $this->_aQueryAppend['profile_id'] = $this->_iContextPid;
- }
- public function setList($sList)
- {
- $this->_sList = bx_process_input($sList);
- $this->_aQueryAppend['list'] = $this->_sList;
- $this->_aListInfo = $this->_oModule->_oDb->getPreLists([
- 'sample' => 'name',
- 'name' => $this->_sList
- ]);
- }
- public function getFormCallBackUrlAPI($sAction, $iId = 0)
- {
- return '/api.php?r=system/perfom_action_api/TemplServiceGrid/¶ms[]=&o=' . $this->_sObject . '&a=' . $sAction . '&profile_id=' . $this->_iContextPid . '&list=' . $this->_sList . '&id=' . $iId;
- }
- public function performActionAdd()
- {
- if(!$this->_sList)
- return $this->_getActionResult(($sMsg = _t('_bx_tasks_txt_err_empty_pre_list')) && $this->_bIsApi ? bx_api_get_msg($sMsg) : ['msg' => $sMsg]);
- $sAction = 'add';
- $oForm = $this->_getForm($sAction);
- $oForm->initChecker();
- if($oForm->isSubmittedAndValid()) {
- $iId = (int)$oForm->insert(['context_id' => $this->_iContextPid, 'list' => $this->_sList]);
- if(!$iId)
- return $this->_getActionResult(['msg' => _t('_bx_tasks_txt_err_cannot_perform_action')]);
- return $this->_bIsApi ? [] : echoJson(['grid' => $this->getCode(false), 'blink' => $iId]);
- }
- if($this->_bIsApi)
- return $this->getFormBlockAPI($oForm, $sAction);
- $sContent = BxTemplFunctions::getInstance()->popupBox($this->_oModule->_oConfig->getHtmlIds('pre_values_popup') . $sAction, _t('_bx_tasks_popup_pv_title_' . $sAction), $this->_oModule->_oTemplate->parseHtmlByName('popup_pre_values.html', [
- 'form_id' => $oForm->aFormAttrs['id'],
- 'form' => $oForm->getCode(true),
- 'object' => $this->_sObject,
- 'action' => $sAction
- ]));
- return echoJson(['popup' => ['html' => $sContent, 'options' => ['closeOnOuterClick' => false]]]);
- }
- public function performActionEdit()
- {
- $sAction = 'edit';
- $iItemId = $this->_getIds();
- $aItem = $this->_oModule->_oDb->getPreValues(['sample' => 'id', 'id' => $iItemId]);
- if(!$aItem)
- return $this->_bIsApi ? [] : echoJson([]);
- $oForm = $this->_getForm($sAction, $aItem);
- $oForm->initChecker($aItem);
- if($oForm->isSubmittedAndValid()) {
- if(!$oForm->update($aItem['id']))
- return $this->_getActionResult(['msg' => _t('_bx_tasks_txt_err_cannot_perform_action')]);
- return $this->_bIsApi ? [] : echoJson(['grid' => $this->getCode(false), 'blink' => $iItemId]);
- }
- if($this->_bIsApi)
- return $this->getFormBlockAPI($oForm, $sAction, $iItemId);
- $sContent = BxTemplFunctions::getInstance()->popupBox($this->_oModule->_oConfig->getHtmlIds('pre_values_popup') . $sAction, _t('_bx_tasks_popup_pv_title_' . $sAction), $this->_oModule->_oTemplate->parseHtmlByName('popup_pre_values.html', [
- 'form_id' => $oForm->aFormAttrs['id'],
- 'form' => $oForm->getCode(true),
- 'object' => $this->_sObject,
- 'action' => $sAction
- ]));
- echoJson(['popup' => ['html' => $sContent, 'options' => ['closeOnOuterClick' => false]]]);
- }
- public function performActionActivate()
- {
- parent::performActionEnable(1);
- }
- public function performActionDeactivate()
- {
- parent::performActionEnable(0);
- }
- protected function _getActionAdd($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = [])
- {
- if(!$this->_sList)
- $isDisabled = true;
- return parent::_getActionDefault($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
- }
- protected function _getFilterOnChange()
- {
- return $this->_oModule->_oConfig->getJsObject('pre_values') . '.onChangeList(this)';
- }
- protected function _getFilterControls()
- {
- parent::_getFilterControls();
- $sContent = $this->_getFilterSelectOne('list', $this->_sList, $this->_oModule->getPreLists(), '_bx_tasks_grid_filter_item_title_pv_select_one_list');
- $sContent .= $this->_getSearchInput();
- return $sContent;
- }
- protected function _getFilterControlsAPI($aFilters = [])
- {
- $aFilters = [
- 'list' => [
- ['value' => '', 'title' => _t('_bx_tasks_grid_filter_item_title_pv_select_one_list')]
- ]
- ];
- $aLists = $this->_oModule->getPreLists();
- foreach($aLists as $sKey => $sValue)
- $aFilters['list'][] = ['value' => $sKey, 'title' => $sValue];
- return parent::_getFilterControlsAPI($aFilters);
- }
- protected function _getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage)
- {
- if(!$this->_iContextPid || !$this->_sList)
- return [];
- $this->_aOptions['source'] .= $this->_oModule->_oDb->prepareAsString(' AND `context_id`=? AND `list`=?', $this->_iContextPid, $this->_sList);
- return parent::_getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);
- }
- protected function _getForm($sAction, $aItem = [])
- {
- $CNF = &$this->_oModule->_oConfig->CNF;
- $aActionParams = [
- 'o' => $this->_sObject,
- 'a' => $sAction,
- 'profile_id' => $this->_iContextPid,
- 'list' => $this->_sList
- ];
- if($aItem)
- $aActionParams['id'] = $aItem['id'];
- $aForm = [
- 'form_attrs' => [
- 'id' => 'bx-tasks-pre-value-' . $sAction,
- 'action' => BX_DOL_URL_ROOT . bx_append_url_params('grid.php', $aActionParams),
- 'method' => BX_DOL_FORM_METHOD_DEFAULT
- ],
- 'params' => [
- 'db' => [
- 'table' => $CNF['TABLE_PRE_VALUES'],
- 'key' => 'id',
- 'uri' => '',
- 'uri_title' => '',
- 'submit_name' => 'do_submit'
- ],
- ],
- 'inputs' => [
- 'value' => [
- 'type' => 'hidden',
- 'name' => 'value',
- 'value' => (int)$this->_oModule->_oDb->getPreValues([
- 'sample' => 'value_to_use',
- 'context_id' => $this->_iContextPid,
- 'list' => $this->_sList
- ]),
- 'db' => [
- 'pass' => 'Int',
- ]
- ],
- 'color' => [
- 'type' => 'rgb',
- 'name' => 'color',
- 'caption' => _t('_bx_tasks_form_pv_input_color'),
- 'value' => '',
- 'required' => '0',
- 'db' => [
- 'pass' => 'Xss',
- ]
- ],
- 'title' => [
- 'type' => 'text',
- 'name' => 'title',
- 'caption' => _t('_bx_tasks_form_pv_input_title'),
- 'value' => '',
- 'required' => '1',
- 'db' => [
- 'pass' => 'Xss',
- ],
- 'checker' => [
- 'func' => 'Avail',
- 'params' => [],
- 'error' => _t('_bx_tasks_form_pv_input_err'),
- ],
- ],
- 'controls' => [
- 'name' => 'controls',
- 'type' => 'input_set',
- [
- 'type' => 'submit',
- 'name' => 'do_submit',
- 'value' => _t('_bx_tasks_form_pv_input_submit'),
- ], [
- 'type' => 'reset',
- 'name' => 'do_cancel',
- 'value' => _t('_bx_tasks_form_pv_input_cancel'),
- 'attrs' => [
- 'onclick' => "$('.bx-popup-applied:visible').dolPopupHide()",
- 'class' => 'bx-def-margin-sec-left',
- ],
- ]
- ]
- ]
- ];
- if($this->_aListInfo && (int)$this->_aListInfo['use_color'] == 0)
- unset($aForm['inputs']['color']);
- return new BxTemplFormView($aForm);
- }
- protected function _getIds()
- {
- if(($aIds = bx_get('ids')) && is_array($aIds))
- return reset($aIds);
- if(($iId = bx_get('id')) !== false)
- return (int)$iId;
- return false;
- }
- }
- /** @} */
|