/**
  * Publishes and registers the necessary script files.
  * @param $id
  * @param $embeddedScript
  */
 protected function registerScripts($id, $embeddedScript)
 {
     $cs = Yii::app()->clientScript;
     $package = Yii::app()->clientScript->packages['pickadate'];
     Yii::app()->clientScript->packages['pickadate']['css'] = array("themes/{$this->theme}.css", "themes/{$this->theme}.date.css", "themes/{$this->theme}.time.css");
     if ($this->rtl) {
         Yii::app()->clientScript->packages['pickadate']['css'][] = "themes/rtl.css";
     }
     if (!empty($this->language)) {
         Yii::app()->clientScript->packages['pickadate']['js'][] = "translations/{$this->language}.js";
     }
     Bootstrap::getBootstrap()->registerPackage('pickadate');
     $cs->registerScript($id, $embeddedScript, CClientScript::POS_LOAD);
 }
 public function registerAssets()
 {
     $bootstrap = Bootstrap::getBootstrap();
     if ($this->type == 'date' || $this->type == 'combodate') {
         /** @var $widget TbDatePicker */
         $widget = Yii::app()->widgetFactory->createWidget($this->getOwner(), 'bootstrap.widgets.TbDatePicker', array('options' => isset($this->options['datepicker']) ? $this->options['datepicker'] : array()));
         $widget->registerLanguageScript();
     } elseif ($this->type == 'datetime') {
         $bootstrap->registerPackage('datetimepicker');
         /** @var $widget TbDateTimePicker */
         $widget = Yii::app()->widgetFactory->createWidget($this->getOwner(), 'bootstrap.widgets.TbDateTimePicker', array('options' => isset($this->options['datetimepicker']) ? $this->options['datetimepicker'] : array()));
         $widget->registerLanguageScript();
     }
     if ($this->type == 'combodate') {
         // include moment.js if needed
         $bootstrap->registerPackage('moment');
     } elseif ($this->type == 'select2') {
         //include select2 if needed
         $bootstrap->registerPackage('select2');
     }
     $bootstrap->registerPackage('x-editable');
     return;
     /* TODO original */
     $am = Yii::app()->getAssetManager();
     $cs = Yii::app()->getClientScript();
     $form = yii::app()->editable->form;
     $mode = $this->mode ? $this->mode : yii::app()->editable->defaults['mode'];
     // bootstrap
     if ($form === EditableConfig::FORM_BOOTSTRAP) {
         if ($bootstrap = yii::app()->getComponent('bootstrap')) {
             $bootstrap->registerCoreCss();
             $bootstrap->registerCoreScripts();
         } else {
             throw new CException('You need to setup Yii-bootstrap extension first.');
         }
         $assetsUrl = $am->publish(Yii::getPathOfAlias('editable.assets.bootstrap-editable'));
         $js = 'bootstrap-editable.js';
         $css = 'bootstrap-editable.css';
         // jqueryui
     } elseif ($form === EditableConfig::FORM_JQUERYUI) {
         if ($mode === EditableConfig::POPUP && Yii::getVersion() < '1.1.13') {
             throw new CException('jQuery UI editable popup supported from Yii 1.1.13+');
         }
         //register jquery ui
         $this->registerJQueryUI();
         $assetsUrl = $am->publish(Yii::getPathOfAlias('editable.assets.jqueryui-editable'));
         $js = 'jqueryui-editable.js';
         $css = 'jqueryui-editable.css';
         // plain jQuery
     } else {
         $assetsUrl = $am->publish(Yii::getPathOfAlias('editable.assets.jquery-editable'));
         $js = 'jquery-editable-poshytip.js';
         $css = 'jquery-editable.css';
         //publish & register poshytip for popup version
         if ($mode === EditableConfig::POPUP) {
             $poshytipUrl = $am->publish(Yii::getPathOfAlias('editable.assets.poshytip'));
             $cs->registerScriptFile($poshytipUrl . '/jquery.poshytip.js');
             $cs->registerCssFile($poshytipUrl . '/tip-yellowsimple/tip-yellowsimple.css');
         }
         //register jquery ui for datepicker
         if ($this->type == 'date' || $this->type == 'dateui') {
             $this->registerJQueryUI();
         }
     }
     //register assets
     $cs->registerCssFile($assetsUrl . '/css/' . $css);
     $cs->registerScriptFile($assetsUrl . '/js/' . $js, CClientScript::POS_END);
     //include moment.js for combodate
     if ($this->type == 'combodate') {
         $momentUrl = $am->publish(Yii::getPathOfAlias('editable.assets.moment'));
         $cs->registerScriptFile($momentUrl . '/moment.min.js');
     }
     //include select2 lib for select2 type
     if ($this->type == 'select2') {
         $select2Url = $am->publish(Yii::getPathOfAlias('editable.assets.select2'));
         $cs->registerScriptFile($select2Url . '/select2.min.js');
         $cs->registerCssFile($select2Url . '/select2.css');
     }
     //include bootstrap-datetimepicker
     if ($this->type == 'datetime') {
         $url = $am->publish(Yii::getPathOfAlias('editable.assets.bootstrap-datetimepicker'));
         $cs->registerScriptFile($url . '/js/bootstrap-datetimepicker.js');
         $cs->registerCssFile($url . '/css/datetimepicker.css');
     }
     //TODO: include locale for datepicker
     //may be do it manually?
     /*
     if ($this->type == 'date' && $this->language && substr($this->language, 0, 2) != 'en') {
          //todo: check compare dp locale name with yii's
          $localesUrl = Yii::app()->getAssetManager()->publish(Yii::getPathOfAlias('ext.editable.assets.js.locales'));
          Yii::app()->clientScript->registerScriptFile($localesUrl . '/bootstrap-datepicker.'. str_replace('_', '-', $this->language).'.js', CClientScript::POS_END);
     }
     */
 }
 public function registerLanguageScript()
 {
     if (isset($this->options['language']) && $this->options['language'] != 'en') {
         $file = 'locales/bootstrap-datetimepicker.' . $this->options['language'] . '.js';
         $booster = Bootstrap::getBootstrap();
         if (@file_exists(Yii::getPathOfAlias('booster.assets.bootstrap-datetimepicker') . '/js/' . $file)) {
             if ($booster->enableCdn) {
                 // Not in CDN yet
                 $booster->registerAssetJs('../bootstrap-datetimepicker' . '/js/' . $file);
             } else {
                 $booster->registerAssetJs('../bootstrap-datetimepicker' . '/js/' . $file);
             }
         }
     }
 }
 /**
  *### .registerClientScript()
  *
  * Registers required client script for bootstrap select2. It is not used through bootstrap->registerPlugin
  * in order to attach events if any
  *
  * @param $id
  *
  * @throws CException
  */
 public function registerClientScript($id)
 {
     if ($this->language) {
         Yii::app()->clientScript->packages['select2']['js'][1] = "js/i18n/{$this->language}.js";
     }
     Bootstrap::getBootstrap()->registerPackage('select2');
     if ($this->bootstrap) {
         Bootstrap::getBootstrap()->registerPackage('select2-bootstrap');
         $this->options['theme'] = 'bootstrap';
     }
     $options = !empty($this->options) ? CJavaScript::encode($this->options) : '';
     if (!empty($this->val)) {
         if (is_array($this->val)) {
             $value = $this->val['id'];
         } else {
             $value = $this->val;
         }
         $defValue = ".val('{$value}').trigger('change')";
     } else {
         $defValue = '';
     }
     if ($this->readonly) {
         $defValue .= ".prop('readonly', true)";
     } elseif ($this->disabled) {
         $defValue .= ".prop('disabled', true)";
     }
     ob_start();
     echo "jQuery('#{$id}').select2({$options})";
     foreach ($this->events as $event => $handler) {
         echo ".on('{$event}', " . CJavaScript::encode($handler) . ")";
     }
     if ($this->disableUnselect) {
         echo ".on('select2:unselecting', function(e) {\n\t\t\t\t\$(this).select2('val', '');\n\t\t\t\te.preventDefault();\n\t\t\t})";
     }
     echo $defValue;
     Yii::app()->getClientScript()->registerScript(__CLASS__ . '#' . $this->getId(), ob_get_clean() . ';');
 }
 /**
  *### .registerClientScript()
  *
  * Registers required client script for bootstrap datepicker. It is not used through bootstrap->registerPlugin
  * in order to attach events if any
  */
 public function registerClientScript()
 {
     Bootstrap::getBootstrap()->registerPackage('datepicker');
 }
 /**
  * Registers necessary client scripts.
  */
 public function registerClientScript()
 {
     $id = $this->getId();
     //filter out non visible buttons
     $buttons = array_filter($this->initToolbarButtons(), function ($btn) {
         return !isset($btn['visible']) || $btn['visible'] != false;
     });
     Bootstrap::getBootstrap()->registerPackage('datatables');
     if (!empty($buttons)) {
         Bootstrap::getBootstrap()->registerPackage('datatables-buttons');
     }
     $columnDefs = $this->initColumnsJS();
     $defaultOptions = array('buttons' => $buttons);
     $options = array_merge($defaultOptions, $this->options);
     $this->initClientScript($this->cssFiles, $this->jsFiles, $this->configurable, $this->registerJUI);
     $options = CJavaScript::encode($options);
     Yii::app()->getClientScript()->registerScript(__CLASS__ . '#' . $id, "jQuery('#{$id} table').DataTable({$options});");
 }
 public function registerLanguageScript()
 {
     $booster = Bootstrap::getBootstrap();
     if (isset($this->options['language']) && $this->options['language'] != 'en') {
         $filename = '/bootstrap-datepicker/js/locales/bootstrap-datepicker.' . $this->options['language'] . '.js';
         if (file_exists(Yii::getPathOfAlias('booster.assets') . $filename)) {
             if ($booster->enableCdn) {
                 Yii::app()->clientScript->registerScriptFile('//cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.2.0/js/locales/bootstrap-datepicker.' . $this->options['language'] . '.js', CClientScript::POS_HEAD);
             } else {
                 $booster->cs->registerScriptFile($booster->getAssetsUrl() . $filename, CClientScript::POS_HEAD);
             }
         }
     }
 }