Revert "Upload avec script adhoc."
[Plinn.git] / skins / custom_generic / folder_rename_form.py
1 ##parameters=b_start=0, key='', reverse=0, ids=(), new_ids=(), rename='', cancel='', ajax=''
2 ##
3 from Products.CMFCore.utils import getToolByName
4 from Products.CMFDefault.utils import html_marshal
5
6 utool = getToolByName(script, 'portal_url')
7 portal_url = utool()
8
9
10 form = context.REQUEST.form
11 default_kw = {'b_start': b_start, 'key': key, 'reverse': reverse}
12 if ajax :
13 default_kw.update({'ajax' : ajax})
14 if rename and \
15 context.folder_rename_control(**form) and \
16 context.setRedirect(context, 'object/folderContents', **default_kw):
17 return
18 elif cancel and \
19 context.setRedirect(context, 'object/folderContents', **default_kw):
20 return
21
22
23 options = {}
24
25 c = context.aq_explicit
26 raw_items = [ getattr(c, id) for id in ids if hasattr(c, id) ]
27 raw_items = [ item for item in raw_items if item.cb_isMoveable() ]
28 items = []
29 for item in raw_items:
30 item_icon = item.getIcon(1)
31 items.append( { 'icon': item_icon and ( '%s/%s' % (portal_url, item_icon) ) or '',
32 'id': item.getId(),
33 'title': item.Title(),
34 'type': item.Type() or None } )
35 options['batch'] = { 'listItemInfos': tuple(items) }
36
37 target = context.getActionInfo('object/rename_items')['url']
38 hidden_vars = []
39 default_kw.pop('ajax', None)
40 for name, value in html_marshal(**default_kw):
41 hidden_vars.append( {'name': name, 'value': value} )
42 buttons = []
43 buttons.append( {'name': 'rename', 'value': 'Rename'} )
44 buttons.append( {'name': 'cancel', 'value': 'Cancel'} )
45 options['form'] = { 'action': target,
46 'listHiddenVarInfos': tuple(hidden_vars),
47 'listButtonInfos': tuple(buttons) }
48
49 return context.folder_rename_template(**options)