Ext

Archive for June, 2008

Fun with Ext JS and Aptana Jaxer

Tuesday, June 10th, 2008

Shortly after Aptana released Jaxer, a new server-side JavaScript platform, I was able to spend some time running Ext JS code on the server-side. Jaxer facilitates a tightly knit integration between the client and server by allowing you to include JS code that will be run on the server, client, both, or as a server-proxy. The server-proxy allows Jaxer to wrap client and server-side communications up allowing either synchronous or asynchronous calls between the client and server. Jaxer provides a means for file, database or even socket access as one would expect from a server-side platform. Check out Aptana Jaxer for more details on how you can leverage your JavaScript skills on the server-side.

Jaxer Store and the Ext Grid

Download the complete source for these examples if you would like to setup the code on your own Jaxer server. This first example shows off a very simple wrapper around an Ext.data.Store and the corresponding Jaxer server code.

JaxerStoreServer.js contains a simple server side function that builds and executes a query. It assumes that you have already properly configured Jaxer’s config.js to point to the corresponding database. Notice that no server-side post processing is involved as it natively returns a JSON object.

function ExtJaxerProxy(params) {
   var fld = [], q = [];
   var fields = params.fields;
   for (var i = 0; i < fields.length; i++) {
       if (typeof fields[i] == 'string') {
           fld.push(fields[i]);
           q.push('?');
       } else if (typeof fields[i] == 'object') {
           fld.push(fields[i].name);
           q.push('?');
       }
   }
 
   var qp = fld;
 
   var query = 'SELECT ' + fld.join(',') + ' FROM ' + params.table;
   if (params.sortInfo) {
       query += ' ORDER BY ' + params.sortInfo.sort + ' '
               + params.sortInfo.dir;
       qp.push(params.sortInfo.sort);
       qp.push(params.sortInfo.dir);
   }
   if (params.start && params.limit) {
       query += ' START ' + params.start + ' LIMIT ' + params.limit;
       qp.push(params.start);
       qp.push(params.limit);
   }
   return Jaxer.DB.execute(query);
}

JaxerStore.js contains a very simple Ext data store to deal with connecting to Jaxer. This utilizes the built in ‘Async’ function that Jaxer wraps around all functions contained in a ’server-proxy’ include.

Ext.data.JaxerStore = function(config) {
   var params = Ext.apply({
       fields : config.fields,
       table : config.table
   }, config.baseParams || {});
 
   Ext.data.JaxerStore.superclass.constructor.call(this, 
       Ext.applyIf(config, {
       reader : new Ext.data.JsonReader(Ext.apply({
           root : 'rows'
       }, config.readerConfig), config.fields)
   }));
   ExtJaxerProxyAsync(this.loadData.createDelegate(this), params);
};
Ext.extend(Ext.data.JaxerStore, Ext.data.Store);

Make sure both files are being included on your page, along with Ext.JaxerStore should be running in the client and JaxerStoreServer should be running as a ’server-proxy’. With the Jaxer store and server proxy in place, it’s only a matter of creating an instance of the store and hooking it up to a component that can use the data. Here we create the Jaxer store (notice that it now requires an additional table parameter), then we create a simple GridPanel and pass along our new-fangled JaxerStore.

Ext.onReady(function() {
   var store = new Ext.data.JaxerStore({
       table : 'demo',
       fields : [
           {name : 'name'},
           {name : 'phone'},
           {name : 'email'}
       ],
       readerConfig : {
           sortInfo : {
               sort : 'name',
               dir : 'asc'
           }
       }
   });
 
   // create the Grid
   var grid = new Ext.grid.GridPanel({
       store : store,
       columns : [
           {header : "Name", sortable : true, dataIndex : 'name'},
           {header : "Phone #", sortable : true, dataIndex : 'phone'},
           {header : "Email", sortable : true, dataIndex : 'email'}
       ],
       viewConfig : {
           forceFit : true
       },
       stripeRows : true,
       height : 350,
       width : 680,
       title : 'Jaxer Demo Grid',
       renderTo : Ext.getBody()
   });
});

Jaxer Grid

Server-side Ext.(X)Template

This second example shows off actually running some Ext code on the server-side to take advantage of Ext’s template system. For this example I changed the JS includes for ext-base and ext-all to include a runat=”both” attribute so that the Ext library is available on the client and the server side. The html page includes a simple empty div with an id of ‘posts-main’ and a call to window.onserverload = loadPosts(). The loadPosts function simply selects some data from the ‘posts’ table in the database, then runs that data through the Ext.XTemplate. The XTemplate then loops through the rows array that Jaxer queries provide and will create the div/h2/p structure for each row. A quick formatting function lets us add a nice little ‘more’ link for those posts that are too long.

function loadPosts() {
   var vals = Jaxer.DB.execute('select id, title, body, perm from posts');
 
   var tpl = new Ext.XTemplate('<tpl for="rows">',
           '<div id="post-{id}" class="post">',
           '<h2><a href="/jxtest/post/{perm}">{title}</a></h2>',
           '<p class="post-body">{body:this.formatBody}</p>', '</div>',
           '</tpl>', {
               formatBody : function(val, all) {
                   if (val.length > 300) {
                       return Ext.util.Format.ellipsis(val, 300)
                               + '<a href="/jxtest/post/' + all.perm
                               + '">Read More &raquo;</a>';
                   } else {
                       return val;
                   }
               }
           });
 
   tpl.overwrite('posts-main', vals);
}

Jaxer Template

In Conclusion

We can see that Jaxer lets developers leverage the hard work which has already been spent building client-side libraries on the server-side. These simple examples show off some of the true potential of utilizing the Ext JS framework on the server-side.

Download the source code for the examples in this post.

WiiExtJS - Fun times with Nintendos embedded Opera browser

Wednesday, June 4th, 2008

Wii ExtJSIf I had done the product marketing for the Wii web browser – and its probably a good thing I didn’t - I would have called it the “Wiib Browser”, however those smart guys at Nintendo came up with “The Internet Channel”. From a consumer standpoint their version is probably better, but enough about that.

The Wii’s browser is running on a custom built version of Opera 9. ExtJS supports Opera, so Wii on TVeverything works the same as it would in a normal PC based web browser. With a complete JavaScript engine, its just as good as the full fledged Opera browser. Im not expecting any enterprise quality applications to be developed for use on the Wii, but it would be nice to use some of the ExtJS features to catch up on our blog, read the forum, or just drag windows around using the Wiimote (much more fun than it sounds).

What Do I Need to Do?

The things we have to take into account when creating an ExtJS site for the Wii are screen resolution, font sizes and input limitations. A typical Wii user is sitting further away from the screen than the PC user and to top it off the resolution is much less. The Wii in standard TV mode (480i/p) runs in one of two resolutions:

  • 16:9 (800 by 472)
  • 4:3 (800 by 628)

So we need to account for resolution, which is also not as straight forward as it should be. The Wii browser has a toolbar that may be shown all the time, or use an ‘autohide’ feature. The screen resolution is reported differently based on whether the toolbar is showing or not.

Another obstacle is that televisions tend to crop the edges of the screen off. The Opera Wii browser tries to compensate for this by adding space to the top and bottom of the screen. As you can imagine, an ExtJS viewport would have its edges off the sides of the screen, and the top and bottom are left with extra space.

Meet the Wii Layout

Ext.ns('Ext.ux.layout');
Ext.ux.layout.wii = Ext.extend(Ext.layout.FitLayout, {
    setItemSize : function(item, size){
        var viewSize = Ext.getBody().getViewSize();
        this.container.addClass('ux-layout-wii');
        item.addClass('ux-layout-wii-item');
        size.height = (viewSize.height-60);
        size.width = (viewSize.width-60);
        item.setSize(size);
    }
});
Ext.Container.LAYOUTS['wii'] = Ext.ux.layout.wii;<

Using a fit layout, centering it, and moving its edges inward does the trick. A bit of code to decide which layout to use based on the user agent, and were done.

    Ext.isWii = navigator.userAgent.toLowerCase().indexOf("wii") > -1;
    var layout = 'fit';
    var title = 'Normal';
    if (Ext.isWii) {
        layout = 'wii';
        title = 'Wii';
    }

Big Fonts

Wii ForumWhat would be considered a normal size font on a computer is rendered almost unreadable on a television, so we need to crank up the font size. This can be accomplished by using a “tv” targeted stylesheet.

<link rel=”stylesheet” type=”text/css” href=”wii.css” media=”tv” />

Input Limitations

There are some basic input limitations because there is no keyboard, so when designing Wii sites, we need to be sure to not require the use of combinations of keys, or special keys. For example, the functions keys are not available on the Wii, and pressing a ctrl combination would be impossible. Another thing to keep in mind is that the user cannot press enter, so things like form fields that perform an action on the enter key would be unusable.

Wii Migration

I cant imagine many of the typical ExtJS users updating their ExtJS applications to be Wii compatible, but what I do see is a way to improve the usefulness of the Wii. I could sit on my couch (remove the laptop from my lap) and use the rich ExtJS features I have grow accustom to.

See the Wii forum reader in action. If your viewing it from your computer then you will see a normal panel with grid, but from a Wii it will use the Wii layout along with larger fonts.

Ext GWT v1.0 Beta 4 Released

Monday, June 2nd, 2008

Ext JS is pleased to announce the Ext GWT 1.0 beta4 release. This release includes numerous enhancements and bug fixes since the beta3 release and is a recommended upgrade for those using beta 3. For first time users of Ext GWT, the new Help Center includes new articles to get you setup up and running your first Ext GWT application in GWT.

GWT RC1

GWT RC 1 was released recently. Ext GWT beta 4 is compiled and tested using RC1. Ext GWT utilizes the new Animation classes, as well as the new DOM API.

Performance

Many classes have been refactored to enhance their performance. Layouts in particular will receive a huge performance boost by upgrading. Initial rendering times are quicker and the new layout code reacts quicker to window resizing. Other performance improvements were made to TabPanel and Table.

Advanced Form Layouts

With beta 4, it is possible to create multi-column forms and to also embed child containers such as TabPanel. These layouts are supported by both AnchorLayout, and the new ColumnLayout. A new Column Form and TabPanel Form have been added to the Explorer Demo.

ColumnForm

Mail Demo

A new mail application has been developed as an Ext GWT reference application. This app can be found in the samples directory of your download and will be updated with each release to illustrate best practices in an Ext GWT application. The code demonstrates:

  • Data loading with GWT RPC
  • MVC
  • Custom components
  • Stores and Binders

Mail Demo

Improved Data Loading, Store, Binder, and Field API

A number of enhancements and updates were applied to the data related classes. More information on data loading can be found in the Help Center.

New API

Documentation

A new Help Center is now available and will serve as the repository for GXT documentation. Beta 4 adds a significant amount of new documentation including a new Eclipse Help Plugin. New articles and tutorials have been added. This includes:

  • Project Setup Guide
  • Building from SVN Guild
  • Component Reference
  • Data Loading Reference
  • LayoutContainer Reference
  • Remote TreeTable Tutorial

In addition, a new Eclipse Help Plugin is available. All the above listed content can be integrated into the Eclipse Help Info Center. The plugin is available via the new Update Site.

Help Center

The Ext GWT API is now available with integrated UML diagrams. These diagrams make it easy to visualize the package structure and details of all Ext GWT classes. The diagrams are available in the Help Center under Reference.

UML

Download

To download the beta 4 build or view the full release notes (API changes documented), please visit the Ext GWT download page. To find out more about Ext GWT and view the latest beta 4 samples, please visit the Ext GWT overview. To see beta 4 in action, take a look at the Explorer Demo or the Mail Demo.

Implementation Spotlight: VersoChat

Monday, June 2nd, 2008

Last week I had the pleasure to sit down with the team at Red Sun Systems to have a demo of VersoChat, their website chat management application. This is a very interesting tool that allows visitors to request chats with site operators, and for operators to push chat requests to site visitors. The console application includes many features for monitoring site usage, managing and transferring chat sessions, etc. and the UI looks fantastic! VersoChat is an existing application, but they have recently retooled the user interface from the ground up using Ext 2.0 and are launching the new version this week.

Tell us a little bit about VersoChat and how it evolved from its original version.

VersoChat is a web-based, multi-platform live chat solution with real time analytics for businesses with websites. Originally, VersoChat used simple PHP/MySQL scripts for both the font and back ends. Each chat session had to be opened in a separate browser window, and the live monitor was missing some of the functions that now are possible thanks to Ext. With Ext everything has changed. The UI is much more intuitive and easy to learn, and we implemented a lot of new features. For example, ChatTabs (multiple chats can be now handled in one window), GeoIP, IP labeling and many more great features are now possible that make VersoChat a top notch solution for live chat! VersoChat currently is only web-based, but now with Ext enabled our possibilities are endless and we plan to create a downloadable version with Adobe AIR in the near future.

VersoChat Console Screenshot

Did you evaluate other JavaScript frameworks when starting work on VersoChat? Why did you choose Ext?

Our general development experience was very good. Our live chat application was built in PHP and we wanted to have a robust, responsive and desktop-like front end for the new version of our application. We compared various JavaScript frameworks and found Ext’s features most suitable to our requirements because the widgets were extremely good-looking with professional quality. And most of the widgets we needed like panels, grids, forms etc. were available out of the box which made it a lot easier. When I came across your website and saw the BorderLayout example, I just fell in love with it and thought: “Where were you Ext when we started development on the first version of VersoChat?”

How does Ext fit into your overall application architecture?

The main work was in porting an already working application (chat support system) to Ext. So our work was really on the front end side of things along with changing the back end code output to suit our new AJAX needs. Our application still has PHP/MySQL as the back end, and Ext serves the front end. As our application was already running, there were some problems and issues in porting it to Ext, but those were gradually solved.

The VersoChat operator console is a pretty complex application. How did you manage the coding complexity?

It is true that the VersoChat operator console is a complex application, but given the power of Ext, it was not much of a problem. We mainly required grids for presenting user data and forms for getting input from the user. Ext’s Grids, Forms and Tabs made programming a lot easier. Much of the AJAX request handling, error checking and validation was easily and gracefully handled by Ext.

What features could we add to Ext to make building a rich application like VersoChat easier in the future?

Tab panels don’t support title/header which is required in certain circumstances. Size of Ext is an issue but considering the functionality it provides, you can’t really complain. And once the things load the performance is always good afterwards.

Do you have any advice for developers just starting out with Ext for the first time?

Learning Ext can be a bit intimidating in the beginning due to its steep learning curve but I guess that’s true for every framework out there. So be patient! Layout implementation is a major part of this framework and many issues can be solved just by using the right layout for parent and child elements, so try to understand the Layout structure of Ext.


© 2006-2009 Ext, LLC