<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Pro Bono Geek » ExtJS</title>
	
	<link>http://blog.probonogeek.org</link>
	<description>Technology for the Good of People</description>
	<lastBuildDate>Tue, 06 Dec 2011 10:00:30 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/probonogeek-extjs" /><feedburner:info uri="probonogeek-extjs" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:browserFriendly></feedburner:browserFriendly><item>
		<title>ExtJS Git Submodule</title>
		<link>http://blog.probonogeek.org/2009/04/extjs-git-submodule/</link>
		<comments>http://blog.probonogeek.org/2009/04/extjs-git-submodule/#comments</comments>
		<pubDate>Fri, 24 Apr 2009 00:36:58 +0000</pubDate>
		<dc:creator>probonogeek</dc:creator>
				<category><![CDATA[ExtJS]]></category>

		<guid isPermaLink="false">http://blog.probonogeek.org/?p=573</guid>
		<description><![CDATA[I know it&#8217;s been a while since I last posted about ExtJS&#8230; things have been quite busy at work and I&#8217;ve forced myself to take a sabbatical from the project that has me working with ExtJS everyday. I&#8217;ll get back to it soon, don&#8217;t worry, and I have lots of topics in the queue. In [...]]]></description>
			<content:encoded><![CDATA[<p>I know it&#8217;s been a while since I last posted about ExtJS&#8230; things have been quite busy at work and I&#8217;ve forced myself to take a sabbatical from the project that has me working with ExtJS everyday. I&#8217;ll get back to it soon, don&#8217;t worry, and I have lots of topics in the queue. In the meantime, I have a bit of a public service announcement for those who use ExtJS with git.<span id="more-573"></span></p>
<p>If you&#8217;re not familiar with <a href="http://git-scm.com/">git</a> as a version control system, I encourage you to check it out. I came from Subversion, which was great&#8230; but, at least for me, git is better. Better yet, if you use git with open source projects, you can use <a href="http://github.com">github.com</a> for free to host your code, which is pretty cool, and self-hosting isn&#8217;t very challenging either. One of the aspects of git I&#8217;m just coming to understand is <a href='http://www.kernel.org/pub/software/scm/git/docs/git-submodule.html'>git-submodule</a>. The idea is that there is an external project you&#8217;d like to pull into your project, but instead of committing it to your own repository, you want to use the external project&#8217;s repository. Lots of reasons to want to do this, such as making it easier to track upstream changes, or reducing the size of your own repository.</p>
<p>Ever since I learned about git submodules, I&#8217;ve thought that ExtJS seemed like a perfect candidate. As there is a mechanism to change the library at runtime without changing the code on the file system, there&#8217;s very little reason to have the library in your own repository. On top of which, ExtJS is <i>big</i>, so why waste the space. Sadly, the fine folks at extjs.com do not provide ExtJS in git form. There is a subversion repository for commercial clients (of which my employer is) but subversion is not git.</p>
<p>Thus, I have decided to take matters into my own hands. As ExtJS is licensed under the GPL, I have the legal right to redistribute the code. So I created my own <a href="http://github.com/probonogeek/extjs/tree/master">git repository just for ExtJS</a> at github which anyone can use as to add ExtJS as a git submodule. I&#8217;m still trying to figure out some aspects of git-submodule&#8230; like, is it possible to specify a tag from the external repo? If so, I will start adding tags to the repository as new versions are released.</p>
<p>For those who want to jump right into using the repo, here&#8217;s the magical incantation you want to run from your project root (change the &#8220;public/extjs&#8221; part to the relative path you want to install ExtJS at):</p>
<pre class="brush: shell">
git submodule add git://github.com/probonogeek/extjs.git public/extjs
git submodule init
git submodule update
</pre>
<p>Lastly, if there are any extjs.com folks reading this who object to what I&#8217;ve done, please don&#8217;t hesitate to contact me. While the GPL gives me permission to do as I&#8217;ve done, there is a big difference between legal right and community consent. Right now I&#8217;m operating on a sort of tacit consent, but will take the repository down if requested.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.probonogeek.org/2009/04/extjs-git-submodule/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Preparing Your ExtJS Environment</title>
		<link>http://blog.probonogeek.org/2009/04/preparing-your-extjs-environment/</link>
		<comments>http://blog.probonogeek.org/2009/04/preparing-your-extjs-environment/#comments</comments>
		<pubDate>Mon, 06 Apr 2009 03:24:32 +0000</pubDate>
		<dc:creator>probonogeek</dc:creator>
				<category><![CDATA[ExtJS]]></category>

		<guid isPermaLink="false">http://blog.probonogeek.org/?p=406</guid>
		<description><![CDATA[In my last post I said that ExtJS is a front-end widget system. No doubt you could use it to create an entire system, front to back, in nothing by ExtJS, but that&#8217;s not my project nor is what I plan to talk about in these posts. Which brings us to the first question you [...]]]></description>
			<content:encoded><![CDATA[<p>In my last post I said that ExtJS is a front-end widget system. No doubt you could use it to create an entire system, front to back, in nothing by ExtJS, but that&#8217;s not my project nor is what I plan to talk about in these posts. Which brings us to the first question you need to answer when setting up your ExtJS environment: what am I going to use as a back-end? There are probably lots of <i>right</i> answers to this question, and a great deal of debate over which one is <i>more</i> right, and I gleefully leave that fight for others. For my purposes, the answer to that question is <a href="">merb</a> (it&#8217;s like rails, but better), so if that&#8217;s not your platform of choice, you will have to make some adaptations of your own.<span id="more-406"></span></p>
<p>First things first, setup your application by whatever magical incantation is appropriate, in my case:</p>
<pre class="brush: shell">
merb-gen app extjs_demo
</pre>
<p>Now we have a clean application all ready to go. Next you need to bring ExtJS into your codebase so you will have access to it. As ExtJS is 99% javascript, you will want to install in whatever directory your app will use as its document_root so that HTTP requests can get at it. In merb/rails, that directory is called public/. I recommend against using public/javascripts/, even though it&#8217;s <i>right there</i> calling out for javascript files. The way I see it, ExtJS is an external library, while public/javascripts/ is where you put your own application scripts, but reasonable minds can disagree.</p>
<p>Head on over to <a href="http://extjs.com/products/extjs/download.php">extjs.com</a> and grab the latests release (2.2.1 as of this writing). Pay attention here&#8230; you want to unzip the file in its own directory named extjs-2.2.1 (or whatever version you downloaded). If you unzip the file directly into public/, you&#8217;re going to be sorry. Now create a symlink pointing to extjs-2.2.1 called &#8220;extjs&#8221;. </p>
<pre class="brush: shell">
ln -s extjs-2.2.1 extjs
</pre>
<p>This symlinking strategy allows you to easily try out new releases of ExtJS and revert back without having to worry about blowing away old versions until you are ready.</p>
<p>Now you have ExtJS installed and can already do a great deal if you were to startup your empty app <i>right this very second</i> and access http://localhost:4000/extjs/docs/index.html with your trusty browser. Your framework may use a different port number (Rails defaults to 3000). With merb properly installed on my system, I can just startup the app from the merb root directory by running:</p>
<pre class="brush: shell">
bin/merb
</pre>
<p>Your browser should show you the API docs just as if you had accessed them on the <a href="http://www.extjs.com/deploy/dev/docs/">ExtJS website</a>. This is going to be your number one place to learn the finner points of ExtJS, and now you have it with you so long as you have your application&#8217;s source. Handy for those times you don&#8217;t have internet access. If you&#8217;re using source control, now is a good time to commit <img src='http://blog.probonogeek.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Next we face an important choice. As we build our application we are going to define different ExtJS subclasses (more on what that means in a later post). Those subclasses need to be loaded into your application via the familiar <b>script</b> tag. But there are two different ways our application can respond the script tags request:</p>
<ol>
<li>Serve static javascript files from public/</li>
<li>Serve dynamic javascript files from a controller/view setup</li>
</ol>
<p>Static files in public/ have the advantage of loading much faster, as they come directly off the file system and skip over the framework&#8217;s call stack. Dynamic files from a controller/view are dynamic, which allow the javascript to be custom tailored for the user&#8217;s needs. Both have their uses and after a lot of trial and experimentation, I determined the best approach is to use both. Okay, so I lied&#8230; there is no choice.</p>
<p>What we are going to do is define the various subclass methods in public/javascripts/. These files do not need to change on a per-user basis, so we get the benefit of the static load time. But any files that require dynamic generation will be done via a controller and a view. But before we go a step further we need to setup your application&#8217;s index page.</p>
<p>In my estimation, there are two ways to use ExtJS in your application. You can either use it as a widget set for things like buttons, dialog boxes, and grids in the way you might use <a href="http://jqueryui.com/">jQuery UI</a>. Or you can do <i>everything</i> in ExtJS. For the app I&#8217;m building at work, ExtJS powers the entire display of the administrative back-end. The setup I&#8217;ll show you today assumes that you&#8217;re entire app is going to be driven by ExtJS. If you think you&#8217;re going to be less whole-hog, don&#8217;t worry, many of the steps will be the same.</p>
<p>First things first, we need a root index page to work with. By default, I get a lovely <b>No routes match the request: /</b> error message when trying to access http://localhost:4000. There are lots of ways to setup an index page depending on your framework, all of which is beyond the scope of this post. What I did with merb was create a controller called &#8220;home&#8221; and added a route to connect &#8220;/&#8221; with &#8220;home/index&#8221;.</p>
<p>Next we need to get the view for home/index looking how we want. Many MVC frameworks use layouts to reduce code duplication between views &#8212; which is great &#8212; but for us, it&#8217;s actually a real problem. So I recommend you disable layouts for the home controller (in merb you just declare &#8220;layout false&#8221; in the controller file). Now head over to the view for home/index (in merb, it will be at app/views/home/index.html.erb). This file is going to serve as your loading point for all the ExtJS magic you need to make your application sing.</p>
<p>Now, add the following HTML right into the file:</p>
<pre class="brush: html">
&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;
    &quot;http://www.w3.org/TR/html4/loose.dtd&quot;&gt;
&lt;html&gt;
&lt;head&gt;
  &lt;title&gt;Your ExtJS Application&lt;/title&gt;
  &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot;&gt;
  &lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;/extjs/resources/css/ext-all.css&quot;&gt;
&lt;/head&gt;
&lt;body&gt;

  &lt;!-- External Dependencies --&gt;
  &lt;script type=&quot;text/javascript&quot; src=&quot;/extjs/adapter/ext/ext-base.js&quot;&gt;&lt;/script&gt;
  &lt;script type=&quot;text/javascript&quot; src=&quot;/extjs/ext-all-debug.js&quot;&gt;&lt;/script&gt;

  &lt;!-- Application Runner --&gt;
  &lt;script type=&quot;text/javascript&quot; src=&quot;/home/application.js&quot;&gt;&lt;/script&gt;

  &lt;!-- App Specific Classes --&gt;

&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>Let&#8217;s look at the lines that may not seem immediately obvious:</p>
<pre class="brush: html">
&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;/extjs/resources/css/ext-all.css&quot;&gt;
</pre>
<p>Loads the ExtJS master CSS file. This has all sorts of CSS definitions that make all the ExtJS widgets look super delicious.</p>
<pre class="brush: html">
&lt;!-- External Dependencies --&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;/extjs/adapter/ext/ext-base.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;/extjs/ext-all-debug.js&quot;&gt;&lt;/script&gt;
</pre>
<p>These two lines load up the ExtJS library itself into your application. Make sure you load them in the order specified here. Couple of important notes here. The first line is the adapter line, and I&#8217;m told it allows you to teach ExtJS to play nice with other JS frameworks like jQuery and Prototype. I haven&#8217;t played with any of that, so your mileage may vary if you go that direction, here we are using ExtJS with ExtJS. The second line is the monster library include and here you actually have two choices. In development mode, I always load ext-all-debug.js, because Firebug output is far more useful&#8230; but in production, you&#8217;ll want to use ext-all.js, which has been <a href="http://www.crockford.com/javascript/jsmin.html">minified</a> for quicker download to your clients. In a more advanced application, we&#8217;d have the view determine which file to send programatically, but we are going to take it slow.</p>
<pre class="brush: html">
&lt;!-- Application Runner --&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;/home/application.js&quot;&gt;&lt;/script&gt;

&lt;!-- App Specific Classes --&gt;
</pre>
<p>The Application Runner is the starter pistol of your ExtJS application&#8230; the thing which makes it go. We are going to setup a basic one in just a moment. Then under that is where your application specific ExtJS subclasses are going to be loaded. There aren&#8217;t any at present, but we will write one shortly and it&#8217;s good to have a place ready to put them.</p>
<p>For the Application runner you will need to add an application action to the home controller and indicate that it serves up javascript. In Merb:</p>
<pre class="brush: ruby">
  def application
    provides :js
    render
  end
</pre>
<p>Then create a view at app/views/home/application.js.erb and dump in the following:</p>
<pre class="brush: javascript">
Ext.BLANK_IMAGE_URL = &#039;/extjs/resources/images/default/s.gif&#039;;
Ext.ns(&#039;demo&#039;);

// application main entry point
Ext.onReady(function() {

  var viewport = new Ext.Viewport({
    items: [
      {
        region:     &#039;north&#039;,
        html:       &#039;&lt;h1 class=&quot;x-panel-header&quot;&gt;Your Demo Application&lt;/h1&gt;&#039;,
        autoHeight: true,
        border:     false,
        margins:    &#039;0 0 5 0&#039;
      },{
        region:     &#039;center&#039;
      }
    ]
  });
  viewport.show();

});
</pre>
<p>The first two lines of code set some global configuration. The first line there is a request from the fine folks at ExtJS to use your own locally hosted single blank pixel instead of theirs (it&#8217;s the least you can do). The next creates a namespace for the code you are going to be writing. I&#8217;ve chosen the highly descriptive &#8220;demo&#8221; as my namespace here, but I recommend using a short-hand version of your application. The big advantage of using a namespace is now you can define whatever classes you want without bumping into native javascript classes. All of the ExtJS base classes are namedspaced to &#8220;Ext&#8221;, so I recommend using something other than that.</p>
<p>Then comes the starter pistol:</p>
<pre class="brush: javascript">
Ext.onReady(function() {
  // code goes here
});
</pre>
<p>If you are familiar with jQuery, this is equivalent to:</p>
<pre class="brush: javascript">
$(document).ready(function(){
  // code goes here
});
</pre>
<p>What it does is ensure the code inside of the block is not executed until the entire page is done loading. Meaning all of the javascript libraries, CSS files, etc. If you try to execute your application code right away, you can&#8217;t be sure the environment is full prepped. Wrapping your code in the Ext.onReady method gives you the confidence everything is, well, ready.</p>
<p>Then lastly we&#8217;ve got this Ext.Viewport constructor with some configuration parameters passed into the constructor. Don&#8217;t worry about the specifics of the configuration at the moment, we&#8217;ll talk about Viewports in some other post. What&#8217;s important to know is that Viewports setup a full browser window environment to instantiate other components. It is the starting point of any full ExtJS application.</p>
<p>At this point you can save these files, startup your application and go to the index page. You should get a panel at the top that reads &#8220;Your Demo Application&#8221;. Congratulations, you&#8217;ve got an ExtJS application!</p>
<p>One last thing to do before we close down for the day. The Viewport there has application specific configuration variables, and as you will learn in the post on subclassing, that is indicator number one that we should create an ExtJS subclass. To do so, create a file at public/javascripts/demo.viewport.js (note, if you declared a different namespace than &#8220;demo&#8221; use that wherever I use &#8220;demo&#8221; in all of the following examples). In the file you just created, paste the following:</p>
<pre class="brush: javascript">
demo.viewport = function(config) {

  var base_config = {
    items: [
      {
        region:     &#039;north&#039;,
        html:       &#039;&lt;h1 class=&quot;x-panel-header&quot;&gt;Your Demo Application&lt;/h1&gt;&#039;,
        autoHeight: true,
        border:     false,
        margins:    &#039;0 0 5 0&#039;
      },{
        region:     &#039;center&#039;
      }
    ]
  };

  Ext.apply(base_config,config);

  demo.viewport.superclass.constructor.call(this,base_config);

}

Ext.extend(demo.viewport, Ext.Viewport, {});
</pre>
<p>Update your application.js file to read:</p>
<pre class="brush: javascript">
Ext.BLANK_IMAGE_URL = &#039;/extjs/resources/images/default/s.gif&#039;;

Ext.ns(&#039;demo&#039;);

// application main entry point
Ext.onReady(function() {

  var viewport = new demo.viewport()
  viewport.show();

});
</pre>
<p>And under &#8220;App Specific Classes&#8221; in the index.html file, add:</p>
<pre class="brush: html">
&lt;script type=&quot;text/javascript&quot; src=&quot;/javascripts/demo.viewport.js&quot;&gt;&lt;/script&gt;
</pre>
<p>Reload the index page and nothing should change. Except now we&#8217;ve got the static parts of the application being served from public/javascripts/ and the dynamic parts of the application from the home controller. With this basic framework we are ready to start learning about subclasses and how to organize you ExtJS code.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.probonogeek.org/2009/04/preparing-your-extjs-environment/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introducing wp-extjs-loader</title>
		<link>http://blog.probonogeek.org/2009/02/introducing-wp-extjs-loader/</link>
		<comments>http://blog.probonogeek.org/2009/02/introducing-wp-extjs-loader/#comments</comments>
		<pubDate>Sun, 01 Mar 2009 01:23:20 +0000</pubDate>
		<dc:creator>probonogeek</dc:creator>
				<category><![CDATA[ExtJS]]></category>

		<guid isPermaLink="false">http://blog.probonogeek.org/?p=452</guid>
		<description><![CDATA[Today I wrote my first WordPress plugin. Its purpose is to load the ExtJS libraries into a WordPress post whose category has been set to &#8220;ExtJS&#8221;&#8230; just like the post you are reading now. See, ExtJS is a heavy library, and even minimified it clocks in at nearly 600 KBs. I don&#8217;t want to have [...]]]></description>
			<content:encoded><![CDATA[<p>Today I wrote my first WordPress plugin. Its purpose is to load the ExtJS libraries into a WordPress post whose category has been set to &#8220;ExtJS&#8221;&#8230; just like the post you are reading now. See, ExtJS is a heavy library, and even minimified it clocks in at nearly 600 KBs. I don&#8217;t want to have to pay that bandwidth cost if I don&#8217;t have to, nor do my readers who aren&#8217;t the least bit interested in ExtJS. So the plugin takes care of loading only when the post is about ExtJS.<span id="more-452"></span></p>
<p>I honestly can&#8217;t imagine a use for this plugin other than someone who blogs about both ExtJS and non-ExtJS topics. But, if you are interested in the plugin, it is <a href="http://github.com/probonogeek/wp-extjs-loader/">available at github</a>.</p>
<p>A few caveats&#8230; this plugin is still very much <i>in progress</i>. The ExtJS category ID is hard coded into the code. So, unless your ExtJS category ID == 10, as mine does, the code won&#8217;t work. Future releases will allow you to specify which category to load on&#8230; and maybe, down the road, allow you to specify which parts of ExtJS to load, as opposed to the whole suite like it&#8217;s doing right now.</p>
<p>But here&#8217;s the big payoff for all this work. I give you my first embedded ExtJS example:</p>
<p><script type="text/javascript">
  Ext.onReady(function() {
    button = new Ext.Button({
      text:     "Click me, I won't bite",
      renderTo: 'example-button',
      handler:  function(){
        Ext.Msg.alert("Congratulations","You clicked me!");
      }
    });
  });
</script></p>
<div class="extjs" id='example-button'></div>
<p></p>
<p>Now, if you think that was easy, you&#8217;ve got another thing coming&#8230; took me forever to get that to work. Not because of the ExtJS, but because of all the stylesheet interference with my kick-ass WordPress theme. But I think I&#8217;ve got it all sorted out. Here&#8217;s the entirety of the code I used to produce the above.</p>
<pre class="brush: javascript">
  Ext.onReady(function() {
    button = new Ext.Button({
      text:     &quot;Click me, I won&#039;t bite&quot;,
      renderTo: &#039;example-button&#039;,
      handler:  function(){
        Ext.Msg.alert(&quot;Congratulations&quot;,&quot;You clicked me!&quot;);
      }
    });
  });
</pre>
<p>And then I defined a DIV on the page with ID = &#8220;example-button&#8221;. It&#8217;s just that easy. I think all the kinks are finally worked out and we can get into some real learning with the next post.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.probonogeek.org/2009/02/introducing-wp-extjs-loader/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Javascript Foundation</title>
		<link>http://blog.probonogeek.org/2009/02/javascript-foundation/</link>
		<comments>http://blog.probonogeek.org/2009/02/javascript-foundation/#comments</comments>
		<pubDate>Fri, 27 Feb 2009 07:15:57 +0000</pubDate>
		<dc:creator>probonogeek</dc:creator>
				<category><![CDATA[ExtJS]]></category>

		<guid isPermaLink="false">http://blog.probonogeek.org/?p=414</guid>
		<description><![CDATA[To get any use out of ExtJS you need to understand javascript. It&#8217;s inescapable. This is not a framework were you are going to be writing ruby code that generates javascript for you, like you may have experienced with Rails/Prototype. There may, someday, be that sort of integrated support&#8230; but not today, and quite frankly, [...]]]></description>
			<content:encoded><![CDATA[<p>To get any use out of ExtJS you need to understand javascript. It&#8217;s inescapable. This is not a framework were you are going to be writing ruby code that generates javascript for you, like you may have experienced with Rails/Prototype. There may, someday, be that sort of integrated support&#8230; but not today, and quite frankly, it would be an abomination of the framework anyway. If you are an old pro at Javascript, chances are this isn&#8217;t going to be very informative, but if the last great Javascript trick you learned was how to change the browser&#8217;s status bar, you may learn a thing or two.<span id="more-414"></span></p>
<h3>Firebug, the Indispensable Tool</h3>
<p>The first central concept to cover is basic tools. Back in the day, javascript debugging involved peppering your code with alert() calls that would popup little messages&#8230; like print statements in a scripting language, but way more annoying because they would stop the process until you pressed the &#8220;okay&#8221; button. But now there is a <i>better way</i>. The better way is <a href="http://www.getfirebug.com">Firebug</a>. It&#8217;s a Firefox extension that lets you peer into your webpage in ways never before possible. It is absolutely essential to doing ExtJS work, so if you don&#8217;t have it, you need to get it. If there is a similar tool for IE, I haven&#8217;t encountered it, so even if IE is your target browser, use Firefox for development purposes and just be sure to occasionally test in IE for cross-browser issues.</p>
<p>By now I&#8217;m assuming you have Firebug installed. You should have a little bug icon in the bottom right of your browser. If you click on it, a panel will expand showing some Firebug options. You want to <b>enable</b> the Console. Script and Net have their uses too, but for today&#8217;s lesson, we want the Console. Turn it on for this blog&#8230; the page will reload and then you will see four items printed out to the terminal.</p>
<p>The first is a string I sent to the console with the following Javascript code:</p>
<p><script type="text/javascript">
  console.log('Hello Word');
</script></p>
<pre class="brush: javascript">
console.log(&#039;Hello Word&#039;);
</pre>
<p>By calling the log method on the console object I can send pretty much anything I want to the Console you now see below. Turns out you can send nearly anything to the console and Firebug will let you see all sort of internal data. But I&#8217;m getting ahead of myself. Before talking about the remaining items in the FireBug Console, I need to talk about some central features of Javascript.</p>
<p>If you were at all like me, you learned about the basic Javascript native types. Chances are that means you learned the following:</p>
<pre class="brush: javascript">
var n = 5; // is a Number
var s = &#039;Hello&#039;; // is a String
var a = new Array(&#039;red&#039;,&#039;blue&#039;,green&#039;); // is an Array
</pre>
<p>You may have even learned a little more advanced stuff, like:</p>
<pre class="brush: javascript">
var t = new Time(); // is a Time object
var a[&#039;key&#039;] = &#039;value&#039;; // is an associative array
</pre>
<p>And, of course, you learned about functions:</p>
<pre class="brush: javascript">
function do_stuff( argument ){
  // stuff gets done
}
</pre>
<p>That was probably good enough to do all sorts of stuff. But if that&#8217;s where you stopped you never really learned the fundamental attributes of Javascript that make it possible to do all the cool stuff that ExtJS does (to say nothing of JQuery or Prototype). There are two critical parts of your education that need reenforcement.</p>
<h3>Hashes (actually, objects)</h3>
<p>Basic computer science teaches us about arrays and hashes, one is ordered data and the other is keyed data. Each have strength and weaknesses. If all you learned was the above, then you probably came to believe &#8212; as I did &#8212; that Javascript used the Array type for both. Since it was possible to use both integers and strings as Array indexes, it&#8217;s not hard to see why.</p>
<pre class="brush: javascript">
addresses = new Array();
addresses[&#039;alice&#039;] = &#039;123 Fake Street&#039;;
addresses[&#039;bob&#039;] = &#039;1600 Pennsylvania Ave&#039;;
</pre>
<p>Sure looks like a hash to me. And in a way it is a hash, because it&#8217;s keyed data. But in Javascript there is another more powerful way to create a hash. Except, Javascript doesn&#8217;t call it a hash, it is called an object. Behold:</p>
<pre class="brush: javascript">
addresses = {
  alice: &#039;123 Fake Street&#039;,
  bob: &#039;1600 Pennsylvania Ave&#039;
};
</pre>
<p>Looks like awfully familiar syntax, don&#8217;t it? Like, here&#8217;s the same object expressed in Ruby:</p>
<pre class="brush: ruby">
addresses = {
  :alice =&gt; &#039;123 Fake Street&#039;,
  :bob =&gt; &#039;1600 Pennsylvania Ave&#039;
}
</pre>
<p>I honestly couldn&#8217;t tell you why it&#8217;s an object and not a hash, but there it is. The important part is that you can create arbitrarily complex data structures using this syntax in a single assignment. Oh, and for an additional syntactic win, instead of using <b>new Array()</b>, you can just use <b>[]</b>. Which means we can do the following:</p>
<p><script type="text/javascript">
console.log({
  first_name: 'Alice',
  address: {
    street: '123 Fake Street',
    city: 'Springfield',
    zipcode: '12345'
  },
  favorite_colors: ['blue','green']
});
</script></p>
<pre class="brush: javascript">
persona_data = {
  first_name: &#039;Alice&#039;,
  address: {
    street: &#039;123 Fake Street&#039;,
    city: &#039;Springfield&#039;,
    zipcode: &#039;12345&#039;
  },
  favorite_colors: [&#039;blue&#039;,&#039;green&#039;]
};
</pre>
<p>Now that you see how data structures in Javascript can be very sophisticated, let&#8217;s see how you can use the Firebug Console to peer inside. Open up the console again and click on the second row that reads <b> Object first_name=Alice address=Object favorite_colors=[2]</b>. In there you will see the different <i>properties</i> of the personal_data object we created above. You can expand the address property to discover it too is an object with its own properties, or expand the favorite_colors property to inspect an array.</p>
<h3>Functions as Properties</h3>
<p>It turns out that objects, like the ones above, can hold any type of Javascript native type in one of its properties. Arrays, strings, numbers, other objects&#8230; you&#8217;ve seen examples of all of that by now. The final piece of the puzzle then is to see that objects can also store functions. In Javascript, a function is just another piece of data that can be assigned to a variable, like this:</p>
<pre class="brush: javascript">
var my_method = function(){
  // do stuff
}
</pre>
<p>Now I can run around with the my_method variable, assign it to other variables, and even execute it. And here in lies the third and final lesson of the post. Consider an object like the following:</p>
<pre class="brush: javascript">
var refrigerator = {
  contents: [&#039;milk&#039;,&#039;eggs&#039;,&#039;cheese&#039;],
  grab_item: function(){
    return this.contents.pop();
  }
}
</pre>
<p>Here we&#8217;ve got our refrigerator object, it&#8217;s got some stuff in it, and we&#8217;ve got a grab_item method that returns the last item off the contents array. To call that method we have to use just the right syntactic sugar, which means putting parentheses at the end. Consider the following two lines of code:</p>
<pre class="brush: javascript">
  snack1 = refrigerator.grab_item // wrong, snack1 now equals the function
  snack2 = refrigerator.grab_item() // right, snack2 now equals &#039;cheese&#039;
</pre>
<p>See, we have to tell javascript we want to actually execute the function, not just assign the data. Firebug confirms this in lines three and four on the console.</p>
<p><script type="text/javascript">
var refrigerator = {
  contents: ['milk','eggs','cheese'],
  grab_item: function(){
    return this.contents.pop();
  }
}
console.log( refrigerator.grab_item );
console.log( refrigerator.grab_item() );
</script></p>
<p>Okay, with the concepts of objects and methods down, and Firebug installed, we are ready to start diving into ExtJS. Next ExtJS post will have actual ExtJS examples, I promise&#8230; I think I&#8217;ve nearly got all the bugs worked out for demoing live ExtJS code.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.probonogeek.org/2009/02/javascript-foundation/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>What is ExtJS and why do I care?</title>
		<link>http://blog.probonogeek.org/2009/02/what-is-extjs-and-why-do-i-care/</link>
		<comments>http://blog.probonogeek.org/2009/02/what-is-extjs-and-why-do-i-care/#comments</comments>
		<pubDate>Mon, 23 Feb 2009 07:48:10 +0000</pubDate>
		<dc:creator>probonogeek</dc:creator>
				<category><![CDATA[ExtJS]]></category>

		<guid isPermaLink="false">http://blog.probonogeek.org/?p=341</guid>
		<description><![CDATA[If you don&#8217;t build websites, the answer to the second question is you don&#8217;t. There are better things for you to spend your limited internet time learning about&#8230; like, did you know there was a Simple Wikipedia project? I didn&#8217;t until just a few minutes ago.
Okay, now that we are just down to the web [...]]]></description>
			<content:encoded><![CDATA[<p>If you don&#8217;t build websites, the answer to the second question is you <i>don&#8217;t</i>. There are better things for you to spend your limited internet time learning about&#8230; like, did you know there was a <a href="http://simple.wikipedia.org">Simple Wikipedia</a> project? I didn&#8217;t until <a href="http://xkcd.com/547/">just</a> a few minutes ago.</p>
<p>Okay, now that we are just down to the web developers and the wannabe web developers, lets try and get the basics established so that future posts will have a common language we all agree on&#8230; or, at least, that I agree on and that you will be forced to understand to extract anything from my ramblings.<span id="more-341"></span></p>
<p><a href="http://extjs.com/products/extjs/">ExtJS describes itself</a> as a &#8220;Ext JS is a cross-browser JavaScript library for building rich internet applications.&#8221; Which is as good a description as any, if not a tad simplistic. I think a more complete description would be, &#8220;Ext JS is a GUI framework for building rich internet applications available under either a commercial or open source license.&#8221; The emphasis here is that ExtJS:</p>
<ol>
<li>allows for the quick deployment of reusable GUI components</li>
<li>is used to build front ends</li>
<li>contains a mixture of javascript, CSS, and binary assets</li>
<li>has a dual license model</li>
</ol>
<p>Let&#8217;s break those points down to understand what I&#8217;m driving at.</p>
<h3>Allows for the quick deployment of reusable GUI components</h3>
<p>Let&#8217;s talk about the sexy stuff first. ExtJS provides a whole ton of Graphical User Interface (GUI) components that you would expect to see in a modern Desktop Environment, but generally don&#8217;t see on the web. There is an outstanding <a href="http://extjs.com/deploy/dev/examples/samples.html">ExtJS Example</a> page that shows off most of what the framework can do.</p>
<p>Here&#8217;s a quick and dirty list of the various components:</p>
<ul>
<li>grids (like in a spreadsheet)</li>
<li>tabs</li>
<li>modal windows</li>
<li>trees</li>
<li>enhanced form elements</li>
<li>toolbars</li>
<li>menus</li>
<li>buttons</li>
<li>sliders</li>
<li>tooltips</li>
<li>progress bars</li>
</ul>
<p>Sadly, I haven&#8217;t come up with a good way to demo any of these bits of code in WordPress yet (all JS code is sanitized by default to protect against <a href="http://en.wikipedia.org/wiki/Cross-site_scripting">evil</a>), but it&#8217;s something I very much plan to work out. In the mean time, let me show you how easy it would be to create an attractive looking button.</p>
<pre class="brush: javascript">
  buttonObj = new Ext.Button({
    text:&#039;Press Me&#039;,
    renderTo: &#039;button&#039;
    handler: function(){
      // button action goes here
    },
  })
</pre>
<p>Then, all we would need is an HTML DIV element with an ID set to &#8220;button&#8221; and we&#8217;d be done. Once the Javascript had executed it would render the button inside of the designated DIV complete with the handler functionality all ready to go. If all of that is Greek to you, don&#8217;t worry, I&#8217;m going to explain some of the Javascript basics in a future post.</p>
<h3>Is used to build front ends</h3>
<p>ExtJS&#8217;s primary function is to generate HTML for display via a web browser and to attach behaviors to those HTML elements that the user can interact with. This aspect is more important for what it isn&#8217;t, than what it is. What ExtJS shouldn&#8217;t be used for is application logic. That&#8217;s not to say it <i>cannot</i> be used for application logic, just that down that way is madness, so try to avoid it. Here&#8217;s some good reasons to keep application logic out of ExtJS.</p>
<ul>
<li>ExtJS talks to your webserver via AJAX, which means you will need backend scripts of some kind to process those requests. As those scripts are closer to the database that will back your application, it is those scripts that serve as the more appropriate vessel for your application logic.</li>
<li>ExtJS uses Javascript for anything functional, which means you would end up writing your application logic in Javascript. Not to dis on Javascript as a language, but most of us don&#8217;t have the experience with Javascript to write clean and maintainable application code.</li>
<li>ExtJS is more like the View part of an MCV application, and the MCV paradigm does not take kindly to embedding logic into the View. For example, if you put application logic into the view <b>and</b> have two views on the same data, you would need two implementations of the same logic. Talk about code duplication nightmares.</li>
</ul>
<p>If you are really dead set on making a pure ExtJS application, I wish you all the luck in the world, but I don&#8217;t think you&#8217;re going to find many of my posts very helpful. Consider yourself warned.</p>
<h3>Contains a mixture of javascript, CSS, and binary assets</h3>
<p>Here&#8217;s where I disagree most strongly with the official ExtJS definition. Yes, ExtJS is a &#8220;Javascript library,&#8221; but it&#8217;s so much more than that. In addition to the javascript files that comprise the core of ExtJS, there is a full 2.3 MBs of CSS and image resource files that go along with it. For the most basic uses of ExtJS, you may never look in the resources directory. But as you begin to understand the deeper relationships in the library, you will begin to see how fundamentally important those CSS definitions are, and how tweaking a few images can give you a wide range of flexibility.</p>
<h3>Has a dual license model</h3>
<p>If ExtJS were to ever be considered controversial, it would be because of this final point. I didn&#8217;t come to ExtJS until late 2008, at which point the library had been around for a while. The story goes that ExtJS used to be available under a more permissive open source license, such that commercial developers could use the code without buying a commercial license. At some point in ExtJS&#8217;s product development, the <a href="http://extjs.com/company/dual.php">company decided to change</a> the open source license to the strictest of all licenses, the <a href="http://www.opensource.org/licenses/gpl-3.0.html">GNU General Public License</a>. This engendered quite a bit of bad blood among those commercial developers, who felt like they were tricked into adopting a library and now either had to cough up the dough for a commercial license, GPL their own works, or start all over again.</p>
<p>My opinion is what it generally is involving the GPL&#8230; sounds good to me! If a commercial developer wants to benefit from the work, then they are free to pay for future development by buying a license or they can contribute back to the community. The value of a third option is marginal at best, and more likely to induce free-riding than stimulate community.</p>
<p>My company has the good fortune of being able to buy a commercial license outright, so we do all of our development in a closed source environment, so I won&#8217;t be showing any examples from that project. What you will see in these posts is using my own personal copy of ExtJS which I have under the terms of the GPL. Which, by my reckoning, makes any example code I throw up here also available under the terms of the GPL. Of course, a lot of the code will be more functional than expressive, in which case you don&#8217;t really need to worry about licenses&#8230; just use this to study and build your own.</p>
<p>I think that should do it for our introductory post (clocking in at 1133 words already!). Next time I&#8217;ll discuss some basic javascript concepts and then get into some of the GUI elements.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.probonogeek.org/2009/02/what-is-extjs-and-why-do-i-care/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Talking about ExtJS</title>
		<link>http://blog.probonogeek.org/2009/02/talking-about-extjs/</link>
		<comments>http://blog.probonogeek.org/2009/02/talking-about-extjs/#comments</comments>
		<pubDate>Sun, 22 Feb 2009 22:44:08 +0000</pubDate>
		<dc:creator>probonogeek</dc:creator>
				<category><![CDATA[ExtJS]]></category>

		<guid isPermaLink="false">http://blog.probonogeek.org/?p=327</guid>
		<description><![CDATA[In November of 2008 I traveled to frigid Chicago to attend the inaugural sprint of my company&#8217;s new content management system. It was a week long affair where we started the work of building a multi-client Merb based CMS to replace the old work horse of the company, a proprietary Zope product known as ListMonster. [...]]]></description>
			<content:encoded><![CDATA[<p>In November of 2008 I traveled to frigid Chicago to attend the inaugural sprint of my company&#8217;s new <a href='http://en.wikipedia.org/wiki/Content_management_system'>content management system</a>. It was a week long affair where we started the work of building a multi-client <a href="http://en.wikipedia.org/wiki/Merb">Merb</a> based CMS to replace the old work horse of the company, a proprietary <a href="http://en.wikipedia.org/wiki/Zope">Zope</a> product known as ListMonster. ListMonster had served us well for many years, but its age was beginning to show and we knew the time had come for a serious upgrade. David, as a major proponent of all things Ruby, wanted to us to either develop in Rails or a new fangled <a href="http://en.wikipedia.org/wiki/Model_View_Controller">MCV</a> system known as Merb. In the end I&#8217;m not convinced that particular decision was really all that big of a deal, as <a href="http://en.wikipedia.org/wiki/Ruby_on_Rails">Rails</a> and Merb as so similar that Rails 3.0 <i>will be</i> Merb 2.0, and Merb 2.0 <i>will be</i> Rails 3.0. But the Merb decision wasn&#8217;t the only big decision made that week, we also agreed to use <a href="http://extjs.com/">ExtJS</a> for all front end development.<span id="more-327"></span></p>
<p>Since November, I have taken the lead in our company to build the front-end of the new CMS (which is called the Articulated Man Publishing System, or AMPS for short). The process has been both frustrating and rewarding, but now that I&#8217;m at the tail end of the learning curve, I find it to be 100x more rewarding than frustrating and can&#8217;t imagine building AMPS in anything else.</p>
<p>But the months between the final decision and feeling like I finally <i>get it</i> have been long and lonely. While there is excellent <a href="http://extjs.com/deploy/dev/docs/">primary documentation</a> on ExtJS, there is very little secondary documentation, like blog posts on how to do X, or discussions on the merits of different approaches to Y. Other than the <a href="http://extjs.com/forum/">sprawling and disorganized forums</a>, ExtJS sort of just expects you to figure it out on your own.</p>
<p>Starting today, I&#8217;m going to do my part to remedy that situation. I have created a new subcategory under <a href="http://blog.probonogeek.org/category/technology/">Technology</a> called &#8212; unsurprisingly &#8212; <a href="http://blog.probonogeek.org/category/technology/extjs/">ExtJS</a>, and this is the category&#8217;s maiden post. My goal here is to build up a set of posts that explain what I consider to be <a href="http://en.wiktionary.org/wiki/idiomatic">idiomatic</a> ExtJS, in particular the intersection between <a href="http://en.wikipedia.org/wiki/Model-view-controller">MVC applications</a> and ExtJS. With any luck, someone venturing out on a project similar to mine will find this information useful, but if nothing else, it will help me clarify my own thinking on how best to solve problems with ExtJS.</p>
<p>Be on the lookout for my first post, probably tonight, where I explain in the most general terms what ExtJS is so that everyone can play along at home. But, if you can&#8217;t wait, you can always take a gander at the <a href="http://extjs.com/deploy/dev/examples/samples.html">example pages</a> and learn for yourself.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.probonogeek.org/2009/02/talking-about-extjs/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
