Widget Execution Handler

Widgets are a great way to customize your Cliq home screen and build a custom page for your app. 

Each action performed on the widget will pass the following attributes:

Attribute NameDescription
userDetails of the user interacting with the widget. 
targetDetails of the button with which the user is interacting in the widget. The target object contains the button ID and button label.  
event

Details of the current action the user is performing in the widget.

Allowed values: load | refresh | tab_click

access​Details of the web client from which the user is accessing the widget button, their user ID.
environmentDetails of the data center to which the user belongs. 

Example:

Let us consider a widget created to pull all your Google Drive files right into Cliq. In the following sample syntax, we're defining two tabs, one to display all your files that you have uploaded to your Google Drive, with options to both view and download them while the second tab shows all your starred files. The invoke URL task is used to establish a connection between Cliq and Google Drive. 




id = "recent";
type = "recent";
header = Map();
footer = Map();
sections = list();
header = {"title":"Home","navigation":"new"};
tabsList = {{"label":"Recent","id":"recent"},{"label":"Starred","id":"starred"}};
if(target.containKey("id"))
{
	id = target.get("id");
}
params = Map();
params.put("pageSize","20");
params.put("fields","*");
if(id == "recent")
{
	params.put("q","trashed = false");
}
else if(id == "starred")
{
	params.put("orderBy","starred");
	type = "starred";
}
filesResponse = invokeurl
[
	url :"https://www.googleapis.com/drive/v3/files"
	type :GET
	parameters:params
	connection: //"connection_name" 
];
files = filesResponse.get("files");
if(files == null || files.isEmpty())
{
	if(id == "recent")
	{
		return {"type":"applet","data_type":"info","info":{"title":"Oops! No recent files found.","description":""},"tabs":tabsList,"active_tab":id};
	}
	else if(id == "starred")
	{
		return {"type":"applet","data_type":"info","info":{"title":"Oops! No starred files found.","description":""},"tabs":tabsList,"active_tab":id};
	}
}
i = 1;
length = files.size();
for each  file in files
{
	if(i > 20)
	{
		break;
	}
	if(file.get("trashed"))
	{
		continue;
	}
	if(!file.get("mimeType").contains("folder"))
	{
		if(id == "starred")
		{
			if(file.get("starred") == false)
			{
				continue;
			}
		}
		elements = list();
		title = file.get("name");
		if(title.length() > 50)
		{
			title = title.subString(0,47) + "...";
		}
		downloadAction = "";
		if(file.get("webContentLink") != null)
		{
			downloadAction = "|  [Download](" + file.get("webContentLink") + ")";
		}
		elements.add({"type":"activity","image_url":file.get("iconLink"),"title":title,"description":"[View](" + file.get("webViewLink") + ") " + downloadAction});
		elements.add({"type":"divider"});
		sections.add({"id":i,"elements":elements});
		i = i + 1;
	}
}
if(length >= 20 && i >= 20 && filesResponse.get("nextPageToken") != null)
{
	buttons = List();
	buttons.add({"label":"Next","type":"invoke.function","name":"gdrivenextfunc","id":type + "|" + filesResponse.get("nextPageToken") + "|1"});
	footer = {"buttons":buttons};
}
else if(sections.isEmpty())
{
	if(id == "recent")
	{
		return {"type":"applet","data_type":"info","info":{"title":"Oops! No recent files found.","description":""},"tabs":tabsList,"active_tab":id};
	}
	else if(id == "starred")
	{
		return {"type":"applet","data_type":"info","info":{"title":"Oops! No starred files found.","description":""},"tabs":tabsList,"active_tab":id};
	}
}
return {"type":"applet","tabs":tabsList,"active_tab":id,"header":header,"footer":footer,"sections":sections};