[gen] Added parameter Ref.collapsible allowing to show/hide (via a cookie in the UI, similar to object history) available or tied items.

This commit is contained in:
Gaetan Delannay 2015-01-26 17:26:05 +01:00
parent 73f81d9304
commit fcf6a52974
6 changed files with 67 additions and 35 deletions

View file

@ -1240,6 +1240,11 @@ class BaseMixin:
res.append(event)
return Object(events=res, totalNumber=len(history))
def getHistoryCollapse(self):
'''Gets a Collapsible instance for showing a collapse or expanded
history in this object.'''
return Collapsible('appyHistory', self.REQUEST)
def mayNavigate(self):
'''May the currently logged user see the navigation panel linked to
this object?'''

View file

@ -673,13 +673,13 @@ function readCookie(name) {
return null;
}
function toggleCookie(cookieId) {
function toggleCookie(cookieId, display, defaultValue) {
// What is the state of this boolean (expanded/collapsed) cookie?
var state = readCookie(cookieId);
if ((state != 'collapsed') && (state != 'expanded')) {
// No cookie yet, create it.
createCookie(cookieId, 'collapsed');
state = 'collapsed';
// No cookie yet, create it
createCookie(cookieId, defaultValue);
state = defaultValue;
}
var hook = document.getElementById(cookieId); // The hook is the part of
// the HTML document that needs to be shown or hidden.
@ -688,7 +688,7 @@ function toggleCookie(cookieId) {
var imgSrc = 'ui/expand.gif';
if (state == 'collapsed') {
// Show the HTML zone
displayValue = 'block';
displayValue = display;
imgSrc = 'ui/collapse.gif';
newState = 'expanded';
}

View file

@ -1,5 +1,6 @@
# ------------------------------------------------------------------------------
import re, os, os.path, base64, urllib
from appy.px import Px
from appy.shared import utils as sutils
# Function for creating a Zope object ------------------------------------------
@ -251,5 +252,29 @@ class Tool(Model):
'''Subclass me to extend or modify the Tool class.'''
class User(Model):
'''Subclass me to extend or modify the User class.'''
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
class Collapsible:
'''Represents a chunk of HTML code that can be collapsed/expanded via a
plus/minus icon.'''
# Plus/minus icon allowing to collapse/expand a chunk of HTML
px = Px('''
<img id=":'%s_img' % collapse.id" class="clickable" align=":dleft"
onclick=":'toggleCookie(%s,%s,%s)' % \
(q(collapse.id), q(collapse.display), q(collapse.default))"
src=":collapse.expanded and url('collapse.gif') or url('expand.gif')"
style="padding-right:4px"/>''')
def __init__(self, id, request, default='collapsed', display='block'):
'''p_display is the value of style attribute "display" for the XHTML
element when it must be displayed. By default it is "block"; for a
table it must be "table", etc.'''
self.id = id # The ID of the collapsible HTML element
self.request = request # The request object
self.default = default
self.display = display
# Must the element be collapsed or expanded ?
self.expanded = request.get(id, default) == 'expanded'
self.style = 'display:%s' % (self.expanded and self.display or 'none')
# ------------------------------------------------------------------------------

View file

@ -397,16 +397,13 @@ class AbstractWrapper(object):
<div if="not zobj.isTemporary()"
var2="hasHistory=zobj.hasHistory();
historyMaxPerPage=req.get('maxPerPage', 5);
historyExpanded=req.get('appyHistory','collapsed')=='expanded';
collapse=zobj.getHistoryCollapse();
creator=zobj.Creator()">
<table width="100%" class="summary" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2" class="by">
<!-- Plus/minus icon for accessing history -->
<x if="hasHistory">
<img class="clickable" onclick="toggleCookie('appyHistory')"
src=":historyExpanded and url('collapse.gif') or url('expand.gif')"
align=":dleft" id="appyHistory_img" style="padding-right:4px"/>
<x if="hasHistory"><x>:collapse.px</x>
<x>:_('object_history')</x> &mdash;
</x>
@ -434,8 +431,7 @@ class AbstractWrapper(object):
<!-- Object history -->
<tr if="hasHistory">
<td colspan="2">
<span id="appyHistory"
style=":historyExpanded and 'display:block' or 'display:none'">
<span id=":collapse.id" style=":collapse.style">
<div var="ajaxHookId=zobj.id + '_history'" id=":ajaxHookId">
<script type="text/javascript">::'askObjectHistory(%s,%s,%d,0)' % \
(q(ajaxHookId), q(zobj.absolute_url()), \