Пишу свой компонент. делаю сортировку перетаскиванием. Нашел в интернете
https://joomla.stackexchange.com/questions/14374/adding-drag-n-drop-ordering-in-component в котором описано как сделать. все сделал по нему, drag-n-drop заработал но при отработке saveOrderAjax возвращает ошибку
<br />
<b>Fatal error</b>: Call to undefined method Fgbu_ReportModelDeployEgrn_Stages::saveorder() in <b>/srv/www/report/libraries/legacy/controller/admin.php</b> on line <b>390</b><br />
в контроллере (class JControllerAdmin ) ругается на строку $model = $this->getModel();
Часть кода с "libraries/legacy/controller/admin.php"
public function saveOrderAjax()
{
// Get the input
$pks = $this->input->post->get('cid', array(), 'array');
$order = $this->input->post->get('order', array(), 'array');
// Sanitize the input
$pks = ArrayHelper::toInteger($pks);
$order = ArrayHelper::toInteger($order);
// Get the model
$model = $this->getModel();
// Save the ordering
$return = $model->saveorder($pks, $order);
if ($return)
{
echo '1';
}
// Close the application
JFactory::getApplication()->close();
}
Код с моей компоненты (вывод списка)
контроллер
class Fgbu_ReportControllerDeployEgrn_Stages extends JControllerAdmin
{
public function getModel($name = 'DeployEgrn_Stages', $prefix = 'Fgbu_ReportModel')
{
$model = parent::getModel($name, $prefix, array('ignore_request' => true));
return $model;
}
}
модель
class Fgbu_ReportModelDeployEgrn_Stages extends JModelList
{
public function __construct($config = array())
{
if (empty($config['filter_fields'])) {
$config['filter_fields'] = array(
'id', 'de_stage.id',
'name', 'de_stage.name',
'category', 'de_stage.name',
'ordering', 'de_stage.ordering',
'catid', 'de_stage.catid', 'category_title', 'category_id', 'cat.title'
);
}
parent::__construct($config);
}
public function getItems()
{
$items = parent::getItems();
if (!empty ($items)) {
/* $cat = 0;
$stage = 0;
$cattmp = '';
foreach ($items as $item) {
if ($cattmp != $item->catid) {
$cat ++;
$stage = 0;
$cattmp = $item->catid;
}
$item->sequence= $cat.'.'.++$stage;
} */
}
return $items;
}
protected function getListQuery()
{
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->select("de_stage.*")
->from('#__fgbureport_deployegrn_stage as de_stage ');
$query->select('cat.title as category')
->leftJoin('#__categories AS cat ON cat.id = de_stage.catid');
// Фильтр категории
$categoryId = $this->getState('filter.category_id');
if (is_numeric($categoryId))
{
$query->where($db->quoteName('de_stage.catid'). ' = ' . (int) $categoryId);
}
// Фильтр поиска
$search = $this->getState('filter.search');
if (!empty($search))
{
$search = $db->quote('%' . str_replace(' ', '%', $db->escape(trim($search), true). '%'));
$query->where('(de_stage.name LIKE ' . $search . ' OR de_stage.action LIKE ' . $search . ' OR de_stage.result LIKE ' . $search . ')');
}
$orderCol = $this->state->get('list.ordering', 'de_stage.ordering');
$orderDirn = $this->state->get('list.direction', 'DESC');
$query->order($db->escape($orderCol). ' ' . $db->escape($orderDirn));
return $query;
}
protected function populateState($ordering = 'de_stage.ordering', $direction = 'desc')
{
parent::populateState($ordering, $direction);
}
}
Вьюха
class Fgbu_ReportViewDeployEgrn_Stages extends JViewLegacy
{
function display($tpl = null)
{
$this->items = $this->get('Items');
$this->pagination = $this->get('Pagination');
$this->state = $this->get('State');
$this->filterForm = $this->get('FilterForm');
$this->activeFilters = $this->get('ActiveFilters');
if (count($errors = $this->get('Errors')))
{
JError::raiseError(500, implode("\n", $errors));
return false;
}
$this->addToolBar();
$this->sidebar = JHtmlSidebar::render();
parent::display($tpl);
}
protected function addToolBar()
{
JToolBarHelper::title(JText::_('COM_FGBU_REPORT').': '.JText::_('COM_FGBU_REPORT_DEPLOYEGRN_STAGE'), 'Fgbu_Report');
JToolBarHelper::addNew('deployegrn_stage.add');
JToolBarHelper::editList('deployegrn_stage.edit');
JToolbarHelper::divider();
default
<?php
defined('_JEXEC') or die('Restricted Access');
$listOrder = $this->escape($this->state->get('list.ordering'));
$listDirn = $this->escape($this->state->get('list.direction'));
$saveOrder = $listOrder == 'de_stage.ordering';
if ($saveOrder)
{
$saveOrderingUrl = 'index.php?option=com_fgbu_report&task=deployegrn_stages.saveOrderAjax&tmpl=component';
JHtml::_('sortablelist.sortable', 'deployegrn_stages_list', 'adminForm', strtolower($listDirn), $saveOrderingUrl);
}
?>
<form action="<?php echo JRoute::_('index.php?option=com_fgbu_report&view=deployegrn_stages'); ?>" method="post" name="adminForm" id="adminForm">
<?php if (!empty( $this->sidebar)) : ?>
<div id="j-sidebar-container" class="span2">
<?php echo $this->sidebar; ?>
</div>
<div id="j-main-container" class="span10">
<?php else : ?>
<div id="j-main-container">
<?php endif;?>
<?php echo JLayoutHelper::render('joomla.searchtools.default', array('view' => $this, 'options' => array('filterButton' => true,'totalResults' => count($this->items),))); ?>
<table class="table table-striped" id="deployegrn_stages_list">
<thead>
<tr>
<th width="1%" class="nowrap center hidden-phone">
<?php echo JHtml::_('searchtools.sort', '', 'de_stage.ordering', $listDirn, $listOrder, null, 'asc', 'JGRID_HEADING_ORDERING', 'icon-menu-2'); ?>
</th>
<th width="1%" class="center"><?php echo JHtml::_('grid.checkall'); ?></th>
<th><?php echo JHtml::_('searchtools.sort', 'Этап', 'category', $listDirn, $listOrder); ?></th>
<th><?php echo JHtml::_('searchtools.sort', 'Наименование', 'de_stage.name', $listDirn, $listOrder); ?></th>
<th>Воздействие ЦА</th>
<th>Ожидаемый результат</th>
</tr>
</thead>
<tbody>
<?php
foreach($this->items as $i => $item){
?>
<tr class="row<?php echo $i % 2; ?>">
<td class="order nowrap center hidden-phone">
<?php
$iconClass = '';
if (!$saveOrder)
{
$iconClass = ' inactive tip-top hasTooltip" title="' . JHtml::_('tooltipText', 'JORDERINGDISABLED');
}
?>
<span class="sortable-handler<?php echo $iconClass ?>">
<span class="icon-menu" aria-hidden="true"></span>
</span>
<?php if ($saveOrder) : ?>
<input type="text" style="display:none" name="order[]" size="5" value="<?php echo $item->ordering; ?>" class="width-20 text-area-order " />
<?php endif; ?>
</td>
<td class="center">
<?php echo JHtml::_('grid.id', $i, $item->id); ?>
</td>
<td><?php echo $item->category; ?></td>
<td><a href="<?php echo JRoute::_('index.php?option=com_fgbu_report&task=deployegrn_stage.edit&id='.$item->id);?>"><?php echo $item->name; ?></a></td>
<td><?php echo $item->action; ?></td>
<td><?php echo $item->result; ?></td>
</tr>
<?php } ?>
</tbody>
<tfoot>
<tr>
<td colspan="10"><?php echo $this->pagination->getListFooter(); ?></td>
</tr>
</tfoot>
</table>
<div>
<input type="hidden" name="task" value="" />
<input type="hidden" name="boxchecked" value="0" />
<?php echo JHtml::_('form.token'); ?>
</div>
</div>
</form>
Заранее спасибо за помощь