diff --git a/app/views/guidance_groups/_guidance_group_form.html.erb b/app/views/guidance_groups/_guidance_group_form.html.erb new file mode 100644 index 0000000..e64f904 --- /dev/null +++ b/app/views/guidance_groups/_guidance_group_form.html.erb @@ -0,0 +1,14 @@ +
+ <%= f.label _('Name'), for: :name, class: "control-label" %> + <%= f.text_field :name, as: :string, class: "form-control", 'data-toggle': 'tooltip', title: _('Add an appropriate name for your guidance group. This name will be used to tell the end user where the guidance has come from. It will be appended to text identifying the theme e.g. "[guidance group name]: guidance on data sharing" so we suggest you just use the institution or department name.'), 'aria-required': true %> +
+ +
+ <%= f.label :published, raw("#{f.check_box :published, 'data-toggle': 'tooltip', title: _('Check this box when you are ready for guidance associated with this group to appear on user\'s plans.')} #{_('Published')}") %> +
+ +
+ <%= f.label :optional_subset, raw("#{f.check_box :optional_subset, 'data-toggle': 'tooltip', title: _('If the guidance is only meant for a subset of users e.g. those in a specific college or institute, check this box. Users will be able to select to display this subset guidance when answering questions in the \'create plan\' wizard.')} #{_('Optional Subset (e.g. School/Department)')}") %> +
+ +<%= f.submit _('Save'), class: 'btn btn-primary' %> \ No newline at end of file diff --git a/app/views/guidance_groups/admin_edit.html.erb b/app/views/guidance_groups/admin_edit.html.erb index 42ad47d..64991f2 100644 --- a/app/views/guidance_groups/admin_edit.html.erb +++ b/app/views/guidance_groups/admin_edit.html.erb @@ -29,7 +29,6 @@ <%= f.submit _('Publish'), name: "save_publish", class: "btn btn-primary" %> <% end %> - <% end %> diff --git a/app/views/guidances/_guidance_form.html.erb b/app/views/guidances/_guidance_form.html.erb new file mode 100644 index 0000000..e484508 --- /dev/null +++ b/app/views/guidances/_guidance_form.html.erb @@ -0,0 +1,19 @@ +
+ <%= f.label :text, class: 'control-label' %> + <%= text_area_tag("guidance-text", guidance.text, class: "tinymce form-control", 'aria-required': true, rows: 10) %> +
+
+ <%= f.label _('Themes'), for: :theme_ids, class: 'control-label' %> + <%= f.collection_select(:theme_ids, themes, + :id, :title, {prompt: false, include_blank: 'None'}, {multiple: true, 'data-toggle': 'tooltip', title: _('Select which theme(s) this guidance relates to.'), class: 'form-control', 'aria-required': true}) %> +
+
+ <%= f.label _('Guidance group'), for: :guidance_group_id, class: 'control-label' %> + <%= f.collection_select(:guidance_group_id, guidance_groups, + :id, :name, {prompt: false, include_blank: 'None'}, {multiple: false, 'data-toggle': 'tooltip', title: _('Select which group this guidance relates to.'), class: 'form-control', 'aria-required': true})%> +
+
+ <%= f.label :published, raw("#{f.check_box :published, as: :check_boxes, 'data-toggle': 'tooltip', title: _("Check this box when you are ready for this guidance to appear on user's plans.")} #{_('Published?')}") %> +
+ +<%= f.submit _('Save'), name: "edit_guidance_submit", class: 'btn btn-primary' %> \ No newline at end of file diff --git a/app/views/guidances/admin_edit.html.erb b/app/views/guidances/admin_edit.html.erb index 6c27a87..60afa97 100644 --- a/app/views/guidances/admin_edit.html.erb +++ b/app/views/guidances/admin_edit.html.erb @@ -4,39 +4,9 @@
-
+
<%= form_for(@guidance, url: admin_update_guidance_path(@guidance), html: { method: :put , id: 'edit_guidance_form', class: 'roadmap-form bordered'}) do |f| %> -
-
- <%= f.label _('Text'), for: @guidance.text %> - <%= text_area_tag("guidance-text", @guidance.text, class: "tinymce") %> -
-
- <%= f.label _('Themes'), for: :theme_ids %> - <%= f.collection_select(:theme_ids, @themes, :id, :title, - {prompt: false, include_blank: 'None'}, {multiple: true, 'data-toggle': 'tooltip', title: _('Select which theme(s) this guidance relates to.')})%> -
-
- <%= f.label _('Published'), for: :published %> - <%= f.check_box :published , as: :check_boxes, 'data-toggle': 'tooltip', title: _("Check this box when you are ready for this guidance to appear on user's plans.") %> -
-
- <%= f.label _('Guidance group'), for: :guidance_group_id %> - <%= f.collection_select(:guidance_group_id, @guidance_groups, - :id, :name, {prompt: false, include_blank: 'None'}, {multiple: false, 'data-toggle': 'tooltip', title: _('Select which group this guidance relates to.')})%> -
- -
-
-
 
- -
-
+ <%= render partial: 'guidance_form', locals: { f: f, themes: @themes, guidance_groups: @guidance_groups, guidance: @guidance } %> <%end%>
- - - \ No newline at end of file diff --git a/app/views/guidances/admin_index.html.erb b/app/views/guidances/admin_index.html.erb index a740ba9..a290dff 100644 --- a/app/views/guidances/admin_index.html.erb +++ b/app/views/guidances/admin_index.html.erb @@ -15,14 +15,22 @@ <% if @guidance_groups.length > 0 then%>
- +
+ <% if @guidance_groups.length > TABLE_FILTER_MIN_ROWS %> + + + + <% end %> - + @@ -48,19 +56,19 @@ - <% end %> @@ -85,19 +93,20 @@ <% if @guidances.length > 0 then%>
-
+ <%= render(partial: "shared/table_filter", + locals: {path: admin_index_guidance_path(current_user.org_id), placeholder: _('Filter guidance groups')}) %> +
<%= _('Name') %> <%= _('Published') %> <%= _('Optional subset') %> <%= _('Last updated') %><%= _('Actions') %>
<%= l guidance_gr.updated_at.to_date, formats: :short %> - + + +
+
<% if @guidances.length > TABLE_FILTER_MIN_ROWS %> - <%= render(partial: "shared/table_filter", locals: {path: admin_index_guidance_path, placeholder: _('Filter guidance')}) %> + <%= render(partial: "shared/table_filter", + locals: {path: admin_index_guidance_path(current_user.org_id), placeholder: _('Filter guidance')}) %> <% end %> - - - - - + + + + diff --git a/app/views/guidances/admin_new.html.erb b/app/views/guidances/admin_new.html.erb index cefaf2f..7f2cd4f 100644 --- a/app/views/guidances/admin_new.html.erb +++ b/app/views/guidances/admin_new.html.erb @@ -5,39 +5,9 @@
-
- <%= form_for :guidance, url: {action: 'admin_create'}, html: {id: 'edit_guidance_form', class: 'roadmap-form bordered'} do |f| %> -
-
- <%= f.label :text %> - <%= text_area_tag("guidance-text", "", class: "tinymce") %> -
-
- <%= f.label _('Themes'), for: :theme_ids %> - <%= f.collection_select(:theme_ids, @themes, - :id, :title, {prompt: false, include_blank: 'None'}, {multiple: true, 'data-toggle': 'tooltip', title: _('Select which theme(s) this guidance relates to.')}) %> -
-
- <%= f.label :published %> - <%= f.check_box :published , as: :check_boxes, 'data-toggle': 'tooltip', title: _("Check this box when you are ready for this guidance to appear on user's plans.") %> -
-
- <%= f.label _('Guidance group'), for: :guidance_group_id %> - <%= f.collection_select(:guidance_group_id, @guidance_groups, - :id, :name, {prompt: false, include_blank: 'None'}, {multiple: false, 'data-toggle': 'tooltip', title: _('Select which group this guidance relates to.')})%> -
- -
-
-
 
- -
-
+
+ <%= form_for :guidance, url: {action: 'admin_create'}, html: {id: 'new_guidance_form'} do |f| %> + <%= render partial: 'guidance_form', locals: { f: f, themes: @themes, guidance_groups: @guidance_groups, guidance: @guidance } %> <% end %>
- - - \ No newline at end of file diff --git a/app/views/plans/new.html.erb b/app/views/plans/new.html.erb index af9500f..7c6f428 100644 --- a/app/views/plans/new.html.erb +++ b/app/views/plans/new.html.erb @@ -71,7 +71,6 @@ class: 'form-control', 'aria-describedby': 'template-selection') %>
- <%= _('Only one DMP template is available for those research and funding organisations.') %> <%= _('We found multiple DMP templates corresponding to your funder.') %>
diff --git a/lib/assets/javascripts/application.js b/lib/assets/javascripts/application.js index e53810c..94e863e 100644 --- a/lib/assets/javascripts/application.js +++ b/lib/assets/javascripts/application.js @@ -10,6 +10,10 @@ import './views/devise/passwords/edit'; import './views/devise/passwords/new'; import './views/devise/registrations/edit'; +import './views/guidance_groups/admin_edit'; +import './views/guidance_groups/admin_new'; +import './views/guidances/admin_edit'; +import './views/guidances/admin_new'; import './views/notes/index'; import './views/orgs/admin_edit'; import './views/orgs/shibboleth_ds'; diff --git a/lib/assets/javascripts/utils/ariatiseForm.js b/lib/assets/javascripts/utils/ariatiseForm.js index 1ecb370..41071cd 100644 --- a/lib/assets/javascripts/utils/ariatiseForm.js +++ b/lib/assets/javascripts/utils/ariatiseForm.js @@ -30,7 +30,7 @@ Example: `` */ - +import { Tinymce } from './tinymce'; import { isObject, isString, isBoolean } from './isType'; import * as constants from '../constants'; import * as validator from './isValidInputType'; @@ -77,6 +77,8 @@ return $(el).attr('type'); // available types at https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#Form__types } else if ($(el).is('select')) { return 'select'; + } else if ($(el).is('.tinymce')) { + return 'tinymce'; } else if ($(el).is('textarea')) { return 'textarea'; } @@ -88,6 +90,10 @@ switch (type) { case 'radio': return $(el).closest('form').find(`input[name="${$(el).attr('name')}"]:checked`).val(); + case 'select': + return $(el).find(':selected').val(); + case 'tinymce': + return Tinymce.findEditorById($(el).attr('id')).getContent(); default: return $(el).val(); } @@ -104,6 +110,8 @@ return validator.isValidText(value); case 'textarea': return validator.isValidText(value); + case 'tinymce': + return validator.isValidText(value); case 'number': return validator.isValidNumber(value); case 'email': @@ -112,6 +120,8 @@ return validator.isValidPassword(value); case 'radio': return validator.isValidText(value); + case 'select': + return validator.isValidText(value); case 'js-combobox': return validator.isValidText(value); default: diff --git a/lib/assets/javascripts/views/guidance_groups/admin_edit.js b/lib/assets/javascripts/views/guidance_groups/admin_edit.js new file mode 100644 index 0000000..8be4f31 --- /dev/null +++ b/lib/assets/javascripts/views/guidance_groups/admin_edit.js @@ -0,0 +1,5 @@ +import ariatiseForm from '../../utils/ariatiseForm'; + +$(() => { + ariatiseForm({ selector: '#admin_update_guidance_group_form' }); +}); diff --git a/lib/assets/javascripts/views/guidance_groups/admin_new.js b/lib/assets/javascripts/views/guidance_groups/admin_new.js new file mode 100644 index 0000000..8f882fd --- /dev/null +++ b/lib/assets/javascripts/views/guidance_groups/admin_new.js @@ -0,0 +1,5 @@ +import ariatiseForm from '../../utils/ariatiseForm'; + +$(() => { + ariatiseForm({ selector: '#admin_create_guidance_group_form' }); +}); diff --git a/lib/assets/javascripts/views/guidances/admin_edit.js b/lib/assets/javascripts/views/guidances/admin_edit.js index 31a99e1..40e9f31 100644 --- a/lib/assets/javascripts/views/guidances/admin_edit.js +++ b/lib/assets/javascripts/views/guidances/admin_edit.js @@ -1,55 +1,7 @@ -$(document).ready(function(){ - $('#edit_guidance_submit').click( function(e){ - var alert_message = []; +import ariatiseForm from '../../utils/ariatiseForm'; +import { Tinymce } from '../../utils/tinymce'; - //verify if text area is not nil - var editorContent = tinyMCE.get('guidance-text').getContent(); - if (editorContent == ''){ - alert_message.push(__('add guidance text')); - } - //verify dropdown with questions has a selected option if guidance for a question being used - if($('#guidance_theme_ids').val() == undefined || $('#guidance_theme_ids').val() == ''){ - alert_message.push(__('select at least one theme')); - } - //verify if guidance group is selected - if ( ($('#guidance_guidance_group_id').val() == '') || $('#guidance_guidance_group_id').val() == undefined ) { - alert_message.push(__('select a guidance group')); - } - - if(alert_message.length == 0){ - $('#edit_guidance_form').submit(); - return false; - } - else if (alert_message.length != 0){ - var message = '', - self = this; - - $('#edit_guidance_alert_dialog').dialog({ - modal: true, - width: '400px', - title: 'Before submitting, please:', - - open: function(e, ui){ - // This duplicates functionality in modals.js. We should make this a - // standard modal OR convert to use the standard error handling we decide on - $("button.ui-dialog-titlebar-close").remove(); - $(".ui-dialog-titlebar").append(''); - - $("span.modal-close").click(function(e){ - e.preventDefault(); - $(this).parent(".ui-dialog-titlebar").siblings("div.modal").dialog('close'); - }); - - $("#missing_fields_edit_guidance").empty(); - $.each(alert_message, function(key, value){ - message += "
  • "+value+"
  • "; - }); - $("#missing_fields_edit_guidance").append(message); - } - }); - delete message; - } - delete alert_message; - e.preventDefault(); - }); -}); \ No newline at end of file +$(() => { + ariatiseForm({ selector: '#edit_guidance_form' }); + Tinymce.init({ selector: '.tinymce' }); +}); diff --git a/lib/assets/javascripts/views/guidances/admin_new.js b/lib/assets/javascripts/views/guidances/admin_new.js new file mode 100644 index 0000000..5e3810c --- /dev/null +++ b/lib/assets/javascripts/views/guidances/admin_new.js @@ -0,0 +1,7 @@ +import ariatiseForm from '../../utils/ariatiseForm'; +import { Tinymce } from '../../utils/tinymce'; + +$(() => { + ariatiseForm({ selector: '#new_guidance_form' }); + Tinymce.init({ selector: '.tinymce' }); +}); diff --git a/lib/assets/javascripts/views/plans/new.js b/lib/assets/javascripts/views/plans/new.js index 63ed8c9..9ab1310 100644 --- a/lib/assets/javascripts/views/plans/new.js +++ b/lib/assets/javascripts/views/plans/new.js @@ -5,6 +5,11 @@ import { isValidText } from '../../utils/isValidInputType'; $(() => { + // AJAX error function for available template search + const error = () => { + // TODO: add error handling + }; + // AJAX success function for available template search const success = (data) => { if (isObject(data) && @@ -14,28 +19,21 @@ data.templates.forEach((t) => { $('#plan_template_id').append(``); }); - // If there is only one template, show it but disable the dropdown and hide - // the 'Multiple templates found message' + // If there is only one template, set the input field value and submit the form + // otherwise show the dropdown list and the 'Multiple templates found message' if (data.templates.length === 1) { $('#plan_template_id option').attr('selected', 'true'); - $('#single-template').show(); $('#multiple-templates').hide(); } else { - $('#single-template').hide(); $('#multiple-templates').show(); + $('#available-templates').fadeIn(); } - $('#available-templates').fadeIn(); } else { - $('#available-templates').fadeOut(); - // TODO adequate error handling for no templates returned - // (this would mean there is no default template!) + error(); } } }; - // AJAX error function for available template search - const error = () => { - // TODO adequate error handling for network error - }; + const getAction = jQueryForm => jQueryForm.attr('action'); const getMethod = jQueryForm => jQueryForm.attr('method');
    <%= _('Text') %><%= _('Themes') %><%= _('Guidance group') %><%= _('Last updated') %> + <%= _('Text') %><%= _('Themes') %><%= _('Guidance group') %><%= _('Last updated') %><%= _('Actions') %>