diff --git a/app/assets/javascripts/admin/utils/validate_click_form.js b/app/assets/javascripts/admin/utils/validate_click_form.js new file mode 100644 index 0000000000000000000000000000000000000000..c3e0bab8b708c8ed827052cf81525034e64079ed --- /dev/null +++ b/app/assets/javascripts/admin/utils/validate_click_form.js @@ -0,0 +1,46 @@ +/* global $ */ +window.osuny.validateFromClickManager = { + init: function () { + 'use strict'; + + this.elements = document.querySelectorAll('.js-validate-form-click'); + + if (this.elements.length > 0) { + this.listen(); + } + }, + + listen: function() { + 'use strict'; + + this.elements.forEach(function(element) { + this.bindClick(element) + }.bind(this)); + }, + + bindClick: function(element) { + 'use strict'; + var form = element.querySelector('form'); + + if (!form) { + return; + } + + element.style.cursor = "pointer" + element.addEventListener('click', function() { + form.submit(); + }); + }, + + invoke: function () { + 'use strict'; + return { + init: this.init.bind(this) + }; + } +}.invoke(); + +window.addEventListener('DOMContentLoaded', function () { + 'use strict'; + window.osuny.validateFromClickManager.init(); +}); diff --git a/app/views/admin/communication/blocks/new.html.erb b/app/views/admin/communication/blocks/new.html.erb index 7fdb0aa1d449ee07078f33f761f0beeddeb12f8f..0676c2d0960096517d7a76612bef496f318d783f 100644 --- a/app/views/admin/communication/blocks/new.html.erb +++ b/app/views/admin/communication/blocks/new.html.erb @@ -14,7 +14,7 @@ %> <% next unless template.allowed_for_about? %> <div class="col-xxl-2 col-lg-3 col-md-4 d-flex"> - <div class="<%= 'card' if current_admin_theme == 'appstack' %> flex-fill position-relative"> + <div class="<%= 'card' if current_admin_theme == 'appstack' %> flex-fill position-relative js-validate-form-click"> <%= image_tag "communication/blocks/templates/#{kind}.jpg", alt: '', class:"card-img-top block__image" %> <div class="<%= 'card-body' if current_admin_theme == 'appstack' %>"> <h3 class="h4 block__title"><%= t "enums.communication.block.template_kind.#{kind}" %></h4>