1
0

BxBaseStudioPage.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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($sHelp);
  73. $sHelp = $oTemplate->parseHtmlByName('page_caption_help_popup.html', array('content' => $sHelp));
  74. }
  75. $sActions = $this->getPageCaptionActions();
  76. if(($bActions = strlen($sActions)) > 0) {
  77. $sActions = $oFunctions->transBox($sActions);
  78. $sActions = $oTemplate->parseHtmlByName('page_caption_actions_popup.html', array('content' => $sActions));
  79. }
  80. $oTemplate->addInjection('injection_header', 'text', $sHelp . $sActions);
  81. //--- Menu Left ---//
  82. $aItems = array(
  83. 'back' => array(
  84. 'name' => 'back',
  85. 'icon' => 'th',
  86. 'link' => BX_DOL_URL_STUDIO . 'launcher.php',
  87. 'title' => '_adm_txt_back_to_launcher'
  88. )
  89. );
  90. bx_import('BxTemplStudioMenu');
  91. $oMenu = new BxTemplStudioMenu(array('template' => 'menu_top_toolbar.html', 'menu_items' => $aItems));
  92. $sMenuLeft = $oMenu->getCode();
  93. //--- Menu Right ---//
  94. $aItems = array();
  95. if($bHelp)
  96. $aItems['help'] = array(
  97. 'name' => 'help',
  98. 'icon' => 'question-sign',
  99. 'onclick' => BX_DOL_STUDIO_PAGE_JS_OBJECT . ".togglePopup('help', this)",
  100. 'title' => '_adm_txt_show_help'
  101. );
  102. if($bActions)
  103. $aItems['actions'] = array(
  104. 'name' => 'actions',
  105. 'icon' => 'cog',
  106. 'onclick' => BX_DOL_STUDIO_PAGE_JS_OBJECT . ".togglePopup('actions', this)",
  107. 'title' => '_adm_txt_show_help'
  108. );
  109. $oMenu = new BxTemplStudioMenu(array('template' => 'menu_top_toolbar.html', 'menu_items' => $aItems));
  110. $sMenuRight = $oMenu->getCode();
  111. $aTmplVars = array(
  112. 'menu_left' => $sMenuLeft,
  113. 'caption' => _t($this->aPage['caption']),
  114. 'menu_right' => $sMenuRight
  115. );
  116. return $oTemplate->parseHtmlByName('page_caption.html', $aTmplVars);
  117. }
  118. function getPageAttributes() {
  119. return '';
  120. }
  121. function getPageMenu($aMenu, $aMarkers = array()) {
  122. bx_import('BxTemplStudioMenu');
  123. $oMenu = new BxTemplStudioMenu(array('template' => 'menu_side.html', 'menu_items' => $aMenu));
  124. if(!empty($aMarkers))
  125. $oMenu->addMarkers($aMarkers);
  126. return $oMenu->getCode();
  127. }
  128. function getPageCode($bHidden = false) {}
  129. protected function getPageCaptionHelp() {
  130. $oTemplate = BxDolStudioTemplate::getInstance();
  131. $sContent = _t('_adm_txt_show_help_content_empty');
  132. return $oTemplate->parseHtmlByName('page_caption_help.html', array('content' => $sContent));
  133. }
  134. protected function getPageCaptionActions() {
  135. if(empty($this->aActions))
  136. return "";
  137. $aForm = array(
  138. 'form_attrs' => array(
  139. 'id' => 'adm-page-actions',
  140. 'name' => 'adm-page-actions',
  141. 'action' => '',
  142. 'method' => 'post',
  143. ),
  144. 'params' => array(),
  145. 'inputs' => array()
  146. );
  147. foreach($this->aActions as $aAction) {
  148. $aInput = array(
  149. 'type' => $aAction['type'],
  150. 'name' => $aAction['name'],
  151. 'caption' => _t($aAction['caption'])
  152. );
  153. switch($aAction['type']) {
  154. case 'switcher':
  155. $aInput['checked'] = $aAction['checked'];
  156. $aInput['attrs']['onchange'] = $aAction['onchange'];
  157. break;
  158. }
  159. $aForm['inputs'][$aInput['name']] = $aInput;
  160. }
  161. bx_import('BxTemplStudioFormView');
  162. $oForm = new BxTemplStudioFormView($aForm);
  163. return BxDolStudioTemplate::getInstance()->parseHtmlByName('page_caption_actions.html', array('content' => $oForm->getCode()));
  164. }
  165. /**
  166. *
  167. * Block Methods
  168. *
  169. */
  170. function getBlockCaption($aBlock) {
  171. if(empty($aBlock) || !is_array($aBlock))
  172. return '';
  173. $oTemplate = BxDolStudioTemplate::getInstance();
  174. $aTmplActions = array();
  175. if(isset($aBlock['actions']) && is_array($aBlock['actions']))
  176. foreach($aBlock['actions'] as $aAction) {
  177. $sCaption = _t($aAction['caption']);
  178. $aTmplActions[] = array(
  179. 'name' => $aAction['name'],
  180. 'url' => $aAction['url'],
  181. 'title' => $sCaption,
  182. 'bx_if:show_onclick' => array(
  183. 'condition' => $aAction['onclick'] != '',
  184. 'content' => array(
  185. 'onclick' => $aAction['onclick']
  186. )
  187. ),
  188. 'caption' => $sCaption
  189. );
  190. }
  191. $aTmplVars = array(
  192. 'caption' => _t($aBlock['caption']),
  193. 'bx_if:show_actions' => array(
  194. 'condition' => count($aTmplActions) > 0,
  195. 'content' => array(
  196. 'bx_repeat:actions' => $aTmplActions
  197. )
  198. ),
  199. );
  200. return $oTemplate->parseHtmlByName('block_caption.html', $aTmplVars);
  201. }
  202. function getBlockPanelTop($aBlock) {
  203. if(empty($aBlock) || !is_array($aBlock))
  204. return '';
  205. $oTemplate = BxDolStudioTemplate::getInstance();
  206. $aTmplVars = array(
  207. 'content' => isset($aBlock['panel_top']) ? $aBlock['panel_top'] : ''
  208. );
  209. return $oTemplate->parseHtmlByName('block_panel_top.html', $aTmplVars);
  210. }
  211. function getBlockPanelBottom($aBlock) {
  212. if(empty($aBlock) || !is_array($aBlock))
  213. return '';
  214. $oTemplate = BxDolStudioTemplate::getInstance();
  215. $aTmplVars = array(
  216. 'content' => isset($aBlock['panel_bottom']) ? $aBlock['panel_bottom'] : ''
  217. );
  218. return $oTemplate->parseHtmlByName('block_panel_bottom.html', $aTmplVars);
  219. }
  220. protected function getJsResult($sMessage, $bTranslate = true, $bRedirect = false, $sRedirect = '', $sOnResult = '') {
  221. $aResult = array();
  222. $aResult['message'] = $bTranslate ? _t($sMessage) : $sMessage;
  223. if($bRedirect)
  224. $aResult['redirect'] = $sRedirect != '' ? $sRedirect : BX_DOL_URL_STUDIO;
  225. if(!empty($sOnResult))
  226. $aResult['on_result'] = $sOnResult;
  227. $oJson = new Services_JSON();
  228. $sResult = "window.parent." . BX_DOL_STUDIO_PAGE_JS_OBJECT . ".showMessage(" . $oJson->encode($aResult) . ");";
  229. return BxDolStudioTemplate::getInstance()->_wrapInTagJsCode($sResult);
  230. }
  231. }
  232. /** @} */