14 Yii::import(
'zii.widgets.jui.CJuiInputWidget');
84 if ($this->uploadTemplate === null) {
85 $this->uploadTemplate =
"#template-upload";
88 if ($this->downloadTemplate === null) {
89 $this->downloadTemplate =
"#template-download";
92 if (!isset($this->htmlOptions[
'enctype'])) {
93 $this->htmlOptions[
'enctype'] =
'multipart/form-data';
105 list($name, $id) = $this->resolveNameID();
107 $this->htmlOptions[
'id'] = $this->
id.
'-'.($this->hasModel() ? get_class($this->model) :
'fileupload') .
'-form';
112 if (!isset($this->options[
'acceptFileTypes'])) {
114 if (isset($fileTypes)) {
115 $fileTypes = (preg_match(
':jpg:', $fileTypes) && !preg_match(
':jpe:', $fileTypes) ? preg_replace(
120 $this->options[
'acceptFileTypes'] =
'js:/(\.)(' . preg_replace(
':,:',
'|', $fileTypes) .
')$/i';
125 if (!isset($this->options[
'maxFileSize'])) {
127 if (isset($fileSize)) {
128 $this->options[
'maxFileSize'] = $fileSize;
132 if ($this->multiple) {
133 $this->htmlOptions[
"multiple"] =
true;
136 $this->render($this->uploadView);
137 $this->render($this->downloadView);
138 $this->render($this->formView, array(
'name' => $name,
'htmlOptions' => $this->htmlOptions));
140 if ($this->previewImages || $this->imageProcessing) {
141 $this->render($this->previewImagesView);
155 $booster->registerAssetCss(
'fileupload/jquery.fileupload-ui.css');
159 $booster->registerAssetJs(
'fileupload/vendor/jquery.ui.widget.js');
161 $booster->registerAssetJs(
"fileupload/tmpl.min.js", CClientScript::POS_END);
163 if ($this->previewImages || $this->imageProcessing) {
164 $booster->registerAssetJs(
"fileupload/load-image.min.js", CClientScript::POS_END);
165 $booster->registerAssetJs(
"fileupload/canvas-to-blob.min.js", CClientScript::POS_END);
167 $booster->registerAssetCss(
"bootstrap-image-gallery.min.css");
168 $booster->registerAssetJs(
"bootstrap-image-gallery.min.js", CClientScript::POS_END);
171 $booster->registerAssetJs(
'fileupload/jquery.iframe-transport.js');
172 $booster->registerAssetJs(
'fileupload/jquery.fileupload.js');
174 if ($this->imageProcessing) {
175 $booster->registerAssetJs(
'fileupload/jquery.fileupload-ip.js');
178 if ($this->previewImages) {
179 $booster->registerAssetJs(
'fileupload/jquery.fileupload-fp.js');
182 $booster->registerAssetJs(
'fileupload/jquery.fileupload-locale.js');
184 $booster->registerAssetJs(
'fileupload/jquery.fileupload-ui.js');
186 $options = CJavaScript::encode($this->options);
187 Yii::app()->clientScript->registerScript(__CLASS__ .
'#' . $id,
"jQuery('#{$id}').fileupload({$options});");
201 if (!isset($model, $attribute, $property)) {
205 foreach ($model->getValidators($attribute) as $validator) {
206 if ($validator instanceof CFileValidator) {
207 $ret = $validator->$property;
210 return isset($ret) ? $ret : null;