HCE Project DC service web UI  0.2
Hierarchical Cluster Engine DC service web UI
 All Classes Namespaces Files Functions Variables Pages
TbJsonPickerColumn.php
Go to the documentation of this file.
1 <?php
19 {
23  public $class = 'picker';
24 
33  public $pickerOptions = array();
34 
38  public function init()
39  {
40  if (!$this->class) {
41  $this->class = 'picker';
42  }
43  $this->registerClientScript();
44  }
45 
54  public function renderDataCellContent($row, $data)
55  {
56 
57  if ($this->value !== null) {
58  $value = $this->evaluateExpression($this->value, array('data' => $data, 'row' => $row));
59  } else if ($this->name !== null) {
60  $value = CHtml::value($data, $this->name);
61  }
62 
63  $class = preg_replace('/\s+/', '.', $this->class);
64  $value = !isset($value) ? $this->grid->nullDisplay : $this->grid->getFormatter()->format($value, $this->type);
65  $value = CHtml::link($value, '#', array('class' => $class));
66 
67  if ($this->grid->json) {
68  return $value;
69  }
70  echo $value;
71  return;
72  }
73 
77  public function registerClientScript()
78  {
80  $cs = Yii::app()->getClientScript();
81 
82  $cs->registerPackage('picker');
83 
84  $pickerOptions = CJavaScript::encode($this->pickerOptions);
85  $gridId = $this->grid->id;
86  $class = preg_replace('/\s+/', '.', $this->class);
87 
88  // Registering script to properly open *only* the picker for which corresponding toggler was clicked,
89  // and close all other pickers.
90  $cs->registerScript(
91  __CLASS__ . '#' . $this->id,
92  <<<ENDL
93 $(document).on('click','#{$gridId} a.{$class}', function() {
94  if ($(this).hasClass('pickeron')) {
95  $(this).removeClass('pickeron').picker('toggle');
96  return;
97  }
98  $('#{$gridId} a.pickeron')
99  .removeClass('pickeron')
100  .each(function (i, elem) {
101  $(elem).picker('toggle');
102  });
103  $(this)
104  .picker({$pickerOptions})
105  .picker('toggle').addClass('pickeron'); return false;
106 });
107 ENDL
108  );
109  }
110 
111 }