Skip to content

Commit b0aaa13

Browse files
bembelimensakiss
authored andcommitted
Separate transition dropdown in articles list view (joomla#102)
1 parent b6b21c7 commit b0aaa13

File tree

9 files changed

+150
-69
lines changed

9 files changed

+150
-69
lines changed

administrator/components/com_content/forms/filter_articles.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@
125125
<option value="">JGLOBAL_SORT_BY</option>
126126
<option value="a.ordering ASC">JGRID_HEADING_ORDERING_ASC</option>
127127
<option value="a.ordering DESC">JGRID_HEADING_ORDERING_DESC</option>
128+
<option value="ws.title ASC">JSTAGE_ASC</option>
129+
<option value="ws.title DESC">JSTAGE_DESC</option>
128130
<option value="a.state ASC">JSTATUS_ASC</option>
129131
<option value="a.state DESC">JSTATUS_DESC</option>
130132
<option value="a.featured ASC">JFEATURED_ASC</option>

administrator/components/com_content/forms/filter_featured.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@
111111
<option value="">JGLOBAL_SORT_BY</option>
112112
<option value="fp.ordering ASC">JGRID_HEADING_ORDERING_ASC</option>
113113
<option value="fp.ordering DESC">JGRID_HEADING_ORDERING_DESC</option>
114+
<option value="ws.title ASC">JSTAGE_ASC</option>
115+
<option value="ws.title DESC">JSTAGE_DESC</option>
114116
<option value="a.state ASC">JSTATUS_ASC</option>
115117
<option value="a.state DESC">JSTATUS_DESC</option>
116118
<option value="a.title ASC">JGLOBAL_TITLE_ASC</option>

administrator/components/com_content/src/Model/ArticlesModel.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ public function __construct($config = array())
6969
'level',
7070
'tag',
7171
'rating_count', 'rating',
72-
'stage',
72+
'stage', 'wa.stage_id',
73+
'ws.title'
7374
);
7475

7576
if (Associations::isEnabled())
@@ -276,6 +277,7 @@ protected function getListQuery()
276277
$db->quoteName('wa.stage_id', 'stage_id'),
277278
$db->quoteName('ws.title', 'stage_title'),
278279
$db->quoteName('ws.workflow_id', 'workflow_id'),
280+
$db->quoteName('w.title', 'workflow_title'),
279281
]
280282
)
281283
->from($db->quoteName('#__content', 'a'))
@@ -288,7 +290,8 @@ protected function getListQuery()
288290
->join('LEFT', $db->quoteName('#__categories', 'parent'), $db->quoteName('parent.id') . ' = ' . $db->quoteName('c.parent_id'))
289291
->join('LEFT', $db->quoteName('#__users', 'ua'), $db->quoteName('ua.id') . ' = ' . $db->quoteName('a.created_by'))
290292
->join('INNER', $db->quoteName('#__workflow_associations', 'wa'), $db->quoteName('wa.item_id') . ' = ' . $db->quoteName('a.id'))
291-
->join('INNER', $db->quoteName('#__workflow_stages', 'ws'), $db->quoteName('ws.id') . ' = ' . $db->quoteName('wa.stage_id'));
293+
->join('INNER', $db->quoteName('#__workflow_stages', 'ws'), $db->quoteName('ws.id') . ' = ' . $db->quoteName('wa.stage_id'))
294+
->join('INNER', $db->quoteName('#__workflows', 'w'), $db->quoteName('w.id') . ' = ' . $db->quoteName('ws.workflow_id'));
292295

293296
if (PluginHelper::isEnabled('content', 'vote'))
294297
{

administrator/components/com_content/src/Model/FeaturedModel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function __construct($config = array())
5656
'level',
5757
'tag',
5858
'rating_count', 'rating',
59-
'stage',
59+
'ws.title',
6060
);
6161
}
6262

administrator/components/com_content/tmpl/articles/default.php

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
use Joomla\CMS\Button\FeaturedButton;
1313
use Joomla\CMS\Button\PublishedButton;
14+
use Joomla\CMS\Button\TransitionButton;
1415
use Joomla\CMS\Component\ComponentHelper;
1516
use Joomla\CMS\Factory;
1617
use Joomla\CMS\HTML\HTMLHelper;
@@ -112,6 +113,11 @@
112113
<th scope="col" class="w-1 text-center d-none d-md-table-cell">
113114
<?php echo HTMLHelper::_('searchtools.sort', '', 'a.ordering', $listDirn, $listOrder, null, 'asc', 'JGRID_HEADING_ORDERING', 'icon-menu-2'); ?>
114115
</th>
116+
<?php if ($workflow_enabled) : ?>
117+
<th scope="col" class="w-1 text-center d-none d-md-table-cell">
118+
<?php echo HTMLHelper::_('searchtools.sort', 'JSTAGE', 'ws.title', $listDirn, $listOrder); ?>
119+
</th>
120+
<?php endif; ?>
115121
<th scope="col" class="w-1 text-center d-none d-md-table-cell">
116122
<?php echo HTMLHelper::_('searchtools.sort', 'JFEATURED', 'a.featured', $listDirn, $listOrder); ?>
117123
</th>
@@ -200,48 +206,40 @@
200206
<input type="text" name="order[]" size="5" value="<?php echo $item->ordering; ?>" class="width-20 text-area-order hidden">
201207
<?php endif; ?>
202208
</td>
203-
<td class="text-center d-none d-md-table-cell">
204-
<?php
205-
206-
$options = [
207-
'disabled' => !$canChange
208-
];
209-
210-
if ($workflow_enabled) :
211-
$options['disabled'] = true;
212-
endif;
213-
214-
echo (new FeaturedButton)
215-
->render((int) $item->featured, $i, $options, $item->featured_up, $item->featured_down);
216-
?>
217-
</td>
218-
<td class="article-status">
219209
<?php if ($workflow_enabled) : ?>
220-
<div class="d-flex align-items-center tbody-icon mr-1 small">
210+
<td class="article-stage">
211+
<div class="d-flex align-items-center tbody-icon small">
221212
<?php
222213
$options = [
223214
'transitions' => $transitions,
224-
'stage' => Text::_($item->stage_title),
225-
'id' => (int) $item->id
215+
'title' => Text::_($item->stage_title),
216+
'tip_content' => Text::sprintf('JWORKFLOW', Text::_($item->workflow_title))
226217
];
227218

228-
echo (new PublishedButton)
229-
->removeState(0)
230-
->removeState(1)
231-
->removeState(2)
232-
->removeState(-2)
233-
->addState(ContentComponent::CONDITION_PUBLISHED, '', 'publish', Text::_('COM_CONTENT_CHANGE_STAGE'), ['tip_title' => Text::_('JPUBLISHED')])
234-
->addState(ContentComponent::CONDITION_UNPUBLISHED, '', 'unpublish', Text::_('COM_CONTENT_CHANGE_STAGE'), ['tip_title' => Text::_('JUNPUBLISHED')])
235-
->addState(ContentComponent::CONDITION_ARCHIVED, '', 'archive', Text::_('COM_CONTENT_CHANGE_STAGE'), ['tip_title' => Text::_('JARCHIVED')])
236-
->addState(ContentComponent::CONDITION_TRASHED, '', 'trash', Text::_('COM_CONTENT_CHANGE_STAGE'), ['tip_title' => Text::_('JTRASHED')])
237-
->setLayout('joomla.button.transition-button')
238-
->render((int) $item->state, $i, $options, $item->publish_up, $item->publish_down);
219+
echo (new TransitionButton($options))
220+
->render(0, $i);
239221
?>
240222
</div>
223+
</td>
224+
<?php endif; ?>
225+
<td class="text-center d-none d-md-table-cell">
241226
<?php
242-
else :
243-
echo HTMLHelper::_('jgrid.published', $item->state, $i, 'articles.', $canChange, 'cb', $item->publish_up, $item->publish_down);
244-
endif;
227+
$options = [
228+
'disabled' => $workflow_enabled || !$canChange
229+
];
230+
231+
echo (new FeaturedButton)
232+
->render((int) $item->featured, $i, $options, $item->featured_up, $item->featured_down);
233+
?>
234+
</td>
235+
<td class="article-status text-center">
236+
<?php
237+
$options = [
238+
'task_prefix' => 'articles.',
239+
'disabled' => $workflow_enabled || !$canChange
240+
];
241+
242+
echo (new PublishedButton)->render((int) $item->state, $i, $options, $item->publish_up, $item->publish_down);
245243
?>
246244
</td>
247245
<th scope="row" class="has-context">

administrator/components/com_content/tmpl/featured/default.php

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
use Joomla\CMS\Button\FeaturedButton;
1313
use Joomla\CMS\Button\PublishedButton;
14+
use Joomla\CMS\Button\TransitionButton;
1415
use Joomla\CMS\Component\ComponentHelper;
1516
use Joomla\CMS\Factory;
1617
use Joomla\CMS\HTML\HTMLHelper;
@@ -106,6 +107,11 @@
106107
<th scope="col" class="w-1 text-center d-none d-md-table-cell">
107108
<?php echo HTMLHelper::_('searchtools.sort', '', 'fp.ordering', $listDirn, $listOrder, null, 'asc', 'JGRID_HEADING_ORDERING', 'icon-menu-2'); ?>
108109
</th>
110+
<?php if ($workflow_enabled) : ?>
111+
<th scope="col" class="w-1 text-center d-none d-md-table-cell">
112+
<?php echo HTMLHelper::_('searchtools.sort', 'JSTAGE', 'ws.title', $listDirn, $listOrder); ?>
113+
</th>
114+
<?php endif; ?>
109115
<th scope="col" class="w-1 text-center">
110116
<?php echo Text::_('JFEATURED'); ?>
111117
</th>
@@ -192,6 +198,22 @@
192198
<input type="text" name="order[]" size="5" value="<?php echo $item->ordering; ?>" class="width-20 text-area-order hidden">
193199
<?php endif; ?>
194200
</td>
201+
<?php if ($workflow_enabled) : ?>
202+
<td class="article-stage">
203+
<div class="d-flex align-items-center tbody-icon small">
204+
<?php
205+
$options = [
206+
'transitions' => $transitions,
207+
'title' => Text::_($item->stage_title),
208+
'tip_content' => Text::sprintf('JWORKFLOW', Text::_($item->workflow_title))
209+
];
210+
211+
echo (new TransitionButton($options))
212+
->render(0, $i);
213+
?>
214+
</div>
215+
</td>
216+
<?php endif; ?>
195217
<td class="text-center">
196218
<?php
197219

@@ -208,33 +230,13 @@
208230
?>
209231
</td>
210232
<td class="article-status">
211-
<?php if ($workflow_enabled) : ?>
212-
<div class="d-flex align-items-center tbody-icon mr-1 small">
213-
<?php
214-
215-
$options = [
216-
'transitions' => $transitions,
217-
'stage' => Text::_($item->stage_title),
218-
'id' => (int) $item->id
219-
];
220-
221-
echo (new PublishedButton)
222-
->removeState(0)
223-
->removeState(1)
224-
->removeState(2)
225-
->removeState(-2)
226-
->addState(ContentComponent::CONDITION_PUBLISHED, '', 'publish', Text::_('COM_CONTENT_CHANGE_STAGE'), ['tip_title' => Text::_('JPUBLISHED')])
227-
->addState(ContentComponent::CONDITION_UNPUBLISHED, '', 'unpublish', Text::_('COM_CONTENT_CHANGE_STAGE'), ['tip_title' => Text::_('JUNPUBLISHED')])
228-
->addState(ContentComponent::CONDITION_ARCHIVED, '', 'archive', Text::_('COM_CONTENT_CHANGE_STAGE'), ['tip_title' => Text::_('JARCHIVED')])
229-
->addState(ContentComponent::CONDITION_TRASHED, '', 'trash', Text::_('COM_CONTENT_CHANGE_STAGE'), ['tip_title' => Text::_('JTRASHED')])
230-
->setLayout('joomla.button.transition-button')
231-
->render((int) $item->state, $i, $options, $item->publish_up, $item->publish_down);
232-
?>
233-
</div>
234233
<?php
235-
else :
236-
echo HTMLHelper::_('jgrid.published', $item->state, $i, 'articles.', $canChange, 'cb', $item->publish_up, $item->publish_down);
237-
endif;
234+
$options = [
235+
'task_prefix' => 'articles.',
236+
'disabled' => $workflow_enabled || !$canChange
237+
];
238+
239+
echo (new PublishedButton)->render((int) $item->state, $i, $options, $item->publish_up, $item->publish_down);
238240
?>
239241
</td>
240242
<th scope="row" class="has-context">

administrator/language/en-GB/joomla.ini

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ JREGISTER="Register"
115115
JORDERINGDISABLED="Please sort by order to enable reordering"
116116
JSAVE="Save &amp; Close"
117117
JSELECT="Select"
118+
JSTAGE="Stage"
119+
JSTATUS="Status"
120+
JSTAGE_ASC="Stage ascending"
121+
JSTAGE_DESC="Stage descending"
118122
JSTATUS="Status"
119123
JSTATUS_ASC="Status ascending"
120124
JSTATUS_DESC="Status descending"
@@ -135,6 +139,7 @@ JUNPROTECTED="Unprotected"
135139
JUNPUBLISHED="Unpublished"
136140
JVISIT_LINK="Visit Link"
137141
JVISIT_WEBSITE="Visit Website"
142+
JWORKFLOW="Workflow: %s"
138143
JYEAR="Year"
139144
JVERSION="Version"
140145
JYES="Yes"

layouts/joomla/button/transition-button.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,44 +23,44 @@
2323
$only_icon = empty($options['transitions']);
2424
$disabled = !empty($options['disabled']);
2525
$tip = !empty($options['tip']);
26-
$id = (int) $options['id'];
2726
$tipTitle = $options['tip_title'];
27+
$tipContent = $options['tip_content'];
2828
$checkboxName = $options['checkbox_name'];
2929
?>
3030
<?php if ($only_icon) : ?>
3131
<span class="tbody-icon mr-1">
3232
<span class="<?php echo $this->escape($icon ?? ''); ?> <?php echo $tip ? 'hasPopover' : ''; ?>"
3333
title="<?php echo HTMLHelper::_('tooltipText', $tipTitle ?: $title, '', 0); ?>"
34-
data-content="<?php echo HTMLHelper::_('tooltipText', $title, '', 0); ?>"
34+
data-content="<?php echo HTMLHelper::_('tooltipText', $tipContent, '', 0); ?>"
3535
data-placement="top"
3636
></span>
3737
</span>
38-
<div class="mr-auto"><?php echo $this->escape($options['stage']); ?></div>
38+
<div class="mr-auto"><?php echo $options['title']; ?></div>
3939
<?php else : ?>
4040
<a class="tbody-icon mr-1 data-state-<?php echo $this->escape($value ?? ''); ?> <?php echo $this->escape(!empty($disabled) ? 'disabled' : null); ?> <?php echo $tip ? 'hasPopover' : ''; ?>"
4141
<?php if (empty($disabled)) : ?>
4242
href="javascript://"
4343
<?php endif; ?>
4444

4545
title="<?php echo HTMLHelper::_('tooltipText', $tipTitle ?: $title, '', 0); ?>"
46-
data-content="<?php echo HTMLHelper::_('tooltipText', $title, '', 0); ?>"
46+
data-content="<?php echo HTMLHelper::_('tooltipText', $tipContent, '', 0); ?>"
4747
data-placement="top"
4848
onclick="Joomla.toggleAllNextElements(this, 'd-none')"
4949
>
5050
<span class="<?php echo $this->escape($icon ?? ''); ?>" aria-hidden="true"></span>
5151
</a>
52-
<div class="mr-auto"><?php echo $this->escape($options['stage']); ?></div>
52+
<div class="mr-auto"><?php echo $options['title']; ?></div>
5353
<div class="d-none">
5454
<?php
5555
$default = [
56-
HTMLHelper::_('select.option', '', $this->escape($options['stage'])),
56+
HTMLHelper::_('select.option', '', $this->escape($options['title'])),
5757
HTMLHelper::_('select.option', '-1', '--------', ['disable' => true])
5858
];
5959

6060
$transitions = array_merge($default, $options['transitions']);
6161

6262
$attribs = [
63-
'id' => 'transition-select_' . (int) $id,
63+
'id' => 'transition-select_' . (int) $row ?? '',
6464
'list.attr' => [
6565
'class' => 'custom-select custom-select-sm w-auto',
6666
'onchange' => "this.form.transition_id.value=this.value;Joomla.listItemTask('" . $checkboxName . $this->escape($row ?? '') . "', 'articles.runTransition')"]
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
/**
3+
* Joomla! Content Management System
4+
*
5+
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
6+
* @license GNU General Public License version 2 or later; see LICENSE.txt
7+
*/
8+
9+
namespace Joomla\CMS\Button;
10+
11+
use Joomla\CMS\Date\Date;
12+
use Joomla\CMS\Factory;
13+
use Joomla\CMS\HTML\HTMLHelper;
14+
use Joomla\CMS\Language\Text;
15+
16+
/**
17+
* The PublishedButton class.
18+
*
19+
* @since 4.0.0
20+
*/
21+
class TransitionButton extends ActionButton
22+
{
23+
/**
24+
* The layout path to render.
25+
*
26+
* @var string
27+
*
28+
* @since 4.0.0
29+
*/
30+
protected $layout = 'joomla.button.transition-button';
31+
32+
/**
33+
* ActionButton constructor.
34+
*
35+
* @param array $options The options for all buttons in this group.
36+
*
37+
* @since 4.0.0
38+
*/
39+
public function __construct(array $options = [])
40+
{
41+
parent::__construct($options);
42+
43+
$this->unknownState['icon'] = 'shuffle';
44+
$this->unknownState['title'] = $options['title'] ?? Text::_('JLIB_HTML_UNKNOWN_STATE');
45+
$this->unknownState['tip_content'] = $options['tip_content'] ?? $this->unknownState['title'];
46+
}
47+
48+
/**
49+
* Render action button by item value.
50+
*
51+
* @param integer|null $value Current value of this item.
52+
* @param integer|null $row The row number of this item.
53+
* @param array $options The options to override group options.
54+
* @param string|Date $publishUp The date which item publish up.
55+
* @param string|Date $publishDown The date which item publish down.
56+
*
57+
* @return string Rendered HTML.
58+
*
59+
* @since 4.0.0
60+
*/
61+
public function render(?int $value = null, ?int $row = null, array $options = []): string
62+
{
63+
$default = $this->unknownState;
64+
65+
$options['tip_title'] = $options['tip_title'] ?? ($options['title'] ?? $default['title']);
66+
67+
return parent::render($value, $row, $options);
68+
}
69+
}

0 commit comments

Comments
 (0)