<?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>I Can Has Code?!? &#187; Ext JS</title>
	<atom:link href="http://icanhascode.com/tag/ext-js/feed/" rel="self" type="application/rss+xml" />
	<link>http://icanhascode.com</link>
	<description>No, not for you.</description>
	<lastBuildDate>Wed, 17 Jun 2009 07:22:14 +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>Code Quickie : Ensuring The Correct Accept Header In ExtJS</title>
		<link>http://icanhascode.com/2009/06/code-quickie-ensuring-the-correct-accept-header-in-extjs/</link>
		<comments>http://icanhascode.com/2009/06/code-quickie-ensuring-the-correct-accept-header-in-extjs/#comments</comments>
		<pubDate>Wed, 17 Jun 2009 07:17:32 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Code Quickie]]></category>
		<category><![CDATA[Ext JS]]></category>

		<guid isPermaLink="false">http://icanhascode.com/2009/06/code-quickie-ensuring-the-correct-accept-header-in-extjs/</guid>
		<description><![CDATA[When you are using any type of &#34;respond to&#34; functionality that is dependant on the Accept header in order to determine how to respond, it is important that any request you make against your application sends the appropriate headers.&#160; This is a pretty simple thing to do when you are making your own AJAX requests, [...]]]></description>
			<content:encoded><![CDATA[<p>When you are using any type of &quot;respond to&quot; functionality that is dependant on the <strong><em>Accept</em></strong> header in order to determine how to respond, it is important that any request you make against your application sends the appropriate headers.&#160; This is a pretty simple thing to do when you are making your own AJAX requests, but not always that simple when using library components, such as the <strong><em>JsonStore</em></strong>, provided by ExtJS.&#160; Below, I extend the built-in <strong><em>HttpProxy</em></strong> and<strong><em> TreeLoader</em></strong> to send the appropriate headers for the request.&#160; These extensions are done in place and require no additional code &#8230; though, a word of warning, these extensions may break with future versions of the ExtJS framework.&#160; The code below was tested with the RC1 release of ExtJS 3.0.</p>
<pre class="jscript" name="code">Ext.override(Ext.data.HttpProxy, {
    request: function(action, rs, params, reader, callback, scope, options) {
        if (this.conn &amp;&amp; reader)
        {
            this.conn.headers = this.conn.headers || {};

            if (this.conn.headers.hasOwnProperty(&#39;Accept&#39;) == false)
            {
                if (reader instanceof Ext.data.JsonReader)
                    this.conn.headers[&#39;Accept&#39;] = &#39;application/json&#39;;
                if (reader instanceof Ext.data.XmlReader)
                    this.conn.headers[&#39;Accept&#39;] = &#39;application/xml&#39;;
            }
        } 

        Ext.data.HttpProxy.superclass.request.apply(this, arguments);
    }
}); 

Ext.override(Ext.tree.TreeLoader, {
    requestData: function(node, callback){
        if(this.fireEvent(&quot;beforeload&quot;, this, node, callback) !== false){
            this.transId = Ext.Ajax.request({
                method:this.requestMethod,
                url: this.dataUrl||this.url,
                success: this.handleResponse,
                headers: {&#39;Accept&#39;: &#39;application/json&#39;},
                failure: this.handleFailure,
                scope: this,
                argument: {callback: callback, node: node},
                params: this.getParams(node)
            });
        }else{
            // if the load is cancelled, make sure we notify
            // the node that we are done
            if(typeof callback == &quot;function&quot;){
                callback();
            }
        }
    }
});</pre>
<p>There&#8217;s not too much to this code.&#160; In our extending of the <strong><em>HttpProxy</em>&#160;</strong>we override the <strong><em>request</em></strong> method which is only defined in the <strong><em>HttpProxy&#8217;s</em></strong> base class (and consequently inherited).&#160; In it, we check to see if there is a <strong><em>conn</em></strong> object as well as a <strong><em>reader</em></strong> and if there is, we check to see if an <strong><em>Accept</em></strong> has already been defined (just in case) and then we set the appropriate <strong><em>Accept</em></strong> header based on the type of <strong><em>reader</em></strong> that is being used.</p>
<p>For the <strong><em>TreeLoader </em></strong>extension, it&#8217;s not quite as simple.&#160; Since <strong><em>TreeLoader</em></strong> directly extends from <strong><em>Observable</em></strong> there&#8217;s no method we can easily override without overwriting, so for this one, we have to copy the functionality from the <strong><em>TreeLoader</em></strong> implementation itself.&#160; In doing so, we only have to add a <strong><em>headers</em></strong> property to the options for the AJAX request and we&#8217;re all set.</p>
]]></content:encoded>
			<wfw:commentRss>http://icanhascode.com/2009/06/code-quickie-ensuring-the-correct-accept-header-in-extjs/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Code Quickie : ExtJS JsonReader With Mapping Support For Use In AIR</title>
		<link>http://icanhascode.com/2009/05/code-quickie-extjs-jsonreader-with-mapping-support-for-use-in-air/</link>
		<comments>http://icanhascode.com/2009/05/code-quickie-extjs-jsonreader-with-mapping-support-for-use-in-air/#comments</comments>
		<pubDate>Wed, 20 May 2009 07:40:28 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Code Quickie]]></category>
		<category><![CDATA[Adobe AIR]]></category>
		<category><![CDATA[Ext JS]]></category>

		<guid isPermaLink="false">http://icanhascode.com/2009/05/code-quickie-extjs-jsonreader-with-mapping-support-for-use-in-air/</guid>
		<description><![CDATA[So, yesterday I decided to play around with Adobe AIR, which I&#8217;m not familiar with, in conjunction with Ext JS, which I am familiar with.  Overall, if you are familiar with Ext JS on the web, you&#8217;re familiar with it in Adobe AIR &#8230; except for a number of unique issues due to Adobe AIR&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>So, yesterday I decided to play around with Adobe AIR, which I&#8217;m not familiar with, in conjunction with Ext JS, which I am familiar with.  Overall, if you are familiar with Ext JS on the web, you&#8217;re familiar with it in Adobe AIR &#8230; except for a number of unique issues due to Adobe AIR&#8217;s default sandbox, mostly revolving around the sandbox and what you can and can&#8217;t do in it.  Well, I ran into an issue tonight where I needed to use a <strong><em>JsonReader</em></strong> and use <strong><em>Record</em></strong> mappings with dot notation (i.e. binding a field to a child object in the JSON data).  My guess is that, as is the case with <strong><em>eval</em></strong>, <strong><em>new Function(&#8230;)</em></strong>, which is what the default implementation of <strong><em>getJsonAccessor</em></strong> uses, is blocked by the sandbox.  I fixed it by extending the default <strong><em>JsonReader</em></strong> and providing a new implementation of <strong><em>getJsonAccessor</em></strong> using some code I created a while back for form binding in JavaScript.</p>
<pre class="jscript" name="code">JsonReader = Ext.extend(Ext.data.JsonReader, {
    exprToPath: function(expr) {
        var parts = expr.split(".");
        var path = [];
        Ext.each(parts, function(item, index, list) {
            var match = item.match(/([a-zA-Z0-9_]+)\[([^\]]+)\]/);
            if (match)
            {
                path.push(match[1]);
                if (/^\d+$/.test(match[2]))
                    path.push(parseInt(match[2]));
                else
                    path.push(match[2]);
            }
            else
            {
                path.push(item);
            }
        });
        return path;
    },  

    getDataValue: function(o, path) {
        var current = o;
        var rPath = path.slice().reverse();
        while (current &amp;&amp; rPath.length &gt; 0)
        {
            var key = rPath.pop();
            if (typeof current[key] !== &#39;undefined&#39;) current = current[key]; else return null;
        }

        return current;
    },

    getJsonAccessor: function(expr) {
        var self = this;
        var path = this.exprToPath(expr);
        return function(obj) {
            return self.getDataValue(obj, path);
        };
    }
});</pre>
<p>It&#8217;s probably a bit of overkill for what is needed, but it does work well.</p>
]]></content:encoded>
			<wfw:commentRss>http://icanhascode.com/2009/05/code-quickie-extjs-jsonreader-with-mapping-support-for-use-in-air/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.186 seconds -->
