Michelangelo
19 Jun 2008, 10:24 AM
Hi all,
I'm new of Extjs. Fantastic web solution.
I have to create a big application and I don't know how to start.
Questions:
1. How can I communicate between object? :-/ how can I get the record passed from the Application.UsersGrid.js to Application.UsersWindow.js and show the data in the form? :-/
2. How can add a toolbar in the Application.UsersWindow.js ? :-/
3. The documentation have no sample inside every method/event/property, is there a place where I can get these information? The tutorials are little application that doesn't use the namespace system.
4. How can I see an example with all the features of the Ext.data.JsonStore ?
The way I started:
I have create 4 files .js
Application.Main.js
Application.Categories.js
Application.UsersGrid.js
Application.UsersWindow.js
Application.Main.js
Ext.namespace('Application');
Ext.BLANK_IMAGE_URL = './ext/resources/images/default/s.gif';
Ext.ns('Application');
// application main entry point
Ext.onReady(function() {
Ext.QuickTips.init();
// code here
var viewport = new Ext.Viewport({
layout:'border',
items:[{
region:'north',
height:28,
items: new Ext.Panel(
{tbar :
[{text: 'Logout'}]
})
},{
region:'center',
layout:'fit',
items: {xtype:'usersgrid'}
},{
region: 'west',
collapsible: true,
title: 'Job Categories',
items: {xtype:'categories'},
width: 300,
autoScroll: true,
split: true
},{
region:'east',
title:'Information',
width:200,
split:true,
collapsible:true
},{
region:'south',
title:'Actions',
height:200,
split:true,
collapsible:true,
collapsed:true
}]
});
}); // eo function onReady
// eof
Application.Categories.js
Ext.namespace("Application");
Ext.extend(
Application.Categories = function(config){
Application.Categories.superclass.constructor.call(this,config);
},
Ext.tree.TreePanel,
{
border:false,
initComponent:function() {
Ext.apply(this, {
loader: new Ext.tree.TreeLoader({
dataUrl:'php/get_categories.php'
}),
root: new Ext.tree.AsyncTreeNode({
expanded: true
}),
rootVisible: false,
listeners: {
click: function(n) {
Ext.Msg.alert('Navigation Tree Click', 'You clicked: "' + n.attributes.text + '"');
}
}
});
this.on('click', function(value){
alert(value);
});
Application.Categories.superclass.initComponent.apply(this, arguments);
} // eo function initComponent
,onRender:function() {
Application.Categories.superclass.onRender.apply(this, arguments);
} // eo function onRender
});
Ext.reg('categories', Application.Categories);
Application.UsersGrid.js
Ext.namespace("Application");
Ext.extend(
Application.UsersGrid = function(config){
Application.UsersGrid.superclass.constructor.call(this,config);
},
Ext.grid.GridPanel,
{
border:false,
initComponent:function() {
this.store = new Ext.data.JsonStore({
url: 'php/get.php',
root: 'records',
totalProperty: 'totalCount',
fields: [
{name:'idpersonal_data', type:'int'},
{name:'public', type:'int'},
{name:'name', type:'string'},
{name:'surname', type:'string'},
{name:'registration_date', type:'date', dateFormat: 'Y-m-d H:i:s'},
{name:'email', type:'string'},
{name:'pac', type:'string'},
{name:'idtongues', type:'int'},
{name:'WE', type:'int'},
{name:'ET', type:'int'},
{name:'OL', type:'int'},
{name:'CS', type:'int'},
{name:'CL', type:'int'},
{name:'CN', type:'int'},
{name:'RF', type:'int'},
{name:'element_translated', type:'int'},
{name:'language_name', type:'string'}
]
});
Ext.apply(this, {
trackMouseOver:false,
autoExpandColumn: 'name',
loadMask: {msg:'Wait a moment, please ...'},
cm: new Ext.grid.ColumnModel([
{header: 'ID', dataIndex: 'idpersonal_data', width: 10, sortable: true},
{header: 'Translator', dataIndex: 'language_name', width: 20, sortable: true},
{header: 'Mode', dataIndex: 'public', width: 15, sortable: true, renderer: function(value) { return (value == 1) ? "Public" : "Private"}},
{header: 'Language', dataIndex: 'idtongues', width: 10, sortable: true, renderer: function(value) { return "<img src=\"images/flags/" + value + ".gif\">";}},
{header: 'First Name', dataIndex: 'name', width: 60, sortable: true},
{header: 'Last Name', dataIndex: 'surname', width: 80, sortable: true},
{header: 'Registration Date', dataIndex: 'registration_date', width: 40, sortable: true, hidden: false, renderer: Ext.util.Format.dateRenderer('d/m/Y H:i:s')},
{header: 'P.A.C.', dataIndex: 'pac', width: 50, renderer: function(value){ return "<a href=\"http://" + value + ".eurocv.eu\" target=\"_blank\">" + value + "</a>"}, hidden: false},
{header: 'Email Address', dataIndex: 'email', width: 80, hidden: false},
{header: 'WE', dataIndex: 'WE', width: 10},
{header: 'ET', dataIndex: 'ET', width: 10},
{header: 'OL', dataIndex: 'OL', width: 10},
{header: 'CS', dataIndex: 'CS', width: 10},
{header: 'CN', dataIndex: 'CN', width: 10},
{header: 'CL', dataIndex: 'CL', width: 10},
{header: 'RF', dataIndex: 'RF', width: 10}
]),
iconCls:'icon-grid',
sm: new Ext.grid.RowSelectionModel({singleSelect:true}),
viewConfig: {
forceFit:true
},
bbar: new Ext.PagingToolbar({
pageSize: 25,
store: this.store,
displayInfo: true,
displayMsg: 'Displaying items {0} - {1} of {2}',
emptyMsg: "No items to display"
})
});
this.on('rowdblclick', function(grid, rowIndex, e){
var record = grid.getStore().getAt(rowIndex);
var userw = new Application.UsersWindow(record);
userw.show();
});
Application.UsersGrid.superclass.initComponent.apply(this, arguments);
} // eo function initComponent
,onRender:function() {
this.store.load({params:{start:0, limit:25}});
Application.UsersGrid.superclass.onRender.apply(this, arguments);
} // eo function onRender
}
);
Ext.reg('usersgrid', Application.UsersGrid);
Application.UsersWindow.js
Ext.namespace("Application");
Ext.extend(
Application.UsersWindow = function(config){
Application.UsersWindow.superclass.constructor.call(this,config);
},
Ext.Window,
{
border:false
,initComponent:function() {
Ext.apply(this, {
labelWidth: 75, // label settings here cascade unless overridden
url:'save-form.php',
title: 'Simple Form',
waitMsgTarget: true,
bodyStyle:'padding:5px',
autoHeight: true,
width: 600,
modal:true,
items: [{
layout:'column',
border:false,
items:[{
columnWidth:.5,
layout: 'form',
border:false,
items: [{
xtype:'textfield',
fieldLabel: 'First Name',s
name: 'name',
anchor:'95%'
}, {
xtype:'textfield',
fieldLabel: 'Last Name',
name: 'surname',
anchor:'95%'
}]
},{
columnWidth:.5,
layout: 'form',
border:false,
items: [{
xtype:'textfield',
fieldLabel: 'Email',
name: 'email',
anchor:'95%'
},{
xtype:'textfield',
fieldLabel: 'PAC',
name: 'pac',
vtype:'string',
anchor:'95%'
}]
}]
},{
xtype:'tabpanel',
plain:true,
activeTab: 0,
height:235,
defaults:{bodyStyle:'padding:10px'},
items:[{
title:'Personal Details',
layout:'form',
defaultType: 'textfield',
items: [{
fieldLabel: 'First Name',
name: 'first',
allowBlank:false,
value: 'Jack'
},{
fieldLabel: 'Last Name',
name: 'last',
value: 'Slocum'
},{
fieldLabel: 'Company',
name: 'company',
value: 'Ext JS'
}, {
fieldLabel: 'Email',
name: 'email',
vtype:'email'
}]
},{
title:'Phone Numbers',
layout:'form',
defaultType: 'textfield',
items: [{
fieldLabel: 'Home',
name: 'home',
value: '(888) 555-1212'
},{
fieldLabel: 'Business',
name: 'business'
},{
fieldLabel: 'Mobile',
name: 'mobile'
},{
fieldLabel: 'Fax',
name: 'fax'
}]
},{
cls:'x-plain',
title:'Biography',
layout:'fit',
items: {
xtype:'htmleditor',
id:'bio2',
fieldLabel:'Biography'
}
}]
}],
buttons:
[
{
text: "Chiudi",
handler: function()
{
this.close();
}
},
{
text: "OK"
}
]
});
Application.UsersWindow.superclass.initComponent.apply(this, arguments);
} // eo function initComponent
,onRender:function() {
this.loadRecord(config);
Application.UsersWindow.superclass.onRender.apply(this, arguments);
} // eo function onRender
}
);
Ext.reg('userswindow', Application.UsersWindow);
I'm new of Extjs. Fantastic web solution.
I have to create a big application and I don't know how to start.
Questions:
1. How can I communicate between object? :-/ how can I get the record passed from the Application.UsersGrid.js to Application.UsersWindow.js and show the data in the form? :-/
2. How can add a toolbar in the Application.UsersWindow.js ? :-/
3. The documentation have no sample inside every method/event/property, is there a place where I can get these information? The tutorials are little application that doesn't use the namespace system.
4. How can I see an example with all the features of the Ext.data.JsonStore ?
The way I started:
I have create 4 files .js
Application.Main.js
Application.Categories.js
Application.UsersGrid.js
Application.UsersWindow.js
Application.Main.js
Ext.namespace('Application');
Ext.BLANK_IMAGE_URL = './ext/resources/images/default/s.gif';
Ext.ns('Application');
// application main entry point
Ext.onReady(function() {
Ext.QuickTips.init();
// code here
var viewport = new Ext.Viewport({
layout:'border',
items:[{
region:'north',
height:28,
items: new Ext.Panel(
{tbar :
[{text: 'Logout'}]
})
},{
region:'center',
layout:'fit',
items: {xtype:'usersgrid'}
},{
region: 'west',
collapsible: true,
title: 'Job Categories',
items: {xtype:'categories'},
width: 300,
autoScroll: true,
split: true
},{
region:'east',
title:'Information',
width:200,
split:true,
collapsible:true
},{
region:'south',
title:'Actions',
height:200,
split:true,
collapsible:true,
collapsed:true
}]
});
}); // eo function onReady
// eof
Application.Categories.js
Ext.namespace("Application");
Ext.extend(
Application.Categories = function(config){
Application.Categories.superclass.constructor.call(this,config);
},
Ext.tree.TreePanel,
{
border:false,
initComponent:function() {
Ext.apply(this, {
loader: new Ext.tree.TreeLoader({
dataUrl:'php/get_categories.php'
}),
root: new Ext.tree.AsyncTreeNode({
expanded: true
}),
rootVisible: false,
listeners: {
click: function(n) {
Ext.Msg.alert('Navigation Tree Click', 'You clicked: "' + n.attributes.text + '"');
}
}
});
this.on('click', function(value){
alert(value);
});
Application.Categories.superclass.initComponent.apply(this, arguments);
} // eo function initComponent
,onRender:function() {
Application.Categories.superclass.onRender.apply(this, arguments);
} // eo function onRender
});
Ext.reg('categories', Application.Categories);
Application.UsersGrid.js
Ext.namespace("Application");
Ext.extend(
Application.UsersGrid = function(config){
Application.UsersGrid.superclass.constructor.call(this,config);
},
Ext.grid.GridPanel,
{
border:false,
initComponent:function() {
this.store = new Ext.data.JsonStore({
url: 'php/get.php',
root: 'records',
totalProperty: 'totalCount',
fields: [
{name:'idpersonal_data', type:'int'},
{name:'public', type:'int'},
{name:'name', type:'string'},
{name:'surname', type:'string'},
{name:'registration_date', type:'date', dateFormat: 'Y-m-d H:i:s'},
{name:'email', type:'string'},
{name:'pac', type:'string'},
{name:'idtongues', type:'int'},
{name:'WE', type:'int'},
{name:'ET', type:'int'},
{name:'OL', type:'int'},
{name:'CS', type:'int'},
{name:'CL', type:'int'},
{name:'CN', type:'int'},
{name:'RF', type:'int'},
{name:'element_translated', type:'int'},
{name:'language_name', type:'string'}
]
});
Ext.apply(this, {
trackMouseOver:false,
autoExpandColumn: 'name',
loadMask: {msg:'Wait a moment, please ...'},
cm: new Ext.grid.ColumnModel([
{header: 'ID', dataIndex: 'idpersonal_data', width: 10, sortable: true},
{header: 'Translator', dataIndex: 'language_name', width: 20, sortable: true},
{header: 'Mode', dataIndex: 'public', width: 15, sortable: true, renderer: function(value) { return (value == 1) ? "Public" : "Private"}},
{header: 'Language', dataIndex: 'idtongues', width: 10, sortable: true, renderer: function(value) { return "<img src=\"images/flags/" + value + ".gif\">";}},
{header: 'First Name', dataIndex: 'name', width: 60, sortable: true},
{header: 'Last Name', dataIndex: 'surname', width: 80, sortable: true},
{header: 'Registration Date', dataIndex: 'registration_date', width: 40, sortable: true, hidden: false, renderer: Ext.util.Format.dateRenderer('d/m/Y H:i:s')},
{header: 'P.A.C.', dataIndex: 'pac', width: 50, renderer: function(value){ return "<a href=\"http://" + value + ".eurocv.eu\" target=\"_blank\">" + value + "</a>"}, hidden: false},
{header: 'Email Address', dataIndex: 'email', width: 80, hidden: false},
{header: 'WE', dataIndex: 'WE', width: 10},
{header: 'ET', dataIndex: 'ET', width: 10},
{header: 'OL', dataIndex: 'OL', width: 10},
{header: 'CS', dataIndex: 'CS', width: 10},
{header: 'CN', dataIndex: 'CN', width: 10},
{header: 'CL', dataIndex: 'CL', width: 10},
{header: 'RF', dataIndex: 'RF', width: 10}
]),
iconCls:'icon-grid',
sm: new Ext.grid.RowSelectionModel({singleSelect:true}),
viewConfig: {
forceFit:true
},
bbar: new Ext.PagingToolbar({
pageSize: 25,
store: this.store,
displayInfo: true,
displayMsg: 'Displaying items {0} - {1} of {2}',
emptyMsg: "No items to display"
})
});
this.on('rowdblclick', function(grid, rowIndex, e){
var record = grid.getStore().getAt(rowIndex);
var userw = new Application.UsersWindow(record);
userw.show();
});
Application.UsersGrid.superclass.initComponent.apply(this, arguments);
} // eo function initComponent
,onRender:function() {
this.store.load({params:{start:0, limit:25}});
Application.UsersGrid.superclass.onRender.apply(this, arguments);
} // eo function onRender
}
);
Ext.reg('usersgrid', Application.UsersGrid);
Application.UsersWindow.js
Ext.namespace("Application");
Ext.extend(
Application.UsersWindow = function(config){
Application.UsersWindow.superclass.constructor.call(this,config);
},
Ext.Window,
{
border:false
,initComponent:function() {
Ext.apply(this, {
labelWidth: 75, // label settings here cascade unless overridden
url:'save-form.php',
title: 'Simple Form',
waitMsgTarget: true,
bodyStyle:'padding:5px',
autoHeight: true,
width: 600,
modal:true,
items: [{
layout:'column',
border:false,
items:[{
columnWidth:.5,
layout: 'form',
border:false,
items: [{
xtype:'textfield',
fieldLabel: 'First Name',s
name: 'name',
anchor:'95%'
}, {
xtype:'textfield',
fieldLabel: 'Last Name',
name: 'surname',
anchor:'95%'
}]
},{
columnWidth:.5,
layout: 'form',
border:false,
items: [{
xtype:'textfield',
fieldLabel: 'Email',
name: 'email',
anchor:'95%'
},{
xtype:'textfield',
fieldLabel: 'PAC',
name: 'pac',
vtype:'string',
anchor:'95%'
}]
}]
},{
xtype:'tabpanel',
plain:true,
activeTab: 0,
height:235,
defaults:{bodyStyle:'padding:10px'},
items:[{
title:'Personal Details',
layout:'form',
defaultType: 'textfield',
items: [{
fieldLabel: 'First Name',
name: 'first',
allowBlank:false,
value: 'Jack'
},{
fieldLabel: 'Last Name',
name: 'last',
value: 'Slocum'
},{
fieldLabel: 'Company',
name: 'company',
value: 'Ext JS'
}, {
fieldLabel: 'Email',
name: 'email',
vtype:'email'
}]
},{
title:'Phone Numbers',
layout:'form',
defaultType: 'textfield',
items: [{
fieldLabel: 'Home',
name: 'home',
value: '(888) 555-1212'
},{
fieldLabel: 'Business',
name: 'business'
},{
fieldLabel: 'Mobile',
name: 'mobile'
},{
fieldLabel: 'Fax',
name: 'fax'
}]
},{
cls:'x-plain',
title:'Biography',
layout:'fit',
items: {
xtype:'htmleditor',
id:'bio2',
fieldLabel:'Biography'
}
}]
}],
buttons:
[
{
text: "Chiudi",
handler: function()
{
this.close();
}
},
{
text: "OK"
}
]
});
Application.UsersWindow.superclass.initComponent.apply(this, arguments);
} // eo function initComponent
,onRender:function() {
this.loadRecord(config);
Application.UsersWindow.superclass.onRender.apply(this, arguments);
} // eo function onRender
}
);
Ext.reg('userswindow', Application.UsersWindow);