YiiWheels
  • Package
  • Class
  • Tree

Packages

  • None
  • yiiwheels
    • behaviors
    • widgets
    • widgets
      • ace
      • box
      • datepicker
      • daterangepicker
      • datetimepicker
      • detail
      • fileupload
      • fileuploader
      • gallery
      • google
      • grid
        • behaviors
        • operations
      • highcharts
      • maskInput
      • maskmoney
      • modal
      • multiselect
      • rangeslider
      • redactor
      • select2
      • sparklines
      • switch
      • timeago
      • timepicker
      • toggle
      • typeahead

Classes

  • WhMaskMoney
 1 <?php
 2 /**
 3  * WhMaskMoney widget class
 4  *
 5  * @author Antonio Ramirez <amigo.cobos@gmail.com>
 6  * @copyright Copyright &copy; 2amigos.us 2013-
 7  * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
 8  * @package YiiWheels.widgets.maskmoney
 9  * @uses YiiStrap.helpers.TbArray
10  */
11 
12 Yii::import('bootstrap.helpers.TbArray');
13 
14 class WhMaskMoney extends CInputWidget
15 {
16 
17     /**
18      * @var array the plugin options
19      */
20     public $pluginOptions;
21 
22     /**
23      * Initializes the widget.
24      */
25     public function init()
26     {
27         $this->attachBehavior('ywplugin', array('class' => 'yiiwheels.behaviors.WhPlugin'));
28     }
29 
30     /**
31      * Runs the widget.
32      */
33     public function run()
34     {
35         $this->renderField();
36         $this->registerClientScript();
37     }
38 
39     /**
40      * Renders the the input field
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      * Registers required client script for maskmoney plugin.
58      */
59     public function registerClientScript()
60     {
61         /* publish assets dir */
62         $path      = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'assets';
63         $assetsUrl = $this->getAssetsUrl($path);
64 
65         /* @var $cs CClientScript */
66         $cs = Yii::app()->getClientScript();
67 
68         $cs->registerScriptFile($assetsUrl . '/js/jquery.maskmoney.js');
69 
70         /* initialize plugin */
71         $selector = '#' . TbArray::getValue('id', $this->htmlOptions, $this->getId());
72 
73         $this->getApi()->registerPlugin('maskMoney', $selector, $this->pluginOptions);
74     }
75 }
YiiWheels API documentation generated by ApiGen 2.8.0