Making IT services more agile
Enterprise Agile Planning
The agile revolution completely transformed how we create digital prod ...
Read MoreThis post is from the CollabNet VersionOne blog and has not been updated since the original publish date.
fields.coffee
contains the set of fields and their HTML form element type, plus a few other attributes. For scalar types, it's very simple.
By default, a project will use the fields specified in the defuault
property.Note: To override that set for a specific project, simply add another property, at the same level as default
, with the scope id, like Scope:173519
. We'll cover this in a later section.
Here's how the form we saw way back in the beginning demo article gets specified:
[gist id=4689117 file=gistfile6.coffee]title
// will be used as the description label on the formtype
// specifies what kind of form element to use, defaulting to simple text boxassetName
// specifies the VersionOne asset type for relations on an assetautofocus
// specifies that a field should be automatically focused on loadoptional
// when true, allows an empty value for the fieldtype
attribute for form element types.Note: If you do visit the Backbone Forms documentation, you'll notice that autofocus
, optional
, and, of course assetName
are not part of its API. That's because we pre/process these properties before passing this into Backbone Forms. We'll go into that in more detail in another section.F12
and select the Console tabJSON.stringify( vRequestForm.getValue() )
and hit entervRequestForm
, along with v1AssetEditor
, are variables set into the global window
object in scripts/main.js
in a Backbone.Events based event handler, which we'll cover at the end of this exercise.v1RequestForm.setValue('RequestedBy', 'Your Name')
Your Name
!v1RequestForm.getValue('RequestedBy')
, you'll see Your Name
JSON.stringify( v1AssetEditor.createDto() )
. You should see something like:_links
property, which specifies the relation items necessary for the VersionOne API to properly process the request.
Here's what createDto
actually does:
[gist id=4689117 file=gistfile9.coffee]
The most important part to note here is the iteration over the select
items. This jQuery selector is getting all the INPUT elements of type SELECT, and then creating relation references in the special _links
property of the DTO. Then, it simply removes the prpoerty from the JSON object that was magically created by Backbone Forms. If you compare the output from the previous step, you'll notice that Priority was part of the top/level JSON object, whereas now it is inside the _links
object.
That's really all that's needed to transform Backbone Forms' output into a VersionOne/compliant JSON DTO!RequestedBy
or Name
(Title on screen) fields, then click the List
button, you'll notice that these changes are already reflected in the list. But, you don't see any additional traffic on the Network tab when you do this. That's because we're using Backbone.Events to create our own event handler, which subscribes to a custom event called assetUpdated
.
Here's how we do that way back inside of VersionOneAssetEditor.constructor
:
[gist id=4689117 file=gistfile10.coffee]
And, here's how the event is triggered from inside of the saveAsset
method. The same pathway is used for both create and update, but different event names are passed in for publication.
This section also ties together a lot of important architectural concepts, but we'll cover them in detail in the next section.
[gist id=4689117 file=gistfil11.coffee]
Now, do you remember the JSON response body from part one in step 4, the one with the moments in it? If not, here's a snippet from that:
[gist id=4689117 file=gistfile2.json]
The normalize functions simply remove the moment number from the id
and href
values in the _links.self
object. This is important because we need to load the latest, momentless version of the asset on click.
Now, add your own, additional event handler like this:v1AssetEditor.on('assetUpdated', function(assetEditor, asset){ console.log(JSON.stringify(asset)); })
and hit enterBackbone.Events is Awesome!
and hit Save