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

<channel>
	<title>Saki's Blog &#187; application</title>
	<atom:link href="http://blog.extjs.eu/tag/application/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.extjs.eu</link>
	<description>For good of all productive developers</description>
	<lastBuildDate>Sun, 21 Nov 2010 01:36:03 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Writing a Big Application in Ext (Part 2)</title>
		<link>http://blog.extjs.eu/know-how/writing-a-big-application-in-ext-part-2/</link>
		<comments>http://blog.extjs.eu/know-how/writing-a-big-application-in-ext-part-2/#comments</comments>
		<pubDate>Mon, 02 Feb 2009 12:12:55 +0000</pubDate>
		<dc:creator>Saki</dc:creator>
				<category><![CDATA[Know-how]]></category>
		<category><![CDATA[application]]></category>
		<category><![CDATA[extjs]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://blog.extjs.eu/?p=137</guid>
		<description><![CDATA[<br/>Important
If you have not already done so, study Writing a Big Application in Ext (Part 1) before you read this article. It would be very hard, if not impossible, to understand concepts explained here before you fully understand the first part.
Introduction

It has been almost one year since I have published the first part of this [...]]]></description>
			<content:encoded><![CDATA[<br/><h2 style="margin-top:30px"><em>Important</em></h2>
<p>If you have not already done so, study <a href="http://blog.extjs.eu/know-how/writing-a-big-application-in-ext/" style="font-size:125%;">Writing a Big Application in Ext (Part 1)</a> before you read this article. It would be very hard, if not impossible, to understand concepts explained here before you fully understand the first part.</p>
<h1>Introduction</h1>
<p>
It has been almost one year since I have published the first part of this article. I have been successfully using the concept of pre-configured classes personally to write a really big application (~150 javascript files, ~60,000 lines of code, plus server-side and css). The application is fully modularized, each class in separate file and it has proven that it can be easily developed, managed and debugged.
</p>
<p>
Unfortunately, the same <em>has not been always</em> true for other users, they were hitting various problems and Ext Support Team have had to handle may questions and help requests. These accumulated to the degree where the concept has been called <em>&#8220;absolute abomination&#8221;</em> (read absolutely hated) and it was stated that <em>&#8220;it causes problems&#8221;</em>.
</p>
<p><em>Note: As &#8220;fast cars&#8221; do not cause accidents but &#8220;slow drivers driving fast cars&#8221; do, the concept itself cannot be a cause of the problems but its application can.</em>
</p>
<p>
In any case, there must be some illogic if I can use the concept but others cannot.
</p>
<p>Thus, I have looked deeper in it and I have isolated some pitfalls the users can run into on the course of development. I will also write on &#8220;dos&#8221; and &#8220;don&#8217;ts&#8221; and on when to use a pre-configured class and when not. I will <em>not</em> compare this concept to another application design concepts (factory functions, in-line configuration, on-demand load, or other) because 1) I do not use them and 2) I do not want to turn this article into a Linux versus Windows discussion.
</p>
<p>
It is fully up to you which application design concept you choose. However, if you do choose this one then follow the rules I&#8217;m going to lay down.</p>
<h1>Most Common Sources of Troubles</h1>
<ul>
<li>Dull Copy&amp;Paste</li>
<li>Extending a non-Ext.Component class</li>
<li>Not calling parent methods</li>
<li>initialConfig</li>
<li>listeners</li>
</ul>
<h2 style="margin-top:30px">Dull Copy&amp;Paste</h2>
<p>Do you know such people? They post on a forum:</p>
<blockquote><p>I need to drag from tree to qrid, gimme plz complete codez</p></blockquote>
<p>And if somebody altruistic writes a fragment of &#8220;codez&#8221; for him in a sheer attempt to help the response is going to be:
</p>
<blockquote><p>Your codez don&#8217;t work. Help me plz my manager wants it working</p></blockquote>
<p>
Do you see what happened? A dull &#8220;developer&#8221; <i>ordered</i> a code on the forum, he&#8217;s got some, copied&amp;pasted it to his application without a clue what the code does, maybe hasn&#8217;t even changed url that still points to your server and the result is: <em>it doesn&#8217;t work</em>.
</p>
<p>
Well, this is an extreme (but not so rare as you would think), nevertheless, copying&amp;pasting without understanding of what the copied&amp;pasted code does can lead only to frustrations.
</p>
<p>
I am not against Copy&amp;Paste in general, it can save a lot of time and I also occasionally do it, but <strong>I am against not-understanding or mis-understanding</strong> not only of coding but also of life.
</p>
<p><em>The Rule:</em> <strong>Do Copy&amp;Paste but always with full understanding of what the code does.</strong></p>
<h2 style="margin-top:30px">Extending a non-Ext.Component class</h2>
<p>If an Ext class does not inherit from Ext.Component the <code>initComponent</code> is never called so the code you have written there is never executed. This is fragment from Ext.Component constructor:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">getId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    Ext.<span style="color: #660066;">ComponentMgr</span>.<span style="color: #660066;">register</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    Ext.<span style="color: #660066;">Component</span>.<span style="color: #660066;">superclass</span>.<span style="color: #660066;">constructor</span>.<span style="color: #660066;">call</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">baseAction</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">baseAction</span>.<span style="color: #660066;">addComponent</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">initComponent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>
Ext classes that do not inherit from Ext.Component do not have <code>this.initComponent();</code> line in their constructors.
</p>
<p><em>The Rule:</em> <strong>Always check if the Ext class you are going to pre-configure inherits from Ext.Component. You have to use an another approach if it does not.</strong>
</p>
<h2 style="margin-top:30px">Not calling parent methods</h2>
<p>
It happens very often that you do not only <em>add</em> some methods in your extended class but that you <em>modify</em> existing ones. <code>initComponent</code> being the first example. <code>onRender</code>, <code>afterLayout</code> are other (but not only) frequently overriden methods.
</p>
<p>
These methods <em>are already implemented</em> in the class you are extending and its parents so if you forget the line:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// in initComponent override</span>
YourExtension.<span style="color: #660066;">superclass</span>.<span style="color: #660066;">initComponent</span>.<span style="color: #660066;">apply</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> arguments<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// or in onRender override</span>
YourExtension.<span style="color: #660066;">superclass</span>.<span style="color: #660066;">onRender</span>.<span style="color: #660066;">apply</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> arguments<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// or in afterLayout override</span>
YourExtension.<span style="color: #660066;">superclass</span>.<span style="color: #660066;">afterLayout</span>.<span style="color: #660066;">apply</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> arguments<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>your class <em>will not work</em>.
</p>
<p><em>The Rule:</em> <strong>Never forget to call the parent method, unless you exactly know what you are doing.</strong>
</p>
<h2 style="margin-top:30px">initialConfig</h2>
<p>The constructor of Ext.Component saves the config passed to it as <code>initialConfig</code>:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">    <span style="color: #006600; font-style: italic;">/**
     * This Component's initial configuration specification. Read-only.
     * @type Object
     * @property initialConfig
     */</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">initialConfig</span> <span style="color: #339933;">=</span> config<span style="color: #339933;">;</span>
&nbsp;
    Ext.<span style="color: #660066;">apply</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> config<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">addEvents</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/* abbreviated for clarity */</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">getId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    Ext.<span style="color: #660066;">ComponentMgr</span>.<span style="color: #660066;">register</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    Ext.<span style="color: #660066;">Component</span>.<span style="color: #660066;">superclass</span>.<span style="color: #660066;">constructor</span>.<span style="color: #660066;">call</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">baseAction</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">baseAction</span>.<span style="color: #660066;">addComponent</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">initComponent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>You see what happens? The constructor saves <code>initialConfig</code> <strong>before</strong> <code>initComponent</code> is executed. Thus, all configuration you write in <code>initComponent</code> is not saved. I have overlooked this in first versions of my templates and examples mainly because there is only a couple of classes that refer to initialConfig and even in these classes the absence of properly saved <code>initialConfig</code> causes problems very rarely. These Ext classes refer to <code>initialConfig</code>:
</p>
<ul>
<li>AnchorLayout</li>
<li>BorderLayout</li>
<li>Action</li>
<li>GridPanel</li>
<li>Tip</li>
<li>Combo</li>
<li>Form</li>
</ul>
<p>Now, I have updated all my examples, extensions, templates and main site to include this &#8220;magic&#8221; pattern:
</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// create config</span>
<span style="color: #003366; font-weight: bold;">var</span> config <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// put your config here</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// eo config object</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// apply config</span>
Ext.<span style="color: #660066;">apply</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> Ext.<span style="color: #660066;">apply</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">initialConfig</span><span style="color: #339933;">,</span> config<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// call parent</span>
YourExtension.<span style="color: #660066;">superclass</span>.<span style="color: #660066;">initComponent</span>.<span style="color: #660066;">apply</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> arguments<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><em>The Rule:</em> <strong>Ensure that your extension saves <code>initialConfig</code>.</strong>
</p>
<h2 style="margin-top:30px">listeners</h2>
<p>
If you try to install event handlers by setting property <code>listeners</code> in your <code>config</code> they will not work. Why? The answer lies again in the order of actions in Ext.Component constructor:
</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">    Ext.<span style="color: #660066;">Component</span>.<span style="color: #660066;">superclass</span>.<span style="color: #660066;">constructor</span>.<span style="color: #660066;">call</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">baseAction</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">baseAction</span>.<span style="color: #660066;">addComponent</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">initComponent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>
As you can see, the constructor calls its parent, that is <code>Ext.util.Observable</code> <strong>before</strong> <code>initComponent</code>. <code>Ext.util.Observable</code> constructor executes:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">Ext.<span style="color: #660066;">util</span>.<span style="color: #660066;">Observable</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">listeners</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">on</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">listeners</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">delete</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">listeners</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Any listeners set in <code>initComponent</code> are thus ignored.</p>
<p>There is an easy workaround. Put <code>constructor</code> method in your extension:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">&nbsp;
 constructor<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>config<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// parent constructor call pre-processing - configure listeners here</span>
    config <span style="color: #339933;">=</span> config <span style="color: #339933;">||</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
    config.<span style="color: #660066;">listeners</span> <span style="color: #339933;">=</span> config.<span style="color: #660066;">listeners</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
    Ext.<span style="color: #660066;">applyIf</span><span style="color: #009900;">&#40;</span>config.<span style="color: #660066;">listeners</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #006600; font-style: italic;">// add listeners config here</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// call parent constructor</span>
    AnExtension.<span style="color: #660066;">superclass</span>.<span style="color: #660066;">constructor</span>.<span style="color: #660066;">call</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> config<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// parent constructor call post-processing</span>
&nbsp;
<span style="color: #009900;">&#125;</span> <span style="color: #006600; font-style: italic;">// eo function constructor</span></pre></td></tr></table></div>

<p>and define your listeners therein.</p>
<p><em>The Rule:</em> <strong>Define listeners in <code>constructor</code> method.</strong></p>
<h1>Conclusion</h1>
<p>If you decide to use my way of writing a big application then follow these rules:</p>
<ol>
<li>Do Copy&amp;Paste but always with full understanding of what the code does.</li>
<li>Always check if the Ext class you are going to pre-configure inherits from Ext.Component. You have to use an another approach if it does not.</li>
<li>Never forget to call the parent method, unless you exactly know what you are doing.</li>
<li>Ensure that your extension saves <code>initialConfig</code>.</li>
<li>Define listeners in <code>constructor</code> method.</li>
</ol>
<p>
Happy extending!
</p>
<p><strong><em>Do not forget to read <a href="http://blog.extjs.eu/know-how/writing-a-big-application-in-ext/">Part 1</a> and <a href="http://blog.extjs.eu/know-how/writing-a-big-application-in-ext-part-3/">Part 3</a> of this article. </em></strong><br />
<form action="https://www.paypal.com/cgi-bin/webscr" method="post"><div class="paypal-donations"><input type="hidden" name="cmd" value="_donations" /><input type="hidden" name="business" value="js02@aariadne.com" /><input type="hidden" name="item_number" value="Blog Donation" /><input type="hidden" name="currency_code" value="EUR" /><input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-butcc-donate.gif" name="submit" alt="PayPal - The safer, easier way to pay online." /><img alt="" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1" /></div></form></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.extjs.eu/know-how/writing-a-big-application-in-ext-part-2/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>How to switch between Production and Development system</title>
		<link>http://blog.extjs.eu/know-how/how-to-switch-between-production-and-development-system/</link>
		<comments>http://blog.extjs.eu/know-how/how-to-switch-between-production-and-development-system/#comments</comments>
		<pubDate>Tue, 15 Apr 2008 00:58:45 +0000</pubDate>
		<dc:creator>Saki</dc:creator>
				<category><![CDATA[Know-how]]></category>
		<category><![CDATA[application]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.extjs.eu/?p=29</guid>
		<description><![CDATA[<br/>Preface
This article it the follow up of the Writing a Big Application in Ext post and it assumes that your application is written, at least to some degree, that way. It also assumes that the server side language is PHP 5.x, other users can take the idea and write the server side logic in their [...]]]></description>
			<content:encoded><![CDATA[<br/><h1>Preface</h1>
<p>This article it the follow up of the <a title="Permanent Link: Writing a Big Application in Ext" rel="bookmark" href="http://blog.extjs.eu/know-how/writing-a-big-application-in-ext" target="_blank">Writing a Big Application in Ext</a> post and it assumes that your application is written, at least to some degree, that way. It also assumes that the server side language is <a href="http://php.net" target="_blank">PHP 5.x</a>, other users can take the idea and write the server side logic in their languages. It is written on and for <a href="http://opensuse.org" target="_blank">Linux</a> environment, again, users of other systems must accommodate it to their environments.</p>
<h1>What&#8217;s the difference anyway?</h1>
<p>On a <em>development</em> system we want fast cycle of edit-file/run-application. Also, we want to have access to human readable, fully commented files into which we can step with <a href="http://getfirebug.com" target="_blank">Firebug</a> debugger to see what is happening when code runs. If your application consists of 100 javascript files we want them all individually included in page head to be able to quickly edit/reload page/see the result.</p>
<p>On a <em>production</em> system we want fastest load possible, no debugging, and possibly to prevent unauthorized users or attackers to read our files. No comments are needed in files.</p>
<h1>The Files</h1>
<p>We have our source javascript files but we need a bit more. First of all we need a file list that would define which files and in which order we will include. This file list will be used by both switch logic and Makefile that will create the compressed version of sources. An example of such file list can be:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">FILES</span>=\
    Ext.ux.grid.Search.js \
    Ext.ux.IconMenu.js \
    Ext.ux.IconCombo.js \
    Ext.ux.ThemeCombo.js \
    Ext.ux.LangSelectCombo.js \
    Ext.ux.grid.RowActions.js \
    Ext.ux.grid.CellActions.js \
    Ext.ux.tree.ArrayTree.js \
    Ext.ux.FileUploader.js \
    Ext.ux.UploadPanel.js \
    Ext.ux.FileTreeMenu.js \
    Ext.ux.FileTreePanel.js</pre></div></div>

<p>Next, we need <code><strong>Makefile</strong></code> (file with rules for <code><strong>make</strong></code> program):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">include filelist
&nbsp;
application-all.js: application-all-debug.js
    java <span style="color: #660033;">-jar</span> ~<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>yuicompressor.jar \
        application-all-debug.js <span style="color: #000000; font-weight: bold;">&gt;</span> application-all.js
&nbsp;
application-all-debug.js: $<span style="color: #7a0874; font-weight: bold;">&#40;</span>FILES<span style="color: #7a0874; font-weight: bold;">&#41;</span>
    <span style="color: #c20cb9; font-weight: bold;">cat</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span>FILES<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">&gt;</span> application-all-debug.js
&nbsp;
clean:
    <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-f</span> application-all-debug.js application-all.js
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">install</span>: application-all.js
    <span style="color: #666666; font-style: italic;"># whatever you need to do to upload </span>
    <span style="color: #666666; font-style: italic;"># new version to production server</span></pre></div></div>

<p>You can download yuicompressor <a href="http://developer.yahoo.com/yui/compressor">here</a> and you may need to install some &#8220;devel tools&#8221; and java on your Linux box for the above to run.</p>
<h1>The Switch</h1>
<p>We need a server-side logic that would generate the includes for individual files on the development system and one-file include on productions system. Decision what system it is running on can be also automatic. For example, our public, production web server has name <code><strong>extjs.eu</strong></code> and our development system has name <strong><code>extjs.localhost</code></strong>.</p>
<p>We can easily check if <strong><code>"extjs.localhost" === $_SERVER["SERVER_NAME"]</code></strong> and if yes we can run development branch if not we run production branch.</p>
<h1>The Development Cycle</h1>
<p>With all this in place, if you add a file you just add it to the file list, test it and debug it on the development system and if everything is works you issue the command:</p>

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

<p>The compressed version is created and it is uploaded to your production system. The same is true for editing of a file, you only won&#8217;t modify your file list. If you delete file, just remove its line from file list and <strong><code>make install</code></strong>.</p>
<h1>Conclusion</h1>
<p>Hopefully this can make your developer&#8217;s life easier; I couldn&#8217;t live without it.</p>
<p>The complete working example of the above system is <a href="http://examples.extjs.eu?ex=prodswitch" target="_blank">here</a>, with manual switch for demonstration purposes.</p>
<p>Enjoy!<br />
<form action="https://www.paypal.com/cgi-bin/webscr" method="post"><div class="paypal-donations"><input type="hidden" name="cmd" value="_donations" /><input type="hidden" name="business" value="js02@aariadne.com" /><input type="hidden" name="item_number" value="Blog Donation" /><input type="hidden" name="currency_code" value="EUR" /><input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-butcc-donate.gif" name="submit" alt="PayPal - The safer, easier way to pay online." /><img alt="" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1" /></div></form></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.extjs.eu/know-how/how-to-switch-between-production-and-development-system/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Writing a Big Application in Ext (Part 1)</title>
		<link>http://blog.extjs.eu/know-how/writing-a-big-application-in-ext/</link>
		<comments>http://blog.extjs.eu/know-how/writing-a-big-application-in-ext/#comments</comments>
		<pubDate>Sat, 12 Apr 2008 21:20:40 +0000</pubDate>
		<dc:creator>Saki</dc:creator>
				<category><![CDATA[Know-how]]></category>
		<category><![CDATA[application]]></category>
		<category><![CDATA[extjs]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://blog.extjs.eu/?p=28</guid>
		<description><![CDATA[<br/>Preface
I have decided to write this article for those users of Ext 2.x that have already grown up from having one HTML page with embedded script that creates one simple window or form, for those who are already decided that Ext is the way and for those who are fighting with too long files hardly [...]]]></description>
			<content:encoded><![CDATA[<br/><h1>Preface</h1>
<p>I have decided to write this article for those users of Ext 2.x that have already grown up from having one HTML page with embedded script that creates one simple window or form, for those who are already decided that Ext is <em>the</em> way and for those who are fighting with too long files hardly to search in and feeling that their applications need a structure.</p>
<p>The number of approaches to a problem and number of solutions of it is equal to number of people that tackle it. The way I am going to describe in the following text in not <em>the only one</em> and do not want to say that either an application is going to be written <em>my way</em> or it is not good. Nothing like that.</p>
<p>What I <em>do</em> want to say is that this approach is workable, neatly structured, easily maintable, simply stated: <em>It works!</em></p>
<p>&nbsp;</p>
<h1>What is &#8220;A Big Application&#8221;?</h1>
<p>If you have a Viewport with BorderLayout, a grid and a form all in one file it certainly <em>is not</em> the big application, right?. If you have tens of windows each with a grid, form or border layout in it in tens of files it certainly <em>is</em> the bit application, right?</p>
<p>(Germans have very nice word: <em>Jein</em> which is combination of Ja = Yes and Nein = No.)</p>
<p>The answer to both above statement is <em>Jein</em>. When the application becomes big, then? The answer is simple: It becomes big when <em>you</em> feel it is big. It is the point when you start to have troubles to orient yourself in number of files or in you have troubles to find a specific place in one file, when you cease to understand relations of components, etc. I am writing <em>you</em> here but imagine when a 2-3 grades less experienced programmer starts to have this feelings.</p>
<p>We can safely state that <em>each</em> application is big as also a small application deserves to be well written and it may likely become <em>really</em> big as we start to add new features, write new lines of code, new CSS rules, etc.</p>
<p><strong>The best and the safest state of the mind at the start of a new application is: I&#8217;m starting the <em>big</em> application!</strong></p>
<p>&nbsp;</p>
<h1>Files and Directories</h1>
<p>These we need to organize first. There is always a ServerRoot directory configured in Apache or another HTTP server so all subdirectories I&#8217;ll describe later are relative to it.</p>
<p>Recommended directory structure:<br />
<code><br />
./css (optionally link)<br />
./ext (link)<br />
./img (link)<br />
./js<br />
index.html<br />
</code></p>
<p>Link in the above structure means a soft link pointing to a real directory where files are stored. The advantage is that you, for example, download new Ext version to a real directory then you change the link above to point there and without changing a line in your application you can test if everything works also with this new version. If yes, keep it as it is, if no, you just change the link back.</p>
<ul>
<li><strong>css</strong> will hold all your stylesheets. If you have global stylesheets with company colors or fonts you can create css directory as link too.</li>
<li><strong>ext</strong> link you your Ext JS Library tree as described above</li>
<li><strong>img</strong> link to your images. It can contain <em>icons</em> subdirectory as well.</li>
<li><strong>js</strong> will hold all javascript files the Application is composed of.</li>
<li><strong>index.html</strong> HTML file that is an entry point of your application. You can name it as you want and you may need some more files for example for a login process. Anyway, there is <em>one</em> application entry point/file.</li>
<li><strong>optionally</strong> you can create a directory or a link for your server side part of the application (I have <code>./classes</code>). You can name it as you wish but consistently for all applications you write (<code>./server, ./php</code> are some good examples)</li>
</ul>
<p>&nbsp;</p>
<h2>index.html</h2>
<p>Minimal index.html file content is:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">html</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">meta</span> <span style="color: #000066;">http-equiv</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Content-Type&quot;</span> <span style="color: #000066;">content</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/html; charset=utf-8&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">link</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;./ext/resources/css/ext-all.css&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">link</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;./css/application.css&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;./ext/adapter/ext/ext-base.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;./ext/ext-all-debug.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;./application.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">title</span>&gt;</span>A Big Application<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">title</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></pre></div></div>

<p>Although you can do with the above file I would recommend to add a descriptive header to not only this file but to all files you create. Also an &#8220;End of file&#8221; marker has its value. See <a href="http://blog.extjs.eu/category/patterns/file-patters" target="_blank">File Patterns</a> for example of such headers.</p>
<p>&nbsp;</p>
<h2>application.js</h2>
<p>We need a file where the onReady function will be placed; let&#8217;s call it application.js. Minimum content is:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// vim: sw=4:ts=4:nu:nospell:fdc=4</span>
<span style="color: #006600; font-style: italic;">/**
* An Application
*
* @author    Ing. Jozef Sakáloš
* @copyright (c) 2008, by Ing. Jozef Sakáloš
* @date      2. April 2008
* @version   $Id$
*
* @license application.js is licensed under the terms of the Open Source
* LGPL 3.0 license. Commercial use is permitted to the extent that the
* code/component(s) do NOT become part of another Open Source or Commercially
* licensed development library or toolkit without explicit permission.
*
* License details: http://www.gnu.org/licenses/lgpl.html
*/</span>
&nbsp;
<span style="color: #009966; font-style: italic;">/*global Ext, Application */</span>
&nbsp;
Ext.<span style="color: #660066;">BLANK_IMAGE_URL</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'./ext/resources/images/default/s.gif'</span><span style="color: #339933;">;</span>
Ext.<span style="color: #660066;">ns</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Application'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// application main entry point</span>
Ext.<span style="color: #660066;">onReady</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    Ext.<span style="color: #660066;">QuickTips</span>.<span style="color: #660066;">init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// code here</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// eo function onReady</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// eof</span></pre></div></div>

<p>Your header and footer may vary but sure you need to set <code><strong>Ext.BLANK_IMAGE_URL</strong></code> to point to your server. This is path to 1&#215;1px transparent image file that is used by Ext as an image placeholder and if it points to an invalid location you can get various rendering problems such as missing combo trigger images, missing icons or similar.</p>
<p>You may also need to create a new global object variable for your application (here it is <code><strong>Application</strong></code>).</p>
<p>What you need for sure is <code><strong>Ext.onReady</strong></code> that is the main application entry point &#8211; the place where you write your application.</p>
<p>&nbsp;</p>
<h2>css/application.css</h2>
<p>You will put your css stylesheet to this file, if any. If you need only a couple of rules it may seem as unnecessary to create a separate file for them and it looks like the better idea to put them to &lt;style&gt; tags in the page head.</p>
<p>The reverse is true, remember you&#8217;re writing a <em>big</em> application, so everything has to have its place. If you put styles in the page head sooner or later you will solve some rendering problems and you won&#8217;t know where the styles are.</p>
<p>&nbsp;</p>
<h1>The wrong way</h1>
<p>What normally follows when we have all basics in as we have at this point? Let&#8217;s begin writing. So we sit down and we start to write:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> vp <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">Viewport</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
layout<span style="color: #339933;">:</span><span style="color: #3366CC;">'border'</span>
    <span style="color: #339933;">,</span>items<span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span>
        <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">grid</span>.<span style="color: #660066;">GridPanel</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
            store<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">data</span>.<span style="color: #660066;">Store</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
                proxy<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">data</span>.<span style="color: #660066;">HttpProxy</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> ...</pre></div></div>

<p>Wait a minute. This way we will have 10,000 lines in our application.js very soon and that is what we want last. Obviously, some step is missing as if we&#8217;re going to create such a big file why we couldn&#8217;t write it in <code><strong>index.html</strong></code> in the first place?</p>
<p>&nbsp;</p>
<h1>The right way: Break it apart</h1>
<p>Even the most complex whole consists of smaller system which consist of smaller parts which consist of some elements. Your to-be-written big application is not an exception. <strong>Now</strong> it is the time to identify this parts, components and relationships between them.</p>
<p>So, sit down, think it over, draw a sketch, make a list, whatever but result has to be that you know the components, at least most important ones, your application will consist of.</p>
<p>&nbsp;</p>
<h1>Pre-configured classes</h1>
<p>Now, that you are done with application analysis and identifying its components you can start to write the first one. But how? The best approach is to write extension classes of Ext components that have all configuration options, otherwise passed as the configuration object, built-in. I call such extensions pre-configured classes as they rarely add much functionality to base Ext ones but the main purpose of having them is to have them <strong>configured</strong>. For example, to have a &#8220;Personnel&#8221; grid with personnel specific column model, store, sorting options, editors, etc.</p>
<p>If we had such, our configuration of a Window could look like:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> win <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">Window</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
     title<span style="color: #339933;">:</span><span style="color: #3366CC;">'Personnel'</span>
    <span style="color: #339933;">,</span>widht<span style="color: #339933;">:</span><span style="color: #CC0000;">600</span>
    <span style="color: #339933;">,</span>height<span style="color: #339933;">:</span><span style="color: #CC0000;">400</span>
    <span style="color: #339933;">,</span>items<span style="color: #339933;">:</span><span style="color: #009900;">&#123;</span>xtype<span style="color: #339933;">:</span><span style="color: #3366CC;">'personnelgrid'</span><span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
win.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>&nbsp;</p>
<h2>Writing a pre-configured class</h2>
<p>Let&#8217;s take an example to discuss:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">Application.<span style="color: #660066;">PersonnelGrid</span> <span style="color: #339933;">=</span> Ext.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span>Ext.<span style="color: #660066;">grid</span>.<span style="color: #660066;">GridPanel</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
     border<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">false</span>
    <span style="color: #339933;">,</span>initComponent<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> config <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
           store<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">data</span>.<span style="color: #660066;">Store</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>...<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
          <span style="color: #339933;">,</span>columns<span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#123;</span>...<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>...<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#93;</span>
          <span style="color: #339933;">,</span>plugins<span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span>...<span style="color: #009900;">&#93;</span>
          <span style="color: #339933;">,</span>viewConfig<span style="color: #339933;">:</span><span style="color: #009900;">&#123;</span>forceFit<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#125;</span>
          <span style="color: #339933;">,</span>tbar<span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span>...<span style="color: #009900;">&#93;</span>
          <span style="color: #339933;">,</span>bbar<span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span>...<span style="color: #009900;">&#93;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// eo config object</span>
&nbsp;
        <span style="color: #006600; font-style: italic;">// apply config</span>
        Ext.<span style="color: #660066;">apply</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> Ext.<span style="color: #660066;">apply</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">initialConfig</span><span style="color: #339933;">,</span> config<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        Application.<span style="color: #660066;">PersonnelGrid</span>.<span style="color: #660066;">superclass</span>.<span style="color: #660066;">initComponent</span>.<span style="color: #660066;">apply</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> arguments<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #006600; font-style: italic;">// eo function initComponent</span>
&nbsp;
    <span style="color: #339933;">,</span>onRender<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">store</span>.<span style="color: #660066;">load</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        Application.<span style="color: #660066;">PersonnelGrid</span>.<span style="color: #660066;">superclass</span>.<span style="color: #660066;">onRender</span>.<span style="color: #660066;">apply</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> arguments<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #006600; font-style: italic;">// eo function onRender</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
Ext.<span style="color: #660066;">reg</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'personnelgrid'</span><span style="color: #339933;">,</span> Application.<span style="color: #660066;">PersonnelGrid</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>What we&#8217;re doing here? We&#8217;re extending <code><strong>Ext.grid.GridPanel</strong></code> creating the new class (extension) <code><strong>Application.PersonnelGrid</strong></code> and we are registering it as the new <code><strong>xtype</strong></code> with name <code><strong>personnelgrid</strong></code>.</p>
<p>We are giving the general grid panel all the configuration options needed to become the specific personnel grid. From this point on we have a new component, a building block for our application that we can use everywhere (window, border panel region, standalone) where the list of personnel is needed. We can create it either as:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> pg <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Application.<span style="color: #660066;">PersonnelGrid</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// or using it's xtype</span>
<span style="color: #003366; font-weight: bold;">var</span> win <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">Window</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
     items<span style="color: #339933;">:</span><span style="color: #009900;">&#123;</span>xtype<span style="color: #339933;">:</span><span style="color: #3366CC;">'personnelgrid'</span><span style="color: #009900;">&#125;</span>
    <span style="color: #339933;">,</span>....
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>&nbsp;</p>
<h1>Organizing pre-configured classes</h1>
<p>The code above does not need to and should not run within the onReady function because it has nothing to do with DOM structure; it only creates a new javascript object. Therefore it can and <strong>it should</strong> be written in a separate file (<code><strong>js/Application.PersonnelGrid.js</strong></code>) and it can and must be included in the index.html header as:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span> src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;./js/Application.PersonnelGrid&quot;</span><span style="color: #339933;">&gt;&lt;</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>So far so good, we have almost everything in place and (almost) all we need to do more is to continue writing our pre-configured classes, put them in <code><b>./js</b></code>; directory, include them in index.html and build your application from instances of them as puzzle is assembled from pieces.</p>
<p>Looks good, yeah?</p>
<p>Anyway, there is a bit more to it.</p>
<p>&nbsp;</p>
<h1>Inter component communication</h1>
<p>Imagine that we need a border layout with a link list in the west and tab panel in the center region. Clicking a link in the west would create a new tab in the center. Now, where should we put the logic of it, event handler and creation routine? In the west, or in the center?</p>
<p>Neither of them. Why? If we have a pre-configured class that creates and displays the west link list and we put the above logic in it it can no longer exist without center region. We just cannot use it without center as then we have no component to create tabs in.</p>
<p>If we put it in center, the result is same: center cannot exist without west.</p>
<p>The only component that should be aware of the existence of both west and center panels is their container with the border layout and this is the only right place where to put inter-component communication.</p>
<p>What should we do then? The container (with border layout) should listen to events fired by the west and it should create tabs in the center as responses to these clicks. The example of the component communication written this way can be found here: <a href="http://examples.extjs.eu/?ex=compcomm" target="_blank">Saki&#8217;s Ext Examples</a></p>
<p>&nbsp;</p>
<h1>Production Systems</h1>
<p>As we keep on writing our application we happen to have large number of included javascript files very soon (I have around 80 includes in one application at present and this number grows every day). This can degrade performance of a production system.</p>
<p>The best way to solve it is to concatenate all javascript files in the right order to create one big and to minify it with some of the javascript minfying or compression tools. Also, you do not need debug version of Ext Library for production systems.</p>
<p>We would include:</p>
<ul>
<li>ext-all.js</li>
<li>app-all.js and</li>
<li>application.js</li>
</ul>
<p>on a production system.</p>
<p>&nbsp;</p>
<h1>Conclusion</h1>
<p>It&#8217;s almost all there is to it&#8230; There are specific techniques for specific Ext classes, there is a lot of another server and client side know-how but the above is the overall concept.</p>
<p>Happy coding!</p>
<p><strong><em>Do not forget to read <a href="http://blog.extjs.eu/know-how/writing-a-big-application-in-ext-part-2/">Part 2</a> and <a href="http://blog.extjs.eu/know-how/writing-a-big-application-in-ext-part-3/">Part 3</a> of this article. </em></strong><br />
<form action="https://www.paypal.com/cgi-bin/webscr" method="post"><div class="paypal-donations"><input type="hidden" name="cmd" value="_donations" /><input type="hidden" name="business" value="js02@aariadne.com" /><input type="hidden" name="item_number" value="Blog Donation" /><input type="hidden" name="currency_code" value="EUR" /><input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-butcc-donate.gif" name="submit" alt="PayPal - The safer, easier way to pay online." /><img alt="" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1" /></div></form></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.extjs.eu/know-how/writing-a-big-application-in-ext/feed/</wfw:commentRss>
		<slash:comments>57</slash:comments>
		</item>
		<item>
		<title>JavaScript Application File Pattern</title>
		<link>http://blog.extjs.eu/patterns/file-patters/javascript-file-pattern/</link>
		<comments>http://blog.extjs.eu/patterns/file-patters/javascript-file-pattern/#comments</comments>
		<pubDate>Wed, 02 Apr 2008 15:10:59 +0000</pubDate>
		<dc:creator>Saki</dc:creator>
				<category><![CDATA[File Patters]]></category>
		<category><![CDATA[application]]></category>
		<category><![CDATA[extjs]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[pattern]]></category>

		<guid isPermaLink="false">http://blog.extjs.eu/?p=8</guid>
		<description><![CDATA[<br/>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// vim: sw=4:ts=4:nu:nospell:fdc=4
/**
 * An Application
 *
 * @author    Ing. Jozef Sakáloš
 * @copyright (c) 2008, by Ing. Jozef Sakáloš
 * @date      2. April 2008
 * @version   $Id$
 *
 * @license application.js is licensed under the terms of the Open Source
 * LGPL 3.0 license. [...]]]></description>
			<content:encoded><![CDATA[<br/>
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// vim: sw=4:ts=4:nu:nospell:fdc=4</span>
<span style="color: #006600; font-style: italic;">/**
 * An Application
 *
 * @author    Ing. Jozef Sakáloš
 * @copyright (c) 2008, by Ing. Jozef Sakáloš
 * @date      2. April 2008
 * @version   $Id$
 *
 * @license application.js is licensed under the terms of the Open Source
 * LGPL 3.0 license. Commercial use is permitted to the extent that the 
 * code/component(s) do NOT become part of another Open Source or Commercially
 * licensed development library or toolkit without explicit permission.
 * 
 * License details: http://www.gnu.org/licenses/lgpl.html
 */</span>
&nbsp;
<span style="color: #009966; font-style: italic;">/*global Ext, Application */</span>
&nbsp;
Ext.<span style="color: #660066;">ns</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Application'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// extensions here</span>
&nbsp;
Ext.<span style="color: #660066;">BLANK_IMAGE_URL</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'./ext/resources/images/default/s.gif'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// application main entry point</span>
Ext.<span style="color: #660066;">onReady</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    Ext.<span style="color: #660066;">QuickTips</span>.<span style="color: #660066;">init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// code here</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// eo function onReady</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// eof</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.extjs.eu/patterns/file-patters/javascript-file-pattern/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

