1
0

BxBaseStudioFormView.php 6.8 KB

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