Commit 91e67a9b authored by Côme Chilliet's avatar Côme Chilliet
Browse files

feat(management) Moved list HTML in a smarty template

parent 6b17a2df
<table class="listing-container">
<tbody>
<tr>
<td class="list">
<div class="contentboxh">
<p class="contentboxh">&nbsp;{$HEADLINE}&nbsp;{$SIZELIMIT}</p>
</div>
<input type="hidden" value="{$PID}" name="PID"/>
<div style="width:100%;">
<table class="listingTable management">
<thead><tr>
{if $multiSelect}
<th class="checkbox">
<input type="checkbox" id="select_all" name="select_all" title="{t}Select all{/t}" onClick='toggle_all_("listing_selected_[0-9]*$","select_all");' />
</th>
{/if}
{foreach from=$headers key=index item=header}
{if $header.sortable}
<th {$header.props}><a href="?plug={$PLUG}&amp;PID={$PID}&amp;act=SORT_{$index}">{$header.label|escape}
{if isset($header.sortdirection)}
&nbsp;<img title="{if $header.sortdirection}{t}Up{/t}{else}{t}Down{/t}{/if}" src="geticon.php?context=actions&amp;size=16&amp;icon=view-sort-{if $header.sortdirection}descending{else}ascending{/if}" alt="{if $header.sortdirection}{t}Sort up{/t}{else}{t}Sort down{/t}{/if}"/>
{/if}
</a></th>
{else}
<th {$header.props}>{$header.label|escape}</th>
{/if}
{/foreach}
</tr></thead>
<div class="contentboxb" style="background:white;">
<table>
<tbody>
<tr>
{foreach from=$NAVIGATION item="action"}
<td class="{$action.class}">
{if $action.enabled}
<input type="image" src="{$action.icon|escape}"
name="{$action.id}" title="{$action.desc}" alt="{$action.name}"/>
{else}
<img src="{$action.icon|escape}&amp;disabled=1" alt="{$action.name}"/>
{/if}
&nbsp;</td>
{/foreach}
{if $BASE}<td><img src="images/lists/seperator.png" alt="-" height="16" width="1" class="center"/>&nbsp;</td><td>{t}Base{/t} {$BASE}&nbsp;</td>{/if}
{if $ACTIONS}<td><img src="images/lists/seperator.png" alt="-" height="16" width="1" class="center"/>&nbsp;</td><td>{$ACTIONS}</td>{/if}
</tr>
</tbody>
</table>
</div>
<tbody>
{if (count($rows) == 0)}
<tr><td colspan="{$columnCount}" class="filler">&nbsp;</td></tr>
{/if}
<div style="margin-top:4px;">
{$LIST}
</div>
</td>
<td class="filter">
{$FILTER}
</td>
</tr>
{foreach from=$rows item=row}
<tr class="{' '|implode:$row.classes}">
{if $multiSelect}
<td class="checkbox">
<input type="checkbox" id="listing_selected_{$row.index}" name="listing_selected_{$row.index}"/>
</td>
{/if}
{foreach from=$row.cells item=cell}
<td {$cell.props}>{$cell.render}</td>
{/foreach}
</tr>
{/foreach}
</tbody>
</table>
</div>
{if ($showFooter)}
<div class="nlistFooter">
{foreach from=$objectCounts item=type}
<img src="{$type.icon|escape}" title="{$type.name|escape}" alt="{$type.name|escape}"/>&nbsp;{$type.count}&nbsp;&nbsp;&nbsp;&nbsp;
{/foreach}
<input type="hidden" name="ignore"/>
</div>
{/if}
<table class="listing-container">
<tbody>
<tr>
<td class="list">
<div class="contentboxh">
<p class="contentboxh">&nbsp;{$HEADLINE}&nbsp;{$SIZELIMIT}</p>
</div>
<div class="contentboxb" style="background:white;">
<table>
<tbody>
<tr>
{foreach from=$NAVIGATION item="action"}
<td class="{$action.class}">
{if $action.enabled}
<input type="image" src="{$action.icon|escape}"
name="{$action.id}" title="{$action.desc}" alt="{$action.name}"/>
{else}
<img src="{$action.icon|escape}&amp;disabled=1" alt="{$action.name}"/>
{/if}
&nbsp;</td>
{/foreach}
{if $BASE}<td><img src="images/lists/seperator.png" alt="-" height="16" width="1" class="center"/>&nbsp;</td><td>{t}Base{/t} {$BASE}&nbsp;</td>{/if}
{if $ACTIONS}<td><img src="images/lists/seperator.png" alt="-" height="16" width="1" class="center"/>&nbsp;</td><td>{$ACTIONS}</td>{/if}
</tr>
</tbody>
</table>
</div>
<div style="margin-top:4px;">
{$LIST}
</div>
</td>
<td class="filter">
{$FILTER}
</td>
</tr>
</tbody>
</table>
<input type="hidden" name="ignore"/>
......@@ -37,11 +37,7 @@ class ListingEntry implements ArrayAccess
public function offsetSet($offset, $value)
{
if (is_null($offset)) {
$this->container[] = $value;
} else {
$this->attrs[$offset] = $value;
}
$this->attrs[$offset] = $value;
}
public function offsetExists($offset)
......
......@@ -415,11 +415,14 @@ class management
{
global $config;
$list = $this->listing->render();
$filter = $this->filter->render();
$smarty = get_smarty();
$smarty->assign('usePrototype', 'true');
$smarty->assign('FILTER', $this->filter->render());
$smarty->assign('FILTER', $filter);
$smarty->assign('LIST', $list);
$smarty->assign('SIZELIMIT', print_sizelimit_warning());
$smarty->assign('LIST', $this->listing->render());
$smarty->assign('MULTISELECT', $this->listing->multiSelect);
// Assign navigation elements
......@@ -432,7 +435,7 @@ class management
// Assign summary
$smarty->assign('HEADLINE', $this->headline);
return $this->getHeader().$smarty->fetch(get_template_path('management/list.tpl'));
return $this->getHeader().$smarty->fetch(get_template_path('management/management.tpl'));
}
function renderActionMenu()
......
......@@ -142,7 +142,6 @@ class managementListing
protected $objectTypeCount = array();
//~ protected $objectDnMapping = array();
//~ protected $snapshotHandler = NULL;
protected $height = 0;
protected $baseSelector;
//~ protected $filterCache = array();
......@@ -208,16 +207,6 @@ class managementListing
return $this->columns;
}
/*!
* \brief Set the height
*
* \param integer $height
*/
function setHeight($height)
{
$this->height = $height;
}
/*!
* \brief Set a SnapshotHandler
*
......@@ -269,16 +258,13 @@ class managementListing
$this->sortDirection[$index] = FALSE;
}
$sorter = '';
$this->header[$index] = array(
'props' => $column->getHtmlProps(),
'sortable' => $column->isSortable(),
'label' => $column->getLabel(),
);
if (($index == $this->sortColumn) && $column->isSortable()) {
$sorter = '&nbsp;<img title="'.($this->sortDirection[$index] ? _('Up') : _('Down')).'" src="geticon.php?context=actions&amp;size=16&amp;icon=view-sort-'.($this->sortDirection[$index] ? 'descending' : 'ascending').'" alt="'.($this->sortDirection[$index] ? _('Sort up') : _('Sort down')).'"/>';
}
$link = 'href="?plug='.$_GET['plug'].'&amp;PID='.$this->pid.'&amp;act=SORT_'.$index.'"';
if ($column->isSortable()) {
$this->header[$index] = '<th '.$column->getHtmlProps().'><a '.$link.'>'.$column->getLabel().$sorter.'</a></th>';
} else {
$this->header[$index] = '<th '.$column->getHtmlProps().'>'.$column->getLabel().'</th>';
$this->header[$index]['sortdirection'] = $this->sortDirection[$index];
}
}
}
......@@ -295,86 +281,63 @@ class managementListing
$this->renderHeader();
// Initialize list
$result = '<input type="hidden" value="'.$this->pid.'" name="PID"/>'."\n";
$height = 450;
if ($this->height != 0) {
$result .= '<input type="hidden" value="'.$this->height.'" id="d_height"/>'."\n";
$height = $this->height;
}
$result .= '<div style="width:100%;">'."\n";
$result .= '<table class="listingTable management">'."\n";
// Build list header
$result .= '<thead><tr>'."\n";
if ($this->multiSelect) {
$result .= '<th class="checkbox"><input type="checkbox" id="select_all" name="select_all" title="'._('Select all').'" onClick=\'toggle_all_("listing_selected_[0-9]*$","select_all");\' /></th>'."\n";
}
foreach ($this->header as $header) {
$result .= $header;
}
$result .= '</tr></thead>'."\n";
// Build list body
$result .= '<tbody>'."\n";
// No results? Just take an empty colspanned row
if (count($this->entries) == 0) {
$result .= '<tr><td colspan="'.(count($this->columns) + ($this->multiSelect ? 1 : 0)).'" class="filler">&nbsp;</td></tr>'."\n";
}
$smarty = get_smarty();
$smarty->assign('PID', $this->pid);
$smarty->assign('PLUG', $_GET['plug']);
$smarty->assign('multiSelect', $this->multiSelect);
$smarty->assign('showFooter', $this->showFooter);
$smarty->assign('headers', $this->header);
// Fill with contents, sort as configured
$row = 0;
foreach ($this->entries as $dn => &$entry) {
$trow = '';
$rowclasses = array();
$smarty->assign('columnCount', (count($this->columns) + ($this->multiSelect ? 1 : 0)));
// Render multi select if needed
if ($this->multiSelect) {
$trow .= '<td class="checkbox"><input type="checkbox" id="listing_selected_'.$row.'" name="listing_selected_'.$row.'"/></td>'."\n";
}
// Complete list by sorting entries and appending them to the output
$entryIterator = $this->getIterator();
foreach ($this->columns as $index => $column) {
$renderedCell = $column->renderCell($entry);
$trow .= '<td '.$column->getHtmlCellProps().'>'.$renderedCell.'</td>'."\n";
$rowclasses = array_merge($rowclasses, $column->getRowClasses($entry));
$rows = array();
foreach ($entryIterator as $entry) {
$row = array(
'cells' => array(),
'classes' => array(),
);
foreach ($this->columns as $column) {
$row['cells'][] = array(
'props' => $column->getHtmlCellProps(),
'render' => $column->renderCell($entry)
);
$row['classes'] = array_merge($row['classes'], $column->getRowClasses($entry));
}
// Save rendered entry
$entry['render'] = '<tr class="'.implode(' ', $rowclasses).'">'.$trow."</tr>\n";
$row++;
}
unset($entry);
$row['index'] = $entry->row;
// Complete list by sorting entries and appending them to the output
$entryIterator = $this->getIterator();
foreach ($entryIterator as $row => $entry) {
$result .= $entry['render'];
$rows[] = $row;
}
// Close list body
$result .= "</tbody></table></div>";
$smarty->assign('rows', $rows);
// Add the footer if requested
if ($this->showFooter) {
$result .= '<div class="nlistFooter">';
$types = array();
foreach ($this->parent->objectTypes as $type) {
if (isset($this->objectTypeCount[$type])) {
$infos = objects::infos($type);
$result .= '<img src="'.htmlentities($infos['icon'], ENT_COMPAT, 'UTF-8').'" title="'.$infos['name'].'" alt="'.$infos['name'].'"/>&nbsp;'.$this->objectTypeCount[$type].'&nbsp;&nbsp;&nbsp;&nbsp;';
$types[] = array(
'name' => $infos['name'],
'icon' => $infos['icon'],
'count' => $this->objectTypeCount[$type],
);
}
if (isset($this->objectTypeCount['template_'.$type])) {
$infos = objects::infos($type);
$result .= '<img src="'.htmlentities('geticon.php?context=devices&icon=template&size=16', ENT_COMPAT, 'UTF-8').'" title="'.sprintf(_('%s template'), $infos['name']).'" alt="'.sprintf(_('%s template'), $infos['name']).'"/>&nbsp;'.$this->objectTypeCount['template_'.$type].'&nbsp;&nbsp;&nbsp;&nbsp;';
$types[] = array(
'name' => sprintf(_('%s template'), $infos['name']),
'icon' => 'geticon.php?context=devices&icon=template&size=16',
'count' => $this->objectTypeCount['template_'.$type],
);
}
}
$result .= '</div>';
$smarty->assign('objectCounts', $types);
}
return $result;
return $smarty->fetch(get_template_path('management/list.tpl'));
}
function getIterator()
......
......@@ -93,7 +93,7 @@ class Column
if (isset($this->label)) {
return _($this->label);
} else {
return '&nbsp;';
return ' ';
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment