Thanks for the great example @ebrehault
By default, mr.bob adds a static
folder to the add-on it generates, so in my case there was no need to add anything to the browser/configure.zcml
... this was already there:
<plone:static
name="uwosh.oie.studyabroadstudent"
type="plone"
directory="static"
/>
It's important to note the type value "plone" and the name "uwosh.oie.studyabroadstudent"; those are needed in the registry entry below.
In the static
folder I created a programedit.js
containing:
$(document).ready(function() {
if($('body').hasClass('template-edit') && $('body').hasClass('portaltype-oiestudyabroadprogram')) {
alert('Editing a program');
// add more code here
});
The initial if
is to ensure that we are editing only one specific content type (not just any edit form, in other words).
Then in profiles/default/registry.xml
I added this:
<records prefix="plone.bundles/uwosh.oie.studyabroadstudent"
interface='Products.CMFPlone.interfaces.IBundleRegistry'>
<value key="enabled">True</value>
<value key="jscompilation">++plone++uwosh.oie.studyabroadstudent/programedit.js</value>
<value key="compile">False</value>
<value key="depends">plone</value>
<value key="merge_with">logged-in</value>
</records>
A couple of notes:
-
The pseudo path string "++plone++uwosh.oie.studyabroadstudent/programedit.js" comes from the type value "plone" and the name value "uwosh.oie.studyabroadstudent" that are in the static folder definition in
browser/configure.zcml
-
In the
<records prefix=
value "plone.bundles/uwosh.oie.studyabroadstudent" I assume "plone.bundles" is magic and Shall Not Be Messed With, but I don't know if "uwosh.oie.studyabroadstudent" is arbitrary or has to match the add-on name.
And if anyone is interested, here's the (maybe hackish?) JavaScript that I added some coordination logic among a few widgets on the edit form, in programedit.js
: https://github.com/uwosh/uwosh.oie.studyabroadstudent/blob/master/src/uwosh/oie/studyabroadstudent/browser/static/programedit.js