*/ WBClass::load('WBHtml_JS', 'WBUser'); /** * patForms Elemenbt: vfsselect * * Select files from VFS * * @version 0.2.0 * @package Wombat * @subpackage patForms */ class patForms_Element_Vfsselect extends patForms_Element { /** * Stores the name of the element - this is used mainly by the patForms * error management and should be set in every element class. * @var string */ public $elementName = 'Vfsfile'; /** * element type to create HTML output * @var array */ public $elementType = array("html" => "input"); /** * session * @var patSession_Storage */ private $sess; /** * session * @var WBVFS_File */ private $file; /** * set here which attributes you want to include in the element if you want to use * the {@link patForms_Element::convertDefinition2Attributes()} method to automatically * convert the values from your element definition into element attributes. * * @see patForms_Element::convertDefinition2Attribute() * @var array */ public $attributeDefinition = array( 'id' => array( 'required' => false, 'format' => 'string', 'outputFormats' => array(), ), 'name' => array( 'required' => true, 'format' => 'string', 'outputFormats' => array('html'), 'modifiers' => array('insertSpecials' => array()), ), 'type' => array( 'required' => false, 'format' => 'string', 'default' => 'file', 'outputFormats' => array(), ), 'default' => array( 'required' => false, 'format' => 'string', 'outputFormats' => array(), ), 'title' => array( 'required' => false, 'format' => 'string', 'outputFormats' => array('html'), 'modifiers' => array('insertSpecials' => array()), ), 'description' => array( 'required' => false, 'format' => 'string', 'outputFormats' => array(), 'modifiers' => array('insertSpecials' => array()), ), 'label' => array( 'required' => false, 'format' => 'string', 'outputFormats' => array(), ), 'display' => array( 'required' => false, 'format' => 'string', 'default' => 'yes', 'outputFormats' => array(), ), 'edit' => array( 'required' => false, 'format' => 'string', 'default' => 'yes', 'outputFormats' => array(), ), 'required' => array( 'required' => false, 'format' => 'string', 'default' => 'yes', 'outputFormats' => array(), ), 'value' => array( 'required' => false, 'format' => 'string', 'outputFormats' => array(''), ), 'style' => array( 'required' => false, 'outputFormats' => array('html'), 'format' => 'string', ), 'class' => array( 'required' => false, 'outputFormats' => array('html'), 'format' => 'string', ), 'onchange' => array( 'required' => false, 'format' => 'string', 'outputFormats' => array('html'), 'modifiers' => array('insertSpecials' => array() ), ), 'onmouseover' => array( 'required' => false, 'format' => 'string', 'outputFormats' => array('html'), 'modifiers' => array('insertSpecials' => array()), ), 'onmouseout' => array( 'required' => false, 'format' => 'string', 'outputFormats' => array('html'), 'modifiers' => array('insertSpecials' => array()), ), 'accesskey' => array( 'required' => false, 'format' => 'string', 'outputFormats' => array('html'), ), 'position' => array( 'required' => false, 'format' => 'int', 'outputFormats' => array(), ), 'tabindex' => array( 'required' => false, 'format' => 'int', 'outputFormats' => array('html'), ), 'format' => array( 'required' => false, 'format' => 'string', 'outputFormats' => array(), ), 'disabled' => array( 'required' => false, 'format' => 'string', 'default' => 'no', 'outputFormats' => array('html'), ), 'user' => array( 'required' => false, 'format' => 'string', 'outputFormats' => array(), ), 'chroot' => array( 'required' => false, 'format' => 'int', 'outputFormats' => array(), ), 'multiple' => array( 'required' => false, 'format' => 'string', 'outputFormats' => array( 'html' ), ), 'min' => array( 'required' => false, 'format' => 'int', 'outputFormats' => array(), ), 'max' => array( 'required' => false, 'format' => 'int', 'outputFormats' => array(), ), 'listformat' => array( 'required' => false, 'format' => 'string', 'default' => 'array', 'outputFormats' => array(), ), 'mimetype' => array( 'required' => false, 'format' => 'string', 'default' => '*/*', 'outputFormats' => array(), ), 'thumbnailsize' => array( 'required' => false, 'format' => 'string', 'default' => '50x50', 'outputFormats' => array(), ), ); /** * Initialize validation codes using gettext * * Overwrite this function to add element's error codes * * @return bool $success Always returns true. * @see $attributeDefaults */ public function loadValidatiorErrorCodes() { $this->validatorErrorCodes = array( 1 => patI18n::dgettext('wombat', 'This field is required, please complete it.'), // 2 => patI18n::dgettext('wombat', 'The values given for the element does not match any of the possible values.' ), 3 => patI18n::dgettext('wombat', 'You have to select at least [MIN] entries.' ), 4 => patI18n::dgettext('wombat', 'You may not select more than [MAX] entries.' ), ); return true; } /** * element creation method for the 'HTML' format in the 'default' form mode. * * @param mixed value of the element * @return mixed $element The element, or false if failed. */ public function serializeHtmlDefault($value) { $this->startSession(); $value = $this->normalizeValue($value); // editable or not? if (isset($this->attributes['edit']) && $this->attributes['edit'] == 'no') { return $this->serializeHtmlReadonly($value); } $id = $this->attributes['id']; WBHtml_JS::add('WB/Form'); WBHtml_JS::add('WB/Form/Element'); WBHtml_JS::add('WB/Form/Element/Vfsselect'); WBHtml_JS::add(sprintf('$("%s").selector = new WB.Form.Element.Vfsselect("%1$s", "file");', $id), WBHtml_JS::AREA_FOOT); $className = ''; if (isset($this->attributes['class']) && !empty($this->attributes['class'])) { $className = $this->attributes['class'] . ' '; } // control element $atts = $this->getAttributesFor('html'); $atts['onclick'] = "$('$id').selector.select(this, '[[PATH]]', '{CONTENT_PATH}');"; $atts['class'] = $className . 'control'; $control = $this->createTag('div', 'full', $atts, 'Datei(en) auswählen...'); // list element $atts = array(); $atts['class'] = $className . 'list'; $list = $this->createTag('div', 'opening', $atts) . $this->values2HtmlList($value) . $this->createTag('div', 'closing'); // surrounding box element $atts = array(); $atts['class'] = $className . 'vfsselect'; $box = $this->createTag('div', 'opening', $atts) . $control . $list . $this->createHiddenTag(implode(',', $value)) . $this->createTag('div', 'closing'); return $box; } private function values2HtmlList($value, $buttons = true) { $className = ''; if (isset($this->attributes['class']) && !empty($this->attributes['class'])) { $className = $this->attributes['class'] . ' '; } $list = array(); $id = $this->attributes['id']; $ts = '50x50'; if (isset($this->attributes['thumbnailsize']) && !empty($this->attributes['thumbnailsize'])) { $ts = $this->attributes['thumbnailsize']; } WBHtml_JS::add(sprintf('$("%s").selector.setThumbnailSize("%s");', $id, $ts), WBHtml_JS::AREA_FOOT); foreach ($value as $v) { if (empty($v)) { continue; } $file = $this->file->loadById($v); if (!$file->isOK()) { continue; } $o = $file->getObscureId(); $n = $file->getName(); $item = array(); $item[] = '