diff --git a/app/controllers/guidances_controller.rb b/app/controllers/guidances_controller.rb
index 123b334..5387dc9 100644
--- a/app/controllers/guidances_controller.rb
+++ b/app/controllers/guidances_controller.rb
@@ -13,62 +13,24 @@
##
# GET /guidances/1
def admin_show
- @guidance = Guidance.includes(:guidance_group, :themes).find(params[:id])
+ @guidance = Guidance.eager_load(:guidance_group, :themes).find(params[:id])
authorize @guidance
end
def admin_new
@guidance = Guidance.new
authorize @guidance
-
- load_select_box_content
+ @themes = Theme.all.order('title')
+ @guidance_groups = GuidanceGroup.where(org_id: current_user.org_id).order('name ASC')
end
- #setup variables for use in the dynamic updating
- def update_phases
- authorize Guidance
- # updates phases, versions, sections and questions based on template selected
- dmptemplate = Template.find(params[:dmptemplate_id])
- # map to title and id for use in our options_for_select
- @phases = dmptemplate.phases.map{|a| [a.title, a.id]}.insert(0, _('Select a phase'))
- @versions = dmptemplate.versions.map{|s| [s.title, s.id]}.insert(0, _('Select a version'))
- @sections = dmptemplate.sections.map{|s| [s.title, s.id]}.insert(0, _('Select a section'))
- @questions = dmptemplate.questions.map{|s| [s.text, s.id]}.insert(0, _('Select a question'))
- end
-
- def update_versions
- authorize Guidance
- # updates versions, sections and questions based on phase selected
- phase = Phase.find(params[:phase_id])
- # map to name and id for use in our options_for_select
- @versions = phase.versions.map{|s| [s.title, s.id]}.insert(0, _('Select a version'))
- @sections = phase.sections.map{|s| [s.title, s.id]}.insert(0, _('Select a section'))
- @questions = phase.questions.map{|s| [s.text, s.id]}.insert(0, _('Select a question'))
- end
-
- def update_sections
- authorize Guidance
- # updates sections and questions based on version selected
- version = Version.find(params[:version_id])
- # map to name and id for use in our options_for_select
- @sections = version.sections.map{|s| [s.title, s.id]}.insert(0, _('Select a section'))
- @questions = version.questions.map{|s| [s.text, s.id]}.insert(0, _('Select a question'))
- end
-
- def update_questions
- authorize Guidance
- # updates songs based on artist selected
- section = Section.find(params[:section_id])
- @questions = section.questions.map{|s| [s.text, s.id]}.insert(0, _('Select a question'))
- end
-
##
# GET /guidances/1/edit
def admin_edit
- @guidance = Guidance.includes(:themes, :guidance_group).find(params[:id])
+ @guidance = Guidance.eager_load(:themes, :guidance_group).find(params[:id])
authorize @guidance
-
- load_select_box_content
+ @themes = Theme.all.order('title')
+ @guidance_groups = GuidanceGroup.where(org_id: current_user.org_id).order('name ASC')
end
##
@@ -78,6 +40,10 @@
authorize @guidance
@guidance.text = params["guidance-text"]
@guidance.question_id = params["question_id"]
+
+ @guidance.themes = []
+ params[:theme_ids].map{|t| @guidance.themes << Theme.find(t.to_i) unless t.empty? }
+
if @guidance.published == true then
@gg = GuidanceGroup.find(@guidance.guidance_group_id)
if @gg.published == false || @gg.published.nil? then
@@ -89,7 +55,8 @@
if @guidance.save
redirect_to admin_show_guidance_path(@guidance), notice: _('Guidance was successfully created.')
else
- load_select_box_content
+ @themes = Theme.all.order('title')
+ @guidance_groups = GuidanceGroup.where(org_id: current_user.org_id).order('name ASC')
render action: "admin_new"
end
end
@@ -101,11 +68,15 @@
authorize @guidance
@guidance.text = params["guidance-text"]
@guidance.question_id = params["question_id"]
-
- if @guidance.update_attributes(params[:guidance])
- redirect_to admin_show_guidance_path(params[:guidance]), notice: _('Guidance was successfully updated.')
+
+ @guidance.themes = []
+ guidance_params[:theme_ids].map{|t| @guidance.themes << Theme.find(t.to_i) unless t.empty? }
+
+ if @guidance.update_attributes(guidance_params)
+ redirect_to admin_show_guidance_path(guidance_params), notice: _('Guidance was successfully updated.')
else
- load_select_box_content
+ @themes = Theme.all.order('title')
+ @guidance_groups = GuidanceGroup.where(org_id: current_user.org_id).order('name ASC')
render action: "admin_edit"
end
end
@@ -124,39 +95,6 @@
private
def guidance_params
# The form on the page is weird. The text and template/section/question stuff is outside of the normal form params
- params.require(:guidance).permit(:guidance_group_id, :theme_ids, :published)
- end
-
- def load_select_box_content
- #@templates = Template.funders_and_own_templates(current_user.org_id)
- # Replacing weird accessor on Template
- @templates = (Org.funders.collect{|o| o.templates } + current_user.org.templates).flatten
-
- @phases = nil
- @templates.each do |template|
- if @phases.nil? then
- @phases = template.phases.all.order('number')
- else
- @phases = @phases + template.phases.all.order('number')
- end
- end
- @sections = nil
- @phases.each do |phase|
- if @sections.nil? then
- @sections = phase.sections.all.order('number')
- else
- @sections = @sections + phase.sections.all.order('number')
- end
- end
- @questions = nil
- @sections.each do |section|
- if @questions.nil? then
- @questions = section.questions.all.order('number')
- else
- @questions = @questions + section.questions.all.order('number')
- end
- end
- @themes = Theme.all.order('title')
- @guidance_groups = GuidanceGroup.where(org_id: current_user.org_id).order('name ASC')
+ params.require(:guidance).permit(:guidance_group_id, :published, theme_ids: [])
end
end
\ No newline at end of file
diff --git a/app/models/guidance.rb b/app/models/guidance.rb
index 26a83ff..00b912c 100644
--- a/app/models/guidance.rb
+++ b/app/models/guidance.rb
@@ -16,7 +16,7 @@
# belongs_to :question
has_and_belongs_to_many :themes, join_table: "themes_in_guidance"
# depricated, but required for migration "single_group_for_guidance"
- has_and_belongs_to_many :guidance_groups, join_table: "guidance_in_group"
+# has_and_belongs_to_many :guidance_groups, join_table: "guidance_in_group"
diff --git a/app/views/guidances/_add_guidance.html.erb b/app/views/guidances/_add_guidance.html.erb
index 19579e5..28f75f6 100644
--- a/app/views/guidances/_add_guidance.html.erb
+++ b/app/views/guidances/_add_guidance.html.erb
@@ -17,15 +17,6 @@
| <%= _('Should this guidance apply:') %> |
-
- <%= select_tag "g_options", options_for_select([[_('by themes'), 1],
- [_('by question'), 2]]) %>
-
-
- <%= link_to( image_tag("help_button.png"), "#", class: "guidance_apply_to_popover", rel: "popover", "data-html" => "true", "data-content" => _('Decide whether your guidance should display by themes (default) or if it only pertains to a specific question in one of the funder templates.'))%>
-
-
-
<%= f.collection_select(:theme_ids,
@@ -36,7 +27,6 @@
<%= link_to( image_tag("help_button.png"), "#", class: "guidance_by_themes_popover", rel: "popover", "data-html" => "true", "data-content" => _('Select which theme(s) this guidance relates to.'))%>
-
|
diff --git a/app/views/guidances/admin_edit.html.erb b/app/views/guidances/admin_edit.html.erb
index 5851286..565f5d4 100644
--- a/app/views/guidances/admin_edit.html.erb
+++ b/app/views/guidances/admin_edit.html.erb
@@ -34,24 +34,9 @@
- | <%= _('Should this guidance apply:') %> |
-
- <% if !@guidance.question_id.nil? then %>
- <% select_op = 2 %>
- <% else %>
- <% select_op = 1%>
- <% end %>
- <%= hidden_field 'select_op', value: select_op, id: 'edit_guid_ques_flag' %>
-
- <%= select_tag "g_options", options_for_select({_('by themes') => 1,
- _('by question') => 2}, select_op) %>
-
-
- <%= link_to( image_tag('help_button.png'), '#', class: 'guidance_apply_to_popover', rel: "popover", 'data-html' => "true", 'data-content' => _('Decide whether your guidance should display by themes (default) or if it only pertains to a specific question in one of the funder templates.'))%>
-
-
-
-
+ <%= _('Themes') %> |
+
+
<%= f.collection_select(:theme_ids, @themes, :id, :title,
{prompt: false, include_blank: 'None'}, {multiple: true})%>
@@ -60,7 +45,6 @@
<%= link_to( image_tag('help_button.png'), '#', class: 'guidance_by_themes_popover', rel: "popover", 'data-html' => "true", 'data-content' => _('Select which theme(s) this guidance relates to.'))%>
-
|
diff --git a/app/views/guidances/admin_new.html.erb b/app/views/guidances/admin_new.html.erb
index cdbb0a0..eb7f7a3 100644
--- a/app/views/guidances/admin_new.html.erb
+++ b/app/views/guidances/admin_new.html.erb
@@ -29,17 +29,9 @@
|
- | <%= _('Should this guidance apply:') %> |
-
- <%= select_tag "g_options", options_for_select([[_('by themes'), 1],
- [_('by question'), 2]]) %>
-
-
- <%= link_to( image_tag('help_button.png'), '#', class: 'guidance_apply_to_popover', rel: "popover", 'data-html' => "true", 'data-content' => _('Decide whether your guidance should display by themes (default) or if it only pertains to a specific question in one of the funder templates.'))%>
-
-
-
-
+ <%= _('Themes') %> |
+
+
<%= f.collection_select(:theme_ids, @themes,
:id, :title, {prompt: false, include_blank: 'None'}, {multiple: true})%>
@@ -48,25 +40,8 @@
<%= link_to( image_tag('help_button.png'), '#', class: 'guidance_by_themes_popover', rel: "popover", 'data-html' => "true", 'data-content' => _('Select which theme(s) this guidance relates to.'))%>
-
-
-
- <%= collection_select(nil, :template_id, @templates, :id, :title, {prompt: _('Select a template')}, {id: 'templates_select'}) %>
-
- <%= collection_select(nil, :phase_id, @phases, :id, :title, {prompt: _('Select a phase')}, {id: 'phases_select'}) %>
-
- <%= collection_select(nil, :section_id, @sections, :id, :title, {prompt: _('Select a section')}, {id: 'sections_select'}) %>
-
- <%= collection_select(nil, :question_id, @questions, :id, :text, {prompt: _('Select a question')}, {id: 'questions_select'}) %>
-
-
-
- <%= link_to( image_tag('help_button.png'), '#', class: 'guidance_by_question_popover', rel: "popover", 'data-html' => "true", 'data-content' => _('Select the relevant template, phase, version, section and question from the following dropdown options to define which specific question this guidance should display on.'))%>
-
-
-
-
+
|
|
diff --git a/app/views/guidances/admin_show.html.erb b/app/views/guidances/admin_show.html.erb
index 59de8ba..4742641 100644
--- a/app/views/guidances/admin_show.html.erb
+++ b/app/views/guidances/admin_show.html.erb
@@ -25,21 +25,10 @@
| <%= _('Text') %> |
<%= raw @guidance.text %> |
- <% if @guidance.themes !=[] then %>
-
- | <%= _('Themes') %> |
- <% @guidance.themes.each do |th|%>
- <%= th.title %>
- <% end %>
- |
-
- <% end %>
- <% if !@guidance.question_id.nil? %>
-
- | <%= _('Question') %> |
- <%= raw @guidance.question.text %> |
-
- <% end %>
+
+ | <%= _('Themes') %> |
+ <%= @guidance.themes.order(:title).collect{|t| t.title}.join(', ') %> |
+
| <%= _('Guidance group') %> |
diff --git a/app/views/guidances/update_phases.js.erb b/app/views/guidances/update_phases.js.erb
deleted file mode 100644
index 3be4344..0000000
--- a/app/views/guidances/update_phases.js.erb
+++ /dev/null
@@ -1,5 +0,0 @@
-$('#phases_select').html("<%= escape_javascript(options_for_select(@phases)) %>");
-$('#versions_select').html("<%= escape_javascript(options_for_select(@versions)) %>");
-$('#sections_select').html("<%= escape_javascript(options_for_select(@sections)) %>");
-$('#questions_select').html("<%= escape_javascript(options_for_select(@questions)) %>");
-
\ No newline at end of file
diff --git a/app/views/guidances/update_questions.js.erb b/app/views/guidances/update_questions.js.erb
deleted file mode 100644
index 56f5ceb..0000000
--- a/app/views/guidances/update_questions.js.erb
+++ /dev/null
@@ -1 +0,0 @@
-$('#questions_select').html("<%= escape_javascript(options_for_select(@questions)) %>hiya");
\ No newline at end of file
diff --git a/app/views/guidances/update_sections.js.erb b/app/views/guidances/update_sections.js.erb
deleted file mode 100644
index 710716c..0000000
--- a/app/views/guidances/update_sections.js.erb
+++ /dev/null
@@ -1,2 +0,0 @@
-$('#sections_select').html("<%= escape_javascript(options_for_select(@sections)) %>");
-$('#questions_select').html("<%= escape_javascript(options_for_select(@questions)) %>");
\ No newline at end of file
diff --git a/app/views/guidances/update_versions.js.erb b/app/views/guidances/update_versions.js.erb
deleted file mode 100644
index f8bcf54..0000000
--- a/app/views/guidances/update_versions.js.erb
+++ /dev/null
@@ -1,3 +0,0 @@
-$('#versions_select').html("<%= escape_javascript(options_for_select(@versions)) %>");
-$('#sections_select').html("<%= escape_javascript(options_for_select(@sections)) %>");
-$('#questions_select').html("<%= escape_javascript(options_for_select(@questions)) %>");
\ No newline at end of file
diff --git a/lib/assets/javascripts/admin.js b/lib/assets/javascripts/admin.js
index 3e0e27d..f572f71 100644
--- a/lib/assets/javascripts/admin.js
+++ b/lib/assets/javascripts/admin.js
@@ -93,7 +93,7 @@
//Code to show/hide divs on new guidance (by themes or by question)
- $('#g_options').on("change", function (){
+/* $('#g_options').on("change", function (){
var g_t_q = $(this).val();
e_g_q_f = $("#edit_guid_ques_flag").val();
@@ -108,10 +108,10 @@
}
}).trigger('change');
-
+*/
//filter from template to question 5 dropdowns
- $('#templates_select').change(function() {
+/* $('#templates_select').change(function() {
$.ajax({
type: 'GET',
url: "update_phases",
@@ -170,7 +170,7 @@
//$('#sections_select').show();
$('#questions_select').show();
});
-
+*/
//action for show or hide template editing display
$('#edit_template_button').click(function(e){
@@ -312,7 +312,7 @@
$('#new_guidance_alert_dialog').modal("hide");
});
-
+// TODO: This seems to duplicate the functionality in #edit_guidance_submit
$('#new_guidance_submit').click( function(e){
// $('#new_guidance_alert_dialog').on("hide", function(){
@@ -322,18 +322,9 @@
if (editorContent == ''){
alert_message.push(I18n.t("js.add_guidance_text"));
}
- //verify dropdown with questions has a selected option if guidance for a question being used
- if ($('#g_options').val() == '2') {
- if ($('#questions_select').val() == '' || isNaN($('#questions_select').val())){
- alert_message.push(I18n.t("js.select_question"));
- }
- }
-
- //verify dropdown with questions has a selected option if guidance for a question being used
- if ($('#g_options').val() == '1' ){
- if($('#guidance_theme_ids').val() == undefined || $('#guidance_theme_ids').val() == ''){
- alert_message.push(I18n.t("js.select_at_least_one_theme"));
- }
+ //verify if themes are selected
+ if($('#guidance_theme_ids').val() == undefined || $('#guidance_theme_ids').val() == ''){
+ alert_message.push(I18n.t("js.select_at_least_one_theme"));
}
//verify if guidance group is selected
if ( ($('#guidance_guidance_group_id').val() == '') || $('#guidance_guidance_group_id').val() == undefined ) {
@@ -391,13 +382,11 @@
}
}
//verify dropdown with questions has a selected option if guidance for a question being used
- if ($('#g_options').val() == '1' ){
- if($('#guidance_theme_ids').val() == undefined || $('#guidance_theme_ids').val() == ''){
- alert_message.push(I18n.t("js.select_at_least_one_theme"));
- }
+ if($('#guidance_theme_ids').val() == undefined || $('#guidance_theme_ids').val() == ''){
+ alert_message.push(I18n.t("js.select_at_least_one_theme"));
}
//verify if guidance group is selected
- if ( ($('#guidance_guidance_group_ids').val() == '') || $('#guidance_guidance_group_ids').val() == undefined ) {
+ if ( ($('#guidance_guidance_group_id').val() == '') || $('#guidance_guidance_group_id').val() == undefined ) {
alert_message.push(I18n.t("js.select_guidance_group"));
}
|