Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: Simple lookup zimlet, help needed

  1. #1
    Dirk's Avatar
    Dirk is offline Moderator
    Join Date
    May 2006
    Location
    England.
    Posts
    927
    Rep Power
    10

    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.

  2. #2
    marcmac is offline Expert Member
    Join Date
    Sep 2005
    Posts
    2,103
    Rep Power
    13

    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!

  3. #3
    Dirk's Avatar
    Dirk is offline Moderator
    Join Date
    May 2006
    Location
    England.
    Posts
    927
    Rep Power
    10

    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?

  4. #4
    Dirk's Avatar
    Dirk is offline Moderator
    Join Date
    May 2006
    Location
    England.
    Posts
    927
    Rep Power
    10

    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.

  5. #5
    marcmac is offline Expert Member
    Join Date
    Sep 2005
    Posts
    2,103
    Rep Power
    13

    Default

    You can pull that straight out of the ymaps zimlet - look for the string "proxy"
    Bugzilla - Wiki - Downloads - Before posting... Search!

  6. #6
    Dirk's Avatar
    Dirk is offline Moderator
    Join Date
    May 2006
    Location
    England.
    Posts
    927
    Rep Power
    10

    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!

  7. #7
    phoenix is online now Zimbra Consultant & Moderator
    Join Date
    Sep 2005
    Location
    Vannes, France
    Posts
    23,470
    Rep Power
    56

    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


    Acompli: A new adventure for Co-Founder KevinH.

  8. #8
    Dirk's Avatar
    Dirk is offline Moderator
    Join Date
    May 2006
    Location
    England.
    Posts
    927
    Rep Power
    10

    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?

  9. #9
    phoenix is online now Zimbra Consultant & Moderator
    Join Date
    Sep 2005
    Location
    Vannes, France
    Posts
    23,470
    Rep Power
    56

    Default

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


    Bill


    Acompli: A new adventure for Co-Founder KevinH.

  10. #10
    Dirk's Avatar
    Dirk is offline Moderator
    Join Date
    May 2006
    Location
    England.
    Posts
    927
    Rep Power
    10

    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?

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 21
    Last Post: 02-04-2010, 10:06 AM
  2. [SOLVED] Amavisd-Postfix RCPT TO Takes a long time
    By samuraii in forum Administrators
    Replies: 8
    Last Post: 02-11-2009, 03:34 PM
  3. Help needed. Simple Zimlet
    By Martinchin2289 in forum Zimlets
    Replies: 6
    Last Post: 11-24-2008, 03:12 AM
  4. Replies: 5
    Last Post: 01-11-2008, 05:34 AM
  5. Post instsallation problems
    By Assaf in forum Installation
    Replies: 14
    Last Post: 01-29-2007, 11:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •