[Checkins] SVN: z3c.formjsdemo/trunk/src/z3c/formjsdemo/tree/ Added a contract button.

Paul Carduner paulcarduner at gmail.com
Tue Aug 21 17:46:48 EDT 2007


Log message for revision 79101:
  Added a contract button.

Changed:
  U   z3c.formjsdemo/trunk/src/z3c/formjsdemo/tree/browser.py
  U   z3c.formjsdemo/trunk/src/z3c/formjsdemo/tree/inline.pt
  U   z3c.formjsdemo/trunk/src/z3c/formjsdemo/tree/tree.css
  U   z3c.formjsdemo/trunk/src/z3c/formjsdemo/tree/treenode.pt

-=-
Modified: z3c.formjsdemo/trunk/src/z3c/formjsdemo/tree/browser.py
===================================================================
--- z3c.formjsdemo/trunk/src/z3c/formjsdemo/tree/browser.py	2007-08-21 21:27:08 UTC (rev 79100)
+++ z3c.formjsdemo/trunk/src/z3c/formjsdemo/tree/browser.py	2007-08-21 21:46:47 UTC (rev 79101)
@@ -26,7 +26,7 @@
 from z3c.formui import layout
 from z3c.form.interfaces import IWidgets, DISPLAY_MODE
 
-from z3c.formjs import jsaction, jsswitch
+from z3c.formjs import jsaction, jsfunction
 from z3c.formjs.interfaces import IJSButton
 import tree, interfaces
 
@@ -88,14 +88,36 @@
 
     fields = field.Fields(interfaces.ITreeNode).select('title')
 
+    @jsfunction.function('tree')
+    def expandNode(self, url, expanderId, contractorId, containerId):
+        """Expand the node that using the given prefix and url"""
+        return '''
+        $.get(url,
+          function(data){
+            $("#"+expanderId).addClass("hidden");
+            $("#"+contractorId).removeClass("hidden");
+            $("#"+containerId).html(data);
+          }
+        );
+        '''
 
+    @jsfunction.function('tree')
+    def contractNode(self, expanderId, contractorId, containerId):
+        """Expand the node that using the given prefix and url"""
+        return '''
+        $("#"+expanderId).removeClass("hidden");
+        $("#"+contractorId).addClass("hidden");
+        $("#"+containerId).html('');
+        '''
+
 class IButtons(Interface):
     """Buttons for the inline tree node form."""
 
     expand = jsaction.JSButton(title=u'+')
+    contract = jsaction.JSButton(title=u'-')
 
 
-class TreeNodeInlineForm(PrefixForm, jsswitch.WidgetModeSwitcher, form.Form):
+class TreeNodeInlineForm(PrefixForm, form.Form):
 
     fields = field.Fields(interfaces.ITreeNode).select('title')
     buttons = button.Buttons(IButtons)
@@ -103,11 +125,21 @@
     @jsaction.handler(buttons['expand'])
     def handleExpand(self, event, selector):
         url = absoluteURL(self.context, self.request) + '/@@contents'
-        return '''$.get("%s", function(data){
-                    $("#%s-inlinecontent").html(data);
-                 });
-               ''' % (url, self.prefix)
+        return TreeNodeForm.expandNode.call(url,
+                                            self.actions['expand'].id,
+                                            self.actions['contract'].id,
+                                            self.prefix+'-inlinecontent')
 
+    @jsaction.handler(buttons['contract'])
+    def handleExpand(self, event, selector):
+        return TreeNodeForm.contractNode.call(self.actions['expand'].id,
+                                              self.actions['contract'].id,
+                                              self.prefix+'-inlinecontent')
+
+    def updateActions(self):
+        super(TreeNodeInlineForm, self).updateActions()
+        self.actions['contract'].addClass('hidden')
+
     def updateWidgets(self):
         self.widgets = getMultiAdapter(
             (self, self.request, self.getContent()), IWidgets)

Modified: z3c.formjsdemo/trunk/src/z3c/formjsdemo/tree/inline.pt
===================================================================
--- z3c.formjsdemo/trunk/src/z3c/formjsdemo/tree/inline.pt	2007-08-21 21:27:08 UTC (rev 79100)
+++ z3c.formjsdemo/trunk/src/z3c/formjsdemo/tree/inline.pt	2007-08-21 21:46:47 UTC (rev 79101)
@@ -2,6 +2,7 @@
 
 <div class="node">
   <span tal:replace="structure view/actions/expand/render" />
+  <span tal:replace="structure view/actions/contract/render" />
   <span tal:replace="structure view/widgets/title/render" />
 
   <div tal:attributes="id string:${view/prefix}-inlinecontent"

Modified: z3c.formjsdemo/trunk/src/z3c/formjsdemo/tree/tree.css
===================================================================
--- z3c.formjsdemo/trunk/src/z3c/formjsdemo/tree/tree.css	2007-08-21 21:27:08 UTC (rev 79100)
+++ z3c.formjsdemo/trunk/src/z3c/formjsdemo/tree/tree.css	2007-08-21 21:46:47 UTC (rev 79101)
@@ -1,3 +1,7 @@
+.hidden {
+  display: none;
+}
+
 div.node {
   margin-left: 1em;
   border-left: 1px dashed black;

Modified: z3c.formjsdemo/trunk/src/z3c/formjsdemo/tree/treenode.pt
===================================================================
--- z3c.formjsdemo/trunk/src/z3c/formjsdemo/tree/treenode.pt	2007-08-21 21:27:08 UTC (rev 79100)
+++ z3c.formjsdemo/trunk/src/z3c/formjsdemo/tree/treenode.pt	2007-08-21 21:46:47 UTC (rev 79101)
@@ -1,3 +1,4 @@
+<script type="text/javascript" tal:content="view/jsFunctions/render"></script>
 <h2>The Root is: <strong tal:content="context/title" /></h2>
 <p>And here is the tree:</p>
 



More information about the Checkins mailing list