| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- <?php defined('BX_DOL') or die('hack attempt');
- /**
- * Copyright (c) UNA, Inc - https://una.io
- * MIT License - https://opensource.org/licenses/MIT
- *
- * @defgroup Notifications Notifications
- * @ingroup UnaModules
- *
- * @{
- */
- class BxNtfsGridEtemplates extends BxTemplGrid
- {
- protected $_sModule;
- protected $_oModule;
- public function __construct ($aOptions, $oTemplate = false)
- {
- parent::__construct ($aOptions, $oTemplate);
- $this->_sModule = 'bx_notifications';
- $this->_oModule = BxDolModule::getInstance($this->_sModule);
- }
- public function getCode($isDisplayHeader = true)
- {
- $sResult = parent::getCode($isDisplayHeader);
- if(!$sResult)
- return $sResult;
- return $sResult . $this->_oModule->_oTemplate->getJsCode('main');
- }
- public function performActionAdd()
- {
- $sAction = 'add';
- $oForm = $this->_getFormObject($sAction);
- $oForm->initChecker();
- if($oForm->isSubmittedAndValid()) {
- if(($iId = $oForm->insert()) !== false)
- $aRes = ['grid' => $this->getCode(false), 'blink' => $iId];
- else
- $aRes = ['msg' => _t('_bx_ntfs_txt_err_cannot_perform')];
- echoJson($aRes);
- }
- else {
- $sContent = BxTemplFunctions::getInstance()->popupBox($this->_oModule->_oConfig->getHtmlIds('view', 'add_etemplate_popup'), _t('_bx_ntfs_grid_popup_title_ett_add'), $this->_oModule->_oTemplate->parseHtmlByName('etemplate_form.html', [
- 'style_prefix' => $this->_oModule->_oConfig->getPrefix('style'),
- 'form_id' => $oForm->aFormAttrs['id'],
- 'form' => $oForm->getCode(true),
- 'object' => $this->_sObject,
- 'action' => $sAction
- ]));
- echoJson(['popup' => ['html' => $sContent, 'options' => ['closeOnOuterClick' => false, 'removeOnClose' => true]]]);
- }
- }
- public function performActionEdit()
- {
- $sAction = 'edit';
- $iId = $this->_getId();
- $aEtemplate = $this->_oModule->_oDb->getEtemplates(['sample' => 'id', 'id' => $iId]);
- if(empty($aEtemplate) || !is_array($aEtemplate))
- return echoJson([]);
- $oForm = $this->_getFormObject($sAction, $aEtemplate);
- $oForm->initChecker($aEtemplate);
- if($oForm->isSubmittedAndValid()) {
- if($oForm->update($iId) !== false)
- $aRes = ['grid' => $this->getCode(false), 'blink' => $iId];
- else
- $aRes = ['msg' => _t('_bx_ntfs_txt_err_cannot_perform')];
- echoJson($aRes);
- }
- else {
- $sContent = BxTemplFunctions::getInstance()->popupBox($this->_oModule->_oConfig->getHtmlIds('view', 'edit_etemplate_popup'), _t('_bx_ntfs_grid_popup_title_ett_edit'), $this->_oModule->_oTemplate->parseHtmlByName('etemplate_form.html', [
- 'style_prefix' => $this->_oModule->_oConfig->getPrefix('style'),
- 'form_id' => $oForm->aFormAttrs['id'],
- 'form' => $oForm->getCode(true),
- 'object' => $this->_sObject,
- 'action' => $sAction
- ]));
- echoJson(['popup' => ['html' => $sContent, 'options' => ['closeOnOuterClick' => false, 'removeOnClose' => true]]]);
- }
- }
- public function performActionPreview()
- {
- $iId = $this->_getId();
- $aEtemplate = $this->_oModule->_oDb->getEtemplates(['sample' => 'id', 'id' => $iId]);
- if(empty($aEtemplate) || !is_array($aEtemplate))
- return echoJson([]);
- $aTemplate = BxDolEmailTemplates::getInstance()->parseTemplate('bx_notifications_new_event', [
- 'subject' => !empty($aEtemplate['subject']) ? $aEtemplate['subject'] : _t('_bx_ntfs_txt_new_event_subject', getParam('site_title')),
- 'content' => $aEtemplate['body']
- ]);
- $sContent = BxTemplFunctions::getInstance()->popupBox($this->_oModule->_oConfig->getHtmlIds('view', 'preview_etemplate_popup'), _t('_bx_ntfs_grid_popup_title_ett_preview'), $this->_oModule->_oTemplate->parseHtmlByName('etemplate_preview.html', [
- 'style_prefix' => $this->_oModule->_oConfig->getPrefix('style'),
- 'subject' => $aTemplate['Subject'],
- 'body' => $aTemplate['Body']
- ]));
- echoJson(['popup' => ['html' => $sContent, 'options' => ['closeOnOuterClick' => true, 'removeOnClose' => true]]]);
- }
- protected function _getCellType($mixedValue, $sKey, $aField, $aRow)
- {
- return parent::_getCellDefault($this->_oModule->_oTemplate->getTypeTitle($mixedValue), $sKey, $aField, $aRow);
- }
- protected function _getCellAction($mixedValue, $sKey, $aField, $aRow)
- {
- return parent::_getCellDefault($this->_oModule->_oTemplate->getActionTitle($mixedValue), $sKey, $aField, $aRow);
- }
- protected function _getActionsDisabledBehavior($aRow)
- {
- return false;
- }
- protected function _getFormObject($sAction, $aItem = [])
- {
- $CNF = &$this->_oModule->_oConfig->CNF;
- $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ETEMPLATE'], $CNF['OBJECT_FORM_ETEMPLATE_DISPLAY_' . strtoupper($sAction)]);
- $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . 'grid.php?o=' . $this->_sObject . '&a=' . $sAction;
- if(!empty($aItem['id']))
- $oForm->aFormAttrs['action'] .= '&id=' . $aItem['id'];
- if(($sK = 'type') && isset($oForm->aInputs[$sK])) {
- $oForm->aInputs[$sK] = array_merge($oForm->aInputs[$sK], [
- 'attrs' => [
- 'onchange' => $this->_oModule->_oConfig->getJsObject('main') . '.onChangeType(this)',
- ],
- 'values' => [
- ['key' => '', 'value' => _t('_sys_please_select')]
- ]
- ]);
- $aTypes = $this->_oModule->_oDb->getHandlerTypes();
- foreach($aTypes as $sType)
- $oForm->aInputs[$sK]['values'][] = ['key' => $sType, 'value' => $this->_oModule->_oTemplate->getTypeTitle($sType)];
- }
- if(($sK = 'action') && isset($oForm->aInputs[$sK])) {
- $oForm->aInputs[$sK] = array_merge($oForm->aInputs[$sK], [
- 'attrs' => [
- 'id' => $this->_oModule->_oConfig->getHtmlIds('main', 'field_action'),
- 'disabled' => 'disabled'
- ],
- 'values' => [
- ['key' => '', 'value' => _t('_sys_please_select')]
- ]
- ]);
- }
- if(($sK = 'body') && isset($oForm->aInputs[$sK]))
- $oForm->aInputs[$sK]['code'] = 1;
- return $oForm;
- }
- protected function _getId()
- {
- if(($aIds = bx_get('ids')) && is_array($aIds))
- return array_shift($aIds);
- return ($iId = bx_get('id')) !== false ? (int)$iId : false;
- }
- }
- /** @} */
|