<?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</title>
	<atom:link href="http://blog.extjs.eu/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.extjs.eu</link>
	<description>For good of all productive developers</description>
	<lastBuildDate>Thu, 11 Mar 2010 15:55:54 +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>New Example &#8211; Grid in Card Layout</title>
		<link>http://blog.extjs.eu/examples/new-example-grid-in-card-layout/</link>
		<comments>http://blog.extjs.eu/examples/new-example-grid-in-card-layout/#comments</comments>
		<pubDate>Tue, 13 Oct 2009 12:49:17 +0000</pubDate>
		<dc:creator>Saki</dc:creator>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[ext]]></category>

		<guid isPermaLink="false">http://blog.extjs.eu/?p=540</guid>
		<description><![CDATA[<br/>Hi all,
I&#8217;ve just uploaded new example of Grid in Card Layout
Enjoy!
]]></description>
			<content:encoded><![CDATA[<br/><p>Hi all,</p>
<p>I&#8217;ve just uploaded new example of <a target="_blank" href="http://examples.extjs.eu/?ex=gridincard">Grid in Card Layout</a></p>
<p>Enjoy!</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/examples/new-example-grid-in-card-layout/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to Convert DVD to iPhone Video with Subtitles and Chapters on Linux</title>
		<link>http://blog.extjs.eu/multimedia/how-to-convert-dvd-to-iphone-video-with-subtitles-and-chapters-on-linux/</link>
		<comments>http://blog.extjs.eu/multimedia/how-to-convert-dvd-to-iphone-video-with-subtitles-and-chapters-on-linux/#comments</comments>
		<pubDate>Sun, 04 Oct 2009 21:02:44 +0000</pubDate>
		<dc:creator>Saki</dc:creator>
				<category><![CDATA[Multimedia]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://blog.extjs.eu/?p=506</guid>
		<description><![CDATA[<br/>iPhone can play video that contains multiple streams and chapters:

video
multiple audio streams (languages)
multiple subtitles (languages)
chapters for easy navigation

After some googling and many trials and errors I found a multiplatform software that can create videos with all the above features. The software is HandBrake. HandBrake for (openSUSE) Linux can be downloaded from Packman.
Let&#8217;s convert our DVD [...]]]></description>
			<content:encoded><![CDATA[<br/><p>iPhone can play video that contains multiple streams and chapters:</p>
<ul>
<li>video</li>
<li>multiple audio streams (languages)</li>
<li>multiple subtitles (languages)</li>
<li>chapters for easy navigation</li>
</ul>
<p>After some googling and many trials and errors I found a multiplatform software that can create videos with all the above features. The software is <a target="_blank" href="http://handbrake.fr">HandBrake</a>. HandBrake for (openSUSE) Linux can be downloaded from <a target="_blank" href="http://packman.links2linux.org">Packman</a>.</p>
<p>Let&#8217;s convert our DVD to the iPhone video. For that insert an original DVD in the drive, start HandBrake and select source.</p>
<p><a href="http://blog.extjs.eu/wp-content/uploads/2009/10/dvd2ipod-011.png"><img src="http://blog.extjs.eu/wp-content/uploads/2009/10/dvd2ipod-011.png" alt="dvd2ipod-01" title="dvd2ipod-01" width="600" class="aligncenter size-full wp-image-520" /></a></p>
<p>Select <i>iPhone &amp; iPod Touch</i> preset and type the file name and the destination directory.</p>
<p><a href="http://blog.extjs.eu/wp-content/uploads/2009/10/dvd2ipod-02.png"><img src="http://blog.extjs.eu/wp-content/uploads/2009/10/dvd2ipod-02.png" alt="dvd2ipod-02" title="dvd2ipod-02" width="600" class="aligncenter size-full wp-image-521" /></a></p>
<p>There is not too much to set on Video tab, however, you can play with quality if you want.</p>
<p><a href="http://blog.extjs.eu/wp-content/uploads/2009/10/dvd2ipod-03.png"><img src="http://blog.extjs.eu/wp-content/uploads/2009/10/dvd2ipod-03.png" alt="dvd2ipod-03" title="dvd2ipod-03" width="600" class="aligncenter size-full wp-image-522" /></a></p>
<p>In Audio tab, add as many audio tracks as you want:</p>
<p><a href="http://blog.extjs.eu/wp-content/uploads/2009/10/dvd2ipod-04.png"><img src="http://blog.extjs.eu/wp-content/uploads/2009/10/dvd2ipod-04.png" alt="dvd2ipod-04" title="dvd2ipod-04" width="600" class="aligncenter size-full wp-image-523" /></a></p>
<p>If you want to &#8220;burn&#8221; subtitles into video, just select one from the original DVD and you&#8217;re done. More difficult is if you want Closed Captioning subtitles (that can be turned off on iPhone). For that you need external files with subtitles in <code>srt</code> format. You can download them from <a target="_blank" href="http://opensubtitles.org">opensubtitles.org</a>. The problem can be that the downloaded subtitles may not be in sync with you video. I haven&#8217;t found a better way only to encode the DVD and, if subtitles are out of sync, use <a target="_blank" href="http://subcomposer.sourceforge.net">Subtitle Composer</a> to adjust the timing(s) and re-encode.</p>
<p><a href="http://blog.extjs.eu/wp-content/uploads/2009/10/dvd2ipod-05.png"><img src="http://blog.extjs.eu/wp-content/uploads/2009/10/dvd2ipod-05.png" alt="dvd2ipod-05" title="dvd2ipod-05" width="600" class="aligncenter size-full wp-image-524" /></a></p>
<p>Default settings in H.264 tab do not need any change.</p>
<p><a href="http://blog.extjs.eu/wp-content/uploads/2009/10/dvd2ipod-06.png"><img src="http://blog.extjs.eu/wp-content/uploads/2009/10/dvd2ipod-06.png" alt="dvd2ipod-06" title="dvd2ipod-06" width="600" class="aligncenter size-full wp-image-525" /></a></p>
<p>Rename chapters if you want. Names are sometimes on DVD covers, sometimes not.</p>
<p><a href="http://blog.extjs.eu/wp-content/uploads/2009/10/dvd2ipod-07.png"><img src="http://blog.extjs.eu/wp-content/uploads/2009/10/dvd2ipod-07.png" alt="dvd2ipod-07" title="dvd2ipod-07" width="600" class="aligncenter size-full wp-image-526" /></a></p>
<p>Start encoding, wait an hour or so and then download the resulting video to your iPhone with iTunes.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.extjs.eu/multimedia/how-to-convert-dvd-to-iphone-video-with-subtitles-and-chapters-on-linux/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to extract subtitles from DVD</title>
		<link>http://blog.extjs.eu/multimedia/how-to-extract-subtitles-from-dvd/</link>
		<comments>http://blog.extjs.eu/multimedia/how-to-extract-subtitles-from-dvd/#comments</comments>
		<pubDate>Fri, 02 Oct 2009 09:11:09 +0000</pubDate>
		<dc:creator>Saki</dc:creator>
				<category><![CDATA[Multimedia]]></category>

		<guid isPermaLink="false">http://blog.extjs.eu/?p=504</guid>
		<description><![CDATA[<br/>
mencoder dvd://1 -oac copy -ovc copy -o /dev/null -vobsubout output -sid 1

Then use avidemux2_qt4
]]></description>
			<content:encoded><![CDATA[<br/>
<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">mencoder dvd:<span style="color: #000000; font-weight: bold;">//</span><span style="color: #000000;">1</span> <span style="color: #660033;">-oac</span> copy <span style="color: #660033;">-ovc</span> copy <span style="color: #660033;">-o</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null <span style="color: #660033;">-vobsubout</span> output <span style="color: #660033;">-sid</span> <span style="color: #000000;">1</span></pre></div></div>

<p>Then use <code>avidemux2_qt4</code></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.extjs.eu/multimedia/how-to-extract-subtitles-from-dvd/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<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>4</slash:comments>
		</item>
		<item>
		<title>New Example &#8211; Ext.ux.MsgBus Demo</title>
		<link>http://blog.extjs.eu/examples/new-example-ext-ux-msgbus-demo/</link>
		<comments>http://blog.extjs.eu/examples/new-example-ext-ux-msgbus-demo/#comments</comments>
		<pubDate>Sun, 20 Sep 2009 21:48:38 +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[plugin]]></category>

		<guid isPermaLink="false">http://blog.extjs.eu/?p=490</guid>
		<description><![CDATA[<br/>Hi there,
I&#8217;ve just uploaded demo of Ext.ux.MsgBus Plugin at http://examples.extjs.eu/?ex=msgbus.
Enjoy!
]]></description>
			<content:encoded><![CDATA[<br/><p>Hi there,</p>
<p>I&#8217;ve just uploaded demo of <a href="http://blog.extjs.eu/plugins/ext-ux-msgbus-plugin/">Ext.ux.MsgBus Plugin</a> at <a href="http://examples.extjs.eu/?ex=msgbus">http://examples.extjs.eu/?ex=msgbus</a>.</p>
<p>Enjoy!</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/examples/new-example-ext-ux-msgbus-demo/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Ext.ux.MsgBus Plugin</title>
		<link>http://blog.extjs.eu/plugins/ext-ux-msgbus-plugin/</link>
		<comments>http://blog.extjs.eu/plugins/ext-ux-msgbus-plugin/#comments</comments>
		<pubDate>Sun, 20 Sep 2009 12:45:10 +0000</pubDate>
		<dc:creator>Saki</dc:creator>
				<category><![CDATA[Plugins]]></category>

		<guid isPermaLink="false">http://blog.extjs.eu/?p=473</guid>
		<description><![CDATA[<br/>Recently I&#8217;ve been looking for a better way of inter-component communication in Ext so I&#8217;ve read a couple of posts with Message Bus implementations, I&#8217;ve skimmed over OpenAjax Hub page but I haven&#8217;t found anything suitable for my needs.
The first approach was Simple Message Bus Example but that is more concept proof than a really [...]]]></description>
			<content:encoded><![CDATA[<br/><p>Recently I&#8217;ve been looking for a better way of inter-component communication in Ext so I&#8217;ve read a couple of posts with Message Bus implementations, I&#8217;ve skimmed over <a target="_blank" href="http://openajax.org">OpenAjax Hub</a> page but I haven&#8217;t found anything suitable for my needs.</p>
<p>The first approach was <a target="_blank" href="http://blog.extjs.eu/examples/new-example-simple-message-bus">Simple Message Bus Example</a> but that is more concept proof than a really usable way in production environment.</p>
<p>I like the concept of message subjects (topics) as <a target="_blank" href="http://www.openajax.org/member/wiki/OpenAjax_Hub_2.0_Specification_Topic_Names">dot separated sequence of tokens</a> with the ability to subscribe to messages with specific subjects and with wildcard support.</p>
<p>For example, if a component would subscribe to the subject <code>eu.extjs.desktop.**</code> it would receive message with subject <code>eu.extjs.desktop.wallpaper.set</code> but it wouldn&#8217;t receive message <code>eu.extjs.taskbar.hide</code>.</p>
<p>So this plugin was born.</p>
<p>Ext.ux.MsgBus fits in any component that is descendant of Ext.util.Observable and it does not need any other changes/overrides. You would stick it only into the components that must participate in bus messaging. It adds <code>subscribe</code> and <code>publish</code> methods to the component.</p>
<p>Usage example:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> p <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: #3366CC;">'msgbus'</span><span style="color: #009900;">&#93;</span>
    <span style="color: #339933;">,</span>onWallpaper<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>subject<span style="color: #339933;">,</span> message<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #006600; font-style: italic;">// do something</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #006600; font-style: italic;">// the rest of config</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
p.<span style="color: #660066;">subscribe</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'eu.extjs.desktop.wallpaper.**'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>fn<span style="color: #339933;">:</span>p.<span style="color: #660066;">onWallpaper</span><span style="color: #339933;">,</span> single<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The above would call p.onWallpaper callback once upon the receipt of a &#8220;wallpaper&#8221; message.</p>
<p>Other example:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">p.<span style="color: #660066;">publish</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'eu.extjs.this.panel.move'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>oldx<span style="color: #339933;">:</span><span style="color: #CC0000;">100</span><span style="color: #339933;">,</span> oldy<span style="color: #339933;">:</span><span style="color: #CC0000;">200</span><span style="color: #339933;">,</span> x<span style="color: #339933;">:</span><span style="color: #CC0000;">300</span><span style="color: #339933;">,</span> y<span style="color: #339933;">:</span><span style="color: #CC0000;">400</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>I haven&#8217;t tested it fully yet so take it more as an initial idea than as a bullet-proof, worldwide-tested code. Also, I didn&#8217;t try in any means to implement OpenAjax standards and use this plugin for an inter library communication. Consider it as a one possibility of intra-Ext, inter-component communication.</p>
<p>Any comments and/or bug reports are welcome.</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;">/**
 * Message Bus Plugin
 *
 * @author    Ing. Jozef Sakáloš
 * @copyright (c) 2009, by Ing. Jozef Sakáloš
 * @date      19. September 2009
 * @version   $Id: Ext.ux.MsgBus.js 29 2009-09-23 09:51:55Z jozo $
 *
 * @license Ext.ux.MsgBus.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,window */</span>
&nbsp;
<span style="color: #006600; font-style: italic;">/**
 * @class Ext.ux.MsgBus
 *
 * Creates new Ext.ux.MsgBus object
 * @constructor
 * @param {Object} config The config object
 */</span>
Ext.<span style="color: #660066;">ux</span>.<span style="color: #660066;">MsgBus</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>
    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: #339933;">,</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// eo constructor</span>
&nbsp;
Ext.<span style="color: #660066;">override</span><span style="color: #009900;">&#40;</span>Ext.<span style="color: #660066;">ux</span>.<span style="color: #660066;">MsgBus</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">/**
     * @cfg {String} busName Name of the global Observable instance
     */</span>
     busName<span style="color: #339933;">:</span><span style="color: #3366CC;">'Ext.ux.Bus'</span>
    <span style="color: #006600; font-style: italic;">/**
     * @private
     */</span>
    <span style="color: #339933;">,</span>bus<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">false</span>
    <span style="color: #006600; font-style: italic;">/**
     * Initializes the plugin and component
     * @private
     */</span>
    <span style="color: #339933;">,</span>init<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>cmp<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;">cmp</span> <span style="color: #339933;">=</span> cmp<span style="color: #339933;">;</span>
        cmp.<span style="color: #660066;">bus</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">getBus</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        cmp.<span style="color: #660066;">bus</span>.<span style="color: #660066;">addEvents</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'message'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        cmp.<span style="color: #660066;">subs</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">applyConfig</span><span style="color: #009900;">&#40;</span><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 init</span>
    <span style="color: #006600; font-style: italic;">// {{{</span>
    <span style="color: #006600; font-style: italic;">/**
     * Returns or creates the global Observable instance
     * @private
     */</span>
    <span style="color: #339933;">,</span>getBus<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> bus <span style="color: #339933;">=</span> window<span style="color: #339933;">;</span>
        <span style="color: #003366; font-weight: bold;">var</span> a <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">busName</span>.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003366; font-weight: bold;">var</span> last <span style="color: #339933;">=</span> a.<span style="color: #660066;">pop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        Ext.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>n<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: #339933;">!</span>Ext.<span style="color: #660066;">isObject</span><span style="color: #009900;">&#40;</span>bus<span style="color: #009900;">&#91;</span>n<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                bus <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
                <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
                bus <span style="color: #339933;">=</span> bus<span style="color: #009900;">&#91;</span>n<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</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><span style="color: #003366; font-weight: bold;">false</span> <span style="color: #339933;">===</span> bus<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            Ext.<span style="color: #660066;">ns</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">busName</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">getBus</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span>bus<span style="color: #009900;">&#91;</span>last<span style="color: #009900;">&#93;</span> <span style="color: #000066; font-weight: bold;">instanceof</span> Ext.<span style="color: #660066;">util</span>.<span style="color: #660066;">Observable</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            bus<span style="color: #009900;">&#91;</span>last<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">util</span>.<span style="color: #660066;">Observable</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000066; font-weight: bold;">return</span> bus<span style="color: #009900;">&#91;</span>last<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #006600; font-style: italic;">// eo function getBus</span>
    <span style="color: #006600; font-style: italic;">// }}}</span>
    <span style="color: #006600; font-style: italic;">// {{{</span>
    <span style="color: #006600; font-style: italic;">/**
     * Creates RegExp for message filtering.
     * Override it if you need another logic.
     * @param {String} subject The message subject
     * @return {RegExp} RegExp used for message filtering
     */</span>
    <span style="color: #339933;">,</span>getFilterRe<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>subject<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> a <span style="color: #339933;">=</span> subject.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003366; font-weight: bold;">var</span> last <span style="color: #339933;">=</span> a.<span style="color: #660066;">length</span> <span style="color: #339933;">-</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>
        a<span style="color: #009900;">&#91;</span>last<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'**'</span> <span style="color: #339933;">===</span> a<span style="color: #009900;">&#91;</span>last<span style="color: #009900;">&#93;</span> <span style="color: #339933;">?</span> <span style="color: #3366CC;">'.*'</span> <span style="color: #339933;">:</span> a<span style="color: #009900;">&#91;</span>last<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #003366; font-weight: bold;">var</span> re <span style="color: #339933;">=</span> <span style="color: #009966; font-style: italic;">/^\w+$/</span><span style="color: #339933;">;</span>
        Ext.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>token<span style="color: #339933;">,</span> i<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: #339933;">!</span>re.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span>token<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #3366CC;">'*'</span> <span style="color: #339933;">!==</span> token <span style="color: #339933;">&amp;&amp;</span> <span style="color: #3366CC;">'.*'</span> <span style="color: #339933;">!==</span> token<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000066; font-weight: bold;">throw</span> <span style="color: #3366CC;">'Invalid subject: '</span> <span style="color: #339933;">+</span> subject<span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'*'</span> <span style="color: #339933;">===</span> token<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                a<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'<span style="color: #000099; font-weight: bold;">\\</span>w+'</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>
        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">new</span> RegExp<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'^'</span> <span style="color: #339933;">+</span> a.<span style="color: #660066;">join</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'<span style="color: #000099; font-weight: bold;">\\</span>.'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'$'</span><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 getFilter</span>
    <span style="color: #006600; font-style: italic;">// }}}</span>
    <span style="color: #006600; font-style: italic;">// {{{</span>
    <span style="color: #006600; font-style: italic;">/**
     * Applies new methods to the component
     * @private
     */</span>
    <span style="color: #339933;">,</span>applyConfig<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>
        Ext.<span style="color: #660066;">applyIf</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">cmp</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #006600; font-style: italic;">/**
             * Subscribes to messages (parent component method)
             * @param {String} subject Dotted notation subject with wildcards.
             * See http://www.openajax.org/member/wiki/OpenAjax_Hub_2.0_Specification_Topic_Names
             * @param {Object} config Same as addListener config object
             * @return {Boolean} success true on success, false on failure (subscription exists)
             */</span>
             subscribe<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>subject<span style="color: #339933;">,</span> config<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                 <span style="color: #003366; font-weight: bold;">var</span> sub <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">subs</span><span style="color: #009900;">&#91;</span>subject<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>sub<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
                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;">filter</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">getFilterRe</span><span style="color: #009900;">&#40;</span>subject<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">subs</span><span style="color: #009900;">&#91;</span>subject<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>config<span style="color: #339933;">:</span>config<span style="color: #339933;">,</span> fn<span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">filterMessage</span>.<span style="color: #660066;">createDelegate</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#91;</span>config<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
                <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">bus</span>.<span style="color: #660066;">on</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'message'</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">subs</span><span style="color: #009900;">&#91;</span>subject<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">fn</span><span style="color: #339933;">,</span> config.<span style="color: #660066;">scope</span> <span style="color: #339933;">||</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;">return</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #006600; font-style: italic;">/**
             * Unsubscribes from messages (parent component method)
             * @param {String} subject Dotted notation subject with wildcards.
             * @return {Boolean} success true on success, false on failure (nonexistent subscription)
             */</span>
            <span style="color: #339933;">,</span>unsubscribe<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>subject<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #003366; font-weight: bold;">var</span> sub <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">subs</span><span style="color: #009900;">&#91;</span>subject<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>sub<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
                <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">bus</span>.<span style="color: #660066;">un</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'message'</span><span style="color: #339933;">,</span> sub.<span style="color: #660066;">fn</span><span style="color: #339933;">,</span> sub.<span style="color: #660066;">scope</span> <span style="color: #339933;">||</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> sub.<span style="color: #660066;">config</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;">subs</span><span style="color: #009900;">&#91;</span>subject<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                sub <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span>
                <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span> <span style="color: #006600; font-style: italic;">// eo function unsubscribe</span>
&nbsp;
            <span style="color: #006600; font-style: italic;">/**
             * Publishes the message (parent component method)
             * @param {String} subject Message subject
             * @param {Mixed} message Message body, most likely an object
             */</span>
            <span style="color: #339933;">,</span>publish<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>subject<span style="color: #339933;">,</span> message<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;">getFilterRe</span><span style="color: #009900;">&#40;</span>subject<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">bus</span>.<span style="color: #660066;">fireEvent</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'message'</span><span style="color: #339933;">,</span> subject<span style="color: #339933;">,</span> message<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 publish</span>
&nbsp;
            <span style="color: #006600; font-style: italic;">/**
             * Returns current subscriptions
             * @return {Object} subscriptions
             */</span>
            <span style="color: #339933;">,</span>getSubscriptions<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;">return</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">subs</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span> <span style="color: #006600; font-style: italic;">// eo function</span>
&nbsp;
            <span style="color: #006600; font-style: italic;">/**
             * @private
             */</span>
            <span style="color: #339933;">,</span>getFilterRe<span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">getFilterRe</span>
&nbsp;
            <span style="color: #006600; font-style: italic;">/**
             * Filters incoming messages
             * @private
             */</span>
            <span style="color: #339933;">,</span>filterMessage<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>subject<span style="color: #339933;">,</span> message<span style="color: #339933;">,</span> config<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>config.<span style="color: #660066;">filter</span>.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span>subject<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    <span style="color: #009900;">&#40;</span>config.<span style="color: #660066;">fn</span> <span style="color: #339933;">||</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">onMessage</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">call</span><span style="color: #009900;">&#40;</span>config.<span style="color: #660066;">scope</span> <span style="color: #339933;">||</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> subject<span style="color: #339933;">,</span> message<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 function filterMessage</span>
&nbsp;
            <span style="color: #006600; font-style: italic;">/**
             * Default message processing function
             * @param {String} subject The message subject
             * @param {Mixed} message The message body
             */</span>
            <span style="color: #339933;">,</span>onMessage<span style="color: #339933;">:</span>Ext.<span style="color: #660066;">emptyFn</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #006600; font-style: italic;">// eo function applyConfig</span>
    <span style="color: #006600; font-style: italic;">// }}}</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 override</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// register ptype</span>
Ext.<span style="color: #660066;">preg</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'msgbus'</span><span style="color: #339933;">,</span> Ext.<span style="color: #660066;">ux</span>.<span style="color: #660066;">MsgBus</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #006600; font-style: italic;">// eof</span></pre></div></div>

<p>Enjoy!</p>
<p>The accompanying example: <a target="_blank" href="http://examples.extjs.eu/?ex=msgbus">Ext.ux.MsgBus</a></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/plugins/ext-ux-msgbus-plugin/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>New Example &#8211; Simple Message Bus</title>
		<link>http://blog.extjs.eu/examples/new-example-simple-message-bus/</link>
		<comments>http://blog.extjs.eu/examples/new-example-simple-message-bus/#comments</comments>
		<pubDate>Sat, 19 Sep 2009 20:02:45 +0000</pubDate>
		<dc:creator>Saki</dc:creator>
				<category><![CDATA[Examples]]></category>

		<guid isPermaLink="false">http://blog.extjs.eu/?p=465</guid>
		<description><![CDATA[<br/>Hi all,
I&#8217;ve just uploaded very simple, extremely simple, example of how to implement Message Bus in Ext using the global Ext.util.Observable instance.
Enjoy!
Simple Message Bus Example
See also: Ext.ux.MsgBus Plugin
]]></description>
			<content:encoded><![CDATA[<br/><p>Hi all,</p>
<p>I&#8217;ve just uploaded very simple, extremely simple, example of how to implement Message Bus in Ext using the global Ext.util.Observable instance.</p>
<p>Enjoy!</p>
<p><a target="_blank" href="http://examples.extjs.eu/?ex=simplebus">Simple Message Bus Example</a></p>
<p>See also: <a href="http://blog.extjs.eu/plugins/ext-ux-msgbus-plugin/">Ext.ux.MsgBus Plugin</a></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/examples/new-example-simple-message-bus/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What the hell is mon and mun?</title>
		<link>http://blog.extjs.eu/know-how/what-the-hell-is-mon-and-mun/</link>
		<comments>http://blog.extjs.eu/know-how/what-the-hell-is-mon-and-mun/#comments</comments>
		<pubDate>Fri, 18 Sep 2009 00:31:51 +0000</pubDate>
		<dc:creator>Saki</dc:creator>
				<category><![CDATA[Know-how]]></category>

		<guid isPermaLink="false">http://blog.extjs.eu/?p=446</guid>
		<description><![CDATA[<br/>I&#8217;ve run across the following code in some of Ext 3.x examples:

this.mon&#40;toolsUl, 'click', this.onClick, this&#41;;

Looks like event handler installation but what it really does anyway?
So I delved into the code and remembered ExtJS Conference and now it is clear to me.
Imagine you create a component and then you need to install an event handler, for [...]]]></description>
			<content:encoded><![CDATA[<br/><p>I&#8217;ve run across the following code in some of Ext 3.x examples:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">mon</span><span style="color: #009900;">&#40;</span>toolsUl<span style="color: #339933;">,</span> <span style="color: #3366CC;">'click'</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">onClick</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Looks like event handler installation but what it really does anyway?</p>
<p>So I delved into the code and remembered ExtJS Conference and now it is clear to me.</p>
<p>Imagine you create a component and then you need to install an event handler, for example, on its body. Something 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> handler <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 my body'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> p <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>
     renderTo<span style="color: #339933;">:</span>Ext.<span style="color: #660066;">getBody</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #339933;">,</span>title<span style="color: #339933;">:</span><span style="color: #3366CC;">'Panel with a listener on the body'</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
p.<span style="color: #660066;">body</span>.<span style="color: #660066;">on</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'click'</span><span style="color: #339933;">,</span> handler<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Easy enough, we&#8217;ve done something like this many times. But, if the panel is ever to be destroyed we need to remove this listener ourselves as Ext knows nothing about it.</p>
<p> Something 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> p <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>
     renderTo<span style="color: #339933;">:</span>Ext.<span style="color: #660066;">getBody</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #339933;">,</span>title<span style="color: #339933;">:</span><span style="color: #3366CC;">'Panel with a listener on the body'</span>
    <span style="color: #339933;">,</span>beforeDestroy<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;">body</span>.<span style="color: #660066;">un</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'click'</span><span style="color: #339933;">,</span> handler<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>
If we install our listener as inline function, such as:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">p.<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 my body'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

</p>
<p>then it is impossible to remove this listener selectively, you would need to use</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">p.<span style="color: #660066;">body</span>.<span style="color: #660066;">removeAllListeners</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>to remove <i>all</i> body listeners.</p>
<p>Now, if we use <code>mon</code> (m stands for &#8220;managed&#8221;) this way</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">p.<span style="color: #660066;">mon</span><span style="color: #009900;">&#40;</span>p.<span style="color: #660066;">body</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'click'</span><span style="color: #339933;">,</span> handler<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>then the listener is automatically removed by Ext on panel destroy. Nice, isn&#8217;t it? Saves a lot of our work and also handles our laziness or forgetfulness about destroying and cleanups of components.</p>
<p>
Mind the first argument, that is the element to install the listener to. It can, but not necessarily have to be within the component. Also remember that when you destroy <code>p</code> Ext only removes listener from the element so if the element is outside of <code>p</code> you need to remove it yourself if it is not necessary anymore.
</p>
<p>Should you ever need to remove the listener installed by <code>mon</code> you use <code>mun</code> with same arguments. You cannot selectively remove inline listeners.</p>
<p><code>mon</code> and <code>mun</code> are defined in Component so you can use them from Component down the descendant classes chain.</p>
<p>
<span style="color:#c00000;font-size:14px;font-weight:bold">Warning! <code>mon</code> and <code>mun</code> are not documented (yet?) so there is still (a little) risk that they will change or will be removed.</span>
</p>
<p>&nbsp;</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/what-the-hell-is-mon-and-mun/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Mastering Ext.Direct, Part 3</title>
		<link>http://blog.extjs.eu/know-how/mastering-ext-direct-part-3/</link>
		<comments>http://blog.extjs.eu/know-how/mastering-ext-direct-part-3/#comments</comments>
		<pubDate>Thu, 17 Sep 2009 12:20:37 +0000</pubDate>
		<dc:creator>Saki</dc:creator>
				<category><![CDATA[Know-how]]></category>

		<guid isPermaLink="false">http://blog.extjs.eu/?p=421</guid>
		<description><![CDATA[<br/>]]></description>
			<content:encoded><![CDATA[<br/><h4><a href="http://blog.extjs.eu/know-how/mastering-ext-direct-part-2"><<< Mastering Ext.Direct, Part 2</a></h4>
<h1>Processing responses</h1>
<p>As I&#8217;ve already said, you cannot use the return value of an API function call as result is not know at the moment of the call return. It is never stressed enough that
<p><b>Ext.Direct calls are ASYNCHRONOUS</b>.</p>
<p>Therefore, all Ext.Direct created API functions, for example <code>Example.Car.go()</code> take one extra argument in addition to arguments you have specified in server-side class definition. That argument is <b>callback function</b>.
</p>
<p>
In our example, <code>Example.Car.go()</code> takes one argument, <code>speed</code> per server side method definition, however, it takes two in fact: <code>Example.Car.go(speed, callback)</code>
</p>
<p>
Let&#8217;s call it with a callback to test it. Type in the Firebug console:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">Example.<span style="color: #660066;">Car</span>.<span style="color: #660066;">go</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">80</span><span style="color: #339933;">,</span> console.<span style="color: #660066;">info</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><code>console.info</code> is a function that prints its arguments in a human readable form. We use it as the callback so we see:</p>
<ul>
<li>that it really gets called when the response arrives</li>
<li>which arguments Ext.Direct passes to the callback</li>
</ul>
<p>
As you can see, the callback is called with two arguments:</p>
<ul>
<li><code>response</code> &#8211; it is that what is returned by the server-side <code>Car.go()</code> method. It can be string (as in our example), boolean, object, array or void (nothing).</li>
<li><code>e</code> &#8211; it is <a target="_blank" href="http://www.extjs.com/deploy/dev/docs/?class=Ext.Direct&#038;member=eventTypes">Ext.Direct.Event</a> object or, being more specific, Ext.Direct.RemotingEvent.
</ul>
</p>
<p>
The event <code>e</code> has some useful properties and methods, most important of them are:</p>
<ul>
<li><code>status</code> is <code>true</code> if the call was successful, <code>false</code> if the call failed</li>
<li><code>result</code> contains same value as the first argument &#8211; it is server response data</li>
<li><code>type</code> is <code>rpc</code> in our example but it also can be <code>exception</code> or others
<li><code>action</code> is the class name</li>
<li><code>method</code> is name of the method called</li>
<li><code>getTransaction()</code> is method to retrieve the transaction used in this server round trip. You would use it if you want more data on the transaction.
</ul>
</p>
<h1>Processing exceptions</h1>
<p>Let&#8217;s call go method again:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">Example.<span style="color: #660066;">Car</span>.<span style="color: #660066;">go</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">300</span><span style="color: #339933;">,</span> console.<span style="color: #660066;">info</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The callback is called as before but the arguments differ:</p>
<ul>
<li><code>response</code> is <code>undefined</code> &#8211; no data from server</li>
<li><code>e</code> has type <code>exception</code> and has property <code>message</code> that contains error message text</li>
</ul>
<h1>An example application</h1>
<p>That is almost all we need to know to start using Ext.Direct in an application. I&#8217;ve written a simple one so you have something to play with.</p>
<p>First, create file <code>example.js</code> with the following content:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/**
 * Mastering Ext.Direct example script
 *
 * @author     Ing. Jozef Sakalos
 * @copyright  (c) 2009, by Ing. Jozef Sakalos
 * @date       16. September 2009
 * @version    1.0
 * @revision   $Id$
 */</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;
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>
    <span style="color: #006600; font-style: italic;">/**
     * This function is called when Ext.Direct request
     * response arrives from the server.
     *
     * @param {String/Object/Array/Null} response 
     * That what is returned by server method
     * @param {Ext.Direct.RemotingEvent/Ext.Direct.ExceptionEvent} e 
     */</span>
    <span style="color: #003366; font-weight: bold;">var</span> callback <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>response<span style="color: #339933;">,</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #006600; font-style: italic;">// uncomment if you want to inspect arguments in Firebug Console</span>
<span style="color: #006600; font-style: italic;">//        console.log(response, e);</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">var</span> <span style="color: #000066;">status</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'&lt;b&gt;Success&lt;/b&gt;'</span>
        <span style="color: #003366; font-weight: bold;">var</span> text <span style="color: #339933;">=</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #006600; font-style: italic;">// success handling - e.status is success flag: </span>
        <span style="color: #006600; font-style: italic;">// true is success, false is failure</span>
        <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">true</span> <span style="color: #339933;">===</span> e.<span style="color: #000066;">status</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #006600; font-style: italic;">// response argument is same as e.result</span>
            text <span style="color: #339933;">=</span> response<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #006600; font-style: italic;">// failure handling</span>
        <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066;">status</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'&lt;b&gt;&lt;i&gt;Failure&lt;/i&gt;&lt;/b&gt;'</span>
&nbsp;
            <span style="color: #006600; font-style: italic;">// in the case of an exception, we don't have response but message</span>
            text <span style="color: #339933;">=</span> e.<span style="color: #660066;">message</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #006600; font-style: italic;">// grab the center body</span>
        <span style="color: #003366; font-weight: bold;">var</span> body <span style="color: #339933;">=</span> win.<span style="color: #660066;">items</span>.<span style="color: #660066;">itemAt</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">body</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #006600; font-style: italic;">// display the response</span>
        body.<span style="color: #660066;">createChild</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
             tag<span style="color: #339933;">:</span><span style="color: #3366CC;">'div'</span>
            <span style="color: #339933;">,</span>cls<span style="color: #339933;">:</span><span style="color: #3366CC;">'response'</span>
            <span style="color: #339933;">,</span>html<span style="color: #339933;">:</span><span style="color: #000066;">status</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">': '</span> <span style="color: #339933;">+</span> text
        <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;">// scroll down</span>
        body.<span style="color: #660066;">scrollTo</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'top'</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">100000</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
    <span style="color: #006600; font-style: italic;">// create Ext.Direct test window</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>
         title<span style="color: #339933;">:</span><span style="color: #3366CC;">'Mastering Ext.Direct by Saki'</span>
        <span style="color: #339933;">,</span>width<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>closable<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">false</span>
        <span style="color: #339933;">,</span>layout<span style="color: #339933;">:</span><span style="color: #3366CC;">'border'</span>
        <span style="color: #339933;">,</span>border<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">false</span>
        <span style="color: #339933;">,</span>items<span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #006600; font-style: italic;">// west region with buttons</span>
             region<span style="color: #339933;">:</span><span style="color: #3366CC;">'west'</span>
            <span style="color: #339933;">,</span>width<span style="color: #339933;">:</span><span style="color: #CC0000;">160</span>
            <span style="color: #339933;">,</span>minSize<span style="color: #339933;">:</span><span style="color: #CC0000;">160</span>
            <span style="color: #339933;">,</span>split<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">true</span>
            <span style="color: #339933;">,</span>defaults<span style="color: #339933;">:</span><span style="color: #009900;">&#123;</span>minWidth<span style="color: #339933;">:</span><span style="color: #CC0000;">120</span><span style="color: #009900;">&#125;</span>
            <span style="color: #339933;">,</span>layout<span style="color: #339933;">:</span><span style="color: #3366CC;">'table'</span>
            <span style="color: #339933;">,</span>bodyStyle<span style="color: #339933;">:</span><span style="color: #3366CC;">'padding:20px'</span>
            <span style="color: #339933;">,</span>layoutConfig<span style="color: #339933;">:</span><span style="color: #009900;">&#123;</span>columns<span style="color: #339933;">:</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> tableAttrs<span style="color: #339933;">:</span><span style="color: #009900;">&#123;</span>style<span style="color: #339933;">:</span><span style="color: #009900;">&#123;</span>width<span style="color: #339933;">:</span><span style="color: #3366CC;">'100%'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#125;</span>
            <span style="color: #339933;">,</span>items<span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#123;</span>
                 xtype<span style="color: #339933;">:</span><span style="color: #3366CC;">'button'</span>
                <span style="color: #339933;">,</span>text<span style="color: #339933;">:</span><span style="color: #3366CC;">'Car.start()'</span>
&nbsp;
                <span style="color: #006600; font-style: italic;">// a delegate is needed if we want to pass arguments</span>
                <span style="color: #339933;">,</span>handler<span style="color: #339933;">:</span>Example.<span style="color: #660066;">Car</span>.<span style="color: #660066;">start</span>.<span style="color: #660066;">createDelegate</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#91;</span>callback<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span>
                 xtype<span style="color: #339933;">:</span><span style="color: #3366CC;">'button'</span>
                <span style="color: #339933;">,</span>text<span style="color: #339933;">:</span><span style="color: #3366CC;">'Car.go(80)'</span>
&nbsp;
                <span style="color: #006600; font-style: italic;">// a delegate is needed if we want to pass arguments</span>
                <span style="color: #339933;">,</span>handler<span style="color: #339933;">:</span>Example.<span style="color: #660066;">Car</span>.<span style="color: #660066;">go</span>.<span style="color: #660066;">createDelegate</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#91;</span><span style="color: #CC0000;">80</span><span style="color: #339933;">,</span> callback<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span>
                 xtype<span style="color: #339933;">:</span><span style="color: #3366CC;">'button'</span>
                <span style="color: #339933;">,</span>text<span style="color: #339933;">:</span><span style="color: #3366CC;">'Car.go(250)'</span>
&nbsp;
                <span style="color: #006600; font-style: italic;">// a delegate is needed if we want to pass arguments</span>
                <span style="color: #339933;">,</span>handler<span style="color: #339933;">:</span>Example.<span style="color: #660066;">Car</span>.<span style="color: #660066;">go</span>.<span style="color: #660066;">createDelegate</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#91;</span><span style="color: #CC0000;">250</span><span style="color: #339933;">,</span> callback<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span>
                 xtype<span style="color: #339933;">:</span><span style="color: #3366CC;">'button'</span>
                <span style="color: #339933;">,</span>text<span style="color: #339933;">:</span><span style="color: #3366CC;">'Car.stop()'</span>
&nbsp;
                <span style="color: #006600; font-style: italic;">// a delegate is needed if we want to pass arguments</span>
                <span style="color: #339933;">,</span>handler<span style="color: #339933;">:</span>Example.<span style="color: #660066;">Car</span>.<span style="color: #000066;">stop</span>.<span style="color: #660066;">createDelegate</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#91;</span>callback<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span>
                 xtype<span style="color: #339933;">:</span><span style="color: #3366CC;">'button'</span>
                <span style="color: #339933;">,</span>text<span style="color: #339933;">:</span><span style="color: #3366CC;">'Send All'</span>
&nbsp;
                <span style="color: #006600; font-style: italic;">// another option is inline function that executes calls</span>
                <span style="color: #339933;">,</span>handler<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>
&nbsp;
                    <span style="color: #006600; font-style: italic;">// the following calls will be combined in one request</span>
                    Example.<span style="color: #660066;">Car</span>.<span style="color: #660066;">start</span><span style="color: #009900;">&#40;</span>callback<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    Example.<span style="color: #660066;">Car</span>.<span style="color: #660066;">go</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">80</span><span style="color: #339933;">,</span> callback<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    Example.<span style="color: #660066;">Car</span>.<span style="color: #660066;">go</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">250</span><span style="color: #339933;">,</span> callback<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    Example.<span style="color: #660066;">Car</span>.<span style="color: #000066;">stop</span><span style="color: #009900;">&#40;</span>callback<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;">&#93;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span>
            <span style="color: #006600; font-style: italic;">// responses are displayed here</span>
             region<span style="color: #339933;">:</span><span style="color: #3366CC;">'center'</span>
            <span style="color: #339933;">,</span>autoScroll<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">true</span>
            <span style="color: #339933;">,</span>tbar<span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'-&gt;'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
                text<span style="color: #339933;">:</span><span style="color: #3366CC;">'Clear'</span>
               <span style="color: #339933;">,</span>handler<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>win.<span style="color: #660066;">items</span>.<span style="color: #660066;">itemAt</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">body</span>.<span style="color: #660066;">update</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#93;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#93;</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>
&nbsp;
<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;">// eof</span></pre></div></div>

</p>
<p>
Then tune your <code>index.php</code> so that it reads:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;?require_once<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;config.php&quot;</span><span style="color: #66cc66;">&#41;</span>;?&gt;</span>
<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>Mastering Ext.Direct by Saki<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;">style</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span>&gt;</span>
      .x-table-layout-cell {
        height:40px;
        text-align:center;
        vertical-align:middle;
    }
    .x-table-layout-cell table {
        margin:auto
    }
    .response {
        padding:4px 0 4px 20px;
        font-size:13px;
    }
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">style</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;api.php&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>&gt;</span>
      Ext.Direct.addProvider(Example.API);
  <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: #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;example.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: #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;</span>
<span style="color: #009900;">&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>
<h1>Conclusion</h1>
<p>Good! Play with Ext.Direct and let me know what you would like to have in next parts.<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/mastering-ext-direct-part-3/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Mastering Ext.Direct, Part 2</title>
		<link>http://blog.extjs.eu/know-how/mastering-ext-direct-part-2/</link>
		<comments>http://blog.extjs.eu/know-how/mastering-ext-direct-part-2/#comments</comments>
		<pubDate>Mon, 07 Sep 2009 20:50:58 +0000</pubDate>
		<dc:creator>Saki</dc:creator>
				<category><![CDATA[Know-how]]></category>

		<guid isPermaLink="false">http://blog.extjs.eu/?p=384</guid>
		<description><![CDATA[<br/>add() call and add /** @remotable */ comments to methods
multiple requests and responses are combined in one if they come fast enough

Mastering Ext.Direct, Part 3 >>>
]]></description>
			<content:encoded><![CDATA[<br/><h4><a href="http://blog.extjs.eu/know-how/mastering-ext-direct-part-1"><<< Mastering Ext.Direct, Part 1</a></h4>
<h1>Adding server-side classes</h1>
<p>
After completing part 1, we have the basic setup running. Although Ext.Direct PHP stack example classes are fine for demonstrating the functionality we will need our own PHP classes in the real life. I&#8217;m not going to explain basics of PHP object oriented programming, anyway, there is a couple of things to point out.
</p>
<p>
Let&#8217;s create (useless) class <code>Car</code> from part1. For that, create file <code>classes/Car.php</code> with the following content:
</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// vim: sw=4:ts=4:fdc=4:nospell</span>
    <span style="color: #000000; font-weight: bold;">class</span> Car <span style="color: #009900;">&#123;</span>
        <span style="color: #009933; font-style: italic;">/**
          * @remotable
          */</span>
        <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> start<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">&quot;Started&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// eo function start</span>
&nbsp;
        <span style="color: #009933; font-style: italic;">/**
          * @remotable
          */</span>
        <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> go<span style="color: #009900;">&#40;</span><span style="color: #000088;">$speed</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">&quot;The speed is <span style="color: #006699; font-weight: bold;">$speed</span>&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// eo function go</span>
&nbsp;
        <span style="color: #009933; font-style: italic;">/**
          * @remotable
          */</span>
        <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> stop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">&quot;Stopped&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// eo function stop</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> repair<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">&quot;Done&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// eo function repair</span>
&nbsp;
    <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// eo class car</span>
<span style="color: #666666; font-style: italic;">// eof</span></pre></div></div>

<p>Then edit <code>api.php</code> and add <code>Car</code> to <code>$api->add()</code> call so that it reads:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// ...</span>
<span style="color: #000088;">$api</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">add</span><span style="color: #009900;">&#40;</span>
    <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
        <span style="color: #0000ff;">'Echo'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'prefix'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Class_'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'Exception'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'prefix'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Class_'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'Time'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'File'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'Car'</span>
    <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// ...</span></pre></div></div>

<p>Reload <code>index.php</code> and type in Firebug console:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">Example.<span style="color: #660066;">Car</span>.<span style="color: #660066;">start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>You should get the following response:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;type&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;rpc&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;tid&quot;</span><span style="color: #339933;">:</span><span style="color: #CC0000;">2</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;action&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;Car&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;method&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;start&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;result&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;Started&quot;</span><span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now type:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">Example.<span style="color: #660066;">Car</span>.<span style="color: #660066;">repair</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Error, yes? Why? Take a deeper look at <code>Car</code> source code. Some methods have comments</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">        <span style="color: #009933; font-style: italic;">/**
          * @remotable
          */</span></pre></div></div>

<p>
but <code>repair</code> does not have it. And that is the single reason why it is not exported to API so it is not known to the client application. You can verify it by typing:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">Example.<span style="color: #660066;">API</span>.<span style="color: #660066;">actions</span>.<span style="color: #660066;">Car</span><span style="color: #339933;">;</span></pre></div></div>

<p> in Firebug console.</p>
<p>If you want to know how is it done study <code>ExtDirect_API</code> PHP class in <code>classes/API.php</code> file and <a href="http://php.net/manual/en/class.reflectionclass.php" target="_blank">ReflectionClass</a> documentation. In any case, it makes our life very easy as we only need to:</p>
<ul>
<li>write server side classes</li>
<li>add the above comment to the methods that can be called remotely</li>
</ul>
<p>Can it be simpler?</p>
<h1>Returning values</h1>
<p>Type in Firebug console:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>Example.<span style="color: #660066;">Car</span>.<span style="color: #660066;">start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Now you see that the return value of the call is <code>undefined</code> despite of the fact that server side method returns string <code>"Started"</code>. This leads us to a very important note:</p>
<p>
<strong>Ext.Direct calls are ASYNCHRONOUS.</strong>
</p>
<p>That means that the code execution does <strong>NOT</strong> wait until the call is finished but it immediately continues. So never try to use the return value, neither assume that you have data available at the line that follows the call.
</p>
<p>
The value returned from the server side method call is wrapped in the request response and it arrives when it arrives. It can take milliseconds or seconds depending on the connection speed, server execution time and other factors.
</p>
<p>I will discuss response processing in the next part</p>
<h1>Exceptions</h1>
<p>Edit <code>go</code> method of our <code>Car</code> class so that it reads:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">        <span style="color: #009933; font-style: italic;">/**
          * @remotable
          */</span>
        <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> go<span style="color: #009900;">&#40;</span><span style="color: #000088;">$speed</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span> <span style="color: #339933;">&gt;=</span> <span style="color: #000088;">$speed</span> <span style="color: #339933;">||</span> <span style="color: #cc66cc;">200</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$speed</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                throw <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Speed must be between 0 and 200&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">&quot;The speed is <span style="color: #006699; font-weight: bold;">$speed</span> <span style="color: #006699; font-weight: bold;">$unit</span>&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// eo function go</span></pre></div></div>

<p>and execute:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">Example.<span style="color: #660066;">Car</span>.<span style="color: #660066;">go</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">300</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>You get the following response:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;type&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;exception&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;tid&quot;</span><span style="color: #339933;">:</span><span style="color: #CC0000;">3</span><span style="color: #339933;">,</span>
<span style="color: #3366CC;">&quot;message&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;Speed must be between than 0 and 200&quot;</span><span style="color: #339933;">,</span>
<span style="color: #3366CC;">&quot;where&quot;</span><span style="color: #339933;">:</span>
<span style="color: #3366CC;">&quot;#0 [internal function]: Car-&gt;go(300)<span style="color: #000099; font-weight: bold;">\n</span>
#1 <span style="color: #000099; font-weight: bold;">\/</span>ddata1<span style="color: #000099; font-weight: bold;">\/</span>devel<span style="color: #000099; font-weight: bold;">\/</span>extjs.eu<span style="color: #000099; font-weight: bold;">\/</span>direct<span style="color: #000099; font-weight: bold;">\/</span>ExtDirect<span style="color: #000099; font-weight: bold;">\/</span>Router.php(176): call_user_func_array(Array, Array)<span style="color: #000099; font-weight: bold;">\n</span>
#2 <span style="color: #000099; font-weight: bold;">\/</span>ddata1<span style="color: #000099; font-weight: bold;">\/</span>devel<span style="color: #000099; font-weight: bold;">\/</span>extjs.eu<span style="color: #000099; font-weight: bold;">\/</span>direct<span style="color: #000099; font-weight: bold;">\/</span>ExtDirect<span style="color: #000099; font-weight: bold;">\/</span>Router.php(62): ExtDirect_Router-&gt;rpc(Object(stdClass))<span style="color: #000099; font-weight: bold;">\n</span>
#3 <span style="color: #000099; font-weight: bold;">\/</span>ddata1<span style="color: #000099; font-weight: bold;">\/</span>devel<span style="color: #000099; font-weight: bold;">\/</span>extjs.eu<span style="color: #000099; font-weight: bold;">\/</span>direct<span style="color: #000099; font-weight: bold;">\/</span>router.php(23): ExtDirect_Router-&gt;dispatch()<span style="color: #000099; font-weight: bold;">\n</span>
#4 {main}&quot;</span><span style="color: #009900;">&#125;</span></pre></div></div>

<p>
You see that the response type changed from <code>rpc</code> (remote procedure call) to <code>exception</code> and the response contains member <code>message</code> that is the text of the Exception we&#8217;ve thrown at server side. So far so good, however, <code>where</code> member contains debugging data that, while useful for debugging, shouldn&#8217;t be disclosed in a production environment.
</p>
<p>You can freely throw exceptions while debugging your Ext.Direct application but you should consider another method(s) of handling errors for production systems. I will tackle it again later in this series.
</p>
<h1>Combining requests</h1>
<p>Type the following:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">Example.<span style="color: #660066;">Car</span>.<span style="color: #660066;">start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>Example.<span style="color: #660066;">Car</span>.<span style="color: #660066;">go</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">80</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>Example.<span style="color: #660066;">Car</span>.<span style="color: #000066;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The request is:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#91;</span>
<span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;action&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;Car&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;method&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;start&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;data&quot;</span><span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;type&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;rpc&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;tid&quot;</span><span style="color: #339933;">:</span><span style="color: #CC0000;">4</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;action&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;Car&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;method&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;go&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;data&quot;</span><span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">80</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;type&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;rpc&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;tid&quot;</span><span style="color: #339933;">:</span><span style="color: #CC0000;">5</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;action&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;Car&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;method&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;stop&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;data&quot;</span><span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;type&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;rpc&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;tid&quot;</span><span style="color: #339933;">:</span><span style="color: #CC0000;">6</span><span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#93;</span></pre></div></div>

<p>and the response is:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#91;</span>
<span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;type&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;rpc&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;tid&quot;</span><span style="color: #339933;">:</span><span style="color: #CC0000;">4</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;action&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;Car&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;method&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;start&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;result&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;Started&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;type&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;rpc&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;tid&quot;</span><span style="color: #339933;">:</span><span style="color: #CC0000;">5</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;action&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;Car&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;method&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;go&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;result&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;The speed is 80&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;type&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;rpc&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;tid&quot;</span><span style="color: #339933;">:</span><span style="color: #CC0000;">6</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;action&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;Car&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;method&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;stop&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;result&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;Stopped&quot;</span><span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#93;</span></pre></div></div>

<p>Ext.Direct combines requests that come within a configurable time frame into one to minimize the server round trips count.</p>
<h1>Conclusion</h1>
<p>Now we know a couple of basics:</p>
<ul>
<li>we need to export API from server to client &#8211; Ext.Direct stack does a lot of dirty work for us</li>
<li>we can call server side methods directly at client prefixed with a configurable namespace (Example in our case)</li>
<li>we <strong>cannot</strong> use return values of client calls because calls are <strong>asynchronous</strong></li>
<li>to add classes we need to add them to $api->add() call and add /** @remotable */ comments to methods</li>
<li>multiple requests and responses are combined in one if they come fast enough
</ul>
<h4><a href="http://blog.extjs.eu/know-how/mastering-ext-direct-part-3">Mastering Ext.Direct, Part 3 >>></a></h4>
<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/mastering-ext-direct-part-2/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
