HCE Project DC service web UI  0.2
Hierarchical Cluster Engine DC service web UI
 All Classes Namespaces Files Functions Variables Pages
TbTags.php
Go to the documentation of this file.
1 <?php
18 class TbTags extends CInputWidget {
19 
26  public $form;
27 
34  public $suggestions = array();
35 
50  public $events = array(
51  // whenAddingTag (tag:string) : anything external you'd like to do with the tag
52  'whenAddingTag' => null,
53  // tagRemoved (tag:string) : find out which tag was removed by either presseing delete key or clicking the (x)
54  'tagRemoved' => null,
55  // definePopover (tag:string) : must return the popover content for the tag that is being added. (eg "Content for [tag]")
56  'definePopover' => null,
57  // excludes (tag:string) : returns true if you want the tag to be excluded, false if allowed
58  'exclude' => null,
59  // pressedReturn (e:triggering event)
60  'pressedReturn' => null,
61  // pressedDelete (e:triggering event)
62  'pressedDelete' => null,
63  // pressedDown (e:triggering event)
64  'pressedDown' => null,
65  // pressedUp (e:triggering event)
66  'pressedUp' => null,
67  );
68 
72  public $restrictTo;
73 
77  public $tagData = array();
78 
84  public $popoverData;
85 
89  public $exclude = array();
90 
95 
100  public $tagClass = 'btn-success';
101 
105  public $promptText = 'Please, type in your tags...';
106 
110  protected $options = array();
111 
117  public function init() {
118 
119  parent::init();
120 
121  $this->options = CMap::mergeArray(
122  array(
123  'suggestions' => $this->suggestions,
124  'restrictTo' => $this->restrictTo,
125  'exclude' => $this->exclude,
126  'displayPopovers' => $this->displayPopovers,
127  'tagClass' => $this->tagClass,
128  'tagData' => $this->tagData,
129  'popoverData' => $this->popoverData
130  ),
131  $this->options
132  );
133  }
134 
140  public function run() {
141 
142  list($name, $id) = $this->resolveNameID();
143 
144  $this->renderContent($id, $name);
145  $this->registerClientScript($id);
146  }
147 
158  public function renderContent($id, $name) {
159 
160  if ($this->hasModel()) {
161  if ($this->form) {
162  echo $this->form->hiddenField($this->model, $this->attribute);
163  } else {
164  echo CHtml::activeHiddenField($this->model, $this->attribute);
165  }
166 
167  } else {
168  echo CHtml::hiddenField($name, $this->value);
169  }
170 
171  $this->htmlOptions['id'] = 'tags_'.$id;
172  if(isset($this->htmlOptions['class']) && !empty($this->htmlOptions['class']))
173  $this->htmlOptions['class'] .= ' tag-list';
174  else
175  $this->htmlOptions['class'] = 'tag-list';
176 
177  echo CHtml::openTag('div', $this->htmlOptions);
178  echo "<div class='tags'></div>";
179  echo CHtml::closeTag('div');
180  }
181 
191  public function registerClientScript($id) {
192 
193  $booster = Booster::getBooster();
194  $booster->registerPackage('bootstrap-tags');
195 
196  $options = !empty($this->options) ? CJavaScript::encode($this->options) : '';
197 
198  Yii::app()->getClientScript()->registerScript(
199  __CLASS__ . '#' . $this->getId(),
200  "jQuery('#tags_{$id}').tags({$options});"
201  );
202  }
203 }