-##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
-utool = getToolByName(context, 'portal_url')
-portal = utool.getPortalObject()
-portalDepth = len(portal.getPhysicalPath())
-uidh = getToolByName(context, 'portal_uidhandler')
-pptool = getToolByName(context, 'portal_photo_print', None)
-req = context.REQUEST
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'})
-start = req.get('b_start', 0)
-brains = [uidh.getBrain(uid) for uid in context.uids]
-batch = Batch(brains, 20, start, orphan=1, quantumleap=1)
+# 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]))
-hereUrl = context.absolute_url()
-cart = sd.get('cart', None)
+elif fg('unload') :
+ sd.set('lightboxpath', None)
+ sd.set('objects_selection', [])
+ sd.set('objects_selection_dict', {})
-infos = []
-for index, b in enumerate(batch) :
- path = '/'.join(b.getPath().split('/')[portalDepth:])
- p = b.getObject()
- if pptool :
- buyable = bool(pptool.getPrintingOptionsFor(p))
- if cart and cart.locked :
- buyable = False
- else :
- buyable = 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]
- d = {'href' : '%s/lightboxcontext/%s' % (hereUrl, path)
- ,'thumbUrl' : '%s/getThumbnail' % b.getURL()
- ,'thumbSize' : b.getThumbnailSize
- ,'title' : ('%s - %s' % (b.Title, b.Description)).strip(' -')
- ,'cmf_uid':b.cmf_uid
- ,'className':''
- ,'buyable' : buyable
- ,'o':b
- }
- infos.append(d)
+ 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 '<deleted>%s</deleted>' % msg
+ else :
+ context.setStatus(True, msg)
-features = {}
-features['del'] = lambda b: '%s/remove_to_lightbox?uid=%s' % (hereUrl, b.cmf_uid)
-features['cart'] = lambda b : '%s/get_slide_buyable_items' % b.getURL()
-options['infos'] = infos
-options['batch'] = batch
-options['features'] = features
options['buttons'] = buttons
options['lightboxSelected'] = lightboxSelected
+options['container_type'] = 'lightbox'
+options.update(context.getLightboxPhotosInfos(context))
return context.lightbox_view_template(**options)