Skip to content

Commit

Permalink
code improvements and solves bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
andrepereiradasilva committed Feb 25, 2016
1 parent 5cd073a commit 94d008f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 25 deletions.
27 changes: 15 additions & 12 deletions administrator/components/com_modules/models/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,28 @@ protected function populateState($ordering = 'a.position', $direction = 'asc')
$this->setState('filter.module', $this->getUserStateFromRequest($this->context . '.filter.module', 'filter_module', '', 'string'));
$this->setState('filter.access', $this->getUserStateFromRequest($this->context . '.filter.access', 'filter_access', '', 'string'));

// If in modal layout on the frontend, state, client and language are always forced.
// If in modal layout on the frontend, state and language are always forced.
if ($app->isSite() && $layout === 'modal')
{
$this->setState('filter.language', 'current');
$this->setState('filter.state', 1);
$this->setState('client_id', 0);
}
// If in backend (modal or not) we get the same fields from the user request.
else
{
$this->setState('filter.language', $this->getUserStateFromRequest($this->context . '.filter.language', 'filter_language', '', 'cmd'));
$this->setState('filter.state', $this->getUserStateFromRequest($this->context . '.filter.state', 'filter_state', null, 'int'));
}

// Special case for the client id.
// Special case for the client id.
if ($app->isSite() || $layout === 'modal')
{
$this->setState('client_id', 0);
}
else
{
$clientId = (int) $this->getUserStateFromRequest($this->context . '.client_id', 'client_id', 0, 'int');
$clientId = (!in_array($clientId, array (0, 1))) ? 0 : $clientId;
$clientId = ($layout === 'modal') ? 0 : $clientId;
$this->setState('client_id', $clientId);
}

Expand Down Expand Up @@ -175,14 +180,14 @@ protected function _getList($query, $limitstart = 0, $limit = 0)
}

// If ordering by fields that doesn't need translate just order the query.
if ($listOrder == 'a.ordering')
if ($listOrder === 'a.ordering')
{
$query->order($this->_db->quoteName('a.position') . ' ASC')
->order($this->_db->quoteName('a.ordering') . ' ' . $this->_db->escape($listDirn));
->order($this->_db->quoteName($listOrder) . ' ' . $this->_db->escape($listDirn));
}
elseif ($listOrder == 'a.position')
elseif ($listOrder === 'a.position')
{
$query->order($this->_db->quoteName('a.position') . ' ' . $this->_db->escape($listDirn))
$query->order($this->_db->quoteName($listOrder) . ' ' . $this->_db->escape($listDirn))
->order($this->_db->quoteName('a.ordering') . ' ASC');
}
else
Expand Down Expand Up @@ -292,10 +297,8 @@ protected function getListQuery()
);

// Filter by client.
if ($clientId = $this->getState('client_id'))
{
$query->where($db->quoteName('a.client_id') . ' = ' . (int) $clientId . ' AND ' . $db->quoteName('e.client_id') . ' = ' . (int) $clientId);
}
$clientId = $this->getState('client_id');
$query->where($db->quoteName('a.client_id') . ' = ' . (int) $clientId . ' AND ' . $db->quoteName('e.client_id') . ' = ' . (int) $clientId);

// Filter by access level.
if ($access = $this->getState('filter.access'))
Expand Down
25 changes: 12 additions & 13 deletions administrator/components/com_modules/views/modules/tmpl/modal.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,18 @@
$editor = JFactory::getApplication()->input->get('editor', '', 'cmd');

JFactory::getDocument()->addScriptDeclaration('
moduleIns = function(type, name) {
var extraVal ,fieldExtra = jQuery("#extra_class");
extraVal = (fieldExtra.length && fieldExtra.val().length) ? "," + fieldExtra.val() : "";
parent.window.jInsertEditorText("{loadmodule " + type + "," + name + extraVal + "}", "' . $editor . '");
parent.window.jModalClose();
}
modulePosIns = function(position) {
var extraVal ,fieldExtra = jQuery("#extra_class");
extraVal = (fieldExtra.length && fieldExtra.val().length) ? "," + fieldExtra.val() : "";
parent.window.jInsertEditorText("{loadposition " + position + extraVal + "}", "' . $editor . '");
parent.window.jModalClose();
}
');
moduleIns = function(type, name) {
var extraVal ,fieldExtra = jQuery("#extra_class");
extraVal = (fieldExtra.length && fieldExtra.val().length) ? "," + fieldExtra.val() : "";
window.parent.jInsertEditorText("{loadmodule " + type + "," + name + extraVal + "}", "' . $editor . '");
window.parent.jModalClose();
};
modulePosIns = function(position) {
var extraVal ,fieldExtra = jQuery("#extra_class");
extraVal = (fieldExtra.length && fieldExtra.val().length) ? "," + fieldExtra.val() : "";
window.parent.jInsertEditorText("{loadposition " + position + extraVal + "}", "' . $editor . '");
window.parent.jModalClose();
};');
?>
<div style="padding-top: 25px;"></div>
<form action="<?php echo JRoute::_('index.php?option=com_modules&view=modules&layout=modal&tmpl=component&' . JSession::getFormToken() . '=1'); ?>" method="post" name="adminForm" id="adminForm">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ public function display($tpl = null)
{
$this->addToolbar();
}
else
{
// If in modal layout client id selector should not exist.
$this->filterForm->removeField('client_id', '');
}

// Include the component HTML helpers.
JHtml::addIncludePath(JPATH_COMPONENT . '/helpers/html');
Expand Down

0 comments on commit 94d008f

Please sign in to comment.