Web Interface For Lite Argus Control modules
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.

168 lines
9.3 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <title>The source code</title>
  5. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  6. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  7. </head>
  8. <body onload="prettyPrint();">
  9. <pre class="prettyprint lang-js">/*!
  10. * Ext JS Library 3.3.1
  11. * Copyright(c) 2006-2010 Sencha Inc.
  12. * licensing@sencha.com
  13. * http://www.sencha.com/license
  14. */
  15. <div id="cls-Ext.data.XmlWriter"></div>/**
  16. * @class Ext.data.XmlWriter
  17. * @extends Ext.data.DataWriter
  18. * DataWriter extension for writing an array or single {@link Ext.data.Record} object(s) in preparation for executing a remote CRUD action via XML.
  19. * XmlWriter uses an instance of {@link Ext.XTemplate} for maximum flexibility in defining your own custom XML schema if the default schema is not appropriate for your needs.
  20. * See the {@link #tpl} configuration-property.
  21. */
  22. Ext.data.XmlWriter = function(params) {
  23. Ext.data.XmlWriter.superclass.constructor.apply(this, arguments);
  24. // compile the XTemplate for rendering XML documents.
  25. this.tpl = (typeof(this.tpl) === 'string') ? new Ext.XTemplate(this.tpl).compile() : this.tpl.compile();
  26. };
  27. Ext.extend(Ext.data.XmlWriter, Ext.data.DataWriter, {
  28. <div id="cfg-Ext.data.XmlWriter-documentRoot"></div>/**
  29. * @cfg {String} documentRoot [xrequest] (Optional) The name of the XML document root-node. <b>Note:</b>
  30. * this parameter is required </b>only when</b> sending extra {@link Ext.data.Store#baseParams baseParams} to the server
  31. * during a write-request -- if no baseParams are set, the {@link Ext.data.XmlReader#record} meta-property can
  32. * suffice as the XML document root-node for write-actions involving just a <b>single record</b>. For requests
  33. * involving <b>multiple</b> records and <b>NO</b> baseParams, the {@link Ext.data.XmlWriter#root} property can
  34. * act as the XML document root.
  35. */
  36. documentRoot: 'xrequest',
  37. <div id="cfg-Ext.data.XmlWriter-forceDocumentRoot"></div>/**
  38. * @cfg {Boolean} forceDocumentRoot [false] Set to <tt>true</tt> to force XML documents having a root-node as defined
  39. * by {@link #documentRoot}, even with no baseParams defined.
  40. */
  41. forceDocumentRoot: false,
  42. <div id="cfg-Ext.data.XmlWriter-root"></div>/**
  43. * @cfg {String} root [records] The name of the containing element which will contain the nodes of an write-action involving <b>multiple</b> records. Each
  44. * xml-record written to the server will be wrapped in an element named after {@link Ext.data.XmlReader#record} property.
  45. * eg:
  46. <code><pre>
  47. &lt;?xml version="1.0" encoding="UTF-8"?>
  48. &lt;user>&lt;first>Barney&lt;/first>&lt;/user>
  49. </code></pre>
  50. * However, when <b>multiple</b> records are written in a batch-operation, these records must be wrapped in a containing
  51. * Element.
  52. * eg:
  53. <code><pre>
  54. &lt;?xml version="1.0" encoding="UTF-8"?>
  55. &lt;records>
  56. &lt;first>Barney&lt;/first>&lt;/user>
  57. &lt;records>&lt;first>Barney&lt;/first>&lt;/user>
  58. &lt;/records>
  59. </code></pre>
  60. * Defaults to <tt>records</tt>. Do not confuse the nature of this property with that of {@link #documentRoot}
  61. */
  62. root: 'records',
  63. <div id="cfg-Ext.data.XmlWriter-xmlVersion"></div>/**
  64. * @cfg {String} xmlVersion [1.0] The <tt>version</tt> written to header of xml documents.
  65. <code><pre>&lt;?xml version="1.0" encoding="ISO-8859-15"?></pre></code>
  66. */
  67. xmlVersion : '1.0',
  68. <div id="cfg-Ext.data.XmlWriter-xmlEncoding"></div>/**
  69. * @cfg {String} xmlEncoding [ISO-8859-15] The <tt>encoding</tt> written to header of xml documents.
  70. <code><pre>&lt;?xml version="1.0" encoding="ISO-8859-15"?></pre></code>
  71. */
  72. xmlEncoding: 'ISO-8859-15',
  73. <div id="cfg-Ext.data.XmlWriter-tpl"></div>/**
  74. * @cfg {String/Ext.XTemplate} tpl The XML template used to render {@link Ext.data.Api#actions write-actions} to your server.
  75. * <p>One can easily provide his/her own custom {@link Ext.XTemplate#constructor template-definition} if the default does not suffice.</p>
  76. * <p>Defaults to:</p>
  77. <code><pre>
  78. &lt;?xml version="{version}" encoding="{encoding}"?>
  79. &lt;tpl if="documentRoot">&lt;{documentRoot}>
  80. &lt;tpl for="baseParams">
  81. &lt;tpl for=".">
  82. &lt;{name}>{value}&lt;/{name}>
  83. &lt;/tpl>
  84. &lt;/tpl>
  85. &lt;tpl if="records.length &gt; 1">&lt;{root}>',
  86. &lt;tpl for="records">
  87. &lt;{parent.record}>
  88. &lt;tpl for=".">
  89. &lt;{name}>{value}&lt;/{name}>
  90. &lt;/tpl>
  91. &lt;/{parent.record}>
  92. &lt;/tpl>
  93. &lt;tpl if="records.length &gt; 1">&lt;/{root}>&lt;/tpl>
  94. &lt;tpl if="documentRoot">&lt;/{documentRoot}>&lt;/tpl>
  95. </pre></code>
  96. * <p>Templates will be called with the following API</p>
  97. * <ul>
  98. * <li>{String} version [1.0] The xml version.</li>
  99. * <li>{String} encoding [ISO-8859-15] The xml encoding.</li>
  100. * <li>{String/false} documentRoot The XML document root-node name or <tt>false</tt> if not required. See {@link #documentRoot} and {@link #forceDocumentRoot}.</li>
  101. * <li>{String} record The meta-data parameter defined on your {@link Ext.data.XmlReader#record} configuration represents the name of the xml-tag containing each record.</li>
  102. * <li>{String} root The meta-data parameter defined by {@link Ext.data.XmlWriter#root} configuration-parameter. Represents the name of the xml root-tag when sending <b>multiple</b> records to the server.</li>
  103. * <li>{Array} records The records being sent to the server, ie: the subject of the write-action being performed. The records parameter will be always be an array, even when only a single record is being acted upon.
  104. * Each item within the records array will contain an array of field objects having the following properties:
  105. * <ul>
  106. * <li>{String} name The field-name of the record as defined by your {@link Ext.data.Record#create Ext.data.Record definition}. The "mapping" property will be used, otherwise it will match the "name" property. Use this parameter to define the XML tag-name of the property.</li>
  107. * <li>{Mixed} value The record value of the field enclosed within XML tags specified by name property above.</li>
  108. * </ul></li>
  109. * <li>{Array} baseParams. The baseParams as defined upon {@link Ext.data.Store#baseParams}. Note that the baseParams have been converted into an array of [{name : "foo", value: "bar"}, ...] pairs in the same manner as the <b>records</b> parameter above. See {@link #documentRoot} and {@link #forceDocumentRoot}.</li>
  110. * </ul>
  111. */
  112. // Encoding the ? here in case it's being included by some kind of page that will parse it (eg. PHP)
  113. tpl: '<tpl for="."><\u003fxml version="{version}" encoding="{encoding}"\u003f><tpl if="documentRoot"><{documentRoot}><tpl for="baseParams"><tpl for="."><{name}>{value}</{name}></tpl></tpl></tpl><tpl if="records.length&gt;1"><{root}></tpl><tpl for="records"><{parent.record}><tpl for="."><{name}>{value}</{name}></tpl></{parent.record}></tpl><tpl if="records.length&gt;1"></{root}></tpl><tpl if="documentRoot"></{documentRoot}></tpl></tpl>',
  114. <div id="method-Ext.data.XmlWriter-render"></div>/**
  115. * XmlWriter implementation of the final stage of a write action.
  116. * @param {Object} params Transport-proxy's (eg: {@link Ext.Ajax#request}) params-object to write-to.
  117. * @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}.
  118. * @param {Object/Object[]} data Data-object representing the compiled Store-recordset.
  119. */
  120. render : function(params, baseParams, data) {
  121. baseParams = this.toArray(baseParams);
  122. params.xmlData = this.tpl.applyTemplate({
  123. version: this.xmlVersion,
  124. encoding: this.xmlEncoding,
  125. documentRoot: (baseParams.length > 0 || this.forceDocumentRoot === true) ? this.documentRoot : false,
  126. record: this.meta.record,
  127. root: this.root,
  128. baseParams: baseParams,
  129. records: (Ext.isArray(data[0])) ? data : [data]
  130. });
  131. },
  132. <div id="method-Ext.data.XmlWriter-createRecord"></div>/**
  133. * createRecord
  134. * @protected
  135. * @param {Ext.data.Record} rec
  136. * @return {Array} Array of <tt>name:value</tt> pairs for attributes of the {@link Ext.data.Record}. See {@link Ext.data.DataWriter#toHash}.
  137. */
  138. createRecord : function(rec) {
  139. return this.toArray(this.toHash(rec));
  140. },
  141. <div id="method-Ext.data.XmlWriter-updateRecord"></div>/**
  142. * updateRecord
  143. * @protected
  144. * @param {Ext.data.Record} rec
  145. * @return {Array} Array of {name:value} pairs for attributes of the {@link Ext.data.Record}. See {@link Ext.data.DataWriter#toHash}.
  146. */
  147. updateRecord : function(rec) {
  148. return this.toArray(this.toHash(rec));
  149. },
  150. <div id="method-Ext.data.XmlWriter-destroyRecord"></div>/**
  151. * destroyRecord
  152. * @protected
  153. * @param {Ext.data.Record} rec
  154. * @return {Array} Array containing a attribute-object (name/value pair) representing the {@link Ext.data.DataReader#idProperty idProperty}.
  155. */
  156. destroyRecord : function(rec) {
  157. var data = {};
  158. data[this.meta.idProperty] = rec.id;
  159. return this.toArray(data);
  160. }
  161. });
  162. </pre>
  163. </body>
  164. </html>