Exemple #1
0
 public function registerClientScript()
 {
     $view = $this->getView();
     if ($this->gallery) {
         GalleryAsset::register($view);
     }
     FileUploadUIAsset::register($view);
     $options = Json::encode($this->clientOptions);
     $id = isset($this->clientOptions['formId']) ? $this->clientOptions['formId'] : $this->options['id'];
     $js[] = ";jQuery('#{$id}').fileupload({$options});";
     if (!empty($this->clientEvents)) {
         foreach ($this->clientEvents as $event => $handler) {
             $js[] = "jQuery('#{$id}').on('{$event}', {$handler});";
         }
     }
     $view->registerJs(implode("\n", $js));
 }
 /**
  * Registers required script for the plugin to work as jQuery File Uploader UI
  */
 public function registerClientScript()
 {
     $view = $this->getView();
     if ($this->gallery) {
         GalleryAsset::register($view);
     }
     FileUploadUIAsset::register($view);
     $options = Json::encode($this->clientOptions);
     $id = $this->options['id'];
     $js[] = ";jQuery('#{$id}').fileupload({$options});";
     if (!empty($this->clientEvents)) {
         foreach ($this->clientEvents as $event => $handler) {
             $js[] = "jQuery('#{$id}').on('{$event}', {$handler});";
         }
     }
     $view->registerJs(implode("\n", $js));
     if ($this->load) {
         $view->registerJs("\n                \$('#{$id}').addClass('fileupload-processing');\n                \$.ajax({\n                    url: \$('#{$id}').fileupload('option', 'url'),\n                    dataType: 'json',\n                    context: \$('#{$id}')[0]\n                }).always(function () {\n                    \$(this).removeClass('fileupload-processing');\n                }).done(function (result) {\n                    \$(this).fileupload('option', 'done').call(this, \$.Event('done'), {result: result});\n                });\n            ");
     }
 }