Blame view

vendor/mihaildev/yii2-elfinder/InputFile.php 2.69 KB
ad2e91f7   Mihail   move multyparser ...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
  <?php
  /**
   * Date: 23.01.14
   * Time: 1:27
   */
  
  namespace mihaildev\elfinder;
  
  use Yii;
  use yii\helpers\Html;
  use yii\helpers\Json;
  use yii\widgets\InputWidget;
  
  
  
  class InputFile extends InputWidget{
  	public $language;
  
  	public $filter;
  
  	public $buttonTag = 'button';
  	public $buttonName = 'Browse';
  	public $buttonOptions = [];
  
  	protected $_managerOptions;
  
  	public $width = 'auto';
  	public $height = 'auto';
  
  	public $template = '{input}{button}';
  
  	public $controller = 'elfinder';
  
  	public $path; // work with PathController
  
  	public $multiple;
  
  	public function init()
  	{
  		parent::init();
  
  		if(empty($this->language))
  			$this->language = ElFinder::getSupportedLanguage(Yii::$app->language);
  
  		if(empty($this->buttonOptions['id']))
  			$this->buttonOptions['id'] = $this->options['id'].'_button';
  
  		$this->buttonOptions['type'] = 'button';
  
  		$managerOptions = [];
  		if(!empty($this->filter))
  			$managerOptions['filter'] = $this->filter;
  
  		$managerOptions['callback'] = $this->options['id'];
  
  		if(!empty($this->language))
  			$managerOptions['lang'] = $this->language;
  
  		if (!empty($this->multiple))
  			$managerOptions['multiple'] = $this->multiple;
  
  		if(!empty($this->path))
  			$managerOptions['path'] = $this->path;
  
  		$this->_managerOptions['url'] = ElFinder::getManagerUrl($this->controller, $managerOptions);
  		$this->_managerOptions['width'] = $this->width;
  		$this->_managerOptions['height'] = $this->height;
  		$this->_managerOptions['id'] = $this->options['id'];
  	}
  
  	/**
  	 * Runs the widget.
  	 */
  	public function run()
  	{
  		if ($this->hasModel()) {
  			$replace['{input}'] = Html::activeTextInput($this->model, $this->attribute, $this->options);
  		} else {
  			$replace['{input}'] = Html::textInput($this->name, $this->value, $this->options);
  		}
  
  		$replace['{button}'] = Html::tag($this->buttonTag,$this->buttonName, $this->buttonOptions);
  
  
  		echo strtr($this->template, $replace);
  
  		AssetsCallBack::register($this->getView());
  
  		if (!empty($this->multiple))
  			$this->getView()->registerJs("mihaildev.elFinder.register(" . Json::encode($this->options['id']) . ", function(files, id){ var _f = []; for (var i in files) { _f.push(files[i].url); } \$('#' + id).val(_f.join(', ')).trigger('change'); return true;}); $(document).on('click','#" . $this->buttonOptions['id'] . "', function(){mihaildev.elFinder.openManager(" . Json::encode($this->_managerOptions) . ");});");
  		else
  			$this->getView()->registerJs("mihaildev.elFinder.register(" . Json::encode($this->options['id']) . ", function(file, id){ \$('#' + id).val(file.url).trigger('change');; return true;}); $(document).on('click', '#" . $this->buttonOptions['id'] . "', function(){mihaildev.elFinder.openManager(" . Json::encode($this->_managerOptions) . ");});");
  	}
  }