From: Vitaliy P. <svn...@pl...> - 2009-02-28 21:29:50
|
Author: piv Date: Sat Feb 28 21:29:41 2009 New Revision: 81495 Added: collective.orgchart/trunk/collective/orgchart/profiles/default/catalog.xml Modified: collective.orgchart/trunk/ (props changed) collective.orgchart/trunk/collective/orgchart/browser/folder.py collective.orgchart/trunk/collective/orgchart/browser/templates/orgchart_recurse.pt collective.orgchart/trunk/collective/orgchart/content/chartbox.py Log: add possibility to style in a different way boxes, add possibility to position lateral boxes under each other, some minor fixes and corrections Modified: collective.orgchart/trunk/collective/orgchart/browser/folder.py ============================================================================== --- collective.orgchart/trunk/collective/orgchart/browser/folder.py (original) +++ collective.orgchart/trunk/collective/orgchart/browser/folder.py Sat Feb 28 21:29:41 2009 @@ -7,15 +7,52 @@ recurse = ViewPageTemplateFile('templates/orgchart_recurse.pt') - def getBoxes(self): + def _getBoxes(self): query = {'path': {'query': '/'.join(self.context.getPhysicalPath())}} - return buildFolderTree(self.context, obj=self.context, query=query)['children'] + tree = buildFolderTree(self.context, obj=self.context, query=query) + + # now process suppressPlacement box' option: + # if current box suppress placement this means that we should + # place his children under each other so as they are each other's + # children, and we have to remove box' grand children + for item in tree['children']: + self._processBox(item) + + return tree['children'] + + def _processBox(self, box, parent=None): + if getattr(box['item'], 'getSuppressPlacement', False): + parent = box + children = box.get('children', [])[:] + for child in children: + child['children'] = [] + parent['children'] = [child,] + parent = child + else: + for item in box.get('children', []): + self._processBox(item) def getOrgChart(self): - boxes = self.getBoxes() + boxes = self._getBoxes() length = len(boxes) result = [] + i = 0 for box in boxes: - result.append(self.recurse(box=box, is_root=True, idx=boxes.index(box), length=length)) + result.append(self.recurse( + box=box, + is_root=True, + idx=i, + length=length + )) + i += 1 return '\n'.join(result) + def calculateItemClass(self, parent_kids_number, my_index, my_kids_number): + klasses = ['orgChartItem',] + if parent_kids_number == my_index + 1: + klasses.append('lastChild') + if not my_kids_number: + klasses.append('hasNoChild') + if parent_kids_number == 1: + klasses.append('onlyChild') + return ' '.join(klasses) Modified: collective.orgchart/trunk/collective/orgchart/browser/templates/orgchart_recurse.pt ============================================================================== --- collective.orgchart/trunk/collective/orgchart/browser/templates/orgchart_recurse.pt (original) +++ collective.orgchart/trunk/collective/orgchart/browser/templates/orgchart_recurse.pt Sat Feb 28 21:29:41 2009 @@ -7,24 +7,30 @@ <dl class="orgChartItem" tal:define="children box/children|python:[]; kids_number python:len(children); - last_child python:idx+1 == length; - klass python:' '.join([ - 'orgChartItem', - last_child and 'lastChild' or '', - not kids_number and 'hasNoChild' or '', - length == -1 and 'onlyChild' or '', - ])" + klass python:view.calculateItemClass(length, idx, kids_number); + item box/item" tal:attributes="class klass;"> - <dt><a href="" - tal:attributes="href box/item/getURL"> - <span class="orgChartItemContent" - tal:content="box/item/Title">orgChartItem 1 Level 1</span><span class="visualHeight"></span></a> + <dt> + <a href="" + class="boxStyle" + tal:define="klass item/getBoxStyle" + tal:attributes="href python:item.getLink or item.getURL(); + class python:klass and klass or None"> + <span class="orgChartItemContent"> + <span class="orgChartItemTitle" + tal:content="item/Title">Box Title</span> + <span class="orgChartItemDescription" + tal:content="structure item/Description">Box Description</span> + </span> + <span class="visualHeight"></span> + </a> </dt> - <dd> - <tal:block repeat="child children"> - <tal:child replace="structure python:view.recurse(box=child, is_root=False, idx=repeat['child'].index, length=kids_number)" /> - </tal:block> - </dd> + <dd class="suppressedOrNot" + tal:attributes="class python:item.getSuppressPlacement and 'suppressPlacement' or None"> + <tal:block repeat="child children"> + <tal:child replace="structure python:view.recurse(box=child, is_root=False, idx=repeat['child'].index, length=kids_number)" /> + </tal:block> + </dd> </dl> </tal:master> \ No newline at end of file Modified: collective.orgchart/trunk/collective/orgchart/content/chartbox.py ============================================================================== --- collective.orgchart/trunk/collective/orgchart/content/chartbox.py (original) +++ collective.orgchart/trunk/collective/orgchart/content/chartbox.py Sat Feb 28 21:29:41 2009 @@ -43,8 +43,8 @@ ), StringField('link', - required=True, - default = "http://", + required=False, + default = "", # either mailto, absolute url or relative url validators = (), widget = StringWidget( @@ -92,7 +92,7 @@ BooleanField('suppressPlacement', - required=True, + required=False, default=False, widget=BooleanWidget( label="Suppress Placement", Added: collective.orgchart/trunk/collective/orgchart/profiles/default/catalog.xml ============================================================================== --- (empty file) +++ collective.orgchart/trunk/collective/orgchart/profiles/default/catalog.xml Sat Feb 28 21:29:41 2009 @@ -0,0 +1,15 @@ +<?xml version="1.0"?> +<object name="portal_catalog" meta_type="Plone Catalog Tool"> + <index name="getLink" meta_type="FieldIndex"> + <indexed_attr value="getLink"/> + </index> + <index name="getBoxStyle" meta_type="FieldIndex"> + <indexed_attr value="getBoxStyle"/> + </index> + <index name="getSuppressPlacement" meta_type="FieldIndex"> + <indexed_attr value="getSuppressPlacement"/> + </index> + <column value="getLink"/> + <column value="getBoxStyle"/> + <column value="getSuppressPlacement"/> +</object> |