[jifty-devel] Manipulating page regions from actions

Sterling Hanenkamp sterling at hanenkamp.com
Sat Aug 16 22:41:42 EDT 2008


Maybe there's a way to do this, but I have found myself recently wanting to
be able to manipulate page regions on the basis of an action's result.

For example, I have an action that does a bunch of magic based upon the
input. I have a page that shows a list of timers. These timers each belong
to an entry, which groups a set of timers together. Each entry has a list of
tasks associated with it that is displayed in a sidebar of each timer for
that entry.

My magic action may have one of the following 5 manipulations that could
happen. I've listed the region manipulations I wish to do for each:

   1. *Create a task.* If the action creates a new task, it will need to
   insert the task into zero or more lists (zero or more page regions depending
   on how many timers are currently being displayed on the page).
   2. *Comment on a task.* In this case, we don't need to refresh anything.
   All regions should remain unchanged.
   3. *Comment on a timer.* I'd need to insert the new comment at the top of
   the comments list (a region) on the top-most timer.
   4. *Restart an entry.* I'd need to insert a new timer (complete with a
   list of comments and tasks) at the top of the timers list.
   5. *Start a new entry.* This is exactly the same as (4), it just happens
   to represent a new, never before seen entry.

I can do this pretty easily by just refreshing the whole page, but I'd
rather not. The page can get pretty long by the end of a day and the point
of using ajax is so that I don't have to refresh the whole page.

What I feel like I'd like to do is something like this from the action:

# on create a task
$self->result->update_page({
    region => 'entry_list-entry_14-task_list',
    prepend => '/journal/task',
    arguments => {
        task_id => 103,
        format => 'journal',
    },
});

# on comment on a task.... nothing

# on comment on a timer
$self->result->update_page({
    region => 'entry_list-entry_14-comment_list',
    prepend => '/journal/view_comment',
    arguments => { comment_id => 7813 },
});

# on restart an entry
$self->result->update_page({
    region => 'entry_list',
    prepend => '/journal/view_timer',
    arguments => { timer_id => 155 },
});

# on start a new entry
# same as above

Essentially, I'd like to change the onclick actions in the response from the
action itself rather than having to foreknow them during at click time.

The other solution I've come up with (and quite possibly the one I use for
now) is to include 5 different buttons that each do these things. Then,
present the button that does the right thing as soon as we have enough input
to make that judgment. I do that to some extent now by having an extra ajax
request that changes the name of the button to something that hints at
what's going on (1=Taskinate, 2=Comment, 3=Post, 4=Restart, 5=Start), but
there are a couple places where I'm going to have to handle that delicately
to make sure it DWIMs.

I'm open to doing this anyway that works reasonably well and will to commit
smallish sized patches to help at thsi time, but I don't have much time to
spare at the moment for anything moderate to largish.

Any suggestions?

Cheers,
Sterling
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jifty.org/pipermail/jifty-devel/attachments/20080816/72b06b95/attachment.htm 


More information about the jifty-devel mailing list