Skip to content
This repository has been archived by the owner on May 26, 2020. It is now read-only.

Commit

Permalink
Merge pull request #62 from C-Lodder/dropdown
Browse files Browse the repository at this point in the history
Toolbar dropdown support
  • Loading branch information
C-Lodder committed Nov 1, 2016
2 parents 0723c9a + 89cb6f7 commit 8293f8c
Show file tree
Hide file tree
Showing 12 changed files with 157 additions and 25 deletions.
26 changes: 19 additions & 7 deletions administrator/components/com_contact/views/contact/view.html.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,14 @@ protected function addToolbar()
// For new records, check the create permission.
if ($isNew && (count($user->getAuthorisedCategories('com_contact', 'core.create')) > 0))
{
JToolbarHelper::apply('contact.apply');
JToolbarHelper::save('contact.save');
JToolbarHelper::save2new('contact.save2new');
JToolbarHelper::saveGroup(
[
['apply', 'contact.apply'],
['save', 'contact.save'],
['save2new', 'contact.save2new']
],
'btn-success'
);
}

JToolbarHelper::cancel('contact.cancel');
Expand All @@ -125,31 +130,38 @@ protected function addToolbar()
{
// Since it's an existing record, check the edit permission, or fall back to edit own if the owner.
$itemEditable = $canDo->get('core.edit') || ($canDo->get('core.edit.own') && $this->item->created_by == $userId);

$toolbarButtons = [];

// Can't save the record if it's checked out and editable
if (!$checkedOut && $itemEditable)
{
JToolbarHelper::apply('contact.apply');
JToolbarHelper::save('contact.save');
$toolbarButtons[] = ['apply', 'contact.apply'];
$toolbarButtons[] = ['save', 'contact.save'];

// We can save this record, but check the create permission to see if we can return to make a new one.
if ($canDo->get('core.create'))
{
JToolbarHelper::save2new('contact.save2new');
$toolbarButtons[] = ['save2new', 'contact.save2new'];
}
}

// If checked out, we can still save
if ($canDo->get('core.create'))
{
JToolbarHelper::save2copy('contact.save2copy');
$toolbarButtons[] = ['save2copy', 'contact.save2copy'];
}

if ($this->state->params->get('save_history', 0) && $itemEditable)
{
JToolbarHelper::versions('com_contact.contact', $this->item->id);
}

JToolbarHelper::saveGroup(
$toolbarButtons,
'btn-success'
);

JToolbarHelper::cancel('contact.cancel', 'JTOOLBAR_CLOSE');
}

Expand Down
66 changes: 59 additions & 7 deletions administrator/includes/toolbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ public static function apply($task = 'apply', $alt = 'JTOOLBAR_APPLY')
$bar = JToolbar::getInstance('toolbar');

// Add an apply button
$bar->appendButton('Apply', 'apply', $alt, $task, false);
$bar->appendButton('Standard', 'apply', $alt, $task, false);
}

/**
Expand All @@ -483,12 +483,12 @@ public static function apply($task = 'apply', $alt = 'JTOOLBAR_APPLY')
*
* @since 1.5
*/
public static function save($task = 'save', $alt = 'JTOOLBAR_SAVE')
public static function save($task = 'save', $alt = 'JTOOLBAR_SAVE', $group = false)
{
$bar = JToolbar::getInstance('toolbar');

// Add a save button.
$bar->appendButton('Standard', 'save', $alt, $task, false);
$bar->appendButton('Standard', 'save', $alt, $task, false, $group);
}

/**
Expand All @@ -502,12 +502,12 @@ public static function save($task = 'save', $alt = 'JTOOLBAR_SAVE')
*
* @since 1.6
*/
public static function save2new($task = 'save2new', $alt = 'JTOOLBAR_SAVE_AND_NEW')
public static function save2new($task = 'save2new', $alt = 'JTOOLBAR_SAVE_AND_NEW', $group = false)
{
$bar = JToolbar::getInstance('toolbar');

// Add a save and create new button.
$bar->appendButton('Standard', 'save-new', $alt, $task, false);
$bar->appendButton('Standard', 'save-new', $alt, $task, false, $group);
}

/**
Expand All @@ -522,12 +522,12 @@ public static function save2new($task = 'save2new', $alt = 'JTOOLBAR_SAVE_AND_NE
*
* @since 1.6
*/
public static function save2copy($task = 'save2copy', $alt = 'JTOOLBAR_SAVE_AS_COPY')
public static function save2copy($task = 'save2copy', $alt = 'JTOOLBAR_SAVE_AS_COPY', $group = false)
{
$bar = JToolbar::getInstance('toolbar');

// Add a save and create new button.
$bar->appendButton('Standard', 'save-copy', $alt, $task, false);
$bar->appendButton('Standard', 'save-copy', $alt, $task, false, $group);
}

/**
Expand Down Expand Up @@ -632,6 +632,58 @@ public static function versions($typeAlias, $itemId, $height = 800, $width = 500
$bar->appendButton('Custom', $layout->render($options), 'versions');
}

/**
* Writes a save button for a given option, with an additional dropdown
*
* @param array $buttons An array of buttons
* @param string $class The button class
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public static function saveGroup($buttons = array(), $class = 'btn-success')
{
// Options array for JLayout
$options = array();
$options['class'] = $class;

$validOptions = array(
'apply' => 'JTOOLBAR_APPLY',
'save' => 'JTOOLBAR_SAVE',
'save2new' => 'JTOOLBAR_SAVE_AND_NEW',
'save2copy' => 'JTOOLBAR_SAVE_AS_COPY'
);

$bar = JToolbar::getInstance('toolbar');

$layout = new JLayoutFile('joomla.toolbar.group.groupopen');
$bar->appendButton('Custom', $layout->render($options));
$firstItem = false;

foreach ($buttons as $button)
{
if (!array_key_exists($button[0], $validOptions))
{
continue;
}

$options['group'] = true;
$altText = isset($button[2]) ? $button[2] : $validOptions[$button[0]];
call_user_func_array('JToolbarHelper::' . $button[0], array($button[1], $altText, $firstItem));

if (!$firstItem)
{
$layout = new JLayoutFile('joomla.toolbar.group.groupmid');
$bar->appendButton('Custom', $layout->render($options));
$firstItem = true;
}
}

$layout = new JLayoutFile('joomla.toolbar.group.groupclose');
$bar->appendButton('Custom', $layout->render());
}

/**
* Displays a modal button
*
Expand Down
6 changes: 5 additions & 1 deletion administrator/templates/atum/_src/scss/blocks/_toolbar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@
line-height: 1.5;
}

.btn-success {
.btn-success:not(.dropdown-toggle) {
width: 140px;
}
.btn-success.dropdown-toggle {
background: #419641;
border-color: #419641;
}
}

Expand Down
7 changes: 6 additions & 1 deletion administrator/templates/atum/css/template.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion administrator/templates/atum/css/template.css.map

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion administrator/templates/atum/css/template.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion administrator/templates/atum/css/template.min.css.map

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions layouts/joomla/toolbar/group/groupclose.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
/**
* @package Joomla.Site
* @subpackage Layout
*
* @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

defined('JPATH_BASE') or die;

?>
</div>
</div>
19 changes: 19 additions & 0 deletions layouts/joomla/toolbar/group/groupmid.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
/**
* @package Joomla.Site
* @subpackage Layout
*
* @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

defined('JPATH_BASE') or die;

$btnClass = $displayData['class'];
?>
<button
type="button"
class="btn btn-sm <?php echo $btnClass; ?> dropdown-toggle dropdown-toggle-split" data-toggle="dropdown"
aria-haspopup="true"
aria-expanded="false"></button>
<div class="dropdown-menu">
14 changes: 14 additions & 0 deletions layouts/joomla/toolbar/group/groupopen.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
/**
* @package Joomla.Site
* @subpackage Layout
*
* @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

defined('JPATH_BASE') or die;

$btnClass = $displayData['class'];
?>
<div class="btn-group">
9 changes: 9 additions & 0 deletions layouts/joomla/toolbar/standard.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,17 @@
$class = $displayData['class'];
$text = $displayData['text'];
$btnClass = $displayData['btnClass'];
$group = $displayData['group'];
?>

<?php if ($group) : ?>
<a href="#" onclick="<?php echo $doTask; ?>" class="dropdown-item">
<span class="<?php echo trim($class); ?>"></span>
<?php echo $text; ?>
</a>
<?php else : ?>
<button onclick="<?php echo $doTask; ?>" class="<?php echo $btnClass; ?>">
<span class="<?php echo trim($class); ?>"></span>
<?php echo $text; ?>
</button>
<?php endif; ?>
14 changes: 8 additions & 6 deletions libraries/cms/toolbar/button/standard.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,25 @@ class JToolbarButtonStandard extends JToolbarButton
/**
* Fetch the HTML for the button
*
* @param string $type Unused string.
* @param string $name The name of the button icon class.
* @param string $text Button text.
* @param string $task Task associated with the button.
* @param boolean $list True to allow lists
* @param string $type Unused string.
* @param string $name The name of the button icon class.
* @param string $text Button text.
* @param string $task Task associated with the button.
* @param boolean $list True to allow lists
* @param boolean $group Does the button belong to a group?
*
* @return string HTML string for the button
*
* @since 3.0
*/
public function fetchButton($type = 'Standard', $name = '', $text = '', $task = '', $list = true)
public function fetchButton($type = 'Standard', $name = '', $text = '', $task = '', $list = true, $group = false)
{
// Store all data to the options array for use with JLayout
$options = array();
$options['text'] = JText::_($text);
$options['class'] = $this->fetchIconClass($name);
$options['doTask'] = $this->_getCommand($options['text'], $task, $list);
$options['group'] = $group;

switch ($name)
{
Expand Down

0 comments on commit 8293f8c

Please sign in to comment.