1
0

BxDevNavigationItems.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup Developer Developer
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxDevNavigationItems extends BxTemplStudioNavigationItems
  12. {
  13. protected $oModule;
  14. function __construct($aOptions, $oTemplate = false)
  15. {
  16. parent::__construct($aOptions, $oTemplate);
  17. $this->oModule = BxDolModule::getInstance('bx_developer');
  18. $this->sUrlPage = BX_DOL_URL_STUDIO . 'module.php?name=' . $this->oModule->_oConfig->getName() . '&page=navigation&nav_page=items';
  19. $this->sUrlViewItems = $this->sUrlPage . '&nav_module=%s&nav_set=%s';
  20. $sModule = bx_get('nav_module');
  21. if(!empty($sModule)) {
  22. $this->sModule = bx_process_input($sModule);
  23. $this->_aQueryAppend['module'] = $this->sModule;
  24. }
  25. $sSet = bx_get('nav_set');
  26. if(!empty($sSet)) {
  27. $this->sSet = bx_process_input($sSet);
  28. $this->_aQueryAppend['set'] = $this->sSet;
  29. }
  30. }
  31. public function performActionAdd()
  32. {
  33. $sAction = 'add';
  34. $sFormObject = $this->oModule->_oConfig->getObject('form_nav_item');
  35. $sFormDisplay = $this->oModule->_oConfig->getObject('form_display_nav_item_add');
  36. $oForm = BxDolForm::getObjectInstance($sFormObject, $sFormDisplay, $this->oModule->_oTemplate);
  37. $oForm->setId($sFormDisplay);
  38. $oForm->setAction(BX_DOL_URL_ROOT . 'grid.php?o=' . $this->_sObject . '&a=' . $sAction . '&set=' . $this->sSet);
  39. $this->fillInSelects($oForm->aInputs);
  40. $oForm->initChecker();
  41. if($oForm->isSubmittedAndValid()) {
  42. $aValsToAdd = [];
  43. $this->onSave($oForm, $aValsToAdd);
  44. if(($iId = (int)$oForm->insert($aValsToAdd)) != 0)
  45. $aRes = array('grid' => $this->getCode(false), 'blink' => $iId);
  46. else
  47. $aRes = array('msg' => _t('_bx_dev_nav_err_items_create'));
  48. echoJson($aRes);
  49. }
  50. else {
  51. $sContent = BxTemplStudioFunctions::getInstance()->popupBox('bx-dev-nav-item-create-popup', _t('_bx_dev_nav_txt_items_create_popup'), $this->_oTemplate->parseHtmlByName('nav_add_item.html', array(
  52. 'form_id' => $oForm->getId(),
  53. 'form' => $oForm->getCode(true),
  54. 'object' => $this->_sObject,
  55. 'action' => $sAction
  56. )));
  57. echoJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))));
  58. }
  59. }
  60. public function performActionEdit($bUpdateGrid = false)
  61. {
  62. $sAction = 'edit';
  63. $sFormObject = $this->oModule->_oConfig->getObject('form_nav_item');
  64. $sFormDisplay = $this->oModule->_oConfig->getObject('form_display_nav_item_edit');
  65. $aItem = $this->_getItem('getItems');
  66. if($aItem === false) {
  67. echoJson(array());
  68. exit;
  69. }
  70. $this->_prepareServiceEdit('addon', $aItem);
  71. $this->_prepareServiceEdit('visibility_custom', $aItem);
  72. $oForm = BxDolForm::getObjectInstance($sFormObject, $sFormDisplay, $this->oModule->_oTemplate);
  73. $oForm->setId($sFormDisplay);
  74. $oForm->setAction(BX_DOL_URL_ROOT . 'grid.php?o=' . $this->_sObject . '&a=' . $sAction . '&set=' . $this->sSet);
  75. $oForm->aInputs['controls'][0]['value'] = _t('_bx_dev_nav_btn_items_save');
  76. $this->fillInSelects($oForm->aInputs);
  77. $oForm->initChecker($aItem);
  78. if($oForm->isSubmittedAndValid()) {
  79. $this->_prepareServiceSave('addon', $oForm);
  80. $this->_prepareServiceSave('visibility_custom', $oForm);
  81. $this->onSave($oForm, $aItem);
  82. if($oForm->update($aItem['id']) !== false)
  83. $aRes = array('grid' => $this->getCode(false), 'blink' => $aItem['id']);
  84. else
  85. $aRes = array('msg' => _t('_bx_dev_nav_err_items_edit'));
  86. echoJson($aRes);
  87. }
  88. else {
  89. $sContent = BxTemplStudioFunctions::getInstance()->popupBox('bx-dev-nav-item-edit-popup', _t('_bx_dev_nav_txt_items_edit_popup', _t($aItem['title_system'])), $this->oModule->_oTemplate->parseHtmlByName('nav_add_item.html', array(
  90. 'form_id' => $oForm->getId(),
  91. 'form' => $oForm->getCode(true),
  92. 'object' => $this->_sObject,
  93. 'action' => $sAction
  94. )));
  95. echoJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))));
  96. }
  97. }
  98. protected function _prepareServiceEdit($sField, &$aItem)
  99. {
  100. if(empty($aItem[$sField]))
  101. return;
  102. $aItem[$sField] = BxDevFunctions::unserializeString($aItem[$sField]);
  103. }
  104. protected function _prepareServiceSave($sField, &$oForm)
  105. {
  106. $sValue = $oForm->getCleanValue($sField);
  107. $sValue = BxDevFunctions::serializeString($sValue);
  108. BxDolForm::setSubmittedValue($sField, $sValue, $oForm->aFormAttrs['method']);
  109. }
  110. protected function _getActionDelete ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  111. {
  112. return parent::_getActionDefault($sType, $sKey, $a, false, $isDisabled, $aRow);
  113. }
  114. protected function _isEditable(&$aRow)
  115. {
  116. return true;
  117. }
  118. protected function _isDeletable(&$aRow)
  119. {
  120. return true;
  121. }
  122. protected function onSave(&$oForm, &$aItem)
  123. {
  124. if(($sConfigApi = $oForm->getCleanValue('config_api')) && !$this->oModule->isValidJson($sConfigApi))
  125. BxDolForm::setSubmittedValue('config_api', '', $oForm->aFormAttrs['method']);
  126. }
  127. private function fillInSelects(&$aInputs)
  128. {
  129. $aInputs['module']['values'] = array_merge(array('' => _t('_bx_dev_nav_txt_select_module')), BxDolStudioUtils::getModules());
  130. $aInputs['module']['value'] = $this->sModule;
  131. $aInputs['set_name']['value'] = $this->sSet;
  132. $aInputs['hidden_on']['values'] = array(
  133. BX_DB_HIDDEN_PHONE => _t('_bx_dev_nav_txt_sys_items_hidden_on_phone'),
  134. BX_DB_HIDDEN_TABLET => _t('_bx_dev_nav_txt_sys_items_hidden_on_tablet'),
  135. BX_DB_HIDDEN_DESKTOP => _t('_bx_dev_nav_txt_sys_items_hidden_on_desktop'),
  136. BX_DB_HIDDEN_MOBILE => _t('_bx_dev_nav_txt_sys_items_hidden_on_mobile')
  137. );
  138. $aInputs['hidden_on_pt']['values'] = [];
  139. $aPageTypes = BxDolPageQuery::getPageTypes();
  140. foreach($aPageTypes as $aPageType) {
  141. $iPageType = (int)$aPageType['id'];
  142. if($iPageType == 1)
  143. continue;
  144. $aInputs['hidden_on_pt']['values'][$iPageType - 1] = _t($aPageType['title']);
  145. }
  146. $aInputs['hidden_on_col']['values'] = [
  147. 1 => _t('_adm_nav_txt_block_hidden_on_col_thin'),
  148. 2 => _t('_adm_nav_txt_block_hidden_on_col_half'),
  149. 3 => _t('_adm_nav_txt_block_hidden_on_col_wide'),
  150. 4 => _t('_adm_nav_txt_block_hidden_on_col_full')
  151. ];
  152. if(($sKey = 'config_api') && isset($aInputs[$sKey]))
  153. $aInputs[$sKey] = array_merge($aInputs[$sKey], [
  154. 'code' => 1
  155. ]);
  156. }
  157. }
  158. /** @} */