<?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/"
	xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Stephen&#039;s dev blog</title>
	<atom:link href="http://colourgray.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://colourgray.wordpress.com</link>
	<description>I heart javascript</description>
	<lastBuildDate>Mon, 27 Jul 2009 09:06:16 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='colourgray.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/c469c5312e9e557cf1471093e518e3f8?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Stephen&#039;s dev blog</title>
		<link>http://colourgray.wordpress.com</link>
	</image>
			<item>
		<title>jQuery retrieving the data from an AJAX call into the global scope</title>
		<link>http://colourgray.wordpress.com/2009/07/27/jquery-retrieving-the-data-from-an-ajax-call-into-the-global-scope/</link>
		<comments>http://colourgray.wordpress.com/2009/07/27/jquery-retrieving-the-data-from-an-ajax-call-into-the-global-scope/#comments</comments>
		<pubDate>Mon, 27 Jul 2009 09:06:16 +0000</pubDate>
		<dc:creator>Stephen Gray</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[scope]]></category>

		<guid isPermaLink="false">http://colourgray.wordpress.com/?p=133</guid>
		<description><![CDATA[Another quick one. Reading around it seems to be an issue. You make an AJAX call within a function and you want the call to be synchronous so that you can use the data from the call in the function scope.
AJAX calls are obviously asynchronous. jQuery has a &#8216;async: false&#8217; option in AJAX calls but [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=colourgray.wordpress.com&blog=4318111&post=133&subd=colourgray&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Another quick one. Reading around it seems to be an issue. You make an AJAX call within a function and you want the call to be synchronous so that you can use the data from the call in the function scope.</p>
<p>AJAX calls are obviously asynchronous. jQuery has a &#8216;async: false&#8217; option in AJAX calls but it is ignored by most (maybe all?) browsers. Using this method you can force a synchronous request and retrieve that data.</p>
<p><code>function myFunction()</code><br />
<code>{</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;var myVariable = $.ajax(</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;{</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;url: 'someScript.php',</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;async: false</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;}).responseText;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;alert(myVariable);</code><br />
<code>}</code></p>
<p>So .responseText retrieves the text value of the response from the AJAX call. And because we&#8217;re assigning to a variable we are forcing a synchronous request. You can now use that variable as you see fit.</p>
<p>This causes an issue when you are trying to retrieve a JSON object from an AJAX call into the function scope. The best way I&#8217;ve found so far is to retrieve the JSON as a string and use a jquery JSON plugin to convert it into an accessible object. Or you could just use the &#8216;eval&#8217; method.</p>
<p>Stephen.</p>
Posted in Tutorials Tagged: ajax, javascript, jquery, json, scope <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/colourgray.wordpress.com/133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/colourgray.wordpress.com/133/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/colourgray.wordpress.com/133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/colourgray.wordpress.com/133/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/colourgray.wordpress.com/133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/colourgray.wordpress.com/133/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/colourgray.wordpress.com/133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/colourgray.wordpress.com/133/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/colourgray.wordpress.com/133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/colourgray.wordpress.com/133/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=colourgray.wordpress.com&blog=4318111&post=133&subd=colourgray&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://colourgray.wordpress.com/2009/07/27/jquery-retrieving-the-data-from-an-ajax-call-into-the-global-scope/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/717393f091b7d194303f60afa59f2f39?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Gray</media:title>
		</media:content>
	</item>
		<item>
		<title>Custom SQL in symfony 1.2.3</title>
		<link>http://colourgray.wordpress.com/2009/06/29/custom-sql-in-symfony-1-2-3/</link>
		<comments>http://colourgray.wordpress.com/2009/06/29/custom-sql-in-symfony-1-2-3/#comments</comments>
		<pubDate>Mon, 29 Jun 2009 09:59:24 +0000</pubDate>
		<dc:creator>Stephen Gray</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[custom]]></category>
		<category><![CDATA[propel]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://colourgray.wordpress.com/?p=128</guid>
		<description><![CDATA[Quick one. A small snippet for performing custom SQL queries using symfony 1.2.3. The method to do this has varied slightly with the different symfony releases. The method found on the symfony site almost has a good example, this is just adding a bit to it (looping);
&#160;&#160;&#160;&#160;$conn = Propel::getConnection();
&#160;&#160;&#160;&#160;$query = 'SELECT * FROM `my_table`;';

&#160;&#160;&#160;&#160;$statement = [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=colourgray.wordpress.com&blog=4318111&post=128&subd=colourgray&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Quick one. A small snippet for performing custom SQL queries using symfony 1.2.3. The method to do this has varied slightly with the different symfony releases. The method found on the symfony site almost has a good example, this is just adding a bit to it (looping);</p>
<p><code>&nbsp;&nbsp;&nbsp;&nbsp;$conn = Propel::getConnection();</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;$query = 'SELECT * FROM `my_table`;';</code><br />
<code></code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;$statement = $conn-&gt;prepare($query);</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;$statement-&gt;execute();</code><br />
<code></code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;while ($rowObj = $statement-&gt;fetch(PDO::FETCH_OBJ))</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;{</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo var_dump($rowObj);</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;}</code></p>
<p>Stephen.</p>
Posted in Tutorials Tagged: custom, propel, sql, symfony <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/colourgray.wordpress.com/128/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/colourgray.wordpress.com/128/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/colourgray.wordpress.com/128/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/colourgray.wordpress.com/128/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/colourgray.wordpress.com/128/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/colourgray.wordpress.com/128/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/colourgray.wordpress.com/128/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/colourgray.wordpress.com/128/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/colourgray.wordpress.com/128/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/colourgray.wordpress.com/128/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=colourgray.wordpress.com&blog=4318111&post=128&subd=colourgray&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://colourgray.wordpress.com/2009/06/29/custom-sql-in-symfony-1-2-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/717393f091b7d194303f60afa59f2f39?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Gray</media:title>
		</media:content>
	</item>
		<item>
		<title>jQuery wildcard selectors &#8211; update</title>
		<link>http://colourgray.wordpress.com/2009/04/24/jquery-wildcard-selectors-update/</link>
		<comments>http://colourgray.wordpress.com/2009/04/24/jquery-wildcard-selectors-update/#comments</comments>
		<pubDate>Fri, 24 Apr 2009 09:16:58 +0000</pubDate>
		<dc:creator>Stephen Gray</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[selector]]></category>
		<category><![CDATA[wildcard]]></category>

		<guid isPermaLink="false">http://colourgray.wordpress.com/?p=123</guid>
		<description><![CDATA[Hello all,
On my first post on this blog I posted a small snippet to use a small regex pattern in jQuery selectors.
You can find the post here: http://colourgray.wordpress.com/2008/08/05/jquery-wildcard-selectors/
I was reading through some comments and posts on some incoming links and it seems it wasn&#8217;t working for anyone anymore. I just tested it myself and unfortunately [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=colourgray.wordpress.com&blog=4318111&post=123&subd=colourgray&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Hello all,</p>
<p>On my first post on this blog I posted a small snippet to use a small regex pattern in jQuery selectors.</p>
<p>You can find the post here: <a href="http://colourgray.wordpress.com/2008/08/05/jquery-wildcard-selectors/">http://colourgray.wordpress.com/2008/08/05/jquery-wildcard-selectors/</a></p>
<p>I was reading through some comments and posts on some incoming links and it seems it wasn&#8217;t working for anyone anymore. I just tested it myself and unfortunately it&#8217;s true (at least with with jQuery v1.3.1). However! All is not lost, there is another method which I&#8217;ve tested from one of the incoming links to that post which you can find here:</p>
<p><a href="http://ropox.net/archives/1081">http://ropox.net/archives/1081</a></p>
<p>Cheers ropox!</p>
<p>Stephen.</p>
Posted in Tutorials Tagged: javascript, jquery, regex, selector, wildcard <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/colourgray.wordpress.com/123/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/colourgray.wordpress.com/123/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/colourgray.wordpress.com/123/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/colourgray.wordpress.com/123/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/colourgray.wordpress.com/123/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/colourgray.wordpress.com/123/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/colourgray.wordpress.com/123/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/colourgray.wordpress.com/123/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/colourgray.wordpress.com/123/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/colourgray.wordpress.com/123/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=colourgray.wordpress.com&blog=4318111&post=123&subd=colourgray&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://colourgray.wordpress.com/2009/04/24/jquery-wildcard-selectors-update/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/717393f091b7d194303f60afa59f2f39?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Gray</media:title>
		</media:content>
	</item>
		<item>
		<title>Symfony &#8220;Database &#8220;&#8221; does not exist.&#8221; error</title>
		<link>http://colourgray.wordpress.com/2009/03/02/symfony-database-does-not-exist-error/</link>
		<comments>http://colourgray.wordpress.com/2009/03/02/symfony-database-does-not-exist-error/#comments</comments>
		<pubDate>Mon, 02 Mar 2009 11:20:34 +0000</pubDate>
		<dc:creator>Stephen Gray</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[propel]]></category>
		<category><![CDATA[schema]]></category>
		<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://colourgray.wordpress.com/?p=119</guid>
		<description><![CDATA[Hello,
It&#8217;s definitely been too long since I posted here! I will try and post more regularly over the coming months&#8230;
Firstly, we came across this issue after writing a number of plugins for a symfony project. Each of these plugins had their own schema.yml files and therefore we didn&#8217;t need our own custom schema.yml file at [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=colourgray.wordpress.com&blog=4318111&post=119&subd=colourgray&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Hello,</p>
<p>It&#8217;s definitely been too long since I posted here! I will try and post more regularly over the coming months&#8230;</p>
<p>Firstly, we came across this issue after writing a number of plugins for a symfony project. Each of these plugins had their own schema.yml files and therefore we didn&#8217;t need our own custom schema.yml file at that time.</p>
<p>Because of this, our config/schema.yml file looked like this:</p>
<p><code>&nbsp;&nbsp;&nbsp;&nbsp;propel:</code></p>
<p>Pretty, right? When we ran symfony propel:build-sql (after the other usual build tasks) we got the error:</p>
<p><code>&nbsp;&nbsp;&nbsp;&nbsp;Database "" does not exist.</code></p>
<p>In symfony&#8217;s glorious vibrant red error container. It seems when your schema file looks like ours did above, symfony generates the sqldb.map file for that file without a database name, our data/sql/sqldb.map file looked similar to this:</p>
<p><code><br />
&nbsp;&nbsp;&nbsp;&nbsp;# Sqlfile -&gt; Database map<br />
&nbsp;&nbsp;&nbsp;&nbsp;...<br />
&nbsp;&nbsp;&nbsp;&nbsp;lib.model.schema.sql=propel<br />
&nbsp;&nbsp;&nbsp;&nbsp;plugins.pluginName.lib.model.schema.sql=propel<br />
&nbsp;&nbsp;&nbsp;&nbsp;plugins.pluginName2.lib.model.schema.sql=propel<br />
&nbsp;&nbsp;&nbsp;&nbsp;generated-schema.sql=propel<br />
&nbsp;&nbsp;&nbsp;&nbsp;generated-pluginName-schema.sql=propel<br />
&nbsp;&nbsp;&nbsp;&nbsp;generated-pluginName2-schema.sql=propel<br />
&nbsp;&nbsp;&nbsp;&nbsp;...<br />
</code></p>
<p>The quick fix, especially if you don&#8217;t want to have to add a custom table in your schema just to get round this, is to simple add &#8216;propel&#8217; onto the end of the line that is missing it.</p>
<p>Hopefully there&#8217;s a proper fix that I so far haven&#8217;t been bothered to find&#8230;</p>
Posted in Tutorials Tagged: error, propel, schema, symfony <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/colourgray.wordpress.com/119/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/colourgray.wordpress.com/119/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/colourgray.wordpress.com/119/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/colourgray.wordpress.com/119/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/colourgray.wordpress.com/119/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/colourgray.wordpress.com/119/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/colourgray.wordpress.com/119/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/colourgray.wordpress.com/119/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/colourgray.wordpress.com/119/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/colourgray.wordpress.com/119/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=colourgray.wordpress.com&blog=4318111&post=119&subd=colourgray&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://colourgray.wordpress.com/2009/03/02/symfony-database-does-not-exist-error/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/717393f091b7d194303f60afa59f2f39?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Gray</media:title>
		</media:content>
	</item>
		<item>
		<title>symfony Unable to parse default value as date/time value: &#8216;0000-00-00 00:00:00&#8242;</title>
		<link>http://colourgray.wordpress.com/2008/09/26/symfony-unable-to-parse-default-value-as-datetime-value-0000-00-00-000000/</link>
		<comments>http://colourgray.wordpress.com/2008/09/26/symfony-unable-to-parse-default-value-as-datetime-value-0000-00-00-000000/#comments</comments>
		<pubDate>Fri, 26 Sep 2008 13:53:19 +0000</pubDate>
		<dc:creator>Stephen Gray</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[propel]]></category>
		<category><![CDATA[symfony]]></category>
		<category><![CDATA[time]]></category>

		<guid isPermaLink="false">http://colourgray.wordpress.com/?p=114</guid>
		<description><![CDATA[I&#8217;ve just made a change to a symfony project&#8217;s schema.yml file and tried to rebuild the model and came across this error message:
Unable to parse default value as date/time value: &#8216;0000-00-00 00:00:00&#8242;
Which was stopping the build. After looking at various places, it seems this is a problem with Creole, (propel&#8217;s DBAL).
Before PHP v5.2.4, you could [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=colourgray.wordpress.com&blog=4318111&post=114&subd=colourgray&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I&#8217;ve just made a change to a symfony project&#8217;s schema.yml file and tried to rebuild the model and came across this error message:</p>
<p>Unable to parse default value as date/time value: &#8216;0000-00-00 00:00:00&#8242;</p>
<p>Which was stopping the build. After looking at various places, it seems this is a problem with Creole, (propel&#8217;s DBAL).</p>
<p>Before PHP v5.2.4, you could do a strtotime on a value of 000-00-00 00:00:00 and you would get a weird date, something in 1999. Not sure why :S Since the 5.2.4 update however this bug has been fixed and you will now get boolean false returned.</p>
<p>The symfony plugin sfGuard, which is widely used, uses 0000-00-00 00:00:00 as a default value in it&#8217;s schema for some fields and this will now cause problems. To fix this, edit sfGuard&#8217;s schema and change those default values to something like 1970-01-01 and that should do the trick.</p>
<p>Unfortunately Creole isn&#8217;t actively maintained anymore so it&#8217;s not likely to be updated soon to fix this.</p>
Posted in Tutorials Tagged: date, error, propel, symfony, time <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/colourgray.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/colourgray.wordpress.com/114/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/colourgray.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/colourgray.wordpress.com/114/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/colourgray.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/colourgray.wordpress.com/114/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/colourgray.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/colourgray.wordpress.com/114/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/colourgray.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/colourgray.wordpress.com/114/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=colourgray.wordpress.com&blog=4318111&post=114&subd=colourgray&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://colourgray.wordpress.com/2008/09/26/symfony-unable-to-parse-default-value-as-datetime-value-0000-00-00-000000/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/717393f091b7d194303f60afa59f2f39?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Gray</media:title>
		</media:content>
	</item>
		<item>
		<title>jQuery loading remote/external javascript files using getScript()</title>
		<link>http://colourgray.wordpress.com/2008/09/22/jquery-loading-external-javascript-files-using-getscript/</link>
		<comments>http://colourgray.wordpress.com/2008/09/22/jquery-loading-external-javascript-files-using-getscript/#comments</comments>
		<pubDate>Mon, 22 Sep 2008 08:57:22 +0000</pubDate>
		<dc:creator>Stephen Gray</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[external]]></category>
		<category><![CDATA[getScript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[remote]]></category>

		<guid isPermaLink="false">http://colourgray.wordpress.com/?p=109</guid>
		<description><![CDATA[I&#8217;ve been working over the weekend on a site and I got to the part of writing the client side MVC using jQuery (because I love the idea now!).
I found out that jQuery has a nice little method for loading external scripts into the page at run time called getScript(). It basically gets the contents [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=colourgray.wordpress.com&blog=4318111&post=109&subd=colourgray&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I&#8217;ve been working over the weekend on a site and I got to the part of writing the client side MVC using jQuery (because I love the idea now!).</p>
<p>I found out that jQuery has a nice little method for loading external scripts into the page at run time called getScript(). It basically gets the contents of the external file using an AJAX request and then eval()s the code at runtime, which seems like a perfect way of doing it. I reckon it&#8217;s much better than appending new &lt;script&gt; tags to the &lt;head&gt; tag as well.</p>
<p>The only issue is that it can take some time to load an external file so you can&#8217;t always run functions from within that file straight away. Thankfully there is a workaround for this using another jQuery method. You basically set all AJAX request to be synchronous before you run getScript() and then set AJAX requests to be asynchronous again after the script is loaded. If you end up loading like 20 files at the beginning of a page load this could take a while but hopefully you won&#8217;t be doing that <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
<p><code>$.ajaxSetup({async: false});</code><br />
<code>$.getScript(MVCRoot+fileName+'.js');</code><br />
<code>$.ajaxSetup({async: true});</code></p>
<p><a href="http://docs.jquery.com/Ajax/jQuery.getScript">And here&#8217;s some more info on this lovely little function <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </a></p>
Posted in Tutorials Tagged: external, getScript, jquery, remote <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/colourgray.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/colourgray.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/colourgray.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/colourgray.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/colourgray.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/colourgray.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/colourgray.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/colourgray.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/colourgray.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/colourgray.wordpress.com/109/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=colourgray.wordpress.com&blog=4318111&post=109&subd=colourgray&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://colourgray.wordpress.com/2008/09/22/jquery-loading-external-javascript-files-using-getscript/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/717393f091b7d194303f60afa59f2f39?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Gray</media:title>
		</media:content>
	</item>
		<item>
		<title>SproutCore: a proper javascript framework</title>
		<link>http://colourgray.wordpress.com/2008/09/17/sproutcore-a-proper-javascript-framework/</link>
		<comments>http://colourgray.wordpress.com/2008/09/17/sproutcore-a-proper-javascript-framework/#comments</comments>
		<pubDate>Wed, 17 Sep 2008 17:03:49 +0000</pubDate>
		<dc:creator>Stephen Gray</dc:creator>
				<category><![CDATA[Dev thoughts]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[sproutcore]]></category>

		<guid isPermaLink="false">http://colourgray.wordpress.com/?p=107</guid>
		<description><![CDATA[I wrote a while ago about creating a client side MVC system in javascript.
Yesterday at one of the talks SproutCore was mentioned. I had a look today and it looks very promising. It&#8217;s a full framework designed to create full &#8216;thick client&#8217; javascript applications. The core of it was written in Ruby and I haven&#8217;t [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=colourgray.wordpress.com&blog=4318111&post=107&subd=colourgray&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I wrote a while ago about<a href="http://colourgray.wordpress.com/2008/08/28/jquery-create-a-client-side-mvc/"> creating a client side MVC system</a> in javascript.</p>
<p>Yesterday at one of the talks <a href="http://www.sproutcore.com/">SproutCore</a> was mentioned. I had a look today and it looks very promising. It&#8217;s a full framework designed to create full &#8216;thick client&#8217; javascript applications. The core of it was written in Ruby and I haven&#8217;t looked into whether you have to know much Ruby to develop in it or not. It reminds me of <a href="http://www.symfony-project.org">symfony</a> because you are given a number of build tools to use on the command line for creating controllers, new projects, models etc etc.</p>
<p>I think I&#8217;m falling in love with the general idea and it&#8217;s great to see someone has actually implemented it quite well (from the looks of it). I haven&#8217;t had the chance to try it out yet but I&#8217;m thinking of using it on a number of personal projects so we&#8217;ll see how it goes!</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/colourgray.wordpress.com/107/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/colourgray.wordpress.com/107/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/colourgray.wordpress.com/107/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/colourgray.wordpress.com/107/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/colourgray.wordpress.com/107/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/colourgray.wordpress.com/107/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/colourgray.wordpress.com/107/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/colourgray.wordpress.com/107/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/colourgray.wordpress.com/107/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/colourgray.wordpress.com/107/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/colourgray.wordpress.com/107/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/colourgray.wordpress.com/107/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=colourgray.wordpress.com&blog=4318111&post=107&subd=colourgray&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://colourgray.wordpress.com/2008/09/17/sproutcore-a-proper-javascript-framework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/717393f091b7d194303f60afa59f2f39?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Gray</media:title>
		</media:content>
	</item>
		<item>
		<title>Google Developer Day 2008</title>
		<link>http://colourgray.wordpress.com/2008/09/17/google-developer-day-2008/</link>
		<comments>http://colourgray.wordpress.com/2008/09/17/google-developer-day-2008/#comments</comments>
		<pubDate>Wed, 17 Sep 2008 16:54:49 +0000</pubDate>
		<dc:creator>Stephen Gray</dc:creator>
				<category><![CDATA[Dev thoughts]]></category>
		<category><![CDATA[2008]]></category>
		<category><![CDATA[developer]]></category>
		<category><![CDATA[google]]></category>

		<guid isPermaLink="false">http://colourgray.wordpress.com/?p=101</guid>
		<description><![CDATA[I had the fortune yesterday to attend the Google Developer Day 2008 in Wembley Stadium with a colleague from work.
We were told there were around 800 people there but with everyone sat down at the morning keynote meeting it didn&#8217;t seem like so many. Also, pretty much everyone there had an iPhone! Everywhere you looked [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=colourgray.wordpress.com&blog=4318111&post=101&subd=colourgray&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I had the fortune yesterday to attend the Google Developer Day 2008 in Wembley Stadium with a colleague from work.</p>
<p>We were told there were around 800 people there but with everyone sat down at the morning keynote meeting it didn&#8217;t seem like so many. Also, pretty much everyone there had an iPhone! Everywhere you looked someone had an iPhone out. I guess it&#8217;s not surprising with so many geeks in one room <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
<p>The whole experience was good, the talks were in depth and on the most part interesting (we went to the wrong room at one point due to a late room switch and I couldn&#8217;t help but get a bit sleepy &#8211; the room was hot!).</p>
<p>There was an interesting talk by Dion Almaer on AJAX, Dion is the co-owner of <a href="http://www.ajaxian.com" target="_blank">Ajaxian</a>. The session was called &#8216;The State of AJAX&#8217; and he talked about how AJAX has come along in recent times and about the current popular javascript frameworks and libraries. He made a good summary of the current status of these frameworks and talked about how with each framework&#8217;s most recent user interface plug ins they are all very similar in functionality.</p>
<p>So which framework is best to use is now down to personal preference, where as before it was down to which framework was best for what you wanted to do. It certainly made me think about how JavaScript has become a mainstream language and it&#8217;s made me think about concentrating on JavaScript as my primary language. It&#8217;s strange, as up until recently a lot of people only saw JavaScript as an &#8216;add-on&#8217; language, if that&#8217;s the right way to describe it. But now with the way the web is going, with rich user interfaces and applications, JavaScript is definitely the way forward.</p>
<p>There were also talks on the Google App Engine and Google Web Toolkit. Both of these are very interesting offerings but I&#8217;m not sure whether I personally, or the company I work for will have use for either of them. At least for the near future.</p>
<p>The Google App Engine is &#8211; in it&#8217;s most basic form &#8211; another cloud service. Much like Amazon&#8217;s EC2 service. Google are now offering the ability to host your web site or application on their existing infrastructure/system architecture. There are the same obvious advantages to using this system as there are with Amazon; large scalability, strong infrastructure, fast up link speeds etc etc. You initially get 500mb of free space, 2GB of bandwidth per day and up to 5 million page views per month for free. After which you need to start forking out the cash. From what I gathered after using your free allowances, the service won&#8217;t be charged on a pay as you go service as with Amazon, but you will have to buy &#8216;blocks&#8217; of extra dish space, bandwidth etc etc. Personally I think I prefer the pay as you go method, but I haven&#8217;t done any calculations to see which would be cheaper so I could easily be wrong.</p>
<p>Unfortunately, the only language currently supported on the Google App Engine is Python. They mentioned yesterday that they are committed to adding more language runtimes to the system, but seeing as Python is one of Google&#8217;s 3 main languages, it was their obvious first choice. Sites and apps can only be pure Python as well, so no using plug ins/extensions which depend on C++ etc.</p>
<p>Google App engine is obviously still very mature so it wouldn&#8217;t be fair to compare it to the other cloud services currently on offer but so far, I think Amazon&#8217;s EC2 service is still on top. I won&#8217;t go into why here <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I was very impressed by the Google Web Toolkit (GWT). The general idea is that you write your Java application in your normal IDE, run the GWT compiler against your Java code and it compiles your normal Java code into JavaScript and HTML files that can be run in any browser. Obviously this is pretty powerful. The example that we got shown was a full GUI application written in Java for viewing or creating complex diagrams. It seemed to run perfectly in the browser, looking just like it would on the desktop. All current popular browsers are automatically supported and the compiler also optimises and obfuscates the generated JavaScript and HTML code. What more could you ask for? The only problem is I don&#8217;t currently know Java and I don&#8217;t believe my company has any intentions of using Java for anything soon <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' />  But an impressive product none the less.</p>
<p>Throughout the day there were free refreshments and snacks and we were provided with a free (mostly) healthy lunch. At the end of the day they showed a video summarising the day&#8217;s events and then there were drinks and food after which I wasn&#8217;t able to stay for <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />  My colleague stayed on for a while and told me they had a Wii being played on the huge presentation screens with Guitar Hero, among other things such as retro Atari arcade consoles. It&#8217;s a shame I didn&#8217;t stay, I&#8217;d have been able to say I beat some Google guys at Guitar Hero! Woop <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>The day was a good experience and I&#8217;d go again, although some sessions did seem quite long and the seats weren&#8217;t exactly comfortable, but a small price to pay for an event like this <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Oh yeah, I didn&#8217;t take any photos except for a few of the Wembley pitch (by going through a door I don&#8217;t think we were allowed to go through) because I was told I wasn&#8217;t allowed. Then we saw lots of other people taking pictures :S Ah well&#8230;</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/colourgray.wordpress.com/101/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/colourgray.wordpress.com/101/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/colourgray.wordpress.com/101/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/colourgray.wordpress.com/101/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/colourgray.wordpress.com/101/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/colourgray.wordpress.com/101/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/colourgray.wordpress.com/101/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/colourgray.wordpress.com/101/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/colourgray.wordpress.com/101/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/colourgray.wordpress.com/101/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/colourgray.wordpress.com/101/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/colourgray.wordpress.com/101/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=colourgray.wordpress.com&blog=4318111&post=101&subd=colourgray&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://colourgray.wordpress.com/2008/09/17/google-developer-day-2008/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/717393f091b7d194303f60afa59f2f39?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Gray</media:title>
		</media:content>
	</item>
		<item>
		<title>Flex save changes from an AdvancedDataGrid using itemEditEnd</title>
		<link>http://colourgray.wordpress.com/2008/09/15/flex-save-changes-from-an-advanceddatagrid-using-itemeditend/</link>
		<comments>http://colourgray.wordpress.com/2008/09/15/flex-save-changes-from-an-advanceddatagrid-using-itemeditend/#comments</comments>
		<pubDate>Mon, 15 Sep 2008 10:38:22 +0000</pubDate>
		<dc:creator>Stephen Gray</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[advanceddatagrid]]></category>
		<category><![CDATA[datagrid]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[itemEditEnd]]></category>
		<category><![CDATA[save]]></category>

		<guid isPermaLink="false">http://colourgray.wordpress.com/?p=96</guid>
		<description><![CDATA[I just remembered that I had trouble finding out what I could access with this event handler function. Sure it was easy to find out when the event is dispatched, but how can I access the new field value edited by the user? How do I access the previous value?
So this is just a simple [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=colourgray.wordpress.com&blog=4318111&post=96&subd=colourgray&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I just remembered that I had trouble finding out what I could access with this event handler function. Sure it was easy to find out when the event is dispatched, but how can I access the new field value edited by the user? How do I access the previous value?</p>
<p>So this is just a simple example showing you that. This also applies to the normal DataGrid and standard list controls.</p>
<p>The itemEditEnd event is dispatched (it&#8217;s in the name) when a user finishes editing a cell so this is pretty much the best time to save the user&#8217;s changes to that field/row.</p>
<p>Here&#8217;s our function:</p>
<p><code>protected function saveChange(event:AdvancedDataGridEvent):void</code><br />
<code>{</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;/**</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;* use event.dataField to get the edited field name</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;var field:String = event.dataField;</code><br />
<code></code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;/**</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;* i'm using the following line to get the 'id' of the row being edited</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;* because i passed an 'id' field through from my dataProvider.</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;var selectedID:String = event.currentTarget.selectedItem.id.toString();</code><br />
<code></code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;/**</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;* use the itemEditorInstance to get the newly edited value but retrieve</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;* the previous value from the existing grid data. i'm using the default</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;* textinput itemRenderer so I can retrieve the new value using the </code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;* itemEditInstance's 'text' property.</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;var newValue:String = event.currentTarget.itemEditorInstance.text;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;var prevValue:String = ProductPersonalisationList.selectedItem[event.dataField];</code></p>
<p><code>&nbsp;&nbsp;&nbsp;&nbsp;// run a http service call or something to save the change or validate the data</code><br />
<code>}</code></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/colourgray.wordpress.com/96/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/colourgray.wordpress.com/96/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/colourgray.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/colourgray.wordpress.com/96/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/colourgray.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/colourgray.wordpress.com/96/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/colourgray.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/colourgray.wordpress.com/96/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/colourgray.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/colourgray.wordpress.com/96/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/colourgray.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/colourgray.wordpress.com/96/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=colourgray.wordpress.com&blog=4318111&post=96&subd=colourgray&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://colourgray.wordpress.com/2008/09/15/flex-save-changes-from-an-advanceddatagrid-using-itemeditend/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/717393f091b7d194303f60afa59f2f39?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Gray</media:title>
		</media:content>
	</item>
		<item>
		<title>jQuery create a client-side MVC</title>
		<link>http://colourgray.wordpress.com/2008/08/28/jquery-create-a-client-side-mvc/</link>
		<comments>http://colourgray.wordpress.com/2008/08/28/jquery-create-a-client-side-mvc/#comments</comments>
		<pubDate>Thu, 28 Aug 2008 16:59:15 +0000</pubDate>
		<dc:creator>Stephen Gray</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[mvc]]></category>

		<guid isPermaLink="false">http://colourgray.wordpress.com/?p=85</guid>
		<description><![CDATA[jquery, mvc, framework<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=colourgray.wordpress.com&blog=4318111&post=85&subd=colourgray&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>A while ago a colleague suggested to me the idea of having a client-side MVC (Model View Controller) framework. At first I didn&#8217;t like the idea. I have always thought that all client-side code should be seen as one layer, one collection of files that all act as one set of functionality. Whether that be AJAX calls or general functions etc etc.</p>
<p>Then I began to think about it. We already know that a client-side MVC is possible, but I can now see why it would be useful. But it wouldn&#8217;t be the traditional MVC architecture, it would really only be VC, the view and controller layers. And that&#8217;s all it can ever really be. Javascript can never directly access the model in a web application environment.</p>
<p>I decided that a VC client-side system would still be useful and I&#8217;m probably going to develop one for future use. I haven&#8217;t got round to doing this yet but these are my ideas.</p>
<p>Firstly, looking at a few of our sites, I could quickly see that there were many javascript files being loaded per page as they were needed. The number of files could range from 5 to 10 or even more. So we need a way of dynamically loading javascript files onto the page as and when they are needed, on the fly. I initially thought that it wasn&#8217;t possible to dynamically load javascript files from within a javascript page but I Googled around a bit and when I found the solution it was painfully obvious: you simply load more  tags in the  section of the HTML.</p>
<p>So with that in mind, lets create a simple front controller. What does it need to do? It needs to have some basic configuration for the MVC; where the root of the files are etc. It needs to have the aforementioned function to load external javascript files into the current page. It needs to have an initialisation function which kicks the MVC off:</p>
<p>mvc.init.js<br />
<code>/**</code><br />
<code> * client MVC initialiser</code><br />
<code> */</code></p>
<p><code>/**</code><br />
<code> * wheres are the MVC files?</code><br />
<code> *</code><br />
<code> * @access public</code><br />
<code> * @var    string</code><br />
<code> */</code><br />
<code>var MVCRoot = '/js/';</code><br />
<code> </code><br />
<code>/**</code><br />
<code> * initialise the controller</code><br />
<code> */</code><br />
<code>$(document).ready(function()</code><br />
<code>{</code><br />
<code> loadJS('mvc.controller');</code><br />
<code> Controller.init();</code><br />
<code>});</code></p>
<p><code>/**</code><br />
<code> * load an external js file by appending</code><br />
<code> * script tag as child to &lt;head&gt; section</code><br />
<code> *</code><br />
<code> * @var    fileName     name of file to load</code><br />
<code> * @return bool         true on success, false on no fileName given</code><br />
<code> */</code><br />
<code>function loadJS(fileName = null)</code><br />
<code>{</code><br />
<code> if (fileName != null)</code><br />
<code> {</code><br />
<code> $('&lt;script type="text/javascript" src="'+MVCRoot+fileName+'.js"&gt;&lt;/script&gt;').appendTo('head');</code><br />
<code> return true;</code><br />
<code> }</code><br />
<code> else</code><br />
<code> {</code><br />
<code> return false;</code><br />
<code> }</code><br />
<code>}</code></p>
<p>Ok most of that should make sense. The loadJS() function is fairly straight forward, it simply builds a HTML &lt;script&gt; tag for the new javascript file and appends it to the &lt;head&gt; tag of the HTML. The $(document).ready function then uses this function to &#8216;include&#8217; the main controller file (which will be /js/mvc.controller.js according to the current config). Now that the init function can call methods of the Controller class it calls the main controller&#8217;s initialisation method.</p>
<p>As an initial idea, the main controller could start off looking like this:</p>
<p>mvc.controller.js<br />
<code>/**</code><br />
<code> * client main controller</code><br />
<code> */</code></p>
<p><code>var Controller = </code><br />
<code>{</code><br />
<code> /**</code><br />
<code> * holds the current page's type</code><br />
<code> * used for loading required js files etc</code><br />
<code> *</code><br />
<code> * @var    string</code><br />
<code> * @access protected</code><br />
<code> */</code><br />
<code> var _pageType : null,</code><br />
<code> </code><br />
<code> /**</code><br />
<code> * main controller init function</code><br />
<code> * gets current page type</code><br />
<code> * includes required js files</code><br />
<code> */</code><br />
<code> var init : function()</code><br />
<code> {</code><br />
<code> loadJS('mvc.controller.ajax');</code><br />
<code> Controller._getPageType();</code><br />
<code> </code><br />
<code> /**</code><br />
<code> * logic to include required files dependent on page</code><br />
<code> * type etc etc</code><br />
<code> */</code><br />
<code> ...</code><br />
<code> }</code><br />
<code> </code><br />
<code> /**</code><br />
<code> * returns the page type for current URI</code><br />
<code> *</code><br />
<code> * @return void</code><br />
<code> */</code><br />
<code> var _getPageType : function()</code><br />
<code> {</code><br />
<code> var currentURI = window.location;</code><br />
<code> Controller._pageType = ControllerAjax.getPageType(currentURI);</code><br />
<code> }</code><br />
<code>}</code></p>
<p>Again this is mostly basic stuff and it definitely hasn&#8217;t been tested but I think the general idea is in the right direction. I think now that I can visualise how to seperate out javascript objects more clearly I can see how this would benefit a javascript heavy web site/application.</p>
<p>Even though web frameworks have been gaining more and more popularity over recent years I hadn&#8217;t thought of applying the same methodical approach to client side coding until my colleague suggested this idea. I think if you think about it and you&#8217;re thinking like I was, you can quickly warm to the idea as I have. Almost every day you can read a new article about how in development, we need to be separating out our different types of logic and our layers. Javascript is of course just another language, so why should it not get the same treatment? <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/colourgray.wordpress.com/85/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/colourgray.wordpress.com/85/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/colourgray.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/colourgray.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/colourgray.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/colourgray.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/colourgray.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/colourgray.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/colourgray.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/colourgray.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/colourgray.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/colourgray.wordpress.com/85/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=colourgray.wordpress.com&blog=4318111&post=85&subd=colourgray&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://colourgray.wordpress.com/2008/08/28/jquery-create-a-client-side-mvc/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/717393f091b7d194303f60afa59f2f39?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Gray</media:title>
		</media:content>
	</item>
	</channel>
</rss>