| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- <?php
- /**
- * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
- * CC-BY License - http://creativecommons.org/licenses/by/3.0/
- *
- * @defgroup DolphinView Dolphin Studio Representation classes
- * @ingroup DolphinStudio
- * @{
- */
- defined('BX_DOL') or die('hack attempt');
- bx_import('BxDolStudioForm');
- class BxBaseStudioFormView extends BxDolStudioForm {
- function BxBaseStudioFormView($aInfo, $oTemplate) {
- parent::BxDolStudioForm($aInfo, $oTemplate);
- }
- function addCssJs() {
- parent::addCssJs();
- $this->oTemplate->addJs(array(
- 'forms.js'
- ));
- }
- function genRow(&$aInput) {
- $sRow = '';
- switch($aInput['type']) {
- case 'image_uploader':
- $sRow = $this->genRowImageUploader($aInput);
- break;
- default:
- $sRow = parent::genRow($aInput);
- }
- return $sRow;
- }
- function genInput(&$aInput) {
- $sInput = '';
- switch($aInput['type']) {
- case 'text_translatable':
- $sInput = $this->genInputTranslatable($aInput, 'text');
- break;
- case 'textarea_translatable':
- $aInput['html'] = 0;
- $sInput = $this->genInputTranslatable($aInput, 'textarea');
- break;
- default:
- $sInput = parent::genInput($aInput);
- }
- return $sInput;
- }
- function genRowImageUploader(&$aInput) {
- $aTmplVarsPreview = array(
- 'bx_if:show_empty' => array(
- 'condition' => true,
- 'content' => array()
- ),
- 'bx_if:show_image' => array(
- 'condition' => false,
- 'content' => array()
- )
- );
- if(($iId = (int)$aInput['value']) != 0) {
- bx_import('BxDolStorage');
- $sStorage = isset($aInput['storage_object']) && $aInput['storage_object'] != '' ? $aInput['storage_object'] : BX_DOL_STORAGE_OBJ_IMAGES;
- $oStorage = BxDolStorage::getObjectInstance($sStorage);
- $sFileUrl = $oStorage->getFileUrlById($iId);
- if($sFileUrl !== false) {
- $aTmplVarsPreview['bx_if:show_empty']['condition'] = false;
- $aTmplVarsPreview['bx_if:show_image'] = array(
- 'condition' => true,
- 'content' => array(
- 'url' => $sFileUrl,
- 'bx_if:show_action_delete' => array(
- 'condition' => isset($aInput['ajax_action_delete']) && $aInput['ajax_action_delete'] != "",
- 'content' => array(
- 'action' => $aInput['ajax_action_delete']
- )
- )
- )
- );
- }
- }
- $sRow = '';
- $aInputPreview = array(
- 'type' => 'custom',
- 'name' => 'preview',
- 'caption' => isset($aInput['caption_preview']) ? $aInput['caption_preview'] : _t('_adm_txt_form_view_iu_preview'),
- 'content' => $this->oTemplate->parseHtmlByName('form_view_iu_preview.html', $aTmplVarsPreview)
- );
- $sRow .= $this->genRow($aInputPreview);
- $aInput['type'] = 'file';
- $sRow .= $this->genRow($aInput);
- return $sRow;
- }
- function genInputTranslatable(&$aInput, $sType = 'text') {
- $iValueLength = 20;
- $sInputIdPrefix = 'bx-form-input-';
- $aInputMethod = array('text' => 'genInputStandard', 'textarea' => 'genInputTextarea');
- $sInput = '';
- $sInputName = $aInput['name'];
- bx_import('BxTemplStudioFunctions');
- $oFunctions = BxTemplStudioFunctions::getInstance();
- bx_import('BxDolStudioLanguagesUtils');
- $oLanguage = BxDolStudioLanguagesUtils::getInstance();
- $sLanguage = $oLanguage->getCurrentLangName(false);
- $aLanguages = $oLanguage->getLanguagesInfo();
- $aStrings = $oLanguage->getLanguageString($aInput['value']);
- $aInput['type'] = 'hidden';
- $aInput['attrs'] = array(
- 'id' => $sInputIdPrefix . $aInput['name']
- );
- $sInput .= $this->genInputStandard($aInput);
- $aTmplVars = array();
- foreach($aLanguages as $aLanguage) {
- $bLanguage = $aLanguage['name'] == $sLanguage;
- $sValue = '';
- if(($bValue = key_exists($aLanguage['id'], $aStrings)) === true)
- $sValue = $aStrings[$aLanguage['id']]['string'];
- else if(isset($aInput['values'][$aLanguage['name']]))
- $sValue = $aInput['values'][$aLanguage['name']];
- $aInput['type'] = $sType;
- $aInput['name'] = $sInputName . '-' . $aLanguage['name'];
- $aInput['value'] = $sValue;
- $aInput['attrs'] = array(
- 'id' => $sInputIdPrefix . $aInput['name'],
- 'style' => !$bLanguage ? 'display:none;' : ''
- );
- $sInput .= $this->$aInputMethod[$sType]($aInput);
- $aTmplVarValue = array(
- 'condition' => $bValue,
- 'content' => array(
- 'value' => strmaxtextlen($sValue, $iValueLength)
- )
- );
- $aTmplVarMissing = array(
- 'condition' => !$bValue || empty($sValue),
- 'content' => array()
- );
- $aTmplVars[] = array(
- 'name' => $sInputName,
- 'lang_name' => $aLanguage['name'],
- 'lang_flag' => $aLanguage['icon'],
- 'lang_title' => $aLanguage['title'],
- 'bx_if:hide_active' => array(
- 'condition' => !$bLanguage,
- 'content' => array()
- ),
- 'bx_if:act_value' => $aTmplVarValue,
- 'bx_if:act_missing' => $aTmplVarMissing,
- 'bx_if:hide_passive' => array(
- 'condition' => $bLanguage,
- 'content' => array()
- ),
- 'bx_if:pas_value' => $aTmplVarValue,
- 'bx_if:pas_missing' => $aTmplVarMissing,
- );
- }
- $sPopup = $this->oTemplate->parseHtmlByName('form_view_translator.html', array('bx_repeat:languages' => $aTmplVars));
- $sPopup = $oFunctions->transBox('bx-form-field-translator-popup-' . $sInputName, $sPopup, true);
- $aLanguage = $oLanguage->getLanguageInfo($sLanguage);
- $sControl = $this->oTemplate->parseHtmlByName('form_view_translatable.html', array(
- 'flag' => $aLanguage['icon'],
- 'title' => $aLanguage['title'],
- 'name' => $sInputName,
- 'popup' => $sPopup
- ));
- return $sInput . $sControl;
- }
- }
- /** @} */
|