<?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; perl</title>
	<atom:link href="http://hocuspokus.net/category/perl/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>Building Apache and Mod Perl on Mac OS&#160;X</title>
		<link>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2009%2F03%2Fbuilding-apache-and-mod-perl-on-mac-os-x&amp;seed_title=Building+Apache+and+Mod+Perl+on+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%2F2009%2F03%2Fbuilding-apache-and-mod-perl-on-mac-os-x&amp;seed_title=Building+Apache+and+Mod+Perl+on+Mac+OS%26%23160%3BX#comments</comments>
		<pubDate>Sat, 07 Mar 2009 09:45:16 +0000</pubDate>
		<dc:creator>Daz</dc:creator>
				<category><![CDATA[mac]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[apache]]></category>

		<guid isPermaLink="false">http://hocuspokus.net/?p=331</guid>
		<description><![CDATA[I&#8217;ve finally had my work laptop upgraded to Leopard!!! As such, I&#8217;ve just spent the last couple of days getting things all set-up nicely so that I can get on with my work. Most of the work that I do &#8230; <a href="http://hocuspokus.net/feeder/?FeederAction=clicked&#38;feed=Articles+%28RSS2%29&#38;seed=http%3A%2F%2Fhocuspokus.net%2F2009%2F03%2Fbuilding-apache-and-mod-perl-on-mac-os-x&#38;seed_title=Building+Apache+and+Mod+Perl+on+Mac+OS%26%23160%3BX">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve finally had my work laptop upgraded to Leopard!!! <img src='http://hocuspokus.net/wp-content/plugins/smilies-themer/tango/face-smile.png' alt=':)' class='wp-smiley' /> </p>

<p>As such, I&#8217;ve just spent the last couple of days getting things all set-up nicely so that I can get on with my work.  Most of the work that I do is web development orientated, and mainly using <a href="http://www.perl.org/">Perl</a> and <a href="http://www.catalystframework.org/">Catalyst</a>, so an install of Apache and mod_perl is needed.</p>

<p>OS X does come with a complete install of Apache (even with mod_perl!) out of the box and ready to go (info on using this set-up can be found <a href="http://bixsolutions.net/forum/thread-11.html">here</a>), but I&#8217;m also working on another project that may involve the use of <a href="http://www.aptana.com/jaxer">Jaxer</a>, and this requires a newer build of Apache than the one shipped with Leopard. <img src='http://hocuspokus.net/wp-content/plugins/smilies-themer/tango/face-sad.png' alt=':(' class='wp-smiley' /> </p>

<p>Thankfully building these tools isn&#8217;t too complicated, here&#8217;s a quick dump of my notes on getting this done.  Note, I&#8217;m installing them into <a href="http://hivelogic.com/articles/2005/11/using_usr_local">/usr/local</a> so that I don&#8217;t mess with any of the OS X internals that I shouldn&#8217;t be touching - this is completely removable.</p>

<p>First, make a work area for building:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>src
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">chgrp</span> admin <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>src
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #660033;">-R</span> <span style="color: #000000;">775</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>src
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>src</pre></div></div>


<h4>Apache</h4>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">curl <span style="color: #660033;">-O</span> http:<span style="color: #000000; font-weight: bold;">//</span>apache.mirror.infiniteconflict.com<span style="color: #000000; font-weight: bold;">/</span>httpd<span style="color: #000000; font-weight: bold;">/</span>httpd-2.2.11.tar.gz
<span style="color: #c20cb9; font-weight: bold;">tar</span> zxvf httpd-2.2.11.tar.gz
<span style="color: #7a0874; font-weight: bold;">cd</span> httpd-2.2.11</pre></div></div>


<p>Now here&#8217;s the big one - the Apache configuration.  This compiles a heap of modules I probably don&#8217;t need, but it&#8217;s nice to have them there in case I do ever need them&#8230;</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">CFLAGS</span>=<span style="color: #ff0000;">&quot;-O3&quot;</span> <span style="color: #007800;">CXXFLAGS</span>=<span style="color: #ff0000;">&quot;-O3&quot;</span> \
.<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--prefix</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>apache2 \
<span style="color: #660033;">--enable-autoindex</span> \
<span style="color: #660033;">--enable-cache</span> \
<span style="color: #660033;">--enable-cgi</span> \
<span style="color: #660033;">--enable-deflate</span> \
<span style="color: #660033;">--enable-dir</span> \
--enable-disk_cache \
<span style="color: #660033;">--enable-fastcgi</span> \
--enable-file_cache \
<span style="color: #660033;">--enable-headers</span> \
<span style="color: #660033;">--enable-include</span> \
<span style="color: #660033;">--enable-info</span> \
--enable-log_config \
--enable-log_forensic \
<span style="color: #660033;">--enable-logio</span> \
--enable-mem_cache \
<span style="color: #660033;">--enable-mime</span> \
--enable-mime_magic \
<span style="color: #660033;">--enable-negotiation</span> \
<span style="color: #660033;">--enable-perl</span> \
<span style="color: #660033;">--enable-proxy</span> \
<span style="color: #660033;">--enable-proxy-balancer</span> \
<span style="color: #660033;">--enable-proxy-http</span> \
<span style="color: #660033;">--enable-rewrite</span> \
<span style="color: #660033;">--enable-speling</span> \
<span style="color: #660033;">--enable-status</span> \
<span style="color: #660033;">--enable-suexec</span> \
<span style="color: #660033;">--enable-userdir</span> \
<span style="color: #660033;">--enable-usertrack</span> \
<span style="color: #660033;">--enable-version</span> \
--enable-vhost_alias \
<span style="color: #660033;">--enable-so</span> \
<span style="color: #660033;">--enable-mods-shared</span>=all</pre></div></div>


<p>Then the standard make and install:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">make</span>
<span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #7a0874; font-weight: bold;">test</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>


<p>Now to add some configuration so that Apache starts on system boot, first we need to create a startup script:</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>System<span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>StartupItems<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">mkdir</span> Apache
<span style="color: #7a0874; font-weight: bold;">cd</span> Apache
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">touch</span> Apache
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">chmod</span> a+x Apache
mate Apache</pre></div></div>


<p>Paste this content into the file:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
&nbsp;
<span style="color: #666666; font-style: italic;">##</span>
<span style="color: #666666; font-style: italic;"># Apache HTTP Server</span>
<span style="color: #666666; font-style: italic;">##</span>
&nbsp;
. <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>rc.common
&nbsp;
StartService <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>
	ConsoleMessage <span style="color: #ff0000;">&quot;Starting Apache web server&quot;</span>
	<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>apache2<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>apachectl start
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
StopService <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>
	ConsoleMessage <span style="color: #ff0000;">&quot;Stopping Apache web server&quot;</span>
	<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>apache2<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>apachectl stop
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
RestartService <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>
	ConsoleMessage <span style="color: #ff0000;">&quot;Restarting Apache web server&quot;</span>
	<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>apache2<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>apachectl restart
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
RunService <span style="color: #ff0000;">&quot;$1&quot;</span></pre></div></div>


<p>Then a configuration file:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">touch</span> StartupParameters.plist
mate StartupParameters.plist</pre></div></div>


<p>Paste this content into the file:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#123;</span>
  Description     = <span style="color: #ff0000;">&quot;Apache web server&quot;</span>;
  Provides        = <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #ff0000;">&quot;Web Server&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>;
  Requires        = <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #ff0000;">&quot;DirectoryServices&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>;
  Uses            = <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #ff0000;">&quot;Disks&quot;</span>,<span style="color: #ff0000;">&quot;Network Time&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>;
  OrderPreference = <span style="color: #ff0000;">&quot;None&quot;</span>;
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>


<p>Then reboot and open up <a href="http://localhost">http://localhost</a> to make sure things have worked.</p>

<h4>Mod Perl</h4>

<p>This is a lot more straight forward:</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>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>src
curl <span style="color: #660033;">-O</span> http:<span style="color: #000000; font-weight: bold;">//</span>perl.apache.org<span style="color: #000000; font-weight: bold;">/</span>dist<span style="color: #000000; font-weight: bold;">/</span>mod_perl-<span style="color: #000000;">2.0</span>-current.tar.gz
<span style="color: #c20cb9; font-weight: bold;">tar</span> zxvf mod_perl-<span style="color: #000000;">2.0</span>-current.tar.gz
<span style="color: #7a0874; font-weight: bold;">cd</span> mod_perl-2.0.4
<span style="color: #c20cb9; font-weight: bold;">perl</span> Makefile.PL <span style="color: #007800;">MP_AP_PREFIX</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>apache2
<span style="color: #c20cb9; font-weight: bold;">make</span>
<span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #7a0874; font-weight: bold;">test</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>


<p>Now all you have to do is add the following line to your Apache httpd.conf (/usr/local/apache2/conf/httpd.conf) with all of the LoadModule entries:</p>


<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;">LoadModule perl_module modules/mod_perl.so</pre></div></div>


<p>All done! <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%2F03%2Fbuilding-apache-and-mod-perl-on-mac-os-x&amp;seed_title=Building+Apache+and+Mod+Perl+on+Mac+OS%26%23160%3BX/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Ack, a Grep&#160;Replacement</title>
		<link>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F11%2Fack-a-grep-replacement&amp;seed_title=Ack%2C+a+Grep%26%23160%3BReplacement</link>
		<comments>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F11%2Fack-a-grep-replacement&amp;seed_title=Ack%2C+a+Grep%26%23160%3BReplacement#comments</comments>
		<pubDate>Tue, 27 Nov 2007 19:19:51 +0000</pubDate>
		<dc:creator>Daz</dc:creator>
				<category><![CDATA[perl]]></category>
		<category><![CDATA[snippets]]></category>
		<category><![CDATA[grep]]></category>
		<category><![CDATA[search]]></category>

		<guid isPermaLink="false">http://hocuspokus.net/2007/11/27/ack-a-grep-replacement/</guid>
		<description><![CDATA[Ack is a grep alternative, written in pure Perl, using Perl&#8217;s regular expressions to do your searches (just one of the long list of reasons to use this over grep). I think i&#8217;ll be using this then&#8230; ack is a &#8230; <a href="http://hocuspokus.net/feeder/?FeederAction=clicked&#38;feed=Articles+%28RSS2%29&#38;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F11%2Fack-a-grep-replacement&#38;seed_title=Ack%2C+a+Grep%26%23160%3BReplacement">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://petdance.com/ack/">Ack</a> is a grep alternative, written in pure Perl, using Perl&#8217;s regular expressions to do your searches (just one of the long list of reasons to use this over grep).  I think i&#8217;ll be using this then&#8230;</p>

<blockquote>
  <p>ack is a tool like grep, aimed at programmers with large trees of heterogeneous source code.  ack is written purely in Perl, and takes advantage of the power of Perl&#8217;s regular expressions.</p>
</blockquote>

<p><a href="http://daringfireball.net/linked/2007/november#tue-27-ack" class="via">via</a></p>
]]></content:encoded>
			<wfw:commentRss>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F11%2Fack-a-grep-replacement&amp;seed_title=Ack%2C+a+Grep%26%23160%3BReplacement/feed</wfw:commentRss>
		<slash:comments>0</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>Visualizing Your DBIC&#160;Schema</title>
		<link>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F10%2Fvisualizing-your-dbic-schema&amp;seed_title=Visualizing+Your+DBIC%26%23160%3BSchema</link>
		<comments>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F10%2Fvisualizing-your-dbic-schema&amp;seed_title=Visualizing+Your+DBIC%26%23160%3BSchema#comments</comments>
		<pubDate>Fri, 19 Oct 2007 19:13:52 +0000</pubDate>
		<dc:creator>Daz</dc:creator>
				<category><![CDATA[perl]]></category>
		<category><![CDATA[catalyst]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[oracle]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://hocuspokus.net/2007/10/19/visualizing-your-dbic-schema/</guid>
		<description><![CDATA[What a great idea - will give this a bash next week&#8230; If you want a somewhat pretty picture of your DBIC schema (with relationships drawn, of course), install GraphViz, SQL::Translator, and DBICx::Deploy from the CPAN, and then run: $ &#8230; <a href="http://hocuspokus.net/feeder/?FeederAction=clicked&#38;feed=Articles+%28RSS2%29&#38;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F10%2Fvisualizing-your-dbic-schema&#38;seed_title=Visualizing+Your+DBIC%26%23160%3BSchema">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>What a great idea - will give this a bash next week&#8230;</p>

<blockquote>
  <p>If you want a somewhat pretty picture of your DBIC schema (with relationships drawn, of course), install GraphViz, SQL::Translator, and DBICx::Deploy from the CPAN, and then run:</p>
  
  <p><code>$ dbicdeploy -Ilib MyApp::Schema ~/graphs GraphViz</code></p>
  
  <p>~/graphs will then contain a .sql file that is actually a png of your schema. Rename it and see your schema in your favorite png viewing application.</p>
</blockquote>

<p><a href="http://blog.jrock.us/articles/Visualizing%20your%20DBIC%20schema.pod" class="via">via</a></p>
]]></content:encoded>
			<wfw:commentRss>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F10%2Fvisualizing-your-dbic-schema&amp;seed_title=Visualizing+Your+DBIC%26%23160%3BSchema/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Remove Case-Sensitivity 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%2Fremove-case-sensitivity-in-oracle&amp;seed_title=Remove+Case-Sensitivity+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%2Fremove-case-sensitivity-in-oracle&amp;seed_title=Remove+Case-Sensitivity+in%26%23160%3BOracle#comments</comments>
		<pubDate>Thu, 18 Oct 2007 16:06:42 +0000</pubDate>
		<dc:creator>Daz</dc:creator>
				<category><![CDATA[oracle]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://hocuspokus.net/2007/10/18/remove-case-sensitivity-in-oracle/</guid>
		<description><![CDATA[Oracle is a great RDBMS, but the fact that searches against the database are case-sensitive can be a pain in the butt. Here&#8217;s how you can make searches case-insensitive&#8230; In SQL&#8230; 1 2 ALTER session SET NLS_SORT=BINARY_CI; ALTER session SET &#8230; <a href="http://hocuspokus.net/feeder/?FeederAction=clicked&#38;feed=Articles+%28RSS2%29&#38;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F10%2Fremove-case-sensitivity-in-oracle&#38;seed_title=Remove+Case-Sensitivity+in%26%23160%3BOracle">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Oracle is a great RDBMS, but the fact that searches against the database are case-sensitive can be a pain in the butt.  Here&#8217;s how you can make searches case-insensitive&#8230;</p>

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

<p>In SQL&#8230;</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">ALTER</span> session <span style="color: #993333; font-weight: bold;">SET</span> NLS_SORT<span style="color: #66cc66;">=</span>BINARY_CI;
<span style="color: #993333; font-weight: bold;">ALTER</span> session <span style="color: #993333; font-weight: bold;">SET</span> NLS_COMP<span style="color: #66cc66;">=</span>LINGUISTIC;</pre></td></tr></table></div>


<p>For use in Perl::DBI&#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
</pre></td><td class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">use</span> strict<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> DBI<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$dbh</span> <span style="color: #339933;">=</span> DBI<span style="color: #339933;">-&gt;</span><span style="color: #006600;">connect</span><span style="color: #009900;">&#40;</span>
    <span style="color: #ff0000;">'dbi:Oracle:schema_name'</span><span style="color: #339933;">,</span>
    <span style="color: #ff0000;">'user'</span><span style="color: #339933;">,</span>
    <span style="color: #ff0000;">'password'</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#123;</span>
        RaiseError    <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>
        AutoCommit    <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
        on_connect_do <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#91;</span>
            <span style="color: #ff0000;">'alter session set NLS_SORT=BINARY_CI'</span><span style="color: #339933;">,</span>
            <span style="color: #ff0000;">'alter session set NLS_COMP=LINGUISTIC'</span>
        <span style="color: #009900;">&#93;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #000066;">die</span> <span style="color: #ff0000;">&quot;Database connection not made: $DBI::errstr&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #0000ff;">$dbh</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">disconnect</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></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%2Fremove-case-sensitivity-in-oracle&amp;seed_title=Remove+Case-Sensitivity+in%26%23160%3BOracle/feed</wfw:commentRss>
		<slash:comments>0</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>Some Useful Catalyst&#160;Tips</title>
		<link>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F10%2Fsome-useful-catalyst-tips&amp;seed_title=Some+Useful+Catalyst%26%23160%3BTips</link>
		<comments>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F10%2Fsome-useful-catalyst-tips&amp;seed_title=Some+Useful+Catalyst%26%23160%3BTips#comments</comments>
		<pubDate>Wed, 10 Oct 2007 20:02:18 +0000</pubDate>
		<dc:creator>Daz</dc:creator>
				<category><![CDATA[perl]]></category>
		<category><![CDATA[snippets]]></category>
		<category><![CDATA[catalyst]]></category>

		<guid isPermaLink="false">http://hocuspokus.net/2007/10/10/some-useful-catalyst-tips/</guid>
		<description><![CDATA[Found this small selection of tips that can come in use whilst working with Catalyst&#8230; read more]]></description>
			<content:encoded><![CDATA[<p>Found this small selection of tips that can come in use whilst working with Catalyst&#8230;</p>

<p><a href="http://blog.jrock.us/articles/Catalyst%20Tips%3A%20Part%201.pod" class="via">read more</a></p>
]]></content:encoded>
			<wfw:commentRss>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F10%2Fsome-useful-catalyst-tips&amp;seed_title=Some+Useful+Catalyst%26%23160%3BTips/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Making Editable Tables With Catalyst and&#160;TableKit</title>
		<link>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F09%2Fmaking-editable-tables-with-catalyst-and-tablekit&amp;seed_title=Making+Editable+Tables+With+Catalyst+and%26%23160%3BTableKit</link>
		<comments>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F09%2Fmaking-editable-tables-with-catalyst-and-tablekit&amp;seed_title=Making+Editable+Tables+With+Catalyst+and%26%23160%3BTableKit#comments</comments>
		<pubDate>Sun, 23 Sep 2007 08:55:45 +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[prototype]]></category>
		<category><![CDATA[tablekit]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://hocuspokus.net/2007/09/23/making-editable-tables-with-catalyst-and-tablekit/</guid>
		<description><![CDATA[Catalyst is an MVC web-development framework for Perl, very similar in concepts, ideas (and even some of the implementation) to Ruby on Rails. I&#8217;m using Catalyst a lot in my job now, and one of the first challenges that i&#8217;ve &#8230; <a href="http://hocuspokus.net/feeder/?FeederAction=clicked&#38;feed=Articles+%28RSS2%29&#38;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F09%2Fmaking-editable-tables-with-catalyst-and-tablekit&#38;seed_title=Making+Editable+Tables+With+Catalyst+and%26%23160%3BTableKit">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.catalystframework.org/">Catalyst</a> is an MVC web-development framework for Perl, very similar in concepts, ideas (and even some of the implementation) to <a href="http://rubyonrails.org/">Ruby on Rails</a>.  I&#8217;m using Catalyst a lot in my job now, and one of the first challenges that i&#8217;ve had to go through is making dynamically editable tables for some of the views we are using (in other words, Ajax driven edit-in-place tables).</p>

<p>Following a short Google, there seemed to be only two ready-made options I could see: one, using the Catalyst controller module <a href="http://search.cpan.org/~karman/Catalyst-Controller-Rose-0.04/lib/Catalyst/Controller/Rose/EIP.pm">Catalyst::Controller::ROSE::EIP</a>; or two, by integrating and using the stand-alone javascript package <a href="http://www.millstream.com.au/view/code/tablekit/">TableKit</a>.</p>

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

<p>Unfortunately the first option, ROSE::EIP is dependent on the use of the <a href="http://search.cpan.org/~jsiracusa/Rose-DB-Object-0.765/lib/Rose/DB/Object.pm">Rose::DB::Object</a> as your database ORM mapper. As our webapp is already using <a href="http://search.cpan.org/~ash/DBIx-Class-0.08007/lib/DBIx/Class.pm">DBIx::Class</a> as its ORM layer, that rules ROSE::EIP out and TableKit was the way to go.  Here&#8217;s a quick rundown of how I got it going, using a very simple table to store a users first and last names as an example (all files used in this tutorial are available for download at the bottom of this post) and a single controller called &#8216;users&#8217;.</p>

<p>First off, head on over to the <a href="http://www.millstream.com.au/view/code/tablekit/">TableKit</a> site and download the latest TableKit package, then create the following three directories in your <code>/MyApp/root/</code> directory: <em>javascript</em>, <em>css</em>, and <em>images</em>.</p>

<p>From the TableKit download, copy the files: <em>tablekit.js</em>, <em>fastinit.js</em> and <em>prototype.js</em> (found in scriptaculous/lib) into your new &#8216;<em>javascript</em>&#8217; directory; then copy the two images - <em>down.gif</em> and <em>up.gif</em> into the <em>images</em> directory.</p>

<p>Now create a new file and add in the following CSS code:</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
</pre></td><td class="code"><pre class="css" style="font-family:monospace;">table <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">border-collapse</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">collapse</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
td<span style="color: #00AA00;">,</span> th <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">0.5em</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#CCC</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
thead<span style="color: #00AA00;">,</span> tfoot <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;">#DDD</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
thead <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">border-bottom</span><span style="color: #00AA00;">:</span> <span style="color: #933;">2px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#f08900</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
tfoot <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">border-top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">2px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#f08900</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
tr<span style="color: #6666ff;">.rowodd</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: #00AA00;">&#125;</span>
&nbsp;
tr<span style="color: #6666ff;">.roweven</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;">#F2F2F2</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.sortcol</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">cursor</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">pointer</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">padding-right</span><span style="color: #00AA00;">:</span> <span style="color: #933;">20px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background-repeat</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background-position</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">right</span> <span style="color: #993333;">center</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.sortasc</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;">#DDFFAC</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background-image</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'/images/up.gif'</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.sortdesc</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;">#B9DDFF</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background-image</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'/images/down.gif'</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.nosort</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">cursor</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">default</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
th<span style="color: #6666ff;">.resize-handle-active</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">cursor</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">e-resize</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
div<span style="color: #6666ff;">.resize-handle</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">cursor</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">e-resize</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">2px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">border-right</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #993333;">dashed</span> <span style="color: #cc00cc;">#1E90FF</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</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></pre></td></tr></table></div>


<p>Save this file as &#8216;<em>myapp.css</em>&#8217; in your new <em>css</em> directory.  This will give your tables a on okay looking starting point and nice striping on odd and even rows when we&#8217;re finished.</p>

<p>Next, open up the <code>/MyApp/root/lib/site/html</code> file and add the following lines within the head tags:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">link</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;/css/myapp.css&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #000066;">media</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;screen&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;/javascript/prototype.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;/javascript/fastinit.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;/javascript/tablekit.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span></pre></td></tr></table></div>


<p>Now, we update our <code>/MyApp/root/src/users/list.tt</code> file so that the users table looks like the following snippet of code:</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
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;">[% META title = 'User List' -%]
<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: #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: #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>&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;">&quot;[% user.id %]&quot;</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: #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>In the above lines of code there are two important details that need to be done in order for the table sorting and editing to work:</p>

<p><em>One: The id properties</em></p>

<p>The id properties on each column of the table are set to the same names as the fields in the database table. and the table rows, (in the body of the table) also have an id associated with them - this becomes the database row &#8216;ID&#8217; attribute when the template is interpreted.  These id&#8217;s then become some of the parameters that are passed via TableKit to our Ajax.Updater controller method.</p>

<p><em>Two: The class properties</em></p>

<p>In the table header, the id column has two classes applied to it - &#8216;sortfirstasc&#8217; and &#8216;noedit&#8217; - this tells TableKit to first sort the table based on this column (and ascending), and that the values of this column are not to be editable.</p>

<p>Also in the declaration of the table, the table has the classes: &#8216;sortable&#8217; &#8216;resizable&#8217; and &#8216;editable&#8217; - these tell TableKit what you&#8217;d like to be able to do with your table.</p>

<p>Finally, add the following snippet of Javascript code to the bottom of the same file (<code>/MyApp/root/src/users/list.tt</code>):</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</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> comments_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;">'[% update_uri %]'</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>


<p>This initializes the TableKit actions and tells TableKit the uri that the Prototype Ajax.Updater is to call (a Catalyst controller method that we&#8217;re about to create).</p>

<p>The final step is now back in the &#8216;Users&#8217; controller.  Here&#8217;s the code that we need for both the initial list of users and the Ajax.Updater method that TableKit calls:</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
</pre></td><td class="code"><pre class="perl" style="font-family:monospace;"><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: #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>update_uri<span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">uri_for</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'/users/_update_user'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</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></pre></td></tr></table></div>


<p>There you go, you should now have a table on your &#8216;/users/list&#8217; page that is sortable, resizable, and now even in-place editable.  I hope these instructions are clear enough (there&#8217;s quite a lot in there!), any questions, comments or improvements people could give me would be most appreciated.</p>

<p>Next up, i&#8217;ll go through how I made the tables more functional by adding in add and delete buttons (to add and delete rows to the table, and therefore create new database entries). <img src='http://hocuspokus.net/wp-content/plugins/smilies-themer/tango/face-smile.png' alt=':)' class='wp-smiley' /> </p>

<h4>Attached Files:</h4>

<p><a href='http://hocuspokus.net/wp-content/uploads/2007/09/myapp.zip' title='MyApp' class="archive">MyApp</a></p>
]]></content:encoded>
			<wfw:commentRss>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F09%2Fmaking-editable-tables-with-catalyst-and-tablekit&amp;seed_title=Making+Editable+Tables+With+Catalyst+and%26%23160%3BTableKit/feed</wfw:commentRss>
		<slash:comments>1</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! -->