Using the Silva Object Lookup window
As of Silva 1.4 the object lookup window has been refactored to one implementation, and it is now possible to use it in your code sources and custom products. The object lookup window is VERY easy to use, and this document outlines how to use it.
Silva 1.5 will come with a new formulator field, called a 'lookup field'. This field is a combo with a text field and a button containing an onclick. The default for the onclick will cause the reference window to open and lookup assets. So, the first part of this tutorial probably isn't as useful, but the latter details how to call the window.
To open a lookup window, attach an onclick handler to a button. The onclick handler should look something like this:
onclick="reference.getReference(handler,start_path,filter,show_add);"
The parameters follow the following syntax:
handler:
This is a function that does the action you want when the user clicks 'place reference' in the object lookup window. It looks like this:function(path, id, title) { //do stuff in the code source or whatever }This function is in the scope of the calling document (i.e. the document that opened the lookup window), so it can do something like "retrieve a text field by it's id and set it's value equal to the path of the reference.
start_path:
The location the object lookup window should display the contents of first. In TAL, this might look like:request/model/aq_parent/absolute_url
filter:
The type of content to display. According to ViewCode.object_lookup_get_objects:filter: 'Asset', 'Content', a certain meta_type (string) or a list of meta_types
I would amend this by saying 'filter' can be one of: 'Asset', 'Content', 'Container','Publishable', a certain meta_type or a list of meta_types. While this function can handle a list (python) of meta_types, there is no way to feed a list of meta_types to the lookup window. You're stuck with the predefined types above and a single meta_type.
- show_add:
The new object lookup window can also create objects. The addables list will be restricted to just the types of objects you specify. This is a flag, either true, 1, false, 0
Putting it all togethor
Finally, let's put all of this togethor in a real example:
<input type="text" name="document" id="sel_doc" />
<button value="Get Reference"
tal:attributes="onclick string:reference.getReference(function(path, id, title)
{document.getElementById('sel_doc').value = path;},
'${request/model/aq_parent/absolute_url}',
'Silva Document', true);"
/>