Skip to content

Commit

Permalink
Merge pull request #2 from digi604/new_toolbar
Browse files Browse the repository at this point in the history
New toolbar
  • Loading branch information
Angelo Dini committed Nov 6, 2012
2 parents 4539c52 + d051a7f commit 9ee2422
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 116 deletions.
27 changes: 19 additions & 8 deletions cms/plugin_rendering.py
Expand Up @@ -10,6 +10,7 @@
from django.template.defaultfilters import title
from django.template.loader import render_to_string
from django.utils.translation import ugettext_lazy as _
from django.utils.safestring import mark_safe

# these are always called before all other plugin context processors
DEFAULT_PLUGIN_CONTEXT_PROCESSORS = (
Expand Down Expand Up @@ -81,6 +82,11 @@ def render_plugins(plugins, context, placeholder, processors=None):
context.pop()
return out


def render_dragables(plugins):
return render_to_string("cms/toolbar/placeholder_dragables.html", {'plugins':plugins})


def render_placeholder(placeholder, context_to_copy, name_fallback="Placeholder"):
"""
Renders plugins for a placeholder on the given page using shallow copies of the
Expand Down Expand Up @@ -108,7 +114,7 @@ def render_placeholder(placeholder, context_to_copy, name_fallback="Placeholder"
if not key in context:
context[key] = value

content = []


# Prepend frontedit toolbar output if applicable
edit = False
Expand All @@ -122,15 +128,20 @@ def render_placeholder(placeholder, context_to_copy, name_fallback="Placeholder"
processors = (toolbar_plugin_processor,)
else:
processors = None

content = []
content.extend(render_plugins(plugins, context, placeholder, processors))
content = "".join(content)
toolbar_content = ''
dragables_content = ''
if edit:
content = render_placeholder_toolbar(placeholder, context, content, name_fallback)
toolbar_content = mark_safe(render_placeholder_toolbar(placeholder, context, name_fallback))
dragables_content = mark_safe(render_dragables(plugins))
content = mark_safe("".join(content))

result = render_to_string("cms/toolbar/placeholder.html", {'plugins':content, "toolbar":toolbar_content, "dragables":dragables_content, 'edit':edit})
context.pop()
return content
return result

def render_placeholder_toolbar(placeholder, context, content, name_fallback=None):
def render_placeholder_toolbar(placeholder, context, name_fallback=None):
from cms.plugin_pool import plugin_pool
request = context['request']
page = placeholder.page if placeholder else None
Expand Down Expand Up @@ -158,6 +169,6 @@ def render_placeholder_toolbar(placeholder, context, content, name_fallback=None
context['placeholder_label'] = name
context['placeholder'] = placeholder
context['page'] = page
toolbar = render_to_string("cms/toolbar/placeholder.html", context)
toolbar = render_to_string("cms/toolbar/placeholder_toolbar.html", context)
context.pop()
return "".join([toolbar, content])
return toolbar
4 changes: 3 additions & 1 deletion cms/static/cms/js/plugins/cms.placeholders.js
Expand Up @@ -152,10 +152,12 @@ $(document).ready(function () {
'stop': function (event, ui) {
// TODO this needs refactoring, first should be ALL placeholders than all dragitems within a list
// TODO otherwise this wont work

//var dragitem = ui.item;

//plugin.insertBefore(dragitem);


// TODO we need some ajax checking before actually replacing
// TODO we might also need some loading indication

Expand Down Expand Up @@ -460,4 +462,4 @@ $(document).ready(function () {
'move_plugin': ''
}
}
*/
*/
22 changes: 22 additions & 0 deletions cms/templates/cms/toolbar/items/plugin_drag.html
@@ -0,0 +1,22 @@

<div id="cms_dragholder-{{ plugin.pk }}" class="cms_reset cms_light cms_dragholder cms_dragholder-draggable">
<div class="cms_dragmenu"></div>
<div class="cms_dragmenu-dropdown">
<span>{% trans "Settings" %}</span>
<a rel="dialogue" data-text="Are you sure you want to copy this plugin?" href="#">Copy</a>
<a rel="sideframe" href="{{ instance.placeholder.get_remove_url }}{{ instance.pk }}">Delete</a>
{% for class, name in child_plugin_classes %}
{% if forloop.first %}<span>{% trans "Add Plugin" %}</span>{% endif %}
<!-- TODO add correct url instead of only clas -->
<a rel="custom" href="#{{ class }}">{{ name }}</a>
{% endfor %}
</div>
<div class="cms_dragitem"><strong>{{ instance.plugin_type }}</strong> {{ instance.placeholder.slot }}</div>
{% if plugin.get_plugin_class.allow_children and plugin.plugin_children_instances %}
{% for child in plugin.plugin_children_instances %}
{# workaround because include tag does not allow recursive includes #}
{% with template_name="cms/toolbar/items/plugin_drag.html" %}{% include template_name %}{% endwith %}

{% endfor %}
{% endif %}
</div>
40 changes: 8 additions & 32 deletions cms/templates/cms/toolbar/placeholder.html
@@ -1,33 +1,9 @@
{% load i18n sekizai_tags %}
{% addtoblock "js" %}
<script type="text/javascript">
CMS.$(document).ready(function () {
new CMS.Placeholder('#cms_placeholder-bar-{{ placeholder.pk }}', {
'type': 'bar',
'placeholder_id': '{{ placeholder.pk }}',
'plugin_language': '{{ language }}', // todo not required should be within backend
'plugin_restriction': ['TextPlugin', 'PicturePlugin'], // empty = false // todo just testing atm
'urls': {
'add_plugin': '{{ placeholder.get_add_url }}',
'edit_plugin': '{{ placeholder.get_changelist_url }}'
}
});
});
</script>
{% endaddtoblock %}
<div id="cms_placeholder-bar-{{ placeholder.pk }}" class="cms_reset cms_light cms_placeholder-bar">
<div class="cms_placeholder-title">{{ placeholder_label }}</div>
<div class="cms_placeholder-btn">
<a href="#"><span>{% trans "Add Plugin" %}</span></a>
<ul class="cms_placeholder-subnav">
{% regroup installed_plugins by module as module_list %}
{% for module in module_list %}
<li class="cms_placeholder-subnav-title"><span>{% if module.grouper %}{{ module.grouper|capfirst }}{% else %}{% trans "Add Plugin" %}{% endif %}</span></li>
{% for p in module.list %}
<li><a href="#{{ p.value }}">{{ p.name }}</a></li>
{% endfor %}
{% endfor %}
</ul>
</div>
{% if edit %}
{{ toolbar }}
<div>
{{ plugins }}
{{ dragables }}
</div>
<div class="cms_reset cms_light cms_dragholder cms_dragholder-empty cms_dragholder-droppable"><div class="cms_dragitem">Drop a plugin here</div></div>
{% else %}
{{ plugins }}
{% endif %}
3 changes: 3 additions & 0 deletions cms/templates/cms/toolbar/placeholder_dragables.html
@@ -0,0 +1,3 @@
{% for plugin in plugins %}
{% include "cms/toolbar/items/plugin_drag.html" with plugin=plugin %}
{% endfor %}
33 changes: 33 additions & 0 deletions cms/templates/cms/toolbar/placeholder_toolbar.html
@@ -0,0 +1,33 @@
{% load i18n sekizai_tags %}
{% addtoblock "js" %}
<script type="text/javascript">
CMS.$(document).ready(function () {
new CMS.Placeholder('#cms_placeholder-bar-{{ placeholder.pk }}', {
'type': 'bar',
'placeholder_id': '{{ placeholder.pk }}',
'plugin_language': '{{ language }}', // todo not required should be within backend
'plugin_restriction': ['TextPlugin', 'PicturePlugin'], // empty = false // todo just testing atm
'urls': {
'add_plugin': '{{ placeholder.get_add_url }}',
'edit_plugin': '{{ placeholder.get_changelist_url }}'
}
});
});
</script>
{% endaddtoblock %}
<div id="cms_placeholder-bar-{{ placeholder.pk }}" class="cms_reset cms_light cms_placeholder-bar">
<div class="cms_placeholder-title">{{ placeholder_label }}</div>
<div class="cms_placeholder-btn">
<a href="#"><span>{% trans "Add Plugin" %}</span></a>
<ul class="cms_placeholder-subnav">
{% regroup installed_plugins by module as module_list %}
{% for module in module_list %}
<li class="cms_placeholder-subnav-title"><span>{% if module.grouper %}{{ module.grouper|capfirst }}{% else %}{% trans "Available plugins" %}{% endif %}</span></li>
{% for p in module.list %}
<li><a href="#{{ p.value }}">{{ p.name }}</a></li>
{% endfor %}
{% endfor %}
</ul>
</div>
</div>
<div class="cms_reset cms_light cms_dragholder cms_dragholder-empty cms_dragholder-droppable"><div class="cms_dragitem">Drop a plugin here</div></div>
22 changes: 1 addition & 21 deletions cms/templates/cms/toolbar/placeholder_wrapper.html
Expand Up @@ -26,24 +26,4 @@
</script>
{% endaddtoblock %}

{% if not instance.parent %}<div id="cms_placeholder-{{ instance.pk }}" class="cms_placeholder cms_light">{{ rendered_content }}</div>{% endif %}
<div id="cms_dragholder-{{ instance.pk }}" class="cms_reset cms_light cms_dragholder cms_dragholder-draggable">
<div class="cms_dragmenu"></div>
<div class="cms_dragmenu-dropdown">
<span>{% trans "Settings" %}</span>
<a rel="dialogue" data-text="Are you sure you want to copy this plugin?" href="#">Copy</a>
<a rel="sideframe" href="{{ instance.placeholder.get_remove_url }}{{ instance.pk }}">Delete</a>
{% for class, name in child_plugin_classes %}
{% if forloop.first %}<span>{% trans "Add Plugin" %}</span>{% endif %}
<!-- TODO add correct url instead of only clas -->
<a rel="custom" href="#{{ class }}">{{ name }}</a>
{% endfor %}
</div>
<div class="cms_dragitem"><strong>{{ instance.plugin_type }}</strong> {{ instance.placeholder.slot }}</div>
{% if instance.get_plugin_class.allow_children and instance.plugion_children %}
{% for plugin in instance.plugin_children %}
{% render_plugin plugin %}
{% endfor %}
{% endif %}
</div>

<div id="cms_placeholder-{{ instance.pk }}" class="cms_placeholder cms_light">{{ rendered_content }}</div>

0 comments on commit 9ee2422

Please sign in to comment.