Skip to content

038 Setup Site Edit View in JCB

Amigo edited this page Jul 29, 2019 · 17 revisions

SETUP SITE EDIT VIEW IN JCB

Adding Admin View To Front-End Site

00:00:00

How to add an Admin View to the front end of your site. There can be editing and submission of the front end of this specific Admin View. The public version of JCB is being used to illustrate this, it has this Demo Version in it. First it is compiled and installed to the local Joomla website. Install it, open it. Here is the demo version that is publicly available and it has a Admin View called "Looks". 00:01:07 If you go to the List View of the Admin View, called 'Looks', there is none. Create 'New'. There is a description box in the New view. A 'More' item, where you can click, and see some custom fields: 'email', 'mobile phone', 'date of birth', 'image', 'website' and the normal Publish, Permission, Structure for the view, and the name field. Now that is what has been referred to as the Admin view. It is this combination of fields working together in one view.

How To Add Editing Area

00:01:50

How to add a editing area, (these three tabs to the front end of the site) that it will function like a form. Who will be allowed to access the form will depend upon the permissions structure. The permission structure controls who can edit and who can add items to a specific Admin view. 00:02:14 Currently the public cannot edit this, if an item is created they cannot edit it. There is an item level on permissions. If it is closed then it can be seen there is also a 'Global' control on permissions in 'Options'. The Global control of permissions is also, if you want public to be able to submit to this form, it is necessary to allow them to be able to create.00:02:46 Set it to 'Allow', and the public is allowed to create. Most components has more than one view. This one has only one; it is called 'Look'. Over here('Look create') say allow, and if you want them to edit existing submissions. 00:03:13There is the 'Edit state', 'Edit own', 'Created by', all these things in the global spec, as well as in the local edit of the view.

Two Switches

00:03:30

There are two switches. One is a global switch, and one that is specifically focusing on the view. If the view cannot be accessed on the front end after it has been created, it is necessary to come back to this area and sort out the permissions for the specific group who should have access to the specific view on a front end. 00:03:57 This permission structure is quite intense and extendable. Specific groups can be targeted with specific permissions for every view that JCB builds in the Admin as well as in the Site views. Cancel out, no further changes will be done and it returns to the Demo Component.

Demo Component - Settings

00:04:21

In JCB there is a switch that can be flipped for JCB to write the code for the site end of this component. So go back to JCB and to components and open the component. In the component there is an area called 'Settings' where all the admin views are linked. If that is opened, it may be seen that there is usually this bug in Joomla, which if it is opened for first time does not reflect the original setting. I usually open it, cancel it, and then open it again and the original setting is back.00:05:17 You will see that 'Edit/Create Site View' must be set to 'Yes'. If it is set to 'Yes', then it means that it is going to create a Site View of this 'Look', so that it can be editted on the site end and not only in the Admin area and it also means Create items. Save this and then also save and close. Go back to compiler, compile demo. Install it.

Code - Controller - Model - View

00:06:05

Looking at the demo websites folder structure in the code, there is a com_demo folder under components. 00:06:19 There are the Models as well as the Controllers and the Views. This is the View that was dynamically generated by JCB. The View, the Model and the Controller are called 'Look'. Open (controller look.php) to see what was the code that was written. 00:06:49 It looks very similar to the Admin Area except that it has been slightly modified for the front end and its requirements. As you can see we were adding some CSS classes and JavaScript from the back end. Here is the 'model','getItem', 'getForm', and the Controller.00:07:16 It shows the code that has been created. The fact that this was created, does not mean that there is a set of links that you can click and edit the forms which was submitted or that there is a link to create any. These things should be done manually. 00:07:51

Manually Add Links

Under site views there are two views, one is called 'Looks' and other one is called 'Looking'. As you can remember the one we looked at here, which I set was automatically generated is called 'Look', so that one is not showing because it was a tick box that created this whole View model and Controller. It is not necessary to build the 'Look' view again but you need to get links to it.00:08:21 In 'Looks' a Dynamic Gets is used, as well as in 'Looking'. Open the Dynamic Get page. There is one called 'Looks' and 'Looking'. Go to the Looks Dynamic Get. It got a custom script area were it is asked whether the items are set or whether there are items.<<<<<<

Then we looping through them, and during the looping process we determine by $canDo script, 00:09:10 you will see in the helper class there's a getAction function.

The getAction function asks whether look item, where the current user has the edit option to the specific look item. If it does it in this little script, it builds an edit look button. And dynamically adds that to the edit link, which is coupled to the item, and then continues on. It dynamically generates the button for edit in the dynamic get. 00:09:48 You could have done that anywhere. I decided to do it here, because then it gets added to the model, which is more where your logic, for lots of your data structure should be placed. If you go back to the site views, open the looks site view. You will see that we got the main get set as looks. If you scroll down, 00:10:25 in this area we are looping through the look items, and echoing the edit link after the description. That means the link that we built in the Dynamic Get which is the button, will either be empty and therefore show nothing. If the user doesn't have the permission to edit it, or it will show a button. 00:11:04 As I look at this I haven't added a link for creating new looks. The same would be required to do that.

  • Add A Button To Create New Looks

You could use the same button script, copy that. Here before the table, you could 00:11:29 add a button to create new looks. All you would need to change is this link here ((index_php?option_com_"Component") that it will have an id to zero. It will create a new look. That's a quick tutorial on how to add an editable 00:11:53 admin view to the site end of your component. Then link it into your side view, that you can click on a button and edit a specific id view or create more. Then control that with this getAction helper class method, which gives you whether it can be edited. You can go look at this helper class in the code. 00:12:23

Let me just quickly open that for you. Here in the code, in helpers, we open demo.php. We scroll down until we get the method called getAction. 00:12:50 Around 540 depends on how much the customer scripting there is been added. You can go through this logic to see that we are dealing with a number of concepts and trying to determine the permission to edit own and to create. It all gets stored and gives back to you 00:13:17 in the result set. You could also echo out the result, var dump or something in the look to see exactly what is the result that you get from that structure.

If we go back to the looks view. 00:13:42 Let's just open that model. You will see that the custom scripting we looked at, gets added (see video) from JCB that custom scripting that creates the button. You could come in here, and you can add a var_dump);exit; and take $cando 00:14:06 and login as any kind of user on the site, then when you load the page, it should show you the $cando list of that specific user group. Also keep in mind that here's the authorise setting that is applicable to the looks site view. And it also controlled in the permission structure. 00:14:33 There's a lot of permissions automatically being added to components build in JCB. You need to always keep that in mind. It might look like things don't work while it works very well. You just haven't kept in mind that there is a permission structure, and that you need to adapt that permission on structure as it is fitting to your project.

Clone this wiki locally