X-Git-Url: https://scm.cri.ensmp.fr/git/Portfolio.git/blobdiff_plain/ce41148a886372e66942d71778d9e184eebc7fc0..9d15a219a1b6910463064c64f9c211c606b4b5eb:/skins/lightbox_view.py diff --git a/skins/lightbox_view.py b/skins/lightbox_view.py index 849f840..52df314 100755 --- a/skins/lightbox_view.py +++ b/skins/lightbox_view.py @@ -1,30 +1,70 @@ -##parameters=load='',unload='',**kw -from Products.CMFCore.utils import getToolByName -from Products.Plinn.PloneMisc import Batch +##parameters= +from Products.Portfolio.utils import translate +_ = lambda msg : translate(msg, context) options = {} -buttons = [] -lightboxSelected = False sd = context.session_data_manager.getSessionData(create = 1) path = context.getPhysicalPath() +req = context.REQUEST +form = req.form +fg = form.get -if load : - sd.set('lightboxpath', path) - selection = context.getUidList() - sd.set('objects_selection', selection) - sd.set('objects_selection_dict', dict([(uid, True) for uid in selection])) -elif unload : - sd.set('lightboxpath', None) - sd.set('objects_selection', []) - sd.set('objects_selection_dict', {}) - +# check if lighbox is selected sessionpath = sd.get('lightboxpath', None) +lightboxSelected = False if sessionpath == path : - lightboxSelected = True - buttons.append({'name': 'unload', 'value': 'Unload from my selection'}) -else : - buttons.append({'name':'load', 'value': 'Load in my selection'}) + lightboxSelected = True + +# form processing +if fg('load') : + sd.set('lightboxpath', path) + selection = context.getUidList() + sd.set('objects_selection', selection) + sd.set('objects_selection_dict', dict([(uid, True) for uid in selection])) + lightboxSelected = True +elif fg('unload') : + sd.set('lightboxpath', None) + sd.set('objects_selection', []) + sd.set('objects_selection_dict', {}) + lightboxSelected = False + +elif fg('delete.x') or form.has_key('delete') : + uids = fg('uids', []) + if not lightboxSelected : + for uid in [int(uid) for uid in uids] : + context.remove(uid) + else : + selection = sd.get('objects_selection', []) + selDict = sd.get('objects_selection_dict', {}) + for uid in [int(uid) for uid in uids] : + context.remove(uid) + selection.remove(uid) + del selDict[uid] + + sd['objects_selection'] = selection + sd['objects_selection_dict'] = selDict + + # ui feedback message + if uids : + if len(uids) == 1 : + msg = _('Photo removed.') + else : + msg = _('Removed photos.') + else : + msg = _('Nothing to remove.') + + if fg('ajax') : + context.REQUEST.RESPONSE.setHeader('Content-Type', 'text/xml;;charset=utf-8') + return '%s' % msg + else : + context.setStatus(True, msg) + +buttons=[] +if lightboxSelected : + buttons.append({'name': 'unload', 'value': 'Unload from my selection'}) +else : + buttons.append({'name':'load', 'value': 'Load in my selection'}) options['buttons'] = buttons options['lightboxSelected'] = lightboxSelected