Plugin providing Ext JS resources
Dependency :
compile "org.grails.plugins.extjs-resources:extjs:3.4.0.0"
Summary
Installation
grails install-plugin extjs
Description
Please note that all development (including the examples) have recently been migrated to GitHub. Please update your branches!
Please bear in mind that Ext JS license prohibits you to use it in commercial projects if you didn't pay for it. Refer to the Ext JS dual-licensing model for further details.Remember: this is a fantastic library! Don't mess around creating commercial projects without first paying for it! If you want to earn money with it you've got to pay for it!
See GitHub for known issues.Sources: http://github.com/padcom/grails-extjsContinuous integration: http://dev.aplaline.com/hudson/job/grails-extjs/
Installation
grails install-plugin extjs
Sources
You can clone this Git repository to get the sources:http://dev.aplaline.com/git/grails-extjs.git
Continous integration
You can fetch the latest and the greatest version of this plugin from Hudson:http://dev.aplaline.com/hudson/job/grails-extjs/
Usage
To use this plugin create your GSP file or HTML file like this:<html><head> <meta name="layout" content="ext"/> <script type="text/javascript"> Ext.onReady(function() { // your startup code goes here }); </script> </head><body> </body></html>
ext takes care of loading all the necessary resources.The following templates are provided by this plugin:
- ext - just the basic Ext JS libraries and content
- ext-ux - the basic Ext JS libraries and ux-all.*
- ext-jquery - just the basic Ext JS libraries and content with jQuery and the appropriate adapter
- ext-ux-jquery - the basic Ext JS libraries, ux-all.*, with jQuery and the appropriate adapter
- ext-prototype - just the basic Ext JS libraries and content with Prototype and the appropriate adapter
- ext-ux-prototype - the basic Ext JS libraries, ux-all.*, with Prototype and the appropriate adapter
- ext-desktop - basic Ext JS libraries and content plus a slightly modified version of the desktop example as a ready-to-use platform
- ext-desktop-jquery - basic Ext JS libraries and content plus a slightly modified version of the desktop example as a ready-to-use platform with jQuery and the appropriate adapter
- ext-desktop-prototype - basic Ext JS libraries and content plus a slightly modified version of the desktop example as a ready-to-use platform with Prototype and the appropriate adapter
- ext-desktop-ux - basic Ext JS libraries and content plus a slightly modified version of the desktop example as a ready-to-use platform with ux-all
- ext-desktop-ux-jquery - basic Ext JS libraries and content plus a slightly modified version of the desktop example as a ready-to-use platform with ux-all, jQuery and the appropriate adapter
- ext-desktop-ux-prototype - basic Ext JS libraries and content plus a slightly modified version of the desktop example as a ready-to-use platform with ux-all, Prototype and the appropriate adapter
Creating applications using the ext-desktop layouts
Creating an application that has the appearance of a desktop instead of an n-column layout with header and footer is fun and it looks really cool. Using this plugin and the provided templates it's really simple to do so.Creating the application object
At first you need an application object that's extending the Ext.app.App class. You can do so like this:MyApp = new Ext.app.App({ init: function(){ }, getModules: function(){ return [ ] }, getShortcuts: function(){ return [ ] }, getStartConfig: function(){ return { } } });
The application object already contains everything it needs in Ext.onReady event handler so you should put it directly into the script and NOT into the Ext.onReady event handler!This is the basic template. Let's examine the functions in details.
init function
This function is called once the application starts. Typically you'd want to run any initialization code here, for example code that initializes QuickTips:init: function(){
Ext.QuickTips.init();
},getModules function
The purpose of getModules function is to return an array of objects inheriting from Ext.app.Module, like the Ext.app.Module or Ext.app.EmbeddedModule. You can do so like this:getModules: function(){
return [
new Ext.app.EmbeddedModule({
id: 'example-win',
url: '/example/modules/example.gsp',
name: 'Example 1',
title: 'Example 2',
iconCls: 'grid-icon',
width: 800,
height: 600
})
]
}An application MUST consist of at least one module!
getShortcuts function
The purpose of the getShortcuts function is to return a list of definitions of desktop shortcuts (icons) to be placed on the desktop. Here's an example placing a shortcut to module with the window id example-win:getShortcuts : function() {
return [ {
id: 'example-win',
title: 'Example Window'
} ]
}getStartConfig function
The purpose of getStartConfig is to return the definition of how the start menu will look like. This means the icons in the right column (the so called tools), title and optional icon to be placed left of the title. Here's an example of such function:getStartConfig: function() {
return {
title: 'Jack Slocum',
iconCls: 'user',
toolItems: [{
text:'Settings',
iconCls:'settings',
handler: function() { Ext.MessageBox.alert("Information", "You clicked on the Settings tool button"); },
scope:this
},'-',{
text:'Logout',
iconCls:'logout',
handler: function() { Ext.MessageBox.alert("Information", "You clicked on the Logout tool button"); },
scope:this
}]
};
},Creating modules
To create a module you'll have to instantiate the Ext.app.Module class passing it a configuration object like this:Ext.ns("Modules");Modules.Example = Ext.extend(Ext.app.Module, { id: 'example-win', init : function(){ this.launcher = { text: 'Example 1', iconCls: 'icon-example', handler : this.createWindow, scope: this, windowId: this.id } }, createWindow : function(src){ var desktop = this.app.getDesktop(); var win = desktop.getWindow(this.id); if(!win){ win = desktop.createWindow({ id: this.id, title: 'Example 2', iconCls: 'icon-example', width: 800, height: 600, layout: 'fit', html: 'Put something useful here...', shim:false, animCollapse:true, constrainHeader:true }); } win.show(); } });
- text to be displayed in menu start is 'Example 1'
- window title will be 'Example 2'
Creating embedded modules
An embedded module is a module that has its content downloaded from some other file. This is very similar to when you're instantiating the Ext.app.Module but it assumes that the content will be downloaded from a URL:new Ext.app.EmbeddedModule({
id: 'example-win',
url: '/example/modules/example.gsp',
name: 'Example 1',
title: 'Example 2',
iconCls: 'grid-icon',
width: 800,
height: 600
})- text to be displayed in menu start is 'Example 1'
- window title will be 'Example 2'
- the content will be downloaded from /example/modules/example.gsp
Creating loadable content for Ext.app.EmbeddedModule
To use the embedded module you need to provide it with some content that will be loaded into the window's body. You can provide any type of content as long as you remember the following rule:Everything you load is de facto being included in the same window as the application itself.This means of course that all Ext JS resources will be automatically available. Since the ext-desktop* layouts include the ScriptLoader it's also possible to load additional JavaScript files to be used.
<script type="text/javascript"> Ext.ns("Modules.Example"); Modules.Example.config = { parentId: '${params.parentId}' } Ext.ScriptMgr.load({ disableCaching: true, scripts: [ '/example/js/modules/example.js' ], callback: function() { Modules.Example.main(); } }); </script>
- This code is executed every time you open this module so it needs to be safe this way.
- The params.parentId contains the id of the module's window. This is the one defined as id in the embedded module.
Modules.Example.main = function() {
var win = Ext.getCmp(Modules.Example.config.parentId); var count = 0;
var panel = new Ext.Panel({
layout: 'fit',
title: 'My panel',
items: {
xtype: 'button',
text: 'clickme1',
handler: function() {
Ext.MessageBox.alert("Info", "You clicked me " + (++count) + " times.");
}
}
}); win.add(panel);
win.doLayout();
};Do not use the renderTo option with modules. This will make the object impossible to fit into the parent's window (in this case the module's one)
Styling
There are 3 things you might want to apply styles to:- Desktop
- Shortcuts on the desktop
- Menu start items
Desktop
To style the desktop (change its color and possibly wallpaper) create a style for the x-desktop element like this:#x-desktop {
background: black url(${resource(dir:'images', file: 'grails_logo.png')}) no-repeat center;
}Shortcuts on the desktop
Every shortcut should have a meaningful icon for the user to better recognize what this particular application does. A desktop icon here consts of an empty image (the s.gif one) and some text. Let's have a look at how we might make it more interesting.#example-win-shortcut img {
width:48px;
height:48px;
background-image: url(${resource(dir:"images", file: "favicon.ico")});
filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(
src='${resource(dir:"images", file: "favicon.ico")}', sizingMethod='scale'
);
}Start menu icons and windows icons.
Styling menu start icons and icons for windows is exactly the same as adding an icon to a button element. You define a custom style and specify it in the module's configuration:new Ext.app.EmbeddedModule({
id: 'example-win',
url: '/example/modules/example.gsp',
name: 'Example 1',
title: 'Example 2',
iconCls: 'grid-icon',
width: 800,
height: 600
}).grid-icon {
background-image: url(http://cdn1.blackberryforums.com/images/icons/icon11.gif);
}Example
There's an example usage for ext-desktop template here:http://dev.aplaline.com/git/grails-extjs-example.git
grails-extjs grails-extjs-example