Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#46 Added actions (cut,copy,paste,...) #51

Merged
merged 1 commit into from
May 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ Changelog
1.0.0a8 (unreleased)
--------------------

- Nothing changed yet.
Added:

- Added object_buttons actions like cut,copy,paste. #46
[sarnold]


1.0.0a7 (2019-02-05)
Expand Down
53 changes: 51 additions & 2 deletions src/collective/sidebar/browser/sidebar.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@


class SidebarViewlet(ViewletBase):

index = ViewPageTemplateFile('templates/sidebar.pt')

def _contentCanBeAdded(self, addContext, request):
Expand Down Expand Up @@ -338,6 +337,38 @@ def get_workflow_actions(self):
})
return results

@staticmethod
def is_actions_enabled():
"""
Should actions be shown
"""
return api.portal.get_registry_record(
name='collective.sidebar.enable_actions',
default=True,
)

def has_actions(self):
"""
Checks whether there are actions to display
"""
return len(self.get_actions()) > 0

def get_actions(self):
"""
Returns registred object_actions like cut, copy, paste, ...
"""
portal = api.portal.get()
actions = portal.portal_actions.listFilteredActionsFor(self.context)
buttons = list()
if actions:
buttons = actions.get('object_buttons', list())
for action in buttons:
if not action.get('icon', None):
action.icon = get_action_icon(action.get('id', None))
if action.get('url', None):
action.url = addTokenToUrl(action.get('url'), self.request)
return buttons

def get_addable_items(self):
"""
Return menu item entries in a TAL-friendly form.
Expand Down Expand Up @@ -415,6 +446,25 @@ def get_addable_items(self):
return results


def get_action_icon(id1):
"""
Returns icons for action ids
"""
icon_map = {
'cut': 'glyphicon glyphicon-scissors',
'copy': 'glyphicon glyphicon-copy',
'paste': 'glyphicon glyphicon-paste',
'delete': 'glyphicon glyphicon-trash',
'rename': 'glyphicon glyphicon-pencil',
'ical_import_enable': 'glyphicon glyphicon-calendar',
'ical_import_disable': 'glyphicon glyphicon-calendar',
}
if id1 and id1 in icon_map:
return icon_map[id1]
else:
return 'glyphicon glyphicon-star'


class SidebarAJAX(BrowserView):

def __call__(self, render):
Expand All @@ -430,5 +480,4 @@ def render_viewlet(self, context, request):


class CoverViewlet(SidebarViewlet):

index = ViewPageTemplateFile('templates/cover.pt')
17 changes: 17 additions & 0 deletions src/collective/sidebar/browser/templates/sidebar.pt
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,23 @@

</div>

<!-- Actions -->

<div class="menu-section"
tal:define="actions view/get_actions"
tal:condition="python:view.is_actions_enabled() and view.can_edit() and view.has_actions()">

<div class="menu-section-title" i18n:translate="navigation_heading_actions">Actions</div>

<tal:repeat tal:repeat="action actions">
<a tal:condition="action/allowed"
href="${action/url|nothing}" i18n:domain="plone" class="${python:'pat-plone-modal' if action.get('modal', None) else ''}" data-pat-plone-modal="${action/modal|nothing}">
<span class="menu-item-icon ${action/icon}"></span> <span class="menu-item-title" i18n:translate="">${action/title}</span>
</a>
</tal:repeat>

</div>

<!-- Document Management -->

<div class="menu-section" tal:define="items view/get_addable_items" tal:condition="items">
Expand Down
17 changes: 17 additions & 0 deletions src/collective/sidebar/controlpanel/controlpanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,23 @@ class IControlPanel(Interface):
default=False,
)

enable_actions = schema.Bool(
title=_(
u'controlpanel_sidebar_show_actions_title',
default='Show Actions',
),
description=_(
u'controlpanel_sidebar_show_actions_description',
default=(
u'When enabled, the sidebar will '
'display registred object_buttons actions '
'like cut, copy, paste, ...'
),
),
required=False,
default=True,
)


class ControlPanelEditForm(RegistryEditForm):
schema = IControlPanel
Expand Down
17 changes: 16 additions & 1 deletion src/collective/sidebar/locales/collective.sidebar.pot
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2019-02-04 12:56+0000\n"
"POT-Creation-Date: 2019-05-08 12:51+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI +ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand Down Expand Up @@ -72,6 +72,16 @@ msgstr ""
msgid "contents"
msgstr ""

#. Default: "When enabled, the sidebar will display registred object_buttons actions like cut, copy, paste, ..."
#: collective/sidebar/controlpanel/controlpanel.py
msgid "controlpanel_sidebar_show_actions_description"
msgstr ""

#. Default: "Show Actions"
#: collective/sidebar/controlpanel/controlpanel.py
msgid "controlpanel_sidebar_show_actions_title"
msgstr ""

#. Default: "When enabled, the sidebar will always display the root level navigation."
#: collective/sidebar/controlpanel/controlpanel.py
msgid "controlpanel_sidebar_show_root_nav_description"
Expand Down Expand Up @@ -102,6 +112,11 @@ msgstr ""
msgid "folder_add_settings"
msgstr ""

#. Default: "Actions"
#: collective/sidebar/browser/templates/sidebar.pt
msgid "navigation_heading_actions"
msgstr ""

#. Default: "Add"
#: collective/sidebar/browser/templates/sidebar.pt
msgid "navigation_heading_add"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2019-02-04 12:56+0000\n"
"POT-Creation-Date: 2019-05-08 12:51+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI +ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand Down Expand Up @@ -69,6 +69,16 @@ msgstr "Collective Sidebar"
msgid "contents"
msgstr "Inhalte"

#. Default: "When enabled, the sidebar will display registred object_buttons actions like cut, copy, paste, ..."
#: collective/sidebar/controlpanel/controlpanel.py
msgid "controlpanel_sidebar_show_actions_description"
msgstr "Wenn eingeschaltet zeigt die Sidebar object_buttons Aktionen, wie cut/copy/paste/usw.."

#. Default: "Show Actions"
#: collective/sidebar/controlpanel/controlpanel.py
msgid "controlpanel_sidebar_show_actions_title"
msgstr "Aktionen anzeigen"

#. Default: "When enabled, the sidebar will always display the root level navigation."
#: collective/sidebar/controlpanel/controlpanel.py
msgid "controlpanel_sidebar_show_root_nav_description"
Expand Down Expand Up @@ -99,6 +109,11 @@ msgstr "Bearbeiten"
msgid "folder_add_settings"
msgstr "Einschränkungen"

#. Default: "Actions"
#: collective/sidebar/browser/templates/sidebar.pt
msgid "navigation_heading_actions"
msgstr "Aktionen"

#. Default: "Add"
#: collective/sidebar/browser/templates/sidebar.pt
msgid "navigation_heading_add"
Expand Down