YiiWheels
  • Package
  • Class
  • Tree

Packages

  • None
  • yiiwheels
    • behaviors
    • widgets
    • widgets
      • ace
      • box
      • datepicker
      • daterangepicker
      • datetimepicker
      • detail
      • fileupload
      • fileuploader
      • gallery
      • google
      • grid
        • behaviors
        • operations
      • highcharts
      • maskInput
      • maskmoney
      • modal
      • multiselect
      • rangeslider
      • redactor
      • select2
      • sparklines
      • switch
      • timeago
      • timepicker
      • toggle
      • typeahead

Classes

  • WhBasicFileUpload
  • WhFileUpload
 1 <?php
 2 /**
 3  * WhBasicFileUpload widget class
 4  *
 5  * @author Antonio Ramirez <amigo.cobos@gmail.com>
 6  * @copyright Copyright &copy; 2amigos.us 2013-
 7  * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
 8  * @package YiiWheels.widgets.fileupload
 9  * @uses YiiStrap.helpers.TbArray
10  */
11 Yii::import('bootstrap.helpers.TbArray');
12 
13 class WhBasicFileUpload extends CInputWidget
14 {
15     /**
16      * Editor options that will be passed to the editor
17      * @see http://imperavi.com/redactor/docs/
18      */
19     public $pluginOptions = array();
20 
21     /**
22      * @var string upload action url
23      */
24     public $uploadAction;
25 
26     /**
27      * Widget's initialization method
28      * @throws CException
29      */
30     public function init()
31     {
32         if ($this->uploadAction === null) {
33             throw new CException(Yii::t('zii', '"uploadAction" attribute cannot be blank'));
34         }
35 
36         $this->attachBehavior('ywplugin', array('class' => 'yiiwheels.behaviors.WhPlugin'));
37     }
38 
39     /**
40      * Runs the widget.
41      */
42     public function run()
43     {
44         $this->renderField();
45         $this->registerClientScript();
46     }
47 
48     /**
49      * Renders the input file field
50      */
51     public function renderField()
52     {
53         list($name, $id) = $this->resolveNameID();
54 
55         TbArray::defaultValue('id', $id, $this->htmlOptions);
56         TbArray::defaultValue('name', $name, $this->htmlOptions);
57         $this->htmlOptions['data-url'] = $this->uploadAction;
58         $this->pluginOptions['url']    = $this->uploadAction;
59         if ($this->hasModel()) {
60             echo CHtml::activeFileField($this->model, $this->attribute, $this->htmlOptions);
61 
62         } else {
63             echo CHtml::fileField($name, $this->value, $this->htmlOptions);
64         }
65     }
66 
67     /**
68      * Registers client script
69      */
70     public function registerClientScript()
71     {
72         /* publish assets dir */
73         $path      = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'assets';
74         $assetsUrl = $this->getAssetsUrl($path);
75 
76         /* @var $cs CClientScript */
77         $cs = Yii::app()->getClientScript();
78 
79         $cs->registerCssFile($assetsUrl . '/css/jquery.fileupload-ui.css');
80         $cs->registerScriptFile($assetsUrl . '/js/vendor/jquery.ui.widget.js');
81         $cs->registerScriptFile($assetsUrl . '/js/jquery.iframe-transport.js');
82         $cs->registerScriptFile($assetsUrl . '/js/jquery.fileupload.js');
83 
84         /* initialize plugin */
85         $selector = '#' . TbArray::getValue('id', $this->htmlOptions, $this->getId());
86 
87         $this->getApi()->registerPlugin('fileupload', $selector, $this->pluginOptions);
88     }
89 
90 }
YiiWheels API documentation generated by ApiGen 2.8.0