Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Load content chooser resources only on compose mode
- Loading branch information
Showing
6 changed files
with
71 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<configure | ||
xmlns="http://namespaces.zope.org/zope" | ||
xmlns:browser="http://namespaces.zope.org/browser"> | ||
|
||
<browser:page | ||
name="cover_helper" | ||
for="*" | ||
permission="zope.Public" | ||
class=".utils.Helper" | ||
allowed_interface=".interfaces.IHelper" | ||
/> | ||
|
||
</configure> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from zope.interface import Interface | ||
|
||
|
||
class IHelper(Interface): | ||
|
||
"""Helper view used to determine if resources are being loaded or not.""" | ||
|
||
def is_view_mode(): | ||
"""True if we are in the context of a cover object in view mode.""" | ||
|
||
def is_compose_mode(): | ||
"""True if we are in the context of a cover object in compose mode.""" | ||
|
||
def is_layout_mode(): | ||
"""True if we are in the context of a cover object in layout mode.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# -*- coding: utf-8 -*- | ||
from Acquisition import aq_inner | ||
from collective.cover.browser.interfaces import IHelper | ||
from collective.cover.interfaces import ICover | ||
from Products.Five.browser import BrowserView | ||
from zope.interface import implements | ||
|
||
|
||
class Helper(BrowserView): | ||
|
||
"""Helper view used to determine if resources are being loaded or not.""" | ||
|
||
implements(IHelper) | ||
|
||
def __call__(self): | ||
self.context = aq_inner(self.context) | ||
self.is_cover = ICover.providedBy(self.context) | ||
# the name of the template is in the parent request | ||
if self.is_cover and 'PARENT_REQUEST' in self.request: | ||
# template name is the last part of the URL | ||
url = self.request.PARENT_REQUEST.URL | ||
self.mode = url.split('/')[-1] | ||
else: | ||
self.mode = '' | ||
|
||
def is_view_mode(self): | ||
"""True if we are in the context of a cover object in view mode.""" | ||
return self.mode == 'view' | ||
|
||
def is_compose_mode(self): | ||
"""True if we are in the context of a cover object in compose mode.""" | ||
return self.mode == 'compose' | ||
|
||
def is_layout_mode(self): | ||
"""True if we are in the context of a cover object in layout mode.""" | ||
return self.mode == 'layout' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
<?xml version="1.0"?> | ||
<object name="portal_css" meta_type="Stylesheets Registry"> | ||
<stylesheet title="" cacheable="True" compression="safe" cookable="True" | ||
enabled="1" expression="" id="++resource++collective.cover/contentchooser.css" media="screen" | ||
rel="stylesheet" rendering="link"/> | ||
enabled="1" expression="python:portal.restrictedTraverse('@@cover_helper').is_compose_mode()" | ||
id="++resource++collective.cover/contentchooser.css" media="screen" | ||
rel="stylesheet" rendering="link" authenticated="True" /> | ||
<stylesheet title="" cacheable="True" compression="safe" cookable="True" | ||
enabled="1" expression="" id="++resource++collective.cover/cover.css" media="screen" | ||
rel="stylesheet" rendering="link"/> | ||
rel="stylesheet" rendering="link" /> | ||
</object> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters