1
0

BxBaseMenuMoreAuto.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. return $sResult;
  39. }
  40. protected function _isMoreAuto()
  41. {
  42. if(is_bool($this->_bMoreAuto))
  43. return $this->_bMoreAuto;
  44. $aResult = $this->getMenuItems();
  45. $sItem = BX_DEF_MENU_ITEM_MORE_AUTO;
  46. if(!empty($this->_aObject['menu_items'][$sItem]) && is_array($this->_aObject['menu_items'][$sItem]) && (int)$this->_aObject['menu_items'][$sItem]['active'] == 1)
  47. $this->_bMoreAuto = true;
  48. else
  49. $this->_bMoreAuto = false;
  50. return $this->_bMoreAuto;
  51. }
  52. protected function _getTemplateVars()
  53. {
  54. $bMoreAuto = $this->_isMoreAuto();
  55. $aResult = array_merge(parent::_getTemplateVars(), array(
  56. 'html_id' => $this->_getHtmlIdMain(),
  57. 'bx_if:show_more_auto_class' => array(
  58. 'condition' => $bMoreAuto,
  59. 'content' => array()
  60. ),
  61. 'js_code' => $bMoreAuto ? $this->_getJsCodeMoreAuto() : ''
  62. ));
  63. return $aResult;
  64. }
  65. protected function _getJsCodeMoreAuto()
  66. {
  67. $sJsObject = $this->_getJsObjectMoreAuto();
  68. $aJsParams = array(
  69. 'sObject' => $this->_sObject,
  70. 'iItemsStatic' => $this->_iMoreAutoItemsStatic,
  71. 'aHtmlIds' => $this->_getHtmlIds()
  72. );
  73. return $this->_oTemplate->_wrapInTagJsCode("if(!" . $sJsObject . ") {var " . $sJsObject . " = new BxDolMenuMoreAuto(" . json_encode($aJsParams) . "); " . $sJsObject . ".init();}");
  74. }
  75. protected function _getMenuItem ($aItem)
  76. {
  77. $aItem['popup'] = '';
  78. if($aItem['name'] != BX_DEF_MENU_ITEM_MORE_AUTO)
  79. return parent::_getMenuItem($aItem);
  80. $aItem['onclick'] = $this->_getJsObjectMoreAuto() . '.more(this);';
  81. $aItem['popup'] = BxTemplFunctions::getInstance()->transBox($this->_aHtmlIds['more_auto_popup'], $this->_oTemplate->parseHtmlByName($this->_getTmplNameItemMorePopup(), array(
  82. 'content' => ''
  83. )), true);
  84. return parent::_getMenuItem($aItem);
  85. }
  86. protected function _getHtmlIds()
  87. {
  88. return $this->_aHtmlIds;
  89. }
  90. protected function _getHtmlIdMain()
  91. {
  92. return $this->_aHtmlIds['main'];
  93. }
  94. protected function _getJsObjectMoreAuto()
  95. {
  96. return $this->_sJsObjectMoreAuto;
  97. }
  98. protected function _getTmplNameItemMore()
  99. {
  100. return $this->_sTmplNameItemMore;
  101. }
  102. protected function _getTmplNameItemMorePopup()
  103. {
  104. return $this->_sTmplNameItemMorePopup;
  105. }
  106. }
  107. /** @} */