Browse Source

Merge branch 'upstream' into 364-toAscii

* upstream:
  Fixed build break.
  Fixes issue #194: Added Application::catchAll.
  added missing default to getValue in boostrap tabs
  \yii\widgets\Menu improvement
  Fixes issue #467: allow view file to be absent as long as the themed version exists.
  better auto scrolling.
  Fixes issue #446: automatically scroll to first error.
tags/2.0.0-beta
Antonio Ramirez 12 years ago
parent
commit
65461683ff
  1. 14
      framework/yii/assets/yii.activeForm.js
  2. 2
      framework/yii/base/View.php
  3. 2
      framework/yii/bootstrap/Tabs.php
  4. 25
      framework/yii/web/Application.php
  5. 26
      framework/yii/widgets/Menu.php
  6. 2
      tests/unit/framework/i18n/FormatterTest.php

14
framework/yii/assets/yii.activeForm.js

@ -135,12 +135,20 @@
data.submitting = true; data.submitting = true;
if (!data.settings.beforeSubmit || data.settings.beforeSubmit($form)) { if (!data.settings.beforeSubmit || data.settings.beforeSubmit($form)) {
validate($form, function (messages) { validate($form, function (messages) {
var hasError = false; var errors = [];
$.each(data.attributes, function () { $.each(data.attributes, function () {
hasError = updateInput($form, this, messages) || hasError; if (updateInput($form, this, messages)) {
errors.push(this.input);
}
}); });
updateSummary($form, messages); updateSummary($form, messages);
if (!hasError) { if (errors.length) {
var top = $form.find(errors.join(',')).first().offset().top;
var wtop = $(window).scrollTop();
if (top < wtop || top > wtop + $(window).height) {
$(window).scrollTop(top);
}
} else {
data.validated = true; data.validated = true;
var $button = data.submitObject || $form.find(':submit:first'); var $button = data.submitObject || $form.find(':submit:first');
// TODO: if the submission is caused by "change" event, it will not work // TODO: if the submission is caused by "change" event, it will not work

2
framework/yii/base/View.php

@ -235,10 +235,10 @@ class View extends Component
public function renderFile($viewFile, $params = array(), $context = null) public function renderFile($viewFile, $params = array(), $context = null)
{ {
$viewFile = Yii::getAlias($viewFile); $viewFile = Yii::getAlias($viewFile);
if (is_file($viewFile)) {
if ($this->theme !== null) { if ($this->theme !== null) {
$viewFile = $this->theme->applyTo($viewFile); $viewFile = $this->theme->applyTo($viewFile);
} }
if (is_file($viewFile)) {
$viewFile = FileHelper::localize($viewFile); $viewFile = FileHelper::localize($viewFile);
} else { } else {
throw new InvalidParamException("The view file does not exist: $viewFile"); throw new InvalidParamException("The view file does not exist: $viewFile");

2
framework/yii/bootstrap/Tabs.php

@ -132,7 +132,7 @@ class Tabs extends Widget
$header = Html::a($label, "#", array('class' => 'dropdown-toggle', 'data-toggle' => 'dropdown')) . "\n" $header = Html::a($label, "#", array('class' => 'dropdown-toggle', 'data-toggle' => 'dropdown')) . "\n"
. Dropdown::widget(array('items' => $item['items'], 'clientOptions' => false)); . Dropdown::widget(array('items' => $item['items'], 'clientOptions' => false));
} elseif (isset($item['content'])) { } elseif (isset($item['content'])) {
$options = array_merge($this->itemOptions, ArrayHelper::getValue($item, 'options')); $options = array_merge($this->itemOptions, ArrayHelper::getValue($item, 'options', array()));
$options['id'] = ArrayHelper::getValue($options, 'id', $this->options['id'] . '-tab' . $n); $options['id'] = ArrayHelper::getValue($options, 'id', $this->options['id'] . '-tab' . $n);
$this->addCssClass($options, 'tab-pane'); $this->addCssClass($options, 'tab-pane');

25
framework/yii/web/Application.php

@ -23,6 +23,26 @@ class Application extends \yii\base\Application
* @var string the default route of this application. Defaults to 'site'. * @var string the default route of this application. Defaults to 'site'.
*/ */
public $defaultRoute = 'site'; public $defaultRoute = 'site';
/**
* @var array the configuration specifying a controller action which should handle
* all user requests. This is mainly used when the application is in maintenance mode
* and needs to handle all incoming requests via a single action.
* The configuration is an array whose first element specifies the route of the action.
* The rest of the array elements (key-value pairs) specify the parameters to be bound
* to the action. For example,
*
* ~~~
* array(
* 'offline/notice',
* 'param1' => 'value1',
* 'param2' => 'value2',
* )
* ~~~
*
* Defaults to null, meaning catch-all is not effective.
*/
public $catchAll;
/** /**
* Processes the request. * Processes the request.
@ -34,7 +54,12 @@ class Application extends \yii\base\Application
$request = $this->getRequest(); $request = $this->getRequest();
Yii::setAlias('@wwwroot', dirname($request->getScriptFile())); Yii::setAlias('@wwwroot', dirname($request->getScriptFile()));
Yii::setAlias('@www', $request->getBaseUrl()); Yii::setAlias('@www', $request->getBaseUrl());
if (empty($this->catchAll)) {
list ($route, $params) = $request->resolve(); list ($route, $params) = $request->resolve();
} else {
$route = $this->catchAll[0];
$params = array_splice($this->catchAll, 1);
}
try { try {
return $this->runAction($route, $params); return $this->runAction($route, $params);
} catch (InvalidRouteException $e) { } catch (InvalidRouteException $e) {

26
framework/yii/widgets/Menu.php

@ -9,6 +9,7 @@ namespace yii\widgets;
use Yii; use Yii;
use yii\base\Widget; use yii\base\Widget;
use yii\helpers\ArrayHelper;
use yii\helpers\Html; use yii\helpers\Html;
/** /**
@ -68,6 +69,13 @@ class Menu extends Widget
*/ */
public $items = array(); public $items = array();
/** /**
* @var array list of HTML attributes for the menu container tag. This will be overwritten
* by the "options" set in individual [[items]]. The following special options are recognized:
*
* - tag: string, defaults to "li", the tag name of the item container tags.
*/
public $itemOptions = array();
/**
* @var string the template used to render the body of a menu which is a link. * @var string the template used to render the body of a menu which is a link.
* In this template, the token `{url}` will be replaced with the corresponding link URL; * In this template, the token `{url}` will be replaced with the corresponding link URL;
* while `{label}` will be replaced with the link text. * while `{label}` will be replaced with the link text.
@ -110,7 +118,9 @@ class Menu extends Widget
*/ */
public $hideEmptyItems = true; public $hideEmptyItems = true;
/** /**
* @var array the HTML attributes for the menu's container tag. * @var array the HTML attributes for the menu's container tag. The following special options are recognized:
*
* - tag: string, defaults to "ul", the tag name of the item container tags.
*/ */
public $options = array(); public $options = array();
/** /**
@ -151,7 +161,9 @@ class Menu extends Widget
$this->params = $_GET; $this->params = $_GET;
} }
$items = $this->normalizeItems($this->items, $hasActiveChild); $items = $this->normalizeItems($this->items, $hasActiveChild);
echo Html::tag('ul', $this->renderItems($items), $this->options); $options = $this->options;
$tag = ArrayHelper::remove($options, 'tag', 'ul');
echo Html::tag($tag, $this->renderItems($items), $options);
} }
/** /**
@ -164,7 +176,8 @@ class Menu extends Widget
$n = count($items); $n = count($items);
$lines = array(); $lines = array();
foreach ($items as $i => $item) { foreach ($items as $i => $item) {
$options = isset($item['options']) ? $item['options'] : array(); $options = array_merge($this->itemOptions, ArrayHelper::getValue($item, 'options', array()));
$tag = ArrayHelper::remove($options, 'tag', 'li');
$class = array(); $class = array();
if ($item['active']) { if ($item['active']) {
$class[] = $this->activeCssClass; $class[] = $this->activeCssClass;
@ -189,7 +202,7 @@ class Menu extends Widget
'{items}' => $this->renderItems($item['items']), '{items}' => $this->renderItems($item['items']),
)); ));
} }
$lines[] = Html::tag('li', $menu, $options); $lines[] = Html::tag($tag, $menu, $options);
} }
return implode("\n", $lines); return implode("\n", $lines);
} }
@ -203,13 +216,13 @@ class Menu extends Widget
protected function renderItem($item) protected function renderItem($item)
{ {
if (isset($item['url'])) { if (isset($item['url'])) {
$template = isset($item['template']) ? $item['template'] : $this->linkTemplate; $template = ArrayHelper::getValue($item, 'template', $this->linkTemplate);
return strtr($template, array( return strtr($template, array(
'{url}' => Html::url($item['url']), '{url}' => Html::url($item['url']),
'{label}' => $item['label'], '{label}' => $item['label'],
)); ));
} else { } else {
$template = isset($item['template']) ? $item['template'] : $this->labelTemplate; $template = ArrayHelper::getValue($item, 'template', $this->labelTemplate);
return strtr($template, array( return strtr($template, array(
'{label}' => $item['label'], '{label}' => $item['label'],
)); ));
@ -284,5 +297,4 @@ class Menu extends Widget
} }
return false; return false;
} }
} }

2
tests/unit/framework/i18n/FormatterTest.php

@ -83,6 +83,6 @@ class FormatterTest extends TestCase
{ {
$time = time(); $time = time();
$this->assertSame(date('n/j/y', $time), $this->formatter->asDate($time)); $this->assertSame(date('n/j/y', $time), $this->formatter->asDate($time));
$this->assertSame(date('M j, Y', $time), $this->formatter->asDate($time, 'long')); $this->assertSame(date('F j, Y', $time), $this->formatter->asDate($time, 'long'));
} }
} }

Loading…
Cancel
Save