<?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; Know-how</title>
	<atom:link href="http://blog.extjs.eu/tag/know-how/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>Keeping modified records of EditorGridPanel while paging</title>
		<link>http://blog.extjs.eu/patterns/code-patterns/keeping-modified-records-of-editorgridpanel-while-paging/</link>
		<comments>http://blog.extjs.eu/patterns/code-patterns/keeping-modified-records-of-editorgridpanel-while-paging/#comments</comments>
		<pubDate>Mon, 28 Sep 2009 08:59:44 +0000</pubDate>
		<dc:creator>Saki</dc:creator>
				<category><![CDATA[Code Patterns]]></category>
		<category><![CDATA[extjs]]></category>
		<category><![CDATA[grid]]></category>
		<category><![CDATA[Know-how]]></category>
		<category><![CDATA[pattern]]></category>

		<guid isPermaLink="false">http://blog.extjs.eu/?p=498</guid>
		<description><![CDATA[<br/>If you modify records of an editable grid with paging and if you then page-out, your changes are lost. Well, they are not lost in fact unless you have set pruneModifiedRecords:true on the strore. The modifications are still available so we just need to apply them. Here is the code fragment that does it:

var grid [...]]]></description>
			<content:encoded><![CDATA[<br/><p>If you modify records of an editable grid with paging and if you then page-out, your changes are lost. Well, they are not lost in fact unless you have set <code><a target="_blank" href="http://www.extjs.com/deploy/dev/docs/?class=Ext.data.Store&#038;member=pruneModifiedRecords">pruneModifiedRecords:true</a></code> on the strore. The modifications are still available so we just need to apply them. Here is the code fragment that does it:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> grid <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">grid</span>.<span style="color: #660066;">EditorGridPanel</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>
         listeners<span style="color: #339933;">:</span><span style="color: #009900;">&#123;</span>
            load<span style="color: #339933;">:</span><span style="color: #009900;">&#123;</span>scope<span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> fn<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>store<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
                <span style="color: #006600; font-style: italic;">// loop through modified records</span>
                <span style="color: #003366; font-weight: bold;">var</span> modified <span style="color: #339933;">=</span> store.<span style="color: #660066;">getModifiedRecords</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> modified.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
                    <span style="color: #006600; font-style: italic;">// see if we have a record with same id </span>
                    <span style="color: #006600; font-style: italic;">// and apply changes if yes</span>
                    <span style="color: #003366; font-weight: bold;">var</span> r <span style="color: #339933;">=</span> store.<span style="color: #660066;">getById</span><span style="color: #009900;">&#40;</span>modified<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>r<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        <span style="color: #003366; font-weight: bold;">var</span> changes <span style="color: #339933;">=</span> modified<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">getChanges</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>p <span style="color: #000066; font-weight: bold;">in</span> changes<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>changes.<span style="color: #660066;">hasOwnProperty</span><span style="color: #009900;">&#40;</span>p<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                                r.<span style="color: #660066;">set</span><span style="color: #009900;">&#40;</span>p<span style="color: #339933;">,</span> changes<span style="color: #009900;">&#91;</span>p<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                            <span style="color: #009900;">&#125;</span>
                        <span style="color: #009900;">&#125;</span> <span style="color: #006600; font-style: italic;">// eo changes loop</span>
                    <span style="color: #009900;">&#125;</span>
                <span style="color: #009900;">&#125;</span> <span style="color: #006600; font-style: italic;">// eo modified loop</span>
            <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#125;</span> <span style="color: #006600; font-style: italic;">// eo load listener</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #006600; font-style: italic;">// eo listeners</span>
&nbsp;
        <span style="color: #006600; font-style: italic;">// rest of store configuration</span>
&nbsp;
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// rest of grid configuration</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span> <span style="color: #006600; font-style: italic;">// eo grid</span></pre></div></div>

<p><b>pruneModifiedRecords must be false (the default) for this to work.</b></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.extjs.eu/patterns/code-patterns/keeping-modified-records-of-editorgridpanel-while-paging/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>New Example &#8211; Combo with Remote Store</title>
		<link>http://blog.extjs.eu/examples/new-example-combo-with-remote-store/</link>
		<comments>http://blog.extjs.eu/examples/new-example-combo-with-remote-store/#comments</comments>
		<pubDate>Fri, 03 Apr 2009 11:58:36 +0000</pubDate>
		<dc:creator>Saki</dc:creator>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[extjs]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[Know-how]]></category>

		<guid isPermaLink="false">http://blog.extjs.eu/?p=295</guid>
		<description><![CDATA[<br/>Hi, 
I&#8217;ve just uploaded a full-fledged example of combo with remote store at http://examples.extjs.eu.
Enjoy!
]]></description>
			<content:encoded><![CDATA[<br/><p>Hi, </p>
<p>I&#8217;ve just uploaded a full-fledged example of combo with remote store at <a href="http://examples.extjs.eu/?ex=combo" target="_blank">http://examples.extjs.eu</a>.</p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.extjs.eu/examples/new-example-combo-with-remote-store/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Factory Function File Pattern</title>
		<link>http://blog.extjs.eu/know-how/factory-function-file-pattern/</link>
		<comments>http://blog.extjs.eu/know-how/factory-function-file-pattern/#comments</comments>
		<pubDate>Tue, 17 Mar 2009 13:50:04 +0000</pubDate>
		<dc:creator>Saki</dc:creator>
				<category><![CDATA[File Patters]]></category>
		<category><![CDATA[Know-how]]></category>
		<category><![CDATA[extjs]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://blog.extjs.eu/?p=266</guid>
		<description><![CDATA[<br/>You know, I&#8217;m not very big fan of factory functions, nevertheless, I&#8217;m aware of the fact that they may be necessary in some situations. Here is the file pattern that works (briefly tested).
Keep each factory function in a separate file name of which should be Namespace.Factory.functionName.js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// vim: ts=4:sw=4:nu:fdc=4:nospell
/*global Ext, MyNamespace */
/**
 * @class MyNamespace.Factory
 *
 [...]]]></description>
			<content:encoded><![CDATA[<br/><p>You know, I&#8217;m not very big fan of factory functions, nevertheless, I&#8217;m aware of the fact that they may be necessary in some situations. Here is the file pattern that works (briefly tested).</p>
<p><b>Keep each factory function in a separate file name of which should be <code>Namespace.Factory.functionName.js</code></b></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// vim: ts=4:sw=4:nu:fdc=4:nospell</span>
<span style="color: #009966; font-style: italic;">/*global Ext, MyNamespace */</span>
<span style="color: #006600; font-style: italic;">/**
 * @class MyNamespace.Factory
 *
 * A Factory function pattern
 *
 * @author    Ing. Jozef Sakáloš
 * @copyright (c) 2009, by Ing. Jozef Sakáloš
 * @date      17. March 2009
 * @version   0.1
 * @revision  $Id$
 *
 * @license MyNamespace.Factory.myPanel.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.
 * 
 * &lt;p&gt;License details: &lt;a href=&quot;http://www.gnu.org/licenses/lgpl.html&quot;
 * target=&quot;_blank&quot;&gt;http://www.gnu.org/licenses/lgpl.html&lt;/a&gt;&lt;/p&gt;
 */</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// create namespace</span>
Ext.<span style="color: #660066;">ns</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'MyNamespace.Factory'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">/**
 * @method myPanel
 * @param {Object} config
 * A config object
 * @return {Ext.Panel}
 */</span>
MyNamespace.<span style="color: #660066;">Factory</span>.<span style="color: #660066;">myPanel</span> <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>
&nbsp;
	<span style="color: #006600; font-style: italic;">// pre-instantiation code</span>
	<span style="color: #003366; font-weight: bold;">var</span> defaults <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #006600; font-style: italic;">// put your defaults here</span>
		<span style="color: #006600; font-style: italic;">// but avoid id, el, contentEl, renderTo, applyTo, or similar</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// eo defaults object</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// create config object</span>
	<span style="color: #003366; font-weight: bold;">var</span> cfg <span style="color: #339933;">=</span> Ext.<span style="color: #660066;">apply</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> config<span style="color: #339933;">,</span> defaults<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// instantiate</span>
	<span style="color: #003366; font-weight: bold;">var</span> cmp <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">Panel</span><span style="color: #009900;">&#40;</span>cfg<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// post-instantiation code</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// return the created component</span>
	<span style="color: #000066; font-weight: bold;">return</span> cmp<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span> <span style="color: #006600; font-style: italic;">// eo function MyNamespace.Factory.myPanel</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// eof</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.extjs.eu/know-how/factory-function-file-pattern/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Writing a Big Application in Ext (Part 3)</title>
		<link>http://blog.extjs.eu/know-how/writing-a-big-application-in-ext-part-3/</link>
		<comments>http://blog.extjs.eu/know-how/writing-a-big-application-in-ext-part-3/#comments</comments>
		<pubDate>Sat, 14 Mar 2009 12:53:34 +0000</pubDate>
		<dc:creator>Saki</dc:creator>
				<category><![CDATA[Know-how]]></category>
		<category><![CDATA[extension]]></category>
		<category><![CDATA[extjs]]></category>

		<guid isPermaLink="false">http://blog.extjs.eu/?p=234</guid>
		<description><![CDATA[<br/>Important
If you have not already done so, study Writing a Big Application in Ext (Part 1) and Writing a Big Application in Ext (Part 2)before you read this article. It would be very hard, if not impossible, to understand concepts explained here before you fully understand the first and second part.
Introduction
Helping on the forum and [...]]]></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> and <a href="http://blog.extjs.eu/know-how/writing-a-big-application-in-ext-part-2/" style="font-size:125%;">Writing a Big Application in Ext (Part 2)</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 and second part.</p>
<h1>Introduction</h1>
<p>Helping on the <a href="http://extjs.com/forum" target="_blank">forum</a> and reading code of others that failed to extend Ext classes, revealed more errors that users, especially beginners, commonly make. Therefore, I&#8217;ve decided to start this article that will collect these errors and will explain why the errors <i>are</i> errors. I mean it as loosely ended as I may discover more errors and ways of avoiding them so I plan just to add them to <i>this</i> article, not endlessly create parts 4, 5, etc&#8230;</p>
<h1><span style="font-size:12px">&#8230; continued:</span> Most Common Sources of Troubles</h1>
<p>Here we go:</p>
<ol>
<li><a href="#unnecessary-extending">Unnecessary Extending</a></li>
<li><a href="#adding-objects-to-prototype">Adding Objects to Prototype</a></li>
<li><a href="#hard-coding-ids">Hard Coding ids</a></li>
</ol>
<p>&nbsp;</p>
<h2 id="unnecessary-extending">Unnecessary Extending</h2>
<p>The main reasons for extending are:</p>
<ul>
<li>re-usability</li>
<li>adding functionality</li>
<li>combination of them</li>
</ul>
<p>so we extend if we need a re-usable component <b>or</b> we need to add a functionality (new methods) or both. If we are after <b>re-usability</b> the extension can be as simple as:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">MyPortlet <span style="color: #339933;">=</span> Ext.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span>Ext.<span style="color: #660066;">Panel</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
     anchor<span style="color: #339933;">:</span><span style="color: #3366CC;">'100%'</span>
    <span style="color: #339933;">,</span>draggable<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">true</span>
    <span style="color: #339933;">,</span>defaultType<span style="color: #339933;">:</span><span style="color: #3366CC;">'mygraph'</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>You see what happens? We are going to use MyPortlet many times so instead of scatter the above configuration in 10,000 lines application code 100 times, we create this simple extension and we save 297 lines of code. </p>
<p>The other aspect is that if we upgrade our &#8216;mygraph&#8217; to &#8216;mygraph_new&#8217; the only place where to change it is our extension saving us searching out code for all occurrences of &#8216;mygraph&#8217; (100 times) and replacing it with &#8216;mygraph_new&#8217; 100 times.</p>
<p>(Well, 100 is exaggerated, but you get the point, right?)</p>
<p>If we are after <b>adding functionality</b>, which can be also simple, we add some &#8220;logic&#8221;:</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;">MyPanel <span style="color: #339933;">=</span> Ext.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span>Ext.<span style="color: #660066;">Panel</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</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>
        MyPanel.<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: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Rendered'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Here we add some logic to Panel, it <b>does more</b> that it did before. </p>
<p><b>There is no need to extend in all other cases.</b></p>
<p>&nbsp;</p>
<h2 id="adding-objects-to-prototype">Adding Objects to Prototype</h2>
<p>Run this code first:</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;">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;">title</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;page-title&quot;</span>&gt;</span>Extending Error: Object in prototype<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: #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>&gt;</span>
  Ext.BLANK_IMAGE_URL = 'ext/resources/images/default/s.gif';
  Ext.onReady(function() {
    MyPanel = Ext.extend(Ext.Panel, {
         layout:'fit'
        ,panelConfig: {
            bodyBg:'red'
        }
&nbsp;
        ,initComponent:function() {
            var config = {
                bodyStyle:'background-color:' + this.panelConfig.bodyBg
            }; // eo config object
&nbsp;
            // apply config
            Ext.apply(this, Ext.apply(this.initialConfig, config));
&nbsp;
            MyPanel.superclass.initComponent.apply(this, arguments);
        } // eo function initComponent
&nbsp;
        ,applyBackground:function(color) {
            this.panelConfig.bodyBg = color;
            this.body.applyStyles({'background-color':color});
        } // eo function applyBackground
&nbsp;
    }); // eo extend
&nbsp;
    var p1 = new MyPanel({
         title:'Panel with Blue Background'
        ,renderTo:Ext.getBody()
        ,width:240
        ,height:160
    });
&nbsp;
    p1.applyBackground('blue');
&nbsp;
    var p2 = new MyPanel({
         title:'Panel with Red Background'
        ,renderTo:Ext.getBody()
        ,width:240
        ,height:160
    });
&nbsp;
  });
  <span style="color: #009900;">&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: #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>What do we expect? It is written in titles of panels: Top panel (p1) should have <b>blue</b> body background because we set it to it after it is created. And bottom panel (p2) should have <b>red</b> because we just create default <code>MyPanel</code>.</p>
<p><b>But it is blue too!!! Why?</b> The reason is simple: <code>panelConfig</code> is object that is created during <i>class definition</i> and it is added to MyPanel prototype. Objects (arrays too) are accessed by reference so p1 and p2 <b>share the same instance of <code>panelConfig</code></b>. Setting <code>bodyBg</code> property in <code>applyBackground</code> method changes this single instance of <code>panelConfig</code> object. So we create p2 with blue background too.</p>
<p>You see, here it is clearly and immediately visible that something went wrong but making this error can lead to weeks of wasted debugging time in real applications. Imagine you have a store in prototype&#8230;</p>
<p>&nbsp;</p>
<h2 id="hard-coding-ids">Hard Coding ids</h2>
<p>Very simple, but deadly mistake is to set ids in the extension either to the main extension object or on its items, toolbars, buttons, etc. If a hard coded ids are set we cannot create two or more instances of our extension, can we?</p>
<h1>Loose End</h1>
<p>That&#8217;s all for now but if I discover more errors I will add them above. </p>
<p>Stay tuned!</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-2/">Part 2</a> of this article. </em></strong></p>
<p>Follow up: <strong><a href="http://blog.extjs.eu/know-how/factory-functions-in-ext-extensions/">Factory Functions in Ext Extensions (Abstract Classes)</a></strong></p>
<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>
]]></content:encoded>
			<wfw:commentRss>http://blog.extjs.eu/know-how/writing-a-big-application-in-ext-part-3/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>How to remove all children of a tree node</title>
		<link>http://blog.extjs.eu/know-how/how-to-remove-all-children-of-a-tree-node/</link>
		<comments>http://blog.extjs.eu/know-how/how-to-remove-all-children-of-a-tree-node/#comments</comments>
		<pubDate>Wed, 04 Mar 2009 21:34:29 +0000</pubDate>
		<dc:creator>Saki</dc:creator>
				<category><![CDATA[Know-how]]></category>
		<category><![CDATA[extjs]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://blog.extjs.eu/?p=221</guid>
		<description><![CDATA[<br/>Suppose we want to remove all children of the node node:

while&#40;node.firstChild&#41; &#123;
    node.removeChild&#40;node.firstChild&#41;;
&#125;

That&#8217;s all there is to it
]]></description>
			<content:encoded><![CDATA[<br/><p>Suppose we want to remove all children of the node <code><b>node</b></code>:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">while</span><span style="color: #009900;">&#40;</span>node.<span style="color: #660066;">firstChild</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    node.<span style="color: #660066;">removeChild</span><span style="color: #009900;">&#40;</span>node.<span style="color: #660066;">firstChild</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>That&#8217;s all there is to it</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.extjs.eu/know-how/how-to-remove-all-children-of-a-tree-node/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<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>Which events are fired?</title>
		<link>http://blog.extjs.eu/know-how/which-events-are-fired/</link>
		<comments>http://blog.extjs.eu/know-how/which-events-are-fired/#comments</comments>
		<pubDate>Sun, 18 May 2008 09:13:54 +0000</pubDate>
		<dc:creator>Saki</dc:creator>
				<category><![CDATA[Know-how]]></category>
		<category><![CDATA[extjs]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://blog.extjs.eu/?p=73</guid>
		<description><![CDATA[<br/>We need to know all events that are fired by a component and in which order sometimes. It is easy to find out.
Let&#8217;s say that the component in question has id my-comp. Load the page with the component, open Firebug, Console tab, and type:

Ext.util.Observable.capture&#40;Ext.getCmp&#40;'my-comp'&#41;, console.info&#41;

Now do some actions with the component and watch the Firebug [...]]]></description>
			<content:encoded><![CDATA[<br/><p>We need to know all events that are fired by a component and in which order sometimes. It is easy to find out.</p>
<p>Let&#8217;s say that the component in question has id <b><code>my-comp</code></b>. Load the page with the component, open Firebug, Console tab, and type:</p>

<div class="wp_syntax"><div 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: #660066;">capture</span><span style="color: #009900;">&#40;</span>Ext.<span style="color: #660066;">getCmp</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'my-comp'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> console.<span style="color: #660066;">info</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>Now do some actions with the component and watch the Firebug output.<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/which-events-are-fired/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Events Explained</title>
		<link>http://blog.extjs.eu/know-how/events-explained/</link>
		<comments>http://blog.extjs.eu/know-how/events-explained/#comments</comments>
		<pubDate>Sun, 18 May 2008 08:44:43 +0000</pubDate>
		<dc:creator>Saki</dc:creator>
				<category><![CDATA[Know-how]]></category>
		<category><![CDATA[extjs]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://blog.extjs.eu/?p=72</guid>
		<description><![CDATA[<br/>Historical Background
Most likely many of you who will read this article do not remember times of Fortran language and computers that were fed with tons of punch cards to have some some job done.
The main purpose of computers at that time was to compute something really; that is not true anymore because computers are used [...]]]></description>
			<content:encoded><![CDATA[<br/><h1>Historical Background</h1>
<p>Most likely many of you who will read this article do not remember times of <a href="http://en.wikipedia.org/wiki/Fortran" target="_blank">Fortran</a> language and computers that were fed with tons of <a href="http://en.wikipedia.org/wiki/Punch_card" target="_blank">punch cards</a> to have some some job done.</p>
<p>The main purpose of computers at that time was to <strong>compute</strong> something really; that is not true anymore because computers are used for getting computational result very rarely at schools or scientific institutions nowadays.</p>
<p>How did it work at that time? If you wanted a computer to run a program you went to a shelf with your punched cards, you found the drawer with the stack of them, fed them through card reader and the computer started your program.</p>
<p>First task was to ask for user inputs and once you filled them in the program computed the result, printed it and ended. Easy, straightforward, &#8220;single thread&#8221; job.</p>
<h1>Events Introduced</h1>
<p>With the invent of <a href="http://en.wikipedia.org/wiki/Gui" target="_blank">GUI</a> and <a href="http://en.wikipedia.org/wiki/Mouse_%28computing%29" target="_blank">Mouse</a> this concept of load-run-end just couldn&#8217;t work anymore as we needed some infinite loop that would wait for user actions (mouse movement and clicks) and that would process them to execute the required actions.</p>
<p>I has became clear very soon that putting the code that processes these action directly in that loop is the route to nowhere so the <a href="http://en.wikipedia.org/wiki/Event-driven_programming" target="_blank">Event driven programming</a> was born.</p>
<h1>Event Definition</h1>
<p>Event is a message, a function call, generated by one (part of) program, the event source, that notifies another (part of) program, the event listener, that something happened. Events are generated as responses to user actions or to state changes of the event source.</p>
<p>The event source is independent of event listeners and it generates events also if nobody listens or even if there is no listener defined. The viewpoint of our infinite loop would be: &#8220;I&#8217;m informing everybody that user moved the mouse to position [x,y] and I do not care who listens, if anybody.&#8221;</p>
<p>The viewpoint of the listener would be: &#8220;Let me know when user moves the mouse, I need to do something with it.&#8221;</p>
<h1>Events in Ext</h1>
<p>There are two main &#8220;sorts&#8221; of events in Ext: <a href="http://en.wikipedia.org/wiki/Document_Object_Model" target="_blank">DOM</a> events and JavaScript, or software, events.</p>
<h2>DOM Events</h2>
<p>Browsers that display (X)HTML pages already have our &#8220;infinite loop&#8221; that watches user actions and fires events if these actions are occurring on DOM elements. Before Ext we were used to install event listeners on DOM elements this way:</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;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;mydiv&quot;</span> <span style="color: #000066;">onclick</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;alert('You clicked me')&quot;</span>&gt;</span>Click me!<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></div></div>

<p><a href="http://extjs.com/deploy/dev/docs/?class=Ext.Element" target="_blank">Ext.Element</a> wraps DOM elements together with their events so now we install the same event handlers this way:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">Ext.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'mydiv'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">on</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'click'</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;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'You clicked me'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>It can be said that DOM events are &#8220;passed-through&#8221; from DOM through Ext.Element to listeners.</p>
<h2>JavaScript Events</h2>
<p>Now, DOM elements are not only possible event sources; it is quite easy to implement event source logic and event listener installation to any JavaScript object. But, what could it be good for?</p>
<p>Imagine that you have a complex component such as grid. If you had only DOM events, the handling of user actions such as column move would be extremely difficult. You would need to listen to DOM elements, process mouse clicks, moves, calculate from where to where the column has been moved, etc. If would be much easier if grid component would do all this dirty work for you and, after everything has be done, just informed you: &#8220;User moved column 3 to position 1.&#8221;</p>
<p>That is exactly what grid does: it fires JavaScript events that inform potential listeners what has happened to it. The same is true for another Ext components. Form validation events, Panel resize events, Tree expand/collapse events can serve as examples, to name a few.</p>
<h1>How do I listen to events?</h1>
<p>If you have an object of Ext class, for example Panel, and you need to do some action when panel resizes you would install a <em>listener</em> to implement your action:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// create panel</span>
<span style="color: #003366; font-weight: bold;">var</span> myPanel <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">Panel</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>
&nbsp;
<span style="color: #006600; font-style: italic;">// install resize event listener</span>
myPanel.<span style="color: #660066;">on</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'resize'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>panel<span style="color: #339933;">,</span> w<span style="color: #339933;">,</span> h<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Panel resized to '</span> <span style="color: #339933;">+</span> w <span style="color: #339933;">+</span> <span style="color: #3366CC;">'x'</span> <span style="color: #339933;">+</span> h<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>From this point on, whenever the panel <strong><code>myPanel</code></strong> is resized your function is called so you can do your actions.</p>
<h1>How do I create event source?</h1>
<p>Events related functionality is implemented in <a href="http://extjs.com/deploy/dev/docs/?class=Ext.util.Observable" target="_blank">Ext.util.Observable</a> class so if you want your extension to be an event source just extend Observable. Also, if you extend a class that is already descendant of Observable (Panel, Grid, Form, Tree, etc), your extension is automatically the event source.</p>
<p>Events fired by your extension are events fired by parent class(es).</p>
<h1>Custom Events</h1>
<p>It happens very often that you need add new events, for example you create Employee class and Organization Chart class and you implement drag&amp;drop assignment/dismissal of employee to/from a position. I would come handy to fire event <i>assigned</i> and <i>dismissed</i>, wouldn&#8217;t it? </p>
<p>We could listen to these events and the listeners could send e-mails to the employee informing him that he has been assigned to a position or dismissed from it.</p>
<p>We do it this way:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">OrgChart <span style="color: #339933;">=</span> Ext.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span>Ext.<span style="color: #660066;">Panel</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</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: #006600; font-style: italic;">// call parent init component</span>
        OrgChart.<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;">// add custom events</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: #3366CC;">'assigned'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'dismissed'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #339933;">,</span>assign<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>employee<span style="color: #339933;">,</span> position<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #006600; font-style: italic;">// do whatever is necessary to assign the employee to position</span>
&nbsp;
        <span style="color: #006600; font-style: italic;">// fire assigned event</span>
        <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">fireEvent</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'assigned'</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> employee<span style="color: #339933;">,</span> position<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #339933;">,</span>dismiss<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>empoyee<span style="color: #339933;">,</span> position<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #006600; font-style: italic;">// do whatever is necessary to dismiss employee from position</span>
&nbsp;
        <span style="color: #006600; font-style: italic;">// fire dismissed event</span>
        <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">fireEvent</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'dismissed'</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> employee<span style="color: #339933;">,</span> position<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>In the <b><code>initComponent</code></b> function we inform Observable class that we are going to fire our new events so it can do all necessary setup. </p>
<p><i>Note:</i> We do not extend Observable directly here but <a href="http://extjs.com/deploy/dev/docs/?class=Ext.Panel" target="_blank">Panel</a>, what we extend, does. Panel&#8217;s inheritance chain is: Observable -> Component -> BoxComponent -> Container -> Panel.</p>
<p>And in <b><code>assign</code></b> and <b><code>dismiss</code></b> functions we fire our events after all assign/dismiss job has been done with signature (arguments) of our choice.</p>
<p>When we <b><code>fireEvent</code></b>, Observable looks if there are some listeners to this event and calls all listeners with arguments we supplied in <b><code>fireEvent</code></b> call. If there is no listener it just does nothing.</p>
<h1>Summary</h1>
<ul>
<li>event is a message sent (fired) by an event source to inform listeners that something happened</li>
<li>event source is an object that can fire events</li>
<li>event listener is a function that is called when event source fires an event</li>
<li>to listen to events we use <b><code>on</code></b> function to install an event listener</li>
<li>to create an event source we extend <b><code>Observable</code></b> class, <b><code>addEvents</code></b> and <b><code>fireEvent</code></b>
</ul>
<p>Enjoy firing your events and listening to them!<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/events-explained/feed/</wfw:commentRss>
		<slash:comments>36</slash:comments>
		</item>
		<item>
		<title>Extension or Plugin?</title>
		<link>http://blog.extjs.eu/know-how/extension-or-plugin/</link>
		<comments>http://blog.extjs.eu/know-how/extension-or-plugin/#comments</comments>
		<pubDate>Mon, 28 Apr 2008 01:05:26 +0000</pubDate>
		<dc:creator>Saki</dc:creator>
				<category><![CDATA[Know-how]]></category>
		<category><![CDATA[extension]]></category>
		<category><![CDATA[extjs]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://blog.extjs.eu/?p=64</guid>
		<description><![CDATA[<br/>Preface
I believe that many of Ext users have already thought about adding some custom functionality that is not present in core Ext Library to a class. Something that is specific to their applications or not that specific so that others could also be interested in such feature.
OK, we have the idea, we know what the [...]]]></description>
			<content:encoded><![CDATA[<br/><h1>Preface</h1>
<p>I believe that many of Ext users have already thought about adding some custom functionality that is not present in core Ext Library to a class. Something that is specific to their applications or not that specific so that others could also be interested in such feature.</p>
<p>OK, we have the idea, we know what the new code should do, we even know how to write it, but <i>what</i> should we write? An Extension or a Plugin?</p>
<h1>Extensions and Plugins</h1>
<p>The fact we are talking about them together and the fact that we can be even indecisive which one to use infers that they must have something in common. True, they have. They both <i>add</i> some functionality to an existing library or <i>modify</i> a feature of the library.</p>
<p>Neither extension nor plugin can exist standalone; they have to have a component, a class, they extend or plug into.</p>
<h1>Extension</h1>
<p>An extension (in Ext world) is a <a href="http://en.wikipedia.org/wiki/Inheritance_%28computer_science%29" target="_blank">derived class</a> in fact. Let&#8217;s imagine we have a basic class with some general methods to which we want to add some more specific methods. So, using the inheritance framework of an library or a language we <b>create new class</b> that contains methods of both basic class and new added methods.</p>
<p>We choose an <b>existing</b> Ext class, we extend it using <b><code>Ext.extend</code></b> function and the result is <b>new</b> class with <b>new</b> name. For example:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">MyExtension <span style="color: #339933;">=</span> Ext.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span>Ext.<span style="color: #660066;">Panel</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span><span style="color: #006600; font-style: italic;">/* object with new properties and methods */</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Later on, when we need an object:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> myExtension <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> MyExtension<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #006600; font-style: italic;">/* optional configuration object */</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h1>Plugin</h1>
<p>Plugin does not need any exiting Ext class to exist. Although plugins often extend <b><code>Ext.util.Observable</code></b> it is not a must; they can be written from scratch. Sure, writing a plugin without having a target we want to plug it in has no sense so we always write plugins <b>for an existing</b> Ext class: panel, form, grid, data view, etc.</p>
<p>For example, we create plugin as:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">MyPlugin <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: #006600; font-style: italic;">/* code */</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p>And then we use it this way:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> myPanel <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">Panel</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
     plugins<span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span><span style="color: #003366; font-weight: bold;">new</span> MyPlugin<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #006600; font-style: italic;">/* optional config object */</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span>
    <span style="color: #339933;">,</span><span style="color: #006600; font-style: italic;">// rest of myPanel configuration</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h1>Extension or Plugin?</h1>
<p>It depends&#8230; You can often achieve same result with extension or with plugin. Sometimes it is only that programmer likes plugins more so he writes a plugin or he likes extensions more so he writes an extension. However, plugins are more suitable for adding smaller features and extensions are more suitable for adding more complex functionalities. Plugins can be easily removed from components, extensions are usually more tied to applications.</p>
<h1>Summary</h1>
<ul>
<li>
An <b>extension</b> is a <b>new</b> class with a <b>new</b> name, based on an existing base class and created at <b>definition</b> time. Extension must be <b>instantiated</b> as any other class to work.</li>
<li><b>Plugin</b> plugs into an existing class, is easily removed, is defined during definition time and is initialized during base class <b>initialization</b>.</li>
</ul>
<h1>Further reading</h1>
<ul>
<li><a href="http://extjs.com/learn/Tutorial:Extending_Ext2_Class" target="_blank">Extending an Ext Class</a></lil>
<li><a href="http://extjs.com/learn/Tutorial:Writing_Ext_2_Plugins" target="_blank">Writing an Ext Plugin</a></li>
</ul>
<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>
]]></content:encoded>
			<wfw:commentRss>http://blog.extjs.eu/know-how/extension-or-plugin/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to get permissons of a file/directory</title>
		<link>http://blog.extjs.eu/know-how/cluster/how-to-get-permissons-of-a-filedirectory/</link>
		<comments>http://blog.extjs.eu/know-how/cluster/how-to-get-permissons-of-a-filedirectory/#comments</comments>
		<pubDate>Tue, 22 Apr 2008 12:13:21 +0000</pubDate>
		<dc:creator>Saki</dc:creator>
				<category><![CDATA[Cluster]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Know-how]]></category>

		<guid isPermaLink="false">http://blog.extjs.eu/?p=61</guid>
		<description><![CDATA[<br/>If you want to see permissions of a file or a directory in both human readable and octal notation issue this command:

stat -c &#34;%n %a %A&#34; /tmp # replace /tmp with your file/dir

The output is as follows:

/tmp 1777 drwxrwxrwt

]]></description>
			<content:encoded><![CDATA[<br/><p>If you want to see permissions of a file or a directory in both human readable and octal notation issue this command:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">stat</span> <span style="color: #660033;">-c</span> <span style="color: #ff0000;">&quot;%n %a %A&quot;</span> <span style="color: #000000; font-weight: bold;">/</span>tmp <span style="color: #666666; font-style: italic;"># replace /tmp with your file/dir</span></pre></div></div>

<p>The output is as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>tmp <span style="color: #000000;">1777</span> drwxrwxrwt</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.extjs.eu/know-how/cluster/how-to-get-permissons-of-a-filedirectory/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

