BxBaseStudioFormView.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <?php defined('BX_DOL') or die('hack attempt');
  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. bx_import('BxDolStudioForm');
  11. class BxBaseStudioFormView extends BxDolStudioForm {
  12. function __construct($aInfo, $oTemplate) {
  13. parent::__construct($aInfo, $oTemplate);
  14. }
  15. function addCssJs() {
  16. parent::addCssJs();
  17. $this->oTemplate->addJs(array(
  18. 'forms.js'
  19. ));
  20. }
  21. function genRow(&$aInput) {
  22. $sRow = '';
  23. switch($aInput['type']) {
  24. case 'image_uploader':
  25. $sRow = $this->genRowImageUploader($aInput);
  26. break;
  27. default:
  28. $sRow = parent::genRow($aInput);
  29. }
  30. return $sRow;
  31. }
  32. function genInput(&$aInput) {
  33. $sInput = '';
  34. switch($aInput['type']) {
  35. case 'text_translatable':
  36. $sInput = $this->genInputTranslatable($aInput, 'text');
  37. break;
  38. case 'textarea_translatable':
  39. $aInput['html'] = 0;
  40. $sInput = $this->genInputTranslatable($aInput, 'textarea');
  41. break;
  42. default:
  43. $sInput = parent::genInput($aInput);
  44. }
  45. return $sInput;
  46. }
  47. function genRowImageUploader(&$aInput) {
  48. $aTmplVarsPreview = array(
  49. 'bx_if:show_empty' => array(
  50. 'condition' => true,
  51. 'content' => array()
  52. ),
  53. 'bx_if:show_image' => array(
  54. 'condition' => false,
  55. 'content' => array()
  56. )
  57. );
  58. if(($iId = (int)$aInput['value']) != 0) {
  59. bx_import('BxDolStorage');
  60. $sStorage = isset($aInput['storage_object']) && $aInput['storage_object'] != '' ? $aInput['storage_object'] : BX_DOL_STORAGE_OBJ_IMAGES;
  61. $oStorage = BxDolStorage::getObjectInstance($sStorage);
  62. $sFileUrl = $oStorage->getFileUrlById($iId);
  63. if($sFileUrl !== false) {
  64. $aTmplVarsPreview['bx_if:show_empty']['condition'] = false;
  65. $aTmplVarsPreview['bx_if:show_image'] = array(
  66. 'condition' => true,
  67. 'content' => array(
  68. 'url' => $sFileUrl,
  69. 'bx_if:show_action_delete' => array(
  70. 'condition' => isset($aInput['ajax_action_delete']) && $aInput['ajax_action_delete'] != "",
  71. 'content' => array(
  72. 'action' => $aInput['ajax_action_delete']
  73. )
  74. )
  75. )
  76. );
  77. }
  78. }
  79. $sRow = '';
  80. $aInputPreview = array(
  81. 'type' => 'custom',
  82. 'name' => 'preview',
  83. 'caption' => isset($aInput['caption_preview']) ? $aInput['caption_preview'] : _t('_adm_txt_form_view_iu_preview'),
  84. 'content' => $this->oTemplate->parseHtmlByName('form_view_iu_preview.html', $aTmplVarsPreview)
  85. );
  86. $sRow .= $this->genRow($aInputPreview);
  87. $aInput['type'] = 'file';
  88. $sRow .= $this->genRow($aInput);
  89. return $sRow;
  90. }
  91. function genInputTranslatable(&$aInput, $sType = 'text') {
  92. $iValueLength = 20;
  93. $sInputIdPrefix = 'bx-form-input-';
  94. $aInputMethod = array('text' => 'genInputStandard', 'textarea' => 'genInputTextarea');
  95. $sInput = '';
  96. $sInputName = $aInput['name'];
  97. bx_import('BxTemplStudioFunctions');
  98. $oFunctions = BxTemplStudioFunctions::getInstance();
  99. bx_import('BxDolStudioLanguagesUtils');
  100. $oLanguage = BxDolStudioLanguagesUtils::getInstance();
  101. $sLanguage = $oLanguage->getCurrentLangName(false);
  102. $aLanguages = $oLanguage->getLanguagesInfo();
  103. $aStrings = $oLanguage->getLanguageString($aInput['value']);
  104. $aInput['type'] = 'hidden';
  105. $aInput['attrs'] = array(
  106. 'id' => $sInputIdPrefix . $aInput['name']
  107. );
  108. $sInput .= $this->genInputStandard($aInput);
  109. $aTmplVars = array();
  110. foreach($aLanguages as $aLanguage) {
  111. $bLanguage = $aLanguage['name'] == $sLanguage;
  112. $sValue = '';
  113. if(($bValue = key_exists($aLanguage['id'], $aStrings)) === true)
  114. $sValue = $aStrings[$aLanguage['id']]['string'];
  115. else if(isset($aInput['values'][$aLanguage['name']]))
  116. $sValue = $aInput['values'][$aLanguage['name']];
  117. $aInput['type'] = $sType;
  118. $aInput['name'] = $sInputName . '-' . $aLanguage['name'];
  119. $aInput['value'] = $sValue;
  120. $aInput['attrs'] = array(
  121. 'id' => $sInputIdPrefix . $aInput['name'],
  122. 'style' => !$bLanguage ? 'display:none;' : ''
  123. );
  124. $sInput .= $this->$aInputMethod[$sType]($aInput);
  125. $aTmplVarValue = array(
  126. 'condition' => $bValue,
  127. 'content' => array(
  128. 'value' => strmaxtextlen($sValue, $iValueLength)
  129. )
  130. );
  131. $aTmplVarMissing = array(
  132. 'condition' => !$bValue || empty($sValue),
  133. 'content' => array()
  134. );
  135. $aTmplVars[] = array(
  136. 'name' => $sInputName,
  137. 'lang_name' => $aLanguage['name'],
  138. 'lang_flag' => $aLanguage['icon'],
  139. 'lang_title' => $aLanguage['title'],
  140. 'bx_if:hide_active' => array(
  141. 'condition' => !$bLanguage,
  142. 'content' => array()
  143. ),
  144. 'bx_if:act_value' => $aTmplVarValue,
  145. 'bx_if:act_missing' => $aTmplVarMissing,
  146. 'bx_if:hide_passive' => array(
  147. 'condition' => $bLanguage,
  148. 'content' => array()
  149. ),
  150. 'bx_if:pas_value' => $aTmplVarValue,
  151. 'bx_if:pas_missing' => $aTmplVarMissing,
  152. );
  153. }
  154. $sPopup = $this->oTemplate->parseHtmlByName('form_view_translator.html', array('bx_repeat:languages' => $aTmplVars));
  155. $sPopup = $oFunctions->transBox('bx-form-field-translator-popup-' . $sInputName, $sPopup, true);
  156. $aLanguage = $oLanguage->getLanguageInfo($sLanguage);
  157. $sControl = $this->oTemplate->parseHtmlByName('form_view_translatable.html', array(
  158. 'flag' => $aLanguage['icon'],
  159. 'title' => $aLanguage['title'],
  160. 'name' => $sInputName,
  161. 'popup' => $sPopup
  162. ));
  163. return $sInput . $sControl;
  164. }
  165. }
  166. /** @} */