[Zope3-checkins] CVS: Zope3/src/zope/app/browser - menu.py:1.4.6.1 menus.zcml:1.7.12.1

Peter Simmons pete@bcmpweb.com
Sun, 13 Jul 2003 05:11:02 -0400


Update of /cvs-repository/Zope3/src/zope/app/browser
In directory cvs.zope.org:/tmp/cvs-serv29766/src/zope/app/browser

Modified Files:
      Tag: ozzope-menu
	menu.py menus.zcml 
Log Message:
: ----------------------------------------------------------------------
: This branch contains the beginnings of a recursive menuing system
: Including a drop-down add menu written in javascript. It implements
: extension to the zcml which allows you to link menu items to menus thus
: creating submenus. 
: Peter S and Dave F Melbourne Sprint 
:
: Committing in .
: 
: Modified Files:
:  Tag: ozzope-menu
: 	products.zcml.in src/zope/app/browser/menu.py 
: 	src/zope/app/browser/menus.zcml 
: 	src/zope/app/browser/container/configure.zcml 
: 	src/zope/app/browser/skins/configure.zcml 
: 	src/zope/app/interfaces/publisher/browser.py 
: 	src/zope/app/publisher/browser/configure.zcml 
: 	src/zope/app/publisher/browser/globalbrowsermenuservice.py 
: 	src/zope/app/publisher/browser/meta.zcml
:---------------------------------------------------------------------- 


=== Zope3/src/zope/app/browser/menu.py 1.4 => 1.4.6.1 ===
--- Zope3/src/zope/app/browser/menu.py:1.4	Mon Jun 30 18:44:13 2003
+++ Zope3/src/zope/app/browser/menu.py	Sun Jul 13 05:10:27 2003
@@ -31,5 +31,59 @@
                                             self.context,
                                             self.request)
 
+                                            
+class JavascriptMenuAccessView(BrowserView):
+    """
+    Provides a rendered view of the menu that will work with the 
+    zope_menu.js client side menu machinery.
+    
+    Don't forget to include the zope_menu.js and also the 
+    script at the top of the body 
+    <script language="JavaScript1.2">
+	<!--
+	zopeLoadMenus();
+	//-->
+	</script>
+    """
+    
+    implements(IMenuAccessView)
+    
+    def __getitem__(self, menu_id):
+        # get the browser menu service
+        browser_menu_service = getService(self.context, 'BrowserMenu')
+        menu =  browser_menu_service.getMenu(menu_id,
+                                            self.context,
+                                            self.request)
+        
+        #find the longest item
+        max_len_item = -1
+        for item in menu:
+            title_len = len(item['title'])
+            if title_len > max_len_item:
+                max_len_item = title_len
+        
+        js = """
+        <!--
+        function load_zope_%(menu)s_menu() {
+            if (window.zope_%(menu)s_menu) return;
+            window.zope_%(menu)s_menu = new Menu("root",%(width)s*fontWidth,menuItemHeight,menuFontFace,menuFontSize,menuFontColor,menuFontMouseOverColor,menuItemBgColor,menuMouseOverBgColor,menuHAlign,menuVAlign,menuItemPadding,menuItemSpacing,hideTimeout,submenuXOffset,submenuYOffset,submenuRelativeToItem,menuBgOpaque,isVertical,menuItemIndent,submenuIcon);
+            zope_%(menu)s_menu.hideOnMouseOut=true;
+            zope_%(menu)s_menu.bgColor=menuBgColor;
+            zope_%(menu)s_menu.menuBorder=menuBorder;
+            zope_%(menu)s_menu.menuLiteBgColor=menuLiteBgColor;
+            zope_%(menu)s_menu.menuBorderBgColor=menuBorderBgColor;
+        """ % {'menu':menu_id, 'width':max_len_item} 
+        for item in menu:
+            js += """
+            zope_%(menu)s_menu.addMenuItem(\"%(title)s\",\"location='@@+/action.html?type_name=%(action)s&id=untitled'\");""" % {
+                'menu':menu_id, 'title':item['title'].replace(' ', '&nbsp;'), 'action':item['action']}
+            
+        js += """
+            zope_%(menu)s_menu.writeMenus();
+        }
+        //-->
+        """ % {'menu':menu_id}
+        
+        return js
 
 __doc__ = MenuAccessView.__doc__ + __doc__


=== Zope3/src/zope/app/browser/menus.zcml 1.7 => 1.7.12.1 ===
--- Zope3/src/zope/app/browser/menus.zcml:1.7	Sat Jun 21 17:21:58 2003
+++ Zope3/src/zope/app/browser/menus.zcml	Sun Jul 13 05:10:27 2003
@@ -73,4 +73,13 @@
      allowed_interface="zope.app.interfaces.browser.menu.IMenuAccessView"
      />
 
+  <!-- Javascript Menu access -->
+  <page
+     for="*"
+     name="view_get_javascript_menu"
+     permission="zope.Public"
+     class=".menu.JavascriptMenuAccessView" 
+     allowed_interface="zope.app.interfaces.browser.menu.IMenuAccessView"
+     />
+     
 </zopeConfigure>