]> git.proxmox.com Git - extjs.git/blob - extjs/packages/soap/src/data/soap/Proxy.js
add extjs 6.0.1 sources
[extjs.git] / extjs / packages / soap / src / data / soap / Proxy.js
1 // @tag enterprise
2 /**
3 * The SOAP Proxy class is an {@link Ext.data.proxy.Ajax Ajax Proxy} to access v1.1 SOAP
4 * (Simple Object Access Protocol) services. SOAP Proxy constructs a SOAP Envelope and
5 * submits an AJAX request to load a SOAP response from the server.
6 *
7 * For help getting started please refer to the [Soap Guide](../../../enterprise/soap.html).
8 *
9 * **Note: ** _This functionality is only available with the purchase of
10 * Sencha Complete. For more information about using this class, please visit
11 * our [Sencha Complete](https://www.sencha.com/products/complete/) product page._
12 *
13 * @class Ext.data.soap.Proxy
14 */
15 Ext.define('Ext.data.soap.Proxy', {
16 extend: 'Ext.data.proxy.Ajax',
17 alias: 'proxy.soap',
18
19 requires: [
20 'Ext.data.soap.Reader'
21 ],
22
23 config: {
24 /**
25 * @cfg {Object} api
26 * An object containing "create", "read", "update" and "destroy" properties that define
27 * SOAP operations for each CRUD action method. These operations will be appended to
28 * the {@link #url} as the {@link #operationParam} for each request type.
29 *
30 * api: {
31 * create: undefined,
32 * read: undefined,
33 * update: undefined,
34 * destroy: undefined
35 * }
36 *
37 * At least one operation is required, but additional operations do not need to be configured
38 * if they will not be used. For example, if this proxy is only used for read operations
39 * the following configuration will be sufficient:
40 *
41 * api: {
42 * read: 'Foo'
43 * }
44 */
45
46 /**
47 * @cfg {Object} soapAction
48 * An object containing "create", "read", "update" and "destroy" properties that define
49 * the [SOAPAction](http://www.w3.org/TR/2000/NOTE-SOAP-20000508/#_Toc478383528) header
50 * for each CRUD action method. A soapAction must be specified for each operation
51 * configured in {@link #api} Defaults to:
52 *
53 * soapAction: {
54 * create: undefined,
55 * read: undefined,
56 * update: undefined,
57 * destroy: undefined
58 * }
59 */
60 soapAction: {},
61
62 /**
63 * @cfg {String} [operationParam='op']
64 * The name of the operation parameter to be appened to the SOAP endpoint url
65 */
66 operationParam: 'op',
67
68 /**
69 * @cfg {Object/String/Ext.data.soap.Reader} [reader='soap']
70 * The {@link Ext.data.soap.Reader} to use to decode the server's response. This can
71 * either be a SOAP Reader instance, a SOAP Reader config object or 'soap'.
72 */
73 reader: 'soap',
74
75 /**
76 * @cfg {String} url
77 * The SOAP endpoint url that this proxy will use to request the SOAP data. This can
78 * be a proxied url to work around same-origin policy if the SOAP endpoint url is on
79 * a different domain from your application.
80 */
81 url: '',
82
83 /**
84 * @cfg [envelopeTpl=undefined]
85 * The template used to create the SOAP envelope. Defaults to:
86 *
87 * [
88 * '<?xml version="1.0" encoding="utf-8" ?>',
89 * '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">',
90 * '{[values.bodyTpl.apply(values)]}',
91 * '</soap:Envelope>'
92 * ]
93 */
94 envelopeTpl: [
95 '<?xml version="1.0" encoding="utf-8" ?>',
96 '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">',
97 '{[values.bodyTpl.apply(values)]}',
98 '</soap:Envelope>'
99 ],
100
101 /**
102 * @cfg {Ext.XTemplate/Array} createBodyTpl
103 * The template used to create the SOAP body for the "create" action. If not specified
104 * {@link #writeBodyTpl} will be used for the "create" action.
105 */
106 createBodyTpl: null,
107
108 /**
109 * @cfg {Ext.XTemplate/Array} [readBodyTpl=undefined]
110 * The template used to create the SOAP body for the "read" action. Defaults to:
111 *
112 * [
113 * '<soap:Body>',
114 * '<{operation} xmlns="{targetNamespace}">',
115 * '<tpl foreach="params">',
116 * '<{$}>{.}</{$}>',
117 * '</tpl>',
118 * '</{operation}>',
119 * '</soap:Body>'
120 * ]
121 */
122 readBodyTpl: [
123 '<soap:Body>',
124 '<{operation} xmlns="{targetNamespace}">',
125 '<tpl foreach="params">',
126 '<{$}>{.}</{$}>',
127 '</tpl>',
128 '</{operation}>',
129 '</soap:Body>'
130 ],
131
132 /**
133 * @cfg {Ext.XTemplate/Array} updateBodyTpl
134 * The template used to create the SOAP body for the "update" action. If not specified
135 * {@link #writeBodyTpl} will be used for the "update" action.
136 */
137 updateBodyTpl: null,
138
139 /**
140 * @cfg {Ext.XTemplate/Array} destroyBodyTpl
141 * The template used to create the SOAP body for the "destroy" action. If not specified
142 * {@link #writeBodyTpl} will be used for the "destroy" action.
143 */
144 destroyBodyTpl: null,
145
146 /**
147 * @cfg {Ext.XTemplate/Array} [writeBodyTpl=undefined]
148 * The default template used to create the SOAP body for write actions (create, update,
149 * and destroy). The individual body templates for each write action can be configured
150 * using {@link #createBodyTpl}, {@link #updateBodyTpl}, and {@link #destroyBodyTpl}.
151 * Defaults to:
152 *
153 * [
154 * '<soap:Body>',
155 * '<{operation} xmlns="{targetNamespace}">',
156 * '<tpl for="records">',
157 * '{% var recordName=values.modelName.split(".").pop(); %}',
158 * '<{[recordName]}>',
159 * '<tpl for="fields">',
160 * '<{name}>{[parent.get(values.name)]}</{name}>',
161 * '</tpl>',
162 * '</{[recordName]}>',
163 * '</tpl>',
164 * '</{operation}>',
165 * '</soap:Body>'
166 * ]
167 */
168 writeBodyTpl: [
169 '<soap:Body>',
170 '<{operation} xmlns="{targetNamespace}">',
171 '<tpl for="records">',
172 '{% var recordName=values.modelName.split(".").pop(); %}',
173 '<{[recordName]}>',
174 '<tpl for="fields">',
175 '<{name}>{[parent.get(values.name)]}</{name}>',
176 '</tpl>',
177 '</{[recordName]}>',
178 '</tpl>',
179 '</{operation}>',
180 '</soap:Body>'
181 ],
182
183 /**
184 * @cfg {String} targetNamespace
185 * namespace URI used by {@link #createBodyTpl}, {@link #readBodyTpl}, {@link #updateBodyTpl},
186 * and {@link #destroyBodyTpl} as the "xmlns" attribute for the operation element.
187 */
188 targetNamespace: ''
189 },
190
191 applyEnvelopeTpl: function(tpl) {
192 return this.createTpl(tpl);
193 },
194
195 applyCreateBodyTpl: function(tpl) {
196 return this.createTpl(tpl);
197 },
198
199 applyReadBodyTpl: function(tpl) {
200 return this.createTpl(tpl);
201 },
202
203 applyUpdateBodyTpl: function(tpl) {
204 return this.createTpl(tpl);
205 },
206
207 applyDestroyBodyTpl: function(tpl) {
208 return this.createTpl(tpl);
209 },
210
211 applyWriteBodyTpl: function(tpl) {
212 return this.createTpl(tpl);
213 },
214
215 createTpl: function(tpl) {
216 if (tpl && !tpl.isTpl) {
217 tpl = new Ext.XTemplate(tpl);
218 }
219 return tpl;
220 },
221
222 /**
223 * @property {Object} actionMethods
224 * @readonly
225 * Mapping of action name to HTTP request method. All SOAP actions are mapped to 'POST'
226 */
227
228 doRequest: function(operation) {
229 var me = this,
230 action = operation.getAction(),
231 soapOperation = me.getApi()[action],
232 params = Ext.applyIf(operation.getParams() || {}, me.getExtraParams() || {}),
233 xmlData = me.getEnvelopeTpl().apply({
234 operation: soapOperation,
235 targetNamespace: me.getTargetNamespace(),
236 params: params,
237 records: operation.getRecords(),
238 bodyTpl: me.getBodyTpl(action)
239 }),
240 request = new Ext.data.Request({
241 url: me.getUrl() + '?' + me.getOperationParam() + '=' + soapOperation,
242 method: 'POST',
243 action: action,
244 operation: operation,
245 xmlData: xmlData,
246 headers: Ext.apply({
247 SOAPAction: me.getSoapAction()[action]
248 }, me.getHeaders()),
249 timeout: me.getTimeout(),
250 scope: me,
251 disableCaching: false // explicitly set it to false, ServerProxy handles caching
252 });
253
254 request.setCallback(me.createRequestCallback(request, operation));
255 return me.sendRequest(request);
256 },
257
258 getBodyTpl: function(action) {
259 action = Ext.String.capitalize(action);
260 var tpl = this['get' + action + 'BodyTpl']();
261 return tpl || this.getWriteBodyTpl();
262 }
263 });