e0bc4d839a8030d73a4b5bf9a39618630f074b50
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 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 target
= context
.getActionInfo(default_target
)['url']
90 (key
, reverse
) = context
.getDefaultSorting()
92 elif (key
, reverse
) == context
.getDefaultSorting():
97 columns
= ( {'key': 'Lock',
109 , {'key': 'modified',
110 'title': 'Last Modified',
113 , {'key': 'position',
119 for column
in columns
:
121 if key
== column
['key'] :
122 if not is_default
and manage_props_allowed
:
123 images
.append( {'src' : getattr(context
, 'set_default_sorting.gif').absolute_url(),
124 'alt' : 'Set Sorting as Default',
125 'id' : 'SetSortingAsDefault',
126 'href': '%s?%s' % (target
, make_query(items_sort
=True,
128 reverse
= (key
!= 'position' and [reverse
] or [False])[0] )
133 if key
!= 'position' :
135 toggleImg
= getattr(context
, 'arrowDown.gif')
136 alt
= 'descending sort'
138 toggleImg
= getattr(context
, 'arrowUp.gif')
139 alt
= 'ascending sort'
140 query
= make_query(key
=column
['key'], reverse
= not reverse
)
142 toggleImg
= getattr(context
, 'arrowUp.gif')
143 alt
= 'ascending sort'
144 query
= make_query(key
=column
['key'])
145 images
.append( {'src' : toggleImg
.absolute_url(), 'alt' : alt
} )
147 if key
!= 'position' :
148 query
= make_query(key
=column
['key'], reverse
= reverse
)
150 query
= make_query(key
=column
['key'])
152 column
['url'] = '%s?%s' % (target
, query
)
153 column
['images'] = images
155 context
.filterCookie()
156 folderfilter
= context
.REQUEST
.get('folderfilter', '')
157 filter = context
.decodeFolderFilter(folderfilter
)
158 items
= context
.listCatalogedContents(contentFilter
=filter)
159 sort_dir
= reverse
and 'desc' or 'asc'
160 sortFunc
= key
in ['Type'] and 'nocase' or 'cmp'
161 items
= sequence
.sort( items
, ((key
, sortFunc
, sort_dir
),) )
162 batch_obj
= Batch(items
, context
.default_batch_size
, b_start
, orphan
=0, quantumleap
=1)
165 display_delete_button
= True # TODO : à revoirs
166 for item
in batch_obj
:
167 item_icon
= item
.getIcon
169 item_position
= key
== 'position' and str(b_start
+ i
) or '...'
171 item_url
= item
.getURL()
172 #try : item_delete_allowed = context.objectIdCanBeDeleted(item_id)
173 #except : item_delete_allowed = checkPermission(DeleteObjects, context) # std zope perm
174 #if not display_delete_button :
175 # display_delete_button = item_delete_allowed
179 'icon': item_icon
and ( '%s/%s' % (portal_url
, item_icon
) ) or '',
181 'modified': item
.modified
.strftime(locale_date_fmt
),
182 'position': item_position
,
183 'title_or_id': item
.Title
or item_id
,
184 'type': item
.Type
or None,
187 options
['batch'] = { 'listColumnInfos': tuple(columns
),
188 'listItemInfos': tuple(items
),
190 'sort_dir' : sort_dir
,
191 'batch_obj': batch_obj
}
194 for name
, value
in html_marshal(**default_kw
):
195 hidden_vars
.append( {'name': name
, 'value': value
} )
199 if items_add_allowed
and context
.allowedContentTypes():
200 buttons
.append( {'name': 'items_new', 'value': 'New...'} )
202 buttons
.append( {'name': 'items_rename', 'value': 'Rename'} )
204 if checkPermission(ViewManagementScreens
, context
) and items
:
205 buttons
.append( {'name': 'items_cut', 'value': 'Cut'} )
206 buttons
.append( {'name': 'items_copy', 'value': 'Copy'} )
208 if items_add_allowed
and context
.cb_dataValid():
209 buttons
.append( {'name': 'items_paste', 'value': 'Paste'} )
211 if display_delete_button
and items
:
212 buttons
.append( {'name': 'items_delete', 'value': 'Delete'} )
214 length
= batch_obj
.sequence_length
215 is_orderable
= manage_props_allowed
and (key
== 'position') and length
> 1
216 is_sortable
= manage_props_allowed
and not is_default
217 options
['form'] = { 'action': target
,
218 'listHiddenVarInfos': tuple(hidden_vars
),
219 'listButtonInfos': tuple(buttons
),
220 'is_orderable': is_orderable
,
221 'is_sortable': is_sortable
}
222 if not ajax
and is_orderable
:
223 deltas
= range( 1, min(5, length
) ) + range(5, length
, 5)
224 options
['form']['listDeltas'] = tuple(deltas
)
226 if template
and macro
:
227 options
['template'] = template
228 options
['macro'] = macro
229 return context
.use_macro(**options
)
231 return context
.folder_contents_template(**options
)