PHP Code:
<html>
<head>
<meta HTTP-EQUIV="Pragma" CONTENT="no-cache"/>
<meta HTTP-EQUIV="Expires" CONTENT="-1"/>
<title>Testing ExtJS</title>
<link rel="stylesheet" type="text/css" href="resources/css/ext-all.css"/>
<!-- LIBS -->
<script type="text/javascript" src="adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="ext-all.js"></script>
<script type="text/javascript" src="TooltipFix.js"></script>
<script type="text/javascript" src="InputTextMask.js"></script>
<script type="text/javascript" src="complexform.js"></script>
<!-- ENDLIBS -->
<script type="text/javascript">
var eastPanel;
var eastCards;
Ext.onReady(function()
{
var workData = [
['Apple',29.89,0.24,0.81,'9/1 12:00am'],
['Ext',83.81,0.28,0.34,'9/12 12:00am'],
['Google',71.72,0.02,0.03,'10/1 12:00am'],
['Microsoft',52.55,0.01,0.02,'7/4 12:00am'],
['Yahoo!',29.01,0.42,1.47,'5/22 12:00am']
];
var workReader = new Ext.data.ArrayReader({}, [
{name: 'company'},
{name: 'price', type: 'float'},
{name: 'change', type: 'float'},
{name: 'pctChange', type: 'float'},
{name: 'lastChange', type: 'date', dateFormat: 'n/j h:ia'}
]);
var workgrid = new Ext.grid.GridPanel({
store: new Ext.data.Store({
data: workData,
reader: workReader
}),
columns: [
{header: 'Company', width: 120, sortable: true, dataIndex: 'company'},
{header: 'Price', width: 90, sortable: true, dataIndex: 'price'},
{header: 'Change', width: 90, sortable: true, dataIndex: 'change'},
{header: '% Change', width: 90, sortable: true, dataIndex: 'pctChange'},
{header: 'Last Updated', width: 120, sortable: true,
renderer: Ext.util.Format.dateRenderer('m/d/Y'),
dataIndex: 'lastChange'}
],
viewConfig: {
forceFit: false
},
renderTo: Ext.getBody(),
title: 'Tab Grid One',
tabTip: 'This is the first grid',
stripeRows: false,
frame: true
});
workgrid.getSelectionModel().selectFirstRow();
var myData = [
['Apple',29.89,0.24,0.81,'9/1 12:00am'],
['Ext',83.81,0.28,0.34,'9/12 12:00am'],
['Google',71.72,0.02,0.03,'10/1 12:00am'],
['Microsoft',52.55,0.01,0.02,'7/4 12:00am'],
['Ext',83.81,0.28,0.34,'9/12 12:00am'],
['Google',71.72,0.02,0.03,'10/1 12:00am'],
['Microsoft',52.55,0.01,0.02,'7/4 12:00am'],
['Ext',83.81,0.28,0.34,'9/12 12:00am'],
['Google',71.72,0.02,0.03,'10/1 12:00am'],
['Microsoft',52.55,0.01,0.02,'7/4 12:00am'],
['Ext',83.81,0.28,0.34,'9/12 12:00am'],
['Google',71.72,0.02,0.03,'10/1 12:00am'],
['Microsoft',52.55,0.01,0.02,'7/4 12:00am'],
['Ext',83.81,0.28,0.34,'9/12 12:00am'],
['Google',71.72,0.02,0.03,'10/1 12:00am'],
['Microsoft',52.55,0.01,0.02,'7/4 12:00am'],
['Ext',83.81,0.28,0.34,'9/12 12:00am'],
['Google',71.72,0.02,0.03,'10/1 12:00am'],
['Apple',29.89,0.24,0.81,'9/1 12:00am'],
['Ext',83.81,0.28,0.34,'9/12 12:00am'],
['Google',71.72,0.02,0.03,'10/1 12:00am'],
['Microsoft',52.55,0.01,0.02,'7/4 12:00am'],
['Ext',83.81,0.28,0.34,'9/12 12:00am'],
['Google',71.72,0.02,0.03,'10/1 12:00am'],
['Microsoft',52.55,0.01,0.02,'7/4 12:00am'],
['Ext',83.81,0.28,0.34,'9/12 12:00am'],
['Google',71.72,0.02,0.03,'10/1 12:00am'],
['Microsoft',52.55,0.01,0.02,'7/4 12:00am'],
['Ext',83.81,0.28,0.34,'9/12 12:00am'],
['Google',71.72,0.02,0.03,'10/1 12:00am'],
['Microsoft',52.55,0.01,0.02,'7/4 12:00am'],
['Ext',83.81,0.28,0.34,'9/12 12:00am'],
['Google',71.72,0.02,0.03,'10/1 12:00am'],
['Microsoft',52.55,0.01,0.02,'7/4 12:00am'],
['Ext',83.81,0.28,0.34,'9/12 12:00am'],
['Microsoft',52.55,0.01,0.02,'7/4 12:00am'],
['Yahoo!',29.01,0.42,1.47,'5/22 12:00am']
];
var myReader = new Ext.data.ArrayReader({}, [
{name: 'company'},
{name: 'price', type: 'float'},
{name: 'change', type: 'float'},
{name: 'pctChange', type: 'float'},
{name: 'lastChange', type: 'date', dateFormat: 'n/j h:ia'}
]);
var grid = new Ext.grid.GridPanel({
store: new Ext.data.Store({
data: myData,
reader: myReader
}),
columns: [
{header: 'Company', width: 120, sortable: true, dataIndex: 'company'},
{header: 'Price', width: 90, sortable: true, dataIndex: 'price'},
{header: 'Change', width: 90, sortable: true, dataIndex: 'change'},
{header: '% Change', width: 90, sortable: true, dataIndex: 'pctChange'},
{header: 'Last Updated', width: 120, sortable: true,
renderer: Ext.util.Format.dateRenderer('m/d/Y'),
dataIndex: 'lastChange'}
],
viewConfig: {
forceFit: false
},
renderTo: Ext.getBody(),
title: 'Tab Grid Two',
tabTip: 'This is the second grid',
stripeRows: false,
frame: true
});
grid.getSelectionModel().selectFirstRow();
var viewport = new Ext.Viewport(
{
layout:"border",
renderTo: Ext.getBody(),
items:[
{
id: 'north',
region:"north",
title:"Testing Form Layouts",
bodyStyle:"background-color:#bacfff",
height:50,
buttons: [
{
handler: function() {
eastPanel.expand();
eastCards.getLayout().setActiveItem("newform");
},
text: "Show Form",
tooltip: "Click to show form"
}
]
},
new Ext.Panel({
region:'center',
layout:'border',
items:[
new Ext.Panel({
region:"south",
bodyStyle:"background-color:#bacfff",
title:"Details",
height:80,
autoScroll:true,
collapsible:true,
split:true
}),
new Ext.TabPanel({
region:'center',
deferredRender:false,
activeTab:0,
items:[
workgrid,
grid
// NOTE: When I uncomment the following lines, I get the error <-----
/*,{
xtype: 'panel',
layout: 'fit',
title: "Form",
items: [
testForm
]
}*/
]
})
]
}),
// right-side card layout panel
eastPanel = new Ext.Panel(
{
region: "east",
layout: "border",
width: 400,
minWidth: 262,
split: true,
animCollapse: false,
collapsible: true,
collapseMode: 'mini',
collapsed: true,
hideCollapseTool: true,
items: [
eastCards = new Ext.Panel(
{
region: "center",
layout: "card",
activeItem: 'qresults',
width:400,
items: [
{
xtype: 'panel',
id: 'newform',
layout: 'fit',
title: "New",
items: [
testForm2
]
},
new Ext.Panel(
{
id: 'qresults',
title: "Query Results",
autoScroll: true,
items: [ Ext.get("queryDiv") ]
})
]
}),
{
region: "south",
xtype: "panel",
layout: "fit",
split: true,
animCollapse: false,
collapsible: true,
collapseMode: 'mini',
collapsed: true,
hideCollapseTool: true,
height: 200,
items: [ Ext.get("dummy") ]
}
]
}) // end main layout east pane
]/*,
// See comment below for initialFormFix
listeners: {
afterlayout: {
fn: initialFormFix,
single: true
}
}*/
});
// Init the singleton. Any tag-based quick tips will start working.
Ext.QuickTips.init();
// Apply a set of config properties to the singleton
Ext.apply(Ext.QuickTips.getQuickTip(), {
showDelay: 50,
dismissDelay: 0,
animCollapse: false,
trackMouse: true,
mouseOffset: [10, 10]
});
});//end onReady function
// Call fixFormSize for each form that uses it upon initial layout
// NOT USED in this version as it causes an error (since Form is not initially visible?)
function initialFormFix()
{
fixFormSize(testform);
// others would follow here if there is more than one form
}
// This makes the form buttons appear the way it is wanted.
function fixFormSize(theform)
{
theform.suspendEvents();
var formHeight = theform.getSize().height;
var ctHeight = theform.ownerCt.getInnerHeight();
if(formHeight >= ctHeight)
{
theform.autoHeight = false;
theform.setHeight(ctHeight);
}
else
{
theform.syncSize();
}
theform.autoHeight = true;
theform.resumeEvents();
}
</script>
</head>
<body>
<div id="queryDiv">Query results</div>
<div id="dummy">Hi.</div>
</body>
<meta HTTP-EQUIV="Pragma" CONTENT="no-cache"/>
<meta HTTP-EQUIV="Expires" CONTENT="-1"/>
</html>
complexform.js:
PHP Code:
Ext.ux.DateSearch = Ext.extend(Ext.form.DateField, {
initComponent: Ext.form.TwinTriggerField.prototype.initComponent,
getTrigger: Ext.form.TwinTriggerField.prototype.getTrigger,
initTrigger: Ext.form.TwinTriggerField.prototype.initTrigger,
onTrigger1Click: Ext.form.DateField.prototype.onTriggerClick,
trigger1Class: Ext.form.DateField.prototype.triggerClass,
trigger2Class: 'x-form-search-trigger'
});
Ext.reg('datesearch', Ext.ux.DateSearch);
var formConfig = {
autoHeight:true,
autoScroll: true,
url: 'save.jsp',
method: 'POST',
onSubmit: Ext.emptyFn,
labelAlign: "right",
labelWidth: 120,
//defaults: { labelStyle: "font-weight:bold" },
defaultType: "textfield",
monitorValid: true,
items: [
{
fieldLabel: 'Last Name',
name: 'lastName',
allowBlank: false
},
{
fieldLabel: 'First Name',
name: 'firstName',
allowBlank: false
},
{
fieldLabel: 'Middle Name',
name: 'middleName',
allowBlank: true
},
{
fieldLabel: 'SSN #',
xtype: 'textfield',
name: 'ssn',
allowBlank: false,
plugins: [new Ext.ux.InputTextMask('999-99-9999', false)]
},
{
fieldLabel: 'Date of Birth',
xtype:'datesearch',
anchor:'70%',
name: 'dob',
allowBlank: false,
onTrigger2Click: function()
{
southPanel.expand();
southPanel.getLayout().setActiveItem("history");
historyGrid.setTitle("Date of Birth");
historyGrid.store.load(
{
params: { table: "ChangeLog", filter: "like 'dob%'" }
});
}
},
{
xtype: 'panel',
layout: 'column',
items: [
{
layout:'form',
items: [
{
fieldLabel: 'Gender',
name: 'gender',
xtype: 'radio',
boxLabel: 'Female',
inputValue: 'F',
allowBlank: false,
columnWidth: 0.5
}
]
},
{
layout:'form',
items: [
{
hideLabel:true,
labelSeparator: '',
name: 'gender',
xtype: 'radio',
boxLabel: 'Male',
inputValue: 'M',
allowBlank: false,
columnWidth: 0.5
}
]
}
]
},
{
xtype: 'panel',
layout: 'form',
autoHeight: true,
bodyStyle: "background:#bdc0d9; border:thin solid #AABBCC; margin-left:70px; margin-bottom:8px; width:185px",
labelWidth: 48,
items: [
{
fieldLabel: 'Race',
name: 'race',
xtype: 'radio',
boxLabel: 'White',
inputValue: 'W',
allowBlank: true
},
{
labelSeparator: '',
name: 'race',
xtype: 'radio',
boxLabel: 'Black',
inputValue: 'B',
allowBlank: true
},
{
labelSeparator: '',
name: 'race',
xtype: 'radio',
boxLabel: 'Hispanic',
inputValue: 'H',
allowBlank: true
},
{
labelSeparator: '',
name: 'race',
xtype: 'radio',
boxLabel: 'Asian',
inputValue: 'A',
allowBlank: true
},
{
labelSeparator: '',
name: 'race',
xtype: 'radio',
boxLabel: 'Native American',
inputValue: 'N',
allowBlank: true
},
{
labelSeparator: '',
name: 'race',
xtype: 'radio',
boxLabel: 'Other',
inputValue: 'O',
allowBlank: true
}
]
},
{
fieldLabel: 'Address 1',
name: 'addr1',
allowBlank: true
},
{
fieldLabel: 'Address 2',
name: 'addr2',
allowBlank: true
},
{
fieldLabel: 'Country',
name: 'country',
allowBlank: true
},
{
fieldLabel: 'City',
name: 'city',
allowBlank: true
},
{
fieldLabel: 'State',
name: 'state',
allowBlank: true
},
{
fieldLabel: 'Zip Code',
name: 'zipcode',
allowBlank: true
},
{
fieldLabel: 'Primary Phone #',
name: 'phone1',
allowBlank: true
},
{
fieldLabel: 'Secondary Phone #',
name: 'phone2',
allowBlank: true
},
{
fieldLabel: 'E-mail',
name: 'email',
vtype: 'email',
allowBlank: true
}
],
buttons: [
{
text: 'Save',
tooltip: 'Click to save',
formBind: true,
handler: function()
{
this.getForm().submit(
{
success: function(f, action)
{
}
});
}
},
{
text: 'Cancel',
tooltip: 'Click to cancel',
handler: function()
{
}
}
]
};
// Create form object and resize handler
testForm = new Ext.form.FormPanel(formConfig);
testForm.on('resize', function()
{
fixFormSize(this);
});
// Create form object and resize handler
testForm2 = new Ext.form.FormPanel(formConfig);
testForm2.on('resize', function()
{
fixFormSize(this);
});