Results 1 to 1 of 1

Thread: Code example request : ZmBatchCommand

Hybrid View

  1. #1
    Join Date
    Jul 2012
    Location
    Algiers
    Posts
    55
    Rep Power
    3

    Default [solved] Code example request : ZmBatchCommand

    Hi,

    I would be grateful to anyone who posts an example usage of a very simple code (a hello world code) showing how to use the ZmBatchCommand javascript function in a zimlet to send SOAP requests to zimbra.

    EDIT :

    sorry for bothering again, I'v found one in Zimbra's own source code. Here's how it works (for people like me who were looking for an example)


    Code:
    ZmContactListController.prototype._doMove = function(items, folder, attrs, isShiftKey) {
    [...]
        if (moveFromGal.length) {
    	var batchCmd = new ZmBatchCommand(true, null, true);
    	for (var j = 0; j < moveFromGal.length; j++) {
    	    var contact = moveFromGal[j];
    	    contact.attr[ZmContact.F_folderId] = folder.id;
    	    batchCmd.add(new AjxCallback(contact, contact.create, [contact.attr]));
    	}
    	batchCmd.run(new AjxCallback(this, this._handleMoveFromGal));
        }
        [...]
    };
    
    ZmContact.prototype.create = function(attr, batchCmd) {
        var jsonObj = {CreateContactRequest:{_jsns:"urn:zimbraMail"}};
        [...]
        var respCallback = new AjxCallback(this, this._handleResponseCreate, [attr, batchCmd != null]);
        [...]
        if (batchCmd) {
    	batchCmd.addRequestParams(jsonObj, respCallback);
        } else {
    	appCtxt.getAppController().sendRequest({jsonObj:jsonObj, asyncMode:true, callback:respCallback});
        }
    };

    So basically :

    1/ Create a ZmBatchCommand
    1.1/ add your functions/methods via batch.add(callback). You have to wrap them in an AjxCallback first, before adding them.
    2/ In the individual functions/methods, add a new batch argument. Your functions will be called by the ZmBatchCommand and given that as last argument
    3/ In the individual functions/methods, if you're in batch mode (confirmed by a non-null batch parameter), add your json or xml request along with the response callback as shown above with batchCmd.addRequestParams.
    4/ When you're ready, run the batchrequest and optionnaly specify a response handler.
    Last edited by ychaouche; 10-23-2012 at 05:03 AM.

Similar Threads

  1. Where can I get source code?
    By shobha in forum General Questions
    Replies: 0
    Last Post: 07-31-2012, 05:56 AM
  2. Help me about Zimbra IM code !!! Plz
    By hadongtung in forum Developers
    Replies: 0
    Last Post: 10-03-2010, 07:39 PM
  3. ZCS version for code available in SVN?
    By CJ7 in forum Developers
    Replies: 4
    Last Post: 12-11-2009, 11:14 AM
  4. source code
    By adonis1976 in forum Developers
    Replies: 1
    Last Post: 11-06-2009, 07:00 PM
  5. What is Error Code: 7
    By jroberts235 in forum Installation
    Replies: 5
    Last Post: 03-31-2008, 10:04 AM

Tags for this Thread

Posting Permissions

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