EliteConf
 All Data Structures Namespaces Files Functions Variables Pages
JqGrid.php
Go to the documentation of this file.
1 <?php
2 
55 class jqgrid extends CWidget {
56 
57  public $coreCss = true;
58  public $coreJs = true;
59  public $forceCopyAssets = true;
60  public $options = array();
61  public $language = '';
62 
66  public $htmlOptions = array();
67 
71  protected $_assetsUrl;
72 
73  public function init() {
74  // Register the jqgrid path alias.
75  if (Yii::getPathOfAlias('jqgrid') === false)
76  Yii::setPathOfAlias('jqgrid', realpath(dirname(__FILE__) . '/'));
77 
78  if ($this->coreCss !== false)
79  $this->registerCoreCss();
80 
81  if ($this->coreJs !== false)
82  $this->registerCoreJs();
83  }
84 
88  public function registerCoreCss() {
89  $this->registerAssetCss('ui.jqgrid.css');
90  }
91 
97  public function registerAssetCss($cssFile, $media = '') {
98  Yii::app()->getClientScript()->registerCssFile($this->getAssetsUrl() . "/css/{$cssFile}", $media);
99  }
100 
104  public function registerCoreJs() {
105  $this->registerJS('jquery.jqGrid.js');
106  }
107 
113  public function registerJS($jsFile, $position = CClientScript::POS_HEAD) {
114  /* @var CClientScript $cs */
115  $cs = Yii::app()->getClientScript();
116  $cs->registerCoreScript('jquery');
117  $cs->registerCoreScript('jquery.ui');
118  $cs->registerScriptFile($this->getAssetsUrl() . "/js/{$jsFile}", $position);
119  }
120 
121  public function run() {
122  $id = $this->getId();
123  if (isset($this->htmlOptions['id']))
124  $id = $this->htmlOptions['id'];
125  else
126  $this->htmlOptions['id'] = $id;
127  echo '<table id="'.$id.'"></table>';
128  echo '<div id="pager"></div>';
129  $options = CJavaScript::encode($this->options);
130 
131  $cs = Yii::app()->getClientScript();
132  $cs->registerScript(__CLASS__ . '#' . $id, "$(function(){jQuery('#{$id}').jqGrid($options);})", CClientScript::POS_HEAD);
133  $cs->registerScriptFile($this->getAssetsUrl() . '/js/i18n/grid.locale-' . $this->language . '.js', CClientScript::POS_HEAD);
134  }
135 
140  public function getAssetsUrl() {
141  if (isset($this->_assetsUrl))
142  return $this->_assetsUrl;
143  else {
144  $assetsPath = Yii::getPathOfAlias('jqgrid.assets');
145  $assetsUrl = Yii::app()->assetManager->publish($assetsPath, false, -1, $this->forceCopyAssets);
146  return $this->_assetsUrl = $assetsUrl;
147  }
148  }
149 
150 }