Improved API of `Ajax/Request`
authorAlexander Ebert <ebert@woltlab.com>
Sat, 30 May 2015 19:20:07 +0000 (21:20 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Sat, 30 May 2015 19:20:07 +0000 (21:20 +0200)
wcfsetup/install/files/js/WoltLab/WCF/Ajax/Request.js

index 7b12064bed54bd86f8f41615de2f4ee679c64eb6..cfd81ba5082df16280ed6b9bf8dd0e07de95283e 100644 (file)
@@ -154,11 +154,6 @@ define(['Core', 'Language', 'DOM/ChangeListener', 'DOM/Util', 'UI/Dialog', 'Wolt
                /**
                 * Sets a specific option.
                 * 
-                * Do not call this method, it exists for compatibility with WCF.Action.Proxy
-                * and will be removed at some point without further notice.
-                * 
-                * @deprecated  2.2
-                * 
                 * @param       {string}        key     option name
                 * @param       {*}             value   option value
                 */
@@ -166,6 +161,20 @@ define(['Core', 'Language', 'DOM/ChangeListener', 'DOM/Util', 'UI/Dialog', 'Wolt
                        this._options[key] = value;
                },
                
+               /**
+                * Returns an option by key or undefined.
+                * 
+                * @param       {string}        key     option name
+                * @return      {(*|null)}      option value or null
+                */
+               getOption: function(key) {
+                       if (this._options.hasOwnProperty(key)) {
+                               return this._options[key];
+                       }
+                       
+                       return null;
+               },
+               
                /**
                 * Sets request data while honoring pinned data from setup callback.
                 * 
@@ -198,18 +207,18 @@ define(['Core', 'Language', 'DOM/ChangeListener', 'DOM/Util', 'UI/Dialog', 'Wolt
                                        }
                                        catch (e) {
                                                // invalid JSON
-                                               this._failure(xhr);
+                                               this._failure(xhr, options);
                                                
                                                return;
                                        }
                                        
                                        // trim HTML before processing, see http://jquery.com/upgrade-guide/1.9/#jquery-htmlstring-versus-jquery-selectorstring
-                                       if (data.returnValues !== undefined && data.returnValues.template !== undefined) {
+                                       if (data.returnValues && data.returnValues.template !== undefined) {
                                                data.returnValues.template = data.returnValues.template.trim();
                                        }
                                }
                                
-                               options.success(data, xhr.responseText, xhr);
+                               options.success(data, xhr.responseText, xhr, options.data);
                        }
                        
                        this._finalize(options);
@@ -239,7 +248,7 @@ define(['Core', 'Language', 'DOM/ChangeListener', 'DOM/Util', 'UI/Dialog', 'Wolt
                        
                        var showError = true;
                        if (typeof options.failure === 'function') {
-                               showError = options.failure(data, xhr);
+                               showError = options.failure(data, xhr.responseText, xhr, options.data);
                        }
                        
                        if (options.ignoreError !== true && showError !== false) {