XmlSimlet.html 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>The source code</title>
  6. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  8. <style type="text/css">
  9. .highlight { display: block; background-color: #ddd; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  17. <body onload="prettyPrint(); highlight();">
  18. <pre class="prettyprint lang-js"><span id='Ext-ux-ajax-XmlSimlet'>/**
  19. </span> * This class simulates XML-based requests.
  20. */
  21. Ext.define('Ext.ux.ajax.XmlSimlet', {
  22. extend: 'Ext.ux.ajax.DataSimlet',
  23. alias: 'simlet.xml',
  24. <span id='Ext-ux-ajax-XmlSimlet-property-xmlTpl'> /**
  25. </span> * This template is used to populate the XML response. The configuration of the Reader
  26. * is available so that its `root` and `record` properties can be used as well as the
  27. * `fields` of the associated `model`. But beyond that, the way these pieces are put
  28. * together in the document requires the flexibility of a template.
  29. */
  30. xmlTpl: [
  31. '&lt;{root}&gt;\n',
  32. '&lt;tpl for=&quot;data&quot;&gt;',
  33. ' &lt;{parent.record}&gt;\n',
  34. '&lt;tpl for=&quot;parent.fields&quot;&gt;',
  35. ' &lt;{name}&gt;{[parent[values.name]]}&lt;/{name}&gt;\n',
  36. '&lt;/tpl&gt;',
  37. ' &lt;/{parent.record}&gt;\n',
  38. '&lt;/tpl&gt;',
  39. '&lt;/{root}&gt;'
  40. ],
  41. doGet: function (ctx) {
  42. var me = this,
  43. data = me.getData(ctx),
  44. page = me.getPage(ctx, data),
  45. reader = ctx.xhr.options.proxy.reader,
  46. ret = me.callParent(arguments), // pick up status/statusText
  47. response = {
  48. data: page,
  49. reader: reader,
  50. fields: reader.model.getFields(),
  51. root: reader.root,
  52. record: reader.record
  53. };
  54. if (ctx.groupSpec) {
  55. response.summaryData = me.getSummary(ctx, data, page);
  56. }
  57. var tpl = Ext.XTemplate.getTpl(me, 'xmlTpl'),
  58. xml = tpl.apply(response),
  59. doc;
  60. if (typeof DOMParser != 'undefined') {
  61. doc = (new DOMParser()).parseFromString(xml, &quot;text/xml&quot;);
  62. } else {
  63. // IE doesn't have DOMParser, but fortunately, there is an ActiveX for XML
  64. doc = new ActiveXObject(&quot;Microsoft.XMLDOM&quot;);
  65. doc.async = false;
  66. doc.loadXML(xml);
  67. }
  68. ret.responseText = xml;
  69. ret.responseXML = doc;
  70. return ret;
  71. }
  72. });
  73. </pre>
  74. </body>
  75. </html>