From a84cb293814e7128a3010406962bb0cf16b51185 Mon Sep 17 00:00:00 2001 From: jlukic Date: Tue, 14 Apr 2015 12:54:02 -0400 Subject: [PATCH] Adds updated API docs --- server/documents/behaviors/api.html.eco | 36 +++++++++++++++------ server/documents/modules/accordion.html.eco | 5 +++ 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/server/documents/behaviors/api.html.eco b/server/documents/behaviors/api.html.eco index c3faeadfb..6cad7e9eb 100755 --- a/server/documents/behaviors/api.html.eco +++ b/server/documents/behaviors/api.html.eco @@ -467,22 +467,27 @@ type : 'UI Behavior'

Response Callbacks

Succesful responses from the server will trigger onSuccess, invalid results onFailure.

onError will only trigger on XHR errors (except due to page navigation like clicking a link), but not invalid JSON responses.

+

You can use the onResponse callback to adjust the json response before being parsed against a success test.

$('.follow.button') .api({ + onResponse: function(response) { + // do some adjustments to response + return response; + }, successTest: function(response) { return response.success || false; } - onSuccess: function() { + onSuccess: function(response) { // valid response and response.success = true }, - onFailure: function() { + onFailure: function(errorMessage) { // valid response but response.success = false }, - onError: function() { + onError: function(errorMessage) { // invalid response }, - onAbort: function() { + onAbort: function(errorMessage) { // user cancelled request } }) @@ -494,6 +499,9 @@ type : 'UI Behavior'

Determining JSON Success

API has special success conditions for JSON responses. Instead of providing success and failure callbacks based on the HTTP response of the request. A request is considered succesful only if the server's response tells you the action was successful. The response is passed to a validation test successTest which can be used to check the JSON for a valid response.

For example you might expect all successful JSON responses to return a top level property signifying the success of the response

+

+ You can use the onResponse callback to modify a server's response by returning a new translated response value before it is parsed by a success test. +
{ "success": true, @@ -857,11 +865,26 @@ type : 'UI Behavior' Allows modifying XHR object for request + + onRequest(promise, xhr) + state context + Callback that occurs when request is made. Receives both the api success promise and the xhr request promise. + + + onResponse(response) + state context + Allows modifying the server's response before parsed by other callbacks to determine API event success + onSuccess(response, element) state context Callback on response object that passed successTest + + onComplete(response, element) + state context + Callback on request complete regardless of conditions + onFailure(response, element) state context @@ -877,11 +900,6 @@ type : 'UI Behavior' state context Callback on abort caused by user clicking a link or manually cancelling request - - onComplete(response, element) - state context - Callback on request complete regardless of conditions - diff --git a/server/documents/modules/accordion.html.eco b/server/documents/modules/accordion.html.eco index b3a0b3a5b..2c8f096ad 100755 --- a/server/documents/modules/accordion.html.eco +++ b/server/documents/modules/accordion.html.eco @@ -466,6 +466,11 @@ themes : ['Default', 'Chubby'] true Only allow one section open at a time + + on + click + Event on title that will cause accordion to open + animateChildren true