X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/c930e9176a5a85509c5b0230e2bff5c22a591432..25ef3491bd9ae007ff1fc2b0d7943e6eaaccf775:/src/data/XmlWriter.js
diff --git a/src/data/XmlWriter.js b/src/data/XmlWriter.js
index a4aabbca..270de9e6 100644
--- a/src/data/XmlWriter.js
+++ b/src/data/XmlWriter.js
@@ -1,5 +1,5 @@
/*!
- * Ext JS Library 3.0.0
+ * Ext JS Library 3.0.3
* Copyright(c) 2006-2009 Ext JS, LLC
* licensing@extjs.com
* http://www.extjs.com/license
@@ -9,37 +9,125 @@
* @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 = Ext.extend(Ext.data.DataWriter, {
+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, {
+ /**
+ * @cfg {String} root [records] The name of the root element when writing multiple 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:
+
+<?xml version="1.0" encoding="UTF-8"?>
+<user><first>Barney</first></user>
+
+ * However, when multiple records are written in a batch-operation, these records must be wrapped in a containing
+ * Element.
+ * eg:
+
+<?xml version="1.0" encoding="UTF-8"?>
+ <records>
+ <first>Barney</first></user>
+ <records><first>Barney</first></user>
+ </records>
+
+ * Defaults to records
+ */
+ root: 'records',
+ /**
+ * @cfg {String} xmlVersion [1.0] The version written to header of xml documents.
+<?xml version="1.0" encoding="ISO-8859-15"?>
+ */
+ xmlVersion : '1.0',
+ /**
+ * @cfg {String} xmlEncoding [ISO-8859-15] The encoding written to header of xml documents.
+<?xml version="1.0" encoding="ISO-8859-15"?>
+ */
+ xmlEncoding: 'ISO-8859-15',
+ /**
+ * @cfg {String} tpl The xml template. Defaults to
+
+<?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>
+
+ */
+ // Break up encoding here in case it's being included by some kind of page that will parse it (eg. PHP)
+ tpl: '<' + '?xml version="{version}" encoding="{encoding}"?' + '><{documentRoot}><{name}>{value}{name}<{root}><{parent.record}><{name}>{value}{name}>{parent.record}>{root}>{documentRoot}>',
+
/**
* Final action of a write event. Apply the written data-object to params.
* @param {String} action [Ext.data.Api.create|read|update|destroy]
- * @param {Record[]} rs
+ * @param {Ext.data.Record/Ext.data.Record[]} rs
* @param {Object} http params
- * @param {Object} data object populated according to DataReader meta-data "root" and "idProperty"
+ * @param {Object/Object[]} rendered data.
*/
render : function(action, rs, params, data) {
- // no impl.
+ 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) {
- // no impl
+ return this.toXml(this.toHash(rec));
},
+
/**
* updateRecord
* @param {Ext.data.Record} rec
+ * @return {String} xml element
+ * @private
*/
updateRecord : function(rec) {
- // no impl.
+ return this.toXml(this.toHash(rec));
},
/**
* destroyRecord
* @param {Ext.data.Record} rec
+ * @return {String} xml element
*/
destroyRecord : function(rec) {
- // no impl
+ var data = {};
+ data[this.meta.idProperty] = rec.id;
+ return this.toXml(data);
}
-});
\ No newline at end of file
+});
+