adding ability to link user to chosen page

pull/1014/head
Dave Cranwell 2015-02-19 17:25:33 +00:00
rodzic ab83e3b4a8
commit 82dc0ab2f6
5 zmienionych plików z 32 dodań i 6 usunięć

Wyświetl plik

@ -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);
}
}
});

Wyświetl plik

@ -655,6 +655,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; }

Wyświetl plik

@ -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 %}
@ -183,7 +183,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 %}

Wyświetl plik

@ -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">

Wyświetl plik

@ -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,