Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This over-rides our form submit function and adds "CONTENT-TYPE: APPLICATION/XML" to the header
- Ext.extend(Ext.form.Action.Submit, Ext.form.Action, {
- type : 'submit',
- run : function(){
- var o = this.options;
- var method = this.getMethod();
- var isPost = method == 'POST';
- if(o.clientValidation === false || this.form.isValid()){
- Ext.Ajax.request(Ext.apply(this.createCallback(), {
- form:this.form.el.dom,
- url:this.getUrl(!isPost),
- method: method,
- headers: {
- 'Content-Type': 'application/xml'
- },
- params:isPost ? this.getParams() : null,
- isUpload: this.form.fileUpload
- }));
- }else if (o.clientValidation !== false){ // client validation failed
- this.failureType = Ext.form.Action.CLIENT_INVALID;
- this.form.afterAction(this, false);
- }
- },
- success : function(response){
- var result = this.processResponse(response);
- if(result === true || result.success){
- this.form.afterAction(this, true);
- return;
- }
- if(result.errors){
- this.form.markInvalid(result.errors);
- this.failureType = Ext.form.Action.SERVER_INVALID;
- }
- this.form.afterAction(this, false);
- },
- handleResponse : function(response){
- if(this.form.errorReader){
- var rs = this.form.errorReader.read(response);
- var errors = [];
- if(rs.records){
- for(var i = 0, len = rs.records.length; i < len; i++) {
- var r = rs.records[i];
- errors[i] = r.data;
- }
- }
- if(errors.length < 1){
- errors = null;
- }
- return {
- success : rs.success,
- errors : errors
- };
- }
- return Ext.decode(response.responseText);
- }
- });
- // This overrides our form serializer and makes it into XML instead of &this=that junk
- Ext.lib.Ajax.serializeForm = function(form) {
- if(typeof form == 'string') {
- form = (document.getElementById(form) || document.forms[form]);
- }
- var el, name, val, disabled, data = '', hasSubmit = false;
- for (var i = 0; i < form.elements.length; i++) {
- el = form.elements[i];
- disabled = form.elements[i].disabled;
- name = form.elements[i].name;
- val = form.elements[i].value;
- if (!disabled && name){
- switch (el.type)
- {
- case 'select-one':
- case 'select-multiple':
- for (var j = 0; j < el.options.length; j++) {
- if (el.options[j].selected) {
- if (Ext.isIE) {
- data += '<' + encodeURIComponent(name) + '>' + encodeURIComponent(el.options[j].attributes['value'].specified ? el.options[j].value : el.options[j].text) + '</' + encodeURIComponent(name) + '>';
- }
- else {
- data += '<' + encodeURIComponent(name) + '>' + encodeURIComponent(el.options[j].hasAttribute('value') ? el.options[j].value : el.options[j].text) + '</' + encodeURIComponent(name) + '>';
- }
- }
- }
- break;
- case 'radio':
- case 'checkbox':
- if (el.checked) {
- data += '<' + encodeURIComponent(name) + '>' + encodeURIComponent(val) + '</' + encodeURIComponent(name) + '>';
- }
- break;
- case 'file':
- case undefined:
- case 'reset':
- case 'button':
- break;
- case 'submit':
- if(hasSubmit == false) {
- data += '<' + encodeURIComponent(name) + '>' + encodeURIComponent(val) + '</' + encodeURIComponent(name) + '>';
- hasSubmit = true;
- }
- break;
- default:
- data += '<' + encodeURIComponent(name) + '>' + val + '</' + encodeURIComponent(name) + '>';
- break;
- }
- }
- }
- // This takes the trailing & off...
- // data = data.substr(0, data.length - 1);
- return '<object>'+data+'</object>';
- }
Add Comment
Please, Sign In to add comment