From 31d9cbd9a1abe0ca679ba603150404b63f4d376b Mon Sep 17 00:00:00 2001 From: Tobias Munk Date: Wed, 22 May 2013 23:41:50 +0200 Subject: [PATCH 01/36] added run method to execute yii commands --- .../composer/yii/composer/InstallHandler.php | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/extensions/composer/yii/composer/InstallHandler.php b/extensions/composer/yii/composer/InstallHandler.php index 6d43abd..794ec24 100644 --- a/extensions/composer/yii/composer/InstallHandler.php +++ b/extensions/composer/yii/composer/InstallHandler.php @@ -9,10 +9,16 @@ namespace yii\composer; use Composer\Script\CommandEvent; +defined('YII_DEBUG') or define('YII_DEBUG', true); + +// fcgi doesn't have STDIN defined by default +defined('STDIN') or define('STDIN', fopen('php://stdin', 'r')); + /** * InstallHandler is called by Composer after it installs/updates the current package. * * @author Qiang Xue + * @author Tobias Munk * @since 2.0 */ class InstallHandler @@ -50,4 +56,31 @@ class InstallHandler } } } + + /** + * Executes a yii command. + * @param CommandEvent $event + */ + public static function run($event) + { + $options = array_merge(array( + 'run' => array(), + ), $event->getComposer()->getPackage()->getExtra()); + + $appPath = realpath(__DIR__ . '/../../../../..'); + + require($appPath . '/vendor/yiisoft/yii2/yii/Yii.php'); + require($appPath . '/vendor/autoload.php'); + $config = require($appPath . '/config/console.php'); + + foreach((array)$options['run'] as $params){ + $command = $params[0]; + unset($params[0]); + $params = array(); + // TODO: add params to array + echo "Running command: {$command}\n"; + $application = new \yii\console\Application($config); + $application->runAction($command, $params); + } + } } From d878520c38cc8d0459a3deab0599d764059beb74 Mon Sep 17 00:00:00 2001 From: Tobias Munk Date: Thu, 23 May 2013 00:04:06 +0200 Subject: [PATCH 02/36] fixed formatting --- extensions/composer/yii/composer/InstallHandler.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extensions/composer/yii/composer/InstallHandler.php b/extensions/composer/yii/composer/InstallHandler.php index 794ec24..961f39b 100644 --- a/extensions/composer/yii/composer/InstallHandler.php +++ b/extensions/composer/yii/composer/InstallHandler.php @@ -64,8 +64,8 @@ class InstallHandler public static function run($event) { $options = array_merge(array( - 'run' => array(), - ), $event->getComposer()->getPackage()->getExtra()); + 'run' => array(), + ), $event->getComposer()->getPackage()->getExtra()); $appPath = realpath(__DIR__ . '/../../../../..'); From 767d99c30bb8b7fc748304c057bf91dd74cf4e15 Mon Sep 17 00:00:00 2001 From: Luciano Baraglia Date: Thu, 23 May 2013 00:49:07 -0300 Subject: [PATCH 03/36] Fixing some outdated comments --- docs/guide/upgrade-from-v1.md | 8 +++++--- framework/yii/widgets/Menu.php | 1 - 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/guide/upgrade-from-v1.md b/docs/guide/upgrade-from-v1.md index cc0de73..b3d4411 100644 --- a/docs/guide/upgrade-from-v1.md +++ b/docs/guide/upgrade-from-v1.md @@ -216,12 +216,14 @@ Using a widget is more straightforward in 2.0. You mainly use the `begin()`, `en methods of the `Widget` class. For example, ```php -// $this refers to the View object // Note that you have to "echo" the result to display it echo \yii\widgets\Menu::widget(array('items' => $items)); -// $this refers to the View object -$form = \yii\widgets\ActiveForm::begin($this); +// Passing an array to initialize the object properties +$form = \yii\widgets\ActiveForm::begin(array( + 'options' => array('class' => 'form-horizontal'), + 'fieldConfig' => array('inputOptions' => array('class' => 'input-xlarge')), +)); ... form inputs here ... \yii\widgets\ActiveForm::end(); ``` diff --git a/framework/yii/widgets/Menu.php b/framework/yii/widgets/Menu.php index e76f11f..d63f202 100644 --- a/framework/yii/widgets/Menu.php +++ b/framework/yii/widgets/Menu.php @@ -26,7 +26,6 @@ use yii\helpers\Html; * The following example shows how to use Menu: * * ~~~ - * // $this is the view object currently being used * echo Menu::widget(array( * 'items' => array( * // Important: you need to specify url as 'controller/action', From ad878280afa65e353faae1012c893eabf5175b0f Mon Sep 17 00:00:00 2001 From: Antonio Ramirez Date: Thu, 23 May 2013 08:45:52 +0200 Subject: [PATCH 04/36] added collapse --- framework/yii/bootstrap/Collapse.php | 133 +++++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 framework/yii/bootstrap/Collapse.php diff --git a/framework/yii/bootstrap/Collapse.php b/framework/yii/bootstrap/Collapse.php new file mode 100644 index 0000000..d83df3c --- /dev/null +++ b/framework/yii/bootstrap/Collapse.php @@ -0,0 +1,133 @@ + array( + * // equivalent to the above + * 'Collapsible Group Item #1' => array( + * 'content' => 'Anim pariatur cliche...', + * // open its content by default + * 'contentOptions' => array('class'=>'in') + * ), + * // another group item + * 'Collapsible Group Item #2' => array( + * 'content' => 'Anim pariatur cliche...', + * 'contentOptions' => array(...), + * 'options' => array(...), + * ), + * ) + * )); + * ``` + * + * @see http://twitter.github.io/bootstrap/javascript.html#collapse + * @author Antonio Ramirez + * @since 2.0 + */ +class Collapse extends Widget +{ + /** + * @var array list of groups in the collapse widget. Each array element represents a single + * group with the following structure: + * + * ```php + * // item key is the actual group header + * 'Collapsible Group Item #1' => array( + * // required, the content (HTML) of the group + * 'content' => 'Anim pariatur cliche...', + * // optional the HTML attributes of the content group + * 'contentOptions'=> array(), + * // optional the HTML attributes of the group + * 'options'=> array(), + * ) + * ``` + */ + public $items = array(); + + + /** + * Initializes the widget. + */ + public function init() + { + parent::init(); + $this->addCssClass($this->options, 'accordion'); + } + + /** + * Renders the widget. + */ + public function run() + { + echo Html::beginTag('div', $this->options) . "\n"; + echo $this->renderItems() . "\n"; + echo Html::endTag('div') . "\n"; + $this->registerPlugin('collapse'); + } + + /** + * Renders collapsible items as specified on [[items]]. + * @return string the rendering result + */ + public function renderItems() + { + $items = array(); + $index = 0; + foreach ($this->items as $header => $item) { + $options = ArrayHelper::getValue($item, 'options', array()); + $this->addCssClass($options, 'accordion-group'); + $items[] = Html::tag('div', $this->renderItem($header, $item, ++$index), $options); + } + + return implode("\n", $items); + } + + /** + * Renders a single collapsible item group + * @param string $header a label of the item group [[items]] + * @param array $item a single item from [[items]] + * @param integer $index the item index as each item group content must have an id + * @return string the rendering result + * @throws InvalidConfigException + */ + public function renderItem($header, $item, $index) + { + if (isset($item['content'])) { + $id = $this->options['id'] . '-collapse' . $index; + $options = ArrayHelper::getValue($item, 'contentOptions', array()); + $options['id'] = $id; + $this->addCssClass($options, 'accordion-body collapse'); + + $header = Html::a($header, '#' . $id, array( + 'class' => 'accordion-toggle', + 'data-toggle' => 'collapse', + 'data-parent' => '#' . $this->options['id'] + )) . "\n"; + + $content = Html::tag('div', $item['content'], array('class' => 'accordion-inner')) . "\n"; + } else { + throw new InvalidConfigException('The "content" option is required.'); + } + $group = array(); + + $group[] = Html::tag('div', $header, array('class' => 'accordion-heading')); + $group[] = Html::tag('div', $content, $options); + + return implode("\n", $group); + } +} \ No newline at end of file From 68adc6117e42ad28e7026c7aae5d641354a1a780 Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Thu, 23 May 2013 12:38:42 +0400 Subject: [PATCH 05/36] Lowered PHP requirement to 5.3.7 --- framework/composer.json | 2 +- framework/yii/requirements/requirements.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/framework/composer.json b/framework/composer.json index 4ef6f89..2f0e85f 100644 --- a/framework/composer.json +++ b/framework/composer.json @@ -64,7 +64,7 @@ "source": "https://github.com/yiisoft/yii2" }, "require": { - "php": ">=5.3.11", + "php": ">=5.3.7", "ext-mbstring": "*", "lib-pcre": "*" }, diff --git a/framework/yii/requirements/requirements.php b/framework/yii/requirements/requirements.php index bc53c03..0dbc1fc 100644 --- a/framework/yii/requirements/requirements.php +++ b/framework/yii/requirements/requirements.php @@ -9,9 +9,9 @@ return array( array( 'name' => 'PHP version', 'mandatory' => true, - 'condition' => version_compare(PHP_VERSION, '5.3.11', '>='), + 'condition' => version_compare(PHP_VERSION, '5.3.7', '>='), 'by' => 'Yii Framework', - 'memo' => 'PHP 5.3.11 or higher is required.', + 'memo' => 'PHP 5.3.7 or higher is required.', ), array( 'name' => 'Reflection extension', From 8e6b427f60718d29c74f42358125860a59657e7a Mon Sep 17 00:00:00 2001 From: Tobias Munk Date: Thu, 23 May 2013 12:25:18 +0200 Subject: [PATCH 06/36] removed composer autoloading, since it's already active --- extensions/composer/yii/composer/InstallHandler.php | 1 - 1 file changed, 1 deletion(-) diff --git a/extensions/composer/yii/composer/InstallHandler.php b/extensions/composer/yii/composer/InstallHandler.php index 961f39b..0f121e6 100644 --- a/extensions/composer/yii/composer/InstallHandler.php +++ b/extensions/composer/yii/composer/InstallHandler.php @@ -70,7 +70,6 @@ class InstallHandler $appPath = realpath(__DIR__ . '/../../../../..'); require($appPath . '/vendor/yiisoft/yii2/yii/Yii.php'); - require($appPath . '/vendor/autoload.php'); $config = require($appPath . '/config/console.php'); foreach((array)$options['run'] as $params){ From f53b21758930c13432466b87ef4832bf83333e68 Mon Sep 17 00:00:00 2001 From: Tobias Munk Date: Thu, 23 May 2013 12:26:11 +0200 Subject: [PATCH 07/36] added parsing of anonymous params --- extensions/composer/yii/composer/InstallHandler.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/extensions/composer/yii/composer/InstallHandler.php b/extensions/composer/yii/composer/InstallHandler.php index 0f121e6..2b3661d 100644 --- a/extensions/composer/yii/composer/InstallHandler.php +++ b/extensions/composer/yii/composer/InstallHandler.php @@ -8,6 +8,7 @@ namespace yii\composer; use Composer\Script\CommandEvent; +use yii\console; defined('YII_DEBUG') or define('YII_DEBUG', true); @@ -72,11 +73,13 @@ class InstallHandler require($appPath . '/vendor/yiisoft/yii2/yii/Yii.php'); $config = require($appPath . '/config/console.php'); - foreach((array)$options['run'] as $params){ - $command = $params[0]; - unset($params[0]); - $params = array(); - // TODO: add params to array + foreach ((array)$options['run'] as $rawParams) { + // TODO: we're doing about the same here like console\Request::resolve() + $command = $rawParams[0]; + unset($rawParams[0]); + $params[\yii\console\Request::ANONYMOUS_PARAMS] = $rawParams; + // TODO end + echo "Running command: {$command}\n"; $application = new \yii\console\Application($config); $application->runAction($command, $params); From 58ca27a473c39349e78ba5fc5a213bdbf22f496a Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Thu, 23 May 2013 09:49:01 -0400 Subject: [PATCH 08/36] Refactored console Request. --- framework/yii/console/Request.php | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/framework/yii/console/Request.php b/framework/yii/console/Request.php index d1a6aa6..a9a4b03 100644 --- a/framework/yii/console/Request.php +++ b/framework/yii/console/Request.php @@ -15,9 +15,32 @@ class Request extends \yii\base\Request { const ANONYMOUS_PARAMS = '-args'; - public function getRawParams() + private $_params; + + /** + * Returns the command line arguments. + * @return array the command line arguments. It does not include the entry script name. + */ + public function getParams() + { + if (!isset($this->_params)) { + if (isset($_SERVER['argv'])) { + $this->_params = $_SERVER['argv']; + array_shift($this->_params); + } else { + $this->_params = array(); + } + } + return $this->_params; + } + + /** + * Sets the command line arguments. + * @param array $params the command line arguments + */ + public function setParams($params) { - return isset($_SERVER['argv']) ? $_SERVER['argv'] : array(); + $this->_params = $params; } /** @@ -26,9 +49,7 @@ class Request extends \yii\base\Request */ public function resolve() { - $rawParams = $this->getRawParams(); - array_shift($rawParams); // the 1st argument is the yii script name - + $rawParams = $this->getParams(); if (isset($rawParams[0])) { $route = $rawParams[0]; array_shift($rawParams); From e7c98a499e454e533110dd9c972df15043aa6d60 Mon Sep 17 00:00:00 2001 From: Tobias Munk Date: Thu, 23 May 2013 16:02:39 +0200 Subject: [PATCH 09/36] added configuration file detection from composer.json (extra.config), path cleanup --- extensions/composer/yii/composer/InstallHandler.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/extensions/composer/yii/composer/InstallHandler.php b/extensions/composer/yii/composer/InstallHandler.php index 2b3661d..6ac645a 100644 --- a/extensions/composer/yii/composer/InstallHandler.php +++ b/extensions/composer/yii/composer/InstallHandler.php @@ -66,12 +66,21 @@ class InstallHandler { $options = array_merge(array( 'run' => array(), + 'config' => null, ), $event->getComposer()->getPackage()->getExtra()); - $appPath = realpath(__DIR__ . '/../../../../..'); + // resolve and include config file + if (($options['config'] === null)) { + throw new console\Exception('Config file not specified in composer.json extra.config'); + } else { + if (!is_file(getcwd() . '/' . $options['config'])) { + throw new console\Exception("Config file '{$options['config']}' specified in composer.json extra.config not found"); + } else { + $config = require($options['config']); + } + } - require($appPath . '/vendor/yiisoft/yii2/yii/Yii.php'); - $config = require($appPath . '/config/console.php'); + require(__DIR__ . '/../../../yii2/yii/Yii.php'); foreach ((array)$options['run'] as $rawParams) { // TODO: we're doing about the same here like console\Request::resolve() From 03c2c1e0f114228b8fb175c368cc206357d33e39 Mon Sep 17 00:00:00 2001 From: Alexander Kochetov Date: Thu, 23 May 2013 18:33:43 +0400 Subject: [PATCH 10/36] YiiBase jQuery UI alias --- framework/yii/YiiBase.php | 1 + 1 file changed, 1 insertion(+) diff --git a/framework/yii/YiiBase.php b/framework/yii/YiiBase.php index df5f631..4fe0e77 100644 --- a/framework/yii/YiiBase.php +++ b/framework/yii/YiiBase.php @@ -616,6 +616,7 @@ class YiiBase YiiBase::$aliases = array( '@yii' => array( '@yii/bootstrap' => __DIR__ . '/bootstrap', + '@yii/jui' => __DIR__ . '/jui', '@yii' => __DIR__, ), ); From c4595b8b5d38dc08e7eb4064cea811ce9cf6bc49 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Thu, 23 May 2013 10:47:45 -0400 Subject: [PATCH 11/36] Fixes issue #337: support strict parsing for URL manager. --- framework/yii/web/UrlManager.php | 10 ++++++++++ tests/unit/framework/web/UrlManagerTest.php | 22 ++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/framework/yii/web/UrlManager.php b/framework/yii/web/UrlManager.php index dde10ee..5a3c391 100644 --- a/framework/yii/web/UrlManager.php +++ b/framework/yii/web/UrlManager.php @@ -27,6 +27,12 @@ class UrlManager extends Component */ public $enablePrettyUrl = false; /** + * @var boolean whether to enable strict parsing. If strict parsing is enabled, the incoming + * requested URL must match at least one of the [[rules]] in order to be treated as a valid request. + * This property is used only when [[enablePrettyUrl]] is true. + */ + public $enableStrictParsing = false; + /** * @var array the rules for creating and parsing URLs when [[enablePrettyUrl]] is true. * This property is used only if [[enablePrettyUrl]] is true. Each element in the array * is the configuration array for creating a single URL rule. The configuration will @@ -139,6 +145,10 @@ class UrlManager extends Component } } + if ($this->enableStrictParsing) { + return false; + } + $suffix = (string)$this->suffix; if ($suffix !== '' && $suffix !== '/' && $pathInfo !== '') { $n = strlen($this->suffix); diff --git a/tests/unit/framework/web/UrlManagerTest.php b/tests/unit/framework/web/UrlManagerTest.php index b6246c6..553b163 100644 --- a/tests/unit/framework/web/UrlManagerTest.php +++ b/tests/unit/framework/web/UrlManagerTest.php @@ -224,5 +224,27 @@ class UrlManagerTest extends \yiiunit\TestCase $request->pathInfo = 'site/index'; $result = $manager->parseRequest($request); $this->assertFalse($result); + + // strict parsing + $manager = new UrlManager(array( + 'enablePrettyUrl' => true, + 'enableStrictParsing' => true, + 'suffix' => '.html', + 'cache' => null, + 'rules' => array( + array( + 'pattern' => 'post//', + 'route' => 'post/view', + ), + ), + )); + // matching pathinfo + $request->pathInfo = 'post/123/this+is+sample.html'; + $result = $manager->parseRequest($request); + $this->assertEquals(array('post/view', array('id' => '123', 'title' => 'this+is+sample')), $result); + // unmatching pathinfo + $request->pathInfo = 'site/index.html'; + $result = $manager->parseRequest($request); + $this->assertFalse($result); } } From 9d3fe87230c26803c88f3d730924acb50c084a81 Mon Sep 17 00:00:00 2001 From: Alexander Kochetov <creocoder@gmail.com> Date: Thu, 23 May 2013 18:49:00 +0400 Subject: [PATCH 12/36] assets.php css dependency fixes --- framework/yii/jui/assets.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/framework/yii/jui/assets.php b/framework/yii/jui/assets.php index 1d27cee..c292050 100644 --- a/framework/yii/jui/assets.php +++ b/framework/yii/jui/assets.php @@ -775,7 +775,7 @@ return array( 'css' => array( 'themes/base/jquery.ui.autocomplete.css', ), - 'depends' => array('yii/jui/theme/base/core'), + 'depends' => array('yii/jui/theme/base/core', 'yii/jui/theme/base/menu'), ), 'yii/jui/theme/base/button' => array( 'sourcePath' => __DIR__ . '/assets', @@ -796,7 +796,7 @@ return array( 'css' => array( 'themes/base/jquery.ui.dialog.css', ), - 'depends' => array('yii/jui/theme/base/core'), + 'depends' => array('yii/jui/theme/base/core', 'yii/jui/theme/base/button', 'yii/jui/theme/base/resizeable'), ), 'yii/jui/theme/base/menu' => array( 'sourcePath' => __DIR__ . '/assets', @@ -838,7 +838,7 @@ return array( 'css' => array( 'themes/base/jquery.ui.spinner.css', ), - 'depends' => array('yii/jui/theme/base/core'), + 'depends' => array('yii/jui/theme/base/core', 'yii/jui/theme/base/button'), ), 'yii/jui/theme/base/tabs' => array( 'sourcePath' => __DIR__ . '/assets', From 792d548cd07f43d060f8a7e474264367f56169b8 Mon Sep 17 00:00:00 2001 From: Alexander Kochetov <creocoder@gmail.com> Date: Thu, 23 May 2013 19:28:34 +0400 Subject: [PATCH 13/36] jQuery Accordeon widget --- framework/yii/jui/Accordion.php | 107 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 framework/yii/jui/Accordion.php diff --git a/framework/yii/jui/Accordion.php b/framework/yii/jui/Accordion.php new file mode 100644 index 0000000..0deab15 --- /dev/null +++ b/framework/yii/jui/Accordion.php @@ -0,0 +1,107 @@ +<?php +/** + * @link http://www.yiiframework.com/ + * @copyright Copyright (c) 2008 Yii Software LLC + * @license http://www.yiiframework.com/license/ + */ + +namespace yii\jui; + +use yii\base\InvalidConfigException; +use yii\helpers\base\ArrayHelper; +use yii\helpers\Html; + +/** + * Accordion renders an accordion jQuery UI widget. + * + * For example: + * + * ```php + * echo Accordion::widget(array( + * 'items' => array( + * 'Section 1' => array( + * 'content' => 'Mauris mauris ante, blandit et, ultrices a, suscipit eget...', + * 'contentOptions' => array(...), + * ), + * 'Section 2' => array( + * 'content' => 'Sed non urna. Phasellus eu ligula. Vestibulum sit amet purus...', + * 'headerOptions' => array(...), + * ), + * ), + * )); + * ``` + * + * @see http://api.jqueryui.com/accordion/ + * @author Alexander Kochetov <creocoder@gmail.com> + * @since 2.0 + */ +class Accordion extends Widget +{ + /** + * @var array list of groups in the collapse widget. Each array element represents a single + * group with the following structure: + * + * ```php + * // item key is the actual group header + * 'Section' => array( + * // required, the content (HTML) of the group + * 'content' => 'Mauris mauris ante, blandit et, ultrices a, suscipit eget...', + * // optional the HTML attributes of the content group + * 'contentOptions'=> array(...), + * // optional the HTML attributes of the header group + * 'headerOptions'=> array(...), + * ) + * ``` + */ + public $items = array(); + + + /** + * Renders the widget. + */ + public function run() + { + echo Html::beginTag('div', $this->options) . "\n"; + echo $this->renderItems() . "\n"; + echo Html::endTag('div') . "\n"; + $this->registerWidget('accordion'); + } + + /** + * Renders collapsible items as specified on [[items]]. + * @return string the rendering result. + */ + public function renderItems() + { + $items = array(); + foreach ($this->items as $header => $item) { + $items[] = $this->renderItem($header, $item); + } + + return implode("\n", $items); + } + + /** + * Renders a single collapsible item group. + * @param string $header a label of the item group [[items]]. + * @param array $item a single item from [[items]]. + * @return string the rendering result. + * @throws InvalidConfigException. + */ + public function renderItem($header, $item) + { + if (isset($item['content'])) { + $contentOptions = ArrayHelper::getValue($item, 'contentOptions', array()); + $content = Html::tag('div', $item['content']) . "\n"; + } else { + throw new InvalidConfigException("The 'content' option is required."); + } + + $group = array(); + $headerOptions = ArrayHelper::getValue($item, 'headerOptions', array()); + $group[] = Html::tag('h3', $header, $headerOptions); + $group[] = Html::tag('div', $content, $contentOptions); + + return implode("\n", $group); + } +} From aa3bfa5a8afa42068cbf4b3fdf99087bf7d89cca Mon Sep 17 00:00:00 2001 From: Alexander Kochetov <creocoder@gmail.com> Date: Thu, 23 May 2013 19:32:40 +0400 Subject: [PATCH 14/36] Comments fixes --- framework/yii/jui/Accordion.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/framework/yii/jui/Accordion.php b/framework/yii/jui/Accordion.php index 0deab15..df9ba20 100644 --- a/framework/yii/jui/Accordion.php +++ b/framework/yii/jui/Accordion.php @@ -38,17 +38,17 @@ use yii\helpers\Html; class Accordion extends Widget { /** - * @var array list of groups in the collapse widget. Each array element represents a single - * group with the following structure: + * @var array list of sections in the accordion widget. Each array element represents a single + * section with the following structure: * * ```php - * // item key is the actual group header + * // item key is the actual section header * 'Section' => array( - * // required, the content (HTML) of the group + * // required, the content (HTML) of the section * 'content' => 'Mauris mauris ante, blandit et, ultrices a, suscipit eget...', - * // optional the HTML attributes of the content group + * // optional the HTML attributes of the content section * 'contentOptions'=> array(...), - * // optional the HTML attributes of the header group + * // optional the HTML attributes of the header section * 'headerOptions'=> array(...), * ) * ``` @@ -82,8 +82,8 @@ class Accordion extends Widget } /** - * Renders a single collapsible item group. - * @param string $header a label of the item group [[items]]. + * Renders a single collapsible item section. + * @param string $header a label of the item section [[items]]. * @param array $item a single item from [[items]]. * @return string the rendering result. * @throws InvalidConfigException. From caf9948c5428025ab9a2914930ebc67f763c4fdd Mon Sep 17 00:00:00 2001 From: Alexander Makarov <sam@rmcreative.ru> Date: Thu, 23 May 2013 19:51:47 +0400 Subject: [PATCH 15/36] fixes #377 --- framework/yii/console/controllers/HelpController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/yii/console/controllers/HelpController.php b/framework/yii/console/controllers/HelpController.php index c40ea66..a729f78 100644 --- a/framework/yii/console/controllers/HelpController.php +++ b/framework/yii/console/controllers/HelpController.php @@ -13,7 +13,7 @@ use yii\base\InlineAction; use yii\console\Controller; use yii\console\Exception; use yii\console\Request; -use yii\helpers\StringHelper; +use yii\helpers\Inflector; /** * This command provides help information about console commands. @@ -96,7 +96,7 @@ class HelpController extends Controller foreach ($class->getMethods() as $method) { $name = $method->getName(); if ($method->isPublic() && !$method->isStatic() && strpos($name, 'action') === 0 && $name !== 'actions') { - $actions[] = StringHelper::camel2id(substr($name, 6)); + $actions[] = Inflector::camel2id(substr($name, 6)); } } sort($actions); From c73ab91099282936bbc06cc1831da601cd32e3d6 Mon Sep 17 00:00:00 2001 From: Tobias Munk <schmunk@usrbin.de> Date: Thu, 23 May 2013 18:16:18 +0200 Subject: [PATCH 16/36] added line-break after message --- apps/bootstrap/commands/HelloController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/bootstrap/commands/HelloController.php b/apps/bootstrap/commands/HelloController.php index 16f5f74..b5ecac2 100644 --- a/apps/bootstrap/commands/HelloController.php +++ b/apps/bootstrap/commands/HelloController.php @@ -24,6 +24,6 @@ class HelloController extends Controller */ public function actionIndex($message = 'hello world') { - echo $message; + echo $message."\n"; } } \ No newline at end of file From 8264c5c51d13a513bd650529286170bd89cab491 Mon Sep 17 00:00:00 2001 From: Tobias Munk <schmunk@usrbin.de> Date: Thu, 23 May 2013 18:17:50 +0200 Subject: [PATCH 17/36] refactored param parsing --- extensions/composer/yii/composer/InstallHandler.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/extensions/composer/yii/composer/InstallHandler.php b/extensions/composer/yii/composer/InstallHandler.php index 6ac645a..1171889 100644 --- a/extensions/composer/yii/composer/InstallHandler.php +++ b/extensions/composer/yii/composer/InstallHandler.php @@ -80,17 +80,17 @@ class InstallHandler } } + // prepare console application require(__DIR__ . '/../../../yii2/yii/Yii.php'); + $application = new \yii\console\Application($config); + $request = $application->getRequest(); - foreach ((array)$options['run'] as $rawParams) { - // TODO: we're doing about the same here like console\Request::resolve() - $command = $rawParams[0]; - unset($rawParams[0]); - $params[\yii\console\Request::ANONYMOUS_PARAMS] = $rawParams; - // TODO end - + // run commands from extra.run + foreach ((array)$options['run'] as $rawCommand) { + $opts = str_getcsv($rawCommand, ' '); // see http://stackoverflow.com/a/6609509/291573 + $request->setParams($opts); + list($command, $params) = $request->resolve(); echo "Running command: {$command}\n"; - $application = new \yii\console\Application($config); $application->runAction($command, $params); } } From 34793c1303206a6e3ee8872cd21f270d471250c0 Mon Sep 17 00:00:00 2001 From: Tobias Munk <schmunk@usrbin.de> Date: Thu, 23 May 2013 18:33:48 +0200 Subject: [PATCH 18/36] added full display of command --- extensions/composer/yii/composer/InstallHandler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/composer/yii/composer/InstallHandler.php b/extensions/composer/yii/composer/InstallHandler.php index 1171889..0c4eb2b 100644 --- a/extensions/composer/yii/composer/InstallHandler.php +++ b/extensions/composer/yii/composer/InstallHandler.php @@ -90,7 +90,7 @@ class InstallHandler $opts = str_getcsv($rawCommand, ' '); // see http://stackoverflow.com/a/6609509/291573 $request->setParams($opts); list($command, $params) = $request->resolve(); - echo "Running command: {$command}\n"; + echo "Running command: yiic {$rawCommand}\n"; $application->runAction($command, $params); } } From ebe31c5f604338a50de9e6ece52852a16c3e2778 Mon Sep 17 00:00:00 2001 From: Qiang Xue <qiang.xue@gmail.com> Date: Thu, 23 May 2013 13:24:10 -0400 Subject: [PATCH 19/36] Fixes issue 380: invalid route exception should be 404. --- framework/yii/web/Application.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/framework/yii/web/Application.php b/framework/yii/web/Application.php index 3387044..a786985 100644 --- a/framework/yii/web/Application.php +++ b/framework/yii/web/Application.php @@ -8,6 +8,8 @@ namespace yii\web; use Yii; +use yii\base\HttpException; +use yii\base\InvalidRouteException; /** * Application is the base class for all application classes. @@ -25,6 +27,7 @@ class Application extends \yii\base\Application /** * Processes the request. * @return integer the exit status of the controller action (0 means normal, non-zero values mean abnormal) + * @throws HttpException if the request cannot be resolved. */ public function processRequest() { @@ -32,7 +35,11 @@ class Application extends \yii\base\Application Yii::setAlias('@wwwroot', dirname($request->getScriptFile())); Yii::setAlias('@www', $request->getBaseUrl()); list ($route, $params) = $request->resolve(); - return $this->runAction($route, $params); + try { + return $this->runAction($route, $params); + } catch (InvalidRouteException $e) { + throw new HttpException(404, $e->getMessage(), $e->getCode(), $e); + } } private $_homeUrl; From 8e1079cd047aedd026cb10be9999c60174c59a23 Mon Sep 17 00:00:00 2001 From: resurtm <resurtm@gmail.com> Date: Thu, 23 May 2013 23:33:33 +0600 Subject: [PATCH 20/36] MSSQL more tests. --- tests/unit/data/mssql.sql | 2 +- tests/unit/framework/db/mssql/MssqlCommandTest.php | 55 +++++++++++++++++++++- 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/tests/unit/data/mssql.sql b/tests/unit/data/mssql.sql index d3bc8d2..959c6c6 100644 --- a/tests/unit/data/mssql.sql +++ b/tests/unit/data/mssql.sql @@ -62,7 +62,7 @@ CREATE TABLE [dbo].[tbl_type] ( [char_col3] [text], [float_col] [decimal](4,3) NOT NULL, [float_col2] [float] DEFAULT '1.23', - [blob_col] [binary], + [blob_col] [varbinary](MAX), [numeric_col] [decimal](5,2) DEFAULT '33.22', [time] [datetime] NOT NULL DEFAULT '2002-01-01 00:00:00', [bool_col] [tinyint] NOT NULL, diff --git a/tests/unit/framework/db/mssql/MssqlCommandTest.php b/tests/unit/framework/db/mssql/MssqlCommandTest.php index 422a00c..11d7565 100644 --- a/tests/unit/framework/db/mssql/MssqlCommandTest.php +++ b/tests/unit/framework/db/mssql/MssqlCommandTest.php @@ -21,11 +21,62 @@ class MssqlCommandTest extends \yiiunit\framework\db\CommandTest function testPrepareCancel() { - $this->markTestIncomplete(); + $this->markTestSkipped('MSSQL driver does not support this feature.'); } function testBindParamValue() { - $this->markTestIncomplete(); + $db = $this->getConnection(); + + // bindParam + $sql = 'INSERT INTO tbl_customer(email, name, address) VALUES (:email, :name, :address)'; + $command = $db->createCommand($sql); + $email = 'user4@example.com'; + $name = 'user4'; + $address = 'address4'; + $command->bindParam(':email', $email); + $command->bindParam(':name', $name); + $command->bindParam(':address', $address); + $command->execute(); + + $sql = 'SELECT name FROM tbl_customer WHERE email=:email'; + $command = $db->createCommand($sql); + $command->bindParam(':email', $email); + $this->assertEquals($name, $command->queryScalar()); + + $sql = 'INSERT INTO tbl_type (int_col, char_col, float_col, blob_col, numeric_col, bool_col) VALUES (:int_col, :char_col, :float_col, CONVERT([varbinary], :blob_col), :numeric_col, :bool_col)'; + $command = $db->createCommand($sql); + $intCol = 123; + $charCol = 'abc'; + $floatCol = 1.23; + $blobCol = "\x10\x11\x12"; + $numericCol = '1.23'; + $boolCol = false; + $command->bindParam(':int_col', $intCol); + $command->bindParam(':char_col', $charCol); + $command->bindParam(':float_col', $floatCol); + $command->bindParam(':blob_col', $blobCol); + $command->bindParam(':numeric_col', $numericCol); + $command->bindParam(':bool_col', $boolCol); + $this->assertEquals(1, $command->execute()); + + $sql = 'SELECT int_col, char_col, float_col, CONVERT([nvarchar], blob_col) AS blob_col, numeric_col FROM tbl_type'; + $row = $db->createCommand($sql)->queryRow(); + $this->assertEquals($intCol, $row['int_col']); + $this->assertEquals($charCol, trim($row['char_col'])); + $this->assertEquals($floatCol, $row['float_col']); + $this->assertEquals($blobCol, $row['blob_col']); + $this->assertEquals($numericCol, $row['numeric_col']); + + // bindValue + $sql = 'INSERT INTO tbl_customer(email, name, address) VALUES (:email, \'user5\', \'address5\')'; + $command = $db->createCommand($sql); + $command->bindValue(':email', 'user5@example.com'); + $command->execute(); + + $sql = 'SELECT email FROM tbl_customer WHERE name=:name'; + $command = $db->createCommand($sql); + $command->bindValue(':name', 'user5'); + $this->assertEquals('user5@example.com', $command->queryScalar()); } } From d67416ab8be16f1cf263adc9865621e1478d98ce Mon Sep 17 00:00:00 2001 From: resurtm <resurtm@gmail.com> Date: Thu, 23 May 2013 23:41:57 +0600 Subject: [PATCH 21/36] MSSQL: select what is really needed from information_schema.columns, not just everything as it was before. --- framework/yii/db/mssql/Schema.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/yii/db/mssql/Schema.php b/framework/yii/db/mssql/Schema.php index c52dfc3..add6185 100644 --- a/framework/yii/db/mssql/Schema.php +++ b/framework/yii/db/mssql/Schema.php @@ -163,7 +163,7 @@ class Schema extends \yii\db\Schema $column->isPrimaryKey = null; // primary key will be determined in findColumns() method $column->autoIncrement = $info['IsIdentity'] == 1; $column->unsigned = stripos($column->dbType, 'unsigned') !== false; - $column->comment = $info['Comment'] === null ? '' : $column['Comment']; + $column->comment = $info['Comment'] === null ? '' : $info['Comment']; $column->type = self::TYPE_STRING; if (preg_match('/^(\w+)(?:\(([^\)]+)\))?/', $column->dbType, $matches)) { @@ -221,7 +221,7 @@ class Schema extends \yii\db\Schema $sql = <<<SQL SELECT - [t1].*, + [t1].[COLUMN_NAME], [t1].[IS_NULLABLE], [t1].[DATA_TYPE], [t1].[COLUMN_DEFAULT], COLUMNPROPERTY(OBJECT_ID([t1].[table_schema] + '.' + [t1].[table_name]), [t1].[column_name], 'IsIdentity') AS IsIdentity, CONVERT(VARCHAR, [t2].[value]) AS Comment FROM {$columnsTableName} AS [t1] From 1aac7d61654c1ad4f90e6d3b52f41d74ddc6ceb7 Mon Sep 17 00:00:00 2001 From: Qiang Xue <qiang.xue@gmail.com> Date: Thu, 23 May 2013 13:53:33 -0400 Subject: [PATCH 22/36] refactored InstallHandler. --- apps/bootstrap/composer.json | 4 +- .../composer/yii/composer/InstallHandler.php | 51 +++++++++++----------- 2 files changed, 28 insertions(+), 27 deletions(-) diff --git a/apps/bootstrap/composer.json b/apps/bootstrap/composer.json index 6bd87cc..d44e35a 100644 --- a/apps/bootstrap/composer.json +++ b/apps/bootstrap/composer.json @@ -27,11 +27,11 @@ ] }, "extra": { - "writable": [ + "yii-install-writable": [ "runtime", "www/assets" ], - "executable": [ + "yii-install-executable": [ "yii" ] } diff --git a/extensions/composer/yii/composer/InstallHandler.php b/extensions/composer/yii/composer/InstallHandler.php index 0c4eb2b..20f4c26 100644 --- a/extensions/composer/yii/composer/InstallHandler.php +++ b/extensions/composer/yii/composer/InstallHandler.php @@ -8,7 +8,8 @@ namespace yii\composer; use Composer\Script\CommandEvent; -use yii\console; +use yii\console\Application; +use yii\console\Exception; defined('YII_DEBUG') or define('YII_DEBUG', true); @@ -24,6 +25,11 @@ defined('STDIN') or define('STDIN', fopen('php://stdin', 'r')); */ class InstallHandler { + const PARAM_WRITABLE = 'yii-install-writable'; + const PARAM_EXECUTABLE = 'yii-install-executable'; + const PARAM_CONFIG = 'yii-install-config'; + const PARAM_COMMANDS = 'yii-install-commands'; + /** * Sets the correct permissions of files and directories. * @param CommandEvent $event @@ -31,11 +37,11 @@ class InstallHandler public static function setPermissions($event) { $options = array_merge(array( - 'writable' => array(), - 'executable' => array(), + self::PARAM_WRITABLE => array(), + self::PARAM_EXECUTABLE => array(), ), $event->getComposer()->getPackage()->getExtra()); - foreach ((array)$options['writable'] as $path) { + foreach ((array)$options[self::PARAM_WRITABLE] as $path) { echo "Setting writable: $path ..."; if (is_dir($path)) { chmod($path, 0777); @@ -46,7 +52,7 @@ class InstallHandler } } - foreach ((array)$options['executable'] as $path) { + foreach ((array)$options[self::PARAM_EXECUTABLE] as $path) { echo "Setting executable: $path ..."; if (is_file($path)) { chmod($path, 0755); @@ -65,33 +71,28 @@ class InstallHandler public static function run($event) { $options = array_merge(array( - 'run' => array(), - 'config' => null, + self::PARAM_COMMANDS => array(), ), $event->getComposer()->getPackage()->getExtra()); - // resolve and include config file - if (($options['config'] === null)) { - throw new console\Exception('Config file not specified in composer.json extra.config'); - } else { - if (!is_file(getcwd() . '/' . $options['config'])) { - throw new console\Exception("Config file '{$options['config']}' specified in composer.json extra.config not found"); - } else { - $config = require($options['config']); - } + if (!isset($options[self::PARAM_CONFIG])) { + throw new Exception('Please specify the "' . self::PARAM_CONFIG . '" parameter in composer.json.'); + } + $configFile = getcwd() . '/' . $options[self::PARAM_CONFIG]; + if (!is_file($configFile)) { + throw new Exception("Config file does not exist: $configFile"); } - // prepare console application require(__DIR__ . '/../../../yii2/yii/Yii.php'); - $application = new \yii\console\Application($config); + $application = new Application(require($configFile)); $request = $application->getRequest(); - // run commands from extra.run - foreach ((array)$options['run'] as $rawCommand) { - $opts = str_getcsv($rawCommand, ' '); // see http://stackoverflow.com/a/6609509/291573 - $request->setParams($opts); - list($command, $params) = $request->resolve(); - echo "Running command: yiic {$rawCommand}\n"; - $application->runAction($command, $params); + foreach ((array)$options[self::PARAM_COMMANDS] as $command) { + $params = str_getcsv($command, ' '); // see http://stackoverflow.com/a/6609509/291573 + array_shift($params); + $request->setParams($params); + list($route, $params) = $request->resolve(); + echo "Running command: yii {$command}\n"; + $application->runAction($route, $params); } } } From 89e3077108605a4b27bf195fbcf7d7ef2a54ea08 Mon Sep 17 00:00:00 2001 From: resurtm <resurtm@gmail.com> Date: Fri, 24 May 2013 00:06:40 +0600 Subject: [PATCH 23/36] MSSQL column case consistency. --- framework/yii/db/mssql/Schema.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/framework/yii/db/mssql/Schema.php b/framework/yii/db/mssql/Schema.php index add6185..1991542 100644 --- a/framework/yii/db/mssql/Schema.php +++ b/framework/yii/db/mssql/Schema.php @@ -156,14 +156,14 @@ class Schema extends \yii\db\Schema { $column = new ColumnSchema(); - $column->name = $info['COLUMN_NAME']; - $column->allowNull = $info['IS_NULLABLE'] == 'YES'; - $column->dbType = $info['DATA_TYPE']; + $column->name = $info['column_name']; + $column->allowNull = $info['is_nullable'] == 'YES'; + $column->dbType = $info['data_type']; $column->enumValues = array(); // mssql has only vague equivalents to enum $column->isPrimaryKey = null; // primary key will be determined in findColumns() method - $column->autoIncrement = $info['IsIdentity'] == 1; + $column->autoIncrement = $info['is_identity'] == 1; $column->unsigned = stripos($column->dbType, 'unsigned') !== false; - $column->comment = $info['Comment'] === null ? '' : $info['Comment']; + $column->comment = $info['comment'] === null ? '' : $info['comment']; $column->type = self::TYPE_STRING; if (preg_match('/^(\w+)(?:\(([^\)]+)\))?/', $column->dbType, $matches)) { @@ -191,11 +191,11 @@ class Schema extends \yii\db\Schema $column->phpType = $this->getColumnPhpType($column); - if ($info['COLUMN_DEFAULT'] == '(NULL)') { - $info['COLUMN_DEFAULT'] = null; + if ($info['column_default'] == '(NULL)') { + $info['column_default'] = null; } - if ($column->type !== 'timestamp' || $info['COLUMN_DEFAULT'] !== 'CURRENT_TIMESTAMP') { - $column->defaultValue = $column->typecast($info['COLUMN_DEFAULT']); + if ($column->type !== 'timestamp' || $info['column_default'] !== 'CURRENT_TIMESTAMP') { + $column->defaultValue = $column->typecast($info['column_default']); } return $column; @@ -221,9 +221,9 @@ class Schema extends \yii\db\Schema $sql = <<<SQL SELECT - [t1].[COLUMN_NAME], [t1].[IS_NULLABLE], [t1].[DATA_TYPE], [t1].[COLUMN_DEFAULT], - COLUMNPROPERTY(OBJECT_ID([t1].[table_schema] + '.' + [t1].[table_name]), [t1].[column_name], 'IsIdentity') AS IsIdentity, - CONVERT(VARCHAR, [t2].[value]) AS Comment + [t1].[column_name], [t1].[is_nullable], [t1].[data_type], [t1].[column_default], + COLUMNPROPERTY(OBJECT_ID([t1].[table_schema] + '.' + [t1].[table_name]), [t1].[column_name], 'IsIdentity') AS is_identity, + CONVERT(VARCHAR, [t2].[value]) AS comment FROM {$columnsTableName} AS [t1] LEFT OUTER JOIN [sys].[extended_properties] AS [t2] ON [t1].[ordinal_position] = [t2].[minor_id] AND From cf22567753ed9f6d5201bcb29809176bb5d8f3e7 Mon Sep 17 00:00:00 2001 From: Qiang Xue <qiang.xue@gmail.com> Date: Thu, 23 May 2013 14:30:53 -0400 Subject: [PATCH 24/36] bug fix. --- extensions/composer/yii/composer/InstallHandler.php | 1 - 1 file changed, 1 deletion(-) diff --git a/extensions/composer/yii/composer/InstallHandler.php b/extensions/composer/yii/composer/InstallHandler.php index 20f4c26..9e36a35 100644 --- a/extensions/composer/yii/composer/InstallHandler.php +++ b/extensions/composer/yii/composer/InstallHandler.php @@ -88,7 +88,6 @@ class InstallHandler foreach ((array)$options[self::PARAM_COMMANDS] as $command) { $params = str_getcsv($command, ' '); // see http://stackoverflow.com/a/6609509/291573 - array_shift($params); $request->setParams($params); list($route, $params) = $request->resolve(); echo "Running command: yii {$command}\n"; From 0f6a7080971566e268c593ea2005ca02af4e2d15 Mon Sep 17 00:00:00 2001 From: Alexander Kochetov <creocoder@gmail.com> Date: Thu, 23 May 2013 22:34:07 +0400 Subject: [PATCH 25/36] jQuery Tabs widget raw --- framework/yii/jui/Tabs.php | 85 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 framework/yii/jui/Tabs.php diff --git a/framework/yii/jui/Tabs.php b/framework/yii/jui/Tabs.php new file mode 100644 index 0000000..314aa25 --- /dev/null +++ b/framework/yii/jui/Tabs.php @@ -0,0 +1,85 @@ +<?php +/** + * @link http://www.yiiframework.com/ + * @copyright Copyright (c) 2008 Yii Software LLC + * @license http://www.yiiframework.com/license/ + */ + +namespace yii\jui; + +use yii\base\InvalidConfigException; +use yii\helpers\base\ArrayHelper; +use yii\helpers\Html; + +/** + * Tabs renders an tabs jQuery UI widget. + * + * For example: + * + * ```php + * echo Tabs::widget(array( + * 'items' => array( + * 'One' => array( + * 'content' => 'Mauris mauris ante, blandit et, ultrices a, suscipit eget...', + * 'contentOptions' => array(...), + * ), + * 'Two' => array( + * 'content' => 'Sed non urna. Phasellus eu ligula. Vestibulum sit amet purus...', + * 'headerOptions' => array(...), + * ), + * ), + * )); + * ``` + * + * @see http://api.jqueryui.com/tabs/ + * @author Alexander Kochetov <creocoder@gmail.com> + * @since 2.0 + */ +class Tabs extends Widget +{ + /** + * @var array list of tabs in the tabs widget. Each array element represents a single + * tab with the following structure: + * + * ```php + * // item key is the actual tab header label + * 'Tab header label' => array( + * // required, the content (HTML) of the tab + * 'content' => 'Mauris mauris ante, blandit et, ultrices a, suscipit eget...', + * // optional the HTML attributes of the tab content container + * 'contentOptions'=> array(...), + * // optional the HTML attributes of the tab header container + * 'headerOptions'=> array(...), + * ) + * ``` + */ + public $items = array(); + + + /** + * Renders the widget. + */ + public function run() + { + echo Html::beginTag('div', $this->options) . "\n"; + $headers = array(); + $contents = array(); + $index = 0; + foreach ($this->items as $header => $item) { + $id = $this->options['id'] . '-tab' . ++$index; + $headerOptions = ArrayHelper::getValue($item, 'headerOptions', array()); + $headers[] = Html::tag('li', Html::tag('a', $header, array('href' => "#$id")), $headerOptions); + if (isset($item['content'])) { + $contentOptions = ArrayHelper::getValue($item, 'contentOptions', array()); + $contentOptions['id'] = $id; + $contents[] = Html::tag('div', $item['content'], $contentOptions); + } else { + throw new InvalidConfigException("The 'content' option is required."); + } + } + echo Html::tag('ul', implode("\n", $headers)) . "\n"; + echo implode("\n", $contents) . "\n"; + echo Html::endTag('div') . "\n"; + $this->registerWidget('tabs'); + } +} From e8b9475502de1ee28155696f8cf9f74e908c2fb7 Mon Sep 17 00:00:00 2001 From: Qiang Xue <qiang.xue@gmail.com> Date: Thu, 23 May 2013 15:12:45 -0400 Subject: [PATCH 26/36] changed dependency of composer installer --- extensions/composer/composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/composer/composer.json b/extensions/composer/composer.json index 49f99fe..d8cf49d 100644 --- a/extensions/composer/composer.json +++ b/extensions/composer/composer.json @@ -19,7 +19,7 @@ ], "minimum-stability": "dev", "require": { - "yiisoft/yii2": "dev-master" + "yiisoft/yii2": "*" }, "autoload": { "psr-0": { "yii\\composer": "" } From 153e51df94c93d8d4d925c9c2a8b5967489225b9 Mon Sep 17 00:00:00 2001 From: Alexander Kochetov <creocoder@gmail.com> Date: Thu, 23 May 2013 23:34:12 +0400 Subject: [PATCH 27/36] Html::url() fix for anchors --- framework/yii/helpers/base/Html.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/yii/helpers/base/Html.php b/framework/yii/helpers/base/Html.php index f601772..90396ec 100644 --- a/framework/yii/helpers/base/Html.php +++ b/framework/yii/helpers/base/Html.php @@ -1364,7 +1364,7 @@ class Html return Yii::$app->getRequest()->getUrl(); } else { $url = Yii::getAlias($url); - if ($url[0] === '/' || strpos($url, '://')) { + if ($url[0] === '/' || $url[0] === '#' || strpos($url, '://')) { return $url; } else { return Yii::$app->getRequest()->getBaseUrl() . '/' . $url; From 646161e01ce38876f7290e5589c8bdeeb62d9bd7 Mon Sep 17 00:00:00 2001 From: Alexander Kochetov <creocoder@gmail.com> Date: Fri, 24 May 2013 00:02:40 +0400 Subject: [PATCH 28/36] Refactoring --- framework/yii/jui/Tabs.php | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/framework/yii/jui/Tabs.php b/framework/yii/jui/Tabs.php index 314aa25..258a3a4 100644 --- a/framework/yii/jui/Tabs.php +++ b/framework/yii/jui/Tabs.php @@ -12,7 +12,7 @@ use yii\helpers\base\ArrayHelper; use yii\helpers\Html; /** - * Tabs renders an tabs jQuery UI widget. + * Tabs renders a tabs jQuery UI widget. * * For example: * @@ -62,24 +62,49 @@ class Tabs extends Widget public function run() { echo Html::beginTag('div', $this->options) . "\n"; + echo $this->renderHeaders() . "\n"; + echo $this->renderItems() . "\n"; + echo Html::endTag('div') . "\n"; + $this->registerWidget('tabs'); + } + + /** + * Renders tabs headers as specified on [[items]]. + * @return string the rendering result. + */ + protected function renderHeaders() + { $headers = array(); - $contents = array(); $index = 0; foreach ($this->items as $header => $item) { $id = $this->options['id'] . '-tab' . ++$index; $headerOptions = ArrayHelper::getValue($item, 'headerOptions', array()); - $headers[] = Html::tag('li', Html::tag('a', $header, array('href' => "#$id")), $headerOptions); + $headers[] = Html::tag('li', Html::a($header, "#$id"), $headerOptions); + } + + return Html::tag('ul', implode("\n", $headers)); + } + + /** + * Renders tabs items as specified on [[items]]. + * @return string the rendering result. + * @throws InvalidConfigException. + */ + protected function renderItems() + { + $items = array(); + $index = 0; + foreach ($this->items as $item) { + $id = $this->options['id'] . '-tab' . ++$index; if (isset($item['content'])) { $contentOptions = ArrayHelper::getValue($item, 'contentOptions', array()); $contentOptions['id'] = $id; - $contents[] = Html::tag('div', $item['content'], $contentOptions); + $items[] = Html::tag('div', $item['content'], $contentOptions); } else { throw new InvalidConfigException("The 'content' option is required."); } } - echo Html::tag('ul', implode("\n", $headers)) . "\n"; - echo implode("\n", $contents) . "\n"; - echo Html::endTag('div') . "\n"; - $this->registerWidget('tabs'); + + return implode("\n", $items); } } From f50e8f6bfced26f2d9dfaf5d71d7b6e45d8b56ce Mon Sep 17 00:00:00 2001 From: Alexander Kochetov <creocoder@gmail.com> Date: Fri, 24 May 2013 00:34:56 +0400 Subject: [PATCH 29/36] Final --- framework/yii/jui/Tabs.php | 55 +++++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/framework/yii/jui/Tabs.php b/framework/yii/jui/Tabs.php index 258a3a4..4007d4b 100644 --- a/framework/yii/jui/Tabs.php +++ b/framework/yii/jui/Tabs.php @@ -19,13 +19,15 @@ use yii\helpers\Html; * ```php * echo Tabs::widget(array( * 'items' => array( - * 'One' => array( + * array( + * 'header' => 'One', * 'content' => 'Mauris mauris ante, blandit et, ultrices a, suscipit eget...', - * 'contentOptions' => array(...), * ), - * 'Two' => array( - * 'content' => 'Sed non urna. Phasellus eu ligula. Vestibulum sit amet purus...', + * array( + * 'header' => 'Two', * 'headerOptions' => array(...), + * 'content' => 'Sed non urna. Phasellus eu ligula. Vestibulum sit amet purus...', + * 'options' => array(...), * ), * ), * )); @@ -42,12 +44,13 @@ class Tabs extends Widget * tab with the following structure: * * ```php - * // item key is the actual tab header label - * 'Tab header label' => array( + * array( + * // required, the header (HTML) of the tab + * 'header' => 'Tab label', * // required, the content (HTML) of the tab * 'content' => 'Mauris mauris ante, blandit et, ultrices a, suscipit eget...', * // optional the HTML attributes of the tab content container - * 'contentOptions'=> array(...), + * 'options'=> array(...), * // optional the HTML attributes of the tab header container * 'headerOptions'=> array(...), * ) @@ -63,7 +66,7 @@ class Tabs extends Widget { echo Html::beginTag('div', $this->options) . "\n"; echo $this->renderHeaders() . "\n"; - echo $this->renderItems() . "\n"; + echo $this->renderContents() . "\n"; echo Html::endTag('div') . "\n"; $this->registerWidget('tabs'); } @@ -71,40 +74,46 @@ class Tabs extends Widget /** * Renders tabs headers as specified on [[items]]. * @return string the rendering result. + * @throws InvalidConfigException. */ protected function renderHeaders() { $headers = array(); - $index = 0; - foreach ($this->items as $header => $item) { - $id = $this->options['id'] . '-tab' . ++$index; - $headerOptions = ArrayHelper::getValue($item, 'headerOptions', array()); - $headers[] = Html::tag('li', Html::a($header, "#$id"), $headerOptions); + foreach ($this->items as $n => $item) { + $options = ArrayHelper::getValue($item, 'options', array()); + $id = isset($options['id']) ? $options['id'] : $this->options['id'] . '-tab' . $n; + if (isset($item['header'])) { + $headerOptions = ArrayHelper::getValue($item, 'headerOptions', array()); + $headers[] = Html::tag('li', Html::a($item['header'], "#$id"), $headerOptions); + } else { + throw new InvalidConfigException("The 'header' option is required."); + } } return Html::tag('ul', implode("\n", $headers)); } /** - * Renders tabs items as specified on [[items]]. + * Renders tabs contents as specified on [[items]]. * @return string the rendering result. * @throws InvalidConfigException. */ - protected function renderItems() + protected function renderContents() { - $items = array(); - $index = 0; - foreach ($this->items as $item) { - $id = $this->options['id'] . '-tab' . ++$index; + $contents = array(); + foreach ($this->items as $n => $item) { + $id = $this->options['id'] . '-tab' . $n; if (isset($item['content'])) { - $contentOptions = ArrayHelper::getValue($item, 'contentOptions', array()); - $contentOptions['id'] = $id; - $items[] = Html::tag('div', $item['content'], $contentOptions); + $options = ArrayHelper::getValue($item, 'options', array()); + if (!isset($options['id'])) { + $options['id'] = $id; + } + $contents[] = Html::tag('div', $item['content'], $options); } else { throw new InvalidConfigException("The 'content' option is required."); } } - return implode("\n", $items); + return implode("\n", $contents); } } From cc5981e2e2ddd4c4783081bcf5aa823c07773e69 Mon Sep 17 00:00:00 2001 From: Alexander Kochetov <creocoder@gmail.com> Date: Fri, 24 May 2013 00:38:37 +0400 Subject: [PATCH 30/36] Post final ;) --- framework/yii/jui/Tabs.php | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/framework/yii/jui/Tabs.php b/framework/yii/jui/Tabs.php index 4007d4b..171b7fe 100644 --- a/framework/yii/jui/Tabs.php +++ b/framework/yii/jui/Tabs.php @@ -80,14 +80,13 @@ class Tabs extends Widget { $headers = array(); foreach ($this->items as $n => $item) { - $options = ArrayHelper::getValue($item, 'options', array()); - $id = isset($options['id']) ? $options['id'] : $this->options['id'] . '-tab' . $n; - if (isset($item['header'])) { - $headerOptions = ArrayHelper::getValue($item, 'headerOptions', array()); - $headers[] = Html::tag('li', Html::a($item['header'], "#$id"), $headerOptions); - } else { + if (!isset($item['header'])) { throw new InvalidConfigException("The 'header' option is required."); } + $options = ArrayHelper::getValue($item, 'options', array()); + $id = isset($options['id']) ? $options['id'] : $this->options['id'] . '-tab' . $n; + $headerOptions = ArrayHelper::getValue($item, 'headerOptions', array()); + $headers[] = Html::tag('li', Html::a($item['header'], "#$id"), $headerOptions); } return Html::tag('ul', implode("\n", $headers)); @@ -102,16 +101,15 @@ class Tabs extends Widget { $contents = array(); foreach ($this->items as $n => $item) { - $id = $this->options['id'] . '-tab' . $n; - if (isset($item['content'])) { - $options = ArrayHelper::getValue($item, 'options', array()); - if (!isset($options['id'])) { - $options['id'] = $id; - } - $contents[] = Html::tag('div', $item['content'], $options); - } else { + if (!isset($item['content'])) { throw new InvalidConfigException("The 'content' option is required."); } + $id = $this->options['id'] . '-tab' . $n; + $options = ArrayHelper::getValue($item, 'options', array()); + if (!isset($options['id'])) { + $options['id'] = $id; + } + $contents[] = Html::tag('div', $item['content'], $options); } return implode("\n", $contents); From 7724b5f5e4faa0fb8a6c78d5f4d7dc3f3a10b968 Mon Sep 17 00:00:00 2001 From: Alexander Kochetov <creocoder@gmail.com> Date: Fri, 24 May 2013 00:44:36 +0400 Subject: [PATCH 31/36] Cosmetic change --- framework/yii/jui/Tabs.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/framework/yii/jui/Tabs.php b/framework/yii/jui/Tabs.php index 171b7fe..ca0b3da 100644 --- a/framework/yii/jui/Tabs.php +++ b/framework/yii/jui/Tabs.php @@ -104,10 +104,9 @@ class Tabs extends Widget if (!isset($item['content'])) { throw new InvalidConfigException("The 'content' option is required."); } - $id = $this->options['id'] . '-tab' . $n; $options = ArrayHelper::getValue($item, 'options', array()); if (!isset($options['id'])) { - $options['id'] = $id; + $options['id'] = $this->options['id'] . '-tab' . $n; } $contents[] = Html::tag('div', $item['content'], $options); } From df025fc2bfa27c775cd523d361f9b13db10d51b7 Mon Sep 17 00:00:00 2001 From: Alexander Kochetov <creocoder@gmail.com> Date: Fri, 24 May 2013 01:18:38 +0400 Subject: [PATCH 32/36] jQuery Accordion rework --- framework/yii/jui/Accordion.php | 65 ++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 36 deletions(-) diff --git a/framework/yii/jui/Accordion.php b/framework/yii/jui/Accordion.php index df9ba20..9b68a7e 100644 --- a/framework/yii/jui/Accordion.php +++ b/framework/yii/jui/Accordion.php @@ -19,13 +19,15 @@ use yii\helpers\Html; * ```php * echo Accordion::widget(array( * 'items' => array( - * 'Section 1' => array( + * array( + * 'header' => 'Section 1', * 'content' => 'Mauris mauris ante, blandit et, ultrices a, suscipit eget...', - * 'contentOptions' => array(...), * ), - * 'Section 2' => array( - * 'content' => 'Sed non urna. Phasellus eu ligula. Vestibulum sit amet purus...', + * array( + * 'header' => 'Section 2', * 'headerOptions' => array(...), + * 'content' => 'Sed non urna. Phasellus eu ligula. Vestibulum sit amet purus...', + * 'options' => array(...), * ), * ), * )); @@ -42,12 +44,13 @@ class Accordion extends Widget * section with the following structure: * * ```php - * // item key is the actual section header - * 'Section' => array( + * array( + * // required, the header (HTML) of the section + * 'header' => 'Section label', * // required, the content (HTML) of the section * 'content' => 'Mauris mauris ante, blandit et, ultrices a, suscipit eget...', * // optional the HTML attributes of the content section - * 'contentOptions'=> array(...), + * 'options'=> array(...), * // optional the HTML attributes of the header section * 'headerOptions'=> array(...), * ) @@ -62,46 +65,36 @@ class Accordion extends Widget public function run() { echo Html::beginTag('div', $this->options) . "\n"; - echo $this->renderItems() . "\n"; + echo $this->renderSections() . "\n"; echo Html::endTag('div') . "\n"; $this->registerWidget('accordion'); } /** - * Renders collapsible items as specified on [[items]]. + * Renders collapsible sections as specified on [[items]]. * @return string the rendering result. + * @throws InvalidConfigException. */ - public function renderItems() + protected function renderSections() { - $items = array(); - foreach ($this->items as $header => $item) { - $items[] = $this->renderItem($header, $item); - } + $sections = array(); + foreach ($this->items as $item) { + if (!isset($item['header'])) { + throw new InvalidConfigException("The 'header' option is required."); + } - return implode("\n", $items); - } + $headerOptions = ArrayHelper::getValue($item, 'headerOptions', array()); + $sections[] = Html::tag('h3', $item['header'], $headerOptions); - /** - * Renders a single collapsible item section. - * @param string $header a label of the item section [[items]]. - * @param array $item a single item from [[items]]. - * @return string the rendering result. - * @throws InvalidConfigException. - */ - public function renderItem($header, $item) - { - if (isset($item['content'])) { - $contentOptions = ArrayHelper::getValue($item, 'contentOptions', array()); - $content = Html::tag('div', $item['content']) . "\n"; - } else { - throw new InvalidConfigException("The 'content' option is required."); - } + if (!isset($item['content'])) { + throw new InvalidConfigException("The 'content' option is required."); + } + + $options = ArrayHelper::getValue($item, 'options', array()); + $sections[] = Html::tag('div', $item['content'], $options);; - $group = array(); - $headerOptions = ArrayHelper::getValue($item, 'headerOptions', array()); - $group[] = Html::tag('h3', $header, $headerOptions); - $group[] = Html::tag('div', $content, $contentOptions); + } - return implode("\n", $group); + return implode("\n", $sections); } } From be82ee81dbcbe4c3dca4914256d7f28e1c505ee6 Mon Sep 17 00:00:00 2001 From: Alexander Kochetov <creocoder@gmail.com> Date: Fri, 24 May 2013 01:26:31 +0400 Subject: [PATCH 33/36] Comment fixes --- framework/yii/jui/Accordion.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/yii/jui/Accordion.php b/framework/yii/jui/Accordion.php index 9b68a7e..a4bae15 100644 --- a/framework/yii/jui/Accordion.php +++ b/framework/yii/jui/Accordion.php @@ -49,9 +49,9 @@ class Accordion extends Widget * 'header' => 'Section label', * // required, the content (HTML) of the section * 'content' => 'Mauris mauris ante, blandit et, ultrices a, suscipit eget...', - * // optional the HTML attributes of the content section + * // optional the HTML attributes of the section content container * 'options'=> array(...), - * // optional the HTML attributes of the header section + * // optional the HTML attributes of the section header container * 'headerOptions'=> array(...), * ) * ``` From fb9dbdb236d532820d8924131ef1576559abb892 Mon Sep 17 00:00:00 2001 From: Alexander Kochetov <creocoder@gmail.com> Date: Fri, 24 May 2013 01:29:41 +0400 Subject: [PATCH 34/36] Cosmetic code move --- framework/yii/jui/Accordion.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/framework/yii/jui/Accordion.php b/framework/yii/jui/Accordion.php index a4bae15..6c5dd97 100644 --- a/framework/yii/jui/Accordion.php +++ b/framework/yii/jui/Accordion.php @@ -82,17 +82,13 @@ class Accordion extends Widget if (!isset($item['header'])) { throw new InvalidConfigException("The 'header' option is required."); } - - $headerOptions = ArrayHelper::getValue($item, 'headerOptions', array()); - $sections[] = Html::tag('h3', $item['header'], $headerOptions); - if (!isset($item['content'])) { throw new InvalidConfigException("The 'content' option is required."); } - + $headerOptions = ArrayHelper::getValue($item, 'headerOptions', array()); + $sections[] = Html::tag('h3', $item['header'], $headerOptions); $options = ArrayHelper::getValue($item, 'options', array()); $sections[] = Html::tag('div', $item['content'], $options);; - } return implode("\n", $sections); From 5f6700183959338a66bc2645964a603cf276b5c6 Mon Sep 17 00:00:00 2001 From: Alexander Kochetov <creocoder@gmail.com> Date: Fri, 24 May 2013 01:56:51 +0400 Subject: [PATCH 35/36] jQuery UI effects dependencies --- framework/yii/jui/assets.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/framework/yii/jui/assets.php b/framework/yii/jui/assets.php index c292050..285026c 100644 --- a/framework/yii/jui/assets.php +++ b/framework/yii/jui/assets.php @@ -20,7 +20,7 @@ return array( 'js' => array( 'jquery.ui.accordion.js', ), - 'depends' => array('yii/jui/core', 'yii/jui/widget'), + 'depends' => array('yii/jui/core', 'yii/jui/widget', 'yii/jui/effect/all'), ), 'yii/jui/autocomplete' => array( 'sourcePath' => __DIR__ . '/assets', @@ -41,7 +41,7 @@ return array( 'js' => array( 'jquery.ui.datepicker.js', ), - 'depends' => array('yii/jui/core'), + 'depends' => array('yii/jui/core', 'yii/jui/effect/all'), ), 'yii/jui/datepicker/i18n/af' => array( 'sourcePath' => __DIR__ . '/assets', @@ -559,7 +559,7 @@ return array( 'js' => array( 'jquery.ui.dialog.js', ), - 'depends' => array('yii/jui/core', 'yii/jui/widget', 'yii/jui/button', 'yii/jui/draggable', 'yii/jui/mouse', 'yii/jui/position', 'yii/jui/resizeable'), + 'depends' => array('yii/jui/core', 'yii/jui/widget', 'yii/jui/button', 'yii/jui/draggable', 'yii/jui/mouse', 'yii/jui/position', 'yii/jui/resizeable', 'yii/jui/effect/all'), ), 'yii/jui/draggable' => array( 'sourcePath' => __DIR__ . '/assets', @@ -582,6 +582,13 @@ return array( ), 'depends' => array('yii/jquery'), ), + 'yii/jui/effect/all' => array( + 'sourcePath' => __DIR__ . '/assets', + 'js' => array( + 'jquery.ui.effect.js', + ), + 'depends' => array('yii/jui/effect/blind', 'yii/jui/effect/bounce', 'yii/jui/effect/clip', 'yii/jui/effect/drop', 'yii/jui/effect/explode', 'yii/jui/effect/fade', 'yii/jui/effect/fold', 'yii/jui/effect/highlight', 'yii/jui/effect/pulsate', 'yii/jui/effect/scale', 'yii/jui/effect/shake', 'yii/jui/effect/slide', 'yii/jui/effect/transfer'), + ), 'yii/jui/effect/blind' => array( 'sourcePath' => __DIR__ . '/assets', 'js' => array( @@ -741,14 +748,14 @@ return array( 'js' => array( 'jquery.ui.tabs.js', ), - 'depends' => array('yii/jui/core', 'yii/jui/widget'), + 'depends' => array('yii/jui/core', 'yii/jui/widget', 'yii/jui/effect/all'), ), 'yii/jui/tooltip' => array( 'sourcePath' => __DIR__ . '/assets', 'js' => array( 'jquery.ui.tooltip.js', ), - 'depends' => array('yii/jui/core', 'yii/jui/widget', 'yii/jui/position'), + 'depends' => array('yii/jui/core', 'yii/jui/widget', 'yii/jui/position', 'yii/jui/effect/all'), ), 'yii/jui/theme/base' => array( 'sourcePath' => __DIR__ . '/assets', From 7614450fa7e19e962d6c984dad1823cd2125a83c Mon Sep 17 00:00:00 2001 From: Alexander Kochetov <creocoder@gmail.com> Date: Fri, 24 May 2013 02:41:00 +0400 Subject: [PATCH 36/36] jQuery UI menu widget --- framework/yii/jui/Menu.php | 86 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 framework/yii/jui/Menu.php diff --git a/framework/yii/jui/Menu.php b/framework/yii/jui/Menu.php new file mode 100644 index 0000000..0a84acf --- /dev/null +++ b/framework/yii/jui/Menu.php @@ -0,0 +1,86 @@ +<?php +/** + * @link http://www.yiiframework.com/ + * @copyright Copyright (c) 2008 Yii Software LLC + * @license http://www.yiiframework.com/license/ + */ + +namespace yii\jui; + +use Yii; +use yii\base\View; +use yii\helpers\Json; + + +/** + * Menu renders a menu jQuery UI widget. + * + * @see http://api.jqueryui.com/menu/ + * @author Alexander Kochetov <creocoder@gmail.com> + * @since 2.0 + */ +class Menu extends \yii\widgets\Menu +{ + /** + * @var array the options for the underlying jQuery UI widget. + * Please refer to the corresponding jQuery UI widget Web page for possible options. + * For example, [this page](http://api.jqueryui.com/accordion/) shows + * how to use the "Accordion" widget and the supported options (e.g. "header"). + */ + public $clientOptions = array(); + /** + * @var array the event handlers for the underlying jQuery UI widget. + * Please refer to the corresponding jQuery UI widget Web page for possible events. + * For example, [this page](http://api.jqueryui.com/accordion/) shows + * how to use the "Accordion" widget and the supported events (e.g. "create"). + */ + public $clientEvents = array(); + + + /** + * Initializes the widget. + * If you override this method, make sure you call the parent implementation first. + */ + public function init() + { + parent::init(); + if (!isset($this->options['id'])) { + $this->options['id'] = $this->getId(); + } + } + + /** + * Renders the widget. + */ + public function run() + { + parent::run(); + $this->registerWidget('menu'); + } + + /** + * Registers a specific jQuery UI widget and the related events + * @param string $name the name of the jQuery UI widget + */ + protected function registerWidget($name) + { + $id = $this->options['id']; + $view = $this->getView(); + $view->registerAssetBundle("yii/jui/$name"); + $view->registerAssetBundle(Widget::$theme . "/$name"); + + if ($this->clientOptions !== false) { + $options = empty($this->clientOptions) ? '' : Json::encode($this->clientOptions); + $js = "jQuery('#$id').$name($options);"; + $view->registerJs($js); + } + + if (!empty($this->clientEvents)) { + $js = array(); + foreach ($this->clientEvents as $event => $handler) { + $js[] = "jQuery('#$id').on('$name$event', $handler);"; + } + $view->registerJs(implode("\n", $js)); + } + } +}