Zimbra offers Open Source email server software and shared calendar for Linux and the Mac
 
Go Back   Zimbra - Forums > Zimbra Collaboration Suite > Zimlets

Welcome to the Zimbra - Forums!
Welcome, if you would like to post a comment please register. We also encourage you to explore all things Zimbra with our team and members of the community.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-03-2006, 06:33 AM
Moderator
 
Posts: 701
Default Simple lookup zimlet, help needed

So it's time to get into writing zimlets, I've been looking at the code for the included ones and I'm prepared to just get stuck in and start from scratch, but what I'd really like is for someone to write a very basic one for me to build on and learn from, and yes, I know people must ask this all the time, but my js skills are not too hot yet and tyring to understand what the sample zimlets actually do and how they do it is headache inducing.

What I would like is simply the abitlty to hover over a product code and have it show our current stock level of that item. I can write a simple asp page that will return the quantity of items in our stock based on the url passed to it, so if I go the the fictional address http://domain.com/stockcheck.asp?item=ab123 a page is returned containing a number, that parts easy, I can do that in my sleep

How do I go about making a zimlet recognise the stock code, and go to a webpage based on it, and show the results in a tooltip?

I get the feeling this is really simple and no javascript will be involved (at the start), so if it is, does anyone feel like writing it? Clearly it will eventually need to do far more than just show stock levels, but from the initiall framework I will be able to develop it faster than starting from scratch. If something useful comes of it, I will of course send the tool back to the community.

Thanks all.
Reply With Quote
  #2 (permalink)  
Old 09-03-2006, 09:38 AM
Zimbra Employee
 
Posts: 2,073
Default

the yahoo maps zimlet is a very simple zimlet that does a webscrape like you describe, as is the bugz zimlet.
__________________
Bugzilla - Wiki - Downloads - Before posting... Search!
Reply With Quote
  #3 (permalink)  
Old 09-03-2006, 10:07 AM
Moderator
 
Posts: 701
Default

Righto, I'll get them opened up and start studying. Once I start making changes, is there any easier way to test other than zipping it all up, removing the old one, deploying the new one and restarting tomcat? Can I edit some files directly within the server folders while testing?
Reply With Quote
  #4 (permalink)  
Old 09-04-2006, 05:01 AM
Moderator
 
Posts: 701
Default

Ok, Been working on this since 8am and I've now got it to recognise a stock code and show a tooltip when the mouse hovers over it, the tooltip currently simply contains the regex match, so hovering over 1234567ABC will show a tooltip containing 1234567ABC. Not exactly setting the world on fire just yet.

I've been tearing apart the bugz and amazon code to get this far, and here's what I'm working with:

.XML
Code:
<zimlet name="uk_co_domain_stockcode" version="1.0" description="Stock Code">
	<include>ZmStockObjectHandler.js</include>
	<handlerObject>ZmStockObjectHandler</handlerObject>
	<contentObject type="stock">
        <matchOn>
            <regex attrs="ig">(?:\d\d\d\d\d\d\d\D+)</regex>
        </matchOn>
    </contentObject>
</zimlet>
.js
Code:
function ZmStockObjectHandler() {
}

ZmStockObjectHandler.prototype = new ZmZimletBase;
ZmStockObjectHandler.prototype.constructor = ZmStockObjectHandler;
ZmStockObjectHandler.prototype.toolTipPoppedUp =
function(spanElement, obj, context, canvas) {
	canvas.innerHTML = "<b>ID: </b>"+context;
};
Could anyone point me in the right direction for the next stage, which is to replace the content of the tooltip with the result of a webpage, so a reasonably simple ajax call, but I'm struggling with the syntax.
Reply With Quote
  #5 (permalink)  
Old 09-04-2006, 06:44 AM
Zimbra Employee
 
Posts: 2,073
Default

You can pull that straight out of the ymaps zimlet - look for the string "proxy"
__________________
Bugzilla - Wiki - Downloads - Before posting... Search!
Reply With Quote
  #6 (permalink)  
Old 09-04-2006, 07:13 AM
Moderator
 
Posts: 701
Default

Yeah, I've been looking at that, this is the section:

Code:
Com_Zimbra_YMaps.prototype.toolTipPoppedUp =
function(spanElement, obj, context, canvas) {
	canvas.innerHTML = '<center><img width="345" height="245" id="'+ ZmZimletBase.encodeId(obj)+'" src="'+this.getResource('blank_pixel.gif')+'"/></center>';
	if (Com_Zimbra_YMaps.CACHE[obj+"img"]) {
		Com_Zimbra_YMaps._displayImage(Com_Zimbra_YMaps.CACHE[obj+"img"], obj);
	} else {
		var url = ZmZimletBase.PROXY + AjxStringUtil.urlComponentEncode(Com_Zimbra_YMaps.URL + AjxStringUtil.urlComponentEncode(obj));
		DBG.println(AjxDebug.DBG2, "Com_Zimbra_YMaps URL: " + url);
		AjxRpc.invoke(null, url, null, new AjxCallback(this, Com_Zimbra_YMaps._callback, obj), true);
	}
};
Looking at it, it seems to be checking to see if it's already loaded the result and cached it, so if I throw that part away and just get down to the meat, I have:

Code:
var url = ZmZimletBase.PROXY + AjxStringUtil.urlComponentEncode(Com_Zimbra_YMaps.URL + AjxStringUtil.urlComponentEncode(obj));
DBG.println(AjxDebug.DBG2, "Com_Zimbra_YMaps URL: " + url);
AjxRpc.invoke(null, url, null, new AjxCallback(this, Com_Zimbra_YMaps._callback, obj), true);
Trying to understand what that does is my current problem. I've no idea what the line starting DBG.println is doing and I'm getting rather confused.

Yes, I've experimented, nope it didnt work Come on marcmac, put me out of my misery here!
Reply With Quote
  #7 (permalink)  
Old 09-04-2006, 08:54 AM
Zimbra Consultant & Moderator
 
Posts: 11,508
Default

Quote:
Originally Posted by Dirk
Come on marcmac, put me out of my misery here!
You do realise it's a holiday in the USA today don't you.
__________________
Regards


Bill
Reply With Quote
  #8 (permalink)  
Old 09-04-2006, 09:52 AM
Moderator
 
Posts: 701
Default

Quote:
Originally Posted by phoenix
You do realise it's a holiday in the USA today don't you.
lol, no, cant say that I did

In that case, I'll keep plugging away at it and simply be thankful for any responses at all ! What's the holiday btw?
Reply With Quote
  #9 (permalink)  
Old 09-04-2006, 09:54 AM
Zimbra Consultant & Moderator
 
Posts: 11,508
Default

It's Labor Day (or Labour Day, if you prefer the UK spelling), I'm sure Marc will drop by sometime.
__________________
Regards


Bill
Reply With Quote
  #10 (permalink)  
Old 09-05-2006, 02:36 AM
Moderator
 
Posts: 701
Default

Ok, I've found a very early post that wasnt showing up before (I just notice the 'show post in last 75 days' setting on the forums) and with that I think the code is now correct. The tooltip shows but it's empty, I'm suspecting it cant communicate with the webserver sending the results.

Where can I check the progress in the log files? I've tried launching the client in debug mode, but nothing seems to show up regarding the zimlet, and I've looked at zimbra.log but nothing there either. Any ideas?
Reply With Quote
Reply


Thread Tools
Display Modes


Similar Threads

Why Join?

Registering let's you ask questions, makes it easier to search, displays any files attached to posts, and notifies you about replies.

Zimbrablog.com




 

Search Engine Optimization by vBSEO 3.1.0