Suppression des photos d'une table lumineuse par ajax.
[Portfolio.git] / skins / lightbox_view.py
1 ##parameters=
2 from Products.Portfolio.utils import translate
3 _ = lambda msg : translate(msg, context)
4 options = {}
5 buttons = []
6
7 sd = context.session_data_manager.getSessionData(create = 1)
8 path = context.getPhysicalPath()
9 req = context.REQUEST
10 form = req.form
11 fg = form.get
12
13 # check if lighbox is selected
14 sessionpath = sd.get('lightboxpath', None)
15 lightboxSelected = False
16 if sessionpath == path :
17 lightboxSelected = True
18 buttons.append({'name': 'unload', 'value': 'Unload from my selection'})
19 else :
20 buttons.append({'name':'load', 'value': 'Load in my selection'})
21
22 # form processing
23 if fg('load') :
24 sd.set('lightboxpath', path)
25 selection = context.getUidList()
26 sd.set('objects_selection', selection)
27 sd.set('objects_selection_dict', dict([(uid, True) for uid in selection]))
28
29 elif fg('unload') :
30 sd.set('lightboxpath', None)
31 sd.set('objects_selection', [])
32 sd.set('objects_selection_dict', {})
33
34 elif fg('delete.x') or form.has_key('delete') :
35 uids = fg('uids', [])
36 if not lightboxSelected :
37 for uid in [int(uid) for uid in uids] :
38 context.remove(uid)
39 else :
40 selection = sd.get('objects_selection', [])
41 selDict = sd.get('objects_selection_dict', {})
42 for uid in [int(uid) for uid in uids] :
43 context.remove(uid)
44 selection.remove(uid)
45 del selDict[uid]
46
47 sd['objects_selection'] = selection
48 sd['objects_selection_dict'] = selDict
49
50 # ui feedback message
51 if uids :
52 if len(uids) == 1 :
53 msg = _('Photo removed.')
54 else :
55 msg = _('Removed photos.')
56 else :
57 msg = _('Nothing to remove.')
58
59 if fg('ajax') :
60 context.REQUEST.RESPONSE.setHeader('Content-Type', 'text/xml;;charset=utf-8')
61 return '<deleted>%s</deleted>' % msg
62 else :
63 context.setStatus(True, msg)
64
65
66 options['buttons'] = buttons
67 options['lightboxSelected'] = lightboxSelected
68 options['container_type'] = 'lightbox'
69 options.update(context.getLightboxPhotosInfos(context))
70
71 return context.lightbox_view_template(**options)