I'm trying to add a button to the Elements Tree toolbar to create a new Category. Figured it should be fairly simple, just add another block to the modx.tree.element.js file immediately following the other blocks for the other buttons, following the same pattern. Wrong.
Category management is handled quite differently than the other elements. Category creation is tied to the main Categories element in the Tree, via AJAX. The form is created in the same modx.tree.element.js file, after the toolbar buttons are defined. Ok, shouldn't be a big problem to get the new button in the toolbar to use the same AJAX-based popup form, right? Wrong.
Question: "this" obviously doesn't work; the scope is wrong. But what is the scope supposed to be?
},{
icon: MODx.config.manager_url+'templates/default/images/restyle/icons/category.png'
,cls: 'x-btn-icon'
,tooltip: {text: _('new_category')}
,handler: this.createCategory
,scope: this
,hidden: MODx.perm.new_category ? false : true
}]
I added new_category to the list of permission settings in the config.js.php file (around line 90) so the permission check works on the button.