Conjunto de mudanças 6584 no repositório publico


Ignorar:
Timestamp:
29/06/2012 20:25:43 (9 anos atrás)
Autor:
mazza
Mensagem:

generalizacao: agora podemos ter N carroseis

Localização:
PortalInterlegis/produtos/il.portalinterlegis/trunk/src/il/portalinterlegis
Arquivos:
6 editados

Legenda:

Não Modificado
Adicionado
Removido
  • PortalInterlegis/produtos/il.portalinterlegis/trunk/src/il/portalinterlegis/browser/boxes/carousel.py

    r6554 r6584  
    11# -*- coding: utf-8 -*-
     2from Products.CMFCore.permissions import ModifyPortalContent
    23from five import grok
    34from five.grok.components import ZopeTwoPageTemplate
    4 from interfaces import ICarouselItem
    55from persistent.list import PersistentList
    66from zope.interface import Interface
    77
     8from interfaces import ICarouselItem
    89from manager import BoxAware, Box, NUMBER_OF_PRE_CREATED_BOXES, get_template, BaseBox
    910
     
    1213    """General carousel manager, related to a context"""
    1314
    14     CAROUSEL_KEY = "carousel"
    15     NUMBERS_KEY = "numbers"
    16 
    17     def __init__(self, context):
     15    def __init__(self, number, context):
     16        self.number = number
    1817        self.context = context
    1918
     
    2524        boxes = [(number, Box(ICarouselItem, number)) for number in self.numbers]
    2625        return template.render(
     26            carousel_edit_href=carousel_edit_href(self.number),
    2727            items=[(number,
    2828                    box.get_data(self.context),
    2929                    box.edit_href) for number, box in boxes])
    3030
     31    # TODO: renomear isso para panels
    3132    @property
    3233    def numbers(self):
    33         data = self.get_box_data(self.context, self.CAROUSEL_KEY)
    34         return self.get_or_create_from_dict(data, self.NUMBERS_KEY, PersistentList)
     34        return self.get_box_data(self.context,
     35                                 "carousel_numbers_%s" % self.number,
     36                                 PersistentList)
    3537
    3638    def add_item(self):
    3739        numbers = self.numbers
    3840        for i in range(NUMBER_OF_PRE_CREATED_BOXES):
    39             if i not in numbers:
     41            if i not in numbers and Box(ICarouselItem, number).is_empty(self.context):
    4042                numbers.insert(0, i)
    4143                break
     
    5355
    5456
    55 class CarouselEditView(grok.View):
    56 
    57     EDIT_CAROUSEL = 'edit-carousel'
    58 
    59     grok.name(EDIT_CAROUSEL)
    60     grok.context(Interface)
    61     grok.require('cmf.ModifyPortalContent')
    62 
    63     template = ZopeTwoPageTemplate(filename="carouseledit.pt")
    64 
    65     def carousel(self):
    66         return self._carousel.render(edit_mode=True)
    67 
    68     def update(self, **kwargs):
    69         self._carousel = Carousel(self.context)
    70         if 'add' in self.request:
    71             self._carousel.add_item()
    72         elif 'remove' in self.request:
    73             self._carousel.remove_item(self.request['remove'])
    74         elif 'reorder' in self.request:
    75             self._carousel.reorder(self.request['reorder'])
    76     # TODO: ajustar o render para retornar apenas feedback de sucesso ou falha
    77 
    7857class CarouselBox(BaseBox):
    7958
    8059    id = 'carousel'
    81     edit_href = CarouselEditView.EDIT_CAROUSEL
    8260    is_link_overlay = False
    8361
     62    def __init__(self, number, permission=ModifyPortalContent):
     63        super(CarouselBox, self).__init__(permission)
     64        self.number = number
     65
    8466    def inner_render(self, context):
    85         return Carousel(context).render()
     67        return Carousel(self.number, context).render()
     68
     69    @property
     70    def edit_href(self):
     71        return carousel_edit_href(self.number)
     72
     73
     74def carousel_edit_href(number):
     75    return "carousel_edit_%s" % number
     76
     77def build_CarouselEditView(number):
     78
     79    class CarouselEditView(grok.View):
     80        grok.name(carousel_edit_href(number))
     81        grok.context(Interface)
     82        grok.require('cmf.ModifyPortalContent')
     83
     84        template = ZopeTwoPageTemplate(filename="carouseledit.pt")
     85        number = number
     86
     87        def carousel(self):
     88            return self._carousel.render(edit_mode=True)
     89
     90        def update(self, **kwargs):
     91            self._carousel = Carousel(self.number, self.context)
     92            if 'add' in self.request:
     93                self._carousel.add_item()
     94            elif 'remove' in self.request:
     95                self._carousel.remove_item(self.request['remove'])
     96            elif 'reorder' in self.request:
     97                self._carousel.reorder(self.request['reorder'])
     98
     99    globals()['CarouselEditView_%s' % number] = CarouselEditView
     100
     101# XXX: one more elaborated POG, to avoid complex traversals
     102for number in range(8):
     103    build_CarouselEditView(number)
     104
  • PortalInterlegis/produtos/il.portalinterlegis/trunk/src/il/portalinterlegis/browser/boxes/manager.py

    r6559 r6584  
    3131    ALL_BOXES_KEY = 'il.portalinterlegis.boxes'
    3232
    33     def get_box_data(self, context, key):
     33    def has_box_data(self, context, key):
     34        annotations = IAnnotations(context)
     35        return self.ALL_BOXES_KEY in annotations \
     36          and key in annotations[self.ALL_BOXES_KEY]
     37
     38    def get_box_data(self, context, key, type_to_create=PersistentDict):
    3439        annotations = IAnnotations(context)
    3540        boxes = self.get_or_create_from_dict(annotations, self.ALL_BOXES_KEY)
    36         return self.get_or_create_from_dict(boxes, key)
     41        return self.get_or_create_from_dict(boxes, key, type_to_create)
    3742
    3843    def erase_box_data(self, context, key):
     
    102107    def erase_data(self, context):
    103108        self.erase_box_data(context, self.id)
     109
     110    def is_empty(self, context):
     111        return not self.has_box_data(context, self.id)
    104112
    105113    @property
     
    144152    return BoxEditForm
    145153
    146 
     154# TODO: This is first class POG. Has to be eliminated someday
    147155def build_many_box_forms(schema, max_number):
    148156    for number in range(max_number):
     
    206214
    207215# initialize all the box managers
    208 NUMBER_OF_PRE_CREATED_BOXES = 10
     216NUMBER_OF_PRE_CREATED_BOXES = 20
    209217for s in box_schemas():
    210218    build_many_box_forms(s, NUMBER_OF_PRE_CREATED_BOXES)
  • PortalInterlegis/produtos/il.portalinterlegis/trunk/src/il/portalinterlegis/browser/boxes/templates/carousel-edit.html

    r6552 r6584  
    2020  {%- endfor %}
    2121</div>
    22 <form id="carousel-add-form" method="post" action="edit-carousel">
     22<form id="carousel-add-form" method="post" action="{{ carousel_edit_href }}">
    2323  <button id="carousel-add-button" type="submit" name="add" value="_">
    2424    Adicionar um novo painel
  • PortalInterlegis/produtos/il.portalinterlegis/trunk/src/il/portalinterlegis/browser/homes.py

    r6578 r6584  
    2727
    2828    grid = [
    29         ___((10, CarouselBox()), (6, _(ICalendar)),),
     29        ___((10, CarouselBox(0)), (6, _(ICalendar)),),
    3030        ___((FULL, TabbedPane(
    3131            Tab(u'Informação',  u'Informação Legislativa',
    32                 (4, _(IRelated)), (4, _(IRelated)), (4, _(IRelated)), (4, _(IRelated)),),
     32                (4, _(IRelated)), (4, _(IRelated)), (4, _(IRelated)), (4, CarouselBox(1)),),
    3333            Tab(u'Capacitação', u'Capacitação Legislativa',
    3434                (4, _(IRelated)), (4, _(IRelated)), (4, _(IRelated)), (4, _(IRelated)),),
  • PortalInterlegis/produtos/il.portalinterlegis/trunk/src/il/portalinterlegis/static/js/carousel-edit.js

    r6552 r6584  
    44        update: function(event, ui) {
    55            var order = $(this).sortable('toArray').toString();
    6             $.post('edit-carousel', {reorder:order});
     6            $.post(location.pathname, {reorder:order});
    77        }
    88    });
     
    1919        if (answer){
    2020            var panel = $(this).parents(".portlet:first");
    21             $.post('edit-carousel', {remove:panel.attr('id')});
     21            $.post(location.pathname, {remove:panel.attr('id')});
    2222            panel.fadeOut(300, function() {
    2323                $(this).remove();
  • PortalInterlegis/produtos/il.portalinterlegis/trunk/src/il/portalinterlegis/tests/testunitcarousel.py

    r6540 r6584  
    2020        with patch('il.portalinterlegis.browser.boxes.manager.IAnnotations') as IAnnotations:
    2121            IAnnotations.return_value = {BoxAware.ALL_BOXES_KEY: {
    22                 Carousel.CAROUSEL_KEY: {Carousel.NUMBERS_KEY: [1, 2]},
     22                "carousel_numbers_0": [1, 2],
    2323                Box(ICarouselItem, 1).id: dict(
    2424                    target = "TARGET_1",
     
    6464  </div>
    6565</div>
    66 '''.strip('\n'), Carousel(context).render())
     66'''.strip('\n'), Carousel(0, context).render())
    6767            IAnnotations.assert_called_with(context)
Note: Veja TracChangeset para ajuda no uso do visualizador de conjunto de mudanças.
 

The contents and data of this website are published under license:
Creative Commons 4.0 Brasil - Atribuir Fonte - Compartilhar Igual.