diff --git a/app/controllers/templates_controller.rb b/app/controllers/templates_controller.rb index 742ce33..448b9e2 100644 --- a/app/controllers/templates_controller.rb +++ b/app/controllers/templates_controller.rb @@ -323,4 +323,28 @@ @current = Template.current(@template.dmptemplate_id) end + # PUT /org/admin/templates/:id/admin_copy + # ----------------------------------------------------- + def admin_copy + @template = Template.find(params[:id]) + authorize @template + + new_copy = Template.deep_copy(@template) + new_copy.title = "Copy of " + @template.title + new_copy.version = 0 + new_copy.published = false + new_copy.dmptemplate_id = loop do + random = rand 2147483647 + break random unless Template.exists?(dmptemplate_id: random) + end + + if new_copy.save + flash[:notice] = 'Template was successfully copied.' + redirect_to admin_template_template_path(id: new_copy.id, edit: true), notice: _('Information was successfully created.') + else + flash[:alert] = failed_create_error(new_copy, _('template')) + end + + end + end diff --git a/app/policies/template_policy.rb b/app/policies/template_policy.rb index 754e622..006ed23 100644 --- a/app/policies/template_policy.rb +++ b/app/policies/template_policy.rb @@ -57,6 +57,9 @@ user.can_modify_templates? end + def admin_copy? + user.can_modify_templates? && (template.org_id == user.org_id) + end class Scope < Scope def resolve @@ -64,4 +67,4 @@ end end -end \ No newline at end of file +end diff --git a/app/views/contact_us/contacts/new.html.erb b/app/views/contact_us/contacts/new.html.erb index 05ceef9..985a32f 100644 --- a/app/views/contact_us/contacts/new.html.erb +++ b/app/views/contact_us/contacts/new.html.erb @@ -16,36 +16,31 @@
<% if ContactUs.require_name %>
- - /> + <%= f.label(:name, _('Name')+'*') %> + <%= f.text_field(:name, class: "left-indent required input-large", value: current_user.nil? ? '' : current_user.name(false), readonly: !current_user.nil?) %>
<% end %>
- - /> + <%= f.label(:email, _('Email')+'*') %> + <%= f.text_field(:email, class: "left-indent required input-large", value: current_user.nil? ? '' : current_user.email, readonly: !current_user.nil?) %>
<% if ContactUs.require_subject %>
- - + <%= f.label(:subject, _('Subject')+'*') %> + <%= f.text_field(:subject, class: "left-indent required input-large") %>
<% end %>
- - + <%= f.label(:message, _('Message')+'*', class: "align-top") %> + <%= f.text_area(:message, class: "left-indent required input-large", rows: 10) %>
- <% if !user_signed_in? then %>
- + <%= label_tag(nil, _('Security check')+'*', class: "align-top") %>
<%= recaptcha_tags %>
diff --git a/app/views/templates/admin_index.html.erb b/app/views/templates/admin_index.html.erb index ee4c3b5..ac225c7 100644 --- a/app/views/templates/admin_index.html.erb +++ b/app/views/templates/admin_index.html.erb @@ -63,6 +63,7 @@ <% else %>
<%= link_to _('Unpublish'), admin_unpublish_template_path(hash[:current]), method: :put, class: "dmp_table_link" %> <% end %> + <%= link_to _('Copy'), admin_copy_template_path(id: hash[:current].id), method: :put, class: "dmp_table_link" %> <% end %> diff --git a/config/routes.rb b/config/routes.rb index 4cea84f..65b9185 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -137,6 +137,7 @@ put 'admin_update' put 'admin_publish' put 'admin_unpublish' + put 'admin_copy' get 'admin_transfer_customization' end end diff --git a/lib/assets/javascripts/dmproadmap/forms.js b/lib/assets/javascripts/dmproadmap/forms.js index 5434b52..4cfa730 100644 --- a/lib/assets/javascripts/dmproadmap/forms.js +++ b/lib/assets/javascripts/dmproadmap/forms.js @@ -49,7 +49,7 @@ // --------------------------------------------------------------------------- function validateEmail(sEmail) { - var filter = /^[a-zA-Z0-9]+[a-zA-Z0-9_.-]+[a-zA-Z0-9_-]+@[a-zA-Z0-9]+[a-zA-Z0-9.-]+.[a-z]{2,4}$/; + var filter = /[^@\s]+@(?:[-a-z0-9]+\.)+[a-z]{2,}$/; if(filter.test(sEmail)){ return ''; }else{ diff --git a/lib/assets/javascripts/views/contacts/new_contact.js b/lib/assets/javascripts/views/contacts/new_contact.js index 3127eb2..43f6d84 100644 --- a/lib/assets/javascripts/views/contacts/new_contact.js +++ b/lib/assets/javascripts/views/contacts/new_contact.js @@ -10,16 +10,16 @@ $("input[type='text'], input[type='email'], textarea").change(function(e){ var enable = ($("#contact_us_contact_name").val().trim().length > 0 && - validateEmail($("#contact_us_contact_email").val().trim()) != '' && + validateEmail($("#contact_us_contact_email").val().trim()) === '' && $("#contact_us_contact_subject").val().trim().length > 0 && $("#contact_us_contact_message").val().trim().length > 0); - // Check the recaptcha status - if($("#recaptcha-anchor")){ - if($("#recaptcha-anchor").prop('aria-checked') != 'true'){ - enable = false; - } - } + // Disabled recaptcha since always sets enable, TODO change when we tackle https://github.com/DMPRoadmap/roadmap/issues/501 + // if($("#recaptcha-anchor")){ + // if($("#recaptcha-anchor").prop('aria-checked') != 'true'){ + // enable = false; + // } + // } $("#create_contact_submit").attr('aria-disabled', !enable); }); }); \ No newline at end of file