Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementing JGrid in some backend components #23

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,109 +57,10 @@
</fieldset>
<div class="clr"> </div>

<table class="adminlist">
<thead>
<tr>
<th width="1%">
<input type="checkbox" name="checkall-toggle" value="" title="<?php echo JText::_('JGLOBAL_CHECK_ALL'); ?>" onclick="Joomla.checkAll(this)" />
</th>
<th>
<?php echo JHtml::_('grid.sort', 'JGLOBAL_TITLE', 'a.title', $listDirn, $listOrder); ?>
</th>
<th width="5%">
<?php echo JHtml::_('grid.sort', 'JSTATUS', 'a.published', $listDirn, $listOrder); ?>
</th>
<th width="10%">
<?php echo JHtml::_('grid.sort', 'JGRID_HEADING_ORDERING', 'a.lft', $listDirn, $listOrder); ?>
<?php if ($saveOrder) :?>
<?php echo JHtml::_('grid.order', $this->items, 'filesave.png', 'categories.saveorder'); ?>
<?php endif; ?>
</th>
<th width="10%">
<?php echo JHtml::_('grid.sort', 'JGRID_HEADING_ACCESS', 'access_level', $listDirn, $listOrder); ?>
</th>
<th width="5%" class="nowrap">
<?php echo JHtml::_('grid.sort', 'JGRID_HEADING_LANGUAGE', 'language', $this->state->get('list.direction'), $this->state->get('list.ordering')); ?>
</th>
<th width="1%" class="nowrap">
<?php echo JHtml::_('grid.sort', 'JGRID_HEADING_ID', 'a.id', $listDirn, $listOrder); ?>
</th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="15">
<?php echo $this->pagination->getListFooter(); ?>
</td>
</tr>
</tfoot>
<tbody>
<?php
$originalOrders = array();
foreach ($this->items as $i => $item) :
$orderkey = array_search($item->id, $this->ordering[$item->parent_id]);
$canEdit = $user->authorise('core.edit', $extension.'.category.'.$item->id);
$canCheckin = $user->authorise('core.admin', 'com_checkin') || $item->checked_out == $userId || $item->checked_out == 0;
$canEditOwn = $user->authorise('core.edit.own', $extension.'.category.'.$item->id) && $item->created_user_id == $userId;
$canChange = $user->authorise('core.edit.state', $extension.'.category.'.$item->id) && $canCheckin;
?>
<tr class="row<?php echo $i % 2; ?>">
<td class="center">
<?php echo JHtml::_('grid.id', $i, $item->id); ?>
</td>
<td>
<?php echo str_repeat('<span class="gi">|&mdash;</span>', $item->level-1) ?>
<?php if ($item->checked_out) : ?>
<?php echo JHtml::_('jgrid.checkedout', $i, $item->editor, $item->checked_out_time, 'categories.', $canCheckin); ?>
<?php endif; ?>
<?php if ($canEdit || $canEditOwn) : ?>
<a href="<?php echo JRoute::_('index.php?option=com_categories&task=category.edit&id='.$item->id.'&extension='.$extension);?>">
<?php echo $this->escape($item->title); ?></a>
<?php else : ?>
<?php echo $this->escape($item->title); ?>
<?php endif; ?>
<p class="smallsub" title="<?php echo $this->escape($item->path);?>">
<?php echo str_repeat('<span class="gtr">|&mdash;</span>', $item->level-1) ?>
<?php if (empty($item->note)) : ?>
<?php echo JText::sprintf('JGLOBAL_LIST_ALIAS', $this->escape($item->alias));?>
<?php else : ?>
<?php echo JText::sprintf('JGLOBAL_LIST_ALIAS_NOTE', $this->escape($item->alias), $this->escape($item->note));?>
<?php endif; ?></p>
</td>
<td class="center">
<?php echo JHtml::_('jgrid.published', $item->published, $i, 'categories.', $canChange);?>
</td>
<td class="order">
<?php if ($canChange) : ?>
<?php if ($saveOrder) : ?>
<span><?php echo $this->pagination->orderUpIcon($i, isset($this->ordering[$item->parent_id][$orderkey - 1]), 'categories.orderup', 'JLIB_HTML_MOVE_UP', $ordering); ?></span>
<span><?php echo $this->pagination->orderDownIcon($i, $this->pagination->total, isset($this->ordering[$item->parent_id][$orderkey + 1]), 'categories.orderdown', 'JLIB_HTML_MOVE_DOWN', $ordering); ?></span>
<?php endif; ?>
<?php $disabled = $saveOrder ? '' : 'disabled="disabled"'; ?>
<input type="text" name="order[]" size="5" value="<?php echo $orderkey + 1;?>" <?php echo $disabled ?> class="text-area-order" />
<?php $originalOrders[] = $orderkey + 1; ?>
<?php else : ?>
<?php echo $orderkey + 1;?>
<?php endif; ?>
</td>
<td class="center">
<?php echo $this->escape($item->access_level); ?>
</td>
<td class="center nowrap">
<?php if ($item->language=='*'):?>
<?php echo JText::alt('JALL','language'); ?>
<?php else:?>
<?php echo $item->language_title ? $this->escape($item->language_title) : JText::_('JUNDEFINED'); ?>
<?php endif;?>
</td>
<td class="center">
<span title="<?php echo sprintf('%d-%d', $item->lft, $item->rgt);?>">
<?php echo (int) $item->id; ?></span>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php
echo $this->table;
?>

<?php //Load the batch processing form. ?>
<?php echo $this->loadTemplate('batch'); ?>

Expand All @@ -169,7 +70,7 @@
<input type="hidden" name="boxchecked" value="0" />
<input type="hidden" name="filter_order" value="<?php echo $listOrder; ?>" />
<input type="hidden" name="filter_order_Dir" value="<?php echo $listDirn; ?>" />
<input type="hidden" name="original_order_values" value="<?php echo implode($originalOrders, ','); ?>" />
<input type="hidden" name="original_order_values" value="<?php echo implode($this->originalOrders, ','); ?>" />
<?php echo JHtml::_('form.token'); ?>
</div>
</form>
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,110 @@ public function display($tpl = null)
$options[] = JHtml::_('select.option', '10', JText::_('J10'));

$this->assign('f_levels', $options);

$this->prepareTable();

$this->addToolbar();
parent::display($tpl);
}

/**
* Prepare the table of the view
*
* @since 2.5
*/
protected function prepareTable()
{
$user = JFactory::getUser();
$userId = $user->get('id');
$extension = $this->escape($this->state->get('filter.extension'));
$listOrder = $this->escape($this->state->get('list.ordering'));
$listDirn = $this->escape($this->state->get('list.direction'));
$ordering = ($listOrder == 'a.lft');
$saveOrder = ($listOrder == 'a.lft' && $listDirn == 'asc');

jimport('joomla.html.grid');
$table = new JGrid(array('class' => 'adminlist'));

$table->addColumn('checkbox')
->addColumn('title')
->addColumn('status')
->addColumn('ordering')
->addColumn('access')
->addColumn('language')
->addColumn('id')
;

$table->addRow(array(), 1)
->setRowCell('checkbox', '<input type="checkbox" name="checkall-toggle" value="" title="'.JText::_('JGLOBAL_CHECK_ALL').'" onclick="Joomla.checkAll(this)" />', array('width' => '1%'))
->setRowCell('title', JHtml::_('grid.sort', 'JGLOBAL_TITLE', 'a.title', $listDirn, $listOrder))
->setRowCell('status', JHtml::_('grid.sort', 'JSTATUS', 'a.published', $listDirn, $listOrder), array('width' => '5%'))
->setRowCell('ordering', JHtml::_('grid.sort', 'JGRID_HEADING_ORDERING', 'a.lft', $listDirn, $listOrder).
($saveOrder ? JHtml::_('grid.order', $this->items, 'filesave.png', 'categories.saveorder') : ''), array('width' => '10%'))
->setRowCell('access', JHtml::_('grid.sort', 'JGRID_HEADING_ACCESS', 'access_level', $listDirn, $listOrder), array('width' => '10%'))
->setRowCell('language', JHtml::_('grid.sort', 'JGRID_HEADING_LANGUAGE', 'language', $this->state->get('list.direction'), $this->state->get('list.ordering')), array('width' => '5%', 'class' => 'nowrap'))
->setRowCell('id', JHtml::_('grid.sort', 'JGRID_HEADING_ID', 'a.id', $listDirn, $listOrder), array('width' => '1%', 'class' => 'nowrap'))
;

$table->addRow(array(), 2)
->setRowCell('checkbox', $this->pagination->getListFooter(), array('colspan' => 15))
;
$originalOrders = array();

foreach ($this->items as $i => $item) {
$orderkey = array_search($item->id, $this->ordering[$item->parent_id]);
$canEdit = $user->authorise('core.edit', $extension.'.category.'.$item->id);
$canCheckin = $user->authorise('core.admin', 'com_checkin') || $item->checked_out == $userId || $item->checked_out == 0;
$canEditOwn = $user->authorise('core.edit.own', $extension.'.category.'.$item->id) && $item->created_user_id == $userId;
$canChange = $user->authorise('core.edit.state', $extension.'.category.'.$item->id) && $canCheckin;

$table->addRow(array('class' => 'row'.($i % 2)))
->setRowCell('checkbox', JHtml::_('grid.id', $i, $item->id), array('class' => 'center'));
$table->setRowCell('title', str_repeat('<span class="gi">|&mdash;</span>', $item->level-1));
if ($item->checked_out) {
$table->setRowCell('title', JHtml::_('jgrid.checkedout', $i, $item->editor, $item->checked_out_time, 'categories.', $canCheckin), array(), false);
} else {
if ($canEdit || $canEditOwn) {
$table->setRowCell('title', '<a href="'.JRoute::_('index.php?option=com_categories&task=category.edit&id='.$item->id.'&extension='.$extension).'">
'.$this->escape($item->title).'</a>', array(), false);
} else {
$table->setRowCell('title', $this->escape($item->title), array(), false);
}
$table->setRowCell('title', '<p class="smallsub" title="'.$this->escape($item->path).'">
'.str_repeat('<span class="gtr">|&mdash;</span>', $item->level-1), array(), false);
if (empty($item->note)) {
$table->setRowCell('title', JText::sprintf('JGLOBAL_LIST_ALIAS', $this->escape($item->alias)), array(), false);
} else {
$table->setRowCell('title', JText::sprintf('JGLOBAL_LIST_ALIAS_NOTE', $this->escape($item->alias), $this->escape($item->note)), array(), false);
}
$table->setRowCell('title', '</p>', array(), false);
}

$table->setRowCell('status', JHtml::_('jgrid.published', $item->published, $i, 'categories.', $canChange), array('class' => 'center'));

if ($canChange) {
if ($saveOrder) {
$table->setRowCell('ordering', '<span>'.$this->pagination->orderUpIcon($i, isset($this->ordering[$item->parent_id][$orderkey - 1]), 'categories.orderup', 'JLIB_HTML_MOVE_UP', $ordering).'</span>', array(), false);
$table->setRowCell('ordering', '<span>'.$this->pagination->orderDownIcon($i, $this->pagination->total, isset($this->ordering[$item->parent_id][$orderkey + 1]), 'categories.orderdown', 'JLIB_HTML_MOVE_DOWN', $ordering).'</span>', array(), false);
}
$disabled = $saveOrder ? '' : 'disabled="disabled"';
$table->setRowCell('ordering', '<input type="text" name="order[]" size="5" value="'.($orderkey + 1).'" '.$disabled.' class="text-area-order" />', array(), false);
$originalOrders[] = $orderkey + 1;
} else {
$table->setRowCell('ordering', $orderkey + 1, array(), false);
}

$table->setRowCell('ordering', '', array('class' => 'order'), false);

$table->setRowCell('access', $this->escape($item->access_level), array('class' => 'center nowrap'))
->setRowCell('language', ($item->language == '*') ? JText::alt('JALL','language') : ($item->language_title ? $this->escape($item->language_title) : JText::_('JUNDEFINED')), array('class' => 'center nowrap'))
->setRowCell('id', '<span title="'.sprintf('%d-%d', $item->lft, $item->rgt).'">'.(int) $item->id.'</span>', array('class' => 'center'));
}

$this->originalOrders = $originalOrders;
$this->table = $table;
}

/**
* Add the page title and toolbar.
*
Expand Down Expand Up @@ -135,7 +234,7 @@ protected function addToolbar()
if ($this->state->get('filter.published') == -2 && $canDo->get('core.delete', $component)) {
JToolBarHelper::deleteList('', 'categories.delete', 'JTOOLBAR_EMPTY_TRASH');
}
elseif ($canDo->get('core.edit.state')) {
else if ($canDo->get('core.edit.state')) {
JToolBarHelper::trash('categories.trash');
JToolBarHelper::divider();
}
Expand Down
117 changes: 3 additions & 114 deletions administrator/components/com_users/views/users/tmpl/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,120 +54,9 @@
</fieldset>
<div class="clr"> </div>

<table class="adminlist">
<thead>
<tr>
<th width="1%">
<input type="checkbox" name="checkall-toggle" value="" title="<?php echo JText::_('JGLOBAL_CHECK_ALL'); ?>" onclick="Joomla.checkAll(this)" />
</th>
<th class="left">
<?php echo JHtml::_('grid.sort', 'COM_USERS_HEADING_NAME', 'a.name', $listDirn, $listOrder); ?>
</th>
<th class="nowrap" width="10%">
<?php echo JHtml::_('grid.sort', 'JGLOBAL_USERNAME', 'a.username', $listDirn, $listOrder); ?>
</th>
<th class="nowrap" width="5%">
<?php echo JHtml::_('grid.sort', 'COM_USERS_HEADING_ENABLED', 'a.block', $listDirn, $listOrder); ?>
</th>
<th class="nowrap" width="5%">
<?php echo JHtml::_('grid.sort', 'COM_USERS_HEADING_ACTIVATED', 'a.activation', $listDirn, $listOrder); ?>
</th>
<th class="nowrap" width="10%">
<?php echo JText::_('COM_USERS_HEADING_GROUPS'); ?>
</th>
<th class="nowrap" width="15%">
<?php echo JHtml::_('grid.sort', 'JGLOBAL_EMAIL', 'a.email', $listDirn, $listOrder); ?>
</th>
<th class="nowrap" width="10%">
<?php echo JHtml::_('grid.sort', 'COM_USERS_HEADING_LAST_VISIT_DATE', 'a.lastvisitDate', $listDirn, $listOrder); ?>
</th>
<th class="nowrap" width="10%">
<?php echo JHtml::_('grid.sort', 'COM_USERS_HEADING_REGISTRATION_DATE', 'a.registerDate', $listDirn, $listOrder); ?>
</th>
<th class="nowrap" width="3%">
<?php echo JHtml::_('grid.sort', 'JGRID_HEADING_ID', 'a.id', $listDirn, $listOrder); ?>
</th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="15">
<?php echo $this->pagination->getListFooter(); ?>
</td>
</tr>
</tfoot>
<tbody>
<?php foreach ($this->items as $i => $item) :
$canEdit = $canDo->get('core.edit');
$canChange = $loggeduser->authorise('core.edit.state', 'com_users');
// If this group is super admin and this user is not super admin, $canEdit is false
if ((!$loggeduser->authorise('core.admin')) && JAccess::check($item->id, 'core.admin')) {
$canEdit = false;
$canChange = false;
}
?>
<tr class="row<?php echo $i % 2; ?>">
<td class="center">
<?php if ($canEdit) : ?>
<?php echo JHtml::_('grid.id', $i, $item->id); ?>
<?php endif; ?>
</td>
<td>
<?php if ($canEdit) : ?>
<a href="<?php echo JRoute::_('index.php?option=com_users&task=user.edit&id='.(int) $item->id); ?>" title="<?php echo JText::sprintf('COM_USERS_EDIT_USER', $this->escape($item->name)); ?>">
<?php echo $this->escape($item->name); ?></a>
<?php else : ?>
<?php echo $this->escape($item->name); ?>
<?php endif; ?>
<?php if (JDEBUG) : ?>
<div class="fltrt"><div class="button2-left smallsub"><div class="blank"><a href="<?php echo JRoute::_('index.php?option=com_users&view=debuguser&user_id='.(int) $item->id);?>">
<?php echo JText::_('COM_USERS_DEBUG_USER');?></a></div></div></div>
<?php endif; ?>
</td>
<td class="center">
<?php echo $this->escape($item->username); ?>
</td>
<td class="center">
<?php if ($canChange) : ?>
<?php if ($loggeduser->id != $item->id) : ?>
<?php echo JHtml::_('grid.boolean', $i, !$item->block, 'users.unblock', 'users.block'); ?>
<?php else : ?>
<?php echo JHtml::_('grid.boolean', $i, !$item->block, 'users.block', null); ?>
<?php endif; ?>
<?php else : ?>
<?php echo JText::_($item->block ? 'JNO' : 'JYES'); ?>
<?php endif; ?>
</td>
<td class="center">
<?php echo JHtml::_('grid.boolean', $i, !$item->activation, 'users.activate', null); ?>
</td>
<td class="center">
<?php if (substr_count($item->group_names,"\n") > 1) : ?>
<span class="hasTip" title="<?php echo JText::_('COM_USERS_HEADING_GROUPS').'::'.nl2br($item->group_names); ?>"><?php echo JText::_('COM_USERS_USERS_MULTIPLE_GROUPS'); ?></span>
<?php else : ?>
<?php echo nl2br($item->group_names); ?>
<?php endif; ?>
</td>
<td class="center">
<?php echo $this->escape($item->email); ?>
</td>
<td class="center">
<?php if ($item->lastvisitDate!='0000-00-00 00:00:00'):?>
<?php echo JHtml::_('date',$item->lastvisitDate, 'Y-m-d H:i:s'); ?>
<?php else:?>
<?php echo JText::_('JNEVER'); ?>
<?php endif;?>
</td>
<td class="center">
<?php echo JHtml::_('date',$item->registerDate, 'Y-m-d H:i:s'); ?>
</td>
<td class="center">
<?php echo (int) $item->id; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php
echo $this->table;
?>

<div>
<input type="hidden" name="task" value="" />
Expand Down
Loading