Updated 4a. JCB Demo Component Directory, Folders and Files (markdown)
@@ -286,65 +286,42 @@ defined('_JEXEC') or die('Restricted access');
|
||||
***
|
||||
## \demo.php
|
||||
### Let's look at the JCB Demo component using the admin area of Joomla!, signed in as a Super Administrator. JCB's Editing the Site View in the admin area of the site is where you add the code for the site view entry point for the JCB Demo component, /demo.php. This code has been inserted for you. You will need to supply code for your own components and the code in the JCB Demo component provides the basic elements for any component allowing CRUD (Create, Read, Update Delete) on database table records, in this case, look.
|
||||
|
||||
Super Administrator can:
|
||||
* Login to admin as super administrator and create a look.
|
||||
* Add a registered user.
|
||||
* Create a Joomla! menu item for the demo component looks, access should be registered.
|
||||
|
||||
Registered Users can:
|
||||
* Edit the look record in the demo_look table, reusing the adminForm form to do so
|
||||
The registered user id of the logged in user must match the created_by value for it to display.
|
||||
* First, login as the registered user and select the looks option from the main menu
|
||||
* The site view looks displays with the Name and Description of the registered user's look and an edit toolbar underneath.
|
||||
* Click the edit toolbar and display the admin view look, displaying only the form actions defined for that user group.
|
||||
Save
|
||||
Save and Close
|
||||
Close
|
||||
* The More button was enabled in the JCB demo
|
||||
- This allowing entry of the additional fields on the form.
|
||||
* Edit the look record in the demo_look table, reusing the adminForm form to do so. To display, the registered user id of the logged in user must match the created_by value in the record.
|
||||
* Login as the registered user and select the looks option from the main menu
|
||||
* Observe the site view looks displays with the Name and Description of the registered user's look and an edit toolbar underneath.
|
||||
* Click the edit toolbar and display the admin view look, displaying only the buttons representing the form actions defined for that user group which are Save, Save and Close, Close.
|
||||
* Click the More button, enabled when the record was entered by the Super Administrator using the admin area of the site. This allows the Registered User to access additional fields on the form.
|
||||
|
||||
Let's look at the code behind all of this. admin view look so one can edit their own look record in the looks_demo table. By default, access control is only allowed for the super administrator. If access is given in Joomla!'s ACL to the JCB Demo component for let's say the registered group of Joomla! users, the edit button will display below the name and description. This brings up the matter of access control levels or ACL in Joomla! See the text after the view for information or you will not be able to edit a look despite owning it.
|
||||
Let's look at the code behind all of this. By default, the site view looks is not authorized for any user besides the Super Administrator although it displays on the main menu after logging in to a Registered User and above. If access is given in Joomla!'s ACL to the JCB Demo component for the Registered Group of Joomla! users, the view will display after logging in as a Registered User. For this to happen, the Joomla! ACL must allow access to the component as follows using the admin area's main menu option - Components, Demo, Looks, Options, Permissions tab, Registered:
|
||||
|
||||
If you use Chrome's More Tools - Developer Tools, use the element pointer to find this on the page:
|
||||
Looking (Site) Access Allowed
|
||||
Looks Access Allowed
|
||||
Looks (Site) Access Allowed
|
||||
Looks Edit Own Allowed
|
||||
|
||||
<form action="/comdemo/index.php?option=com_demo&view=looks&Itemid=104" method="post" name="adminForm" id="adminForm">
|
||||
<table class="uk-table uk-table-hover">
|
||||
<caption>List of all looks</caption>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Description</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<a href="index.php?option=com_demo&view=looking&id=1:registered&Itemid=104">Registered</a>
|
||||
</td>
|
||||
<td>
|
||||
Registered<br><br>
|
||||
<a class="uk-button uk-button-text uk-width-1-1" href="/comdemo/index.php?option=com_demo&view=look&task=look.edit&id=1&Itemid=104">
|
||||
<i class="uk-icon-pencil">
|
||||
</i>
|
||||
<span class="uk-hidden-small">
|
||||
Edit Look
|
||||
</span>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
The first option only allows access to the site. The view will display a look but that's all. The second allows access and therefore all looks will display and can be accessed (but not edited) as long as the third access is also granted. The fourth allows editing the look if the user's id matches the one in the look_demo table record More details on th Joomla! ACL on this can be seen in [the video at](https://www.youtube.com/watch?v=gWjQjdhYqXI&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&index=36).
|
||||
|
||||
Revisiting the previous list of actions a registered user may perform:
|
||||
There is a caveat in the demo that must be taken into consideration. From the admin area of the site, main menu option Selecting the Components, Component Builder, Dynamic Gets, Looks, Tweak option you must add the Filter:
|
||||
|
||||
Where Table Key a.created_by equal = $this->user->id
|
||||
|
||||
This Tweak to the Dynamic Get in JCB for the Demo component site view looks Dynamic Get, getListQuery extends it to only include records from the table that are created by the user having the same id as the current user, available from the site view looks $this variable, user id element in the form. The change takes effect once you use JCB to compile the component and install it again using the Joomla! extension installer. The same Tweak is required in the site view looking Dynamic Get, getItem.
|
||||
|
||||
It is also important that you ensure only certain actions are allowed for certain users. In our case, a Registered User should only be allowed to Save, Save and Close, and Close when done editing their own look records. Super Administrators by default are allowed all actions on the admin view. To restrict a Registered user's actions to allow only Save, Save and Close, and Close .
|
||||
|
||||
Continuing with the edit functionality:
|
||||
* Edit the look record in the demo_look table, reusing the adminForm form to do so
|
||||
<form action="/comdemo/index.php?option=com_demo&view=looks&Itemid=104" method="post" name="adminForm" id="adminForm">
|
||||
This line is inserted by JCB during compilation and loads the same looks view used in the admin area to add looks into the demo_look table.
|
||||
- The registered user id of the logged in user must match the created_by value for it to display.
|
||||
By default, the JCB demo allows all user types except public and guest user groups to view all looks, ehether they created them or not. To restrict the looks to the specific user, besides the changes to the Joomla! ACL one must filter the look records in the demo_looks table by owner id. Allowing the following actions in JCB admin, EDThe following accomplishes this. Note, these will take effect without compiling the JCB Demo and other components built using it since it is the Joomla! ACL or the global options permissions of the demo component being changed for Joomla!'s the Registered User Group and not individual permissions within the JCB component which allows for granularity using the Joomla! ACL once again on children of the parent.
|
||||
|
||||
Looks Edit Own
|
||||
Looks Access
|
||||
|
||||
* The registered user id of the logged in user must match the created_by value for it to display.
|
||||
By default, the JCB demo allows all user types except public and guest user groups to view all looks, either they created them or not. To restrict the looks to the specific user, besides the changes to the Joomla! ACL one must filter the look records in the demo_looks table by owner id. Allowing the following actions in JCB admin, EDThe following accomplishes this. Note, these will take effect without compiling the JCB Demo and other components built using it since it is the Joomla! ACL or the global options permissions of the demo component being changed for Joomla!'s the Registered User Group and not individual permissions within the JCB component which allows for granularity using the Joomla! ACL once again on children of the parent.
|
||||
* First, login as the registered user and select the looks option from the main menu
|
||||
* The site view looks displays with the Name and Description of the registered user's look and an edit toolbar underneath.
|
||||
* Click the edit toolbar and display the admin view look, displaying only the form actions defined for that user group.
|
||||
|
Reference in New Issue
Block a user