src/Crud/templates/crud/dropZone_single.html.twig line 1

Open in your IDE?
  1. <script>
  2.     $(document).ready(function(){
  3.             // jquery del dropzone
  4.             try {
  5.                 Dropzone.autoDiscover = false;
  6.                 var rejectDimensions;
  7.                 var acceptDimensions;
  8.                 var myDropzone = new Dropzone("#dropzone_{{ routeClassName }}_{{ field }}" , {
  9.                                         paramName: "file", // The name that will be used to transfer the file
  10.                                         maxFilesize: 2.5, // MB
  11.                                         maxFiles: 1,
  12.                                         addRemoveLinks : true,
  13.                                         removedfile: function(file) {
  14.                                             
  15.                                             jConfirm('{% trans from 'crud' %}delete.confirm{% endtrans %}', 'Alerta', function(r) {
  16.                                                 if (r)
  17.                                                 {
  18.                                                     var deleteUrl = '{{ path('dropzone_single_delete', {'routeClassName': routeClassName, 'id': '__ID__', 'field': field,}) }}';
  19.                                                     deleteUrl = deleteUrl.replace('__ID__',file.id);
  20.                                                     $.getJSON(deleteUrl, function(data) {
  21.                                                         myDropzone.options.maxFiles += 1;
  22.                                                     });
  23.                                                     var _ref;
  24.                                                     return (_ref = file.previewElement) != null ? _ref.parentNode.removeChild(file.previewElement) : void 0; 
  25.                                                 }
  26.                                             });
  27.                                             
  28.                                         },
  29.                                         success: function(file) {
  30.                                             
  31.                                             myDropzone.options.maxFiles -= 1;
  32.                                             if (file.previewElement) {
  33.                                                 //var param = "'"+file.name+"'";
  34.                                                 //$(file.previewElement).append('<a class="dz-description" href="" onclick="javascript:editDescripcion('+file.id+'); return false;">DescripciĆ³n</a>');
  35.                                                 return file.previewElement.classList.add("dz-success");
  36.                                             }
  37.                                             
  38.                                         },
  39.                                         thumbnail: function(file, dataUrl) { 
  40.                                             var thumbnailElement, _i, _len, _ref, _results;
  41.                                             if (file.previewElement) 
  42.                                             {
  43.                                                 file.previewElement.classList.remove("dz-file-preview");
  44.                                                 file.previewElement.classList.add("dz-image-preview");
  45.                                                 _ref = file.previewElement.querySelectorAll("[data-dz-thumbnail]");
  46.                                                 _results = [];
  47.                                                 for (_i = 0, _len = _ref.length; _i < _len; _i++) 
  48.                                                 {
  49.                                                     thumbnailElement = _ref[_i];
  50.                                                     thumbnailElement.alt = file.name;
  51.                                                     _results.push(thumbnailElement.src = dataUrl);
  52.                                                 }
  53.                                                 {% if ratio is defined %}
  54.                                                     if (file.width / file.height < {{ ratio }}-0.01 || file.width / file.height > {{ ratio }}+0.01) 
  55.                                                     {
  56.                                                         file.previewElement.classList.remove("dz-success");
  57.                                                         file.previewElement.classList.add("dz-error");
  58.                                                         var w;
  59.                                                         w=$(file.previewElement).children('.dz-error-message').children('span');
  60.                                                         w.attr('data-dz-errormessage','ASPECT RATIO');
  61.                                                         w.html('ASPECT RATIO');
  62.                                                     }
  63.                                                 {% endif %}
  64.                                                 return _results;
  65.                                             } 
  66.                                         },
  67.                                         dictDefaultMessage :
  68.                         '<span class="bigger-150 bolder"><i class="ace-icon fa fa-caret-right red"></i> Droap files</span> to upload \
  69.                         <span class="smaller-80 grey">(or click)</span> <br /> \
  70.                         <i class="upload-icon ace-icon fa fa-cloud-upload blue fa-3x"></i>',
  71.                                         dictResponseError: 'Error while uploading file!',
  72.                                         acceptedFiles: '{{ acceptedFiles }}{% if acceptedFiles == 'image' %}/*{% endif %}  ',
  73.                                         //change the previewTemplate to use Bootstrap progress bars
  74.                                         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>"
  75.                 });
  76.                 //var existingFileCount = 0; // The number of files already uploaded
  77.                 {% if entity.getFieldValue(field) %}
  78.                     var mockFile = { name: "{{ entity.getFieldValue(field).archivo }}", size: {{ entity.getFieldValue(field).size }}, id: {{ entity.id }} };   
  79.                     myDropzone.options.addedfile.call(myDropzone, mockFile);
  80.                     myDropzone.options.thumbnail.call(myDropzone, mockFile, "{{ absolute_url(entity.getFieldValue(field).getUrl()) }}");
  81.                     myDropzone.options.success.call(myDropzone, mockFile);
  82.                     myDropzone.options.maxFiles = 0;
  83.                 {% endif %}
  84.                 $(document).one('ajaxloadstart.page', function(e) {
  85.                     try {
  86.                         myDropzone.destroy();
  87.                     } catch(e) {}
  88.                 });
  89.             } catch(e) 
  90.             {
  91.                 alert('Dropzone.js does not support older browsers!');
  92.             }
  93.             $('.progress-small').addClass('hide');
  94.     });
  95.     
  96. </script>
  97. {% block index %}
  98.     <div class="alert alert-info">
  99.         <strong>
  100.             <i class="ace-icon fa fa-upload bigger-150"></i>
  101.             {{ texto | upper }}
  102.         </strong>
  103.         <br>
  104.     </div>
  105.     {% if ratio is defined %}
  106.         <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">
  107.     {% else %}        
  108.         <form id="dropzone_{{ routeClassName }}_{{ field }}" class="dropzone" action="{{ path('dropzone_single_upload', {'routeClassName': routeClassName, 'parentId': parentId, 'field': field}) }}" style="background-color: #d9edf7! important">
  109.     {% endif %}        
  110.             <div class="fallback">
  111.                 <input name="file" type="file" />
  112.             </div>
  113.             <div class="dz-message">
  114.             </div>
  115.    
  116.         </form>
  117.                 
  118.     <div id='dialog_descripcion_{{ routeClassName }}'></div>
  119.     <div id='dialog_{{ routeClassName }}'></div>
  120.     <script>
  121.         $(document).ready(function(){
  122.             function editDescripcion(fileId)
  123.             {
  124.                 var baseSite = $('#baseSite').val();
  125.                 var url = baseSite+"{{routeClassName}}/describir/foto/"+fileId;
  126.                 $('#dialog_{{ routeClassName }}').parent().mask("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Cargando...");
  127.                 $('#dialog_{{ routeClassName }}').dialog('open');
  128.                 $('#dialog_{{ routeClassName }}').load(url, function(){
  129.                     $('#dialog_{{ routeClassName }}').parent().unmask();
  130.                 });
  131.             }
  132.         });
  133.     </script>        
  134. {% endblock %}