author Sylvain Thénault <>
Mon, 11 Dec 2017 16:22:05 +0100
changeset 2911 ef03dc37382c
parent 2910 8a08e1df2e59
child 2912 1715f15e4651
permissions -rw-r--r--
[seda tree] Skeleton for allowing to move a node at a specific position of the tree by implementing it on the JQTree adapter, but with only hard-coded position in the js for now.

# copyright 2016 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact --
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation, either version 2.1 of the License, or (at your option)
# any later version.
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
# You should have received a copy of the GNU Lesser General Public License along
# with this program. If not, see <>.
"""cubicweb-seda views for ArchiveUnit"""

from cubicweb import _
from cubicweb.predicates import adaptable, is_instance
from cubicweb.web import component

from ..entities import simplified_profile, component_unit
from ..entities.itree import reparent
from . import jqtree

class ProfileTreeComponent(component.EntityCtxComponent):
    """Display the whole profile tree."""
    __regid__ = 'seda.tree'
    __select__ = (component.EntityCtxComponent.__select__
                  & adaptable('ITreeBase'))
    context = 'left'
    order = -1
    title = _('SEDA profile tree')

    def render_body(self, w):
        self.entity.view('jqtree.treeview', w=w)

class UnitTreeComponent(ProfileTreeComponent):
    __select__ = ProfileTreeComponent.__select__ & component_unit()
    title = _('Archive unit component tree')

class SEDAIJQTreeAdapter(jqtree.IJQTreeAdapter):
    js_can_move_to = 'seda.canMoveTo'

class ArchiveTransferIJQTreeAdapter(SEDAIJQTreeAdapter):
    __select__ = (SEDAIJQTreeAdapter.__select__
                  & is_instance('SEDAArchiveTransfer'))

    def maybe_parent_of(self):
        return ['SEDAArchiveUnit',
                'SEDAPhysicalDataObject', 'SEDABinaryDataObject']

class SimplifiedArchiveTransferIJQTreeAdapter(ArchiveTransferIJQTreeAdapter):
    __select__ = ArchiveTransferIJQTreeAdapter.__select__ & simplified_profile()

    def maybe_parent_of(self):
        return ['SEDAArchiveUnit']

class ArchiveUnitIJQTreeAdapter(SEDAIJQTreeAdapter):
    __select__ = (SEDAIJQTreeAdapter.__select__
                  & is_instance('SEDAArchiveUnit'))

    def maybe_parent_of(self):
        return [] if self.entity.is_archive_unit_ref else ['SEDAArchiveUnit']

    def maybe_moved(self):
        return True

    def reparent(self, peid, index):
        parent = self._cw.entity_from_eid(peid)
        if parent.cw_etype == 'SEDAArchiveUnit':
            parent = parent.first_level_choice.content_sequence
            assert parent.cw_etype == 'SEDAArchiveTransfer', (
                'cannot re-parent to entity type {0}'.format(parent.cw_etype))
        reparent(self.entity, parent.eid, index)

class SimplifiedArchiveUnitIJQTreeAdapter(ArchiveUnitIJQTreeAdapter):
    __select__ = ArchiveUnitIJQTreeAdapter.__select__ & simplified_profile()

    def maybe_parent_of(self):
        return [] if self.entity.is_archive_unit_ref else ['SEDAArchiveUnit',

class DataObjectIJQTreeAdapter(SEDAIJQTreeAdapter):
    __select__ = (SEDAIJQTreeAdapter.__select__
                  & is_instance('SEDABinaryDataObject', 'SEDAPhysicalDataObject'))

    def maybe_moved(self):
        return False

class SimplifiedBinaryDataObjectIJQTreeAdapter(SEDAIJQTreeAdapter):
    __select__ = (SEDAIJQTreeAdapter.__select__
                  & is_instance('SEDABinaryDataObject') & simplified_profile())
    rtype_to_archivetransfer = 'seda_binary_data_object'

    def maybe_moved(self):
        return True

    def reparent(self, peid, index):
        archunit = self._cw.entity_from_eid(peid)
        parent = archunit.first_level_choice.content_sequence
        child = self.entity.reverse_seda_data_object_reference_id[0]
        reparent(child, parent.eid, index)