kopia lustrzana https://github.com/wagtail/wagtail
Removed focal point chooser modal and field
rodzic
f24a9240d3
commit
4daafb61a6
|
@ -1,6 +1,6 @@
|
|||
from django.conf.urls import url
|
||||
|
||||
from wagtail.wagtailimages.views import images, chooser, multiple, focal_point_chooser
|
||||
from wagtail.wagtailimages.views import images, chooser, multiple
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
|
@ -20,6 +20,4 @@ urlpatterns = [
|
|||
url(r'^chooser/(\d+)/$', chooser.image_chosen, name='wagtailimages_image_chosen'),
|
||||
url(r'^chooser/upload/$', chooser.chooser_upload, name='wagtailimages_chooser_upload'),
|
||||
url(r'^chooser/(\d+)/select_format/$', chooser.chooser_select_format, name='wagtailimages_chooser_select_format'),
|
||||
|
||||
url(r'focal_point_chooser/(\d+)/$', focal_point_chooser.chooser, name='wagtailimages_focal_point_chooser')
|
||||
]
|
||||
|
|
|
@ -97,10 +97,6 @@ $(function(){
|
|||
|
||||
// run tagit enhancement
|
||||
$('.tag_field input', itemElement).tagit(window.tagit_opts);
|
||||
|
||||
$('.focal-point-chooser', itemElement).each(function() {
|
||||
createFocalPointCooser($(this));
|
||||
});
|
||||
} else {
|
||||
itemElement.addClass('upload-failure');
|
||||
$('.right .error_messages', itemElement).append(response.error_message);
|
||||
|
|
|
@ -1,52 +1,5 @@
|
|||
function createFocalPointCooser($chooser) {
|
||||
var $chosenText = $('.chosen-text', $chooser);
|
||||
var $focalPointX = $('input.focal_point_x', $chooser);
|
||||
var $focalPointY = $('input.focal_point_y', $chooser);
|
||||
var $focalPointWidth = $('input.focal_point_width', $chooser);
|
||||
var $focalPointHeight = $('input.focal_point_height', $chooser);
|
||||
var chooserUrl = $chooser.data('chooserUrl');
|
||||
|
||||
$('.action-choose', $chooser).click(function() {
|
||||
if (!$chooser.hasClass('blank')) {
|
||||
window.focalPointChooserInitial = {
|
||||
x: $focalPointX.val(),
|
||||
y: $focalPointY.val(),
|
||||
w: $focalPointWidth.val(),
|
||||
h: $focalPointHeight.val(),
|
||||
}
|
||||
} else {
|
||||
window.focalPointChooserInitial = undefined;
|
||||
}
|
||||
|
||||
ModalWorkflow({
|
||||
'url': chooserUrl,
|
||||
'responses': {
|
||||
'focalPointChosen': function(focalPointData) {
|
||||
$focalPointX.val(focalPointData.x);
|
||||
$focalPointY.val(focalPointData.y);
|
||||
$focalPointWidth.val(focalPointData.w);
|
||||
$focalPointHeight.val(focalPointData.h);
|
||||
|
||||
$chosenText.text(focalPointData.x + ", " + focalPointData.y + " " + focalPointData.w + "x" + focalPointData.h);
|
||||
|
||||
$chooser.removeClass('blank');
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$('.action-clear', $chooser).click(function() {
|
||||
$focalPointX.val('');
|
||||
$focalPointY.val('');
|
||||
$focalPointWidth.val('');
|
||||
$focalPointHeight.val('');
|
||||
|
||||
$chooser.addClass('blank');
|
||||
});
|
||||
}
|
||||
|
||||
$(function() {
|
||||
$('.focal-point-chooser').each(function() {
|
||||
createFocalPointCooser($(this));
|
||||
$('img.focal-point-chooser').each(function() {
|
||||
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
{% load wagtailimages_tags i18n %}
|
||||
|
||||
{% trans "Choose focal point" as title_str %}
|
||||
{% include "wagtailadmin/shared/header.html" with title=title_str %}
|
||||
|
||||
<div class="nice-padding">
|
||||
<div class="focal-point-chooser-image">
|
||||
{% image image max-800x600 %}
|
||||
</div>
|
||||
<a class="choose-focal-point button buttom-secondary" href="#">Done</a>
|
||||
</div>
|
|
@ -1,67 +0,0 @@
|
|||
function(modal) {
|
||||
var jcapi;
|
||||
|
||||
function ajaxifyLinks (context) {
|
||||
$('.listing a', context).click(function() {
|
||||
modal.loadUrl(this.href);
|
||||
return false;
|
||||
});
|
||||
|
||||
$('.pagination a', context).click(function() {
|
||||
var page = this.getAttribute("data-page");
|
||||
setPage(page);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
ajaxifyLinks(modal.body);
|
||||
|
||||
// Find image element
|
||||
var $image = $('.focal-point-chooser-image img');
|
||||
|
||||
// Switch on Jcrop
|
||||
$image.Jcrop({}, function() {
|
||||
jcapi = this;
|
||||
});
|
||||
|
||||
// Set initial select box
|
||||
if (window.focalPointChooserInitial) {
|
||||
var scaleX = {{ image.width }} / $image.width();
|
||||
var scaleY = {{ image.height }} / $image.height();
|
||||
|
||||
var x = window.focalPointChooserInitial.x / scaleX;
|
||||
var y = window.focalPointChooserInitial.y / scaleY;
|
||||
var w = window.focalPointChooserInitial.w / scaleX;
|
||||
var h = window.focalPointChooserInitial.h / scaleY;
|
||||
|
||||
jcapi.setSelect([
|
||||
x - w / 2,
|
||||
y - h / 2,
|
||||
x + w / 2,
|
||||
y + h / 2,
|
||||
]);
|
||||
}
|
||||
|
||||
$('a.choose-focal-point', modal.body).click(function() {
|
||||
var selectBox = jcapi.tellSelect();
|
||||
var scaleX = {{ image.width }} / $image.width();
|
||||
var scaleY = {{ image.height }} / $image.height();
|
||||
|
||||
modal.respond('focalPointChosen', {
|
||||
x: Math.floor(scaleX * (selectBox.x + selectBox.x2) / 2),
|
||||
y: Math.floor(scaleY * (selectBox.y + selectBox.y2) / 2),
|
||||
w: Math.floor(scaleX * selectBox.w),
|
||||
h: Math.floor(scaleY * selectBox.h),
|
||||
});
|
||||
|
||||
modal.close();
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
$('#id_q').on('input', function() {
|
||||
clearTimeout($.data(this, 'timer'));
|
||||
var wait = setTimeout(search, 200);
|
||||
$(this).data('timer', wait);
|
||||
});
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
{% load wagtailadmin_tags i18n %}
|
||||
|
||||
<div class="field">
|
||||
<label>{% trans "Focal point" %}</label>
|
||||
<div class="field-content">
|
||||
<div class="input">
|
||||
|
||||
<div class="chooser focal-point-chooser{% if not image.focal_point %} blank{% endif %}" data-chooser-url="{% url 'wagtailimages_focal_point_chooser' image.id %}">
|
||||
<div class="chosen">
|
||||
<div class="chosen-text">
|
||||
{% if image.focal_point %}
|
||||
{{ image.focal_point_x }}, {{ image.focal_point_y }} {{ image.focal_point_width }}x{{ image.focal_point_height }}
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="actions">
|
||||
<input type="button" class="action-clear button-small button-secondary" value="{% trans "Clear" %}">
|
||||
<input type="button" class="action-choose button-small button-secondary" value="{% trans "Change" %}">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="unchosen">
|
||||
<div class="unchosen-text">{% trans "Not set" %}</div>
|
||||
<input type="button" class="action-choose button-small button-secondary" value="{% trans "Set" %}">
|
||||
</div>
|
||||
|
||||
{{ form.focal_point_x }}
|
||||
{{ form.focal_point_y }}
|
||||
{{ form.focal_point_width }}
|
||||
{{ form.focal_point_height }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p class="help"></p>
|
||||
|
||||
{% if field.errors %}
|
||||
<p class="error-message">
|
||||
<span>Invalid input</span>
|
||||
</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
|
@ -15,7 +15,6 @@
|
|||
|
||||
<!-- Focal point chooser -->
|
||||
<script src="{{ STATIC_URL }}wagtailimages/js/vendor/jquery.Jcrop.min.js"></script>
|
||||
<script src="{{ STATIC_URL }}wagtailadmin/js/modal-workflow.js"></script>
|
||||
<script src="{{ STATIC_URL }}wagtailimages/js/focal-point-chooser.js"></script>
|
||||
{% endblock %}
|
||||
|
||||
|
@ -33,10 +32,6 @@
|
|||
|
||||
{% if field.name == 'file' %}
|
||||
{% include "wagtailimages/images/_file_field.html" %}
|
||||
{% elif field.name == 'focal_point_x' %}
|
||||
{% include "wagtailimages/images/_focal_point_chooser.html" %}
|
||||
{% elif field.name == 'focal_point_y' or field.name == 'focal_point_width' or field.name == 'focal_point_height' %}
|
||||
{# These fields are included in the focal point chooser above #}
|
||||
{% elif field.is_hidden %}
|
||||
{{ field }}
|
||||
{% else %}
|
||||
|
@ -49,7 +44,7 @@
|
|||
</form>
|
||||
</div>
|
||||
<div class="col5">
|
||||
{% image image max-800x600 %}
|
||||
{% image image max-800x600 class="focal-point-chooser" %}
|
||||
|
||||
{% if url_generator_enabled %}
|
||||
<a href="{% url 'wagtailimages_url_generator' image.id %}" class="button bicolor icon icon-link">URL Generator</a>
|
||||
|
|
|
@ -7,9 +7,6 @@
|
|||
<link rel="stylesheet" href="{{ STATIC_URL }}wagtailimages/scss/add-multiple.scss" type="text/x-scss" />
|
||||
{% endcompress %}
|
||||
{% include "wagtailadmin/shared/tag_field_css.html" %}
|
||||
|
||||
<!-- Focal point chooser -->
|
||||
<link rel="stylesheet" href="{{ STATIC_URL }}wagtailimages/scss/vendor/jquery.Jcrop.min.css" type="text/css">
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
@ -66,11 +63,6 @@
|
|||
<script src="{{ STATIC_URL }}wagtailimages/js/vendor/jquery.fileupload-image.js"></script>
|
||||
<script src="{{ STATIC_URL }}wagtailadmin/js/vendor/tag-it.js"></script>
|
||||
|
||||
<!-- Focal point chooser -->
|
||||
<script src="{{ STATIC_URL }}wagtailimages/js/vendor/jquery.Jcrop.min.js"></script>
|
||||
<script src="{{ STATIC_URL }}wagtailadmin/js/modal-workflow.js"></script>
|
||||
<script src="{{ STATIC_URL }}wagtailimages/js/focal-point-chooser.js"></script>
|
||||
|
||||
<!-- Main script -->
|
||||
<script src="{{ STATIC_URL }}wagtailimages/js/add-multiple.js"></script>
|
||||
{% endcompress %}
|
||||
|
|
|
@ -4,11 +4,7 @@
|
|||
<ul class="fields">
|
||||
{% csrf_token %}
|
||||
{% for field in form %}
|
||||
{% if field.name == 'focal_point_x' %}
|
||||
{% include "wagtailimages/images/_focal_point_chooser.html" %}
|
||||
{% elif field.name == 'focal_point_y' or field.name == 'focal_point_width' or field.name == 'focal_point_height' %}
|
||||
{# These fields are included in the focal point chooser above #}
|
||||
{% elif field.is_hidden %}
|
||||
{% if field.is_hidden %}
|
||||
{{ field }}
|
||||
{% else %}
|
||||
{% include "wagtailadmin/shared/field_as_li.html" %}
|
||||
|
|
|
@ -1036,54 +1036,3 @@ class TestIssue573(TestCase):
|
|||
# Try creating a rendition from that image
|
||||
# This would crash if the bug is present
|
||||
image.get_rendition('fill-800x600')
|
||||
|
||||
|
||||
class TestFocalPointChooserView(TestCase, WagtailTestUtils):
|
||||
def setUp(self):
|
||||
# Create an image for running tests on
|
||||
self.image = Image.objects.create(
|
||||
title="Test image",
|
||||
file=get_test_image_file(),
|
||||
)
|
||||
|
||||
# Login
|
||||
self.user = self.login()
|
||||
|
||||
def test_get(self):
|
||||
"""
|
||||
This tests that the view responds correctly for a user with edit permissions on this image
|
||||
"""
|
||||
# Get
|
||||
response = self.client.get(reverse('wagtailimages_focal_point_chooser', args=(self.image.id, )))
|
||||
|
||||
# Check response
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertTemplateUsed(response, 'wagtailimages/focal_point_chooser/chooser.html')
|
||||
self.assertTemplateUsed(response, 'wagtailimages/focal_point_chooser/chooser.js')
|
||||
|
||||
def test_get_bad_permissions(self):
|
||||
"""
|
||||
This tests that the view gives a 403 if a user without correct permissions attempts to access it
|
||||
"""
|
||||
# Remove privileges from user
|
||||
self.user.is_superuser = False
|
||||
self.user.user_permissions.add(
|
||||
Permission.objects.get(content_type__app_label='wagtailadmin', codename='access_admin')
|
||||
)
|
||||
self.user.save()
|
||||
|
||||
# Get
|
||||
response = self.client.get(reverse('wagtailimages_focal_point_chooser', args=(self.image.id, )))
|
||||
|
||||
# Check response
|
||||
self.assertEqual(response.status_code, 403)
|
||||
|
||||
def test_get_bad_image(self):
|
||||
"""
|
||||
This tests that the view gives a 404 if the image doesn't exist
|
||||
"""
|
||||
# Get
|
||||
response = self.client.get(reverse('wagtailimages_focal_point_chooser', args=(9999, )))
|
||||
|
||||
# Check response
|
||||
self.assertEqual(response.status_code, 404)
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
from django.shortcuts import get_object_or_404
|
||||
from django.contrib.auth.decorators import permission_required
|
||||
from django.core.exceptions import PermissionDenied
|
||||
|
||||
from wagtail.wagtailadmin.modal_workflow import render_modal_workflow
|
||||
from wagtail.wagtailimages.models import get_image_model
|
||||
|
||||
|
||||
@permission_required('wagtailadmin.access_admin')
|
||||
def chooser(request, image_id):
|
||||
image = get_object_or_404(get_image_model(), id=image_id)
|
||||
|
||||
if not image.is_editable_by_user(request.user):
|
||||
raise PermissionDenied
|
||||
|
||||
return render_modal_workflow(request, 'wagtailimages/focal_point_chooser/chooser.html', 'wagtailimages/focal_point_chooser/chooser.js', {
|
||||
'image': image,
|
||||
})
|
Ładowanie…
Reference in New Issue