Chargement des vignettes après coup pour les tables lumineuses.
authorBenoît Pin <pin@cri.ensmp.fr>
Thu, 28 Aug 2014 11:48:18 +0000 (13:48 +0200)
committerBenoît Pin <pin@cri.ensmp.fr>
Thu, 28 Aug 2014 11:48:18 +0000 (13:48 +0200)
skins/getLightboxPhotosInfos.py [new file with mode: 0644]
skins/lightbox_view.py
skins/photo_layout_macros.pt
skins/photo_lightbox_viewer.js
skins/portfolio_thumbnails_tail.py

diff --git a/skins/getLightboxPhotosInfos.py b/skins/getLightboxPhotosInfos.py
new file mode 100644 (file)
index 0000000..f5afc8c
--- /dev/null
@@ -0,0 +1,50 @@
+##parameters=lightbox, pho_start=None, batch_size=None
+from Products.CMFCore.utils import getToolByName
+from Products.Plinn.PloneMisc import Batch
+
+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()
+
+start = pho_start if pho_start is not None else 0
+brains = [uidh.getBrain(uid) for uid in context.uids]
+batch_size = batch_size if batch_size is not None else context.default_batch_size
+batch = Batch(brains, batch_size, start, quantumleap=1)
+
+lightboxUrl = lightbox.absolute_url()
+cart = sd.get('cart', None)
+
+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
+
+       d = {'href' : '%s/lightboxcontext/%s' % (lightboxUrl, 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)
+
+features = {}
+features['del'] = lambda b: '%s/remove_to_lightbox?uid=%s' % (lightboxUrl, b.cmf_uid)
+features['cart'] = lambda b : '%s/get_slide_buyable_items' % b.getURL()
+
+return {'infos' : infos,
+        'batch' : batch,
+        'features' : features}
\ No newline at end of file
index 562c115..2463656 100755 (executable)
@@ -69,5 +69,6 @@ options['batch'] = batch
 options['features'] = features
 options['buttons'] = buttons
 options['lightboxSelected'] = lightboxSelected
 options['features'] = features
 options['buttons'] = buttons
 options['lightboxSelected'] = lightboxSelected
+options['container_type'] = 'lightbox'
 
 return context.lightbox_view_template(**options)
 
 return context.lightbox_view_template(**options)
index c096822..68d9f1d 100644 (file)
               tal:content="structure python:'''
               new Lightbox(document.getElementById('lightbox'),
                            document.getElementById('lightbox_toolbar'),
               tal:content="structure python:'''
               new Lightbox(document.getElementById('lightbox'),
                            document.getElementById('lightbox_toolbar'),
-                           %s);
-                           ''' % ('true' if not batch.next else 'false')">
+                           %(complete)s,
+                           '%(container_type)s');
+                           ''' % {'complete' : 'true' if not batch.next else 'false',
+                                  'container_type' : options.get('container_type', 'portfolio')}">
       </script>
       <script type="text/javascript"
               tal:condition="dropable"
       </script>
       <script type="text/javascript"
               tal:condition="dropable"
                 var lb = document.getElementById('lightbox');
                 new Lightbox(lb,
                              document.getElementById('lightbox_toolbar'),
                 var lb = document.getElementById('lightbox');
                 new Lightbox(lb,
                              document.getElementById('lightbox_toolbar'),
-                             %(complete)s);
+                             %(complete)s,
+                             '%(container_type)s');
                 var uploadUrl = '%(putUrl)s';
                 var options = {'slideSize' : %(slideSize)d,
                                'thumbnailSize' : %(thumbnailSize)d};
                 var uploadUrl = '%(putUrl)s';
                 var options = {'slideSize' : %(slideSize)d,
                                'thumbnailSize' : %(thumbnailSize)d};
               ''' % {'putUrl' : '%s/put_upload' % here.absolute_url(),
                      'slideSize' : portal_object.slide_size,
                      'thumbnailSize' : portal_object.thumb_size,
               ''' % {'putUrl' : '%s/put_upload' % here.absolute_url(),
                      'slideSize' : portal_object.slide_size,
                      'thumbnailSize' : portal_object.thumb_size,
-                     'complete': 'true' if not batch.next else 'false'}">
+                     'complete': 'true' if not batch.next else 'false',
+                     'container_type' : options.get('container_type', 'portfolio')}">
       </script>
     </div>
     <div metal:define-macro="film_bar" tal:omit-tag="">
       </script>
     </div>
     <div metal:define-macro="film_bar" tal:omit-tag="">
index c649dc2..8dfbaf4 100644 (file)
@@ -11,12 +11,13 @@ var Lightbox;
 
 var reSelected = /.*selected.*/;
 
 
 var reSelected = /.*selected.*/;
 
-Lightbox = function(grid, toolbar, complete) {
+Lightbox = function(grid, toolbar, complete, container_type) {
        var self = this;
        this.grid = grid;
        this._buildSlidesIndex(); // set this.slides and this.lastSlide;
        this.fetchingDisabled = false;
        this.complete = complete;
        var self = this;
        this.grid = grid;
        this._buildSlidesIndex(); // set this.slides and this.lastSlide;
        this.fetchingDisabled = false;
        this.complete = complete;
+       this.container_type = container_type;
        this.toolbar = toolbar;
        if (toolbar) {
                this.toolbarFixed = false;
        this.toolbar = toolbar;
        if (toolbar) {
                this.toolbarFixed = false;
@@ -374,7 +375,9 @@ Lightbox.prototype.fetchTail = function() {
        var url = absolute_url() +
                          '/portfolio_thumbnails_tail?start:int=' +
                          String(this.slides.length) +
        var url = absolute_url() +
                          '/portfolio_thumbnails_tail?start:int=' +
                          String(this.slides.length) +
-                         '&size:int=10';
+                         '&size:int=10' +
+                         '&container_type=' +
+                         this.container_type;
        req.open('GET', url, true);
        req.send();
 };
        req.open('GET', url, true);
        req.send();
 };
index 4f47bf3..9765629 100644 (file)
@@ -1,6 +1,11 @@
-##parameters=start=0, size=10
+##parameters=start=0, size=10, container_type='portfolio'
 options={}
 options={}
-options.update(context.getPhotosInfos(context,
-                                      pho_start=start,
-                                      batch_size=size))
+if container_type == 'portfolio' :
+    options.update(context.getPhotosInfos(context,
+                                          pho_start=start,
+                                          batch_size=size))
+elif container_type == 'lightbox' :
+    options.update(context.getLightboxPhotosInfos(context,
+                                          pho_start=start,
+                                          batch_size=size))
 return context.portfolio_thumbnails_tail_template(**options)
\ No newline at end of file
 return context.portfolio_thumbnails_tail_template(**options)
\ No newline at end of file