How do I override a shared wagtail admin template? - wagtail

In wagtail currently a standard select is used for a one to many relation, and I'd like to override this to use a jquery UI autocomplete widget.
I found the template that renders the component in wagtail/admin/templates/wagtailadmin/shared/collection_chooser.html, so I Thought that by following the instructions I could override the template the way I would a base one, but unfortunately when I create myapp/templates/wagtailadmin/shared/collection_chooser.html it is not rendered in place of the base one. I did confirm that by creating myapp/templates/wagtailadmin/base.html that does get used.
How can I override this template short of editing the source?

Related

Stylizing LWC radio list?

So right now I'm trying to build this radio list for the regions in LWC, the functionality works fine in that when you click on the regions it selects all the states below for that region.
https://i.stack.imgur.com/y2MM8.png
However, I want to stylize it so that it looks more proper. I'm a little confused how to do this using these components that LWC provides. Here's a mockup of what the regions should look like.
https://i.stack.imgur.com/A26PH.png
Here's what the HTML for it looks like.
https://i.stack.imgur.com/1vWcy.png
You can probably achieve this by using the grid system : https://www.lightningdesignsystem.com/utilities/grid/
We can achieve the same style by following a couple of steps:
Pass class to each lightning inputs to scope the styling.
Style radio controls having the passed class name.
save the file as .css and store in static resources.
Load style sheet in component by making use of loadStyle method from platformResourceLoader module.

Is there an easy way to add a copy button to the IndexListing of a non-page model in wagtail?

I have a Snippet model that I'm using ModelAdmin to create, edit, and list in Wagtail. I'd like to create a copy function, and I can see that wagtail supports this out of the box for Page objects:
Before I write custom code to do this, I thought I'd ask if there is any way to easily do this within Wagtail. I didn't find any hooks that would even easily allow adding more buttons, and while I did find modeladmin-list-display-add-buttons, it seems to only allow me to change the placement of the default edit and delete buttons.
It is possible to achieve this. However, it will require custom code, and various overrides and additions in different places. Here are some steps that should help you on your way, with some links to some example code in the wagtailmenus extension, which does this exact thing:
Adding the custom view:
Create a custom CopyView view (subclassing wagtail.contrib.modeladmin.views.EditView will probably be your best starting point). For inspiration, you might want to take a look at one I created for wagtailmenus: https://github.com/rkhleics/wagtailmenus/blob/master/wagtailmenus/views.py#L141
Integrate the view with your ModelAdmin class, by adding a copy_view() method that instantiates your custom view. For example:
https://github.com/rkhleics/wagtailmenus/blob/master/wagtailmenus/modeladmin.py#L78
Override your ModelAdmin class's get_admin_urls_for_registration() method, to make the view accessible via a URL. For example: https://github.com/rkhleics/wagtailmenus/blob/master/wagtailmenus/modeladmin.py#L82
Getting the button to show in the listing:
Create a custom ButtonHelper class by subclassing wagtail.contrib.modeladmin.helpers.ButtonHelper.
Add a copy_button() method to it, that can provide all of the necessary details to create the button. For example: https://github.com/rkhleics/wagtailmenus/blob/master/wagtailmenus/modeladmin.py#L38/
Override the get_buttons_for_obj() method to output the copy button in the listing along with the others, depending on the user's permissions (e.g. https://github.com/rkhleics/wagtailmenus/blob/master/wagtailmenus/modeladmin.py#L49)
Finally, get your ModelAdmin class to use your custom ButtonHelper instead of the default one, by changing the button_helper_class attribute to reference your custom class.
If you'd like to understand more about all of the various classes within wagtail.contrib.modeladmin, I'd suggest reading the modeladmin customisation primer page from the official Wagtail documentation.

How to hide a CQ component dynamically using Extjs?

I need to hide a CQ component from the page, when I select a particular value from another components dialog. Is this possible using ExtJS?
Yes, it is possible, but without more info it is difficult to give more details. In general, you can look up the xtypes you are using in your dialog at http://dev.day.com/docs/en/cq/current/widgets-api/index.html. Find the events that are available for the xtypes you are using in the dialog, then add a listener for one of the events exposed by that xtype. That allows you to run your own JavaScript code in response to an event--and that code could do things like hide HTML DOM elements.
Here is an example of using a listener to add custom functionality in response to an event: http://cq.shishank.info/2011/12/20/adding-limit-to-multifiled/
And here is another example: CQ5 - Hiding a tab within a component dialog depending on user group?

How to hook the template rendering

My site's theme uses custom checkboxes and other items that I need to style. It uses $(".styled, input:radio, input:checkbox, .dataTables_length select").uniform(); to do so.
I'm wondering if instead of creating a bunch of directives if I can just tap into the template rendering and execute this method on the template node.
Why not just a uniform directive, which then you apply to whatever needed? There are surely things (like the .styled ones) which do not come from a template directly.

Creating components from templates (Template or XTemplate)

I'd like to be able to generate a component from within a template. The use case for it is that when I generate a row in a DataView I'd like to be able to incorporate buttons and/or other components (maybe even a nested grid) to the rendered items.
So far everywhere I look all I see is a template calling another template. Is there a way to do what I'd like (generate component instead of just plain html) from an XTemplate?
Since an XTemplate is just used for generating markup to be inserted into the DOM, it alone is not enough to create components -- Components do have an underlying DOM element (through component.el.dom), but also exist as JavaScript objects in browser memory with other methods and properties.
It is possible to accomplish what you are asking through several different ways... you can use the XTemplate to generate the markup, and use the Component.applyTo config option to create a Component object in memory that is linked to the DOM element from your template. Of course, you will have to wait until the template is applied and then create a component with applyTo set to the correct DOM element.
You could also extend the XTemplate class to do the same thing just mentioned, but wrapped up in the applyTemplate stuff. I am pretty sure that Ext does not have a built-in way for the templates to create components -- so far they just create HTML.

Resources