You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
5.5 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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-data-JsonWriter'>/**
  19. </span> * @class Ext.data.JsonWriter
  20. * @extends Ext.data.DataWriter
  21. * DataWriter extension for writing an array or single {@link Ext.data.Record} object(s) in preparation for executing a remote CRUD action.
  22. */
  23. Ext.data.JsonWriter = Ext.extend(Ext.data.DataWriter, {
  24. <span id='Ext-data-JsonWriter-cfg-encode'> /**
  25. </span> * @cfg {Boolean} encode &lt;p&gt;&lt;tt&gt;true&lt;/tt&gt; to {@link Ext.util.JSON#encode JSON encode} the
  26. * {@link Ext.data.DataWriter#toHash hashed data} into a standard HTTP parameter named after this
  27. * Reader's &lt;code&gt;meta.root&lt;/code&gt; property which, by default is imported from the associated Reader. Defaults to &lt;tt&gt;true&lt;/tt&gt;.&lt;/p&gt;
  28. * &lt;p&gt;If set to &lt;code&gt;false&lt;/code&gt;, the hashed data is {@link Ext.util.JSON#encode JSON encoded}, along with
  29. * the associated {@link Ext.data.Store}'s {@link Ext.data.Store#baseParams baseParams}, into the POST body.&lt;/p&gt;
  30. * &lt;p&gt;When using {@link Ext.data.DirectProxy}, set this to &lt;tt&gt;false&lt;/tt&gt; since Ext.Direct.JsonProvider will perform
  31. * its own json-encoding. In addition, if you're using {@link Ext.data.HttpProxy}, setting to &lt;tt&gt;false&lt;/tt&gt;
  32. * will cause HttpProxy to transmit data using the &lt;b&gt;jsonData&lt;/b&gt; configuration-params of {@link Ext.Ajax#request}
  33. * instead of &lt;b&gt;params&lt;/b&gt;.&lt;/p&gt;
  34. * &lt;p&gt;When using a {@link Ext.data.Store#restful} Store, some serverside frameworks are
  35. * tuned to expect data through the jsonData mechanism. In those cases, one will want to set &lt;b&gt;encode: &lt;tt&gt;false&lt;/tt&gt;&lt;/b&gt;, as in
  36. * let the lower-level connection object (eg: Ext.Ajax) do the encoding.&lt;/p&gt;
  37. */
  38. encode : true,
  39. <span id='Ext-data-JsonWriter-cfg-encodeDelete'> /**
  40. </span> * @cfg {Boolean} encodeDelete False to send only the id to the server on delete, true to encode it in an object
  41. * literal, eg: &lt;pre&gt;&lt;code&gt;
  42. {id: 1}
  43. * &lt;/code&gt;&lt;/pre&gt; Defaults to &lt;tt&gt;false&lt;/tt&gt;
  44. */
  45. encodeDelete: false,
  46. <span id='Ext-data-JsonWriter-method-constructor'> constructor : function(config){
  47. </span> Ext.data.JsonWriter.superclass.constructor.call(this, config);
  48. },
  49. <span id='Ext-data-JsonWriter-method-render'> /**
  50. </span> * &lt;p&gt;This method should not need to be called by application code, however it may be useful on occasion to
  51. * override it, or augment it with an {@link Function#createInterceptor interceptor} or {@link Function#createSequence sequence}.&lt;/p&gt;
  52. * &lt;p&gt;The provided implementation encodes the serialized data representing the Store's modified Records into the Ajax request's
  53. * &lt;code&gt;params&lt;/code&gt; according to the &lt;code&gt;{@link #encode}&lt;/code&gt; setting.&lt;/p&gt;
  54. * @param {Object} Ajax request params object to write into.
  55. * @param {Object} baseParams as defined by {@link Ext.data.Store#baseParams}. The baseParms must be encoded by the extending class, eg: {@link Ext.data.JsonWriter}, {@link Ext.data.XmlWriter}.
  56. * @param {Object/Object[]} data Data object representing the serialized modified records from the Store. May be either a single object,
  57. * or an Array of objects - user implementations must handle both cases.
  58. */
  59. render : function(params, baseParams, data) {
  60. if (this.encode === true) {
  61. // Encode here now.
  62. Ext.apply(params, baseParams);
  63. params[this.meta.root] = Ext.encode(data);
  64. } else {
  65. // defer encoding for some other layer, probably in {@link Ext.Ajax#request}. Place everything into &quot;jsonData&quot; key.
  66. var jdata = Ext.apply({}, baseParams);
  67. jdata[this.meta.root] = data;
  68. params.jsonData = jdata;
  69. }
  70. },
  71. <span id='Ext-data-JsonWriter-method-createRecord'> /**
  72. </span> * Implements abstract Ext.data.DataWriter#createRecord
  73. * @protected
  74. * @param {Ext.data.Record} rec
  75. * @return {Object}
  76. */
  77. createRecord : function(rec) {
  78. return this.toHash(rec);
  79. },
  80. <span id='Ext-data-JsonWriter-method-updateRecord'> /**
  81. </span> * Implements abstract Ext.data.DataWriter#updateRecord
  82. * @protected
  83. * @param {Ext.data.Record} rec
  84. * @return {Object}
  85. */
  86. updateRecord : function(rec) {
  87. return this.toHash(rec);
  88. },
  89. <span id='Ext-data-JsonWriter-method-destroyRecord'> /**
  90. </span> * Implements abstract Ext.data.DataWriter#destroyRecord
  91. * @protected
  92. * @param {Ext.data.Record} rec
  93. * @return {Object}
  94. */
  95. destroyRecord : function(rec){
  96. if(this.encodeDelete){
  97. var data = {};
  98. data[this.meta.idProperty] = rec.id;
  99. return data;
  100. }else{
  101. return rec.id;
  102. }
  103. }
  104. });</pre>
  105. </body>
  106. </html>