Upgrade to ExtJS 3.3.0 - Released 10/06/2010
[extjs.git] / docs / source / Api.html
index 5c7c57e..21e640f 100644 (file)
@@ -1,11 +1,19 @@
-<html>\r
-<head>\r
-  <title>The source code</title>\r
-    <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />\r
-    <script type="text/javascript" src="../resources/prettify/prettify.js"></script>\r
-</head>\r
-<body  onload="prettyPrint();">\r
-    <pre class="prettyprint lang-js"><div id="cls-Ext.data.Api"></div>/**
+<html>
+<head>
+  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />    
+  <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.3.0
+ * Copyright(c) 2006-2010 Ext JS, Inc.
+ * licensing@extjs.com
+ * http://www.extjs.com/license
+ */
+
+<div id="cls-Ext.data.Api"></div>/**
  * @class Ext.data.Api
  * @extends Object
  * Ext.data.Api is a singleton designed to manage the data API including methods
@@ -65,8 +73,7 @@ restActions : {
 
         <div id="method-Ext.data.Api-isAction"></div>/**
          * Returns true if supplied action-name is a valid API action defined in <code>{@link #actions}</code> constants
-         * @param {String} action
-         * @param {String[]}(Optional) List of available CRUD actions.  Pass in list when executing multiple times for efficiency.
+         * @param {String} action Action to test for availability.
          * @return {Boolean}
          */
         isAction : function(action) {
@@ -98,7 +105,7 @@ restActions : {
         <div id="method-Ext.data.Api-isValid"></div>/**
          * Returns true if the supplied API is valid; that is, check that all keys match defined actions
          * otherwise returns an array of mistakes.
-         * @return {String[]||true}
+         * @return {String[]|true}
          */
         isValid : function(api){
             var invalid = [];
@@ -169,7 +176,8 @@ new Ext.data.HttpProxy({
                 proxy.api[action] = proxy.api[action] || proxy.url || proxy.directFn;
                 if (typeof(proxy.api[action]) == 'string') {
                     proxy.api[action] = {
-                        url: proxy.api[action]
+                        url: proxy.api[action],
+                        method: (proxy.restful === true) ? Ext.data.Api.restActions[action] : undefined
                     };
                 }
             }
@@ -183,34 +191,44 @@ new Ext.data.HttpProxy({
         restify : function(proxy) {
             proxy.restful = true;
             for (var verb in this.restActions) {
-                proxy.api[this.actions[verb]].method = this.restActions[verb];
+                proxy.api[this.actions[verb]].method ||
+                    (proxy.api[this.actions[verb]].method = this.restActions[verb]);
             }
             // TODO: perhaps move this interceptor elsewhere?  like into DataProxy, perhaps?  Placed here
             // to satisfy initial 3.0 final release of REST features.
             proxy.onWrite = proxy.onWrite.createInterceptor(function(action, o, response, rs) {
                 var reader = o.reader;
-                var res = {};
+                var res = new Ext.data.Response({
+                    action: action,
+                    raw: response
+                });
+
                 switch (response.status) {
-                    case 200:   // standard 200 response, send control back to HttpProxy#onWrite
+                    case 200:   // standard 200 response, send control back to HttpProxy#onWrite by returning true from this intercepted #onWrite
                         return true;
                         break;
                     case 201:   // entity created but no response returned
-                        res[reader.meta.successProperty] = true;
+                        if (Ext.isEmpty(res.raw.responseText)) {
+                          res.success = true;
+                        } else {
+                          //if the response contains data, treat it like a 200
+                          return true;
+                        }
                         break;
                     case 204:  // no-content.  Create a fake response.
-                        res[reader.meta.successProperty] = true;
-                        res[reader.meta.root] = null;
+                        res.success = true;
+                        res.data = null;
                         break;
                     default:
                         return true;
                         break;
                 }
-                if (res[reader.meta.successProperty] === true) {
-                    this.fireEvent("write", this, action, res[reader.meta.root], res, rs, o.request.arg);
+                if (res.success === true) {
+                    this.fireEvent("write", this, action, res.data, res, rs, o.request.arg);
                 } else {
                     this.fireEvent('exception', this, 'remote', action, o, res, rs);
                 }
-                o.request.callback.call(o.request.scope, res[reader.meta.root], res, res[reader.meta.successProperty]);
+                o.request.callback.call(o.request.scope, res.data, res, res.success);
 
                 return false;   // <-- false to prevent intercepted function from running.
             }, proxy);
@@ -218,6 +236,39 @@ new Ext.data.HttpProxy({
     };
 })();
 
+<div id="method-Ext.data.Api-Response"></div>/**
+ * Ext.data.Response
+ * Experimental.  Do not use directly.
+ */
+Ext.data.Response = function(params, response) {
+    Ext.apply(this, params, {
+        raw: response
+    });
+};
+Ext.data.Response.prototype = {
+    message : null,
+    success : false,
+    status : null,
+    root : null,
+    raw : null,
+
+    getMessage : function() {
+        return this.message;
+    },
+    getSuccess : function() {
+        return this.success;
+    },
+    getStatus : function() {
+        return this.status;
+    },
+    getRoot : function() {
+        return this.root;
+    },
+    getRawResponse : function() {
+        return this.raw;
+    }
+};
+
 <div id="cls-Ext.data.Api.Error"></div>/**
  * @class Ext.data.Api.Error
  * @extends Ext.Error
@@ -238,6 +289,8 @@ Ext.apply(Ext.data.Api.Error.prototype, {
         'execute': 'Attempted to execute an unknown action.  Valid API actions are defined in Ext.data.Api.actions"'
     }
 });
-</pre>    \r
-</body>\r
+
+
+</pre>    
+</body>
 </html>
\ No newline at end of file