BxBaseMenuMoreAuto.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 UnaBaseView UNA Base Representation Classes
  7. *
  8. * @{
  9. */
  10. define('BX_DEF_MENU_ITEM_MORE_AUTO', 'more-auto');
  11. class BxBaseMenuMoreAuto extends BxTemplMenu
  12. {
  13. protected $_sTmplNameItemMore;
  14. protected $_sTmplNameItemMorePopup;
  15. protected $_bMoreAuto;
  16. protected $_iMoreAutoItemsStatic;
  17. protected $_sJsObjectMoreAuto;
  18. protected $_aHtmlIds;
  19. public function __construct($aObject, $oTemplate = false)
  20. {
  21. parent::__construct($aObject, $oTemplate);
  22. $this->_sTmplNameItemMore = 'menu_item_more.html';
  23. $this->_sTmplNameItemMorePopup = 'menu_item_more_popup.html';
  24. $this->_bMoreAuto = null;
  25. $this->_iMoreAutoItemsStatic = 1;
  26. $this->_sJsObjectMoreAuto = 'oMenuMoreAuto' . bx_gen_method_name($this->_sObject);
  27. $sPrefix = str_replace('_', '-', $this->_sObject);
  28. $this->_aHtmlIds = array(
  29. 'main' => $sPrefix,
  30. 'more_auto_popup' => $sPrefix . '-ma-popup',
  31. );
  32. }
  33. public function getCode()
  34. {
  35. $sResult = parent::getCode();
  36. if($this->_isMoreAuto()) {
  37. $this->_oTemplate->addJs(array('BxDolMenuMoreAuto.js'));
  38. if(!empty($sResult))
  39. $sResult = $this->_oTemplate->parseHtmlByName('menu_more_auto.html', array(
  40. 'menu' => $sResult
  41. ));
  42. }
  43. return $sResult;
  44. }
  45. protected function _isMoreAuto()
  46. {
  47. if(is_bool($this->_bMoreAuto))
  48. return $this->_bMoreAuto;
  49. $aResult = $this->getMenuItems();
  50. $sItem = BX_DEF_MENU_ITEM_MORE_AUTO;
  51. if(!empty($this->_aObject['menu_items'][$sItem]) && is_array($this->_aObject['menu_items'][$sItem]) && (int)$this->_aObject['menu_items'][$sItem]['active'] == 1)
  52. $this->_bMoreAuto = true;
  53. else
  54. $this->_bMoreAuto = false;
  55. return $this->_bMoreAuto;
  56. }
  57. protected function _getTemplateVars()
  58. {
  59. $bMoreAuto = $this->_isMoreAuto();
  60. $aResult = array_merge(parent::_getTemplateVars(), array(
  61. 'html_id' => $this->_getHtmlIdMain(),
  62. 'bx_if:show_more_auto_class' => array(
  63. 'condition' => $bMoreAuto,
  64. 'content' => array()
  65. ),
  66. 'js_code' => $bMoreAuto ? $this->_getJsCodeMoreAuto() : ''
  67. ));
  68. return $aResult;
  69. }
  70. protected function _getJsCodeMoreAuto()
  71. {
  72. $sJsObject = $this->_getJsObjectMoreAuto();
  73. $aJsParams = array(
  74. 'sObject' => $this->_sObject,
  75. 'iItemsStatic' => $this->_iMoreAutoItemsStatic,
  76. 'aHtmlIds' => $this->_getHtmlIds()
  77. );
  78. return $this->_oTemplate->_wrapInTagJsCode("if(!" . $sJsObject . ") {var " . $sJsObject . " = new BxDolMenuMoreAuto(" . json_encode($aJsParams) . "); " . $sJsObject . ".init();}");
  79. }
  80. protected function _getMenuItem ($aItem)
  81. {
  82. $aItem['popup'] = '';
  83. if($aItem['name'] != BX_DEF_MENU_ITEM_MORE_AUTO)
  84. return parent::_getMenuItem($aItem);
  85. $aItem['onclick'] = $this->_getJsObjectMoreAuto() . '.more(this);';
  86. $aItem['popup'] = BxTemplFunctions::getInstance()->transBox($this->_aHtmlIds['more_auto_popup'], $this->_oTemplate->parseHtmlByName($this->_getTmplNameItemMorePopup(), array(
  87. 'content' => ''
  88. )), true);
  89. return parent::_getMenuItem($aItem);
  90. }
  91. protected function _getHtmlIds()
  92. {
  93. return $this->_aHtmlIds;
  94. }
  95. protected function _getHtmlIdMain()
  96. {
  97. return $this->_aHtmlIds['main'];
  98. }
  99. protected function _getJsObjectMoreAuto()
  100. {
  101. return $this->_sJsObjectMoreAuto;
  102. }
  103. protected function _getTmplNameItemMore()
  104. {
  105. return $this->_sTmplNameItemMore;
  106. }
  107. protected function _getTmplNameItemMorePopup()
  108. {
  109. return $this->_sTmplNameItemMorePopup;
  110. }
  111. }
  112. /** @} */