[jifty-devel] Dispatcher

Andrew Sterling Hanenkamp sterling at hanenkamp.com
Fri Oct 26 12:13:27 EDT 2007


On 10/24/07, Steve H <s_t_e_v_e_h at hotmail.com> wrote:
>
>
> Hi
>
> Further to my question (not yet responded to) from my prev post, is there
> anyone who could provide a code snippet or other insight as to how I would
> (presumably in the Dispatcher), invoke a different action or fragment that
> would update/target a different region.  My attempts to date have the output
> from calls from the Dispatcher to any other fragments, update the region
> associated with the original Dispatcher run/code block.  A use case might
> be: I have a region that can input some criteria (e.g. search or index);
> In it's run code-block, I would like to use it's data (e.g. from action
> response or get()) to then invoke a fragment that will target a DIFFERENT
> region.  That other region should also be able to independently function,
> e.g. next/prev from a pager, and/or submit/s to select and further process
> items of interest).


I'm not sure the Dispatcher is the best place to manipulate regions. The
dispatcher is invoked on request by the client for a specific region, but
can't really talk directly back to the client to tell it to refresh another
region. For that you need a link or button that knows to refresh the other
region.

Jifty->web->link( label => _('See Group 4'), onclick => { refresh =>
'other-region', args => { group => 4 } });

I don't have a working example using the Jifty API that I can think of off
hand, but I do have this in one of my app_behaviour.js scripts:

        element.onclick = function() {
            var question_id = this.id.substr(9);
            update({
                fragments: [
                    {
                        mode: 'Replace',
                        args: {
                            question_id: question_id
                        },
                        region: 'inventory-monster-chart'
                    }
                ]
            }, this);
            new Effect.ScrollTo('region-inventory', { offset: 40 });
        };

This is used on report that shows a bunch of little graphs at the bottom and
a "monster" graph at the top. Clicking on one of the little graphs causes
the monster graph to update to show the same data up top. If I had done this
in the Jifty API, I could have created links like:

Jifty->web->link( label => _('This Chart'), onclick => { refresh =>
'inventory-monster-chart', args => { question_id => $question_id } } );

If I had a form that submitted an action, I could act on the action too by
taking advantage of Jifty::Request::Mapper:

Jifty->web->submit( label => _('Pick Chart'), onclick => [ { submit =>
$some_action }, { refresh => 'inventory-monster-chart', args => {
question_id => { result => $some_action, name => 'question_id' } } } ] );

This would submit the action in $some_action and then refresh the monster
chart and set the new question_id to the value in
$some_action->result->content('question_id') once the action was processed.
I haven't done this exact thing in a bit, so I might have gotten a detail or
two a little off, but that's the gist of how links/buttons can manipulate
regions on the basis of the click or action submitted on click.


...if not able to be done within the original Dispatcher code-block, can/how
> might it be able to construct and inject a separate Request (back into the
> Dispatcher) that could also specify the other region as the one to output
> to?
>
> regards
> SteveH
>
> > From: s_t_e_v_e_h at hotmail.com
> > To: jifty-devel at lists.jifty.org
> > Subject: FW: Some help and/or pointers to doco: updating calling other
> region's/fragments from an action
> > Date: Tue, 9 Oct 2007 11:38:08 +1000
> >
> >
> >
> >> From: s_t_e_v_e_h at hotmail.com
> >> To: jifty-devel at lists.jifty.org
> >> Subject: Some help and/or pointers to doco: updating calling other
> region's/fragments from an action
> >> Date: Sun, 7 Oct 2007 23:19:35 +1000
> >>
> >
> >> I was unable to see from doco or example, how I would cause another
> region/fragment to update from a different region's action.
> >> For example, I have a page that I've composed with various Regions. One
> of these can have search criteria entered, another can add entries, and
> another includes a table of data fetched/displayed via a collection and
> pager. I was wanting to have the pager fragment execute to repopulate it's
> region following input/submit of data into either the Search region or the
> Add region. Both the search and add have an Action defined. I'd anticipated
> using criteria entered in the Search, as args for the Collection used in the
> pager fragment.
> >> The appropriate doco or examples have so far eluded me... along with
> any perhaps more Jifty'esq ways to do it.
> >>
> >>
> >
> > An update: Someone responded to me via the IRC. The penny that hadn't
> dropped for me was related to what is calling what/when/where... in that I
> was looking for how to call a fragment after processing an Action, when all
> along it was the fragment/s that had called the Action in the first place
> and thus execution would naturally return there after processing the
> action... so I just had to include a bit of trace/debug and look a bit
> closer at the call stack. All that said though, I needed to use info from
> args that were visible in the Action. It then became apparent that the same
> args were visible in the calling fragment that execution returned to...
> thing was though, I needed that info in a fragment that was called then from
> that fragment. After much poking and proding, it became apparent that I
> needed to declare the call to the fragment in which I need the info with a
> "default =>" clause and line it up with the args in the called fragment.
> >
> > ...so far, surviving the learning curve.
> > SteveH
> >
> > _________________________________________________________________
> > New music from the Rogue Traders - listen now!
> >
> http://ninemsn.com.au/share/redir/adTrack.asp?mode=click&clientID=832&referral=hotmailtaglineOct07&URL=http://music.ninemsn.com.au/roguetraders
>
> _________________________________________________________________
> It's simple! Sell your car for just $30 at CarPoint.com.au
>
> http://a.ninemsn.com.au/b.aspx?URL=http%3A%2F%2Fsecure%2Dau%2Eimrworldwide%2Ecom%2Fcgi%2Dbin%2Fa%2Fci%5F450304%2Fet%5F2%2Fcg%5F801459%2Fpi%5F1004813%2Fai%5F859641&_t=762955845&_r=tig_OCT07&_m=EXT_______________________________________________
> jifty-devel mailing list
> jifty-devel at lists.jifty.org
> http://lists.jifty.org/cgi-bin/mailman/listinfo/jifty-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.bestpractical.com/pipermail/jifty-devel/attachments/20071026/b6c6a7f3/attachment.htm


More information about the jifty-devel mailing list