diff --git a/app/controllers/guidances_controller.rb b/app/controllers/guidances_controller.rb index 31036f4..eeed41b 100644 --- a/app/controllers/guidances_controller.rb +++ b/app/controllers/guidances_controller.rb @@ -11,19 +11,23 @@ end def admin_new - @guidance = Guidance.new - authorize @guidance - @themes = Theme.all.order('title') - @guidance_groups = GuidanceGroup.where(org_id: current_user.org_id).order('name ASC') + guidance = Guidance.new + authorize guidance + themes = Theme.all.order('title') + guidance_groups = GuidanceGroup.where(org_id: current_user.org_id).order('name ASC') + render(:new_edit, locals: { guidance: guidance, themes: themes, + guidance_groups: guidance_groups, options: { url: admin_create_guidance_path, method: :post }}) end ## # GET /guidances/1/edit def admin_edit - @guidance = Guidance.eager_load(:themes, :guidance_group).find(params[:id]) - authorize @guidance - @themes = Theme.all.order('title') - @guidance_groups = GuidanceGroup.where(org_id: current_user.org_id).order('name ASC') + guidance = Guidance.eager_load(:themes, :guidance_group).find(params[:id]) + authorize guidance + themes = Theme.all.order('title') + guidance_groups = GuidanceGroup.where(org_id: current_user.org_id).order('name ASC') + render(:new_edit, locals: { guidance: guidance, themes: themes, + guidance_groups: guidance_groups, options: { url: admin_update_guidance_path(guidance), method: :put }}) end ## diff --git a/app/views/guidances/new_edit.html.erb b/app/views/guidances/new_edit.html.erb new file mode 100644 index 0000000..79a995c --- /dev/null +++ b/app/views/guidances/new_edit.html.erb @@ -0,0 +1,32 @@ +<%# locals: { guidance, themes, guidance_groups, options } %> +
+
+

<%= _('Guidance') %>

+
+
+
+
+ <%= form_for(guidance, url: options[:url], html: { method: options[:method] , id: 'new_edit_guidance'}) do |f| %> +
+ <%= 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}, {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}, {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" %> + <%= link_to _('Cancel'), admin_index_guidance_path, class: "btn btn-primary", role: 'button' %> + <%end%> +
+
\ No newline at end of file diff --git a/lib/assets/javascripts/application.js b/lib/assets/javascripts/application.js index 88b1a1f..415992b 100644 --- a/lib/assets/javascripts/application.js +++ b/lib/assets/javascripts/application.js @@ -18,8 +18,7 @@ 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/guidances/new_edit'; import './views/notes/index'; import './views/org_admin/templates/edit'; import './views/org_admin/templates/index'; diff --git a/lib/assets/javascripts/views/guidances/admin_edit.js b/lib/assets/javascripts/views/guidances/admin_edit.js deleted file mode 100644 index 40e9f31..0000000 --- a/lib/assets/javascripts/views/guidances/admin_edit.js +++ /dev/null @@ -1,7 +0,0 @@ -import ariatiseForm from '../../utils/ariatiseForm'; -import { Tinymce } from '../../utils/tinymce'; - -$(() => { - 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 deleted file mode 100644 index 5e3810c..0000000 --- a/lib/assets/javascripts/views/guidances/admin_new.js +++ /dev/null @@ -1,7 +0,0 @@ -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/guidances/new_edit.js b/lib/assets/javascripts/views/guidances/new_edit.js new file mode 100644 index 0000000..4aa96c0 --- /dev/null +++ b/lib/assets/javascripts/views/guidances/new_edit.js @@ -0,0 +1,7 @@ +import ariatiseForm from '../../utils/ariatiseForm'; +import { Tinymce } from '../../utils/tinymce'; + +$(() => { + ariatiseForm({ selector: '#new_edit_guidance' }); + Tinymce.init({ selector: '.tinymce' }); +}); diff --git a/test/functional/guidances_controller_test.rb b/test/functional/guidances_controller_test.rb index 692a99b..e2a1bde 100644 --- a/test/functional/guidances_controller_test.rb +++ b/test/functional/guidances_controller_test.rb @@ -61,9 +61,6 @@ get admin_new_guidance_path(@guidance_group) assert_response :success - assert assigns(:guidance) - assert assigns(:guidance_groups) - assert assigns(:themes) end # /org/admin/guidance/:id/admin_edit (admin_edit_guidance_path) @@ -77,9 +74,6 @@ get admin_edit_guidance_path(@guidance_group) assert_response :success - assert assigns(:guidance) - assert assigns(:guidance_groups) - assert assigns(:themes) end # POST /org/admin/guidance/:id/admin_create (admin_create_guidance_path)