Topic: Categories on the fly

One of my favorite features of Basecamp is that you can make new categories quickly and easily. You simply select New Category from the drop-down and you get a pop-up window asking for the new name. You hit OK and it refreshes the select list and selects your newly created category.

Took a peek at the HTML:

Category: <select id="category_select" name="post[category_id]"><option value="8551088">Assets</option>
<option value="8551085">Code</option>
<option value="8551086">Copywriting</option>
<option value="8551084">Design</option>
<option value="8551089">Miscellaneous</option>
<option value="8551087">Transcripts</option><option value='!'>&mdash; add a new category &mdash;</option></select><script type="text/javascript">

I know I need to assign a dom id to the select list as a JS hook, and aslo set up a create category action in my controller. I'm just at a loss on how to get that popup window open and then get it to refresh the list.


Re: Categories on the fly

I imagine categorySelect is sort of like observe_field, watching the category selection. When the option value is !, it calls an RJS action that probably looks like:

page <<

And gets a partial onto there by replacing the elements on the blank window, or possibly writing it straight away, depending how they do the window open. When you finish putting in the category name in the open window, you'll probably click a button like "Commit!" and it'll take you to another action that closes the current window and refreshes category_select.

That's just a guess, anyhow, and pretty pseudocoded at that.