Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Commit

Permalink
organization admin can delete template
Browse files Browse the repository at this point in the history
  • Loading branch information
weiweishi committed May 31, 2016
1 parent aafa7ee commit b285cec
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 34 deletions.
50 changes: 23 additions & 27 deletions app/controllers/dmptemplates_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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



Expand Down
11 changes: 4 additions & 7 deletions app/views/dmptemplates/admin_index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,10 @@
<%= l org_template.updated_at.to_date, :formats => :short %>
</td>
<td class="dmp_td_small">
<%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"%>
</td>
<%= 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"%>

</td>
</tr>
<%end%>
</tbody>
Expand Down
3 changes: 3 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down Expand Up @@ -202,6 +203,8 @@ en:
<p>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.</p>"
create_new_template_text_html: "<p>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. </p>"
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"
Expand Down

0 comments on commit b285cec

Please sign in to comment.