Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 31 additions & 31 deletions ajax-javascript-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,29 @@ The second argument of the `request` method is the options object. You can use a

Option | Description
------------- | -------------
**update** | an object, specifies a list partials and page elements (as CSS selectors) to update: {'partial': '#select'}. If the selector string is prepended with the `@` symbol, the content received from the server will be appended to the element, instead of replacing the existing content.
**confirm** | the confirmation string. If set, the confirmation is displayed before the request is sent. If the user clicks the Cancel button, the request cancels.
**data** | an optional object specifying data to be sent to the server along with the form data: {var: 'value'}. When `files` is true, you may also include files to be uploaded in this object by using [`Blob` objects](https://developer.mozilla.org/en-US/docs/Web/API/Blob). To specify the filename of any `Blob` objects, simply set the `filename` property on the `Blob` object. (Ex. `var blob = new Blob(variable); blob.filename = 'test.txt'; var data = {'uploaded_file': blob};`)
**redirect** | string specifying an URL to redirect the browser to after the successful request.
**beforeUpdate** | a callback function to execute before page elements are updated. The function gets 3 parameters: the data object received from the server, text status string, and the jqXHR object. The `this` variable inside the function resolves to the request content - an object containing 2 properties: `handler` and `options` representing the original request() parameters.
**success** | a callback function to execute in case of a successful request. If this option is supplied it overrides the default framework's functionality: the elements are not updated, the `beforeUpdate` event is not triggered, the `ajaxUpdate` and `ajaxUpdateComplete` events are not triggered. The event handler gets 3 arguments: the data object received from the server, the text status string and the jqXHR object. However, you can still call the default framework functionality calling `this.success(...)` inside your function.
**error** | a callback function execute in case of an error. By default the alert message is displayed. If this option is overridden the alert message won't be displayed. The handler gets 3 parameters: the jqXHR object, the text status string and the error object - see [jQuery AJAX function](http://api.jquery.com/jQuery.ajax/).
**complete** | a callback function execute in case of a success or an error.
**form** | a form element to use for sourcing the form data sent with the request, either passed as a selector string or a form element.
**flash** | when true, instructs the server to clear and send any flash messages with the response. default: false
**files** | when true, the request will accept file uploads, this requires `FormData` interface support by the browser. default: false
**browserValidate** | when true, browser-based client side validation will be performed on the request before submitting. This only applies to requests triggered in the context of a `<form>` element. **NOTE:** This form of validation does not play nice with complex forms where validated fields might not be visible to the user 100% of the time. Recommend that you avoid using it on anything but the most simple forms.
**loading** | an optional string or object to be displayed when a request runs. The string should be a CSS selector for an element, the object should support the `show()` and `hide()` functions to manage the visibility. You may pass the global object `$.wn.stripeLoadIndicator` when using the [framework extras](../ajax/extras).
`update` | an object, specifies a list partials and page elements (as CSS selectors) to update: {'partial': '#select'}. If the selector string is prepended with the `@` symbol, the content received from the server will be appended to the element, instead of replacing the existing content.
`confirm` | the confirmation string. If set, the confirmation is displayed before the request is sent. If the user clicks the Cancel button, the request cancels.
`data` | an optional object specifying data to be sent to the server along with the form data: {var: 'value'}. When `files` is true, you may also include files to be uploaded in this object by using [`Blob` objects](https://developer.mozilla.org/en-US/docs/Web/API/Blob). To specify the filename of any `Blob` objects, simply set the `filename` property on the `Blob` object. (Ex. `var blob = new Blob(variable); blob.filename = 'test.txt'; var data = {'uploaded_file': blob};`)
`redirect` | string specifying an URL to redirect the browser to after the successful request.
`beforeUpdate` | a callback function to execute before page elements are updated. The function gets 3 parameters: the data object received from the server, text status string, and the jqXHR object. The `this` variable inside the function resolves to the request content - an object containing 2 properties: `handler` and `options` representing the original request() parameters.
`success` | a callback function to execute in case of a successful request. If this option is supplied it overrides the default framework's functionality: the elements are not updated, the `beforeUpdate` event is not triggered, the `ajaxUpdate` and `ajaxUpdateComplete` events are not triggered. The event handler gets 3 arguments: the data object received from the server, the text status string and the jqXHR object. However, you can still call the default framework functionality calling `this.success(...)` inside your function.
`error` | a callback function execute in case of an error. By default the alert message is displayed. If this option is overridden the alert message won't be displayed. The handler gets 3 parameters: the jqXHR object, the text status string and the error object - see [jQuery AJAX function](http://api.jquery.com/jQuery.ajax/).
`complete` | a callback function execute in case of a success or an error.
`form` | a form element to use for sourcing the form data sent with the request, either passed as a selector string or a form element.
`flash` | when true, instructs the server to clear and send any flash messages with the response. default: false
`files` | when true, the request will accept file uploads, this requires `FormData` interface support by the browser. default: false
`browserValidate` | when true, browser-based client side validation will be performed on the request before submitting. This only applies to requests triggered in the context of a `<form>` element. **NOTE:** This form of validation does not play nice with complex forms where validated fields might not be visible to the user 100% of the time. Recommend that you avoid using it on anything but the most simple forms.
`loading` | an optional string or object to be displayed when a request runs. The string should be a CSS selector for an element, the object should support the `show()` and `hide()` functions to manage the visibility. You may pass the global object `$.wn.stripeLoadIndicator` when using the [framework extras](../ajax/extras).

You may also override some of the request logic by passing new functions as options. These logic handlers are available.

Handler | Description
------------- | -------------
**handleConfirmMessage(message)** | called when requesting confirmation from the user.
**handleErrorMessage(message)** | called when an error message should be displayed.
**handleValidationMessage(message, fields)** | focuses the first invalid field when validation is used.
**handleFlashMessage(message, type)** | called when a flash message is provided using the **flash** option (see above).
**handleRedirectResponse(url)** | called when the browser should redirect to another location.
`handleConfirmMessage(message)` | called when requesting confirmation from the user.
`handleErrorMessage(message)` | called when an error message should be displayed.
`handleValidationMessage(message, fields)` | focuses the first invalid field when validation is used.
`handleFlashMessage(message, type)` | called when a flash message is provided using the **flash** option (see above).
`handleRedirectResponse(url)` | called when the browser should redirect to another location.

<a name="javascript-examples"></a>
## Usage examples
Expand Down Expand Up @@ -100,24 +100,24 @@ The AJAX framework triggers several events on the updated elements, triggering e

Event | Description
------------- | -------------
**ajaxBeforeSend** | triggered on the window object before sending the request.
**ajaxBeforeUpdate** | triggered on the form object directly after the request is complete, but before the page is updated. The handler gets 5 parameters: the event object, the context object, the data object received from the server, the status text string, and the jqXHR object.
**ajaxUpdate** | triggered on a page element after it has been updated with the framework. The handler gets 5 parameters: the event object, the context object, the data object received from the server, the status text string, and the jqXHR object.
**ajaxUpdateComplete** | triggered on the window object after all elements are updated by the framework. The handler gets 5 parameters: the event object, the context object, the data object received from the server, the status text string, and the jqXHR object.
**ajaxSuccess** | triggered on the form object after the request is successfully completed. The handler gets 5 parameters: the event object, the context object, the data object received from the server, the status text string, and the jqXHR object.
**ajaxError** | triggered on the form object if the request encounters an error. The handler gets 5 parameters: the event object, the context object, the error message, the status text string, and the jqXHR object.
**ajaxErrorMessage** | triggered on the window object if the request encounters an error. The handler gets 2 parameters: the event object and error message returned from the server.
**ajaxConfirmMessage** | triggered on the window object when `confirm` option is given. The handler gets 2 parameters: the event object and text message assigned to the handler as part of `confirm` option. This is useful for implementing custom confirm logic/interface instead of native javascript confirm box.
`ajaxBeforeSend` | triggered on the window object before sending the request.
`ajaxBeforeUpdate` | triggered on the form object directly after the request is complete, but before the page is updated. The handler gets 5 parameters: the event object, the context object, the data object received from the server, the status text string, and the jqXHR object.
`ajaxUpdate` | triggered on a page element after it has been updated with the framework. The handler gets 5 parameters: the event object, the context object, the data object received from the server, the status text string, and the jqXHR object.
`ajaxUpdateComplete` | triggered on the window object after all elements are updated by the framework. The handler gets 5 parameters: the event object, the context object, the data object received from the server, the status text string, and the jqXHR object.
`ajaxSuccess` | triggered on the form object after the request is successfully completed. The handler gets 5 parameters: the event object, the context object, the data object received from the server, the status text string, and the jqXHR object.
`ajaxError` | triggered on the form object if the request encounters an error. The handler gets 5 parameters: the event object, the context object, the error message, the status text string, and the jqXHR object.
`ajaxErrorMessage` | triggered on the window object if the request encounters an error. The handler gets 2 parameters: the event object and error message returned from the server.
`ajaxConfirmMessage` | triggered on the window object when `confirm` option is given. The handler gets 2 parameters: the event object and text message assigned to the handler as part of `confirm` option. This is useful for implementing custom confirm logic/interface instead of native javascript confirm box.

These events are fired on the triggering element:

Event | Description
------------- | -------------
**ajaxSetup** | triggered before the request is formed, allowing options to be modified via the `context.options` object.
**ajaxPromise** | triggered directly before the AJAX request is sent.
**ajaxFail** | triggered finally if the AJAX request fails.
**ajaxDone** | triggered finally if the AJAX request was successful.
**ajaxAlways** | triggered regardless if the AJAX request fails or was successful.
`ajaxSetup` | triggered before the request is formed, allowing options to be modified via the `context.options` object.
`ajaxPromise` | triggered directly before the AJAX request is sent.
`ajaxFail` | triggered finally if the AJAX request fails.
`ajaxDone` | triggered finally if the AJAX request was successful.
`ajaxAlways` | triggered regardless if the AJAX request fails or was successful.

<a name="global-events-examples"></a>
## Usage examples
Expand Down
50 changes: 25 additions & 25 deletions database-model.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,17 @@ There are some standard properties that can be found on models, in addition to t

Property | Description
------------- | -------------
**$primaryKey** | primary key name used to identify the model.
**$incrementing** | boolean that if false indicates that the primary key is not an incrementing integer value.
**$exists** | boolean that if true indicates that the model exists.
**$dates** | values are converted to an instance of Carbon/DateTime objects after fetching.
**$timestamps** | boolean that if true will automatically set created_at and updated_at fields.
**$jsonable** | values are encoded as JSON before saving and converted to arrays after fetching.
**$fillable** | values are fields accessible to [mass assignment](#mass-assignment).
**$guarded** | values are fields guarded from [mass assignment](#mass-assignment).
**$visible** | values are fields made visible when [serializing the model data](../database/serialization).
**$hidden** | values are fields made hidden when [serializing the model data](../database/serialization).
**$connection** | string that contains the [connection name](../database/basics#accessing-connections) that's utilised by the model by default.
`$primaryKey` | primary key name used to identify the model.
`$incrementing` | boolean that if false indicates that the primary key is not an incrementing integer value.
`$exists` | boolean that if true indicates that the model exists.
`$dates` | values are converted to an instance of Carbon/DateTime objects after fetching.
`$timestamps` | boolean that if true will automatically set created_at and updated_at fields.
`$jsonable` | values are encoded as JSON before saving and converted to arrays after fetching.
`$fillable` | values are fields accessible to [mass assignment](#mass-assignment).
`$guarded` | values are fields guarded from [mass assignment](#mass-assignment).
`$visible` | values are fields made visible when [serializing the model data](../database/serialization).
`$hidden` | values are fields made hidden when [serializing the model data](../database/serialization).
`$connection` | string that contains the [connection name](../database/basics#accessing-connections) that's utilised by the model by default.

<a name="property-primary-key"></a>
#### Primary key
Expand Down Expand Up @@ -566,20 +566,20 @@ Models fire several events, allowing you to hook into various points in the mode

Event | Description
------------- | -------------
**beforeCreate** | before the model is saved, when first created.
**afterCreate** | after the model is saved, when first created.
**beforeSave** | before the model is saved, either created or updated.
**afterSave** | after the model is saved, either created or updated.
**beforeValidate** | before the supplied model data is validated.
**afterValidate** | after the supplied model data has been validated.
**beforeUpdate** | before an existing model is saved.
**afterUpdate** | after an existing model is saved.
**beforeDelete** | before an existing model is deleted.
**afterDelete** | after an existing model is deleted.
**beforeRestore** | before a soft-deleted model is restored.
**afterRestore** | after a soft-deleted model has been restored.
**beforeFetch** | before an existing model is populated.
**afterFetch** | after an existing model has been populated.
`beforeCreate` | before the model is saved, when first created.
`afterCreate` | after the model is saved, when first created.
`beforeSave` | before the model is saved, either created or updated.
`afterSave` | after the model is saved, either created or updated.
`beforeValidate` | before the supplied model data is validated.
`afterValidate` | after the supplied model data has been validated.
`beforeUpdate` | before an existing model is saved.
`afterUpdate` | after an existing model is saved.
`beforeDelete` | before an existing model is deleted.
`afterDelete` | after an existing model is deleted.
`beforeRestore` | before a soft-deleted model is restored.
`afterRestore` | after a soft-deleted model has been restored.
`beforeFetch` | before an existing model is populated.
`afterFetch` | after an existing model has been populated.

An example of using an event:

Expand Down
Loading