Ticket #373 (new enhancement)

Opened 16 years ago

Last modified 16 years ago

event-handler types given format attribute

Reported by: Chuck Savage <chuck@…> Owned by:
Priority: normal Milestone: Experimental
Version: 3.0.178 Severity: normal
Keywords: Cc:

Description

I'd like to see event-handler types moved from an attribute of the event-handler to an element, and given it's own attribute of format. It'd really be helpful to be able to assign formats so that certain types would only be called for certain request formats.

For instance, an edit form, doesn't need sidebar or main template information if called within a cfwindow.

To do the same currently, requires a whole new event-handler that is exactly the same as the other one, minus the types that aren't involved. Too much duplicate code.

Change History

Changed 16 years ago by DanWilson

Can you put the format="cfwindow" on the view or include tag? I believe that is supported... Try it and get back to us.

Changed 16 years ago by cfgrok

A small clarification: the format attribute can be used on the <views> container (as well as the <broadcasts> and <results> containers), not on the actual <include> or <view> tag itself.

Changed 16 years ago by Chuck Savage <chuck@…>

Dan I think you missed the point, what I'm suggesting is that type's be optionally executed based on a format. So instead of this...

<event-handler name="edit.cfwindow"> same exact event handler internal code </event-handler> and <event-handler name="edit.html" type="Sidebar,MainTemplate?"> same exact event handler internal code </event-handler>

You'd have

<event-handler name="edit"> <types format="cfwindow" /> <types format="html">

<type name="Sidebar" value="Sidebar"/> <type name="MainTemplate?" value="MainTemplate?" />

</types>

Or

<event-handler name="edit"> <types format="cfwindow" value="" /> <types format="html" value="Sidebar,MainTemplate?"/>

Put the choice of execution of types in the control of the event-handler's types element not in the naming of events.

Changed 16 years ago by Chuck Savage <chuck@…>

Ok, wow that mangled the code, wrapped everything in <p> tags. I'll try again,

<event-handler name="edit.cfwindow"> 
 same exact event handler internal code 
</event-handler> 
and 
<event-handler name="edit.html" type="Sidebar,MainTemplate">
 same exact event handler internal code 
</event-handler>

You'd have

<event-handler name="edit"> 
<types format="cfwindow" /> 
<types format="html">
  <type name="Sidebar" value="Sidebar"/> 
  <type name="MainTemplate" value="MainTemplate" />
</types>

Or

<event-handler name="edit"> 
<types format="cfwindow" value="" /> 
<types format="html" value="Sidebar,MainTemplate"/>

Changed 16 years ago by cfgrok

Chuck, as the format attribute can be used within an event-type, it should already be possible to accomplish your desired result. Given your example code, you'd do something like this:

<event-type name="Sidebar">
    <after>
        <views format="html">
            <include name="sidebar" template="templates/sidebar.cfm" />
        </views>
    </after>
</event-type>

<event-type name="MainTemplate">
    <after>
        <views format="html">
            <include name="sidebar" template="templates/maintemplate.cfm" />
        </views>
    </after>
</event-type>

<event-handler name="edit" type="Sidebar,MainTemplate">
    <views>
        <include name="body" template="pages/edit.cfm" />
    </views>
</event-handler>

Does that make sense?

Changed 16 years ago by cfgrok

Oops, the name attribute on the <include> tag for the MainTemplate? type should be "template", not "sidebar" (well, anything other than "sidebar" or "body", really).

Changed 16 years ago by Chuck Savage <chuck@…>

Of course, it's a work-around for the enhancement. It further obfuscates the issue as I explained above. Sidebar and MainTemplate? now as you've coded above ONLY work in html formats, and not in every format that is required. What if you had http and https versions, etc. Also what if sometimes you did want the Sidebar in a cfwindow? Then you'd have to duplicate the type and call it by another name.

A simple switch/branch statement in the event-handler makes sense to me, rather than a zillion switch/branch statement in every type.

Why not just have the event-handler choose when to run a type and not be hard coded as it is currently.

Changed 16 years ago by DanWilson

  • milestone set to 3.1.x-next-patch

Changed 16 years ago by boomfish

  • milestone changed from 3.1.x-next-patch to Experimental

Event types injected into event handlers when the framework is initialized, so linking event types to event handlers at request time would involve a significant change to the code.

I want to keep this ticket open for discussion but I do not see how we can even plan to include such an enhancement in a release of Model-Glue until we get a better feel for how it will actually work.

Note: See TracTickets for help on using tickets.