? ? Pending

User tests: Successful: Unsuccessful:

avatar asika32764
asika32764
5 Nov 2017

Introduction

Currently we use JHtml (HTMLHelper) to make the action buttons in grid view.

p-2017-11-05-001

But the interface and the number of arguments of JHtmlJGrid::published() is horrible, it hard to use and extends, developers must read many code to understand how to make their own buttons.

The Solution: ActionButton

I try to create a class that is configurable, this is a sample code:

<?php
// In View class
$button = (new ActionButton(['disabled' => !$canChange]))
    ->addState(0, 'articles.featured', 'icon-unfeatured', 'COM_CONTENT_UNFEATURED');
    ->addState(1, 'articles.unfeatured', 'icon-featured', 'COM_CONTENT_FEATURED');

$this->featuredButton = $button;
// In template table view loop

<?php foreach ($articles as $i => $article): ?>
    ...
   <td><?php echo $this->featuredButton->render($article->featured, $i); ?></td>
    ...
<?php endforeach; ?>

It's simple and easy to learn, make developers days joy.

Layout

This class use Joomla layouts to render template. Also we can override layout:

$button->setLayout('my.action.button');

Default State

If an item has an unexpected state value, for example, I changed an article state to 5, it will show Unknow State icon:

p-2017-11-05-002

PublishedButton

For standard Joomla content, I also created a PublishedButton that can handle the publish time:

$button = new PublishedButton(
	[
		'diabled' => $canDoWhat,
		'task_prefix' => 'articles.',
		'checkbox_name' => 'cb'
	]
);

echo $button->render($value, $i, $publish_up, $publish_down);

p-2017-11-23-003


In this PR, I rewrite articles published and featured button to use this class as example, it works well.

If this concept accepted, I will continue finish the test and docblock.

avatar asika32764 asika32764 - open - 5 Nov 2017
avatar asika32764 asika32764 - change - 5 Nov 2017
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 5 Nov 2017
Category Administration com_content Layout Libraries External Library Composer Change
avatar asika32764 asika32764 - change - 5 Nov 2017
The description was changed
avatar asika32764 asika32764 - edited - 5 Nov 2017
avatar asika32764 asika32764 - change - 5 Nov 2017
The description was changed
avatar asika32764 asika32764 - edited - 5 Nov 2017
avatar asika32764 asika32764 - change - 5 Nov 2017
The description was changed
avatar asika32764 asika32764 - edited - 5 Nov 2017
avatar asika32764 asika32764 - change - 5 Nov 2017
Title
[Concept] A more flexible ActionButton class
[4.0|Concept] A more flexible ActionButton class
avatar asika32764 asika32764 - edited - 5 Nov 2017
avatar asika32764 asika32764 - change - 5 Nov 2017
The description was changed
avatar asika32764 asika32764 - edited - 5 Nov 2017
avatar asika32764 asika32764 - change - 5 Nov 2017
The description was changed
avatar asika32764 asika32764 - edited - 5 Nov 2017
avatar asika32764 asika32764 - change - 5 Nov 2017
The description was changed
avatar asika32764 asika32764 - edited - 5 Nov 2017
avatar asika32764 asika32764 - change - 5 Nov 2017
The description was changed
avatar asika32764 asika32764 - edited - 5 Nov 2017
avatar dgt41
dgt41 - comment - 5 Nov 2017

Hmm, I have something different in my mind for j4: using custom elements and client side rendering...

avatar asika32764
asika32764 - comment - 5 Nov 2017

I think it won't be conflict. We still must call PHP to do some configuration or translate string before we call any client-side functions. Just change the template to raise any HTML/JS handling. This class is just a PHP entry to help developers enable button actions.

avatar asika32764
asika32764 - comment - 7 Nov 2017

So do you have any plan for the JToolbar ? I also have some idea similar to this concept.

$toolbar = JToolbar::getInstance('administrator')
    ->addButton(new AddNewButton)
    ->addButton(new PublishButton)
    ->addButton(new CustomButton($html, JText::_('XXX')));

$toolbar->render();
avatar dgt41
dgt41 - comment - 7 Nov 2017

I've started some work like 3 months ago: https://github.com/joomla/joomla-cms/compare/4.0-dev...dgt41:ยง4.0-dev-toolbar-cleanup?expand=1

Actually right now I think that the toolbar should be utilising custom elements, which obviously the above link is not...

avatar asika32764
asika32764 - comment - 7 Nov 2017

I take a look your PR, I think my code can get together with custom elements without any problem.

See https://github.com/joomla/joomla-cms/pull/17375/files#diff-cffc36facfda8c2f198b4f893dd21bbaR35

Custom elements still needs PHP code to render it, most of all, we use JHtml to render HTML elements and include JS files. The main subject or this PR is to replace JHtml and make API interface configurable.

We can imagine the button layout integrated the custom element will look like:

<?php

JHtml::_('webcomponent', ['toolbar-button' => 'system/joomla-toolbar-button.min.js'], ['relative' => true, 'version' => 'auto']);

extract($displayData);
?>
<toolbar-button
  id="<?php echo $id;?>"
  class="<?php echo $class;?>"
  onclick="<?php echo $click;?>"
  color="success"
  check-list="true"
  check-list-warning="Please select an item.">
<?php echo $text;?>
</toolbar-button>
avatar wilsonge
wilsonge - comment - 8 Nov 2017

I like this :) It seems a lot more obvious than what we had before!

avatar asika32764 asika32764 - change - 13 Nov 2017
Labels Added: ? ?
avatar joomla-cms-bot joomla-cms-bot - change - 23 Nov 2017
Category Administration com_content Layout Libraries External Library Composer Change Administration com_content Language & Strings Layout Libraries External Library Composer Change
0a12ddd 23 Nov 2017 avatar asika32764 Typo
avatar asika32764 asika32764 - change - 23 Nov 2017
Labels Added: ?
avatar asika32764 asika32764 - change - 23 Nov 2017
The description was changed
avatar asika32764 asika32764 - edited - 23 Nov 2017
f33ddad 23 Nov 2017 avatar asika32764 Typo
avatar asika32764 asika32764 - change - 26 Nov 2017
Title
[4.0|Concept] A more flexible ActionButton class
[4.0] A more flexible ActionButton class
avatar asika32764 asika32764 - edited - 26 Nov 2017
avatar joomla-cms-bot joomla-cms-bot - change - 26 Nov 2017
Category Administration com_content Layout Libraries External Library Composer Change Language & Strings Administration com_content Language & Strings Layout Libraries
avatar wilsonge wilsonge - change - 26 Nov 2017
Status Pending Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2017-11-26 22:46:44
Closed_By wilsonge
Labels Removed: ?
avatar wilsonge wilsonge - close - 26 Nov 2017
avatar wilsonge wilsonge - merge - 26 Nov 2017
avatar wilsonge
wilsonge - comment - 26 Nov 2017

Thankyou very much for this :)

Add a Comment

Login with GitHub to post a comment