Guest User

Untitled

a guest
Apr 21st, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.53 KB | None | 0 0
  1. // This over-rides our form submit function and adds "CONTENT-TYPE: APPLICATION/XML" to the header
  2. Ext.extend(Ext.form.Action.Submit, Ext.form.Action, {
  3. type : 'submit',
  4.  
  5. run : function(){
  6. var o = this.options;
  7. var method = this.getMethod();
  8. var isPost = method == 'POST';
  9. if(o.clientValidation === false || this.form.isValid()){
  10. Ext.Ajax.request(Ext.apply(this.createCallback(), {
  11. form:this.form.el.dom,
  12. url:this.getUrl(!isPost),
  13. method: method,
  14. headers: {
  15. 'Content-Type': 'application/xml'
  16. },
  17. params:isPost ? this.getParams() : null,
  18. isUpload: this.form.fileUpload
  19. }));
  20.  
  21. }else if (o.clientValidation !== false){ // client validation failed
  22. this.failureType = Ext.form.Action.CLIENT_INVALID;
  23. this.form.afterAction(this, false);
  24. }
  25. },
  26.  
  27. success : function(response){
  28. var result = this.processResponse(response);
  29. if(result === true || result.success){
  30. this.form.afterAction(this, true);
  31. return;
  32. }
  33. if(result.errors){
  34. this.form.markInvalid(result.errors);
  35. this.failureType = Ext.form.Action.SERVER_INVALID;
  36. }
  37. this.form.afterAction(this, false);
  38. },
  39.  
  40. handleResponse : function(response){
  41. if(this.form.errorReader){
  42. var rs = this.form.errorReader.read(response);
  43. var errors = [];
  44. if(rs.records){
  45. for(var i = 0, len = rs.records.length; i < len; i++) {
  46. var r = rs.records[i];
  47. errors[i] = r.data;
  48. }
  49. }
  50. if(errors.length < 1){
  51. errors = null;
  52. }
  53. return {
  54. success : rs.success,
  55. errors : errors
  56. };
  57. }
  58. return Ext.decode(response.responseText);
  59. }
  60. });
  61.  
  62. // This overrides our form serializer and makes it into XML instead of &this=that junk
  63. Ext.lib.Ajax.serializeForm = function(form) {
  64. if(typeof form == 'string') {
  65. form = (document.getElementById(form) || document.forms[form]);
  66. }
  67.  
  68. var el, name, val, disabled, data = '', hasSubmit = false;
  69. for (var i = 0; i < form.elements.length; i++) {
  70. el = form.elements[i];
  71. disabled = form.elements[i].disabled;
  72. name = form.elements[i].name;
  73. val = form.elements[i].value;
  74.  
  75. if (!disabled && name){
  76. switch (el.type)
  77. {
  78. case 'select-one':
  79. case 'select-multiple':
  80. for (var j = 0; j < el.options.length; j++) {
  81. if (el.options[j].selected) {
  82. if (Ext.isIE) {
  83. data += '<' + encodeURIComponent(name) + '>' + encodeURIComponent(el.options[j].attributes['value'].specified ? el.options[j].value : el.options[j].text) + '</' + encodeURIComponent(name) + '>';
  84. }
  85. else {
  86. data += '<' + encodeURIComponent(name) + '>' + encodeURIComponent(el.options[j].hasAttribute('value') ? el.options[j].value : el.options[j].text) + '</' + encodeURIComponent(name) + '>';
  87. }
  88. }
  89. }
  90. break;
  91. case 'radio':
  92. case 'checkbox':
  93. if (el.checked) {
  94. data += '<' + encodeURIComponent(name) + '>' + encodeURIComponent(val) + '</' + encodeURIComponent(name) + '>';
  95. }
  96. break;
  97. case 'file':
  98.  
  99. case undefined:
  100.  
  101. case 'reset':
  102.  
  103. case 'button':
  104.  
  105. break;
  106. case 'submit':
  107. if(hasSubmit == false) {
  108. data += '<' + encodeURIComponent(name) + '>' + encodeURIComponent(val) + '</' + encodeURIComponent(name) + '>';
  109. hasSubmit = true;
  110. }
  111. break;
  112. default:
  113. data += '<' + encodeURIComponent(name) + '>' + val + '</' + encodeURIComponent(name) + '>';
  114. break;
  115. }
  116. }
  117. }
  118. // This takes the trailing & off...
  119. // data = data.substr(0, data.length - 1);
  120. return '<object>'+data+'</object>';
  121. }
Add Comment
Please, Sign In to add comment