2be413b48d26004cb6b22ceb6cdf4113169fcf52
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
16 mtool
= getToolByName(script
, 'portal_membership')
17 checkPermission
= mtool
.checkPermission
18 isAnon
= mtool
.isAnonymousUser()
19 utool
= getToolByName(script
, 'portal_url')
23 form
= context
.REQUEST
.form
24 default_target
= 'object/folderContents'
25 default_kw
= {'b_start': b_start
, 'key': key
, 'reverse': reverse
, 'ajax' : ajax
}
27 if ajax
: default_kw
['syncFragments']=['rightCell']
28 if context
.validateItemIds(**form
) and \
29 context
.folder_copy_control(**form
) and \
30 context
.setRedirect(context
, default_target
, **default_kw
):
33 if ajax
: default_kw
['syncFragments']=['rightCell']
34 if context
.validateItemIds(**form
) and \
35 context
.folder_cut_control(**form
) and \
36 context
.setRedirect(context
, default_target
, **default_kw
):
38 elif items_delete
and \
39 context
.validateItemIds(**form
) and \
40 context
.folder_delete_control(**form
) and \
41 context
.setRedirect(context
, default_target
, **default_kw
):
44 context
.setRedirect(context
, 'object/new', **default_kw
):
47 if ajax
: default_kw
['syncFragments']=['rightCell']
48 if context
.folder_paste_control(**form
) and \
49 context
.setRedirect(context
, default_target
, **default_kw
):
51 elif items_rename
and \
52 context
.validateItemIds(**form
) and \
53 context
.setRedirect(context
, 'object/rename_items', ids
=ids
,
57 context
.folder_sort_control(**form
) and \
58 context
.setRedirect(context
, default_target
, b_start
=b_start
):
61 context
.validateItemIds(**form
) and \
62 context
.folder_up_control(**form
) and \
63 context
.setRedirect(context
, default_target
, **default_kw
):
66 context
.validateItemIds(**form
) and \
67 context
.folder_down_control(**form
) and \
68 context
.setRedirect(context
, default_target
, **default_kw
):
71 context
.validateItemIds(**form
) and \
72 context
.folder_top_control(**form
) and \
73 context
.setRedirect(context
, default_target
, **default_kw
):
75 elif items_bottom
and \
76 context
.validateItemIds(**form
) and \
77 context
.folder_bottom_control(**form
) and \
78 context
.setRedirect(context
, default_target
, **default_kw
):
84 items_add_allowed
= checkPermission(AddPortalContent
, context
)
85 upitems_list_allowed
= checkPermission(ListFolderContents
, context
, 'aq_parent')
86 manage_props_allowed
= checkPermission(ManageProperties
, context
)
88 target
= context
.getActionInfo(default_target
)['url']
91 (key
, reverse
) = context
.getDefaultSorting()
93 elif (key
, reverse
) == context
.getDefaultSorting():
98 columns
= ( {'key': 'Type',
106 , {'key': 'modified',
107 'title': 'Last Modified',
112 for column
in columns
:
114 if key
== column
['key'] :
115 if not is_default
and manage_props_allowed
:
116 images
.append( {'src' : getattr(context
, 'set_default_sorting.gif').absolute_url(),
117 'alt' : 'Set Sorting as Default',
118 'id' : 'SetSortingAsDefault',
119 'href': '%s?%s' % (target
, make_query(items_sort
=True,
121 reverse
= (key
!= 'position' and [reverse
] or [False])[0] )
126 if key
!= 'position' :
128 toggleImg
= getattr(context
, 'arrowDown.gif')
129 alt
= 'descending sort'
131 toggleImg
= getattr(context
, 'arrowUp.gif')
132 alt
= 'ascending sort'
133 query
= make_query(key
=column
['key'], reverse
= not reverse
)
135 toggleImg
= getattr(context
, 'arrowUp.gif')
136 alt
= 'ascending sort'
137 query
= make_query(key
=column
['key'])
138 images
.append( {'src' : toggleImg
.absolute_url(), 'alt' : alt
} )
140 if key
!= 'position' :
141 query
= make_query(key
=column
['key'], reverse
= reverse
)
143 query
= make_query(key
=column
['key'])
145 column
['url'] = '%s?%s' % (target
, query
)
146 column
['images'] = images
148 context
.filterCookie()
149 folderfilter
= context
.REQUEST
.get('folderfilter', '')
150 filter = context
.decodeFolderFilter(folderfilter
)
151 items
= context
.listCatalogedContents(contentFilter
=filter)
152 sort_dir
= reverse
and 'desc' or 'asc'
153 sortFunc
= key
in ['Type'] and 'nocase' or 'cmp'
154 items
= sequence
.sort( items
, ((key
, sortFunc
, sort_dir
),) )
155 batch_obj
= Batch(items
, context
.default_batch_size
, b_start
, orphan
=0, quantumleap
=1)
157 display_delete_button
= not isAnon
# TODO : à revoir
158 for item
in batch_obj
:
159 item_icon
= item
.getIcon
161 item_url
= item
.getURL()
163 {'checkbox': not isAnon
,
164 'icon': item_icon
and ( '%s/%s' % (portal_url
, item_icon
) ) or '',
166 'modified': item
.modified
.strftime(locale_date_fmt
),
167 'title_or_id': item
.Title
or item_id
,
168 'type': item
.Type
or None,
171 options
['batch'] = { 'listColumnInfos': tuple(columns
),
172 'listItemInfos': tuple(items
),
173 'firstItemPos' : b_start
+ 1,
175 'sort_dir' : sort_dir
,
176 'batch_obj': batch_obj
}
179 for name
, value
in html_marshal(**default_kw
):
180 hidden_vars
.append( {'name': name
, 'value': value
} )
184 if items_add_allowed
and context
.allowedContentTypes():
185 buttons
.append( {'name': 'items_new', 'value': 'New...'} )
187 buttons
.append( {'name': 'items_rename', 'value': 'Rename'} )
189 if checkPermission(ViewManagementScreens
, context
) and items
:
190 buttons
.append( {'name': 'items_cut', 'value': 'Cut'} )
191 buttons
.append( {'name': 'items_copy', 'value': 'Copy'} )
193 if items_add_allowed
and context
.cb_dataValid():
194 buttons
.append( {'name': 'items_paste', 'value': 'Paste'} )
196 if display_delete_button
and items
:
197 buttons
.append( {'name': 'items_delete', 'value': 'Delete'} )
199 length
= batch_obj
.sequence_length
200 is_orderable
= manage_props_allowed
and (key
== 'position') and length
> 1
201 is_sortable
= manage_props_allowed
and not is_default
202 options
['form'] = { 'action': target
,
203 'listHiddenVarInfos': tuple(hidden_vars
),
204 'listButtonInfos': tuple(buttons
),
205 'is_orderable': is_orderable
,
206 'is_sortable': is_sortable
,
207 'items_add_allowed': items_add_allowed
}
208 if not ajax
and is_orderable
:
209 deltas
= range( 1, min(5, length
) ) + range(5, length
, 5)
210 options
['form']['listDeltas'] = tuple(deltas
)
212 if template
and macro
:
213 options
['template'] = template
214 options
['macro'] = macro
215 return context
.use_macro(**options
)
217 return context
.folder_contents_template(**options
)