From 84256c91cdc98dc6f3dbb8367c9c23ef2505bc52 Mon Sep 17 00:00:00 2001 From: Doug Bell Date: Wed, 18 Aug 2010 16:46:42 -0500 Subject: [PATCH] add more menus to the Tree view --- www/extras/admin/admin.js | 72 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 1 deletion(-) diff --git a/www/extras/admin/admin.js b/www/extras/admin/admin.js index 0936c12d2..85c6a0a31 100644 --- a/www/extras/admin/admin.js +++ b/www/extras/admin/admin.js @@ -1206,15 +1206,85 @@ WebGUI.Admin.Tree.prototype.formatHelpers elCell.appendChild( document.createTextNode( " | " ) ); } - var more = document.createElement( 'a' ); + var more = document.createElement( 'span' ); + more.className = 'clickable'; elCell.appendChild( more ); more.appendChild( document.createTextNode( window.admin.i18n.get('Asset','More' ) ) ); more.href = '#'; // Build onclick handler to show more menu + // These format functions do not have the right context + window.admin.tree.addMenuOpenHandler( more, oRecord.getData( 'assetId' ), oRecord.getData( 'helpers' ) ); }; +/** + * addMenuOpenHandler( elem, assetId, helpers ) + * Add a handler that will open a menu for the given assetId with the given + * helpers + */ +WebGUI.Admin.Tree.prototype.addMenuOpenHandler += function ( elem, assetId, helpers ) { + var self = this; + YAHOO.util.Event.addListener( elem, "click", function(){ + self.showHelperMenu( elem, assetId, helpers ); + } ); +}; + +/** + * showHelperMenu( elem, assetId, helpers ) + * Show the Helper menu for the given assetId with the given helpers + */ +WebGUI.Admin.Tree.prototype.showHelperMenu += function ( elem, assetId, helpers ) { + if ( this.helperMenu ) { + // destroy the old helper menu! + this.helperMenu.destroy(); + } + this.helperMenu = new YAHOO.widget.Menu( "treeHelperMenu", { + position : "dynamic", + clicktohide : true, + constraintoviewport : true, + context : [ elem, 'tl', 'bl' ], + effect: { effect: YAHOO.widget.ContainerEffect.FADE, duration:0.25 } + } ); + + // Add all the items with appropriate onclick handlers + for ( var i = 0; i < helpers.length; i++ ) { + var helper = helpers[i]; + var item = { + text : helper["label"], + icon : helper["icon"], + onclick : { + fn : this.clickHelper, + obj : [ assetId, helper ], + scope : this + } + }; + this.helperMenu.addItem( item ); + } + + this.helperMenu.render( document.body ); + this.helperMenu.show(); + this.helperMenu.focus(); +}; + +/** + * clickHelper( type, event, args, menuItem ) + * Request the helper. args is an array of [ assetId, helperData ] + */ +WebGUI.Admin.Tree.prototype.clickHelper += function ( type, e, args, menuItem ) { + var assetId = args[0]; + var helper = args[1]; + if ( helper.url ) { + this.admin.showView( helper.url ); + } + else if ( helper['class'] ) { + this.admin.requestHelper( helper['class'], assetId ); + } +}; + /** * formatAssetIdCheckbox ( ) * Format the checkbox for the asset ID.