<script>
$(document).ready(function(){
// jquery del dropzone
try {
Dropzone.autoDiscover = false;
var rejectDimensions;
var acceptDimensions;
var myDropzone = new Dropzone("#dropzone_{{ routeClassName }}_{{ field }}" , {
paramName: "file", // The name that will be used to transfer the file
maxFilesize: 2.5, // MB
maxFiles: 1,
addRemoveLinks : true,
removedfile: function(file) {
jConfirm('{% trans from 'crud' %}delete.confirm{% endtrans %}', 'Alerta', function(r) {
if (r)
{
var deleteUrl = '{{ path('dropzone_single_delete', {'routeClassName': routeClassName, 'id': '__ID__', 'field': field,}) }}';
deleteUrl = deleteUrl.replace('__ID__',file.id);
$.getJSON(deleteUrl, function(data) {
myDropzone.options.maxFiles += 1;
});
var _ref;
return (_ref = file.previewElement) != null ? _ref.parentNode.removeChild(file.previewElement) : void 0;
}
});
},
success: function(file) {
myDropzone.options.maxFiles -= 1;
if (file.previewElement) {
//var param = "'"+file.name+"'";
//$(file.previewElement).append('<a class="dz-description" href="" onclick="javascript:editDescripcion('+file.id+'); return false;">DescripciĆ³n</a>');
return file.previewElement.classList.add("dz-success");
}
},
thumbnail: function(file, dataUrl) {
var thumbnailElement, _i, _len, _ref, _results;
if (file.previewElement)
{
file.previewElement.classList.remove("dz-file-preview");
file.previewElement.classList.add("dz-image-preview");
_ref = file.previewElement.querySelectorAll("[data-dz-thumbnail]");
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++)
{
thumbnailElement = _ref[_i];
thumbnailElement.alt = file.name;
_results.push(thumbnailElement.src = dataUrl);
}
{% if ratio is defined %}
if (file.width / file.height < {{ ratio }}-0.01 || file.width / file.height > {{ ratio }}+0.01)
{
file.previewElement.classList.remove("dz-success");
file.previewElement.classList.add("dz-error");
var w;
w=$(file.previewElement).children('.dz-error-message').children('span');
w.attr('data-dz-errormessage','ASPECT RATIO');
w.html('ASPECT RATIO');
}
{% endif %}
return _results;
}
},
dictDefaultMessage :
'<span class="bigger-150 bolder"><i class="ace-icon fa fa-caret-right red"></i> Droap files</span> to upload \
<span class="smaller-80 grey">(or click)</span> <br /> \
<i class="upload-icon ace-icon fa fa-cloud-upload blue fa-3x"></i>',
dictResponseError: 'Error while uploading file!',
acceptedFiles: '{{ acceptedFiles }}{% if acceptedFiles == 'image' %}/*{% endif %} ',
//change the previewTemplate to use Bootstrap progress bars
previewTemplate: "<div class=\"dz-preview dz-file-preview\">\n <div class=\"dz-details\">\n <div class=\"dz-filename\"><span data-dz-name></span></div>\n <div class=\"dz-size\" data-dz-size></div>\n <img data-dz-thumbnail />\n </div>\n <div class=\"progress progress-small progress-striped active\"><div class=\"progress-bar progress-bar-success\" data-dz-uploadprogress></div></div>\n <div class=\"dz-success-mark\"><span></span></div>\n <div class=\"dz-error-mark\"><span></span></div>\n <div class=\"dz-error-message\"><span data-dz-errormessage></span></div>\n</div>"
});
//var existingFileCount = 0; // The number of files already uploaded
{% if entity.getFieldValue(field) %}
var mockFile = { name: "{{ entity.getFieldValue(field).archivo }}", size: {{ entity.getFieldValue(field).size }}, id: {{ entity.id }} };
myDropzone.options.addedfile.call(myDropzone, mockFile);
myDropzone.options.thumbnail.call(myDropzone, mockFile, "{{ absolute_url(entity.getFieldValue(field).getUrl()) }}");
myDropzone.options.success.call(myDropzone, mockFile);
myDropzone.options.maxFiles = 0;
{% endif %}
$(document).one('ajaxloadstart.page', function(e) {
try {
myDropzone.destroy();
} catch(e) {}
});
} catch(e)
{
alert('Dropzone.js does not support older browsers!');
}
$('.progress-small').addClass('hide');
});
</script>
{% block index %}
<div class="alert alert-info">
<strong>
<i class="ace-icon fa fa-upload bigger-150"></i>
{{ texto | upper }}
</strong>
<br>
</div>
{% if ratio is defined %}
<form id="dropzone_{{ routeClassName }}_{{ field }}" class="dropzone" action="{{ path('dropzone_single_upload', {'routeClassName': routeClassName, 'parentId': parentId, 'field': field, 'ratio': ratio }) }}" style="background-color: #d9edf7! important">
{% else %}
<form id="dropzone_{{ routeClassName }}_{{ field }}" class="dropzone" action="{{ path('dropzone_single_upload', {'routeClassName': routeClassName, 'parentId': parentId, 'field': field}) }}" style="background-color: #d9edf7! important">
{% endif %}
<div class="fallback">
<input name="file" type="file" />
</div>
<div class="dz-message">
</div>
</form>
<div id='dialog_descripcion_{{ routeClassName }}'></div>
<div id='dialog_{{ routeClassName }}'></div>
<script>
$(document).ready(function(){
function editDescripcion(fileId)
{
var baseSite = $('#baseSite').val();
var url = baseSite+"{{routeClassName}}/describir/foto/"+fileId;
$('#dialog_{{ routeClassName }}').parent().mask(" Cargando...");
$('#dialog_{{ routeClassName }}').dialog('open');
$('#dialog_{{ routeClassName }}').load(url, function(){
$('#dialog_{{ routeClassName }}').parent().unmask();
});
}
});
</script>
{% endblock %}