<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>hocuspokus &#187; noteworthy</title>
	<atom:link href="http://hocuspokus.net/category/noteworthy/feed" rel="self" type="application/rss+xml" />
	<link>http://hocuspokus.net</link>
	<description>the life and times of a code monkey</description>
	<lastBuildDate>Tue, 01 Jun 2010 16:40:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Add Git and SVN Branch to Bash&#160;Prompt</title>
		<link>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2009%2F07%2Fadd-git-and-svn-branch-to-bash-prompt&amp;seed_title=Add+Git+and+SVN+Branch+to+Bash%26%23160%3BPrompt</link>
		<comments>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2009%2F07%2Fadd-git-and-svn-branch-to-bash-prompt&amp;seed_title=Add+Git+and+SVN+Branch+to+Bash%26%23160%3BPrompt#comments</comments>
		<pubDate>Thu, 09 Jul 2009 19:58:06 +0000</pubDate>
		<dc:creator>Daz</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[noteworthy]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[command-line]]></category>
		<category><![CDATA[geek]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[os x]]></category>
		<category><![CDATA[svn]]></category>

		<guid isPermaLink="false">http://hocuspokus.net/?p=352</guid>
		<description><![CDATA[EDIT: (12-Mar-2010) slight update to the svn prompt code to give a better / more useful output&#8230; I&#8217;ve seen things like this posted on the net before but never really had a chance to play with the idea. But as &#8230; <a href="http://hocuspokus.net/feeder/?FeederAction=clicked&#38;feed=Articles+%28RSS2%29&#38;seed=http%3A%2F%2Fhocuspokus.net%2F2009%2F07%2Fadd-git-and-svn-branch-to-bash-prompt&#38;seed_title=Add+Git+and+SVN+Branch+to+Bash%26%23160%3BPrompt">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><strong>EDIT:</strong> (12-Mar-2010) slight update to the svn prompt code to give a better / more useful output&#8230;</p>

<p>I&#8217;ve seen things like this posted on the net before but never really had a chance to play with the idea.  But as I&#8217;m now using git and svn a lot more these days (fingers crossed i&#8217;ll be totally free of cvs soon!) I thought it was about time I pulled my finger out.</p>

<p>So here&#8217;s the end goal, in a normal directory, we just get a normal bash promt, but in a directory controlled by git or svn, we also get an addition telling us the source control tool in use and the current branch:</p>

<p><img src="http://hocuspokus.net/wp-content/uploads/2009/07/git_svn_bash_terminal.png" alt="git_svn_bash_terminal" title="git_svn_bash_terminal" width="500" height="305" class="aligncenter size-full wp-image-358" /></p>

<p>So, fire up yer terminal and add the following to your <code>.profile</code>, <code>.bash_profile</code> or <code>.bashrc</code> (whichever one you use):</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">parse_git_branch <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
	git name-rev HEAD <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s#HEAD\ \(.*\)# (git::\1)#'</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
parse_svn_branch<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
	parse_svn_url <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s#^'</span><span style="color: #ff0000;">&quot;<span style="color: #007800;">$(parse_svn_repository_root)</span>&quot;</span><span style="color: #ff0000;">'##g'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print &quot; (svn::&quot;$1&quot;)&quot; }'</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
parse_svn_url<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
	<span style="color: #c20cb9; font-weight: bold;">svn</span> info <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-ne</span> <span style="color: #ff0000;">'s#^URL: ##p'</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
parse_svn_repository_root<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
	<span style="color: #c20cb9; font-weight: bold;">svn</span> info <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-ne</span> <span style="color: #ff0000;">'s#^Repository Root: ##p'</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #007800;">BLACK</span>=<span style="color: #ff0000;">&quot;\[\033[0;38m\]&quot;</span>
<span style="color: #007800;">RED</span>=<span style="color: #ff0000;">&quot;\[\033[0;31m\]&quot;</span>
<span style="color: #007800;">RED_BOLD</span>=<span style="color: #ff0000;">&quot;\[\033[01;31m\]&quot;</span>
<span style="color: #007800;">BLUE</span>=<span style="color: #ff0000;">&quot;\[\033[01;34m\]&quot;</span>
<span style="color: #007800;">GREEN</span>=<span style="color: #ff0000;">&quot;\[\033[0;32m\]&quot;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">PS1</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$BLACK</span>[ \u@<span style="color: #007800;">$RED</span>\h <span style="color: #007800;">$GREEN</span>\w<span style="color: #007800;">$RED_BOLD</span><span style="color: #000099; font-weight: bold;">\$</span>(parse_git_branch)<span style="color: #000099; font-weight: bold;">\$</span>(parse_svn_branch)<span style="color: #007800;">$BLACK</span> ] &quot;</span></pre></div></div>


<p>Simples.  Now just open up a new terminal and move into a project directory using svn or git. <img src='http://hocuspokus.net/wp-content/plugins/smilies-themer/tango/face-smile.png' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2009%2F07%2Fadd-git-and-svn-branch-to-bash-prompt&amp;seed_title=Add+Git+and+SVN+Branch+to+Bash%26%23160%3BPrompt/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Sync Your Things Database via&#160;Dropbox</title>
		<link>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2008%2F11%2Fsync-your-things-database-via-dropbox&amp;seed_title=Sync+Your+Things+Database+via%26%23160%3BDropbox</link>
		<comments>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2008%2F11%2Fsync-your-things-database-via-dropbox&amp;seed_title=Sync+Your+Things+Database+via%26%23160%3BDropbox#comments</comments>
		<pubDate>Thu, 06 Nov 2008 10:03:09 +0000</pubDate>
		<dc:creator>Daz</dc:creator>
				<category><![CDATA[mac]]></category>
		<category><![CDATA[noteworthy]]></category>
		<category><![CDATA[dropbox]]></category>
		<category><![CDATA[gtd]]></category>
		<category><![CDATA[sync]]></category>
		<category><![CDATA[things]]></category>
		<category><![CDATA[to-do]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://hocuspokus.net/?p=241</guid>
		<description><![CDATA[Dropbox is a great service, I&#8217;m using it happily to keep my files in sync across multiple computers - I&#8217;m even using it to keep all of my passwords in sync, but I&#8217;ve thought of another great use&#8230; How about &#8230; <a href="http://hocuspokus.net/feeder/?FeederAction=clicked&#38;feed=Articles+%28RSS2%29&#38;seed=http%3A%2F%2Fhocuspokus.net%2F2008%2F11%2Fsync-your-things-database-via-dropbox&#38;seed_title=Sync+Your+Things+Database+via%26%23160%3BDropbox">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="https://www.getdropbox.com/">Dropbox</a> is a great service, I&#8217;m using it happily to keep my files in sync across multiple computers - I&#8217;m even using it to keep all of my <a href="http://www.switchersblog.com/2008/10/1password-29-br.html">passwords in sync</a>, but I&#8217;ve thought of another great use&#8230;  How about syncing my <a href="http://culturedcode.com/things/">Things</a> database between my macs (as this is my to-do list manager of choice)?</p>

<p>This is not fully tested yet, (just thought of it this morning) so i&#8217;ll update a bit later and report on as to wether things goes completely mental, but the way I&#8217;ve done this is as follows&#8230;</p>

<p>Make sure Things is completely shut down, then open up a terminal and type in the following commands:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> ~<span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>Application\ Support<span style="color: #000000; font-weight: bold;">/</span>Cultured\ Code<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>


<p>This moves us into the correct directory.  First, to be on the safe side - we&#8217;ll take a backup of our files&#8230;</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #660033;">-R</span> Things Things.bak</pre></div></div>


<p>Now just move the Things directory into your dropbox and create a symbolic link in its place.</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">mv</span> Things ~<span style="color: #000000; font-weight: bold;">/</span>Dropbox<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> ~<span style="color: #000000; font-weight: bold;">/</span>Dropbox<span style="color: #000000; font-weight: bold;">/</span>Things Things</pre></div></div>


<p>Fingers crossed this should have the desired results! <img src='http://hocuspokus.net/wp-content/plugins/smilies-themer/tango/face-smile.png' alt=':)' class='wp-smiley' /> </p>

<p><strong>Update:</strong> It works!!! <img src='http://hocuspokus.net/wp-content/plugins/smilies-themer/tango/face-smile-big.png' alt=':D' class='wp-smiley' />  On the second computer all you need to do to get the ball rolling is to close down Things, open up a terminal and type the following commands:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> ~<span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>Application\ Support<span style="color: #000000; font-weight: bold;">/</span>Cultured\ Code<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> Things
<span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> ~<span style="color: #000000; font-weight: bold;">/</span>Dropbox<span style="color: #000000; font-weight: bold;">/</span>Things Things</pre></div></div>


<p>Note - my 2nd mac only had a fresh install of Things - <strong>no data</strong>.  I installed it, opened it up (so the initial database was created), then did the above.</p>
]]></content:encoded>
			<wfw:commentRss>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2008%2F11%2Fsync-your-things-database-via-dropbox&amp;seed_title=Sync+Your+Things+Database+via%26%23160%3BDropbox/feed</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Default Text Field Values That Disappear on&#160;Focus</title>
		<link>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2008%2F05%2Fdefault-text-field-values-that-disappear-on-focus&amp;seed_title=Default+Text+Field+Values+That+Disappear+on%26%23160%3BFocus</link>
		<comments>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2008%2F05%2Fdefault-text-field-values-that-disappear-on-focus&amp;seed_title=Default+Text+Field+Values+That+Disappear+on%26%23160%3BFocus#comments</comments>
		<pubDate>Fri, 16 May 2008 18:08:58 +0000</pubDate>
		<dc:creator>Daz</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[noteworthy]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[prototype]]></category>

		<guid isPermaLink="false">http://hocuspokus.net/?p=146</guid>
		<description><![CDATA[You will have noticed this effect out on your travels on the internet - a text input field has some default text in it (often in a slightly dimmed colour), and when you click on the text box, default text &#8230; <a href="http://hocuspokus.net/feeder/?FeederAction=clicked&#38;feed=Articles+%28RSS2%29&#38;seed=http%3A%2F%2Fhocuspokus.net%2F2008%2F05%2Fdefault-text-field-values-that-disappear-on-focus&#38;seed_title=Default+Text+Field+Values+That+Disappear+on%26%23160%3BFocus">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>You will have noticed this effect out on your travels on the internet - a text input field has some default text in it (often in a slightly dimmed colour), and when you click on the text box, default text disappears and then reappears when you click away from the box.  It happens on the search box to the right here too.</p>

<p>I needed this same effect at work today so a quick Google came up with this great <a href="http://webdeveloper.beforeseven.com/jquery/default-text-field-value-disappears-focus">blog post</a> - a lovely example of the exact effect I was looking for in both raw javascript and a version using the <a href="http://jquery.com/">jQuery</a> library.</p>

<blockquote>
  <p>The script searches the page that it&#8217;s inserted on for all form input fields that have a class of &#8216;default-value&#8217; applied. Each form input field must also have a unique ID.</p>
  
  <p>When the page loads the script changes the color of the text in the text fields it has found to the value of &#8216;inactive&#95;color&#8217;. If the user clicks on the input field, the default text is blanked, and the colour changed to &#8216;active&#95;color&#8217;. If the user clicks away from the input field, i.e. the input field loses focus, the value of the text field will revert back to the original text, and the colour will change back to &#8216;inactive&#95;color&#8217;, unless the user has entered some other text.</p>
</blockquote>

<p>Here&#8217;s a copy of the jQuery version for my own personal notes, never know when that could be useful:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/*
 * Written by Rob Schmitt, The Web Developer's Blog
 * http://webdeveloper.beforeseven.com/
 */</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> active_color <span style="color: #339933;">=</span> <span style="color: #3366CC;">'#000'</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// Colour of user provided text</span>
<span style="color: #003366; font-weight: bold;">var</span> inactive_color <span style="color: #339933;">=</span> <span style="color: #3366CC;">'#999'</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// Colour of default text</span>
&nbsp;
$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;input.default-value&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;color&quot;</span><span style="color: #339933;">,</span> inactive_color<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #003366; font-weight: bold;">var</span> default_values <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Array<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;input.default-value&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066;">focus</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>default_values<span style="color: #009900;">&#91;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">id</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      default_values<span style="color: #009900;">&#91;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">id</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">value</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">value</span> <span style="color: #339933;">==</span> default_values<span style="color: #009900;">&#91;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">id</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">value</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
      <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">style</span>.<span style="color: #660066;">color</span> <span style="color: #339933;">=</span> active_color<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066;">blur</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">value</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">style</span>.<span style="color: #660066;">color</span> <span style="color: #339933;">=</span> inactive_color<span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">value</span> <span style="color: #339933;">=</span> default_values<span style="color: #009900;">&#91;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">id</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>


<p>However, we don&#8217;t use jQuery at work, our entire site is based around <a href="http://www.prototypejs.org/">Prototype</a> and <a href="http://script.aculo.us/">script.aculo.us</a>, so I did a bit of butchering and here&#8217;s the code adapted to use Prototype:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/*
 * Written by Darren Oakley
 * http://hocuspokus.net
 */</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> active_color <span style="color: #339933;">=</span> <span style="color: #3366CC;">'#000'</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// Colour of user provided text</span>
<span style="color: #003366; font-weight: bold;">var</span> inactive_color <span style="color: #339933;">=</span> <span style="color: #3366CC;">'#999'</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// Colour of default text</span>
&nbsp;
Event.<span style="color: #660066;">observe</span><span style="color: #009900;">&#40;</span> window<span style="color: #339933;">,</span> <span style="color: #3366CC;">'load'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> default_values <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Array<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;input.default-value&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>s<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        $<span style="color: #009900;">&#40;</span>s<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">setStyle</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> color<span style="color: #339933;">:</span> inactive_color <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        $<span style="color: #009900;">&#40;</span>s<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">observe</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'focus'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>default_values<span style="color: #009900;">&#91;</span>s.<span style="color: #660066;">id</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                default_values<span style="color: #009900;">&#91;</span>s.<span style="color: #660066;">id</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> s.<span style="color: #660066;">value</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>s.<span style="color: #660066;">value</span> <span style="color: #339933;">==</span> default_values<span style="color: #009900;">&#91;</span>s.<span style="color: #660066;">id</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                s.<span style="color: #660066;">value</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
                $<span style="color: #009900;">&#40;</span>s<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">setStyle</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> color<span style="color: #339933;">:</span> active_color <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            $<span style="color: #009900;">&#40;</span>s<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">observe</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'blur'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>s.<span style="color: #660066;">value</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    $<span style="color: #009900;">&#40;</span>s<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">setStyle</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> color<span style="color: #339933;">:</span> inactive_color <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    s.<span style="color: #660066;">value</span> <span style="color: #339933;">=</span> default_values<span style="color: #009900;">&#91;</span>s.<span style="color: #660066;">id</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>


<p>Now all you need to do is give your input text fields a unique id, and the class of &#8216;default-value&#8217;, then the script will take care of the rest.</p>
]]></content:encoded>
			<wfw:commentRss>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2008%2F05%2Fdefault-text-field-values-that-disappear-on-focus&amp;seed_title=Default+Text+Field+Values+That+Disappear+on%26%23160%3BFocus/feed</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Install PostgreSQL on Ubuntu&#160;8.04</title>
		<link>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2008%2F05%2Finstall-postgresql-on-ubuntu-804&amp;seed_title=Install+PostgreSQL+on+Ubuntu%26%23160%3B8.04</link>
		<comments>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2008%2F05%2Finstall-postgresql-on-ubuntu-804&amp;seed_title=Install+PostgreSQL+on+Ubuntu%26%23160%3B8.04#comments</comments>
		<pubDate>Tue, 13 May 2008 16:19:41 +0000</pubDate>
		<dc:creator>Daz</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[noteworthy]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://hocuspokus.net/?p=145</guid>
		<description><![CDATA[Following up from my old guide to installing PostgreSQL (for Ubuntu 7.10), I thought i&#8217;d better do an update for the latest releases&#8230; This quick walk-through are my notes for installing the PostgreSQL database server and the PgAdmin administration application &#8230; <a href="http://hocuspokus.net/feeder/?FeederAction=clicked&#38;feed=Articles+%28RSS2%29&#38;seed=http%3A%2F%2Fhocuspokus.net%2F2008%2F05%2Finstall-postgresql-on-ubuntu-804&#38;seed_title=Install+PostgreSQL+on+Ubuntu%26%23160%3B8.04">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Following up from my old guide to installing PostgreSQL (for Ubuntu 7.10), I thought i&#8217;d better do an update for the latest releases&#8230; <img src='http://hocuspokus.net/wp-content/plugins/smilies-themer/tango/face-smile.png' alt=':)' class='wp-smiley' /> </p>

<p>This quick walk-through are my notes for installing the PostgreSQL database server and the PgAdmin administration application on Ubuntu Linux, and also set up the server so it allows access to other PC&#8217;s on your network.</p>

<p>Before we move on, this guide was tested on the current release of Ubuntu Linux, (8.04 - Hardy Heron) and PostgreSQL 8.3, but it should also be applicable to older versions (of Ubuntu and PostgreSQL) and other Debian based distros.</p>

<p><span id="more-145"></span></p>

<p>Right for the basic installation, at the command-line, enter the following commands (or search for the listed packages in synaptic if you prefer that way of working):</p>

<pre><code>$ sudo apt-get install postgresql postgresql-client postgresql-contrib
$ sudo apt-get install pgadmin3
</code></pre>

<p>This installs the database server/client, some extra utility scripts and the pgAdmin GUI application for working with the database.</p>

<p>Now we need to reset the password for the &#8216;postgres&#8217; admin account for the server, so we can use this for all of the system administration tasks. Type the following at the command-line (substitute in the password you want to use for your administrator account):</p>

<pre><code>$ sudo su postgres -c psql template1
template1=# ALTER USER postgres WITH PASSWORD 'password';
template1=# \q
</code></pre>

<p>That alters the password for within the database, now we need to do the same for the unix user &#8216;postgres&#8217;:</p>

<pre><code>$ sudo passwd -d postgres
$ sudo su postgres -c passwd
</code></pre>

<p>Now enter the same password that you used previously.</p>

<p>Then, from here on in we can use both pgAdmin and command-line access (as the postgres user) to run the database server.  But before you jump into pgAdmin we should set-up the PostgreSQL admin pack that enables better logging and monitoring within pgAdmin.  Run the following at the command-line:</p>

<pre><code>$ sudo su postgres -c psql &lt; /usr/share/postgresql/8.3/contrib/adminpack.sql
</code></pre>

<p>Finally, we need to open up the server so that we can access and use it remotely - unless you only want to access the database on the local machine. To do this, first, we need to edit the postgresql.conf file:</p>

<pre><code>$ sudo gedit /etc/postgresql/8.3/main/postgresql.conf
</code></pre>

<p>Now, to edit a couple of lines in the &#8216;Connections and Authentication&#8217; section&#8230;</p>

<p>Change the line:</p>

<pre><code>#listen_addresses = 'localhost'
</code></pre>

<p>to</p>

<pre><code>listen_addresses = '*'
</code></pre>

<p>and also change the line:</p>

<pre><code>#password_encryption = on
</code></pre>

<p>to</p>

<pre><code>password_encryption = on
</code></pre>

<p>Then save the file and close gedit.</p>

<p>Now for the final step, we must define who can access the server. This is all done using the pg_hba.conf file.<sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup></p>

<pre><code>$ sudo gedit /etc/postgresql/8.3/main/pg_hba.conf
</code></pre>

<p>Comment out, or delete the current contents of the file, then add this text to the bottom of the file:</p>

<pre><code># DO NOT DISABLE!
# If you change this first entry you will need to make sure that the
# database
# super user can access the database using some other method.
# Noninteractive
# access to all databases is required during automatic maintenance
# (autovacuum, daily cronjob, replication, and similar tasks).
#
# Database administrative login by UNIX sockets
local   all         postgres                          ident sameuser
# TYPE  DATABASE    USER        CIDR-ADDRESS          METHOD

# "local" is for Unix domain socket connections only
local   all         all                               md5
# IPv4 local connections:
host    all         all         127.0.0.1/32          md5
# IPv6 local connections:
host    all         all         ::1/128               md5

# Connections for all PCs on the subnet
#
# TYPE DATABASE USER IP-ADDRESS IP-MASK METHOD
host    all         all         [ip address]          [subnet mask]  md5
</code></pre>

<p>and in the last line, add in your subnet mask (i.e. 255.255.255.0) and the IP address of the machine that you would like to access your server (i.e. 138.250.192.115). However, if you would like to enable access to a range of IP addresses, just substitute the last number for a zero and all machines within that range will be allowed access (i.e. 138.250.192.0 would allow all machines with an IP address 138.250.192.x to use the database server).</p>

<p>That&#8217;s it, now all you have to do is restart the server:</p>

<pre><code>$ sudo /etc/init.d/postgresql-8.3 restart
</code></pre>

<p>And all should be working.</p>

<div class="footnotes">
<hr />
<ol>

<li id="fn:1">
<p>The following advice can also be given to you (plus you don&#8217;t even need to figure out IP addresses and subnet masks) from the latest versions of pgAdmin (1.6.x).  But it doesn&#8217;t hurt to know how things work.&#160;<a href="#fnref:1" rev="footnote">&#8617;</a></p>
</li>

</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2008%2F05%2Finstall-postgresql-on-ubuntu-804&amp;seed_title=Install+PostgreSQL+on+Ubuntu%26%23160%3B8.04/feed</wfw:commentRss>
		<slash:comments>70</slash:comments>
		</item>
		<item>
		<title>Bio-Linux - Bioinformatics Tools for&#160;Linux</title>
		<link>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2008%2F03%2Fbio-linux-bioinformatics-tools-for-linux&amp;seed_title=Bio-Linux+-+Bioinformatics+Tools+for%26%23160%3BLinux</link>
		<comments>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2008%2F03%2Fbio-linux-bioinformatics-tools-for-linux&amp;seed_title=Bio-Linux+-+Bioinformatics+Tools+for%26%23160%3BLinux#comments</comments>
		<pubDate>Fri, 07 Mar 2008 08:52:03 +0000</pubDate>
		<dc:creator>Daz</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[noteworthy]]></category>
		<category><![CDATA[bioinformatics]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://hocuspokus.net/2008/03/07/bio-linux-bioinformatics-tools-for-linux/</guid>
		<description><![CDATA[Bio-Linux is a specialised Linux disro that provides both standard and cutting edge bioinformatics software tools on a Linux base. I wrote a post on my old blog a little while back now detailing how to use the packages from &#8230; <a href="http://hocuspokus.net/feeder/?FeederAction=clicked&#38;feed=Articles+%28RSS2%29&#38;seed=http%3A%2F%2Fhocuspokus.net%2F2008%2F03%2Fbio-linux-bioinformatics-tools-for-linux&#38;seed_title=Bio-Linux+-+Bioinformatics+Tools+for%26%23160%3BLinux">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://nebc.nox.ac.uk/biolinux.html">Bio-Linux</a> is a specialised Linux disro that provides both standard and cutting edge bioinformatics software tools on a Linux base.</p>

<p>I wrote a post on my old blog a little while back now detailing how to use the packages from Bio-Linux in <a href="http://www.ubuntu.com/">Ubuntu Linux</a>, but it got missed in the migration (sorry to all those who have been searching for it).  Here&#8217;s a repost and update for Ubuntu 7.10&#8230;</p>

<p><span id="more-120"></span></p>

<p>Log into your system and open up a terminal, then follow these stepsâ€¦</p>

<pre><code>sudo gedit /etc/apt/sources.list
</code></pre>

<p>Add the following lines to the end of the file:</p>

<pre><code># Bio-Linux package repository
deb http://envgen.nox.ac.uk/bio-linux/ unstable bio-linux
</code></pre>

<p>Save and close the file, now back at the terminal type the following:<sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup></p>

<pre><code>sudo apt-get update
sudo apt-get install bio-linux-base-directories bio-linux-staden
</code></pre>

<p>Next step is to set-up your environment for Bio-Linux&#8230;</p>

<pre><code>sudo gedit /etc/bash.bashrc
</code></pre>

<p>Add the following lines to the end of the file:</p>

<pre><code># Set up Bio-Linux Environment
source /usr/local/bioinf/config_files/aliasrc
source /usr/local/bioinf/config_files/bioenvrc
</code></pre>

<p>Save and close the file.</p>

<p>That&#8217;s it, now all of the packages available through Bio-Linux are now available to you in Ubuntu.  One final word of warning&#8230;  I&#8217;ve noticed that a few of the packages are a little out of date, (the Bio-Linux version of Taverna is 1.4, but 1.7 is <a href="http://taverna.sourceforge.net/">now available</a>)<sup id="fnref:2"><a href="#fn:2" rel="footnote">2</a></sup> so it might be worth checking the version numbers before installing things.</p>

<div class="footnotes">
<hr />
<ol>

<li id="fn:1">
<p>Note that we need to install the <code>bio-linux-staden</code> package, without this we&#8217;d have to do a bit more hacking in config files to stop getting errors whenever we open up a terminal.&#160;<a href="#fnref:1" rev="footnote">&#8617;</a></p>
</li>

<li id="fn:2">
<p>The other thing to note with the Bio-Linux version of Taverna - it doesn&#8217;t start properly without a little bit of hacking&#8230; <img src='http://hocuspokus.net/wp-content/plugins/smilies-themer/tango/face-sad.png' alt=':(' class='wp-smiley' />  (If you decided to go with the Bio-Linux version, you can launch it by running the following in the terminal: <code>/usr/local/bioinf/taverna/taverna/runme.sh</code>).&#160;<a href="#fnref:2" rev="footnote">&#8617;</a></p>
</li>

</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2008%2F03%2Fbio-linux-bioinformatics-tools-for-linux&amp;seed_title=Bio-Linux+-+Bioinformatics+Tools+for%26%23160%3BLinux/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>A Better Ls for Mac OS&#160;X</title>
		<link>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2008%2F01%2Fa-better-ls-for-mac-os-x&amp;seed_title=A+Better+Ls+for+Mac+OS%26%23160%3BX</link>
		<comments>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2008%2F01%2Fa-better-ls-for-mac-os-x&amp;seed_title=A+Better+Ls+for+Mac+OS%26%23160%3BX#comments</comments>
		<pubDate>Fri, 04 Jan 2008 20:34:48 +0000</pubDate>
		<dc:creator>Daz</dc:creator>
				<category><![CDATA[mac]]></category>
		<category><![CDATA[noteworthy]]></category>
		<category><![CDATA[colour scheme]]></category>
		<category><![CDATA[command-line]]></category>
		<category><![CDATA[ego]]></category>
		<category><![CDATA[geek]]></category>
		<category><![CDATA[os x]]></category>
		<category><![CDATA[terminal]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://hocuspokus.net/2008/01/04/a-better-ls-for-mac-os-x/</guid>
		<description><![CDATA[I&#8217;m a bit of a command-line freak and like to spend a fair amount of time with the terminal open&#8230; As such I like to spend a small amount of time getting the terminal set-up nicely. Other than changing the &#8230; <a href="http://hocuspokus.net/feeder/?FeederAction=clicked&#38;feed=Articles+%28RSS2%29&#38;seed=http%3A%2F%2Fhocuspokus.net%2F2008%2F01%2Fa-better-ls-for-mac-os-x&#38;seed_title=A+Better+Ls+for+Mac+OS%26%23160%3BX">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m a bit of a command-line freak and like to spend a fair amount of time with the terminal open&#8230; As such  I like to spend a small amount of time getting the terminal set-up nicely.  Other than changing the default colour scheme and font, one (slightly) more drastic change is to replace the standard implementation of <code>ls</code> for one that is slightly more configurable.</p>

<p>The default <code>ls</code> on OS X comes from BSD and compared to the GNU/Linux alternative is slightly lacking when it comes to comes to changing how things look - so what I like to do is replace it with the GNU <code>ls</code> available in <a href="http://www.macports.org/">MacPorts</a> - this allows me to get a terminal setup like below:</p>

<div style="text-align:center;"><img src="http://hocuspokus.net/wp-content/uploads/2008/01/terminal.png" alt="terminal.png" /></div>

<p><span id="more-96"></span></p>

<p>To get this done is pretty simple, once you have MacPorts set up correctly (if you can type <code>man port</code> and get a manual page you&#8217;re ready), just run the following command:</p>

<pre><code>sudo port install coreutils +with_default_names
</code></pre>

<p>This installs the &#8216;GNU File, Shell, and Text utilities&#8217; which <code>ls</code> is part of - the extra option at the end <code>+with_default_names</code> makes it override (only override - not replace, this is totally removable) the default <code>ls</code> and other tools otherwise they will have a &#8216;g&#8217; prefix - i.e. <code>ls</code> would be <code>gls</code>.</p>

<p>Next we add some extra configuration to our <code>~/.bash_profile</code> file (i&#8217;ll include my MacPorts config in case you get stuck above)&#8230;</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># MacPorts</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">PATH</span>=<span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin:<span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>sbin:<span style="color: #007800;">$PATH</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">MANPATH</span>=<span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">man</span>:<span style="color: #007800;">$MANPATH</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Terminal colours (after installing GNU coreutils)</span>
<span style="color: #007800;">NM</span>=<span style="color: #ff0000;">&quot;\[\033[0;38m\]&quot;</span> <span style="color: #666666; font-style: italic;">#means no background and white lines</span>
<span style="color: #007800;">HI</span>=<span style="color: #ff0000;">&quot;\[\033[0;37m\]&quot;</span> <span style="color: #666666; font-style: italic;">#change this for letter colors</span>
<span style="color: #007800;">HII</span>=<span style="color: #ff0000;">&quot;\[\033[0;31m\]&quot;</span> <span style="color: #666666; font-style: italic;">#change this for letter colors</span>
<span style="color: #007800;">SI</span>=<span style="color: #ff0000;">&quot;\[\033[0;33m\]&quot;</span> <span style="color: #666666; font-style: italic;">#this is for the current directory</span>
<span style="color: #007800;">IN</span>=<span style="color: #ff0000;">&quot;\[\033[0m\]&quot;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">PS1</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$NM</span>[ <span style="color: #007800;">$HI</span>\u <span style="color: #007800;">$HII</span>\h <span style="color: #007800;">$SI</span>\w<span style="color: #007800;">$NM</span> ] <span style="color: #007800;">$IN</span>&quot;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$TERM</span>&quot;</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #ff0000;">&quot;dumb&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">LS_OPTIONS</span>=<span style="color: #ff0000;">'--color=auto'</span>
    <span style="color: #7a0874; font-weight: bold;">eval</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">dircolors</span> ~<span style="color: #000000; font-weight: bold;">/</span>.dir_colors<span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Useful aliases</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;"><span style="color: #c20cb9; font-weight: bold;">ls</span></span>=<span style="color: #ff0000;">'ls $LS_OPTIONS -hF'</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">ll</span>=<span style="color: #ff0000;">'ls $LS_OPTIONS -lhF'</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">l</span>=<span style="color: #ff0000;">'ls $LS_OPTIONS -lAhF'</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> cd..=<span style="color: #ff0000;">&quot;cd ..&quot;</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">c</span>=<span style="color: #ff0000;">&quot;clear&quot;</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">e</span>=<span style="color: #ff0000;">&quot;exit&quot;</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;"><span style="color: #c20cb9; font-weight: bold;">ssh</span></span>=<span style="color: #ff0000;">&quot;ssh -X&quot;</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> ..=<span style="color: #ff0000;">&quot;cd ..&quot;</span></pre></td></tr></table></div>


<p>Then finally we need to create a file called <code>.dir_colors</code> in our home directory that allows us to configure the colours used by <code>ls</code>:</p>

<pre><code>touch ~/.dir_colors
</code></pre>

<p>Then add the contents of the file here:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Configuration file for dircolors, a utility to help you set the</span>
<span style="color: #666666; font-style: italic;"># LS_COLORS environment variable used by GNU ls with the --color option.</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># The keywords COLOR, OPTIONS, and EIGHTBIT (honored by the</span>
<span style="color: #666666; font-style: italic;"># slackware version of dircolors) are recognized but ignored.</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Below, there should be one TERM entry for each termtype that is colorizable</span>
TERM linux
TERM linux-c
TERM mach-color
TERM console
TERM con132x25
TERM con132x30
TERM con132x43
TERM con132x60
TERM con80x25
TERM con80x28
TERM con80x30
TERM con80x43
TERM con80x50
TERM con80x60
TERM xterm
TERM xterm-color
TERM xterm-debian
TERM rxvt
TERM <span style="color: #c20cb9; font-weight: bold;">screen</span>
TERM screen-w
TERM vt100
&nbsp;
<span style="color: #666666; font-style: italic;"># Below are the color init strings for the basic file types. A color init</span>
<span style="color: #666666; font-style: italic;"># string consists of one or more of the following numeric codes:</span>
<span style="color: #666666; font-style: italic;"># Attribute codes:</span>
<span style="color: #666666; font-style: italic;"># 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed</span>
<span style="color: #666666; font-style: italic;"># Text color codes:</span>
<span style="color: #666666; font-style: italic;"># 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white</span>
<span style="color: #666666; font-style: italic;"># Background color codes:</span>
<span style="color: #666666; font-style: italic;"># 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white</span>
NORMAL 00	<span style="color: #666666; font-style: italic;"># global default, although everything should be something.</span>
FILE 00 	<span style="color: #666666; font-style: italic;"># normal file</span>
DIR 01;<span style="color: #000000;">36</span> 	<span style="color: #666666; font-style: italic;"># directory</span>
LINK 01;<span style="color: #000000;">37</span> 	<span style="color: #666666; font-style: italic;"># symbolic link.  (If you set this to 'target' instead of a</span>
           	<span style="color: #666666; font-style: italic;"># numerical value, the color is as for the file pointed to.)</span>
FIFO <span style="color: #000000;">40</span>;<span style="color: #000000;">33</span>	<span style="color: #666666; font-style: italic;"># pipe</span>
SOCK 01;<span style="color: #000000;">35</span>	<span style="color: #666666; font-style: italic;"># socket</span>
DOOR 01;<span style="color: #000000;">35</span>	<span style="color: #666666; font-style: italic;"># door</span>
BLK <span style="color: #000000;">40</span>;<span style="color: #000000;">33</span>;01	<span style="color: #666666; font-style: italic;"># block device driver</span>
CHR <span style="color: #000000;">40</span>;<span style="color: #000000;">33</span>;01 	<span style="color: #666666; font-style: italic;"># character device driver</span>
ORPHAN <span style="color: #000000;">40</span>;<span style="color: #000000;">31</span>;01 <span style="color: #666666; font-style: italic;"># symlink to nonexistent file</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># This is for files with execute permission:</span>
EXEC 01;<span style="color: #000000;">35</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># List any file extensions like '.gz' or '.tar' that you would like ls</span>
<span style="color: #666666; font-style: italic;"># to colorize below. Put the extension, a space, and the color init string.</span>
<span style="color: #666666; font-style: italic;"># (and any comments you want to add after a '#')</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># If you use DOS-style suffixes, you may want to uncomment the following:</span>
<span style="color: #666666; font-style: italic;">#.cmd 01;32 # executables (bright green)</span>
<span style="color: #666666; font-style: italic;">#.exe 01;32</span>
<span style="color: #666666; font-style: italic;">#.com 01;32</span>
<span style="color: #666666; font-style: italic;">#.btm 01;32</span>
<span style="color: #666666; font-style: italic;">#.bat 01;32</span>
&nbsp;
.tar 01;<span style="color: #000000;">31</span> <span style="color: #666666; font-style: italic;"># archives or compressed (bright red)</span>
.tgz 01;<span style="color: #000000;">31</span>
.arj 01;<span style="color: #000000;">31</span>
.taz 01;<span style="color: #000000;">31</span>
.lzh 01;<span style="color: #000000;">31</span>
.zip 01;<span style="color: #000000;">31</span>
.z   01;<span style="color: #000000;">31</span>
.Z   01;<span style="color: #000000;">31</span>
.gz  01;<span style="color: #000000;">31</span>
.bz2 01;<span style="color: #000000;">31</span>
.deb 01;<span style="color: #000000;">31</span>
.rpm 01;<span style="color: #000000;">31</span>
.jar 01;<span style="color: #000000;">31</span>
.dmg 01;<span style="color: #000000;">31</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># image formats</span>
.jpg 01;<span style="color: #000000;">35</span>
.png 01;<span style="color: #000000;">35</span>
.gif 01;<span style="color: #000000;">35</span>
.bmp 01;<span style="color: #000000;">35</span>
.ppm 01;<span style="color: #000000;">35</span>
.tga 01;<span style="color: #000000;">35</span>
.xbm 01;<span style="color: #000000;">35</span>
.xpm 01;<span style="color: #000000;">35</span>
.tif 01;<span style="color: #000000;">35</span>
.png 01;<span style="color: #000000;">35</span>
.mpg 01;<span style="color: #000000;">35</span>
.avi 01;<span style="color: #000000;">35</span>
.fli 01;<span style="color: #000000;">35</span>
.gl 01;<span style="color: #000000;">35</span>
.dl 01;<span style="color: #000000;">35</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># source code files</span>
.pl 00;<span style="color: #000000;">33</span>
.PL 00;<span style="color: #000000;">33</span>
.pm 00;<span style="color: #000000;">33</span>
.tt 00;<span style="color: #000000;">33</span>
.yml 00;<span style="color: #000000;">33</span>
.sql 00;<span style="color: #000000;">33</span>
.html 00;<span style="color: #000000;">33</span>
.css 00;<span style="color: #000000;">33</span>
.js 00;<span style="color: #000000;">33</span></pre></td></tr></table></div>


<p>Finally, all you need to do is close and re-open the Terminal.  Now we should be sorted. <img src='http://hocuspokus.net/wp-content/plugins/smilies-themer/tango/face-smile.png' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2008%2F01%2Fa-better-ls-for-mac-os-x&amp;seed_title=A+Better+Ls+for+Mac+OS%26%23160%3BX/feed</wfw:commentRss>
		<slash:comments>42</slash:comments>
		</item>
		<item>
		<title>Install PostgreSQL on Ubuntu&#160;7.10</title>
		<link>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F11%2Finstall-postgresql-on-ubuntu-710&amp;seed_title=Install+PostgreSQL+on+Ubuntu%26%23160%3B7.10</link>
		<comments>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F11%2Finstall-postgresql-on-ubuntu-710&amp;seed_title=Install+PostgreSQL+on+Ubuntu%26%23160%3B7.10#comments</comments>
		<pubDate>Mon, 05 Nov 2007 18:48:10 +0000</pubDate>
		<dc:creator>Daz</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[noteworthy]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[geek]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://hocuspokus.net/2007/11/05/install-posgresql-on-ubuntu-710/</guid>
		<description><![CDATA[If you are using the latest version of Ubuntu (8.04 - Hardy Heron), you might find these slightly updated instructions useful. This quick walk-through are my notes for installing the PostgreSQL database server and the PgAdmin administration application on Ubuntu &#8230; <a href="http://hocuspokus.net/feeder/?FeederAction=clicked&#38;feed=Articles+%28RSS2%29&#38;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F11%2Finstall-postgresql-on-ubuntu-710&#38;seed_title=Install+PostgreSQL+on+Ubuntu%26%23160%3B7.10">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p class="alert">If you are using the latest version of Ubuntu (8.04 - Hardy Heron), you might find these <a href="http://hocuspokus.net/2008/05/13/install-postgresql-on-ubuntu-804/">slightly updated instructions</a> useful.</p>

<p>This quick walk-through are my notes for installing the PostgreSQL database server and the PgAdmin administration application on Ubuntu Linux, and also set up the server so it allows access to other PC&#8217;s on your network.</p>

<p>Before we move on, this guide was tested on the current release of Ubuntu Linux, (7.10 - Gutsy Gibbon) and PostgreSQL 8.2, but it should also be applicable to older versions (of Ubuntu and PostgreSQL) and other Debian based distros.</p>

<p><span id="more-57"></span></p>

<p>Right for the basic installation, at the command-line, enter the following commands (or search for the listed packages in synaptic if you prefer that way of working):</p>

<pre><code>$ sudo apt-get install postgresql postgresql-client postgresql-contrib
$ sudo apt-get install pgadmin3
</code></pre>

<p>This installs the database server/client, some extra utility scripts and the pgAdmin GUI application for working with the database.</p>

<p>Now we need to reset the password for the &#8216;postgres&#8217; admin account for the server, so we can use this for all of the system administration tasks. Type the following at the command-line (substitute in the password you want to use for your administrator account):</p>

<pre><code>$ sudo su postgres -c psql template1
template1=# ALTER USER postgres WITH PASSWORD 'password';
template1=# \q
</code></pre>

<p>That alters the password for within the database, now we need to do the same for the unix user &#8216;postgres&#8217;:</p>

<pre><code>$ sudo passwd -d postgres
$ sudo su postgres -c passwd
</code></pre>

<p>Now enter the same password that you used previously.</p>

<p>Then, from here on in we can use both pgAdmin and command-line access (as the postgres user) to run the database server.  But before you jump into pgAdmin we should set-up the PostgreSQL admin pack that enables better logging and monitoring within pgAdmin.  Run the following at the command-line:</p>

<pre><code>$ sudo su postgres -c psql &lt; /usr/share/postgresql/8.2/contrib/adminpack.sql
</code></pre>

<p>Finally, we need to open up the server so that we can access and use it remotely - unless you only want to access the database on the local machine. To do this, first, we need to edit the postgresql.conf file:</p>

<pre><code>$ sudo gedit /etc/postgresql/8.2/main/postgresql.conf
</code></pre>

<p>Now, to edit a couple of lines in the &#8216;Connections and Authentication&#8217; section&#8230;</p>

<p>Change the line:</p>

<pre><code>#listen_addresses = 'localhost'
</code></pre>

<p>to</p>

<pre><code>listen_addresses = '*'
</code></pre>

<p>and also change the line:</p>

<pre><code>#password_encryption = on
</code></pre>

<p>to</p>

<pre><code>password_encryption = on
</code></pre>

<p>Then save the file and close gedit.</p>

<p>Now for the final step, we must define who can access the server. This is all done using the pg_hba.conf file.<sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup></p>

<pre><code>$ sudo gedit /etc/postgresql/8.2/main/pg_hba.conf
</code></pre>

<p>Comment out, or delete the current contents of the file, then add this text to the bottom of the file:</p>

<p><pre># DO NOT DISABLE!</p>

<h1>If you change this first entry you will need to make sure that the</h1>

<h1>database</h1>

<h1>super user can access the database using some other method.</h1>

<h1>Noninteractive</h1>

<h1>access to all databases is required during automatic maintenance</h1>

<h1>(autovacuum, daily cronjob, replication, and similar tasks).</h1>

<p>#</p>

<h1>Database administrative login by UNIX sockets</h1>

<p>local   all         postgres                          ident sameuser</p>

<h1>TYPE  DATABASE    USER        CIDR-ADDRESS          METHOD</h1>

<h1>"local" is for Unix domain socket connections only</h1>

<p>local   all         all                               md5</p>

<h1>IPv4 local connections:</h1>

<p>host    all         all         127.0.0.1/32          md5</p>

<h1>IPv6 local connections:</h1>

<p>host    all         all         ::1/128               md5</p>

<h1>Connections for all PCs on the subnet</h1>

<p>#</p>

<h1>TYPE DATABASE USER IP-ADDRESS IP-MASK METHOD</h1>

<p>host    all         all         [ip address]          [subnet mask]  md5</pre></p>

<p>and in the last line, add in your subnet mask (i.e. 255.255.255.0) and the IP address of the machine that you would like to access your server (i.e. 138.250.192.115). However, if you would like to enable access to a range of IP addresses, just substitute the last number for a zero and all machines within that range will be allowed access (i.e. 138.250.192.0 would allow all machines with an IP address 138.250.192.x to use the database server).</p>

<p>That&#8217;s it, now all you have to do is restart the server:</p>

<pre><code>$ sudo /etc/init.d/postgresql-8.2 restart
</code></pre>

<p>And all should be working.</p>

<div class="footnotes">
<hr />
<ol>

<li id="fn:1">
<p>The following advice can also be given to you (plus you don&#8217;t even need to figure out IP addresses and subnet masks) from the latest versions of pgAdmin (1.6.x).  However, this is not the version that ships with Ubuntu, so i&#8217;ll leave these instructions here.&#160;<a href="#fnref:1" rev="footnote">&#8617;</a></p>
</li>

</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F11%2Finstall-postgresql-on-ubuntu-710&amp;seed_title=Install+PostgreSQL+on+Ubuntu%26%23160%3B7.10/feed</wfw:commentRss>
		<slash:comments>63</slash:comments>
		</item>
		<item>
		<title>Adding/Deleting Rows in TableKit Tables&#160;Revisited</title>
		<link>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F11%2Faddingdeleting-rows-in-tablekit-tables-revisited&amp;seed_title=Adding%2FDeleting+Rows+in+TableKit+Tables%26%23160%3BRevisited</link>
		<comments>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F11%2Faddingdeleting-rows-in-tablekit-tables-revisited&amp;seed_title=Adding%2FDeleting+Rows+in+TableKit+Tables%26%23160%3BRevisited#comments</comments>
		<pubDate>Thu, 01 Nov 2007 08:42:51 +0000</pubDate>
		<dc:creator>Daz</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[noteworthy]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[catalyst]]></category>
		<category><![CDATA[geek]]></category>
		<category><![CDATA[prototype]]></category>
		<category><![CDATA[tablekit]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://hocuspokus.net/2007/11/01/addingdeleting-rows-in-tablekit-tables-revisited/</guid>
		<description><![CDATA[TableKit is a great javascript library for making your HTML tables fully editable. However, one problem is that you can&#8217;t add or delete rows from the tables&#8230; I came up with a solution to this not so long ago, but &#8230; <a href="http://hocuspokus.net/feeder/?FeederAction=clicked&#38;feed=Articles+%28RSS2%29&#38;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F11%2Faddingdeleting-rows-in-tablekit-tables-revisited&#38;seed_title=Adding%2FDeleting+Rows+in+TableKit+Tables%26%23160%3BRevisited">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.millstream.com.au/view/code/tablekit/">TableKit</a> is a great javascript library for making your HTML tables fully editable.  However, one problem is that you can&#8217;t add or delete rows from the tables&#8230;</p>

<p>I came up with a solution to this <a href="http://hocuspokus.net/2007/10/11/adding-deleting-rows-to-tablekit-tables/">not so long ago</a>, but it still had a problem - TableKit caches the tables on loading, so after we update the table body (adding or deleting a row) the sorting and editing of the table is completely screwed! <img src='http://hocuspokus.net/wp-content/plugins/smilies-themer/tango/face-sad.png' alt=':(' class='wp-smiley' />  However, with a little more work, and some help from one of the guys in the office - we&#8217;ve finally got this cracked! <img src='http://hocuspokus.net/wp-content/plugins/smilies-themer/tango/face-smile.png' alt=':)' class='wp-smiley' /> </p>

<p><span id="more-50"></span></p>

<p>The basic idea to the fix is, instead of updating the table body, replace the entire table with a new one and get TableKit to do its stuff on the new table.  Although this is not the ideal solution<sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup> - this <em>does</em> work quite well.  Here&#8217;s the details.<sup id="fnref:2"><a href="#fn:2" rel="footnote">2</a></sup></p>

<p>First, we&#8217;ll update the code from our template file (/root/src/users/list.tt):</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;">[% META title = 'User List' -%]
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;users_div&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">table</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;users&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;sortable resizable editable&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">thead</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">th</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;id&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;sortfirstasc noedit&quot;</span>&gt;</span>Id<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">th</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">th</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;firstname&quot;</span>&gt;</span>First Name<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">th</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">th</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;lastname&quot;</span>&gt;</span>Last Name<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">th</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">th</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;noedit nocol&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">th</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">thead</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tfoot</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">th</span>&gt;</span>Id<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">th</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">th</span>&gt;</span>First Name<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">th</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">th</span>&gt;</span>Last Name<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">th</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">th</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;nocol&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">th</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tfoot</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tbody</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;user_body&quot;</span>&gt;</span>
    [% FOREACH user IN users -%]
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'[% user.id %]'</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>[% user.id %]<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>[% user.firstname %]<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>[% user.lastname %]<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;nocol&quot;</span>&gt;</span>
          <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;delete&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span> <span style="color: #000066;">onclick</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;deleteUser([% user.id %]); return false&quot;</span>&gt;</span>delete<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
    [% END -%]
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tbody</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">table</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;add&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span> <span style="color: #000066;">onclick</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;addUser(); return false&quot;</span>&gt;</span>add a user<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span></pre></td></tr></table></div>


<p>Then add this javascript code to the bottom of the same file:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span> charset<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;utf-8&quot;</span><span style="color: #339933;">&gt;</span>
  <span style="color: #003366; font-weight: bold;">var</span> users_table <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> TableKit<span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'users'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
    editAjaxURI<span style="color: #339933;">:</span> <span style="color: #3366CC;">'[% c.uri_for('</span><span style="color: #339933;">/</span>users<span style="color: #339933;">/</span>_update_user<span style="color: #3366CC;">') %]'</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #003366; font-weight: bold;">function</span> addUser<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> timestamp <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">getTime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> new_table <span style="color: #339933;">=</span> <span style="color: #3366CC;">'users'</span> <span style="color: #339933;">+</span> timestamp<span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> url <span style="color: #339933;">=</span> <span style="color: #3366CC;">'[% c.uri_for('</span><span style="color: #339933;">/</span>users<span style="color: #339933;">/</span>_add_user<span style="color: #3366CC;">') %]?timestamp='</span> <span style="color: #339933;">+</span> timestamp<span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">new</span> Ajax.<span style="color: #660066;">Updater</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'users_div'</span><span style="color: #339933;">,</span> url<span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span> 
      asynchronous<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>
      onComplete<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">new</span> TableKit<span style="color: #009900;">&#40;</span> new_table<span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
          editAjaxURI<span style="color: #339933;">:</span> <span style="color: #3366CC;">'[% c.uri_for('</span><span style="color: #339933;">/</span>users<span style="color: #339933;">/</span>_update_user<span style="color: #3366CC;">') %]'</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #003366; font-weight: bold;">function</span> deleteUser<span style="color: #009900;">&#40;</span> user_id <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> timestamp <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">getTime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> new_table <span style="color: #339933;">=</span> <span style="color: #3366CC;">'users'</span> <span style="color: #339933;">+</span> timestamp<span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> url <span style="color: #339933;">=</span> <span style="color: #3366CC;">'[% c.uri_for('</span><span style="color: #339933;">/</span>users<span style="color: #339933;">/</span>_delete_user<span style="color: #339933;">/</span><span style="color: #3366CC;">') %]?user_id='</span> <span style="color: #339933;">+</span> user_id <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&amp;timestamp='</span> <span style="color: #339933;">+</span> timestamp<span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> answer <span style="color: #339933;">=</span> <span style="color: #000066;">confirm</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Are you sure you want to delete this user?'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>answer<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #003366; font-weight: bold;">new</span> Ajax.<span style="color: #660066;">Updater</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'users_div'</span><span style="color: #339933;">,</span> url<span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span> 
        asynchronous<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>
        onComplete<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          <span style="color: #003366; font-weight: bold;">new</span> TableKit<span style="color: #009900;">&#40;</span> new_table<span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
            editAjaxURI<span style="color: #339933;">:</span> <span style="color: #3366CC;">'[% c.uri_for('</span><span style="color: #339933;">/</span>users<span style="color: #339933;">/</span>_update_user<span style="color: #3366CC;">') %]'</span>
          <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>


<p>The main differences in the above from last time round are as follows:
-   The &#8216;users&#8217; table is now inside a div with the id &#8216;users_div&#8217;
-   The link to add a user now calls a javascript function rather than an   Ajax.Updater call directly.
-   The functions to add and delete users are essentially the same:
- -         They create a timestamp to individually identify the new table we       are going to create (this is <strong>the</strong> most important thing here to       remember)!
- -         They then use an Ajax.Updater call to talk to the Perl controller       and generate the new table with a row added or removed.
- -         Once the Ajax.Updater is complete, TableKit is then called again        to make our new table editable and sortable.</p>

<p>That&#8217;s the template sorted, now let&#8217;s look at the controller (/lib/MyApp/Controller/Users.pm):</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
</pre></td><td class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #000066;">package</span> MyApp<span style="color: #339933;">::</span><span style="color: #006600;">Controller</span><span style="color: #339933;">::</span><span style="color: #006600;">Users</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">use</span> strict<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> warnings<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> base <span style="color: #ff0000;">'Catalyst::Controller'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">=head1 NAME
&nbsp;
MyApp::Controller::Users - Catalyst Controller
&nbsp;
=head1 DESCRIPTION
&nbsp;
Catalyst Controller.
&nbsp;
=head1 METHODS
&nbsp;
=cut</span>
&nbsp;
<span style="color: #666666; font-style: italic;">=head2 index 
&nbsp;
=cut</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> <span style="color: #000066;">index</span> <span style="color: #339933;">:</span> Private <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$self</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$c</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">@_</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">response</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">redirect</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'/users/list'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">=head2 list
&nbsp;
Fetch all user objects and pass to users/list.tt in stash to be displayed
&nbsp;
=cut</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> list <span style="color: #339933;">:</span> Local <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$self</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$c</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">@_</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">stash</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>users<span style="color: #009900;">&#125;</span>    <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span> <span style="color: #0000ff;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">model</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'MyAppDB::Users'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">all</span> <span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">stash</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>template<span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'users/list.tt'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">=head2 _update_user
&nbsp;
Ajax method to update the users table
&nbsp;
=cut</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> _update_user <span style="color: #339933;">:</span> Local <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$self</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$c</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">@_</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #0000ff;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">model</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'MyAppDB::Users'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">find</span><span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#123;</span> id <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">req</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">params</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>id<span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span>
      <span style="color: #339933;">-&gt;</span><span style="color: #006600;">update</span><span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#123;</span> <span style="color: #0000ff;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">req</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">params</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>field<span style="color: #009900;">&#125;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">req</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">params</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>value<span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #0000ff;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">res</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">body</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">req</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">params</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>value<span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">=head2 _delete_user
&nbsp;
Ajax method to delete users from the users table
&nbsp;
=cut</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> _delete_user <span style="color: #339933;">:</span> Local <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$self</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$c</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">@_</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;"># Look-up our user entry</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$user</span> <span style="color: #339933;">=</span>
      <span style="color: #0000ff;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">model</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'MyAppDB::Users'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">find</span><span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#123;</span> id <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">req</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">params</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>user_id<span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span>
      <span style="color: #339933;">-&gt;</span><span style="color: #006600;">delete</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$output</span> <span style="color: #339933;">=</span>
      __return_all_users<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$self</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$c</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">req</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">params</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>timestamp<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'null'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #0000ff;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">res</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">body</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$output</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">=head2 _add_user
&nbsp;
Ajax method to add users to the users table
&nbsp;
=cut</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> _add_user <span style="color: #339933;">:</span> Local <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$self</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$c</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">@_</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;"># create a new user...</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$new_user</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">model</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'MyAppDB::Users'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">create</span><span style="color: #009900;">&#40;</span>
        <span style="color: #009900;">&#123;</span>
            id        <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">req</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">params</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>user_id<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
            firstname <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'[First Name]'</span><span style="color: #339933;">,</span>
            lastname  <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'[Last Name]'</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$output</span> <span style="color: #339933;">=</span> __return_all_users<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$self</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$c</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">req</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">params</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>timestamp<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">$new_user</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">id</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #0000ff;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">res</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">body</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$output</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">=head2 __return_all_users
&nbsp;
Private method for the Users ajax interaction.
Returns a html table.
&nbsp;
=cut</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> __return_all_users <span style="color: #339933;">:</span> Private <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$self</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$c</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$timestamp</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$new_user_id</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">@_</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@users</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">model</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'MyAppDB::Users'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">all</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$html</span> <span style="color: #339933;">=</span>
        <span style="color: #ff0000;">'&lt;table id=&quot;users'</span>
      <span style="color: #339933;">.</span> <span style="color: #0000ff;">$timestamp</span>
      <span style="color: #339933;">.</span> <span style="color: #ff0000;">'&quot; class=&quot;sortable resizable editable&quot;&gt;
      &lt;thead&gt;
        &lt;tr&gt;
          &lt;th id=&quot;id&quot; class=&quot;sortfirstasc noedit&quot;&gt;Id&lt;/th&gt;
          &lt;th id=&quot;firstname&quot;&gt;First Name&lt;/th&gt;
          &lt;th id=&quot;lastname&quot;&gt;Last Name&lt;/th&gt;
          &lt;th class=&quot;noedit nocol&quot;&gt;&lt;/th&gt;
        &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tfoot&gt;
        &lt;tr&gt;
          &lt;th&gt;Id&lt;/th&gt;
          &lt;th&gt;First Name&lt;/th&gt;
          &lt;th&gt;Last Name&lt;/th&gt;
          &lt;th class=&quot;nocol&quot;&gt;&lt;/th&gt;
        &lt;/tr&gt;
      &lt;/tfoot&gt;
      &lt;tbody id=&quot;user_body&quot;&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000066;">scalar</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">@users</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">;</span> <span style="color: #0000ff;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #000066;">scalar</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">@users</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span> <span style="color: #0000ff;">$i</span><span style="color: #339933;">++</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$class</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$new_user_id</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #0000ff;">$users</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">id</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">$new_user_id</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #0000ff;">$class</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'new'</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #b1b100;">if</span>   <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$i</span> <span style="color: #339933;">%</span> <span style="color: #cc66cc;">2</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #0000ff;">$class</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'rowodd'</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
                <span style="color: #b1b100;">else</span>                 <span style="color: #009900;">&#123;</span> <span style="color: #0000ff;">$class</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'roweven'</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #0000ff;">$html</span> <span style="color: #339933;">.=</span>
                <span style="color: #ff0000;">&quot;&lt;tr class=<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span> 
              <span style="color: #339933;">.</span> <span style="color: #0000ff;">$class</span>
              <span style="color: #339933;">.</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span> id=<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span>
              <span style="color: #339933;">.</span> <span style="color: #0000ff;">$users</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">id</span> <span style="color: #339933;">.</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;
                &lt;td&gt;&quot;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">$users</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">id</span> <span style="color: #339933;">.</span> <span style="color: #ff0000;">&quot;&lt;/td&gt;
                &lt;td&gt;&quot;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">$users</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">firstname</span> <span style="color: #339933;">.</span> <span style="color: #ff0000;">&quot;&lt;/td&gt;
                &lt;td&gt;&quot;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">$users</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">lastname</span> <span style="color: #339933;">.</span> <span style="color: #ff0000;">&quot;&lt;/td&gt;
                &lt;td class=<span style="color: #000099; font-weight: bold;">\&quot;</span>nocol<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;
                    &lt;a class=<span style="color: #000099; font-weight: bold;">\&quot;</span>delete<span style="color: #000099; font-weight: bold;">\&quot;</span> href=<span style="color: #000099; font-weight: bold;">\&quot;</span>#<span style="color: #000099; font-weight: bold;">\&quot;</span> onclick=<span style="color: #000099; font-weight: bold;">\&quot;</span> deleteUser(&quot;</span>
              <span style="color: #339933;">.</span> <span style="color: #0000ff;">$users</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">id</span> <span style="color: #339933;">.</span> <span style="color: #ff0000;">&quot;); return false<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;delete&lt;/a&gt;
                &lt;/td&gt;
              &lt;/tr&gt;&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #0000ff;">$html</span> <span style="color: #339933;">.=</span>
          <span style="color: #ff0000;">'&lt;tr&gt;&lt;td colspan=&quot;4&quot; class=&quot;nocol&quot;&gt;All Users Deleted&lt;/td&gt;&lt;/tr&gt;'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #0000ff;">$html</span> <span style="color: #339933;">.=</span> <span style="color: #ff0000;">'&lt;/tbody&gt;&lt;/table&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$html</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">=head1 AUTHOR
&nbsp;
Darren Oakley
&nbsp;
=head1 LICENSE
&nbsp;
This library is free software, you can redistribute it and/or modify
it under the same terms as Perl itself.
&nbsp;
=cut</span>
&nbsp;
<span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span></pre></td></tr></table></div>


<p>The only real changes in the controller are a general code clean-up, and a slight change to the &#8216;__return_all_users&#8217; method - this now returns a whole table (identified by the unique timestamped id that we generated in the javascript functions).  Nothing really needed changing in the back-end.</p>

<p>There you go!  Now our TableKit based tables can be used to not only edit entries in the database, we can now add and remove them! <img src='http://hocuspokus.net/wp-content/plugins/smilies-themer/tango/face-smile.png' alt=':)' class='wp-smiley' /> </p>

<p>The files used in this example can be found below.</p>

<h4>Attached Files:</h4>

<p><a href="http://hocuspokus.net/wp-content/uploads/2007/11/myapp.zip" title="myapp.zip" title="MyApp - v3" class="archive">MyApp.zip - v3</a></p>

<div class="footnotes">
<hr />
<ol>

<li id="fn:1">
<p>That would be knowing more about javascript and the dom so that we can make changes to TableKits cache as we update the table body (thus keeping the original table).&#160;<a href="#fnref:1" rev="footnote">&#8617;</a></p>
</li>

<li id="fn:2">
<p>We&#8217;re using the code from the <a href="http://hocuspokus.net/2007/10/11/adding-deleting-rows-to-tablekit-tables/">previous post</a> as a starting point.&#160;<a href="#fnref:2" rev="footnote">&#8617;</a></p>
</li>

</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F11%2Faddingdeleting-rows-in-tablekit-tables-revisited&amp;seed_title=Adding%2FDeleting+Rows+in+TableKit+Tables%26%23160%3BRevisited/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Adding/Deleting Rows in TableKit&#160;Tables</title>
		<link>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F10%2Fadding-deleting-rows-to-tablekit-tables&amp;seed_title=Adding%2FDeleting+Rows+in+TableKit%26%23160%3BTables</link>
		<comments>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F10%2Fadding-deleting-rows-to-tablekit-tables&amp;seed_title=Adding%2FDeleting+Rows+in+TableKit%26%23160%3BTables#comments</comments>
		<pubDate>Thu, 11 Oct 2007 19:50:10 +0000</pubDate>
		<dc:creator>Daz</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[noteworthy]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[catalyst]]></category>
		<category><![CDATA[prototype]]></category>
		<category><![CDATA[tablekit]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://hocuspokus.net/2007/10/11/adding-deleting-rows-to-tablekit-tables/</guid>
		<description><![CDATA[This post has now been updated. Please head over to the new post for something better&#8230; Following on from my previous post on how to integrate the excellent TableKit into your Catalyst webapp (to make your data tables dynamically editable), &#8230; <a href="http://hocuspokus.net/feeder/?FeederAction=clicked&#38;feed=Articles+%28RSS2%29&#38;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F10%2Fadding-deleting-rows-to-tablekit-tables&#38;seed_title=Adding%2FDeleting+Rows+in+TableKit%26%23160%3BTables">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p class="alert">This post has now been <a href="http://hocuspokus.net/2007/11/01/addingdeleting-rows-in-tablekit-tables-revisited/">updated</a>. Please head over to the new post for something better&#8230;</p>

<p>Following on from my <a href="http://hocuspokus.net/2007/09/23/making-editable-tables-with-catalyst-and-tablekit/">previous post</a> on how to integrate the excellent <a href="http://www.millstream.com.au/view/code/tablekit/">TableKit</a> into your <a href="http://www.catalystframework.org/">Catalyst</a> webapp (to make your data tables dynamically editable),  here&#8217;s how i&#8217;ve gone about adding ajax inserts and deletes so that you can add and remove data rows in your tables.<sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup></p>

<p><span id="more-31"></span></p>

<p>We&#8217;re going to be using prototype to do the background ajax calls, as this is already in our app as a requirement of TableKit.  Now let&#8217;s get on with doctoring our template.  First we add in a delete button for each row of our table.  Open up <code>/root/src/users/list.tt</code> and change the code of our table to look like the following (the changes come on lines 9, 17, 20 and 26-28):</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">table</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;users&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;sortable resizable editable&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">thead</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">th</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;id&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;sortfirstasc noedit&quot;</span>&gt;</span>Id<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">th</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">th</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;firstname&quot;</span>&gt;</span>First Name<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">th</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">th</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;lastname&quot;</span>&gt;</span>Last Name<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">th</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">th</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;noedit nocol&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">th</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">thead</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tfoot</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">th</span>&gt;</span>Id<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">th</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">th</span>&gt;</span>First Name<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">th</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">th</span>&gt;</span>Last Name<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">th</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">th</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;nocol&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">th</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tfoot</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tbody</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;user_body&quot;</span>&gt;</span>
  [% FOREACH user IN users -%]
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'[% user.id %]'</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>[% user.id %]<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>[% user.firstname %]<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>[% user.lastname %]<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;nocol&quot;</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;delete&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span> <span style="color: #000066;">onclick</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;userDelete([% user.id %]); return false&quot;</span>&gt;</span>delete<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
  [% END -%]
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tbody</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">table</span>&gt;</span></pre></td></tr></table></div>


<p>The above code adds a &#8216;delete&#8217; link into each row of the table.  This link is to run a short javascript function (called <code>userDelete</code>) that we shall add now at the bottom of the template (within the original javascript block):</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>45
46
47
48
49
50
51
52
53
54
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">userDelete <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> user_id <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #003366; font-weight: bold;">var</span> answer <span style="color: #339933;">=</span> <span style="color: #000066;">confirm</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Are you sure you want to delete this user?'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>answer<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">new</span> Ajax.<span style="color: #660066;">Updater</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'user_body'</span><span style="color: #339933;">,</span> 
      <span style="color: #3366CC;">'[% c.uri_for('</span><span style="color: #339933;">/</span>users<span style="color: #339933;">/</span>_delete_user<span style="color: #339933;">/</span><span style="color: #3366CC;">') %]?user_id='</span> <span style="color: #339933;">+</span> user_id<span style="color: #339933;">,</span> 
      <span style="color: #009900;">&#123;</span> asynchronous<span style="color: #339933;">:</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>


<p>This function basically asks the user to confirm that they want to delete the user entry, the sets up an Ajax.Updater that passes the <code>user_id</code> to be deleted to a new function in our controller (that we shall write next) which deletes it, and then passes the new table body back to be updated on screen.  Let&#8217;s now create a new function <code>_delete_user</code> (and a helper function <code>__return_all_users</code>) in our user controller <code>/lib/MyApp/Controller/Users.pm</code>:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
</pre></td><td class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">=head _delete_user
&nbsp;
Ajax method to delete users from the users table
&nbsp;
=cut</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> _delete_user <span style="color: #339933;">:</span> Local <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$self</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$c</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">@_</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;"># Look-up our user entry</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$user</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">model</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'MyAppDB::Users'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">find</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
      id <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">req</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">params</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>user_id<span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">delete</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$output</span> <span style="color: #339933;">=</span> __return_all_users<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$self</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$c</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'null'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">unless</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$output</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #0000ff;">$output</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'&lt;tr&gt;&lt;td colspan=&quot;4&quot; class=&quot;nocol&quot;&gt;All Users Deleted&lt;/td&gt;&lt;/tr&gt;'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #0000ff;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">res</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">body</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$output</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">=head2 __return_all_users
&nbsp;
Private method for the Users ajax interaction.
Returns the inner body of a html table.
&nbsp;
=cut</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> __return_all_users <span style="color: #339933;">:</span> Private <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$self</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$c</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$new_user_id</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">@_</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@users</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">model</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'MyAppDB::Users'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">all</span><span style="color: #009900;">&#40;</span>
        <span style="color: #009900;">&#123;</span> order_by <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'id ASC'</span> <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$html</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">;</span> <span style="color: #0000ff;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #000066;">scalar</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">@users</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span> <span style="color: #0000ff;">$i</span><span style="color: #339933;">++</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$class</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$new_user_id</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #0000ff;">$users</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">id</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">$new_user_id</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #0000ff;">$class</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'new'</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$i</span> <span style="color: #339933;">%</span> <span style="color: #cc66cc;">2</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #0000ff;">$class</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'rowodd'</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
            <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span> <span style="color: #0000ff;">$class</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'roweven'</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #0000ff;">$html</span> <span style="color: #339933;">.=</span> <span style="color: #ff0000;">&quot;&lt;tr class=<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">$class</span> <span style="color: #339933;">.</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span> id=<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">$users</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">id</span> <span style="color: #339933;">.</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;
            &lt;td&gt;&quot;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">$users</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">id</span> <span style="color: #339933;">.</span> <span style="color: #ff0000;">&quot;&lt;/td&gt;
            &lt;td&gt;&quot;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">$users</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">firstname</span> <span style="color: #339933;">.</span> <span style="color: #ff0000;">&quot;&lt;/td&gt;
            &lt;td&gt;&quot;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">$users</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">lastname</span> <span style="color: #339933;">.</span> <span style="color: #ff0000;">&quot;&lt;/td&gt;
            &lt;td class=<span style="color: #000099; font-weight: bold;">\&quot;</span>nocol<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;
                &lt;a class=<span style="color: #000099; font-weight: bold;">\&quot;</span>delete<span style="color: #000099; font-weight: bold;">\&quot;</span> href=<span style="color: #000099; font-weight: bold;">\&quot;</span>#<span style="color: #000099; font-weight: bold;">\&quot;</span> onclick=<span style="color: #000099; font-weight: bold;">\&quot;</span> userDelete(&quot;</span>
                <span style="color: #339933;">.</span> <span style="color: #0000ff;">$users</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">id</span> <span style="color: #339933;">.</span> <span style="color: #ff0000;">&quot;); return false<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;delete&lt;/a&gt;
            &lt;/td&gt;
            &lt;/tr&gt;&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000066;">return</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$html</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>


<p>The <code>_delete_user</code> function, takes the <code>user_id</code> that we sent to it, deletes the entry from the database, then calls the <code>__return_all_users</code> function to rebuild the table body.  This table body is then used to update the table back on the web page.</p>

<p>That&#8217;s the delete functionality sorted, now on with the row adding&#8230;  Back in the template, add we add another Ajax.Updater link below the table:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>33
34
35
36
37
38
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;add&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span> <span style="color: #000066;">onclick</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot; </span>
<span style="color: #009900;">  new Ajax.Updater( 'user_body',</span>
<span style="color: #009900;">    '[% c.uri_for('/users/_add_user') %]', </span>
<span style="color: #009900;">    { asynchronous: 1, }</span>
<span style="color: #009900;">  ); return false &quot;</span>&gt;</span>add a user<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span></pre></td></tr></table></div>


<p>And add another new method into our controller to add a new user into the database and table:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
</pre></td><td class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">=head _add_user
&nbsp;
Ajax method to add users to the users table
&nbsp;
=cut</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> _add_user <span style="color: #339933;">:</span> Local <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$self</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$c</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">@_</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;"># create a new user...</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$new_user</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">model</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'MyAppDB::Users'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">create</span><span style="color: #009900;">&#40;</span>
        <span style="color: #009900;">&#123;</span>
            id        <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">req</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">params</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>user_id<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
            firstname <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'[First Name]'</span><span style="color: #339933;">,</span>
            lastname  <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'[Last Name]'</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$output</span> <span style="color: #339933;">=</span> __return_all_users<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$self</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$c</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$new_user</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">id</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #0000ff;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">res</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">body</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$output</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>


<p>This function, like the delete function, does its business on the database, then rebuilds the table body and sends it back to the web page.</p>

<p>The final icing on the cake, is a little addition to our CSS to make this all look a little nicer.  Open up <code>/root/css/myapp.css</code> and add the following to the bottom of the file:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.nocol</span><span style="color: #00AA00;">,</span> th<span style="color: #6666ff;">.nocol</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
tr<span style="color: #6666ff;">.new</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#ff9697</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
a <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">outline</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
a<span style="color: #6666ff;">.add</span><span style="color: #00AA00;">,</span> a<span style="color: #6666ff;">.delete</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'/images/add.png'</span><span style="color: #00AA00;">&#41;</span> <span style="color: #000000; font-weight: bold;">left</span> <span style="color: #993333;">center</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">2px</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">2px</span> <span style="color: #933;">20px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
a<span style="color: #6666ff;">.delete</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'/images/delete.png'</span><span style="color: #00AA00;">&#41;</span> <span style="color: #000000; font-weight: bold;">left</span> <span style="color: #993333;">center</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
tr a<span style="color: #6666ff;">.delete</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">0.8em</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>


<p>And there you go.  Now you can edit, add and delete users to your database and table without having to reload the page.</p>

<div style="text-align:center;"><img src="http://hocuspokus.net/wp-content/uploads/2007/10/add-remove-tablekit.png" alt="add-remove-tablekit.png" border="0" width="449" height="535" /></div>

<p>However, there is one small bug that needs to be squashed to make this perfect&#8230;  TableKit caches the tables on page load - if you have a go at re-sorting one of the tables after deleting or adding a row, this causes the table to essentially double in size as the original cached data is reloaded onto the screen! <img src='http://hocuspokus.net/wp-content/plugins/smilies-themer/tango/face-sad.png' alt=':(' class='wp-smiley' />  I now need to figure out a way to clean out the cache for the current table and re-initalise TableKit.  Any suggestions would be more than welcome! <img src='http://hocuspokus.net/wp-content/plugins/smilies-themer/tango/face-smile.png' alt=':)' class='wp-smiley' /> </p>

<p>The files used in the examples can be downloaded below.</p>

<h4>Attached Files:</h4>

<p><a href='http://hocuspokus.net/wp-content/uploads/2007/10/myapp.zip' title='MyApp - v2' class="archive">MyApp - v2</a></p>

<div class="footnotes">
<hr />
<ol>

<li id="fn:1">
<p>You&#8217;ll need the code from the <a href="http://hocuspokus.net/2007/09/23/making-editable-tables-with-catalyst-and-tablekit/">previous post</a> to follow along.&#160;<a href="#fnref:1" rev="footnote">&#8617;</a></p>
</li>

</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F10%2Fadding-deleting-rows-to-tablekit-tables&amp;seed_title=Adding%2FDeleting+Rows+in+TableKit%26%23160%3BTables/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Log/Audit Tables in&#160;Oracle</title>
		<link>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F10%2Flogaudit-tables-in-oracle&amp;seed_title=Log%2FAudit+Tables+in%26%23160%3BOracle</link>
		<comments>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F10%2Flogaudit-tables-in-oracle&amp;seed_title=Log%2FAudit+Tables+in%26%23160%3BOracle#comments</comments>
		<pubDate>Fri, 05 Oct 2007 12:07:06 +0000</pubDate>
		<dc:creator>Daz</dc:creator>
				<category><![CDATA[noteworthy]]></category>
		<category><![CDATA[oracle]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://hocuspokus.net/2007/10/05/logaudit-tables-in-oracle/</guid>
		<description><![CDATA[One of the useful things that i&#8217;ve been asked to set-up lately is automatic logging of changes to several of our database tables. My first thought was to do this in Perl (as the rest of the system is in &#8230; <a href="http://hocuspokus.net/feeder/?FeederAction=clicked&#38;feed=Articles+%28RSS2%29&#38;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F10%2Flogaudit-tables-in-oracle&#38;seed_title=Log%2FAudit+Tables+in%26%23160%3BOracle">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>One of the useful things that i&#8217;ve been asked to set-up lately is automatic logging of changes to several of our database tables.</p>

<p>My first thought was to do this in Perl (as the rest of the system is in Perl), but this would mean adding extra methods and calls in the Perl code to update the database (both the original tables and the new log tables).  That seemed like a solution - a pain in the arse to implement, but a solution.</p>

<p>Thankfully one of the helpful chaps in my department suggested doing it all in the database with triggers as this is quite common in banks and the like.  What a damn fine idea!  Only a little SQL to write and no extra Perl.</p>

<p><span id="more-24"></span></p>

<p>Here&#8217;s an example&#8230;</p>

<p>First, here&#8217;s the table that we want to create an audit log for:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #ff0000;">&quot;COMMENT&quot;</span> <span style="color: #66cc66;">&#40;</span>
  <span style="color: #ff0000;">&quot;COMMENT_ID&quot;</span> NUMBER<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span> 
  <span style="color: #ff0000;">&quot;COMMENT_BODY&quot;</span> VARCHAR2<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1000</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> 
  <span style="color: #ff0000;">&quot;USER&quot;</span> VARCHAR2<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">100</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> 
  <span style="color: #ff0000;">&quot;CREATED_DATE&quot;</span> DATE<span style="color: #66cc66;">,</span> 
  CONSTRAINT <span style="color: #ff0000;">&quot;PK_COMMENT&quot;</span> <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;COMMENT_ID&quot;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>


<p>Now, we create the audit table.<sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup></p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #ff0000;">&quot;COMMENT_AUDIT&quot;</span> <span style="color: #66cc66;">&#40;</span>
  <span style="color: #ff0000;">&quot;COMMENT_ID&quot;</span> NUMBER<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span> 
  <span style="color: #ff0000;">&quot;COMMENT_BODY&quot;</span> VARCHAR2<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1000</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> 
  <span style="color: #ff0000;">&quot;USER&quot;</span> VARCHAR2<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">100</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> 
  <span style="color: #ff0000;">&quot;CREATED_DATE&quot;</span> DATE<span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">&quot;AUDIT_DATE&quot;</span> DATE <span style="color: #993333; font-weight: bold;">DEFAULT</span> SYSTIMESTAMP <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span>
<span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>


<p>Finally, we create the trigger to keep a log of changes to our original table.</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">OR</span> <span style="color: #993333; font-weight: bold;">REPLACE</span> <span style="color: #993333; font-weight: bold;">TRIGGER</span> <span style="color: #ff0000;">&quot;TA_COMMENT&quot;</span> 
before <span style="color: #993333; font-weight: bold;">UPDATE</span> <span style="color: #993333; font-weight: bold;">OR</span> <span style="color: #993333; font-weight: bold;">DELETE</span> <span style="color: #993333; font-weight: bold;">ON</span> COMMENT <span style="color: #993333; font-weight: bold;">FOR</span> each row
begin
<span style="color: #993333; font-weight: bold;">IF</span> deleting <span style="color: #993333; font-weight: bold;">OR</span> updating then 
  <span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> comment_audit<span style="color: #66cc66;">&#40;</span>
    COMMENT_ID<span style="color: #66cc66;">,</span>
    COMMENT_BODY<span style="color: #66cc66;">,</span>
    USER<span style="color: #66cc66;">,</span>
    CREATED_DATE
  <span style="color: #66cc66;">&#41;</span>
  <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span>
    :old<span style="color: #66cc66;">.</span>COMMENT_ID<span style="color: #66cc66;">,</span>
    :old<span style="color: #66cc66;">.</span>COMMENT_BODY<span style="color: #66cc66;">,</span>
    :old<span style="color: #66cc66;">.</span>USER<span style="color: #66cc66;">,</span>
    :old<span style="color: #66cc66;">.</span>CREATED_DATE
  <span style="color: #66cc66;">&#41;</span>;
end <span style="color: #993333; font-weight: bold;">IF</span>;
end;
<span style="color: #66cc66;">/</span>
<span style="color: #993333; font-weight: bold;">ALTER</span> <span style="color: #993333; font-weight: bold;">TRIGGER</span> <span style="color: #ff0000;">&quot;TA_COMMENT&quot;</span> ENABLE;</pre></td></tr></table></div>


<p>Now whenever a delete or update action is performed on the &#8220;COMMENT&#8221; table, a record of the old values and the date/time at which they were changed is recorded in the audit table.</p>

<div class="footnotes">
<hr />
<ol>

<li id="fn:1">
<p>The audit table is exactly the same as the table that we wish to keep a log of, except for one extra column, &#8220;AUDIT_DATE&#8221;, this will keep record the date/time of when an change occurred on the original table.&#160;<a href="#fnref:1" rev="footnote">&#8617;</a></p>
</li>

</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F10%2Flogaudit-tables-in-oracle&amp;seed_title=Log%2FAudit+Tables+in%26%23160%3BOracle/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->