An insurance company (IC) can embed self service widget on its web site. Widget is self-sufficient application. But in some cases IC needs to manage widget externally from the page.
There are such methods:
When widget appears on the page it starts to load data so that external methods are not ready to be used.
Method isReady is introduced in order to identify if client API methods are ready to be used.
if (typeof ScalepointSelfService !== 'undefined' && ScalepointSelfService.widget.isReady()){
//call client API methods
var basketSize = ScalepointSelfService.widget.getItemsQuantity();
if (basketSize > 0){
//do something
}
}
Widget is embedded on an IC web page. The page may contain a lot of controls except the widget. In some cases widget user can for instance forget to save input data and click some external control and will be forwarded to another page. For such a scenario saveItem method was introduced. It simulates clicking on a SAVE ITEM button.
function ScalepointSelfService.widget.saveItem([successCallback, errorCallback])
Function returns false in case of invalid form or empty item description. Else it return true, success or failure callback is called.
In case of IC needs to handle saveItem success or failure event successCallback and errorCallback functions are passed as arguments (but are not required).
function sucessCallback()
function errorCallback([errorData])
ErrorData is an data with response status and text. Please refer to the JSON Schema
Code sample
function successCallback(){
console.log('item is saved');
}
function errorCallback(errorData){
console.log(errorData.status + ' - ' + errorData.statusText);
}
function isWidgetReady(){
return typeof ScalepointSelfService !== 'undefined' && ScalepointSelfService.widget.isReady();
}
function saveItem(){
if (isWidgetReady()){
var isSaved = ScalepointSelfService.widget.saveItem(successCallback, errorCallback);
}
}
IC may want to know the quantity of items in the basket. For this case the getItemsQuantity method was introduced. function ScalepointSelfService.widget.getItemsQuantity()
Code sample
function doSomething(){
if (typeof ScalepointSelfService !== 'undefined' && ScalepointSelfService.widget.isReady()){
var basketSize = ScalepointSelfService.widget.getItemsQuantity();
if (basketSize > 0){
//do something
}
}
}
Please see save client API method
Please see submit client API method
see more about widget implementation: