Finish redactions app
Signed-off-by: Roberto Rosario <roberto.rosario@mayan-edms.com>
This commit is contained in:
@@ -18,22 +18,10 @@
|
||||
.cropper-main img {
|
||||
max-width: 100%;
|
||||
}
|
||||
/*
|
||||
.cropper-preview {
|
||||
width: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.cropper-preview img {
|
||||
max-width: 100%;
|
||||
}
|
||||
*/
|
||||
</style>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div id="cropper-result"></div>
|
||||
|
||||
<div class="cropper-main">
|
||||
<img src="{{ document_page.get_api_image_url }}">
|
||||
</div>
|
||||
@@ -52,6 +40,36 @@
|
||||
var containerData;
|
||||
var $image = $('.cropper-main img');
|
||||
var cropperInstance;
|
||||
var defaultArguments = {
|
||||
left: 10,
|
||||
top: 10,
|
||||
right: 10,
|
||||
bottom: 10,
|
||||
fillcolor: '#000000',
|
||||
}
|
||||
var initialArguments = JSON.parse($('#id_arguments').text() || JSON.stringify(defaultArguments));
|
||||
|
||||
var callbackCrop = function (data) {
|
||||
var crop_left = (data.detail.x / pic_real_width * 100).toFixed(2);
|
||||
var crop_top = (data.detail.y / pic_real_height * 100).toFixed(2);
|
||||
var crop_right = (100.001 - (data.detail.x + data.detail.width) / pic_real_width * 100).toFixed(2);
|
||||
var crop_bottom = (100.001 - (data.detail.y + data.detail.height) / pic_real_height * 100).toFixed(2);
|
||||
|
||||
var arguments = {
|
||||
'left': parseFloat(crop_left),
|
||||
'top': parseFloat(crop_top),
|
||||
'right': parseFloat(crop_right),
|
||||
'bottom': parseFloat(crop_bottom),
|
||||
'fillcolor': '#000000',
|
||||
}
|
||||
|
||||
$('#id_arguments').text(JSON.stringify(arguments));
|
||||
}
|
||||
|
||||
jQuery(document).ready(function() {
|
||||
$('.help-block').hide();
|
||||
$('label').hide();
|
||||
});
|
||||
|
||||
$.getScript("{% static 'redactions/node_modules/cropperjs/dist/cropper.js' %}")
|
||||
.done(function (script, textStatus) {
|
||||
@@ -65,45 +83,22 @@
|
||||
.on('load', function () {
|
||||
pic_real_width = this.width;
|
||||
pic_real_height = this.height;
|
||||
console.log('loaded');
|
||||
});
|
||||
|
||||
cropperInstance = $image.cropper({
|
||||
crop: function (data) {
|
||||
crop_left = (data.detail.x / pic_real_width * 100).toFixed(2);
|
||||
crop_top = (data.detail.y / pic_real_height * 100).toFixed(2);
|
||||
crop_right = (100.001 - (data.detail.x + data.detail.width) / pic_real_width * 100).toFixed(2);
|
||||
crop_bottom = (100.001 - (data.detail.y + data.detail.height) / pic_real_height * 100).toFixed(2);
|
||||
|
||||
$('#id_left').val(crop_left);
|
||||
$('#id_top').val(crop_top);
|
||||
$('#id_right').val(crop_right);
|
||||
$('#id_bottom').val(crop_bottom);
|
||||
|
||||
var arguments = {
|
||||
'left': crop_left,
|
||||
'top': crop_top,
|
||||
'right': crop_right,
|
||||
'bottom': crop_bottom,
|
||||
'fillcolor': '#000000',
|
||||
}
|
||||
|
||||
//$('#id_arguments').text(JSON.stringify(arguments));
|
||||
},
|
||||
crop: callbackCrop,
|
||||
mouseWheelZoom: false,
|
||||
movable: false,
|
||||
//preview: '.cropper-preview',
|
||||
ready: function () {
|
||||
canvasData = $image.cropper('getCanvasData');
|
||||
containerData = $image.cropper('getContainerData');
|
||||
var arguments = JSON.parse($('#id_arguments').text());
|
||||
console.log(arguments);
|
||||
|
||||
$image.cropper('setCropBoxData', {
|
||||
left: Math.round(arguments.left / 100.0 * canvasData.width + canvasData.left),
|
||||
top: Math.round(arguments.top / 100.0 * canvasData.height + canvasData.top),// + canvasData.top),
|
||||
width: Math.round((100.0 - arguments.right - arguments.left) / 100.0 * canvasData.width),// + canvasData.left,
|
||||
height: Math.round((100.0 - arguments.bottom - arguments.top) / 100.0 * canvasData.height),// + canvasData.top),
|
||||
left: initialArguments.left / 100.0 * canvasData.width + canvasData.left,
|
||||
top: initialArguments.top / 100.0 * canvasData.height + canvasData.top,
|
||||
width: (100.0 - initialArguments.right - initialArguments.left) / 100.0 * canvasData.width,
|
||||
height: (100.0 - initialArguments.bottom - initialArguments.top) / 100.0 * canvasData.height,
|
||||
});
|
||||
},
|
||||
rotatable: false,
|
||||
|
||||
Reference in New Issue
Block a user