[CMF-checkins] CVS: CMF/CMFWorkspaces/skins/workspaces - search_box_results.pt:1.1 search_box_results_batch.py:1.1 search_box_small.pt:1.1 workspace_add.py:1.1 object_list_rows.pt:1.2 workspace_remove.py:1.2 workspace_search_results.pt:1.2 workspace_view.pt:1.4

Shane Hathaway shane@cvs.zope.org
Wed, 22 May 2002 16:40:55 -0400


Update of /cvs-repository/CMF/CMFWorkspaces/skins/workspaces
In directory cvs.zope.org:/tmp/cvs-serv18295

Modified Files:
	object_list_rows.pt workspace_remove.py 
	workspace_search_results.pt workspace_view.pt 
Added Files:
	search_box_results.pt search_box_results_batch.py 
	search_box_small.pt workspace_add.py 
Log Message:
Got workspace add/remove, search, sorting, and batching working.


=== Added File CMF/CMFWorkspaces/skins/workspaces/search_box_results.pt ===
<html metal:use-macro="here/main_template/macros/master">
<head>
  <title tal:content="template/title">The title</title>
</head>
<body>

<div metal:fill-slot="main">

<div metal:define-macro="block"
     tal:define="batch_info batch_info | python: 
                 here.search_box_results_batch(request)">

<p>
 Items <span tal:content="batch_info/b_start">1</span>-<span
 tal:content="batch_info/b_end">20</span> of <span
 tal:content="batch_info/total">85</span>
</p>

<table tal:define="items batch_info/batch">
<tbody metal:use-macro="here/object_list_rows/macros/tbody">
<tr><td>Results</td></tr>
</tbody>

  <tr tal:condition="not:items">
    <td colspan="5"><em>No matching items found.</em></td>
  </tr>
</table>

<p>
 <a href="" tal:define="p batch_info/prev_url" tal:condition="p"
    tal:attributes="href p">Previous items</a>
 &nbsp;
 <a href="" tal:define="n batch_info/next_url" tal:condition="n"
    tal:attributes="href n">Next items</a>
</p>

</div>
</div>
</body>
</html>


=== Added File CMF/CMFWorkspaces/skins/workspaces/search_box_results_batch.py ===
##parameters=request=None
##title=Pre-process form variables and return a batch of catalog query results.
##
if request is None:
    request = container.REQUEST

query = request.form.copy()
for key, value in query.items():
    if not value:
        del query[key]

if query.get('creation_from_date') and query.get('creation_to_date'):
    query['CreationDate'] = {
        'query': [query['creation_from_date'],
                  query['creation_to_date']],
        'range': 'min:max'}

if query.get('Subject'):
    q = filter(None, query['Subject'])
    if not q:
        del query['Subject']
    else:
        query['Subject'] = q

results = context.portal_catalog(query)

total = len(results)
b_start = int(request.get('b_start', 1))
b_count = int(request.get('b_count', 20))
b_end = b_start + b_count - 1

from ZTUtils import make_query
url = request['URL']

if b_end >= total:
    b_end = total
if b_start > 1:
    n = b_start - b_count
    if n < 1:
        n = 1
    prev_url = '%s?%s' % (url, make_query(request.form, b_start=n))
else:
    prev_url = ''
if b_end < total:
    n = b_end + 1
    next_url = '%s?%s' % (url, make_query(request.form, b_start=n))
else:
    next_url = ''

batch = []
for item in results[b_start - 1:b_end]:
    batch.append((item.getPath(), item.getObject()))

return {
    'batch': batch,
    'total': total,
    'b_start': b_start,
    'b_end': b_end,
    'prev_url': prev_url,
    'next_url': next_url,
    }


=== Added File CMF/CMFWorkspaces/skins/workspaces/search_box_small.pt ===
<html>
<body>

<form action="search_box_results" method="GET">

<table>
<thead>
<tr>
  <td align="left" colspan="2">
    <strong tal:content="title|default">Find...</strong>
  </td>
</tr>
</thead>

<!--
  tbody is a page fragment used to find objects and add them to something.
  Parameters expected to exist in the local namespace:
    title (optional)
    type_constraints (optional)
-->


<tbody metal:define-macro="tbody">

<tr tal:condition="exists:type_constraints">
  <td>
    <input type="hidden" name="Type:list" tal:repeat="type type_constraints"
           tal:attributes="value type" />
  </td>
</tr>
<tr tal:condition="not:exists:type_constraints">
  <td>Type</td>
  <td>
    <select name="Type">
     <option value="">(any)</option>
     <option tal:repeat="type python:
               here.portal_catalog.uniqueValuesFor('Type')"
             tal:attributes="value type"
             tal:content="type">Type</option>
    </select>
  </td>
</tr>
<tr>
  <td>
    Containing text
  </td>
  <td>
    <input type="text" name="SearchableText" size="60" />
  </td>
</tr>

<tr>
 <td colspan="2">
  <table width="100%" id="advanced_search" style="display: none">
   <tr>
     <td>
       Creator
     </td>
     <td>
       <input type="text" name="Creator" size="20" />
     </td>
   </tr>
   <tr>
     <td>
       Creation date
     </td>
     <td>
       from <input type="text" name="creation_from_date" value="2000-01-01" />
         to
         <input type="text" name="creation_to_date" value="2036-12-31"
                tal:attributes="value python:
                                DateTime().Date().replace('/', '-')" />
       <br />
     </td>
   </tr>
   <tr>
    <td>
     Keywords
    </td>
    <td tal:define="items python:
                    here.portal_catalog.uniqueValuesFor('Subject')">
     <select name="Subject:list" multiple size="5">
      <option value="" selected>(any)</option>
      <option value="" tal:repeat="item items"
                       tal:attributes="value item"
                       tal:content="item">
      </option>
     </select>
    </td>
   </tr>
  </table>
 </td>
</tr>

<script type="text/javascript"><!--

function toggleAdvanced() {
  elem = document.getElementById('advanced_search');
  elem2 = document.getElementById('advanced_button');
  if (elem.style.display == 'none') {
    elem.style.display='block';
    elem2.value = 'Simple Search <<';
  }
  else {
    elem.style.display='none';
    elem2.value = 'Advanced Search >>';
  }
}

// --></script>

<tr>
  <td colspan="2">

    <input type="submit" name="submit" value="Find" />
    <input type="submit" name="advanced" id="advanced_button"
           value="Advanced Search >>"
           onClick="toggleAdvanced(); return false;" />

  </td>
</tr>
</tbody>
</table>

</form>

</body>
</html>


=== Added File CMF/CMFWorkspaces/skins/workspaces/workspace_add.py ===
##parameters=selected_items=(), RESPONSE=None
##title=Add listed paths to a workspace.

count = 0
for path in selected_items:
    object = context.restrictedTraverse(path)
    context.addReference(object)
    count += 1

if count == 1:
    message = "Added+1+reference."
else:
    message = "Added+%d+references." % count

if RESPONSE is not None:
    RESPONSE.redirect("%s/%s?portal_status_message=%s" %
                      (context.absolute_url(),
                       'workspace_view',
                       message))


=== CMF/CMFWorkspaces/skins/workspaces/object_list_rows.pt 1.1 => 1.2 ===
 <tbody metal:define-macro="tbody"
        tal:define="my_url python: request['URL'] + '?';
-                   mq python: modules['ZTUtils'].make_query">
+       mq python: modules['ZTUtils'].make_query;
+       sort_on sort_on | python: request.get('sort_on', 'Title');
+       sort_order sort_order | python: request.get('sort_order', 'normal');">
       <tr>
         <th width="1%"> </th>
-        <th nowrap width="5%"></th>
+        <th nowrap="nowrap" width="5%"></th>
         <th tal:repeat="column python: ['Title', 'Type', 'CreationDate']"
             tal:attributes="width python:
-                            column == 'Title' and '50%' or default">
-          <a href="" tal:omit-tag="python: sort_attr == column"
+                            column == 'Title' and '50%' or default"
+            align="left">
+          <a href="" tal:omit-tag="python: sort_on == column"
              tal:attributes="href python: my_url + 
-             mq(request.form, sort_attr=column, sort_order='normal')"
+             mq(request.form, sort_on=column, sort_order='normal')"
              tal:content="column">Title</a>
-          <a href="" tal:condition="python: sort_attr == column"
+          <a href="" tal:condition="python: sort_on == column"
              tal:attributes="href python: my_url + mq(request.form,
-             sort_attr=column, sort_order=(sort_order == 'normal'
+             sort_on=column, sort_order=(sort_order == 'normal'
              and 'reverse' or 'normal'))"><img border="0"
              src="sorted_down.gif" tal:attributes="src
              python: '%s/%s' % (here.portal_url(), sort_order == 'normal'
@@ -25,7 +28,7 @@
       </tr>
 
       <tr tal:repeat="it items">
-<tal:block define="item python:it[1]">
+       <tal:block define="item python:it[1]">
         <td><img tal:define="status_image item/get_status_image | nothing"
                tal:condition="status_image"
                tal:replace="structure status_image"
@@ -46,17 +49,17 @@
               TITLE or ID </a>
         </td>
 
-        <td tal:content="item/Type"
+        <td tal:content="item/Type" nowrap="nowrap"
             tal:on-error="string:(unknown)">
           Type
         </td>
 
-        <td tal:content="item/CreationDate"
+        <td tal:content="item/CreationDate" nowrap="nowrap"
             tal:on-error="string:(unknown)">
           CreationDate
         </td>
 
-</tal:block>
+       </tal:block>
       </tr>
 </tbody>
 </table>


=== CMF/CMFWorkspaces/skins/workspaces/workspace_remove.py 1.1.1.1 => 1.2 ===
+##parameters=selected_items=(), RESPONSE=None
 ##title=Remove listed references from workspace.
 
-message = "No items selected for removal"
-
 if selected_items:
 
-    missing = []
     plural = ""
 
     for rid in selected_items:
-        try:
-            context.remove_reference(rid)
-        except KeyError:
-            missing.append(rid)
-
-    if missing:
-        amt = len(selected_items) - len(missing)
-        plural = ((amt != 1) and "s") or ""
-        message = ("%s item%s removed %s targets not found"
-                   % (amt, plural, len(missing)))
-    else:
-        amt = len(selected_items)
-        plural = ((amt != 1) and "s") or ""
-        message = "%s item%s removed" % (len(selected_items), plural)
-
-container.do_next(context, message)
+        context.removeReference(rid)
 
+    amt = len(selected_items)
+    plural = ((amt != 1) and "s") or ""
+    message = "Removed+%s+reference%s." % (amt, plural)
+
+if RESPONSE is not None:
+    RESPONSE.redirect("%s/%s?portal_status_message=%s" %
+                      (context.absolute_url(),
+                       'workspace_view',
+                       message))


=== CMF/CMFWorkspaces/skins/workspaces/workspace_search_results.pt 1.1.1.1 => 1.2 ===
 
 <div metal:fill-slot="main"
-     tal:define="action string:workspace_add;
-                 cancel_action string:view;
-                 got here/get_collection_paths">
+     tal:define="batch_info python: here.search_box_results_batch(request)">
 
-<div metal:use-macro="here/search_box_results/macros/form">
+<form action="." method="POST" tal:attributes="action here/absolute_url">
+
+<div metal:use-macro="here/search_box_results/macros/block">
 Search results
 </div>
+
+<input type="submit" name="workspace_add:action" value="Add to workspace"
+       tal:condition="batch_info/total" />
+&nbsp;
+<input type="submit" name="workspace_view:action" value="Search again" />
+
+</form>
 
 </div>
 


=== CMF/CMFWorkspaces/skins/workspaces/workspace_view.pt 1.3 => 1.4 ===
   <form action="" method="POST"
         tal:attributes="action here/absolute_url"
-        tal:define="sort_attr python: request.get('sort_attr', 'Title');
+        tal:define="sort_on python: request.get('sort_on', 'Title');
            sort_order python: request.get('sort_order', 'normal');
-           items python: here.listReferencedItems(sort_attr, sort_order)">
+           items python: here.listReferencedItems(sort_on, sort_order)">
 
     <table tal:condition="items">
 
@@ -55,20 +55,23 @@
 
   </form>
 
+  <form action="." method="GET" tal:attributes="action
+        string:${here/absolute_url}/workspace_search_results">
 
-
-
-
-
-<!--
-  <div tal:define="
-       title string:Find additions to workspace...;
-       action string:${here/absolute_url}/workspace_search_results;">
-  <div metal:use-macro="here/search_box_simple/macros/search_box">
-    SEARCH FORM
-  </div>
-  </div>
--->
+   <table>
+    <thead>
+     <tr>
+      <th align="left" colspan="2">
+       Find additions to workspace...
+      </th>
+     </tr>
+    </thead>
+
+    <tbody metal:use-macro="here/search_box_small/macros/tbody">
+     <tr><td>Search form</td></tr>
+    </tbody>
+   </table>
+  </form>
 
 </div>
 </body>