Alfresco does provide a very decent, clean user interface. We could add more buzz words for it, web2.0ish, Rich Ajax components, Google-style search, Yahoo-style browsing blah blah blah You name it we have it.
But the best thing I like it is that it allows multiple ways for customization and extension. You can easily replace existing icons, register your own icons, setting up new dialogs, menus, wizards etc. You can also create your own “dashlets” which can be used to configure user’s dashboard page.
However, I still got feedbacks like
“Writing a customization is too much”
“We really like Alfresco repository but your UI is too much for end users”
“We don’t have good Java developers and we don’t plan to hire one”
“We just need a simple one-page UI so the users won’t do any crazy stuff”
“CIFS is great for end-user but we still want some simple web interface”
Those feedbacks have been bugging me for very long until Alfresco 2.1 is out. I know now I can leverage the new futures to make those claims go away.
So when I woke up this morning, I decided to do a little project. I am going to use the latest web scripting feature of 2.1 to build a dead simple one-page UI for Alfresco. For the sake of acronym fetish, let us call it DSUFA.
The tools I am going to use
1) Alfresco 2.1
2) Textpad
3) Firefox (with Firebug plugin)
Since there is no bonus for doing this project, let me simplify the user case like this
We have a group of users who have very limited role and they are only allowed to list, create, delete, update and preview documents under a given folder, say Demo folder under Company Home. They will not use full-blown Alfresco UI, instead, we will use web scripts to write a simple one-page UI for them.
Web scripting is a very intriguing new feature in 2.1. It is not something mysterious or coming out from nowhere although we do invent a new buzzword. That is just the nature of the whole IT industry. Open source is no exception.
Alfresco has long history supporting Freemarker templates (Read/Transformation) and Javascript templates (Read/Write). Web scripting is just combination of the two types of scripts. Each web script consists of zero or one Javascript template for handling back-end operation, one or many Freemarker templates for front-end presentation, and one description XML for documentation and other relevant settings. It also comes with utility services such as listing , debugging etc. But the most important thing is that invoking a web script is done through REST interface a.k.a simple URL invocation. I think that would be something people will like most.
Ok. back to our DSUFA project, we first need to setup our development environment. We could setup an ant script and build an exchangeable AMP package. But let us make it simple. So just mount Alfresco repository as a share driver,say Z drive, and point Textpad to it.
By doing that, we will edit the templates and XML files directly, no uploading, no downloading. Another cool feature of web scripting is that it doesn’t require tomcat rebounce when we register new web scripts. We can just go to the service list page
http://localhost:8080/alfresco/service/index
and click the the refresh button. So no tomcat rebounce for the whole project.
Now let us open windows explorer and go to the folder Z:\Data Dictionary\Web Scripts Extensions and let us make up some package hierarchy, for example, org\alfresco\demo\wslib\simpleui and that will be the place we put our web scripts.
So how many web scripts do we need here? It is a simple question, since we need to provide list, create, edit and delete capabilities, we are going to create a web script for each capability.

To make the project look like a real one, let us draw a sequence diagram. The idea is that the List web script will be the entry point for the end user and it also provides links to the Save web script, New web script and Remove web script. For those three scripts, once the back-end operation is done, they will forward user back to the List script. Since web scripts supports REST interfaces, connecting web scripts is a very easy task.
So, let us work on our first web script, the List one. Following the naming convention, we create three files, DocumentList.get.desc.xml (XML Description File), DocumentList.get.html.ftl (Freemarker Template) and DocumentList.get.js (Javascript Template) .
First the description xml file
<webscript>
<shortname>Alfresco Simple UI - Item Listing</shortname>
<description>Execute search for getting a list of items</description>
<url format=”html” template=”/simpleui/document/list.html?q={searchTerms}”/>
<format default=”html”>extension</format>
<authentication>guest</authentication>
<transaction>required</transaction>
</webscript>
and the back-end Javascript template
//Get the search parameter. If null, set it as wildcard
var q = (args.q == null) ? “***” : args.q;
// Build lucene search query string and run the search
var nodes = search.luceneSearch(”( PATH:\”/app:company_home/cm:Demo//*\” ) AND ( TEXT:”+ q+”)”);
//Set the search return and it will be available for the Freemarker template
model.resultset = nodes;
Look simple? You can see we define the REST interface within the XML file and use Alfresco search API to get the list of documents. So three lines of code is all we need here.
Once we retrieve the search results, we are ready to display the results through our Freemarker template.
<table>
<thead>
<tr> <th>Name</th><th>Created</th><th>Modified</th><th>Description</th><th>Body</th>
</tr>
</thead>
<tbody>
<#list resultset as node>
<tr>
<td>${node.name}</td>
<td>${node.properties.created?datetime}</td>
<td>${node.properties.modified?datetime}</td>
<td>${node.properties.description}</td>
<td>${node.content}</td>
</tr>
</#list>
</tbody>
</table>
This is nothing but using some freemaker tags to loop through the search results and display them as a table. Now we are ready to test our first web script. Go to the service list page and do a refresh. You will see the new script is registered. And we can testing our script by hit the following link
http://localhost:8080/alfresco/service/simpleui/document/list.html
If we have created the Demo folder and put some documents over there, we will get a list of documents. Now let us move on to create three other scripts. Remember, according to our design, the freemark templates for those three do nothing but forwarding back to the List page. So they can be as simple as
<META
HTTP-EQUIV=”Refresh”
CONTENT=”1; URL=${url.serviceContext}/simpleui/document/list.html”>
Once we get three other web scripts ready, let us go back to the Freemaker template for the List web script. We still need to build the links from List page to other scripts. Remember Freemarker template does nothing but printing out text. So we are free to put any Javascript or HTML in it.
A link from List page to the Remove web script can be as simple as
<form name=”remove_form” action=”${url.serviceContext}/simpleui/document/remove” method=”post”>
<table>
<tbody>
<tr>
<th><b>Remove File </b><INPUT type=”text” id=”remove_name” name=”name” value=”" disabled/></th>
</tr>
<tr>
<td>Do you really really really want to delete this file?</td>
</tr>
<tr>
<td align=”center”>
<INPUT type=”hidden” id=”remove_noderef” name=”noderef” value=”"/>
<INPUT type=”hidden” id=”remove_name” name=”name” value=”"/>
<input type=”submit” value=”Ok”/>
<input type=”button” id=”hide3″ value=”Cancel” onClick=”removedlg.hide()”></td></td>
</tr>
</tbody>
</table>
</form>
This is just a plain old HTML form which points to the url for the Remove web script. Now, you see, REST interface makes everything really really easy.
We are almost done. Let us have some fun here. To make the UI sexy, we can use the DoJo package shipped with Alfresco 2.1. For this little project, I will use the “FilteringTable” widget for document listing and the “Dialog” widget for the Edit/New/Remove dialogs.
After some Javascript/css/dhtml programming, (googling, copy-n-pasting), we finally got the UI done. It is a dead simple Web2.0ish one-page UI for Alfresco. It allows a user to create/edit/list/preview and remove documents under the given folder.
No java programming is needed here. It took me about 2 hours to finish the project. And I bet for better developers like you, it might take even less time.
If you want to try this example, you can download the zip file (Script Package dsufa.zip). Unzip the org folder to your Data Dictionary\Web Scripts Extensions space. Unzip the dojo folder to the folder tomcat\webapps\alfresco\images under your alfresco installation. Then go to the service list page to register all new scripts and create a “Demo” space under Company Home.


You are now ready to try this dead simple UI.