diff --git a/app/controllers/templates_controller.rb b/app/controllers/templates_controller.rb index 385493e..ad698f1 100644 --- a/app/controllers/templates_controller.rb +++ b/app/controllers/templates_controller.rb @@ -54,6 +54,12 @@ @template = Template.new(params[:template]) @template.org_id = current_user.org_id @template.description = params['template-desc'] + @template.published = false + @template.version = 0 + @template.dmptemplate_id = loop do + random = rand 2147483647 + break random unless Template.exists?(dmptemplate_id: random) + end authorize @template if @template.save redirect_to admin_template_template_path(@template), notice: I18n.t('org_admin.templates.created_message') @@ -82,7 +88,7 @@ @edit = params[:edit] == "true" ? true : false #verify if there are any sections if not create one @sections = @phase.sections - if !@sections.any?() || @sections.count == 0 then + if !@sections.any?() || @sections.count == 0 @section = @phase.sections.build @section.phase = @phase @section.title = '' @@ -93,11 +99,11 @@ @new_sec = true end #verify if section_id has been passed, if so then open that section - if params.has_key?(:section_id) then + if params.has_key?(:section_id) @open = true @section_id = params[:section_id].to_i end - if params.has_key?(:question_id) then + if params.has_key?(:question_id) @question_id = params[:question_id].to_i end end @@ -105,8 +111,9 @@ #preview a phase def admin_previewphase - @template = Template.find(params[:id]) - authorize @template + @phase = Phase.find(params[:id]) + authorize @phase.template + @template = @phase.template end diff --git a/app/models/question.rb b/app/models/question.rb index 7a91897..cd15316 100644 --- a/app/models/question.rb +++ b/app/models/question.rb @@ -28,7 +28,6 @@ :modifiable, :option_comment_display, :as => [:default, :admin] - # EVALUATE CLASS AND INSTANCE METHODS BELOW # # What do they do? do they do it efficiently, and do we need them? @@ -101,11 +100,12 @@ # pulls together guidance from various sources for question guidances = {} theme_ids = question.theme_ids - - GuidanceGroup.where(org_id: org.id).each do |group| - group.guidances.each do |g| - g.themes.where("id IN (?)", theme_ids).each do |gg| - guidances["#{group.name} " + I18n.t('admin.guidance_lowercase_on') + " #{gg.title}"] = g + if theme_ids.present? + GuidanceGroup.where(org_id: org.id).each do |group| + group.guidances.each do |g| + g.themes.where("id IN (?)", theme_ids).each do |gg| + guidances["#{group.name} " + I18n.t('admin.guidance_lowercase_on') + " #{gg.title}"] = g + end end end end diff --git a/app/views/templates/_add_guidance.html.erb b/app/views/templates/_add_guidance.html.erb index de49775..af080d0 100644 --- a/app/views/templates/_add_guidance.html.erb +++ b/app/views/templates/_add_guidance.html.erb @@ -1,93 +1,93 @@
| <%= t("org_admin.guidance.text_label") %> | -
- <%= text_area_tag("guidance-text", "", class: "tinymce") %>
-
-
- <%= link_to( image_tag("help_button.png"), "#", :class => "guidance_text_popover", :rel => "popover", "data-html" => "true", "data-content" => t("org_admin.guidance.text_help_text_html"))%>
-
-
- |
- ||||||||
| <%= t("org_admin.guidance.by_theme_or_by_question") %> | -
- <%= select_tag "g_options", options_for_select([[t("org_admin.guidance.by_themes_label"), 1],
- [t("org_admin.guidance.by_question_label"), 2]]) %>
-
-
- <%= link_to( image_tag("help_button.png"), "#", :class => "guidance_apply_to_popover", :rel => "popover", "data-html" => "true", "data-content" => t("org_admin.guidance.apply_to_help_text_html"))%>
-
-
+ <%= form_for :guidance, url: {action: "admin_create"}, html: {id: "new_guidance_form"} do |f| %>
+
- <%= t("helpers.submit.save")%>
-
- <%= link_to t("helpers.submit.cancel"), :back, :class => "btn cancel" %>
+
+ |
+ ||||||||
| <%= t("org_admin.guidance.published") %> | +
+
+ <%= f.check_box :published , as: :check_boxes %>
+
+ |
+ ||||||||
| <%= t("org_admin.guidance.guidance_group_label") %> | +
+
+ <%= f.collection_select(:guidance_group_ids,
+ GuidanceGroup.where(org_id: current_user.org_id).order("name ASC"),
+ :id, :name, {prompt: false, include_blank: t('helpers.none')}, {multiple: false})%>
+
+
+ <%= link_to( image_tag("help_button.png"), "#", class: "guidance_group_select_popover", rel: "popover", "data-html" => "true", "data-content" => t("org_admin.guidance.guidance_group_select_help_text_html"))%>
+
+
+ |
+