Adding document counts with Ajax
Showing how many documents are in each category is a usefull enhancement to my blog. I cannot use @DocDescendants(), since I am using a @DbColumn() lookup for the categories. So I decided to do it with Ajax.
The XMLHttpRequest wrapper
I first need to extend my 'Mme' namespace with a Mme.request library which will act as a wrapper for the XMLHttpRequest.
Mme.request={
_req:function(){return window.XMLHttpRequest?new XMLHttpRequest():window.ActiveXObject?new ActiveXObject('Microsoft.XMLHTTP'):null},
get:function(a){
var o=this._req()
o.open('GET',a,false)
o.send(null)
return o
}
}
The Mme.getCount library
For my document count, I need the collapsed 'categories' view in XML format, and as you can see, the children attribute of each viewentry node contains the number of documents in that category. Next, the only thing to do is go over each node and add a textnode to each list item in my Categories display box:
Mme.getCount={
init:function(){
var o,x,i,t,n,v
v='http://blog.lotusnotes.be/domino/categories?ReadViewEntries&CollapseView'
o=Mme.request.get(v)
x=Mme.tags('viewentry',o.responseXML.documentElement)
t=Mme.tags('li',Mme.get('categories'))
for(i=0;i<x.length;i++){
n=document.createTextNode(' ('+x[i].getAttribute('children')+')')
t[i].appendChild(n)
}
}
}
And since I extend my Dom - see my previous post And there was Ajax... - and the library has an init function, it is initiated automatically on page load.
Cross browser scripting
A great document I found on the web that explains the differences between Mozilla and Internet Explorer is Migrate apps from Internet Explorer to Mozilla.
Comments
To add a comment, log in or register as new user. It's free and safe.