mirror of
https://github.com/wagtail/wagtail.git
synced 2024-12-01 11:41:20 +01:00
Merge branch 'feature/chooser-panel-edit-links-2' of https://github.com/davecranwell/wagtail into davecranwell-feature/chooser-panel-edit-links-2
This commit is contained in:
commit
32e78d5920
@ -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="{{ widget.link_to_chosen_url }}" class="edit-link button button-small button-secondary" target="_blank">{{ widget.link_to_chosen_text }}</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="unchosen">
|
||||
|
@ -41,6 +41,8 @@ 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_url = "#"
|
||||
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 +70,10 @@ 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')
|
||||
if 'link_to_chosen_url' in kwargs:
|
||||
self.link_to_chosen_url = kwargs.pop('link_to_chosen_url')
|
||||
super(AdminChooser, self).__init__(**kwargs)
|
||||
|
||||
|
||||
@ -75,6 +81,8 @@ class AdminPageChooser(AdminChooser):
|
||||
target_content_type = None
|
||||
choose_one_text = _('Choose a page')
|
||||
choose_another_text = _('Choose another page')
|
||||
link_to_chosen_url = "#"
|
||||
link_to_chosen_text = _('Edit this page')
|
||||
|
||||
def __init__(self, content_type=None, **kwargs):
|
||||
super(AdminPageChooser, self).__init__(**kwargs)
|
||||
@ -86,6 +94,11 @@ class AdminPageChooser(AdminChooser):
|
||||
model_class = self.target_content_type.model_class()
|
||||
instance = self.get_instance(model_class, value)
|
||||
|
||||
try:
|
||||
self.link_to_chosen_url = reverse('wagtailadmin_pages_edit', args=(instance.id,))
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
return render_to_string("wagtailadmin/widgets/page_chooser.html", {
|
||||
'widget': self,
|
||||
'original_field_html': original_field_html,
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -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()
|
||||
|
@ -2,6 +2,7 @@ from __future__ import absolute_import, unicode_literals
|
||||
|
||||
import json
|
||||
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.template.loader import render_to_string
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
@ -12,12 +13,19 @@ from wagtail.wagtaildocs.models import Document
|
||||
class AdminDocumentChooser(AdminChooser):
|
||||
choose_one_text = _('Choose a document')
|
||||
choose_another_text = _('Choose another document')
|
||||
link_to_chosen_url = "#"
|
||||
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)
|
||||
|
||||
instance = self.get_instance(Document, value)
|
||||
|
||||
try:
|
||||
self.link_to_chosen_url = reverse('wagtaildocs_edit_document', args=(instance.id,))
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
return render_to_string("wagtaildocs/widgets/document_chooser.html", {
|
||||
'widget': self,
|
||||
'original_field_html': original_field_html,
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -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,
|
||||
|
@ -2,6 +2,7 @@ from __future__ import absolute_import, unicode_literals
|
||||
|
||||
import json
|
||||
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.template.loader import render_to_string
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
@ -12,7 +13,8 @@ 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_url = "#"
|
||||
link_to_chosen_text = _('Edit this image')
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super(AdminImageChooser, self).__init__(**kwargs)
|
||||
@ -23,6 +25,11 @@ class AdminImageChooser(AdminChooser):
|
||||
|
||||
instance = self.get_instance(self.image_model, value)
|
||||
|
||||
try:
|
||||
self.link_to_chosen_url = reverse('wagtailimages_edit_image', args=(instance.id,))
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
return render_to_string("wagtailimages/widgets/image_chooser.html", {
|
||||
'widget': self,
|
||||
'original_field_html': original_field_html,
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -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(
|
||||
|
@ -2,6 +2,7 @@ from __future__ import absolute_import, unicode_literals
|
||||
|
||||
import json
|
||||
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.template.loader import render_to_string
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
@ -10,12 +11,14 @@ from wagtail.wagtailadmin.widgets import AdminChooser
|
||||
|
||||
class AdminSnippetChooser(AdminChooser):
|
||||
target_content_type = None
|
||||
|
||||
link_to_chosen_url = "#"
|
||||
|
||||
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:
|
||||
@ -27,6 +30,11 @@ class AdminSnippetChooser(AdminChooser):
|
||||
model_class = self.target_content_type.model_class()
|
||||
instance = self.get_instance(model_class, value)
|
||||
|
||||
try:
|
||||
self.link_to_chosen_url = reverse('wagtailsnippets_edit', args=(self.target_content_type.app_label, self.target_content_type, instance.id,))
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
return render_to_string("wagtailsnippets/widgets/snippet_chooser.html", {
|
||||
'widget': self,
|
||||
'original_field_html': original_field_html,
|
||||
|
Loading…
Reference in New Issue
Block a user