Blame view

vendor/mihaildev/yii2-elfinder/ButtonWidget.php 2.14 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
  <?php
  /**
   * Date: 19.05.15
   * Time: 13:57
   *
   * This file is part of the MihailDev project.
   *
   * (c) MihailDev project <http://github.com/mihaildev/>
   *
   * For the full copyright and license information, please view the LICENSE
   * file that was distributed with this source code.
  */
  
  namespace mihaildev\elfinder;
  use yii\base\Widget;
  use yii\helpers\Html;
  use yii\helpers\Json;
  
  /**
   * Class ButtonWidget
   *
   * @package mihaildev\elfinder
   */
  class ButtonWidget extends Widget{
  	public $language;
  
  	public $filter;
  
  	public $tag = 'button';
  	public $name = 'Browse';
  	public $options = [];
  
  	protected $_managerOptions;
  
  	public $width = 'auto';
  	public $height = 'auto';
  
  	public $template = '{input}{button}';
  
  	public $controller = 'elfinder';
  
  	public $path; // work with PathController
  
  	public $callback;
  
  	public function init()
  	{
  		parent::init();
  
  		if(empty($this->language))
  			$this->language = ElFinder::getSupportedLanguage(\Yii::$app->language);
  
  		if(empty($this->options['id']))
  			$this->options['id'] = $this->getId();
  		else
  			$this->setId($this->options['id']);
  
  		$managerOptions = [];
  		if(!empty($this->filter))
  			$managerOptions['filter'] = $this->filter;
  
  		$managerOptions['callback'] = $this->getId()."_manager";
  
  		if(!empty($this->language))
  			$managerOptions['lang'] = $this->language;
  
  		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'] = $managerOptions['callback'];
  	}
  
  	public function run(){
  		AssetsCallBack::register($this->getView());
  
  		echo Html::tag($this->tag, $this->name, $this->options);
  
  		$this->getView()->registerJs("mihaildev.elFinder.register(" . Json::encode($this->_managerOptions['id']) . ", " . Json::encode($this->callback) . ");"); // register callback Function
  		$this->getView()->registerJs("\$(document).on('click', '#" . $this->options['id'] . "', function(){mihaildev.elFinder.openManager(" . Json::encode($this->_managerOptions) . ");});");//on click button open manager
  	}
  }