While a true implementation of UUID is not possible at this time, this implementation provides reasonable uniqueness.
The UUID generated is located in time, however, because of sandbox issues in JavaScript, it is not able to locate spacially and so subsitutes a series of random numbers to ensure uniqueness where NIC addresses could be used.
For IE users, the UUID that's generated is guaranteed to be more unique than for other browsers as it uses a built-in ActiveX object.
Simply include the class file in your header.
<script type="text/javascript" src="Ext.ux.UUID.js"></script>
Next create a new instance of UUID, which returns a string.
var id = new Ext.ux.UUID();
Alternatively, you can pass it a connection config (url and callback at a minimum) pointing to a server-side script which can return a UUID that's even more guaranteed to be unique.
var id = new Ext.ux.UUID({
url: 'uuid.cfm'
, callback: function(options, success, response) {
var responseJSON = Ext.decode(response.responseText);
var uuid = (responseJSON && responseJSON.uuid) ? responseJSON.uuid : '';
Ext.MessageBox.alert('UUID', uuid);
}
});
The server-side script need only return a JSON response, like so:
{ uuid: '12140650-1372-507C-AE1A27128B963581' }
Using ColdFusion, it's as sample as this (contents of uuid.cfm):
<cfcontent reset="Yes" type="application/json">
<cfoutput>{ uuid: '#CreateUUID()#' }</cfoutput>
Original work copyright Erik Giberti.