1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
|
<html>
<head>
<title>The source code</title>
<link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../resources/prettify/prettify.js"></script>
</head>
<body onload="prettyPrint();">
<pre class="prettyprint lang-js">/*!
* Ext JS Library 3.0.3
* Copyright(c) 2006-2009 Ext JS, LLC
* licensing@extjs.com
* http://www.extjs.com/license
*/
<div id="cls-Ext.data.XmlWriter"></div>/**
* @class Ext.data.XmlWriter
* @extends Ext.data.DataWriter
* DataWriter extension for writing an array or single {@link Ext.data.Record} object(s) in preparation for executing a remote CRUD action via XML.
*/
Ext.data.XmlWriter = function(params) {
Ext.data.XmlWriter.superclass.constructor.apply(this, arguments);
this.tpl = new Ext.XTemplate(this.tpl).compile();
};
Ext.extend(Ext.data.XmlWriter, Ext.data.DataWriter, {
<div id="cfg-Ext.data.XmlWriter-root"></div>/**
* @cfg {String} root [records] The name of the root element when writing <b>multiple</b> records to the server. Each
* xml-record written to the server will be wrapped in an element named after {@link Ext.data.XmlReader#record} property.
* eg:
<code><pre>
<?xml version="1.0" encoding="UTF-8"?>
<user><first>Barney</first></user>
</code></pre>
* However, when <b>multiple</b> records are written in a batch-operation, these records must be wrapped in a containing
* Element.
* eg:
<code><pre>
<?xml version="1.0" encoding="UTF-8"?>
<records>
<first>Barney</first></user>
<records><first>Barney</first></user>
</records>
</code></pre>
* Defaults to <tt>records</tt>
*/
root: 'records',
<div id="cfg-Ext.data.XmlWriter-xmlVersion"></div>/**
* @cfg {String} xmlVersion [1.0] The <tt>version</tt> written to header of xml documents.
<code><pre><?xml version="1.0" encoding="ISO-8859-15"?></pre></code>
*/
xmlVersion : '1.0',
<div id="cfg-Ext.data.XmlWriter-xmlEncoding"></div>/**
* @cfg {String} xmlEncoding [ISO-8859-15] The <tt>encoding</tt> written to header of xml documents.
<code><pre><?xml version="1.0" encoding="ISO-8859-15"?></pre></code>
*/
xmlEncoding: 'ISO-8859-15',
<div id="cfg-Ext.data.XmlWriter-tpl"></div>/**
* @cfg {String} tpl The xml template. Defaults to
<code><pre>
<?xml version="{version}" encoding="{encoding}"?>
<tpl if="{[values.nodes.length>1]}"><{root}}>',
<tpl for="records">
<{parent.record}>
<tpl for="fields">
<{name}>{value}</{name}>
</tpl>
</{parent.record}>
</tpl>
<tpl if="{[values.records.length>1]}"></{root}}></tpl>
</pre></code>
*/
// Break up encoding here in case it's being included by some kind of page that will parse it (eg. PHP)
tpl: '<tpl for="."><' + '?xml version="{version}" encoding="{encoding}"?' + '><tpl if="documentRoot"><{documentRoot}><tpl for="baseParams"><tpl for="."><{name}>{value}</{name}</tpl></tpl></tpl><tpl if="records.length>1"><{root}></tpl><tpl for="records"><{parent.record}><tpl for="."><{name}>{value}</{name}></tpl></{parent.record}></tpl><tpl if="records.length>1"></{root}></tpl><tpl if="documentRoot"></{documentRoot}></tpl></tpl>',
<div id="method-Ext.data.XmlWriter-render"></div>/**
* Final action of a write event. Apply the written data-object to params.
* @param {String} action [Ext.data.Api.create|read|update|destroy]
* @param {Ext.data.Record/Ext.data.Record[]} rs
* @param {Object} http params
* @param {Object/Object[]} rendered data.
*/
render : function(action, rs, params, data) {
params.xmlData = this.tpl.applyTemplate({
version: this.xmlVersion,
encoding: this.xmlEncoding,
record: this.meta.record,
root: this.root,
records: (Ext.isArray(rs)) ? data : [data]
});
},
/**
* Converts an Ext.data.Record to xml
* @param {Ext.data.Record} rec
* @return {String} rendered xml-element
* @private
*/
toXml : function(data) {
var fields = [];
Ext.iterate(data, function(k, v) {
fields.push({
name: k,
value: v
});
},this);
return {
fields: fields
};
},
/**
* createRecord
* @param {Ext.data.Record} rec
* @return {String} xml element
* @private
*/
createRecord : function(rec) {
return this.toXml(this.toHash(rec));
},
/**
* updateRecord
* @param {Ext.data.Record} rec
* @return {String} xml element
* @private
*/
updateRecord : function(rec) {
return this.toXml(this.toHash(rec));
},
<div id="method-Ext.data.XmlWriter-destroyRecord"></div>/**
* destroyRecord
* @param {Ext.data.Record} rec
* @return {String} xml element
*/
destroyRecord : function(rec) {
var data = {};
data[this.meta.idProperty] = rec.id;
return this.toXml(data);
}
});
</pre>
</body>
</html>
|