1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
| CreateSite = function(siteDataStore) {
var reference = new Ext.form.TextField({
fieldLabel: 'reference',
allowBlank: false,
name: 'reference',
anchor: '90%'
});
var description = new Ext.form.TextField({
fieldLabel: 'description',
allowBlank: false,
name: 'description',
anchor: '90%'
});
var formPanel = new Ext.form.FormPanel({
baseCls: 'x-plain',
labelWidth: 75,
url:'servlet/SiteCRUDServlet?action=create', // When the form is submitted call this url.
onSubmit: Ext.emptyFn,
items: [ // Add the fields defined above to the form.
reference,
description
]
});
// Define a window with the form panel in it and show it.
var window = new Ext.Window({
title: 'Add New Site',
width: 200,
height: 200,
minWidth: 200,
minHeight: 200,
layout: 'fit',
plain: true,
bodyStyle: 'padding:5px;',
buttonAlign: 'center',
items: formPanel,
buttons: [{
text: 'Save',
handler: saveSite // The method to call when the save button is clicked.
},{
text: 'Cancel',
handler: cancelAdd // The method to call when the cancel button is clicked.
}]
});
/*corps.add(window);
//alert("ffff3");
//rafraichir la page
corps.doLayout(); */
window.show();
// Display the popup window.
/**
* Method is called when the cancel button is clicked on the create person window.
* Simply hide the window.
*/
function cancelAdd() {
window.hide();
}
function saveSite() {
// Check if the form is valid.
if (formPanel.form.isValid()) {
// If the form is valid, submit it.
// To enable normal browser submission of the Ext Form contained in this
// FormPanel, override the submit method.
formPanel.form.submit({
waitMsg: 'In processing',
// The function to call when the response from the server was a failed
// attempt (save in this case), or when an error occurred in the Ajax
// communication.
failure: submitFailed,
// The function to call when the response from the server was a successful
// attempt (save in this case).
success: submitSuccessful
});
} else {
// If the form is invalid.
Ext.MessageBox.alert('Error Message', 'Please fix the errors noted.');
}
}
function submitSuccessful(form, action) {
Ext.MessageBox.alert('Confirm', action.result.message);
// Hide the popup window.
window.hide();
// Reload the data store with a call to the server and load
// the grid again with the newly added person.
siteDataStore.load({params:{start:0, limit:10}});
}
function submitFailed(form, action) {
var failureMessage = "Error occurred trying to save data.";
// Failure type returned when no field values are returned in the
// response's data property or the successProperty value is false.
if (action.failureType == Ext.form.Action.LOAD_FAILURE) {
// Error on the server side will include an error message in
// the response.
failureMessage = action.result.message;
}
// Failure type returned when a communication error happens when
// attempting to send a request to the remote server.
else if (action.failureType == Ext.form.Action.CONNECT_FAILURE) {
// The XMLHttpRequest object containing the
// response data. See <a href="http://www.w3.org/TR/XMLHttpRequest/" target="_blank">http://www.w3.org/TR/XMLHttpRequest/</a> for
// details about accessing elements of the response.
failureMessage = "Please contact support with the following: " +
"Status: " + action.response.status +
", Status Text: " + action.response.statusText;
}
// Failure type returned when server side validation of the Form fails
// indicating that field-specific error messages have been returned in
// the response's errors property.
else if (action.failureType == Ext.form.Action.SERVER_INVALID) {
// Validation on the server side will include an error message in
// the response.
failureMessage = action.result.message;
}
// Failure type returned when client side validation of the Form fails
// thus aborting a submit action.
else if (action.failureType == Ext.form.Action.CLIENT_INVALID) {
failureMessage = "Please fix any and all validation errors.";
}
// Since none of the failure types handled the error, simply retrieve
// the message off of the response. The response from the server on a
// failed submital (application error) is:
// {success: false, message: 'Person was not saved successfully. Please try again.')
else {
failureMessage = action.result.message;
}
Ext.MessageBox.alert('Error Message', failureMessage);
}
}; |
Partager