make view permission indicator update dynamically after permissions are set

This commit is contained in:
Matt Westcott 2014-06-06 16:34:42 +01:00
parent 1c313652eb
commit 0fbd3e7e14
7 changed files with 42 additions and 13 deletions

View file

@ -2,7 +2,16 @@ $(function() {
/* Interface to set view permissions from the explorer / editor */
$('a.action-set-view-permissions').click(function() {
ModalWorkflow({
'url': this.href
'url': this.href,
'responses': {
'setPermission': function(isPublic) {
if (isPublic) {
$('.view-permission-indicator').removeClass('private').addClass('public');
} else {
$('.view-permission-indicator').removeClass('public').addClass('private');
}
}
}
});
return false;
});

View file

@ -0,0 +1,8 @@
.view-permission-indicator {
&.public {
.label-private { display: none; }
}
&.private {
.label-public { display: none; }
}
}

View file

@ -1,3 +1,4 @@
function(modal) {
modal.respond('setPermission', {% if is_public %}true{% else %}false{% endif %});
modal.close();
}

View file

@ -7,6 +7,7 @@
{% compress css %}
<link rel="stylesheet" href="{{ STATIC_URL }}wagtailadmin/scss/layouts/page-editor.scss" type="text/x-scss" />
<link rel="stylesheet" href="{{ STATIC_URL }}wagtailadmin/scss/panels/rich-text.scss" type="text/x-scss" />
<link rel="stylesheet" type="text/x-scss" href="{{ STATIC_URL }}wagtailadmin/scss/components/view-permission-indicator.scss">
{# we'll want tag-it included, for the benefit of any modals that use it, like images. #}
{# TODO: a method of injecting these sorts of things on demand when the modal is spawned #}

View file

@ -5,17 +5,20 @@
{% endif %}
{% with page.get_view_restrictions as has_view_restrictions %}
{% if has_view_restrictions %}
{% trans 'Private' as label %}
{% else %}
{% trans 'Public' as label %}
{% endif %}
{% if page_perms.can_set_view_restrictions %}
<div>
<a href="{% url 'wagtailadmin_pages_set_view_restrictions' page.id %}" class="button button-small action-set-view-permissions">{{ label }}</a>
<div class="view-permission-indicator {% if has_view_restrictions %}private{% else %}public{% endif %}">
<a href="{% url 'wagtailadmin_pages_set_view_restrictions' page.id %}" class="button button-small action-set-view-permissions">
{# labels are shown/hidden in CSS according to the 'private' / 'public' class on view-permission-indicator #}
<span class="label-public">{% trans 'Public' %}</span>
<span class="label-private">{% trans 'Private' %}</span>
</a>
</div>
{% else %}
<div>{{ label }}</div>
{# Read-only display, for users who don't have permission to set view restrictions #}
{% if has_view_restrictions %}
<div class="view-permission-indicator private"><span class="label-private">{% trans 'Private' %}</span></div>
{% else %}
<div class="view-permission-indicator public"><span class="label-public">{% trans 'Public' %}</span></div>
{% endif %}
{% endif %}
{% endwith %}

View file

@ -1,6 +1,5 @@
{% extends "wagtailadmin/base.html" %}
{% load i18n %}
{% load wagtailadmin_tags %}
{% load i18n wagtailadmin_tags compress %}
{% block titletag %}{% blocktrans with title=parent_page.title %}Exploring {{ title }}{% endblocktrans %}{% endblock %}
{% block bodyclass %}menu-explorer page-explorer {% if ordering == 'ord' %}reordering{% endif %}{% endblock %}
@ -20,6 +19,12 @@
{% endblock %}
{% block extra_css %}
{% compress css %}
<link rel="stylesheet" type="text/x-scss" href="{{ STATIC_URL }}wagtailadmin/scss/components/view-permission-indicator.scss">
{% endcompress %}
{% endblock %}
{% block extra_js %}
{% comment %} modal-workflow is required by the view restrictions interface {% endcomment %}
<script src="{{ STATIC_URL }}wagtailadmin/js/modal-workflow.js"></script>

View file

@ -39,7 +39,9 @@ def set_view_restrictions(request, page_id):
page=page, password = form.cleaned_data['password'])
return render_modal_workflow(
request, None, 'wagtailadmin/page_view_restrictions/set_view_restrictions_done.js'
request, None, 'wagtailadmin/page_view_restrictions/set_view_restrictions_done.js', {
'is_public': (form.cleaned_data['restriction_type'] == 'none')
}
)
else: # request is a GET