Page 1 of 1

[SOLVED] Creating a new tag menu

Posted: Wed Jun 08, 2016 4:55 pm
by brick__
Hello guys,

I think you could have guessed from the post's title that I'm trying to create a new tag menu by myself.
TL;DR:I want to have the tag menu in the actions menu in the toolbar. The way i'm trying it is by creating a new ZmTagMenu in the actions menu. The menu creation is working, but i can't get it to populate with the create tag & delete tag and the existing tags as I thought it could. I am trying to use the _render(taglist, addRemove) method which looks like it can do that job for me, but I can't wrap my head around how to get the addRemove[] array needed.
Here's the code that I use to create my new tag menu (I am calling this function in the initializeToolbar(app, toolbar, controller, viewId) method in my zimlet):

Code: Select all

ZmEnhancedToolbar.prototype._setActionsMenu =
function(toolbar) {
    var actionsMenu = toolbar.getActionsMenu();
    
    actionsMenu.createSeparator();
    var subTagButton = actionsMenu.createOp("tag_submenu", {
        text: "myTagMenu"
    });
     
    var subTagMenu = new ZmTagMenu(subTagButton);
    subTagMenu._render(appCtxt.getTagTree(), /*addRemove*/);                                      
    subTagButton.setMenu(subTagMenu);
}
Pretty straight forward. So i'm getting the menu created, but is is empty. I thought it would have been populated as I wanted to on its creation. After lookin at the source code, it seems like the _render(tagList, addRemove) method is responsable for that, and it isn't called in the constructor. So i'm trying to call it, but I'm getting an error caused because I just don't know how to get back the addRemove parameter... I've searched pretty much anywhere I could, or at least i think so...

Code: Select all

Uncaught TypeError: Cannot read property 'add' of undefined
It seems like it is searching for the existing tags in the addRemove array, but how can i get the addRemove array back? Where from? Additionally, will this build the tag menu as I want it?

Re: Creating a new tag menu

Posted: Thu Jun 09, 2016 3:44 pm
by brick__
All right, that last post was pretty bad. I figured a few things out since I first posted it, and I don't think an edit of the first one is worth since I was pretty off beam.
TL;DR: I have a view-wise working sub tagMenu in my actionsMenu, as I wanted. My question is: What is the proper way to bind the listeners?
For anyone who may be heading on the same road (and is as blind as me), there is a set(items, tagList) method that is much more simple to use, and is, I assume, the correct way to build a ZmTagMenu.
Here's how the code looks now:

Code: Select all

ZmEnhancedToolbar.prototype._setActionsMenu =
function(controller, toolbar) {
    var  actionsMenu = toolbar.getActionsMenu();
    
    // Checks for an existing actions menu in the toolbar
    if(actionsMenu){
        actionsMenu.createSeparator();

        var tagSubButton = actionsMenu.createMenuItem(ZmOperation.TAG_MENU, {
            text: ZmMsg.briefcasePropTags,
            image: "Tag"
        });
        
        var subTagMenu = ZmOperation.addTagMenu(tagSubButton);
        
        // This function let's me populate the new subTagMenu
        subTagMenu.set(controller.getItems(), appCtxt.getTagTree());
        
        // Here's how I'm binding the listeners
        controller._setupTagMenu(actionsMenu);
    }
}
So that does the trick except for one thing, which is quiet as similar as the final problem I had in my first post, which is the binding of the listeners to the actual buttons. I guess I probably can browse through all my buttons from the tagMenu in the toolbar, and assign them to the ones on the same index in my newly created sub tagMenu, but it seems a little hacky since I managed to create it that cleanly... Is there a right way or am I just looking to hard at something that doesn't exist..?

EDIT:
So, there's progress sooner than I thought. I found what I was looking for, which was the ZmBaseController._setupTagMenu(parent, listener), and it works like a charm... except for one thing, which is that the removeTag button is always off, no matter the tag there's on the item. So, i've updated the code above, and I'm really looking for a way to fix that rather weird issue.

2 EDIT:
Ok, I finally found what was wrong, and that weird "issue" I had turns out to be perfectly explainable. And now I know what I'm looking for. The reason the removeTag button is always off, is the same reason (which I hadn't notice on my first edit) the tags will all appear, no matter the tags the item already owns. It is the fact that my menu's content is not refreshed. Which means I have to find the right listener. I think I found what I need, but don't know how to implement it (on which objects, or even how to call it). I found this piece of code in the ZmOperation.js file:

Code: Select all

ZmOperation.registerOp(ZmId.OP_TAG_MENU, {textKey: "tag", tooltipKey:"tagTooltip", image:"Tag", showImageInToolbar: true }, ZmSetting.TAGGING_ENABLED, AjxCallback.simpleClosure(function(parent) {
		ZmOperation.addDeferredMenu(ZmOperation.addTagMenu, parent, true);
}));
So I'm pretty interested in this ZmOperation.addDeferredMenu(addMenuFunc, parent) method with the ZmOperation.addTagMenu(parent), and I guess I also need the AjxCallback.simpleClosure(func, object) method. But I don't know how I need to use them. I guess I can keep my tagSubButton, but that's pretty much it. Does anyone know how to use this promise in my context?

Re: Creating a new tag menu

Posted: Mon Jun 20, 2016 11:51 pm
by cdamon
I think what you want to do here is to duplicate what happens when the tag button in the toolbar is pressed: the controller gets a list of the selected items, and then sets the tag menu based on that (only show tags an item lacks, and only allow removal of tags it does have). That happens via the button listener ZmBaseController.prototype._tagButtonListener. You will need a similar listener for your Tag menu item.

It needs to do something like this:

controller._setTagMenu(actionMenu)

Also, you should just use ZmMsg.tags for the menu item text.

Re: Creating a new tag menu

Posted: Tue Jun 21, 2016 9:04 am
by tkhandelwal
As mentioned by cdamon , button listener is what is missing here which refresh's the context .

You can try adding this code :

Code: Select all

tagSubButton.addListener(DwtEvent.ONMOUSEOVER, new AjxListener(this, function() {
            controller._setTagMenu(actionsMenu);
      }));

Re: Creating a new tag menu

Posted: Wed Jun 29, 2016 12:58 pm
by brick__
Thanks guys,
it works as intended now.

Setting the post as solved.