diff --git a/Gemfile b/Gemfile index 0bd6fff..c95209d 100644 --- a/Gemfile +++ b/Gemfile @@ -81,6 +81,7 @@ # INTERNATIONALIZATION gem "i18n-js", ">= 3.0.0.rc11" #damodar added TODO: explain gem 'gettext_i18n_rails', '~> 1.8' +gem "gettext_i18n_rails_js", "~> 1.2.0" # ------------------------------------------------ # API diff --git a/Gemfile.lock b/Gemfile.lock index 9784215..38f77ae 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -136,8 +136,16 @@ actionpack (>= 3.2.13) friendly_id (5.1.0) activerecord (>= 4.0.0) + gettext (3.2.2) + locale (>= 2.0.5) + text (>= 1.3.0) gettext_i18n_rails (1.8.0) fast_gettext (>= 0.9.0) + gettext_i18n_rails_js (1.2.0) + gettext (>= 3.0.2) + gettext_i18n_rails (>= 0.7.1) + po_to_json (>= 1.0.0) + rails (>= 3.2.0) globalid (0.3.7) activesupport (>= 4.1.0) hashdiff (0.3.0) @@ -180,6 +188,7 @@ sprockets (> 2, < 4) tilt libv8 (3.16.14.15) + locale (2.1.2) loofah (2.0.3) nokogiri (>= 1.5.9) mail (2.6.4) @@ -240,6 +249,8 @@ orm_adapter (0.5.0) pg (0.19.0) pkg-config (1.1.7) + po_to_json (1.0.1) + json (>= 1.6.0) protected_attributes (1.1.3) activemodel (>= 4.0.1, < 5.0) pundit (1.1.0) @@ -309,6 +320,7 @@ swagger-docs (0.2.9) activesupport (>= 3) rails (>= 3) + text (1.3.1) therubyracer (0.12.2) libv8 (~> 3.16.14.0) ref @@ -366,6 +378,7 @@ formtastic friendly_id gettext_i18n_rails (~> 1.8) + gettext_i18n_rails_js (~> 1.2.0) htmltoword i18n-js (>= 3.0.0.rc11) jbuilder diff --git a/app/controllers/guidances_controller.rb b/app/controllers/guidances_controller.rb index 637bc2e..3d22eb3 100644 --- a/app/controllers/guidances_controller.rb +++ b/app/controllers/guidances_controller.rb @@ -13,63 +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 -# TODO: These no longer appear to be in use - #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 ## @@ -79,6 +40,10 @@ authorize @guidance @guidance.text = params["guidance-text"] @guidance.question_id = params["question_id"] + + @guidance.themes = [] + guidance_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 @@ -90,8 +55,9 @@ if @guidance.save redirect_to admin_show_guidance_path(@guidance), notice: _('Guidance was successfully created.') else - load_select_box_content flash[:notice] = generate_error_notice(@guidance) + @themes = Theme.all.order('title') + @guidance_groups = GuidanceGroup.where(org_id: current_user.org_id).order('name ASC') render action: "admin_new" end end @@ -107,8 +73,10 @@ if @guidance.save(guidance_params) redirect_to admin_show_guidance_path(params[:guidance]), notice: _('Guidance was successfully updated.') else - load_select_box_content flash[:notice] = generate_error_notice(@guidance) + @themes = Theme.all.order('title') + @guidance_groups = GuidanceGroup.where(org_id: current_user.org_id).order('name ASC') + render action: "admin_edit" end end @@ -127,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 a45c2f2..972efa3 100644 --- a/app/models/guidance.rb +++ b/app/models/guidance.rb @@ -19,8 +19,6 @@ #has_and_belongs_to_many :guidance_groups, join_table: "guidance_in_group" - - # EVALUATE CLASS AND INSTANCE METHODS BELOW # # What do they do? do they do it efficiently, and do we need them? 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.'))%> -
-
- 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.'))%> -
-
- -