[Zope3-checkins] CVS: Zope3/src/zope/app/browser/container - adding.py:1.28 contents.py:1.29 commontasks.pt:1.7 contents.pt:1.9

Naveen P pnaveen at zeomega.com
Fri Dec 12 10:39:49 EST 2003


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

Modified Files:
	adding.py contents.py commontasks.pt contents.pt 
Log Message:
Display an add button on the contents view when only one kind of thing can be added.
Include a space to enter a name if appropriate.
Update content views to not support rename or new-object name entry if the container picks names. 


=== Zope3/src/zope/app/browser/container/adding.py 1.27 => 1.28 ===
--- Zope3/src/zope/app/browser/container/adding.py:1.27	Wed Dec 10 04:04:36 2003
+++ Zope3/src/zope/app/browser/container/adding.py	Fri Dec 12 10:39:18 2003
@@ -199,11 +199,25 @@
                         factory = zapi.getFactory(container, factory)
                         if not checkFactory(container, None, factory):
                             continue
+                        elif item['extra']['factory'] != item['action']:
+                            item['has_custom_add_view']=True
                 result.append(item)
                 
         result.sort(lambda a, b: cmp(a['title'], b['title']))
         return result
+    
+    def isSingleMenuItem(self):
+        "Return whether there is single menu item or not."
+        return len(self.addingInfo()) == 1
 
+    def hasCustomAddView(self):
+       "This should be called only if there is singleMenuItem else return 0"
+       if self.isSingleMenuItem():
+           menu_item = self.addingInfo()[0]
+           if 'has_custom_add_view' in menu_item:
+               return True
+       return False
+           
 class ContentAdding(Adding):
 
     menu_id = "add_content"


=== Zope3/src/zope/app/browser/container/contents.py 1.28 => 1.29 ===
--- Zope3/src/zope/app/browser/container/contents.py:1.28	Thu Oct  2 12:23:19 2003
+++ Zope3/src/zope/app/browser/container/contents.py	Fri Dec 12 10:39:18 2003
@@ -30,6 +30,7 @@
 from zope.app.browser.container.adding import BasicAdding
 from zope.app.copypastemove import rename
 from zope.exceptions import NotFoundError
+from zope.app.interfaces.container import IContainerNamesContainer
 
 class Contents(BrowserView):
 
@@ -56,7 +57,17 @@
 
         elif "container_rename_button" in request and not request.get("ids"):
             self.error = _("You didn't specify any ids to rename.")
-
+        elif "container_add_button" in request:
+            if "single_type_name" in request \
+                   and "single_new_value" in request:
+                request.form['type_name'] = request['single_type_name']
+                request.form['new_value'] = request['single_new_value']
+                self.addObject()
+            elif 'single_type_name' in request \
+                     and 'single_new_value' not in request:
+                request.form['type_name'] = request['single_type_name']
+                request.form['new_value'] = ""
+                self.addObject()
         elif "type_name" in request and "new_value" in request:
             self.addObject()
         elif "rename_ids" in request and "new_value" in request:
@@ -103,7 +114,9 @@
         self.supportsCut = info
         self.supportsCopy = info
         self.supportsPaste = self.pasteable()
-        self.supportsRename = self.supportsCut
+        self.supportsRename = (
+            self.supportsCut and not IContainerNamesContainer.isImplementedBy(self.context)
+            )
 
         return info
 
@@ -188,20 +201,23 @@
 
     def addObject(self):
         request = self.request
-        new = request["new_value"]
-        if new:
-            adding = zapi.queryView(self.context, "+", request)
-            if adding is None:
-                adding = BasicAdding(self.context, request)
-            else:
-                # Set up context so that the adding can build a url
-                # if the type name names a view.
-                # Note that we can't so this for the "adding is None" case
-                # above, because there is no "+" view.
-                adding.__parent__ = self.context
-                adding.__name__ = '+'
+        if IContainerNamesContainer.isImplementedBy(self.context):
+            new = ""
+        else:
+            new = request["new_value"]
 
-            adding.action(request['type_name'], new)
+        adding = zapi.queryView(self.context, "+", request)
+        if adding is None:
+            adding = BasicAdding(self.context, request)
+        else:
+            # Set up context so that the adding can build a url
+            # if the type name names a view.
+            # Note that we can't so this for the "adding is None" case
+            # above, because there is no "+" view.
+            adding.__parent__ = self.context
+            adding.__name__ = '+'
+             
+        adding.action(request['type_name'], new)
 
     def removeObjects(self):
         """Remove objects specified in a list of object ids"""


=== Zope3/src/zope/app/browser/container/commontasks.pt 1.6 => 1.7 ===
--- Zope3/src/zope/app/browser/container/commontasks.pt:1.6	Tue Aug 19 19:26:17 2003
+++ Zope3/src/zope/app/browser/container/commontasks.pt	Fri Dec 12 10:39:18 2003
@@ -5,18 +5,33 @@
     <strong i18n:translate="">Add new content</strong>
   </div>
 
-  <tal:block repeat="info addingInfo">
-    <div tal:define="oddrow repeat/info/odd" class="even"
-      tal:attributes="class python:oddrow and 'content even' or 'content odd'">
-
+  <tal:block repeat="info addingInfo" 
+	define="namesRequired context/@@+/namesAccepted">
+    <div tal:define="oddrow repeat/info/odd; 
+		     namesRequired context/@@+/namesAccepted;
+        has_custom_add_view python:'has_custom_add_view' in info"
+      	tal:attributes="class python:oddrow and 'content even' or 'content odd'"
+	class="even">
       <a href="#"
         tal:define="baseurl python:request.getURL(1)"
-        tal:condition="python: not info['action'].startswith('../')"
+        tal:condition="python: not info['action'].startswith('../')
+                               and namesRequired and not has_custom_add_view"
         tal:attributes="
           href string:${baseurl}/@@contents.html?type_name=${info/action};
           class info/selected"
         tal:content="info/title" i18n:translate="">Folder
       </a>
+      
+      <a href="#"
+        tal:define="baseurl python:request.getURL(1)"
+        tal:condition="python: not info['action'].startswith('../') 
+		               and (has_custom_add_view or not namesRequired)"
+        tal:attributes="
+          href string:${baseurl}/@@+/action.html?type_name=${info/action};
+          class info/selected"
+        tal:content="info/title" i18n:translate="">Folder
+      </a>
+
       <a href="#"
         tal:define="baseurl python:request.getURL(1)"
         tal:condition="python: info['action'].startswith('../')"


=== Zope3/src/zope/app/browser/container/contents.pt 1.8 => 1.9 ===
--- Zope3/src/zope/app/browser/container/contents.pt:1.8	Thu Aug  7 13:40:25 2003
+++ Zope3/src/zope/app/browser/container/contents.pt	Fri Dec 12 10:39:18 2003
@@ -1,7 +1,6 @@
 <html metal:use-macro="views/standard_macros/page">
 <body>
 <div metal:fill-slot="body">
-
   <div metal:define-macro="contents">
 
     <form name="containerContentsForm" method="POST" action="."
@@ -40,7 +39,8 @@
 
         <tbody>
 
-        <tr tal:condition="request/type_name|nothing">
+        <tr tal:define="names_required context/@@+/namesAccepted"
+	    tal:condition="python:names_required and request.has_key('type_name')">
           <td></td>
           <td><input name="new_value" id="focusid" value="" /></td>
           <td></td>
@@ -113,7 +113,9 @@
         </tbody>
       </table>
 
-      <div tal:condition="view/normalButtons">
+      <div tal:condition="view/normalButtons" 
+	   tal:define="addingInfo context/@@+/addingInfo|nothing">
+
         <input type="submit" name="container_rename_button" value="Rename"
                i18n:attributes="value container-rename-button"
                tal:condition="view/supportsRename"
@@ -132,8 +134,28 @@
                />
         <input type="submit" name="container_delete_button" value="Delete"
                i18n:attributes="value container-delete-button"
+			   tal:condition="container_contents"
+               i18n:domain="zope"
+               />
+
+
+	<div tal:condition="context/@@+/isSingleMenuItem" tal:omit-tag="" 
+	     tal:define="has_custom_add_view context/@@+/hasCustomAddView; 
+			 names_required context/@@+/namesAccepted">
+          <input type="submit" name="container_add_button" value="Add"
+		i18n:attributes="value container-add-button"
                i18n:domain="zope"
                />
+          <input type="text" name="single_new_value" id="focusid"
+		 tal:condition="python:names_required and not has_custom_add_view"
+                 i18n:domain="zope"
+               />
+          <input type="hidden" name="single_type_name"
+               value=""
+               tal:attributes="value python:addingInfo[0]['action']" 
+               />
+	</div>
+
       </div>
 
       <div tal:condition="view/specialButtons">
@@ -149,7 +171,8 @@
 
     <script ><!--
         prettydump('focus', LG_INFO);
-        document.containerContentsForm.new_value.focus();
+        if (document.containerContentsForm.new_value)
+	        document.containerContentsForm.new_value.focus();
         //-->
     </script>
 




More information about the Zope3-Checkins mailing list