Quantcast
Channel: Zimbra :: Forums - Developers
Viewing all articles
Browse latest Browse all 286

Code example request : ZmBatchCommand

$
0
0
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.

Viewing all articles
Browse latest Browse all 286

Latest Images

Trending Articles



Latest Images