BxBaseStudioPage.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. <?php
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup DolphinView Dolphin Studio Representation classes
  7. * @ingroup DolphinStudio
  8. * @{
  9. */
  10. defined('BX_DOL') or die('hack attempt');
  11. bx_import('BxDolStudioPage');
  12. bx_import('BxDolStudioTemplate');
  13. bx_import('BxTemplStudioFunctions');
  14. require_once(BX_DIRECTORY_PATH_PLUGINS . 'Services_JSON.php');
  15. class BxBaseStudioPage extends BxDolStudioPage {
  16. function BxBaseStudioPage($mixedPageName) {
  17. parent::BxDolStudioPage($mixedPageName);
  18. }
  19. function getPageIndex() {
  20. if(!is_array($this->aPage) || empty($this->aPage))
  21. return BX_PAGE_DEFAULT;
  22. if(!$this->bPageMultiple)
  23. return !empty($this->aPage['index']) ? (int)$this->aPage['index'] : BX_PAGE_DEFAULT;
  24. else
  25. return !empty($this->aPage[$this->sPageSelected]['index']) ? (int)$this->aPage[$this->sPageSelected]['index'] : BX_PAGE_DEFAULT;
  26. }
  27. function getPageJs() {
  28. return array('common_anim.js', 'page.js');
  29. }
  30. function getPageJsClass() {
  31. return '';
  32. }
  33. function getPageJsObject() {
  34. return '';
  35. }
  36. function getPageJsCode($aOptions = array(), $bWrap = true) {
  37. $sJsClass = $this->getPageJsClass();
  38. $sJsObject = $this->getPageJsObject();
  39. if(empty($sJsClass) || empty($sJsObject))
  40. return '';
  41. $sOptions = '{}';
  42. if(!empty($aOptions)) {
  43. $oJson = new Services_JSON();
  44. $sOptions = $oJson->encode($aOptions);
  45. }
  46. $sContent = 'var ' . $sJsObject . ' = new ' . $sJsClass . '(' . $sOptions . ');';
  47. if($bWrap)
  48. $sContent = BxDolStudioTemplate::getInstance()->_wrapInTagJsCode($sContent);
  49. return $sContent;
  50. }
  51. function getPageCss() {
  52. $aCss = array('menu_top.css');
  53. if((int)$this->aPage['index'] == 3)
  54. $aCss[] = 'page_columns.css';
  55. return $aCss;
  56. }
  57. function getPageHeader() {
  58. if(empty($this->aPage) || !is_array($this->aPage))
  59. return '';
  60. return _t(!$this->bPageMultiple ? $this->aPage['caption'] : $this->aPage[$this->sPageSelected]['caption']);
  61. }
  62. function getPageBreadcrumb() {
  63. return array();
  64. }
  65. function getPageCaption() {
  66. if(empty($this->aPage) || !is_array($this->aPage))
  67. return '';
  68. $oTemplate = BxDolStudioTemplate::getInstance();
  69. $oFunctions = BxTemplStudioFunctions::getInstance();
  70. $sHelp = $this->getPageCaptionHelp();
  71. if(($bHelp = strlen($sHelp)) > 0)
  72. $sHelp = $oFunctions->transBox('bx-std-pcap-menu-popup-help', $sHelp, true);
  73. $sActions = $this->getPageCaptionActions();
  74. if(($bActions = strlen($sActions)) > 0)
  75. $sActions = $oFunctions->transBox('bx-std-pcap-menu-popup-actions', $sActions, true);
  76. $oTemplate->addInjection('injection_header', 'text', $sHelp . $sActions);
  77. //--- Menu Left ---//
  78. $aItems = array(
  79. 'back' => array(
  80. 'name' => 'back',
  81. 'icon' => 'th',
  82. 'link' => BX_DOL_URL_STUDIO . 'launcher.php',
  83. 'title' => '_adm_txt_back_to_launcher'
  84. )
  85. );
  86. bx_import('BxTemplStudioMenu');
  87. $oMenu = new BxTemplStudioMenu(array('template' => 'menu_top_toolbar.html', 'menu_items' => $aItems));
  88. $sMenuLeft = $oMenu->getCode();
  89. //--- Menu Right ---//
  90. $aItems = array();
  91. if($bHelp)
  92. $aItems['help'] = array(
  93. 'name' => 'help',
  94. 'icon' => 'question-circle',
  95. 'onclick' => BX_DOL_STUDIO_PAGE_JS_OBJECT . ".togglePopup('help', this)",
  96. 'title' => '_adm_txt_show_help'
  97. );
  98. if($bActions)
  99. $aItems['actions'] = array(
  100. 'name' => 'actions',
  101. 'icon' => 'cog',
  102. 'onclick' => BX_DOL_STUDIO_PAGE_JS_OBJECT . ".togglePopup('actions', this)",
  103. 'title' => '_adm_txt_show_help'
  104. );
  105. $oMenu = new BxTemplStudioMenu(array('template' => 'menu_top_toolbar.html', 'menu_items' => $aItems));
  106. $sMenuRight = $oMenu->getCode();
  107. $aTmplVars = array(
  108. 'menu_left' => $sMenuLeft,
  109. 'caption' => _t($this->aPage['caption']),
  110. 'menu_right' => $sMenuRight
  111. );
  112. return $oTemplate->parseHtmlByName('page_caption.html', $aTmplVars);
  113. }
  114. function getPageAttributes() {
  115. return '';
  116. }
  117. function getPageMenu($aMenu, $aMarkers = array()) {
  118. bx_import('BxTemplStudioMenu');
  119. $oMenu = new BxTemplStudioMenu(array('template' => 'menu_side.html', 'menu_items' => $aMenu));
  120. if(!empty($aMarkers))
  121. $oMenu->addMarkers($aMarkers);
  122. return $oMenu->getCode();
  123. }
  124. function getPageCode($bHidden = false) {}
  125. protected function getPageCaptionHelp() {
  126. $oTemplate = BxDolStudioTemplate::getInstance();
  127. $sContent = _t('_adm_txt_show_help_content_empty');
  128. return $oTemplate->parseHtmlByName('page_caption_help.html', array('content' => $sContent));
  129. }
  130. protected function getPageCaptionActions() {
  131. if(empty($this->aActions))
  132. return "";
  133. $aForm = array(
  134. 'form_attrs' => array(
  135. 'id' => 'adm-page-actions',
  136. 'name' => 'adm-page-actions',
  137. 'action' => '',
  138. 'method' => 'post',
  139. ),
  140. 'params' => array(),
  141. 'inputs' => array()
  142. );
  143. foreach($this->aActions as $aAction) {
  144. $aInput = array(
  145. 'type' => $aAction['type'],
  146. 'name' => $aAction['name'],
  147. 'caption' => _t($aAction['caption'])
  148. );
  149. switch($aAction['type']) {
  150. case 'switcher':
  151. $aInput['checked'] = $aAction['checked'];
  152. $aInput['attrs']['onchange'] = $aAction['onchange'];
  153. break;
  154. }
  155. $aForm['inputs'][$aInput['name']] = $aInput;
  156. }
  157. bx_import('BxTemplStudioFormView');
  158. $oForm = new BxTemplStudioFormView($aForm);
  159. return BxDolStudioTemplate::getInstance()->parseHtmlByName('page_caption_actions.html', array('content' => $oForm->getCode()));
  160. }
  161. /**
  162. *
  163. * Block Methods
  164. *
  165. */
  166. function getBlockCaption($aBlock) {
  167. if(empty($aBlock) || !is_array($aBlock))
  168. return '';
  169. $oTemplate = BxDolStudioTemplate::getInstance();
  170. $aTmplActions = array();
  171. if(isset($aBlock['actions']) && is_array($aBlock['actions']))
  172. foreach($aBlock['actions'] as $aAction) {
  173. $sCaption = _t($aAction['caption']);
  174. $aTmplActions[] = array(
  175. 'name' => $aAction['name'],
  176. 'url' => $aAction['url'],
  177. 'title' => $sCaption,
  178. 'bx_if:show_onclick' => array(
  179. 'condition' => $aAction['onclick'] != '',
  180. 'content' => array(
  181. 'onclick' => $aAction['onclick']
  182. )
  183. ),
  184. 'caption' => $sCaption
  185. );
  186. }
  187. $aTmplVars = array(
  188. 'caption' => _t($aBlock['caption']),
  189. 'bx_if:show_actions' => array(
  190. 'condition' => count($aTmplActions) > 0,
  191. 'content' => array(
  192. 'bx_repeat:actions' => $aTmplActions
  193. )
  194. ),
  195. );
  196. return $oTemplate->parseHtmlByName('block_caption.html', $aTmplVars);
  197. }
  198. function getBlockPanelTop($aBlock) {
  199. if(empty($aBlock) || !is_array($aBlock))
  200. return '';
  201. $oTemplate = BxDolStudioTemplate::getInstance();
  202. $aTmplVars = array(
  203. 'content' => isset($aBlock['panel_top']) ? $aBlock['panel_top'] : ''
  204. );
  205. return $oTemplate->parseHtmlByName('block_panel_top.html', $aTmplVars);
  206. }
  207. function getBlockPanelBottom($aBlock) {
  208. if(empty($aBlock) || !is_array($aBlock))
  209. return '';
  210. $oTemplate = BxDolStudioTemplate::getInstance();
  211. $aTmplVars = array(
  212. 'content' => isset($aBlock['panel_bottom']) ? $aBlock['panel_bottom'] : ''
  213. );
  214. return $oTemplate->parseHtmlByName('block_panel_bottom.html', $aTmplVars);
  215. }
  216. protected function getJsResult($sMessage, $bTranslate = true, $bRedirect = false, $sRedirect = '', $sOnResult = '') {
  217. $aResult = array();
  218. $aResult['message'] = $bTranslate ? _t($sMessage) : $sMessage;
  219. if($bRedirect)
  220. $aResult['redirect'] = $sRedirect != '' ? $sRedirect : BX_DOL_URL_STUDIO;
  221. if(!empty($sOnResult))
  222. $aResult['on_result'] = $sOnResult;
  223. $oJson = new Services_JSON();
  224. $sResult = "window.parent." . BX_DOL_STUDIO_PAGE_JS_OBJECT . ".showMessage(" . $oJson->encode($aResult) . ");";
  225. return BxDolStudioTemplate::getInstance()->_wrapInTagJsCode($sResult);
  226. }
  227. }
  228. /** @} */