pagemedia.html.twig 5.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. {% extends "forms/field.html.twig" %}
  2. {% block field %}
  3. {% set value = (value is null ? field.default : value) %}
  4. {% set pagemedia = config.get('plugins.admin.pagemedia') %}
  5. {% set pagemedia_settings = {
  6. resolution: {
  7. min: {
  8. width: pagemedia.res_min_width ?: null,
  9. height: pagemedia.res_min_height ?: null
  10. },
  11. max: {
  12. width: pagemedia.res_max_width ?: null,
  13. height: pagemedia.res_max_height ?: null
  14. }
  15. },
  16. resizeWidth: pagemedia.resize_width ?: null,
  17. resizeHeight: pagemedia.resize_height ?: null,
  18. resizeQuality: pagemedia.resize_quality ?: 0.8
  19. } %}
  20. {% set route = admin ? admin.route : grav.uri.route() %}
  21. <div class="pagemedia-field form-field grid vertical {% if field.classes is defined %}{{ field.classes }}{% endif %}">
  22. <div class="form-label">
  23. <label class="media-collapser">
  24. <i class="fa fa-fw small fa-chevron-{{ pageMediaStore.collapsed ? 'right' : 'down' }}"></i>
  25. {{ field.label|t }} <span data-pagemedia-count>({{ admin.page.media|length }})</span>
  26. </label>
  27. <div class="{{ pageMediaStore.collapsed ? 'hidden' : '' }}">
  28. <input type="range" min="70" step="10" max="200" value="{{ pageMediaStore.width }}" class="media-resizer">
  29. </div>
  30. </div>
  31. <div class="form-data form-uploads-wrapper">
  32. {% set uploadLimit = grav.config.system.media.upload_limit / 1024 / 1024 %}
  33. {% set dropzoneSettings = { maxFilesize: uploadLimit }|merge(pagemedia_settings) %}
  34. <div id="grav-dropzone"
  35. class="form-input-file dropzone"
  36. {% if admin %}
  37. data-media-url="{{ base_url }}/media/{{ route|trim('/') }}.json"
  38. data-media-local="{{ base_url_relative_frontend|rtrim('/') }}/{{ route|trim('/') }}"
  39. data-media-path="{{ url(context.relativePagePath) }}"
  40. data-media-uri="{{ context.mediaUri }}"
  41. data-dropzone-options="{{ dropzoneSettings|json_encode|e('html_attr') }}"
  42. data-dropzone-field="{{ (scope ~ field.name)|fieldName }}"
  43. {% else %}
  44. data-media-url="{{ base_url }}/{{ route|trim('/') }}.json"
  45. data-dropzone-options="{{ dropzoneSettings|json_encode|e('html_attr') }}"
  46. data-dropzone-field="{{ (scope ~ field.name)|fieldName }}"
  47. {% endif %}
  48. ></div>
  49. {% if not admin or admin.session.expert == '0' %}
  50. <input type="hidden" name="{{ (scope ~ field.name)|fieldName }}" value="{{ value|e }}" />
  51. {% endif %}
  52. </div>
  53. </div>
  54. {% if grav.browser.browser == 'msie' and grav.browser.version < 12 %}
  55. {% do assets.addJs('plugin://form/assets/object.assign.polyfill.js') %}
  56. {% endif %}
  57. {% do assets.addJs('jquery', 101) %}
  58. {% do assets.addJs('plugin://form/assets/form.vendor.js', { 'loading': 'defer', 'group': 'bottom' }) %}
  59. {% do assets.addJs('plugin://form/assets/form.min.js', { 'loading': 'defer', 'group': 'bottom' }) %}
  60. {% do assets.addCss('plugin://form/assets/dropzone.min.css', { 'group': 'form'}) %}
  61. {{ assets.css('form')|raw }}
  62. {% do assets.addInlineJs("
  63. window.GravForm = window.GravForm || {};
  64. window.GravForm = Object.assign({}, window.GravForm, {
  65. translations: {
  66. PLUGIN_FORM: {
  67. 'DROPZONE_CANCEL_UPLOAD': " ~ 'PLUGIN_FORM.DROPZONE_CANCEL_UPLOAD'|t|json_encode ~ ",
  68. 'DROPZONE_CANCEL_UPLOAD_CONFIRMATION': " ~ 'PLUGIN_FORM.DROPZONE_CANCEL_UPLOAD_CONFIRMATION'|t|json_encode ~ ",
  69. 'DROPZONE_DEFAULT_MESSAGE': " ~ 'PLUGIN_FORM.DROPZONE_DEFAULT_MESSAGE'|t|json_encode ~ ",
  70. 'DROPZONE_FALLBACK_MESSAGE': " ~ 'PLUGIN_FORM.DROPZONE_FALLBACK_MESSAGE'|t|json_encode ~ ",
  71. 'DROPZONE_FALLBACK_TEXT': " ~ 'PLUGIN_FORM.DROPZONE_FALLBACK_TEXT'|t|json_encode ~ ",
  72. 'DROPZONE_FILE_TOO_BIG': " ~ 'PLUGIN_FORM.DROPZONE_FILE_TOO_BIG'|t|json_encode ~ ",
  73. 'DROPZONE_INVALID_FILE_TYPE': " ~ 'PLUGIN_FORM.DROPZONE_INVALID_FILE_TYPE'|t|json_encode ~ ",
  74. 'DROPZONE_MAX_FILES_EXCEEDED': " ~ 'PLUGIN_FORM.DROPZONE_MAX_FILES_EXCEEDED'|t|json_encode ~ ",
  75. 'DROPZONE_REMOVE_FILE': " ~ 'PLUGIN_FORM.DROPZONE_REMOVE_FILE'|t|json_encode ~ ",
  76. 'DROPZONE_REMOVE_FILE_CONFIRMATION': " ~ 'PLUGIN_FORM.DROPZONE_REMOVE_FILE_CONFIRMATION'|t|json_encode ~ ",
  77. 'DROPZONE_RESPONSE_ERROR': " ~ 'PLUGIN_FORM.DROPZONE_RESPONSE_ERROR'|t|json_encode ~ ",
  78. 'RESOLUTION_MIN': " ~ 'PLUGIN_FORM.RESOLUTION_MIN'|t|json_encode ~ ",
  79. 'RESOLUTION_MAX': " ~ 'PLUGIN_FORM.RESOLUTION_MAX'|t|json_encode ~ "
  80. }
  81. }
  82. });
  83. ", { 'group': 'bottom', 'position': 'before' }) %}
  84. {% if not config.flex.pagemedia.dropzone.template %}
  85. {% do config.set('flex.pagemedia.dropzone.template', true) %}
  86. <div id="dropzone-media-template" style="display:none;">
  87. {% include 'forms/fields/pagemedia/template.html.twig' %}
  88. </div>
  89. {% endif %}
  90. {% endblock %}