r52079 (merged from branches/roa)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@59890 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2008-08-06 02:16:16 +00:00
parent b331b93dbc
commit 8c05c9985a
5 changed files with 38 additions and 28 deletions

View File

@ -828,6 +828,38 @@ class ViewableData extends Object implements IteratorAggregate {
}
}
/**
* Get part of class ancestry for css-class-usage.
* Avoids having to subclass just to built templates with new css-classes,
* and allows for versatile css inheritance and overrides.
*
* <example>
* <body class="$CSSClasses">
* </example>
*
* @uses {@link ClassInfo}
*
* @param string Classname to stop traversing upwards the ancestry (Default: ViewableData)
* @return string space-separated attribute encoded classes
*/
function CSSClasses($stopAtClass = false) {
global $_ALL_CLASSES;
if(!$stopAtClass) $stopAtClass = 'ViewableData';
$classes = array();
$classAnchestry = ClassInfo::ancestry($this->class);
$viewableDataAnchestry = ClassInfo::ancestry($stopAtClass);
foreach($classAnchestry as $anchestor) {
if(!in_array($anchestor, $viewableDataAnchestry)) $classes[] = $anchestor;
}
// optionally add template identifier
if(isset($this->template) && $this->template != $this->class) {
$classes[] = $this->template;
}
return Convert::raw2att(implode(" ", $classes));
}
/**
@ -835,7 +867,8 @@ class ViewableData extends Object implements IteratorAggregate {
* @var mixed
*/
public static $casting = array(
'BaseHref' => 'Varchar'
'BaseHref' => 'Varchar',
'CSSClasses' => 'Varchar',
);
/**

View File

@ -975,29 +975,6 @@ JS
return $idField->Value();
}
/**
* Get part of class ancestry for css-class-usage.
* Avoids having to subclass just to built templates with new css-classes.
*/
function Classes() {
global $_ALL_CLASSES;
$items = array();
$parents = $_ALL_CLASSES['parents'][$this->class];
foreach($parents as $parent) {
if(!in_array($parent,$_ALL_CLASSES['parents']["TableListField"])) {
$items[] = $parent;
}
}
$items[] = $this->class;
if($this->template != $this->class) {
$items[] = $this->template;
}
return implode(" ", $items) . ' ' . $this->extraClass();
}
/**

View File

@ -1,4 +1,4 @@
<div id="$id" class="$Classes field">
<div id="$id" class="$CSSClasses field">
<div class="middleColumn">
<% include TableListField_PageControls %>
<table class="data">
@ -37,7 +37,7 @@
<% if Markable %><th width="18">&nbsp;</th><% end_if %>
<td><i>$SummaryTitle</i></td>
<% control SummaryFields %>
<td<% if Function %> class="$Function"<% end_if %>>$SummaryValue</td>
<td<% if Function %> class="$Function"<% end_if %>>&nbsp;</td>
<% end_control %>
<% if Can(show) %><td width="18">&nbsp;</td><% end_if %>
<% if Can(edit) %><td width="18">&nbsp;</td><% end_if %>

View File

@ -1,4 +1,4 @@
<div id="$id" class="$Classes field">
<div id="$id" class="$CSSClasses field">
<div class="middleColumn">
<% include TableListField_PageControls %>
<% if Message %>

View File

@ -1,4 +1,4 @@
<div id="$id" class="$Classes TableField field">
<div id="$id" class="$CSSClasses TableField field">
<% if Print %><% else %><% include TableListField_PageControls %><% end_if %>
<table class="data">
<thead>