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=''
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
#, Message as _
15 from Products
.Plinn
.utils
import Message
as _
17 mtool
= getToolByName(script
, 'portal_membership')
18 checkPermission
= mtool
.checkPermission
19 isAnon
= mtool
.isAnonymousUser()
20 utool
= getToolByName(script
, 'portal_url')
24 form
= context
.REQUEST
.form
25 default_target
= 'object/folderContents'
26 default_kw
= {'b_start': b_start
, 'key': key
, 'reverse': reverse
, 'ajax' : ajax
}
28 if ajax
: default_kw
['syncFragments']=['rightCell']
29 if context
.validateItemIds(**form
) and \
30 context
.folder_copy_control(**form
) and \
31 context
.setRedirect(context
, default_target
, **default_kw
):
34 if ajax
: default_kw
['syncFragments']=['rightCell']
35 if context
.validateItemIds(**form
) and \
36 context
.folder_cut_control(**form
) and \
37 context
.setRedirect(context
, default_target
, **default_kw
):
39 elif items_delete
and \
40 context
.validateItemIds(**form
) and \
41 context
.folder_delete_control(**form
) and \
42 context
.setRedirect(context
, default_target
, **default_kw
):
45 context
.setRedirect(context
, 'object/new', **default_kw
):
48 if ajax
: default_kw
['syncFragments']=['rightCell']
49 if context
.folder_paste_control(**form
) and \
50 context
.setRedirect(context
, default_target
, **default_kw
):
52 elif items_rename
and \
53 context
.validateItemIds(**form
) and \
54 context
.setRedirect(context
, 'object/rename_items', ids
=ids
,
58 context
.folder_sort_control(**form
) and \
59 context
.setRedirect(context
, default_target
, b_start
=b_start
):
62 context
.validateItemIds(**form
) and \
63 context
.folder_up_control(**form
) and \
64 context
.setRedirect(context
, default_target
, **default_kw
):
67 context
.validateItemIds(**form
) and \
68 context
.folder_down_control(**form
) and \
69 context
.setRedirect(context
, default_target
, **default_kw
):
72 context
.validateItemIds(**form
) and \
73 context
.folder_top_control(**form
) and \
74 context
.setRedirect(context
, default_target
, **default_kw
):
76 elif items_bottom
and \
77 context
.validateItemIds(**form
) and \
78 context
.folder_bottom_control(**form
) and \
79 context
.setRedirect(context
, default_target
, **default_kw
):
85 items_add_allowed
= checkPermission(AddPortalContent
, context
)
86 upitems_list_allowed
= checkPermission(ListFolderContents
, context
, 'aq_parent')
87 manage_props_allowed
= checkPermission(ManageProperties
, context
)
89 target
= context
.getActionInfo(default_target
)['url']
92 (key
, reverse
) = context
.getDefaultSorting()
94 elif (key
, reverse
) == context
.getDefaultSorting():
99 columns
= ( {'key': 'Type',
107 , {'key': 'modified',
108 'title': _('Last Modified'),
111 , {'key': 'review_state',
117 for column
in columns
:
119 if key
== column
['key'] :
120 if not is_default
and manage_props_allowed
:
121 images
.append( {'src' : getattr(context
, 'set_default_sorting.gif').absolute_url(),
122 'alt' : _('Set Sorting as Default'),
123 'id' : 'SetSortingAsDefault',
124 'href': '%s?%s' % (target
, make_query(items_sort
=True,
126 reverse
= (key
!= 'position' and [reverse
] or [False])[0] )
131 if key
!= 'position' :
133 toggleImg
= getattr(context
, 'arrowDown.gif')
134 alt
= 'descending sort'
136 toggleImg
= getattr(context
, 'arrowUp.gif')
137 alt
= 'ascending sort'
138 query
= make_query(key
=column
['key'], reverse
= not reverse
)
140 toggleImg
= getattr(context
, 'arrowUp.gif')
141 alt
= 'ascending sort'
142 query
= make_query(key
=column
['key'])
143 images
.append( {'src' : toggleImg
.absolute_url(), 'alt' : alt
} )
145 if key
!= 'position' :
146 query
= make_query(key
=column
['key'], reverse
= reverse
)
148 query
= make_query(key
=column
['key'])
150 column
['url'] = '%s?%s' % (target
, query
)
151 column
['images'] = images
153 context
.filterCookie()
154 folderfilter
= context
.REQUEST
.get('folderfilter', '')
155 filter = context
.decodeFolderFilter(folderfilter
)
156 items
= context
.listCatalogedContents(contentFilter
=filter)
157 sort_dir
= reverse
and 'desc' or 'asc'
158 sortFunc
= key
in ['Type'] and 'nocase' or 'cmp'
159 items
= sequence
.sort( items
, ((key
, sortFunc
, sort_dir
),) )
160 batch_obj
= Batch(items
, context
.default_batch_size
, b_start
, orphan
=0, quantumleap
=1)
162 display_delete_button
= not isAnon
# TODO : à revoir
163 for item
in batch_obj
:
164 item_icon
= item
.getIcon
166 item_url
= item
.getURL()
168 {'checkbox': not isAnon
,
169 'icon': item_icon
and ( '%s/%s' % (portal_url
, item_icon
) ) or '',
171 'modified': item
.modified
.strftime(locale_date_fmt
),
172 'title_or_id': item
.Title
or item_id
,
173 'type': item
.Type
or None,
174 'state': item
.review_state
,
177 options
['batch'] = { 'listColumnInfos': tuple(columns
),
178 'listItemInfos': tuple(items
),
179 'firstItemPos' : b_start
+ 1,
181 'sort_dir' : sort_dir
,
182 'batch_obj': batch_obj
}
185 for name
, value
in html_marshal(**default_kw
):
186 hidden_vars
.append( {'name': name
, 'value': value
} )
190 if items_add_allowed
and context
.allowedContentTypes():
191 buttons
.append( {'name': 'items_new', 'value': 'New...'} )
193 buttons
.append( {'name': 'items_rename', 'value': 'Rename'} )
195 if checkPermission(ViewManagementScreens
, context
) and items
:
196 buttons
.append( {'name': 'items_cut', 'value': 'Cut'} )
197 buttons
.append( {'name': 'items_copy', 'value': 'Copy'} )
199 if items_add_allowed
and context
.cb_dataValid():
200 buttons
.append( {'name': 'items_paste', 'value': 'Paste'} )
202 if display_delete_button
and items
:
203 buttons
.append( {'name': 'items_delete', 'value': 'Delete'} )
205 length
= batch_obj
.sequence_length
206 is_orderable
= manage_props_allowed
and (key
== 'position') and length
> 1
207 is_sortable
= manage_props_allowed
and not is_default
208 options
['form'] = { 'action': target
,
209 'listHiddenVarInfos': tuple(hidden_vars
),
210 'listButtonInfos': tuple(buttons
),
211 'is_orderable': is_orderable
,
212 'is_sortable': is_sortable
,
213 'items_add_allowed': items_add_allowed
}
214 if not ajax
and is_orderable
:
215 deltas
= range( 1, min(5, length
) ) + range(5, length
, 5)
216 options
['form']['listDeltas'] = tuple(deltas
)
218 if template
and macro
:
219 options
['template'] = template
220 options
['macro'] = macro
221 return context
.use_macro(**options
)
223 return context
.folder_contents_template(**options
)