1 <?php
2 3 4 5 6 7 8 9 10
11
12 Yii::import('bootstrap.helpers.TbArray');
13
14 class WhMaskMoney extends CInputWidget
15 {
16
17 18 19
20 public $pluginOptions;
21
22 23 24
25 public function init()
26 {
27 $this->attachBehavior('ywplugin', array('class' => 'yiiwheels.behaviors.WhPlugin'));
28 }
29
30 31 32
33 public function run()
34 {
35 $this->renderField();
36 $this->registerClientScript();
37 }
38
39 40 41
42 public function renderField()
43 {
44 list($name, $id) = $this->resolveNameID();
45
46 TbArray::defaultValue('id', $id, $this->htmlOptions);
47 TbArray::defaultValue('name', $name, $this->htmlOptions);
48
49 if ($this->hasModel()) {
50 echo CHtml::activeTextField($this->model, $this->attribute, $this->htmlOptions);
51 } else {
52 echo CHtml::textField($this->name, $this->value, $this->htmlOptions);
53 }
54 }
55
56 57 58
59 public function registerClientScript()
60 {
61
62 $path = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'assets';
63 $assetsUrl = $this->getAssetsUrl($path);
64
65
66 $cs = Yii::app()->getClientScript();
67
68 $cs->registerScriptFile($assetsUrl . '/js/jquery.maskmoney.js');
69
70
71 $selector = '#' . TbArray::getValue('id', $this->htmlOptions, $this->getId());
72
73 $this->getApi()->registerPlugin('maskMoney', $selector, $this->pluginOptions);
74 }
75 }