kopia lustrzana https://github.com/wagtail/wagtail
Merge branch 'davecranwell-feature/chooser-panel-edit-links-2'
commit
e342ad5580
|
@ -27,6 +27,7 @@ Changelog
|
|||
* SCSS files in wagtailadmin now use absolute imports, to permit overriding by user stylesheets (Martin Sanders)
|
||||
* Bare text entered in rich text areas is now automatically wrapped in a paragraph element
|
||||
* Added pagination to the snippets listing and chooser (Martin Sanders)
|
||||
* Page / document / image / snippet choosers now include a link to edit the chosen item
|
||||
* Fix: The `document_served` signal now correctly passes the Document class as `sender` and the document as `instance`
|
||||
|
||||
0.8.5 (17.02.2015)
|
||||
|
|
|
@ -34,6 +34,7 @@ Admin
|
|||
* Added contextual links to admin notification messages
|
||||
* When copying pages, it is now possible to specify a place to copy to
|
||||
* Added pagination to the snippets listing and chooser
|
||||
* Page / document / image / snippet choosers now include a link to edit the chosen item
|
||||
|
||||
|
||||
**Page editor**
|
||||
|
|
|
@ -2,6 +2,7 @@ function createPageChooser(id, pageType, openAtParentId) {
|
|||
var chooserElement = $('#' + id + '-chooser');
|
||||
var pageTitle = chooserElement.find('.title');
|
||||
var input = $('#' + id);
|
||||
var editLink = chooserElement.find('.edit-link');
|
||||
|
||||
$('.action-choose', chooserElement).click(function() {
|
||||
var initialUrl = window.chooserUrls.pageChooser;
|
||||
|
@ -17,6 +18,7 @@ function createPageChooser(id, pageType, openAtParentId) {
|
|||
openAtParentId = pageData.parentId;
|
||||
pageTitle.text(pageData.title);
|
||||
chooserElement.removeClass('blank');
|
||||
editLink.attr('href', pageData.editUrl);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -661,6 +661,16 @@ ul.inline li:first-child, li.inline:first-child{
|
|||
display: none;
|
||||
}
|
||||
|
||||
.actions{
|
||||
overflow:hidden;
|
||||
@include clearfix;
|
||||
|
||||
li{
|
||||
float:left;
|
||||
margin:0.3em;
|
||||
}
|
||||
}
|
||||
|
||||
/* ...unless the .page-chooser has the 'blank' class set */
|
||||
&.blank {
|
||||
.chosen { display: none; }
|
||||
|
|
|
@ -48,7 +48,7 @@
|
|||
{% elif choosing %}
|
||||
<h2>
|
||||
{% if parent_page.can_choose %}
|
||||
<a class="choose-page" href="#{{ parent_page.id }}" data-id="{{ parent_page.id }}" data-title="{{ parent_page.title }}" data-url="{{ parent_page.url }}">{{ parent_page.title }}</a>
|
||||
<a class="choose-page" href="#{{ parent_page.id }}" data-id="{{ parent_page.id }}" data-title="{{ parent_page.title }}" data-url="{{ parent_page.url }}" data-edit-url="{% url 'wagtailadmin_pages_edit' parent_page.id %}">{{ parent_page.title }}</a>
|
||||
{% else %}
|
||||
{{ parent_page.title }}
|
||||
{% endif %}
|
||||
|
@ -184,7 +184,7 @@
|
|||
{% endif %}
|
||||
{% elif choosing %}
|
||||
{% if page.can_choose %}
|
||||
<a class="choose-page" href="#{{ page.id }}" data-id="{{ page.id }}" data-title="{{ page.title }}" data-url="{{ page.url }}">{{ page.title }}</a>
|
||||
<a class="choose-page" href="#{{ page.id }}" data-id="{{ page.id }}" data-title="{{ page.title }}" data-url="{{ page.url }}" data-edit-url="{% url 'wagtailadmin_pages_edit' page.id %}">{{ page.title }}</a>
|
||||
{% else %}
|
||||
{{ page.title }}
|
||||
{% endif %}
|
||||
|
|
|
@ -12,12 +12,13 @@
|
|||
<div class="chosen">
|
||||
{% block chosen_state_view %}{% endblock %}
|
||||
|
||||
<div class="actions">
|
||||
<ul class="actions">
|
||||
{% if not widget.is_required %}
|
||||
<input type="button" class="action-clear button-small button-secondary" value="{{ widget.clear_choice_text }}">
|
||||
<li><input type="button" class="action-clear button-small button-secondary" value="{{ widget.clear_choice_text }}"></li>
|
||||
{% endif %}
|
||||
<input type="button" class="action-choose button-small button-secondary" value="{{ widget.choose_another_text }}">
|
||||
</div>
|
||||
<li><input type="button" class="action-choose button-small button-secondary" value="{{ widget.choose_another_text }}"></li>
|
||||
<li><a href="{% block edit_chosen_item_url %}#{% endblock %}" class="edit-link button button-small button-secondary" target="_blank">{{ widget.link_to_chosen_text }}</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="unchosen">
|
||||
|
|
|
@ -3,3 +3,5 @@
|
|||
{% block chosen_state_view %}
|
||||
<span class="title">{{ page.title }}</span>
|
||||
{% endblock %}
|
||||
|
||||
{% block edit_chosen_item_url %}{% if page %}{% url 'wagtailadmin_pages_edit' page.id %}{% endif %}{% endblock %}
|
||||
|
|
|
@ -360,6 +360,10 @@ class TestPageChooserPanel(TestCase):
|
|||
def test_render_as_field(self):
|
||||
result = self.page_chooser_panel.render_as_field()
|
||||
self.assertIn('<p class="help">help text</p>', result)
|
||||
self.assertIn('<span class="title">Christmas</span>', result)
|
||||
self.assertIn(
|
||||
'<a href="/admin/pages/%d/edit/" class="edit-link button button-small button-secondary" target="_blank">Edit this page</a>' % self.christmas_page.id,
|
||||
result)
|
||||
|
||||
def test_render_error(self):
|
||||
form = self.PageChooserForm({'page': ''}, instance=self.test_instance)
|
||||
|
|
|
@ -41,6 +41,7 @@ class AdminChooser(WidgetWithScript, widgets.Input):
|
|||
choose_one_text = _("Choose an item")
|
||||
choose_another_text = _("Choose another item")
|
||||
clear_choice_text = _("Clear choice")
|
||||
link_to_chosen_text = _("Edit this item")
|
||||
|
||||
def get_instance(self, model_class, value):
|
||||
# helper method for cleanly turning 'value' into an instance object
|
||||
|
@ -68,6 +69,8 @@ class AdminChooser(WidgetWithScript, widgets.Input):
|
|||
self.choose_another_text = kwargs.pop('choose_another_text')
|
||||
if 'clear_choice_text' in kwargs:
|
||||
self.clear_choice_text = kwargs.pop('clear_choice_text')
|
||||
if 'link_to_chosen_text' in kwargs:
|
||||
self.link_to_chosen_text = kwargs.pop('link_to_chosen_text')
|
||||
super(AdminChooser, self).__init__(**kwargs)
|
||||
|
||||
|
||||
|
@ -75,6 +78,7 @@ class AdminPageChooser(AdminChooser):
|
|||
target_content_type = None
|
||||
choose_one_text = _('Choose a page')
|
||||
choose_another_text = _('Choose another page')
|
||||
link_to_chosen_text = _('Edit this page')
|
||||
|
||||
def __init__(self, content_type=None, **kwargs):
|
||||
super(AdminPageChooser, self).__init__(**kwargs)
|
||||
|
|
|
@ -2,6 +2,7 @@ function createDocumentChooser(id) {
|
|||
var chooserElement = $('#' + id + '-chooser');
|
||||
var docTitle = chooserElement.find('.title');
|
||||
var input = $('#' + id);
|
||||
var editLink = chooserElement.find('.edit-link');
|
||||
|
||||
$('.action-choose', chooserElement).click(function() {
|
||||
ModalWorkflow({
|
||||
|
@ -11,6 +12,7 @@ function createDocumentChooser(id) {
|
|||
input.val(docData.id);
|
||||
docTitle.text(docData.title);
|
||||
chooserElement.removeClass('blank');
|
||||
editLink.attr('href', docData.edit_link);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -4,3 +4,5 @@
|
|||
{% block chosen_state_view %}
|
||||
<span class="title">{{ document.title }}</span>
|
||||
{% endblock %}
|
||||
|
||||
{% block edit_chosen_item_url %}{% if document %}{% url 'wagtaildocs_edit_document' document.id %}{% endif %}{% endblock %}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import json
|
||||
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.shortcuts import get_object_or_404, render
|
||||
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
|
||||
from django.contrib.auth.decorators import permission_required
|
||||
|
@ -11,6 +12,18 @@ from wagtail.wagtailsearch.backends import get_search_backends
|
|||
from wagtail.wagtaildocs.models import Document
|
||||
from wagtail.wagtaildocs.forms import DocumentForm
|
||||
|
||||
def get_document_json(document):
|
||||
"""
|
||||
helper function: given a document, return the json to pass back to the
|
||||
chooser panel
|
||||
"""
|
||||
|
||||
return json.dumps({
|
||||
'id': document.id,
|
||||
'title': document.title,
|
||||
'edit_link': reverse('wagtaildocs_edit_document', args=(document.id,)),
|
||||
})
|
||||
|
||||
|
||||
def chooser(request):
|
||||
if request.user.has_perm('wagtaildocs.add_document'):
|
||||
|
@ -79,11 +92,9 @@ def chooser(request):
|
|||
def document_chosen(request, document_id):
|
||||
document = get_object_or_404(Document, id=document_id)
|
||||
|
||||
document_json = json.dumps({'id': document.id, 'title': document.title})
|
||||
|
||||
return render_modal_workflow(
|
||||
request, None, 'wagtaildocs/chooser/document_chosen.js',
|
||||
{'document_json': document_json}
|
||||
{'document_json': get_document_json(document)}
|
||||
)
|
||||
|
||||
|
||||
|
@ -100,10 +111,9 @@ def chooser_upload(request):
|
|||
for backend in get_search_backends():
|
||||
backend.add(document)
|
||||
|
||||
document_json = json.dumps({'id': document.id, 'title': document.title})
|
||||
return render_modal_workflow(
|
||||
request, None, 'wagtaildocs/chooser/document_chosen.js',
|
||||
{'document_json': document_json}
|
||||
{'document_json': get_document_json(document)}
|
||||
)
|
||||
else:
|
||||
form = DocumentForm()
|
||||
|
|
|
@ -12,6 +12,7 @@ from wagtail.wagtaildocs.models import Document
|
|||
class AdminDocumentChooser(AdminChooser):
|
||||
choose_one_text = _('Choose a document')
|
||||
choose_another_text = _('Choose another document')
|
||||
link_to_chosen_text = _('Edit this document')
|
||||
|
||||
def render_html(self, name, value, attrs):
|
||||
original_field_html = super(AdminDocumentChooser, self).render_html(name, value, attrs)
|
||||
|
|
|
@ -2,6 +2,7 @@ function createImageChooser(id) {
|
|||
var chooserElement = $('#' + id + '-chooser');
|
||||
var previewImage = chooserElement.find('.preview-image img');
|
||||
var input = $('#' + id);
|
||||
var editLink = chooserElement.find('.edit-link');
|
||||
|
||||
$('.action-choose', chooserElement).click(function() {
|
||||
ModalWorkflow({
|
||||
|
@ -16,6 +17,7 @@ function createImageChooser(id) {
|
|||
'alt': imageData.title
|
||||
});
|
||||
chooserElement.removeClass('blank');
|
||||
editLink.attr('href', imageData.edit_link);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -12,3 +12,5 @@
|
|||
{% endif %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block edit_chosen_item_url %}{% if image %}{% url 'wagtailimages_edit_image' image.id %}{% endif %}{% endblock %}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import json
|
||||
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.shortcuts import get_object_or_404, render
|
||||
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
|
||||
from django.contrib.auth.decorators import permission_required
|
||||
|
@ -23,6 +24,7 @@ def get_image_json(image):
|
|||
|
||||
return json.dumps({
|
||||
'id': image.id,
|
||||
'edit_link': reverse('wagtailimages_edit_image', args=(image.id,)),
|
||||
'title': image.title,
|
||||
'preview': {
|
||||
'url': preview_image.url,
|
||||
|
@ -165,6 +167,7 @@ def chooser_select_format(request, image_id):
|
|||
'format': format.name,
|
||||
'alt': form.cleaned_data['alt_text'],
|
||||
'class': format.classnames,
|
||||
'edit_link': reverse('wagtailimages_edit_image', args=(image.id,)),
|
||||
'preview': {
|
||||
'url': preview_image.url,
|
||||
'width': preview_image.width,
|
||||
|
|
|
@ -12,7 +12,7 @@ from wagtail.wagtailimages.models import get_image_model
|
|||
class AdminImageChooser(AdminChooser):
|
||||
choose_one_text = _('Choose an image')
|
||||
choose_another_text = _('Choose another image')
|
||||
clear_choice_text = _('Clear image')
|
||||
link_to_chosen_text = _('Edit this image')
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super(AdminImageChooser, self).__init__(**kwargs)
|
||||
|
|
|
@ -2,6 +2,7 @@ function createSnippetChooser(id, contentType) {
|
|||
var chooserElement = $('#' + id + '-chooser');
|
||||
var docTitle = chooserElement.find('.title');
|
||||
var input = $('#' + id);
|
||||
var editLink = chooserElement.find('.edit-link');
|
||||
|
||||
$('.action-choose', chooserElement).click(function() {
|
||||
ModalWorkflow({
|
||||
|
@ -11,6 +12,7 @@ function createSnippetChooser(id, contentType) {
|
|||
input.val(snippetData.id);
|
||||
docTitle.text(snippetData.string);
|
||||
chooserElement.removeClass('blank');
|
||||
editLink.attr('href', snippetData.edit_link);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -5,3 +5,5 @@
|
|||
{% block chosen_state_view %}
|
||||
<span class="title">{{ item }}</span>
|
||||
{% endblock %}
|
||||
|
||||
{% block edit_chosen_item_url %}{% if item %}{% url 'wagtailsnippets_edit' widget.target_content_type.app_label widget.target_content_type item.id %}{% endif %}{% endblock %}
|
||||
|
|
|
@ -3,6 +3,7 @@ from django.core.paginator import Paginator, PageNotAnInteger, EmptyPage
|
|||
|
||||
from six import text_type
|
||||
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.shortcuts import get_object_or_404
|
||||
|
||||
from wagtail.wagtailadmin.modal_workflow import render_modal_workflow
|
||||
|
@ -46,6 +47,7 @@ def chosen(request, content_type_app_name, content_type_model_name, id):
|
|||
snippet_json = json.dumps({
|
||||
'id': item.id,
|
||||
'string': text_type(item),
|
||||
'edit_link': reverse('wagtailsnippets_edit', args=(content_type_app_name, content_type_model_name, item.id,))
|
||||
})
|
||||
|
||||
return render_modal_workflow(
|
||||
|
|
|
@ -10,12 +10,13 @@ from wagtail.wagtailadmin.widgets import AdminChooser
|
|||
|
||||
class AdminSnippetChooser(AdminChooser):
|
||||
target_content_type = None
|
||||
|
||||
|
||||
def __init__(self, content_type=None, **kwargs):
|
||||
if 'snippet_type_name' in kwargs:
|
||||
snippet_type_name = kwargs.pop('snippet_type_name')
|
||||
self.choose_one_text = _('Choose %s') % snippet_type_name
|
||||
self.choose_another_text = _('Choose another %s') % snippet_type_name
|
||||
self.link_to_chosen_text = _('Edit this %s') % snippet_type_name
|
||||
|
||||
super(AdminSnippetChooser, self).__init__(**kwargs)
|
||||
if content_type is not None:
|
||||
|
|
Ładowanie…
Reference in New Issue