1 ##parameters=b_start=0, key='', reverse=0, ids=(), items_copy='', items_cut='', items_delete='', items_new='', items_paste='', items_rename='', items_up='', items_down='', items_top='', items_bottom='', items_sort='', template='', macro='', ajax='',**others
3 from Products
.Plinn
.PloneMisc
import Batch
4 from DateTime
import DateTime
5 locale_date_fmt
= context
.locale_date_fmt()
6 from ZTUtils
import make_query
7 from Products
.CMFCore
.utils
import getToolByName
8 from Products
.CMFDefault
.permissions
import AddPortalContent
9 from Products
.CMFDefault
.permissions
import DeleteObjects
10 from Products
.CMFDefault
.permissions
import ListFolderContents
11 from Products
.CMFDefault
.permissions
import ManageProperties
12 from Products
.CMFDefault
.permissions
import ViewManagementScreens
13 from Products
.CMFDefault
.permissions
import ModifyPortalContent
14 from Products
.CMFDefault
.utils
import html_marshal
16 mtool
= getToolByName(script
, 'portal_membership')
17 checkPermission
= mtool
.checkPermission
18 utool
= getToolByName(script
, 'portal_url')
22 form
= context
.REQUEST
.form
23 default_target
= 'object/folderContents'
24 default_kw
= {'b_start': b_start
, 'key': key
, 'reverse': reverse
, 'ajax' : ajax
}
26 if ajax
: default_kw
['syncFragments']=['rightCell']
27 if context
.validateItemIds(**form
) and \
28 context
.folder_copy_control(**form
) and \
29 context
.setRedirect(context
, default_target
, **default_kw
):
32 if ajax
: default_kw
['syncFragments']=['rightCell']
33 if context
.validateItemIds(**form
) and \
34 context
.folder_cut_control(**form
) and \
35 context
.setRedirect(context
, default_target
, **default_kw
):
37 elif items_delete
and \
38 context
.validateItemIds(**form
) and \
39 context
.folder_delete_control(**form
) and \
40 context
.setRedirect(context
, default_target
, **default_kw
):
43 context
.setRedirect(context
, 'object/new', **default_kw
):
46 if ajax
: default_kw
['syncFragments']=['rightCell']
47 if context
.folder_paste_control(**form
) and \
48 context
.setRedirect(context
, default_target
, **default_kw
):
50 elif items_rename
and \
51 context
.validateItemIds(**form
) and \
52 context
.setRedirect(context
, 'object/rename_items', ids
=ids
,
56 context
.folder_sort_control(**form
) and \
57 context
.setRedirect(context
, default_target
, b_start
=b_start
):
60 context
.validateItemIds(**form
) and \
61 context
.folder_up_control(**form
) and \
62 context
.setRedirect(context
, default_target
, **default_kw
):
65 context
.validateItemIds(**form
) and \
66 context
.folder_down_control(**form
) and \
67 context
.setRedirect(context
, default_target
, **default_kw
):
70 context
.validateItemIds(**form
) and \
71 context
.folder_top_control(**form
) and \
72 context
.setRedirect(context
, default_target
, **default_kw
):
74 elif items_bottom
and \
75 context
.validateItemIds(**form
) and \
76 context
.folder_bottom_control(**form
) and \
77 context
.setRedirect(context
, default_target
, **default_kw
):
83 items_add_allowed
= checkPermission(AddPortalContent
, context
)
84 upitems_list_allowed
= checkPermission(ListFolderContents
, context
, 'aq_parent')
85 manage_props_allowed
= checkPermission(ManageProperties
, context
)
87 # information pour remonter au dossier parent
89 if upitems_list_allowed
:
90 up_obj
= context
.aq_parent
91 if hasattr(up_obj
, 'portal_url'):
92 up_url
= up_obj
.getActionInfo('object/folderContents')['url']
93 up_info
= { 'icon': '%s/UpFolder_icon.gif' % portal_url
,
97 up_info
= { 'icon': '',
100 options
['up_info'] = up_info
102 target
= context
.getActionInfo(default_target
)['url']
105 (key
, reverse
) = context
.getDefaultSorting()
107 elif (key
, reverse
) == context
.getDefaultSorting():
112 columns
= ( {'key': 'Lock',
120 , {'key': 'title_or_id',
124 , {'key': 'modified',
125 'title': 'Last Modified',
128 , {'key': 'position',
134 for column
in columns
:
136 if key
== column
['key'] :
137 if not is_default
and manage_props_allowed
:
138 images
.append( {'src' : getattr(context
, 'set_default_sorting.gif').absolute_url(),
139 'alt' : 'Set Sorting as Default',
140 'id' : 'SetSortingAsDefault',
141 'href': '%s?%s' % (target
, make_query(items_sort
=True,
143 reverse
= (key
!= 'position' and [reverse
] or [False])[0] )
148 if key
!= 'position' :
150 toggleImg
= getattr(context
, 'arrowDown.gif')
151 alt
= 'descending sort'
153 toggleImg
= getattr(context
, 'arrowUp.gif')
154 alt
= 'ascending sort'
155 query
= make_query(key
=column
['key'], reverse
= not reverse
)
157 toggleImg
= getattr(context
, 'arrowUp.gif')
158 alt
= 'ascending sort'
159 query
= make_query(key
=column
['key'])
160 images
.append( {'src' : toggleImg
.absolute_url(), 'alt' : alt
} )
162 if key
!= 'position' :
163 query
= make_query(key
=column
['key'], reverse
= reverse
)
165 query
= make_query(key
=column
['key'])
167 column
['url'] = '%s?%s' % (target
, query
)
168 column
['images'] = images
170 context
.filterCookie()
171 folderfilter
= context
.REQUEST
.get('folderfilter', '')
172 filter = context
.decodeFolderFilter(folderfilter
)
173 items
= context
.listNearestFolderContents(contentFilter
=filter)
174 sort_dir
= reverse
and 'desc' or 'asc'
175 sortFunc
= key
in ['Type', 'title_or_id'] and 'nocase' or 'cmp'
176 items
= sequence
.sort( items
, ((key
, sortFunc
, sort_dir
),) )
177 batch_obj
= Batch(items
, 20, b_start
, orphan
=0, quantumleap
=1)
180 display_delete_button
= False
181 for item
in batch_obj
:
182 item_icon
= item
.getIcon(1)
183 item_id
= item
.getId()
184 item_position
= key
== 'position' and str(b_start
+ i
) or '...'
186 item_url
= item
.absolute_url()
187 try : item_delete_allowed
= context
.objectIdCanBeDeleted(item_id
)
188 except : item_delete_allowed
= checkPermission(DeleteObjects
, context
) # std zope perm
189 if not display_delete_button
:
190 display_delete_button
= item_delete_allowed
192 {'lock' : not checkPermission(ModifyPortalContent
, item
),
193 'checkbox': item_delete_allowed
and ('cb_%s' % item_id
) or '',
194 'icon': item_icon
and ( '%s/%s' % (portal_url
, item_icon
) ) or '',
196 'modified': item
.modified().strftime(locale_date_fmt
),
197 'position': item_position
,
198 'title_or_id': item
.title_or_id(),
199 'type': item
.Type() or None,
202 options
['batch'] = { 'listColumnInfos': tuple(columns
),
203 'listItemInfos': tuple(items
),
205 'sort_dir' : sort_dir
,
206 'batch_obj': batch_obj
}
209 for name
, value
in html_marshal(**default_kw
):
210 hidden_vars
.append( {'name': name
, 'value': value
} )
214 if items_add_allowed
and context
.allowedContentTypes():
215 buttons
.append( {'name': 'items_new', 'value': 'New...'} )
217 buttons
.append( {'name': 'items_rename', 'value': 'Rename'} )
219 if checkPermission(ViewManagementScreens
, context
) and items
:
220 buttons
.append( {'name': 'items_cut', 'value': 'Cut'} )
221 buttons
.append( {'name': 'items_copy', 'value': 'Copy'} )
223 if items_add_allowed
and context
.cb_dataValid():
224 buttons
.append( {'name': 'items_paste', 'value': 'Paste'} )
226 if display_delete_button
and items
:
227 buttons
.append( {'name': 'items_delete', 'value': 'Delete'} )
229 length
= batch_obj
.sequence_length
230 is_orderable
= manage_props_allowed
and (key
== 'position') and length
> 1
231 is_sortable
= manage_props_allowed
and not is_default
232 options
['form'] = { 'action': target
,
233 'listHiddenVarInfos': tuple(hidden_vars
),
234 'listButtonInfos': tuple(buttons
),
235 'is_orderable': is_orderable
,
236 'is_sortable': is_sortable
}
237 if not ajax
and is_orderable
:
238 deltas
= range( 1, min(5, length
) ) + range(5, length
, 5)
239 options
['form']['listDeltas'] = tuple(deltas
)
241 if template
and macro
:
242 options
['template'] = template
243 options
['macro'] = macro
244 return context
.use_macro(**options
)
246 options
.update(others
)
247 return context
.folder_contents_template(**options
)