Provides the ability to offline OData services.
The plugin provides the client with the ability to define offline stores for an OData producer. When an offline store is first opened, it will synchronize with the OData producer. OData requests made against this plugin will use the available open offline stores.
Requirements
The plugin requires that the datajs JavaScript library is included and available to the application. If SAPUI5/OpenUI5 is used, you can call the method `jQuery.sap.require("sap.ui.thirdparty.datajs");` otherwise use a script include for the datajs library.
Custom OData httpclient
A custom datajs OData httpclient is provided by the plugin. This httpclient will resolve requests with the plugin if the service root of the request matches one of the open stores. The httpclient will fallback to using the original OData.defaultHttpClient if the requests service root does not match any of the currently open stores.
Flushing Modifications
The developer must explicitly call the flush method of a store to send modification to the OData producer.
Refreshing Data
The developer must explicitly refresh their stores to get changes from the OData producer. The plugin provides a refresh method that can refresh the whole store or a subset of it.
Tagging Requests
OData requests can be tagged by including the header `OData-Offline-CustomTag`. If the request has an error during flush, the custom tag will be available in the error archive via the CustomTag field.
The plugin provides the client with the ability to define offline stores for an OData producer. When an offline store is first opened, it will synchronize with the OData producer. OData requests made against this plugin will use the available open offline stores.
Requirements
The plugin requires that the datajs JavaScript library is included and available to the application. If SAPUI5/OpenUI5 is used, you can call the method `jQuery.sap.require("sap.ui.thirdparty.datajs");` otherwise use a script include for the datajs library.
Custom OData httpclient
A custom datajs OData httpclient is provided by the plugin. This httpclient will resolve requests with the plugin if the service root of the request matches one of the open stores. The httpclient will fallback to using the original OData.defaultHttpClient if the requests service root does not match any of the currently open stores.
Flushing Modifications
The developer must explicitly call the flush method of a store to send modification to the OData producer.
Refreshing Data
The developer must explicitly refresh their stores to get changes from the OData producer. The plugin provides a refresh method that can refresh the whole store or a subset of it.
Tagging Requests
OData requests can be tagged by including the header `OData-Offline-CustomTag`. If the request has an error during flush, the custom tag will be available in the error archive via the CustomTag field.
Example
Sample offline setup code
var properties = {
"name": "travel",
"host": "smpserver",
"port": 8080,
"serviceRoot" : "connection_name",
"definingRequests" : {
"req1" : "/Travelagency"
},
}
// Create the store. Need to be online the first time this is created.
var store = sap.OData.createOfflineStore(properties);
store.open(function() {
sap.OData.applyHttpClient();
// Offline OData calls can now be made against datajs.
}, function(e) {
alert("Failed to open store!");
});
Members
(static) stores :Array.<OfflineStore>
An array of the currently open stores.
Type:
- Array.<OfflineStore>
Methods
(static) applyHttpClient()
Replaces the OData.defaultHttpClient with a custom one that uses the SMP OData native APIs.
Requests that don't map to an open store will fallback to using the
original `OData.defaultHttpClient`.
(static) createOfflineStore(properties) → {sap.OfflineStore}
Creates a new OfflineStore object.
The store will be available for offline access only after it is open successfully.
Parameters:
Name | Type | Description | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
properties |
Object | Properties used for creating the store object.
Properties
|
Returns:
A new OfflineStore object.
- Type
- sap.OfflineStore
(static) removeHttpClient()
Removes the custom httpClient if it has been applied.
(static) request(request, successCallback, errorCallback)
Sends a request containing an OData payload to the current open stores.
This method can be used for requests that don't go through the datajs http client.
Parameters:
Name | Type | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
request |
Object |
Properties
|
|||||||||||||||
successCallback |
sap.OData~requestSuccess | Callback function that is called with the response data. | |||||||||||||||
errorCallback |
sap.OData~requestError | Callback function this is called if an error occurs. |
Type Definitions
requestError(error)
Request error callback.
Parameters:
Name | Type | Description |
---|---|---|
error |
String | The error message. |
requestSuccess(response)
Request success callback that provides the response data.
Parameters:
Name | Type | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
response |
Object |
Properties
|