Hosted by Three Crickets

Diligence
Web Framework
For Prudence and MongoDB

Diligence is still under development and incomplete, and some this documentation is wrong. For a more comprehensive but experimental version download the Savory Framework, which was the preview release of Diligence.

Diligence logo: sleeping monkey

Sencha Integration: Ext Direct

Diligence makes it trivial to support Ext Direct, Sencha's straightforward RPC protocol. Ext Direct it has excellent support in Ext JS and Sencha Touch: the frameworks generate a client-side namespace for you with asynchronous methods equivalent to those on the server. All you have to do is call them! Operations are batched for maximum efficiency, and errors are handled as elegantly as can be.
Diligence actually takes Ext Direct one step ahead in letting you automatically generate the API configuration on the server. A "GET" to the resource will retrieve the JSON needed to configure the client-side provider. We show this in detail under "Usage," below.
Ext Direct's functionality is practically identical to that JSON-RPC, but the protocol is incompatible. It may be unfortunate that Sencha decided not to use that better-known protocol, but in any case Diligence supports both.

Setup

Ext Direct setup is almost identical to RPC Service setup, so make sure you read the section there.
One small difference is in how Ext Direct handles namespaces. First of all, you cannot have an empty namespace (the "." namespace in JSON-RPC). And, second, you can optionally set up a client-side namespace, using the "name" key. Here's an example "/libraries/resources.js", similar to the one for the RPC Service:
document.executeOnce('/diligence/integration/frontend/sencha/')
​
var Calc = {
	multiply: function(x, y) {
		return x y
	}
}
​
resources = {
	...
	calc: new Diligence.Sencha.DirectResource({name: 'MyApp', namespaces: {Calc: Calc}})
}
It is also possible to set Ext Direct method attributes using the long-form method definition with the "extDirect" key.

Ext JS Forms

Ext Direct can be used to respond to Ext JS form submissions. To do so, we need to set the "formHandler" attribute and also return an appropriate response:
var Calc = {
	multiply: {
		fn: function(x, y) {
			return {
				success: true,
				msg: '{0} times {1} is {2}'.cast(x, y, x y)
			}
		},
		extDirect: {
			formHandler: true
		}
	}
}
See the section on Ext JS Forms for more information on usage. Note furthermore that Diligence supports all of Ext JS's form submission mechanisms.

Usage

See the Ext JS documentation for full details on the client-side API. Otherwise, here's a quick tutorial, which also shows you how to fetch the provider configuration from the resource.
Here's an example of a dynamic web page, say "direct.d.html":
<html>
<head>
<%
document.executeOnce('/diligence/integration/frontend/sencha/')
Diligence.Sencha.extJsHead(conversation)
%> 
</head>
<body>
</body>
<script>
function init() {
	MyApp.Calc.multiply(2, 3, function(provider, response) {
		if (response.type == 'exception') {
			Ext.Msg.alert('Multiplication', 'Exception: ' + response.message);
		}
		else {
			Ext.Msg.alert('Multiplication', response.result);
		}
	});	
}
​
Ext.Ajax.request({
	url: '<%= conversation.pathToBase %>/calc/',
	method: 'GET',
	disableCaching: false,
	success: function(response) {
		var provider = Ext.decode(response.responseText);
		Ext.Direct.addProvider(provider);
		init();
	},
	failure: function(response) {
		console.log(response);
	}
});
</script>
</html>
Some notes:

The Diligence Manual is provided for you under the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. The complete manual is available for download as a PDF.

Download manual as PDF Creative Commons License