/**
* Runs the widget.
*/
public function run()
{
list($name, $id) = $this->resolveNameID();
$this->resolveId($id);
if ($this->hasModel()) {
$input = TbHtml::activeFileField($this->model, $this->attribute, $this->htmlOptions);
} else {
$input = TbHtml::fileField($name, $this->value, $this->htmlOptions);
}
echo TbHtml::tag('span', $this->buttonOptions, $this->label . ' ' . $input);
if ($this->assetPath !== false) {
$this->publishAssets($this->assetPath);
$this->registerCssFile('css/jquery.fileupload-ui.css');
if ($this->registerJs) {
$this->getClientScript()->registerCoreScript('jquery');
$this->registerScriptFile('js/vendor/jquery.ui.widget.js', CClientScript::POS_END);
$this->registerScriptFile('js/jquery.iframe-transport.js', CClientScript::POS_END);
$this->registerScriptFile('js/jquery.fileupload.js', CClientScript::POS_END);
}
}
if ($this->bindPlugin) {
TbArray::defaultValue('dataType', 'json', $this->pluginOptions);
$options = !empty($this->pluginOptions) ? CJavaScript::encode($this->pluginOptions) : '';
$script = <<<EOD
jQuery('#{$id}')
.fileupload({$options})
.prop('disabled', !jQuery.support.fileInput)
.parent().addClass(jQuery.support.fileInput ? undefined : 'disabled');
EOD;
$this->getClientScript()->registerScript(__CLASS__ . '#' . $id, $script);
}
}