<?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>Fusioncube &#187; Ext</title>
	<atom:link href="http://www.fusioncube.net/index.php/category/javascript/ext/feed" rel="self" type="application/rss+xml" />
	<link>http://www.fusioncube.net</link>
	<description>The online journey of a technophile, by Steve Brownlee</description>
	<lastBuildDate>Wed, 01 Feb 2012 04:17:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Scrolling pagination in Sencha ExtJS</title>
		<link>http://www.fusioncube.net/index.php/scrolling-pagination-in-ext</link>
		<comments>http://www.fusioncube.net/index.php/scrolling-pagination-in-ext#comments</comments>
		<pubDate>Thu, 20 May 2010 21:12:59 +0000</pubDate>
		<dc:creator>Steve Brownlee</dc:creator>
				<category><![CDATA[Ext]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[paging]]></category>
		<category><![CDATA[ExtJS]]></category>
		<category><![CDATA[pagination]]></category>
		<category><![CDATA[scrolling]]></category>
		<category><![CDATA[Sencha]]></category>

		<guid isPermaLink="false">http://www.fusioncube.net/?p=871</guid>
		<description><![CDATA[This is mainly for my own information retrieval, but perhaps it might be useful to another Javascript developer out there who is using ExtJS. I’ve got a list of several thousand insurance plans I need to display to the users of one of my applications. I originally implemented a standard Ext.PagingToolbar to add to the [...]]]></description>
			<content:encoded><![CDATA[<p>This is mainly for my own information retrieval, but perhaps it might be useful to another Javascript developer out there who is using ExtJS.</p>
<p>I’ve got a list of several thousand insurance plans I need to display to the users of one of my applications. I originally implemented a standard Ext.PagingToolbar to add to the footer of my data grid, but I’ve never been a fan of that navigation pattern, and I suspect that my users wouldn’t be either.</p>
<p>I then thought of sites like Google Reader that automatically retrieves the next set of records as soon as it detects that you’ve scrolled to a certain place in the reading element. A quick trip to my friend Google uncovered an <a href="http://www.codeproject.com/KB/ajax/AjaxScrollingPagination.aspx" target="_blank">article on The Code Project by Jason Witty</a> that provided an example of just this technique.</p>
<p>A quick adaptation to my application provided a working example:</p>
<pre class="brush: jscript; title: ; notranslate">
var emptyData;

// Set default scroll variables.
var currentpos = 0;
var currentpage = 1;

// Set constants.
//itemsperpage: number of records that appear on each page of content.
var itemsperpage = 100;

// Number of pages of content to fetch when offset reached.
var pagestofetch = 1;

// Number of pixel interval to fire handler request. You'll need to adjust this value
// depending on the location and size of your data grid
var scrolloffset = 1800;
var scrolloffsetinterval = 1800;

// Create the column model to display only the data needed for the users
var InsurerColumnModel = new Ext.grid.ColumnModel([{
       id:        'col1',
       header:    'Abbreviation',
       dataIndex: 'col1',
       width:     120
    },{
       id:        'col2',
       header:    'Name',
       dataIndex: 'col2',
       width:     240
    },{
       id:        'col3',
       header:    'Group',
       dataIndex: 'col3',
       width:     120
    }
]);

// Create a JSON Store to hold the data elements
var ScrollingProviderStore = new Ext.data.JsonStore({
	data:     emptyData,
	root:     'data',
	fields:   Insurer
});

// Create the grid to display each insurer
var InsurerGrid = new Ext.grid.GridPanel({
    store: ScrollingProviderStore,
    sm: new Ext.grid.RowSelectionModel({singleSelect:true}),
    cm: InsurerColumnModel,
    renderTo: 'insurer-display-grid',
    stripeRows: true,
    width:'auto',
    height:350,
    autoScroll: true,
    autoExpandColumn:'col2',
    title:'Insurance Plans',
    frame:true
});

// Create an event listener for when the user scrolls the grid
InsurerGrid.addListener('bodyscroll',scrollListener);

// Fires when grid is scrolled
function scrollListener(scrollLeft, scrollTop){
    // Only handle scroll downs past highest position.
    if ( scrollTop &gt; currentpos )
    {
        // Check if we should get more data
        if ( scrollTop &gt;  scrolloffset )
        {
            // Store current grid scroll state.
            var state = InsurerGrid.getView().getScrollState();

            // Adjust scroll offset
            scrolloffset = scrollTop + scrolloffsetinterval;

            // Adjust current page
            currentpage = currentpage + 1;

            $.AjaxCFC({
	        url: 'ajaxCFC/ajax.cfc',
	        factory: 'application.framework',
	        bean: 'Insurance',
	        method: 'listProviders',
	        data: { 'start': currentpage },
	        timeout:30000,
	        useDefaultErrorHandler: false,
	        success: function(result) {
	            var insurers = eval('(' + result + ')');
	            ScrollingProviderStore.loadData(insurers,true);

                    // Restore the scrollbar state back to where the user
                    // triggered the load.
                    InsurerGrid.getView().restoreScroll(state);
	        },
                error: function(results) {
	            Ext.MessageBox.alert('Failed', 'Failed to retrieve insurers. Please try again.');
	        }
	   });
        }

        currentpos=scrollTop;
    }
};
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.fusioncube.net/index.php/scrolling-pagination-in-ext/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Javascript argument collections within closures</title>
		<link>http://www.fusioncube.net/index.php/javascript-argument-collections-within-closures</link>
		<comments>http://www.fusioncube.net/index.php/javascript-argument-collections-within-closures#comments</comments>
		<pubDate>Thu, 17 Sep 2009 20:03:26 +0000</pubDate>
		<dc:creator>Steve Brownlee</dc:creator>
				<category><![CDATA[ajaxCFC]]></category>
		<category><![CDATA[Ext]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[closures]]></category>
		<category><![CDATA[ExtJS]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[message box]]></category>
		<category><![CDATA[Sencha]]></category>

		<guid isPermaLink="false">http://www.fusioncube.net/?p=653</guid>
		<description><![CDATA[I have to say, it&#8217;s been a refreshing break to work on one of our older apps that was written pre-Flex. Working on my old jQuery/ExtJS Javascript code has been fun and I&#8217;ve been able to add some new tricks I&#8217;ve learned in the last year and a half. One little tidbit that I thought [...]]]></description>
			<content:encoded><![CDATA[<p>I have to say, it&#8217;s been a refreshing break to work on one of our older apps that was written pre-Flex.  Working on my old jQuery/ExtJS Javascript code has been fun and I&#8217;ve been able to add some new tricks I&#8217;ve learned in the last year and a half.</p>
<p>One little tidbit that I thought I&#8217;d pass along is a simple trick that most Javascript developers know how to do, but may trip up someone just getting into advanced Javascript development with some of the major libraries out there.</p>
<p>Knowing the proper scope of your Javascript variables is a task that everyone who&#8217;s worked with the language knows is important.  Using libraries like jQuery and ExtJS make it a bit tricker.  An example is when you want to pass an entire argument collection from one function to another and then use that argument collection inside a closure for, say, an ExtJS MessageBox.</p>
<p>At first, you may have the desire to simply pass the argument array from the first function to the second.</p>
<pre class="code"><code>function confirm(one, two, three, four) {
    Ext.MessageBox.show({
        title: 'Confirmation',
        msg: 'Please confirm that you want to delete this.',
        buttons: Ext.MessageBox.YESNO,
        fn: function (btn) {
           if(btn == 'yes') doAction(arguments);
        }
    });
}

function doAction(one, two, three, four) {
    $.AjaxCFC({
        url: "com/acme/Widget.cfc",
        method: "delete",
        data: { 'one':one,
                'two':two,
                'three':three,
                'four':four
        }
    });
}</code></pre>
<p>But the execution block that actually calls the doAction() method in within a closure inside the main confirm() method. What this means is that the argument array actually contains the arguments for that anonymous function to handle the button click on the confirmation message.</p>
<p>What you need to do is preserve the arguments collection in a variable scoped to the confirm() method &#8211; which is available to the closure (one of the strengths of Javascript) &#8211; which can then be passed to the doAction() method.</p>
<p>You then use the apply() method on the function (the apply() method allows you to pass the arguments array) and pass that holding variable.</p>
<pre class="code"><code>function confirm(one, two, three, four) {
    var args = arguments;

    Ext.MessageBox.show({
        title: 'Confirmation',
        msg: 'Please confirm that you want to delete this.',
        buttons: Ext.MessageBox.YESNO,
        fn: function (btn) {
           if(btn == 'yes') doAction.apply(this, args);
        }
    });
}

function doAction() {
    var args = arguments;

    $.AjaxCFC({
        url: "com/acme/Widget.cfc",
        method: "delete",
        data: { 'one':args[0],
                'two':args[1],
                'three':args[2],
                'four':args[3]
        }
    });
}</code></pre>
<p>Javascript is such a beautiful and powerful language.  I have to say I&#8217;ve missed working with it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fusioncube.net/index.php/javascript-argument-collections-within-closures/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Sencha ExtJS: TwinTrigger Autocomplete Example</title>
		<link>http://www.fusioncube.net/index.php/ext-twintrigger-autocomplete-example</link>
		<comments>http://www.fusioncube.net/index.php/ext-twintrigger-autocomplete-example#comments</comments>
		<pubDate>Tue, 10 Jun 2008 18:02:27 +0000</pubDate>
		<dc:creator>Steve Brownlee</dc:creator>
				<category><![CDATA[ajax]]></category>
		<category><![CDATA[Ext]]></category>
		<category><![CDATA[autocomplete]]></category>
		<category><![CDATA[ComboBox]]></category>
		<category><![CDATA[ExtJS]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[Sencha]]></category>
		<category><![CDATA[twintrigger]]></category>

		<guid isPermaLink="false">http://www.fusioncube.net/?p=223</guid>
		<description><![CDATA[In addition to the basic ComboBox functionality available in the Ext library, there is a poorly-documented extension called the TwinTriggerField. This is simply a standard ComboBox with two control icons on the right which you can customize. This article is an extension of my Ext: Simple Autocomplete Example article, so please read that one as [...]]]></description>
			<content:encoded><![CDATA[<p>In addition to the basic <a href="http://extjs.com/deploy/dev/docs/?class=Ext.form.ComboBox">ComboBox</a> functionality available in the Ext library, there is a poorly-documented extension called the TwinTriggerField.  This is simply a standard <a href="http://extjs.com/deploy/dev/docs/?class=Ext.form.ComboBox">ComboBox</a> with two control icons on the right which you can customize.</p>
<p>This article is an extension of my <a href="http://www.fusioncube.net/?p=222">Ext: Simple Autocomplete Example</a> article, so please read that one as well to get all related code.  This article will simply show the additional code needed to make a TwinTrigger work.</p>
<p>By default the <a href="http://extjs.com/deploy/dev/docs/?class=Ext.form.ComboBox">ComboBox</a> will have the down arrow which allows users to see the available elements, but you can add another icon to the right of that which, when clicked,  can perform any function that you like.</p>
<h2>The TwinTrigger Class</h2>
<p>Start off by making a new Javascript file in your project named <strong>Ext.TwinTrigger.js</strong> and paste the following code into it. We&#8217;ll go through the code later to show what&#8217;s going on.</p>
<pre class="code"><code>Ext.form.TwinTriggerField = function(config) {
    Ext.form.TwinTriggerField.superclass.constructor.apply(this, arguments);
};
Ext.extend(Ext.form.TwinTriggerField, Ext.form.ComboBox, {

    trigger1Class: 'x-form-search-trigger',
    trigger2Class: 'x-form-select-trigger',

    initComponent : function(){
        Ext.form.TwinTriggerField.superclass.initComponent.call(this);
        this.record = new Object();
        this.triggerConfig = {
            tag:'span', cls:'x-form-twin-triggers', cn:[
            {tag: "img", src: Ext.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.trigger1Class},
            {tag: "img", src: Ext.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.trigger2Class}
        ]};
    },
    getTrigger : function(index){
        return this.triggers[index];
    },
    initTrigger : function(){
        var ts = this.trigger.select('.x-form-trigger', true);
        var triggerField = this;
        ts.each(function(t, all, index){
            t.hide = function(){
                var w = triggerField.wrap.getWidth();
                this.dom.style.display = 'none';
                triggerField.el.setWidth(w-triggerField.trigger.getWidth());
            };
            t.show = function(){
                var w = triggerField.wrap.getWidth();
                this.dom.style.display = '';
                triggerField.el.setWidth(w-triggerField.trigger.getWidth());
            };
            var triggerIndex = 'Trigger'+(index+1);

            if(this['hide'+triggerIndex]){
                t.dom.style.display = 'none';
            }
            t.on("click", this['on'+triggerIndex+'Click'], this, {preventDefault:true});
            t.addClassOnOver('x-form-trigger-over');
            t.addClassOnClick('x-form-trigger-click');
        }, this);
        this.triggers = ts.elements;
    },
    onTrigger1Click : function() {
        this.onTriggerClick();
    },
    onTrigger2Click : function() {
        this.onTrigger2Click();
    }
});</code></pre>
<h2>The User&#8217;s View</h2>
<p>Then include your file in an HTML page.</p>
<pre class="code"><code>&lt;html&gt;
&lt;head&gt;
    &lt;link href="css/ext-all.css" rel="stylesheet" type="text/css"&gt;

    &lt;script type="text/javascript" src="js/ext-all.js"&gt;&lt;/script&gt;
    &lt;script type="text/javascript" src="js/Ext.TwinTrigger.js"&gt;&lt;/script&gt;
    &lt;script type="text/javascript" src="js/interaction.example.js"&gt;&lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;
    &lt;input type="text" size="20" id="facilitySearchField"&gt;
&lt;/body&gt;
&lt;/html&gt;</code></pre>
<h2>The Interaction Layer</h2>
<p>And in your interaction layer, create an instance of your TwinTrigger field. In this example, you&#8217;ll see I&#8217;m using the <em>facilityStore</em> object that I set up in the previous article.</p>
<pre class="code"><code>var search = new Ext.form.TwinTriggerField({
    applyTo:'divName',
    displayField:'name',
    store: facilityStore,
    minChars:4,
    forceSelection:true,
    width: 210,
    listWidth:350,
    onSelect: function(record){    },
    onTrigger2Click: function(){    }
});</code></pre>
<h2>Custom Style for Second Trigger</h2>
<p>If you want to have a custom icon for the 2nd trigger, you&#8217;ll have to do two things.</p>
<p>First, define a custom CSS class and specify it in the Ext.TwinTrigger.js file.  You can name this class anything you like, but try to keep it consistent with Ext&#8217;s naming conventions.  You can see the one that I chose in my code above.</p>
<pre class="code"><code>trigger2Class: 'x-form-select-trigger',</code></pre>
<p>Second, modify the ext-all.css style sheet and specify the image that you&#8217;d like to use for your new class.</p>
<pre class="code"><code>.x-form-field-wrap .x-form-select-trigger{background-image:url(../images/default/form/select-trigger.gif);cursor:pointer;}</code></pre>
<h2>The Guts</h2>
<p>Now that I&#8217;ve laid all the code out, I show you the code to focus on.  The important code in your TwinTrigger class is&#8230;</p>
<pre class="code"><code>onTrigger2Click : function() {
    this.onTrigger2Click();
}</code></pre>
<p>What this does is expose a new event that you can handle in your interaction layer.</p>
<pre class="code"><code>onTrigger2Click: function(){
    // Do something wonderful when the user clicks the 2nd trigger icon
}</code></pre>
<p>Those are the basics for having two trigger icons for a ComboBox.  Like I said, refer to my previous article on how to get the basics of a autocomplete ComboBox working, and then implement this code if you need it.</p>
<p>Comments and questions, as always, are welcome.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fusioncube.net/index.php/ext-twintrigger-autocomplete-example/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Sencha ExtJS: Simple Autocomplete Example</title>
		<link>http://www.fusioncube.net/index.php/ext-simple-autocomplete-example</link>
		<comments>http://www.fusioncube.net/index.php/ext-simple-autocomplete-example#comments</comments>
		<pubDate>Mon, 09 Jun 2008 22:03:06 +0000</pubDate>
		<dc:creator>Steve Brownlee</dc:creator>
				<category><![CDATA[ajax]]></category>
		<category><![CDATA[Ext]]></category>
		<category><![CDATA[recommended]]></category>
		<category><![CDATA[autocomplete]]></category>
		<category><![CDATA[ComboBox]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[ExtJS]]></category>
		<category><![CDATA[httpproxy]]></category>
		<category><![CDATA[Sencha]]></category>

		<guid isPermaLink="false">http://www.fusioncube.net/?p=222</guid>
		<description><![CDATA[An article to show how to implement the Ext autocomplete ComboBox feature]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s somewhat difficult to find examples of the autocomplete ComboBox that the Ext library provides, so I&#8217;ll add another one to the mix in the hopes that it makes it easier for future implementers to find.</p>
<p>First, let&#8217;s look at the code you need.  The Ext stylesheet and the ext-all.js library.  Then you&#8217;ll need your own, custom interaction code.  My naming convention is to start with <em>interaction</em> and then the page to which the code applies.</p>
<pre class="code"><code>&lt;link href="css/ext-all.css" rel="stylesheet" type="text/css"&gt;

&lt;script type="text/javascript" src="js/ext-all.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="js/interaction.example.js"&gt;&lt;/script&gt;</code></pre>
<p>This article is going to focus on the <a href="http://extjs.com/deploy/dev/docs/?class=Ext.data.HttpProxy">HTTPProxy</a> code for the autocomplete feature. The one argument you need is URL, and it value will be the name of the file that is actually going to perform the query and return the results. This code is simply creating a connection to a page that will be used when the user types in a search string.</p>
<p>In the example I&#8217;m pulling from, I&#8217;m searching against a list of facilities for the company.</p>
<pre class="code"><code>facilityProxy = new Ext.data.HttpProxy({url: 'liveQueries/facilities.cfm'});</code></pre>
<p>When the user types in a search string, Ext will then use the <a href="http://extjs.com/deploy/dev/docs/?class=Ext.data.HttpProxy">HTTPProxy</a> to call <em>facilities.cfm</em> with a URL variable named <em>query</em> that contains the search string.  Therefore, if the user typed in &#8216;PHIL&#8217;, the proxy URL would be <strong>liveQueries/facilities.cfm?query=PHIL</strong>.</p>
<p>Now let&#8217;s look at the <em>facilities.cfm</em> code. First, we have to capture the <em>query</em> variable being passed to the page by Ext, which can be done simply with a &lt;cfparam&gt; tag. Then we execute our query.  Once we have the resultset, we&#8217;ll need to serialize it.  I like JSON serialization, so I used the <a href="http://www.epiphantastic.com/cfjson/">CFJSON</a> code from Thomas Messier, Jehiah Czebotar, and others.</p>
<pre class="code"><code>&lt;cfsetting enablecfoutputonly="true"&gt;

&lt;cfparam name="query" default=""&gt;

&lt;cfquery name="facilities" datasource="#datasource_name#"&gt;
select unique facility_no, facility_legal_name
from chg_facility
where (REGEXP_LIKE(facility_no,'#query#','i') OR REGEXP_LIKE(facility_legal_name,'#query#','i'))
order by facility_no asc
&lt;/cfquery&gt;

&lt;cfscript&gt;
jsonBean = createobject("component","webapps.charm.model.ajax.JSON");
jsonEncodedCriteria = jsonBean.encode(data=facilities, queryFormat="array");
writeOutput(jsonEncodedCriteria);
&lt;/cfscript&gt;

&lt;cfsetting enablecfoutputonly="false"&gt;</code></pre>
<p>Ok, so now we&#8217;ve got a JSON-serialized query. What do we do with it?  Well, Ext just happens to have a built-in <a href="http://extjs.com/deploy/dev/docs/?class=Ext.data.JsonReader">JSON reader</a>. Just create a new JsonReader object, tell it what node contains the data (in our case, the node name is <strong>data</strong>) and optionally provide a <strong>totalProperty</strong> argument that contains the total number of records returned.</p>
<p>You then provide a defintion of what a single record of data consist.  You can define a seperate object called a <a href="http://extjs.com/deploy/dev/docs/?class=Ext.data.Record">Record</a>&#8230;.</p>
<pre class="code"><code>facilityRecord = Ext.data.Record.create([
    {name: 'facility_no',         	type: 'string'},
    {name: 'facility_legal_name',	type: 'string'}
]); 

facilityReader = new Ext.data.JsonReader({
    root: 			"data",
    totalProperty:	"recordcount"
}, facilityRecord);</code></pre>
<p>Or just do it inline if the record is simple enough.</p>
<pre class="code"><code>facilityReader = new Ext.data.JsonReader({
    root: 			"data",
    totalProperty:	"recordcount"
}, [
	{name: 'facility_no',         	type: 'string'},
	{name: 'facility_legal_name',	type: 'string'}
]);</code></pre>
<p>Alright, so we&#8217;ve got a proxy object to <em>facilities.cfm</em> that will perform the query on the user&#8217;s search string and return JSON-serialized data.  We&#8217;ve defined the structure of each record, and use a built-in JSON reader to parse the results.</p>
<p>Lastly, we need to populate a data <a href="http://extjs.com/deploy/dev/docs/?class=Ext.data.Store">Store</a> with the deserialized data set that we&#8217;ve retrieved. We simply provide it with the name of the proxy we&#8217;ll be using and which reader it should use to deserialize the data.</p>
<pre class="code"><code>facilityStore = new Ext.data.Store({
    proxy: facilityProxy,
    reader: facilityReader
});</code></pre>
<p>You can also define each element inline instead of creating a separate variables for each object. Here&#8217;s an example:</p>
<pre class="code"><code>new Ext.data.Store({
    proxy: new Ext.data.HttpProxy({url: 'liveQueries/facilities.cfm'}),
    reader: new Ext.data.JsonReader({
        root: 			"data",
        totalProperty:	"recordcount"
    }, [
    	{name: 'facility_no',         	type: 'string'},
    	{name: 'facility_legal_name',	type: 'string'}
	])
})</code></pre>
<p>Now that&#8217;s we&#8217;ve got some interaction code running, let&#8217;s start creating the actual <a href="http://extjs.com/deploy/dev/docs/?class=Ext.form.ComboBox">ComboBox</a>. Create a simple HTML file and place an input element on the page with a unique name.</p>
<pre class="code"><code>&lt;input type="text" size="20" id="facilitySearchField"&gt;</code></pre>
<p>Then, back in your interaction code, let&#8217;s create a <a href="http://extjs.com/deploy/dev/docs/?class=Ext.form.ComboBox">ComboBox</a> instance and tell it to use the data store that we&#8217;ve already defined.</p>
<pre class="code"><code>var search = new Ext.form.ComboBox({
    store: facilityStore,
    minChars:2,
    itemSelector: 'div.search-item',
    tpl: new Ext.XTemplate(
        '&lt;tpl for="."&gt;&lt;div class="search-item"&gt;',
            '{facility_no} - {facility_legal_name}',
        '&lt;/div&gt;&lt;/tpl&gt;'
    ),
    onSelect: function(record){
        // What you want to happen when the enter selects a record (or hit the ENTER key)
    	// Example (redirect to another page):
        //    document.location.href = 'showFacilityDetails.cfm?facilitySelected&amp;fid=' + record.data.facility_no;
    }
});

// Apply the comboBox to the &amp;lt;input&amp;gt; element in our HTML page.
search.applyTo('facilitySearchField');</code></pre>
<h2>Summary</h2>
<h4>HTML Code (example.htm)</h4>
<pre class="code"><code>&lt;html&gt;
&lt;head&gt;
    &lt;link href="css/ext-all.css" rel="stylesheet" type="text/css"&gt;

    &lt;script type="text/javascript" src="js/ext-all.js"&gt;&lt;/script&gt;
    &lt;script type="text/javascript" src="js/interaction.example.js"&gt;&lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;
    &lt;input type="text" size="20" id="facilitySearchField"&gt;
&lt;/body&gt;
&lt;/html&gt;</code></pre>
<h4>Javascript Code (interaction.example.js)</h4>
<pre class="code"><code>facilityProxy = new Ext.data.HttpProxy({url: 'liveQueries/facilities.cfm'});

facilityRecord = Ext.data.Record.create([
    {name: 'facility_no',         	type: 'string'},
    {name: 'facility_legal_name',	type: 'string'}
]); 

facilityReader = new Ext.data.JsonReader({
    root: 			"data",
    totalProperty:	"recordcount"
}, facilityRecord);

facilityStore = new Ext.data.Store({
    proxy: facilityProxy,
    reader: facilityReader
});

var search = new Ext.form.ComboBox({
    store: facilityStore,
    minChars:2,
    itemSelector: 'div.search-item',
    tpl: new Ext.XTemplate(
        '&lt;tpl for="."&gt;&lt;div class="search-item"&gt;',
            '{facility_no} - {facility_legal_name}',
        '&lt;/div&gt;&lt;/tpl&gt;'
    ),
    onSelect: function(record){   }
});
search.applyTo('facilitySearchField');</code></pre>
<h4>ColdFusion Code (facilities.cfm)</h4>
<pre class="code"><code>&lt;cfsetting enablecfoutputonly="true"&gt;

&lt;cfparam name="query" default=""&gt;

&lt;cfquery name="facilities" datasource="#datasource_name#"&gt;
    // Perform search based on user's search string (query parameter)
&lt;/cfquery&gt;

&lt;cfscript&gt;
jsonBean = createobject("component","webapps.model.ajax.JSON");
jsonEncodedCriteria = jsonBean.encode(data=facilities, queryFormat="array");
writeOutput(jsonEncodedCriteria);
&lt;/cfscript&gt;

&lt;cfsetting enablecfoutputonly="false"&gt;</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.fusioncube.net/index.php/ext-simple-autocomplete-example/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Soup for the Brain: jQuery, Sencha ExtJS and ajaxCFC</title>
		<link>http://www.fusioncube.net/index.php/soup-for-the-brain-jquery-ext-and-ajaxcfc</link>
		<comments>http://www.fusioncube.net/index.php/soup-for-the-brain-jquery-ext-and-ajaxcfc#comments</comments>
		<pubDate>Tue, 08 Jan 2008 16:40:28 +0000</pubDate>
		<dc:creator>Steve Brownlee</dc:creator>
				<category><![CDATA[ajax]]></category>
		<category><![CDATA[ajaxCFC]]></category>
		<category><![CDATA[Ext]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[accordion]]></category>
		<category><![CDATA[ajaxcfc]]></category>
		<category><![CDATA[button]]></category>
		<category><![CDATA[datepicker]]></category>
		<category><![CDATA[ExtJS]]></category>
		<category><![CDATA[infopanel]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[Sencha]]></category>

		<guid isPermaLink="false">http://www.fusioncube.net/?p=186</guid>
		<description><![CDATA[These three Javascript libraries are at the core of how I build fun, well-organized, and easy to maintain web applications. Each one serves a different purpose: jQuery &#8211; The best at DOM selection, manipulation and searching Ext &#8211; Makes all my little widgets look great and fun for the users ajaxCFC &#8211; Handles calls to [...]]]></description>
			<content:encoded><![CDATA[<p>These three Javascript libraries are at the core of how I build fun, well-organized, and easy to maintain web applications.  Each one serves a different purpose:</p>
<ul>
<li><a href="http://jquery.com/">jQuery</a> &#8211; The best at DOM selection, manipulation and searching</li>
<li><a href="http://extjs.com/">Ext</a> &#8211; Makes all my little widgets look great and fun for the users</li>
<li><a href="http://ajaxcfc.com/trac">ajaxCFC</a> &#8211; Handles calls to my business logic and serialization of data</li>
</ul>
<p>I&#8217;ll start off with a nice example of how these three libraries play well together and can make an otherwise complicated action very simple and easy to write. </p>
<p>This code has three pieces of functionality.  I&#8217;m using the <a href="http://kelvinluck.com/assets/jquery/datePicker/v2/demo/">jQuery Datepicker</a> on my page, and when the user selects a date from the calendar, I want the database to immediately be updated with the date chosen.  If the method fails, throw up a nice message box with a failure message and ask the user to try again.</p>
<pre class="code"><code>// Use jQuery to bind the dataSelected event of the jQuery DatePicker
$('#requestDueDate').bind('dateSelected',function(e, selectedDate, $td){
        // Use ajaxCFC to call the updateRequestDates() function of the Request component
	$.AjaxCFC({
		url: "model/ajax/request/Request.cfc",
		useDefaultErrorHandler: false,
		method: "updateRequestDates",
		data: { 'request_hdr_seq_no': request_hdr_seq_no,
			'request_due_date': selectedDate.asString(),
			'test_completion_date':$("#testCompletionDate").val() },
		timeout:30000,
		success: submitRequestCheck,
		error: function(results) {
                        // If the call fails, throw up an Ext message box to alert the user
			Ext.MessageBox.alert('Update Failed', "Failed to update the request due date. Please try again.");
			$('input#testCompletionDate').val("");
		}
	});
});</code></pre>
<p>All I was required to do was write 14 lines of code. Now, I can&#8217;t even imagine having to write this code without the use of the Big 3.</p>
<p>Now for one of my favorite features of this site (it&#8217;s actually a boring feature, but how I implemented it is cool).<br />
<img src='http://www.fusioncube.net/wp-content/uploads/2007/12/notes_dialog1.png' alt='Notes Accordion Dialog II' /></p>
<p>This is just a simple note feature where users can record any pertinent information about the work they are performing.  I&#8217;m using the <a href="http://www.aariadne.com/accordion/">Ext Accordion Widget</a> to display all past notes.  You can see how the user can expand and contract each note item &#8211; not really needed, but never hurts to wow the users a little.</p>
<p>This particular page was written to operate as a true application.  Any changes to the UI are immediately written to the database via AJAX calls.  The UI is then updated when the operation completes, and the user can continue working while several tasks are being executed.  No page reloads at all.</p>
<p>So when they add a note, it must be inserted into the database, and the Accordian object must have a new panel added to it, with the new text inserted inside.</p>
<p>I&#8217;ll admit, it stretched all my capabilities and imagination for Javascript programming.  All in all, it took over 3 days of trying different things, and research, to get it to work.</p>
<p>First, I had to include the required features of the libraries.</p>
<pre class="code"><code>&lt;script type="text/javascript" src="js/jquery.AjaxCFC.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="js/json.js"&gt;&lt;/script&gt;

&lt;script type="text/javascript" src="js/ext-buttons.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="js/ext-layout.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="js/Ext.ux.InfoPanel.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="js/Ext.ux.Accordion.js"&gt;&lt;/script&gt;</code></pre>
<p><sup>*This adds up to 300k of jQuery/Ext Javascript libraries.</sup></p>
<p>Then, I build the &lt;div&gt; element that will be used to display the dialog and the accordion panels</p>
<pre class="code"><code>&lt;div id="NoteModalDialog"&gt;
	&lt;div class="x-dlg-hd"&gt;Request Notes&lt;/div&gt;
	&lt;div class="x-dlg-bd"&gt;
       	&lt;div class="x-dlg-tab" title="Notes"&gt;
			&lt;div id="RequestNoteForm"&gt;&lt;/div&gt;
			&lt;div style="font-size:1.1em; font-weight:800;"&gt;Previous Notes&lt;/div&gt;
			&lt;div id="acc-ct" style="width:100%; height:200px"&gt;
				&lt;cfloop query="requestNotesQuery"&gt;
					&lt;cfoutput&gt;
					&lt;div id="panel-#currentRow#"&gt;
						&lt;div&gt;
							#first_name# #last_name# - #setup_date#:
						&lt;/div&gt;
						&lt;div&gt;
							&lt;div class="text-content"&gt;#note_txt#&lt;/div&gt;
							&lt;div style="border-bottom:5px solid white;"&gt;&lt;/div&gt;
						&lt;/div&gt;
					&lt;/div&gt;
					&lt;/cfoutput&gt;
				&lt;/cfloop&gt;
			&lt;/div&gt;
		&lt;/div&gt;
	&lt;/div&gt;
&lt;/div&gt;</code></pre>
<p>Then I instantiate the accordion object and build all the panels with previous notes</p>
<pre class="code"><code>$(document).ready(function(){
	// Create accordion to hold previous notes in note popup
	var accordion = new Ext.ux.Accordion('acc-ct', { height:400,independent:true});

	// Create a panel for each previous note
	&lt;cfloop query="requestNotesQuery"&gt;&lt;cfoutput&gt;
		var panel#currentRow# = accordion.add(new Ext.ux.InfoPanel('panel-#currentRow#', {collapsed:false}));
	&lt;/cfoutput&gt;&lt;/cfloop&gt;
}</code></pre>
<p>Then, of course, I need my wonderful Javascript object that handles building the dialog, saving the note, and loading of previous notes back into the UI/DOM. </p>
<p>It first builds a dynamic Ext form (which includes validation).</p>
<pre class="code"><code>var noteForm = new Ext.form.Form({ labelWidth:25 });
var noteText = new Ext.form.TextArea({
	fieldLabel: 'Note',
	name: 'noteText',
	width:375,
	allowBlank:false,
	grow:true,
	growMax:200,
	emptyText:"Enter your request notes here..."
});
noteForm.add(noteText);</code></pre>
<p>Then using ajaxCFC, I insert the data into database</p>
<pre class="code"><code>$.AjaxCFC({
	url: "model/ajax/note/Note.cfc",
	useDefaultErrorHandler: false,
	method: "add",
	async:false,
	data: { 'seq_no': request_hdr_seq_no, 'note_type':'REQUESTHDR', 'note_txt': noteText.getValue() },
	timeout:30000,
	success: function(results) {
		// Reset the note field to blank
		noteText.setRawValue("");

		{{ This nested ajaxCFC call code shown below }}
	},
	error: function(results) {
		Ext.MessageBox.alert('Save Failed', results.responseText);
	}
});</code></pre>
<p>Upon success of the insertion of the data, update the UI by adding a panel to the Accordion object with the new note inside.</p>
<pre class="code"><code>// Return all notes from the database for this request
$.AjaxCFC({
	url: "model/ajax/request/Request.cfc",
	useDefaultErrorHandler: false,
	method: "getAllRequestNotes",
	async:false,
	data: { 'request_hdr_seq_no': request_hdr_seq_no },
	timeout:30000,
	success: function(results) {
		// Empty out the current accordion object and re-populate it with a panel for each note
		var panel = new Object();
		var accordion = new Ext.ux.Accordion('acc-ct', { height:'400', independent:true });
		$("#acc-ct").empty();

		for(i=0; i&lt;results.NOTECOUNT;i++) {
			$("#acc-ct").append('&lt;div id="panel-' + i + '"&gt;&lt;div&gt;' + results.PANELS[i].FIRST_NAME + ' ' + results.PANELS[i].LAST_NAME + ' - ' +    results.PANELS[i].SETUP_DATE + '&lt;/div&gt;&lt;div&gt;&lt;div class="text-content"&gt;' + results.PANELS[i].NOTE_TXT + '&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;');
			panel[i] = accordion.add(new Ext.ux.InfoPanel('panel-'+i, {collapsed:false}));
		}
	},
	error: function(results) {
		Ext.MessageBox.alert('UI Update Failed', "Failed to update Notes popup with latest note.");
	}
});</code></pre>
<p>I put it all together, and I get a self-documenting, elegant Javascript object that handles user notes.</p>
<pre class="code"><code>// Create the object that will be used for the Request Notes popup
var requestNotesEdit = function() {
	var dialog;
	var noteForm = new Ext.form.Form({ labelWidth:25 });
	var noteText = new Ext.form.TextArea({
		fieldLabel: 'Note',
		name: 'noteText',
		width:375,
		allowBlank:false,
		grow:true,
		growMax:200,
		emptyText:"Enter your request notes here..."
	});
	noteForm.add(noteText);

	return {
		init : function() { this.buildDialog(); },
		saveData : function() {
			if (noteForm.isValid()) {

				$.AjaxCFC({
					url: "model/ajax/note/Note.cfc",
					useDefaultErrorHandler: false,
					method: "add",
					async:false,
					data: { 'seq_no': request_hdr_seq_no, 'note_type':'REQUESTHDR', 'note_txt': noteText.getValue() },
					timeout:30000,
					success: function(results) {
						// Reset the note field to blank
						noteText.setRawValue("");

						// Return all notes from the database for this request
						$.AjaxCFC({
							url: "model/ajax/request/Request.cfc",
							useDefaultErrorHandler: false,
							method: "getAllRequestNotes",
							async:false,
							data: { 'request_hdr_seq_no': request_hdr_seq_no },
							timeout:30000,
							success: function(results) {

								// Empty out the current accordion object and re-populate it with a panel for each note
								var panel = new Object();
								var accordion = new Ext.ux.Accordion('acc-ct', { height:'400', independent:true });
								$("#acc-ct").empty();

								for(i=0; i&lt;results.NOTECOUNT;i++) {
									$("#acc-ct").append('&lt;div id="panel-' + i + '"&gt;&lt;div&gt;' + results.PANELS[i].FIRST_NAME + ' ' + results.PANELS[i].LAST_NAME + ' - ' +    results.PANELS[i].SETUP_DATE + '&lt;/div&gt;&lt;div&gt;&lt;div class="text-content"&gt;' + results.PANELS[i].NOTE_TXT + '&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;');
									panel[i] = accordion.add(new Ext.ux.InfoPanel('panel-'+i, {collapsed:false}));
								}
							},
							error: function(results) {
								Ext.MessageBox.alert('UI Update Failed', "Failed to update Notes popup with latest note.");
							}
						});

					},
					error: function(results) {
						Ext.MessageBox.alert('Save Failed', results.responseText);
					}
				});

				dialog.hide();
			}else{
				Ext.Msg.alert('Field Required', 'Please enter in some note text before submitting.');
			}
		},
		buildDialog : function() {
			noteForm.render('RequestNoteForm');
			dialog = new Ext.BasicDialog("NoteModalDialog", {
				modal:true,
			    width:450,
			    height:350,
			    shadow:true,
			    minWidth:400,
			    minHeight:300,
			    animateTarget:'requestNotes'
			});
			dialog.addKeyListener(27, this.hideWindow, this);
	        dialog.addButton('Save', this.saveData, this);
	        dialog.addButton('Cancel', this.hideWindow, this);
		},
		showWindow : function() { dialog.show(); },
		hideWindow : function() { dialog.hide(); }
	};
};</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.fusioncube.net/index.php/soup-for-the-brain-jquery-ext-and-ajaxcfc/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

