From 255d239ccd0bc111e22faf03bc991da20357b6c7 Mon Sep 17 00:00:00 2001
From: Sebastien Robin <seb@nexedi.com>
Date: Thu, 26 Feb 2004 14:11:24 +0000
Subject: [PATCH] many updates so that we can do selection on many pages

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@519 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 .../skins/erp5_core/base_create_relation.py   |  4 +-
 .../skins/erp5_core/base_folder_delete.py     | 13 +++---
 .../ERP5/skins/erp5_core/base_list_dialog.py  |  3 +-
 .../skins/erp5_core/base_update_relation.py   | 43 +++++++++++++------
 product/ERP5/skins/erp5_core/folder_copy.py   | 21 ++++++---
 product/ERP5/skins/erp5_core/folder_cut.py    | 21 ++++++---
 product/ERP5/skins/erp5_core/folder_delete.py | 14 +++---
 .../ERP5/skins/erp5_core/update_relation.py   | 12 +++++-
 8 files changed, 88 insertions(+), 43 deletions(-)

diff --git a/product/ERP5/skins/erp5_core/base_create_relation.py b/product/ERP5/skins/erp5_core/base_create_relation.py
index 340c7295a2..a83ef5591d 100755
--- a/product/ERP5/skins/erp5_core/base_create_relation.py
+++ b/product/ERP5/skins/erp5_core/base_create_relation.py
@@ -3,7 +3,7 @@
 # Updates attributes of an Zope document
 # which is in a class inheriting from ERP5 Base
 
-
+sdmlkjsdmlkjfdsdfmlj()
 request=context.REQUEST
 
 o = context.portal_catalog.getObject(object_uid)
@@ -60,6 +60,8 @@ try:
     kw['portal_type'] = my_field.get_value('portal_type')
     request.set('base_category', base_category)
     request.set('portal_type', my_field.get_value('portal_type'))
+    request.set('form_id', 'search_relation')
+    request.set('form_toto', 'search_relation')
     request.set(my_field.get_value('catalog_index'), request.get( my_field.id, None))
     relation_list = context.portal_catalog(**kw)
     if len(relation_list) > 0:
diff --git a/product/ERP5/skins/erp5_core/base_folder_delete.py b/product/ERP5/skins/erp5_core/base_folder_delete.py
index d2c8c8d8a8..c553dcd70c 100755
--- a/product/ERP5/skins/erp5_core/base_folder_delete.py
+++ b/product/ERP5/skins/erp5_core/base_folder_delete.py
@@ -1,17 +1,18 @@
 ## Script (Python) "base_folder_delete"
 ##title=Delete objects from a folder
-##parameters=selection_index=None,form_id='',uids=None,ids=None,form_from=None
+##parameters=selection_index=None,form_id='',uids=[], listbox_uid=[],selection_name=''
 
 request=context.REQUEST
-selection_index=None
 
 #return uids
 
-#request.set('uid',uids)
-#request.set('reset',1)
-#request.set('portal_type','Tissu')
+selected_uids = context.portal_selections.updateSelectionCheckedUidList(selection_name,listbox_uid,uids)
+uids = context.portal_selections.getSelectionCheckedUidsFor(selection_name)
+
 
 kw = {'uid': uids}
 request.set('object_uid', context.getUid())
+request.set('uids', uids)
 context.portal_selections.setSelectionParamsFor('folder_delete_selection', kw)
-return context.folder_delete_view(REQUEST=request, uid=uids)
\ No newline at end of file
+#return context.folder_delete_view(REQUEST=request, uid=uids)
+return context.folder_delete_view(uids=uids, REQUEST=request)
diff --git a/product/ERP5/skins/erp5_core/base_list_dialog.py b/product/ERP5/skins/erp5_core/base_list_dialog.py
index 69f40cec09..bf6d89bdeb 100755
--- a/product/ERP5/skins/erp5_core/base_list_dialog.py
+++ b/product/ERP5/skins/erp5_core/base_list_dialog.py
@@ -26,7 +26,8 @@ if dialog_method == 'update_relation':
                               selection_name=selection_name,
                               selection_index=request.get('selection_index'),
                               object_uid=request.get('object_uid'),
-                              uids=request.get('uids'))
+                              uids=request.get('uids'),
+                              listbox_uid=request.get('listbox_uid'))
 if dialog_method == 'base_create_relation':
   return context.base_create_relation(form_id=form_id,
                               selection_name=selection_name,
diff --git a/product/ERP5/skins/erp5_core/base_update_relation.py b/product/ERP5/skins/erp5_core/base_update_relation.py
index 2e44245ba5..ccaeb76ee1 100755
--- a/product/ERP5/skins/erp5_core/base_update_relation.py
+++ b/product/ERP5/skins/erp5_core/base_update_relation.py
@@ -5,6 +5,8 @@
 
 
 from Products.Formulator.Errors import ValidationError, FormValidationError
+from cgi import escape
+from ZTUtils import make_query
 
 
 
@@ -15,6 +17,7 @@ request=context.REQUEST
 base_category = None
 
 o = context.portal_catalog.getObject(object_uid)
+redirect_url = None
 
 if o is None:
   return "Sorrry, Error, the calling object was not catalogued. Do not know how to do ?"
@@ -119,7 +122,20 @@ try:
                                     selection_name = selection_name,
                                     uids = uids,
                                     object_uid = object_uid)
-      return o.search_relation( REQUEST=request )
+      kw = {}
+      kw['form_id'] = 'search_relation'
+      kw['selection_index'] = selection_index
+      kw['object_uid'] = object_uid
+      kw['field_id'] = my_field.id
+      kw['portal_type'] = portal_type
+      kw['base_category'] = base_category
+      kw['selection_name'] = 'search_relation'
+      kw['cancel_url'] = request.get('HTTP_REFERER')
+      kw['previous_form_id'] = form_id
+      redirect_url = '%s/%s?%s' % ( o.absolute_url()
+                                , 'search_relation'
+                                , make_query(kw)
+                                )
     else:
       request.set('catalog_index', my_field.get_value('catalog_index'))
       if my_field.meta_type == 'MultiRelationStringField':
@@ -137,17 +153,18 @@ except FormValidationError, validation_errors:
 else:
   message = 'Relation+Unchanged.'
 
-if not selection_index:
-  redirect_url = '%s/%s?%s' % ( o.absolute_url()
-                            , form_id
-                            , 'portal_status_message=%s' % message
-                            )
-else:
-  redirect_url = '%s/%s?selection_index=%s&selection_name=%s&%s' % ( o.absolute_url()
-                            , form_id
-                            , selection_index
-                            , selection_name
-                            , 'portal_status_message=%s' % message
-                            )
+if redirect_url is None:
+  if not selection_index:
+    redirect_url = '%s/%s?%s' % ( o.absolute_url()
+                              , form_id
+                              , 'portal_status_message=%s' % message
+                              )
+  else:
+    redirect_url = '%s/%s?selection_index=%s&selection_name=%s&%s' % ( o.absolute_url()
+                              , form_id
+                              , selection_index
+                              , selection_name
+                              , 'portal_status_message=%s' % message
+                              )
 
 request[ 'RESPONSE' ].redirect( redirect_url )
diff --git a/product/ERP5/skins/erp5_core/folder_copy.py b/product/ERP5/skins/erp5_core/folder_copy.py
index 0a3334da73..60064103a3 100755
--- a/product/ERP5/skins/erp5_core/folder_copy.py
+++ b/product/ERP5/skins/erp5_core/folder_copy.py
@@ -1,11 +1,20 @@
-##parameters=form_id
+##parameters=form_id, uids=[], listbox_uid=[],selection_name=''
+
+selected_uids = context.portal_selections.updateSelectionCheckedUidList(selection_name,listbox_uid,uids)
+uids = context.portal_selections.getSelectionCheckedUidsFor(selection_name)
+# make sure nothing is checked after
+context.portal_selections.setSelectionCheckedUidsFor(selection_name, [])
+
 
 REQUEST=context.REQUEST
-if REQUEST.has_key('ids'):
-  context.manage_copyObjects(ids=REQUEST['ids'], REQUEST=REQUEST, RESPONSE=REQUEST.RESPONSE)
-  return REQUEST.RESPONSE.redirect(context.absolute_url() + '/' + form_id + '?portal_status_message=Item(s)+Copied.')
-elif REQUEST.has_key('uids'):
-  context.manage_copyObjects(uids=REQUEST['uids'], REQUEST=REQUEST, RESPONSE=REQUEST.RESPONSE)
+# Do we still needs ids ???
+#if REQUEST.has_key('ids'):
+#  context.manage_copyObjects(ids=REQUEST['ids'], REQUEST=REQUEST, RESPONSE=REQUEST.RESPONSE)
+#  return REQUEST.RESPONSE.redirect(context.absolute_url() + '/' + form_id + '?portal_status_message=Item(s)+Copied.')
+#elif REQUEST.has_key('uids'):
+if uids != []:
+  #context.manage_copyObjects(uids=REQUEST['uids'], REQUEST=REQUEST, RESPONSE=REQUEST.RESPONSE)
+  context.manage_copyObjects(uids=uids, REQUEST=REQUEST, RESPONSE=REQUEST.RESPONSE)
   return REQUEST.RESPONSE.redirect(context.absolute_url() + '/' + form_id + '?portal_status_message=Item(s)+Copied.')
 else:
   return REQUEST.RESPONSE.redirect(context.absolute_url() + '/' + form_id + '?portal_status_message=Please+select+one+or+more+items+to+copy+first.')
diff --git a/product/ERP5/skins/erp5_core/folder_cut.py b/product/ERP5/skins/erp5_core/folder_cut.py
index 0c603ddb37..6817ceff35 100755
--- a/product/ERP5/skins/erp5_core/folder_cut.py
+++ b/product/ERP5/skins/erp5_core/folder_cut.py
@@ -1,12 +1,21 @@
 ## Script (Python) "folder_cut"
 ##title=Cut objects from a folder and copy to the clipboard
-##parameters=
+##parameters=form_id,selection_name='',uids=[],listbox_uid=[]
+selected_uids = context.portal_selections.updateSelectionCheckedUidList(selection_name,listbox_uid,uids)
+uids = context.portal_selections.getSelectionCheckedUidsFor(selection_name)
+# make sure nothing is checked after
+context.portal_selections.setSelectionCheckedUidsFor(selection_name, [])
+
+
 REQUEST=context.REQUEST
-if REQUEST.has_key('ids'):
-  context.manage_cutObjects(REQUEST['ids'], REQUEST)
-  return REQUEST.RESPONSE.redirect(context.absolute_url() + '/' + form_id + '/folder_contents?portal_status_message=Item(s)+Cut.')
-elif REQUEST.has_key('uids'):
-  context.manage_cutObjects(uids=REQUEST['uids'], REQUEST=REQUEST)
+# do we still need ids ? XXX finish the work here
+#if REQUEST.has_key('ids'):
+#  context.manage_cutObjects(REQUEST['ids'], REQUEST)
+#  return REQUEST.RESPONSE.redirect(context.absolute_url() + '/' + form_id + '/folder_contents?portal_status_message=Item(s)+Cut.')
+#elif REQUEST.has_key('uids'):
+if uids != []:
+  #context.manage_cutObjects(uids=REQUEST['uids'], REQUEST=REQUEST)
+  context.manage_cutObjects(uids=uids, REQUEST=REQUEST)
   return REQUEST.RESPONSE.redirect(context.absolute_url() + '/' + form_id + '?portal_status_message=Item(s)+Cut.')
 else:
   return REQUEST.RESPONSE.redirect(context.absolute_url() + '/folder_contents?portal_status_message=Please+select+one+or+more+items+to+cut+first.')
diff --git a/product/ERP5/skins/erp5_core/folder_delete.py b/product/ERP5/skins/erp5_core/folder_delete.py
index cae4d2b812..e32a89fc3d 100755
--- a/product/ERP5/skins/erp5_core/folder_delete.py
+++ b/product/ERP5/skins/erp5_core/folder_delete.py
@@ -1,19 +1,17 @@
 ## Script (Python) "folder_delete"
 ##title=Delete objects from a folder
-##parameters=form_id='',selection_index=None,object_uid=None,selection_name=None,field_id=None,uids=None,cancel_url=''
+##parameters=form_id='',selection_index=None,object_uid=None,selection_name=None,field_id=None,uids=None,cancel_url='',listbox_uid=[]
+
+selected_uids = context.portal_selections.updateSelectionCheckedUidList(selection_name,listbox_uid,uids)
+uids = context.portal_selections.getSelectionCheckedUidsFor(selection_name)
 
-#return 'uids: %s, ids: %s' % (str(uids),str(ids))
-#return form_from
 
 REQUEST=context.REQUEST
+REQUEST.set('uids',uids)
 qs = ''
 ret_url = ''
 
-if REQUEST.has_key('ids') and (len(REQUEST['ids'])>0):
-  ret_url = context.absolute_url() + '/' + form_id
-  context.manage_delObjects(ids=REQUEST['ids'], REQUEST=REQUEST)
-  qs = '?portal_status_message=Deleted.'
-elif REQUEST.has_key('uids') and (len(REQUEST['uids'])>0):
+if REQUEST.has_key('uids') and (len(REQUEST['uids'])>0):
   ret_url = context.absolute_url() + '/' + form_id
   context.manage_delObjects(uids=REQUEST['uids'], REQUEST=REQUEST)
   qs = '?portal_status_message=Deleted.'
diff --git a/product/ERP5/skins/erp5_core/update_relation.py b/product/ERP5/skins/erp5_core/update_relation.py
index c3e0493eaa..7adb9c4d5d 100755
--- a/product/ERP5/skins/erp5_core/update_relation.py
+++ b/product/ERP5/skins/erp5_core/update_relation.py
@@ -1,4 +1,4 @@
-##parameters=form_id, field_id, selection_index, selection_name, uids, object_uid
+##parameters=form_id, field_id, selection_index, selection_name, uids, object_uid, listbox_uid
 
 # Updates attributes of an Zope document
 # which is in a class inheriting from ERP5 Base
@@ -13,12 +13,20 @@ o = context.portal_catalog.getObject(object_uid)
 if o is None:
   return "Sorrry, Error, the calling object was not catalogued. Do not know how to do ?"
 
+selected_uids = context.portal_selections.updateSelectionCheckedUidList(selection_name,listbox_uid,uids)
+uids = context.portal_selections.getSelectionCheckedUidsFor(selection_name)
+
+if request.has_key('previous_form_id'):
+  previous_form_id = request.get('previous_form_id')
+  if previous_form_id != '':
+    form_id = previous_form_id
+
 form = getattr(context, form_id)
 field = form.get_field(field_id)
 base_category = field.get_value('base_category')
 portal_type = map(lambda x:x[0],field.get_value('portal_type'))
 
-if uids:
+if uids != []:
   # Clear the relation
   o.setValueUids(base_category,  (), portal_type=portal_type)
   # Warning, portal type is at strange value because of form
-- 
2.30.9