From b285cec9d22cf7f0465ecd7dd37ac99eb6c560ac Mon Sep 17 00:00:00 2001 From: Weiwei Shi Date: Tue, 31 May 2016 16:33:33 -0600 Subject: [PATCH] organization admin can delete template --- app/controllers/dmptemplates_controller.rb | 50 ++++++++++----------- app/views/dmptemplates/admin_index.html.erb | 11 ++--- config/locales/en.yml | 3 ++ 3 files changed, 30 insertions(+), 34 deletions(-) diff --git a/app/controllers/dmptemplates_controller.rb b/app/controllers/dmptemplates_controller.rb index 5b8e6d77..c2ac77dd 100755 --- a/app/controllers/dmptemplates_controller.rb +++ b/app/controllers/dmptemplates_controller.rb @@ -37,31 +37,7 @@ def admin_template end end - - - # PUT /dmptemplates/1 - # PUT /dmptemplates/1.json - def admin_update - if user_signed_in? && current_user.is_org_admin? then - @dmptemplate = Dmptemplate.find(params[:id]) - @dmptemplate.description = params["template-desc"] - - respond_to do |format| - if @dmptemplate.update_attributes(params[:dmptemplate]) - format.html { redirect_to admin_template_dmptemplate_path(params[:dmptemplate]), notice: I18n.t('org_admin.templates.updated_message') } - format.json { head :no_content } - else - format.html { render action: "edit" } - format.json { render json: @dmptemplate.errors, status: :unprocessable_entity } - end - end - else - render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false) - end - end - - - # GET /dmptemplates/new + # GET /dmptemplates/new # GET /dmptemplates/new.json def admin_new if user_signed_in? && current_user.is_org_admin? then @@ -98,6 +74,26 @@ def admin_create end end + # PUT /dmptemplates/1 + # PUT /dmptemplates/1.json + def admin_update + if user_signed_in? && current_user.is_org_admin? then + @dmptemplate = Dmptemplate.find(params[:id]) + @dmptemplate.description = params["template-desc"] + + respond_to do |format| + if @dmptemplate.update_attributes(params[:dmptemplate]) + format.html { redirect_to admin_template_dmptemplate_path(params[:dmptemplate]), notice: I18n.t('org_admin.templates.updated_message') } + format.json { head :no_content } + else + format.html { render action: "edit" } + format.json { render json: @dmptemplate.errors, status: :unprocessable_entity } + end + end + else + render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false) + end + end # DELETE /dmptemplates/1 @@ -108,13 +104,13 @@ def admin_destroy @dmptemplate.destroy respond_to do |format| - format.html { redirect_to admin_index_dmptemplate_path } + format.html { redirect_to admin_index_dmptemplate_path, notice: I18n.t('org_admin.template.template_destroyed_message') } format.json { head :no_content } end else render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false) end - end + end diff --git a/app/views/dmptemplates/admin_index.html.erb b/app/views/dmptemplates/admin_index.html.erb index ed0eabd9..220aa9aa 100755 --- a/app/views/dmptemplates/admin_index.html.erb +++ b/app/views/dmptemplates/admin_index.html.erb @@ -48,13 +48,10 @@ <%= l org_template.updated_at.to_date, :formats => :short %> - <%if current_user.is_org_admin? then%> - <% b_label = t('helpers.submit.edit')%> - <%else%> - <% b_label = t('helpers.view')%> - <%end%> - <%= link_to b_label, admin_template_dmptemplate_path(org_template), :class => "dmp_table_link"%> - + <%= link_to t("helpers.submit.edit"), admin_template_dmptemplate_path(org_template), :class => "dmp_table_link"%> + <%= link_to t("helpers.submit.delete"), admin_destroy_dmptemplate_path(org_template), :confirm => t("org_admin.templates.template_delete_message", :template_title => org_template.title ), :method => :delete, :class => "dmp_table_link"%> + + <%end%> diff --git a/config/locales/en.yml b/config/locales/en.yml index 89ea3fa2..654a1507 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -102,6 +102,7 @@ en: org_admin: admin_area: "Admin area" template_label: "Templates" + template_view: "Template" user_list_label: "Users" org_details_label: "Organisation details" org_text: "These are the basic details for your organisation." @@ -202,6 +203,8 @@ en:

Your template will be presented to users within your institution when no funder templates apply. If you want to add questions to funder templates use the 'customise template' options below.

" create_new_template_text_html: "

To create a new template, first enter a title and description. Once you have saved this you will be presented with options to add one or more phases.

" desc_help_text_html: "Enter a description that helps you to differentiate between templates e.g. if you have ones for different audiences" + template_delete_message: "You are about to delete '%{template_title}'. Are you sure?" + template_destroyed_message: "Template was successfully deleted." own_temp: "Own templates" add_phase_label: "Add new phase +" view_phase_label: "View phase"