Making a Dashlet work in Alfresco Share

Go to this folder : (this is where my tomcat/alfresco3.4.4 is installed)

C:\alfresco-enterprise-tomcat-3.4.4\tomcat\shared\classes\alfresco\web-extension\site-webscripts\org\alfresco\components\dashlets\

Add three files :

mjb.get.desc.xml

<webscript>
   <shortname>MJB</shortname>
   <description>MJB's test Dashlet</description>
   <family>user-dashlet</family>
   <url>/components/dashlets/mjb</url>
</webscript>

mjb.get.html.ftl

<div class="dashlet">
   <div class="title">${title}</div>
   <div class="body">
	<div> cmisQuery       = ${cmisQuery!""} </div>
	<div> Aantal entries  = ${no_entries!""} </div>
   	<div> props[icon]     = ${props["icon"]!""} </div>
      	<div> props[propName] = ${props["propName"]!""} </div>
	<div> doc             = ${doc!""} </div>
	<div> object          = ${object!""} </div>
	<div> properties      = ${properties!""} </div>
	<div> Qname           = ${Qname!""} </div>
	<div> propName        = ${text!""} </div>
	<div> name	      = ${name!""} </div>
   </div>
</div>

mjb.get.js

// Needs to come from cmis:document because cmis:file returns nothing
var selectString =  "SELECT d.*, t.*, a.* FROM cmis:document AS d " +
		    "JOIN cm:titled AS t ON d.cmis:objectId = t.cmis:objectId " +
		    "JOIN cm:author AS a ON d.cmis:objectId = a.cmis:objectId " +
		    "WHERE IN_FOLDER(d, 'workspace://SpacesStore/560b8dd6-6503-4ad5-8066-5946c1456ec1') " +
		    "ORDER BY d.cmis:name"

var cmisQuery = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?><cmis:query xmlns:cmis=\"http://docs.oasis-open.org/ns/cmis/core/200908/\"><cmis:statement>" + selectString + "</cmis:statement></cmis:query>";

// get the documents for the currently active site
var conn = remote.connect("alfresco");

var result = conn.post(stringUtils.urlEncodeComponent("/cmis/queries"), cmisQuery, "application/cmisquery+xml");

	if (result != null) {model.title = "ik krijg iets terug van de query";} else { model.title = "ik krijg niets terug van de query"; }
	model.title = "resultset from query";	// Titel voor de dashlet
	model.result = result;					// keihard de XML -als ruw block data- overgooien.
	model.cmisQuery = cmisQuery;			// Query weergeven

// Lets make a proof of the pudding model.
model.nodes=createModel(atom.toFeed(result));

function getElementByTagName(list, elTagName) {
   var el;
   for (var i = 0, l = list.size(); i < l; i++) {
      el = list.get(i);
      if (el.QName.localPart == elTagName) {
	 model.Qname = el;
         return el;
      }
   }
   return null;
}

function createModel(feed) {
  var list = new Array();
  var entries = feed.getEntries();
  model.entries = entries;
  model.no_entries = entries.size();

  for (var i=0; i < entries.size(); i++) {
    var doc = entries.get(i);
        model.doc = doc;
    var object =  doc.getExtension(atom.createQName("http://docs.oasis-open.org/ns/cmis/restatom/200908/","object"));
    model.object = object;
	properties = getElementByTagName(object.getElements(), "properties");
	model.properties = properties;
    propertiesList = properties.getElements();
	var props = new Array();
	props["icon"] = doc.getExtension(atom.createQName("http://www.alfresco.org","icon")).getText();

	model.text = "";
	var mjb = true;

    for (var j = 0; j < propertiesList.size(); j++) {
      property = propertiesList.get(j);
      if (property != null && property.firstChild != null) {
		 model.text += property.getAttributeValue("propertyDefinitionId");

		 if ((property.getAttributeValue("propertyDefinitionId") == "cmis:name") && (mjb = true)) {
			mjb = false;
			//found cmis:name
			model.name = property.firstChild.text;
		 }
		 var propName = localPart(property.getAttributeValue("propertyDefinitionId"));
		 props[propName] = property.firstChild.text;
		 model.propName = propName;
      }
    }
	model.props = props;
	list[i] = props;
  }
  return list;
}

function localPart(qName){
  return qName.substring(qName.lastIndexOf(":") + 1, qName.length());
}

Note that the workspace ID works for me – but will not work for you. You will need to replace this : workspace://SpacesStore/560b8dd6-6503-4ad5-8066-5946c1456ec1
with a noderef to a directory with a files in it.

Get your own noderef by going into Alfresco – find  a nice looking directory – go to “View Details” – find the Alfresco Node Reference link – right-click and “Copy link adress” which has a similar format (workspace://SpacesStore/some-numbers-and-letters-with-dashes) Paste this is the javascript file (mjb.get.js)

Once the files are in place, your need to update the Alfresco Share webscripts library:
http://localhost:8080/share/page/index
Press the refresh button – you should see 1 more webscript available.
Then login to share
http://localhost:8080/share
Click ‘dashboard wijzigen’ and drag your new dashlet (called MJB) into it.

Yes I know it is very dirty code. It’s even throwing horrible looking output.
But it’s just a small proof of the pudding that shows it’s working.

Advertenties

Geef een reactie

Vul je gegevens in of klik op een icoon om in te loggen.

WordPress.com logo

Je reageert onder je WordPress.com account. Log uit / Bijwerken )

Twitter-afbeelding

Je reageert onder je Twitter account. Log uit / Bijwerken )

Facebook foto

Je reageert onder je Facebook account. Log uit / Bijwerken )

Google+ photo

Je reageert onder je Google+ account. Log uit / Bijwerken )

Verbinden met %s